feat(run): Add engines check before executing scripts. (#7021)
Closes #7013
**Summary**
A more elaborate description is available in #7013. In short, ensuring scripts are ran in the expected environment can deter hard to diagnose bugs.
**Test plan**
Given a `node` engine requirement that doesn’t match the current environment:
```
$ cat package.json | grep -i1 '"node"'
"engines": {
"node": "^10.13.0"
},
$ nvm use 8
Now using node v8.12.0 (npm v6.4.1)
```
A script invocation will fail as follows:
```
$ node ~/Code/JavaScript/yarn/lib/cli/index.js run relay
yarn run v1.15.0-0
error @artsy/reaction@12.1.10: The engine "node" is incompatible with this module. Expected version "^10.13.0". Got "8.12.0"
error Commands cannot run with an incompatible environment.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```
If need be, this can be overridden with the `--ignore-engines` flag:
```
$ node ~/Code/JavaScript/yarn/lib/cli/index.js run --ignore-engines relay
yarn run v1.15.0-0
$ relay-compiler --src ./src --schema data/schema.graphql --language typescript --artifactDirectory ./src/__generated__ --exclude '**/node_modules/**,**/__mocks__/**,**/__generated__/**'
✨ Done in 2.22s.
```
Or, of course, making the environment match the requirements:
```
$ nvm use 10.13
Now using node v10.13.0 (npm v6.4.1)
$ node ~/Code/JavaScript/yarn/lib/cli/index.js run relay
yarn run v1.15.0-0
$ relay-compiler --src ./src --schema data/schema.graphql --language typescript --artifactDirectory ./src/__generated__ --exclude '**/node_modules/**,**/__mocks__/**,**/__generated__/**'
✨ Done in 1.91s.
``` E
Eloy Durán committed
697a254ee794085c77f82f14f4a515d05e81e294
Parent: bba4dce
Committed by Christoph Nakazawa <cpojer@fb.com>
on 3/19/2019, 10:58:27 AM