Skip to content

Commit

Permalink
feat(check-peer-dependencies-optional-dependency): Added a workaround…
Browse files Browse the repository at this point in the history
… for yarn swallowing postinstall script output
  • Loading branch information
christopherthielen committed Apr 10, 2020
1 parent 927fc53 commit a9c9fdf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ Searching for solutions:
yarn upgrade @angular/[email protected]
```

## Running as postinstall script using `yarn` package manager

Please see [check-peer-dependencies-optional-dependency](https://github.com/christopherthielen/check-peer-dependencies/tree/master/packages/check-peer-dependencies-optional-dependency)
36 changes: 36 additions & 0 deletions packages/check-peer-dependencies-optional-dependency/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# check-peer-dependencies-optional-dependency

## This is a hack to make check-peer-dependency output visible as a postinstall script when using yarn.

### Motivation

I wanted to create a meta-package that provides a set of peerDependencies to downstream projects.
I wanted to run `check-peer-dependencies` as a `postinstall` script to inform users which dependencies are not met and offer a solution.

### Problem

By default, `yarn` package manager hides output from postinstall scripts.
I noticed, however, that output from `optionalDependencies` is visible.

### Using

To run `check-peer-dependencies` as when your package is installed, add `check-peer-dependencies-optional-dependency` as an optional dependency.
This package has a `postinstall` script which invokes `check-peer-dependencies`.

```
{
"name": "my-installable-package",
...
"dependencies": {
...
"check-peer-dependencies": "latest"
},
"peerDependencies": {
"this-package-should-be-installed-downstream": "10.0.0"
},
"optionalDependencies: {
"check-peer-dependencies-optional-dependency": "latest"
}
}
```

10 changes: 10 additions & 0 deletions packages/check-peer-dependencies-optional-dependency/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "check-peer-dependencies-optional-dependency",
"version": "1.0.0",
"description": "Add this module as an optional dependency to check peer dependencies as a postinstall script (yarn)",
"author": "Chris Thielen",
"license": "MIT",
"scripts": {
"postinstall": "npx check-peer-dependencies"
}
}

0 comments on commit a9c9fdf

Please sign in to comment.