Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check engines before running scripts #7013

Closed
alloy opened this issue Feb 7, 2019 · 3 comments
Closed

Check engines before running scripts #7013

alloy opened this issue Feb 7, 2019 · 3 comments
Assignees
Labels

Comments

@alloy
Copy link
Contributor

alloy commented Feb 7, 2019

I want to request a feature, if it doesn’t exist yet.

I wasn’t able to find this in the yarn run docs nor a previous issue asking about this, if I missed it please point me at the right direction.

I would like yarn to check the engines specified in the package.json manifest file before executing any scripts through yarn run (or just yarn). In my case I’m specifically interested in ensuring my team all invoke scripts using the same Node version.

We already have a program that checks the Node version and some of our scripts invoke that before doing their actual work, however:

  • It's easy to add a script and forget to prefix it with our verification program.
  • It doesn’t help the cases where people invoke a program directly without there being a script entry in the package.json file. E.g. they might invoke yarn jest directly, instead of yarn test.

What is the current behavior?

Yarn will run scripts without complaining when engine requirements do not match the current env.

What is the expected behavior?

I would like yarn to complain. E.g.

$ yarn jest
The current environment does not satisfy the engine "node" requirements. Expected version "10.13.*".
$ nvm use 10.13
Now using node v10.13.0
$ yarn jest
yarn run v1.12.3
/Users/eloy/Code/Artsy/metaphysics/node_modules/.bin/jest
[…]
@oguzzkilic
Copy link

It sounds good. I can handle it if there is nobody else working on it.

@alloy
Copy link
Contributor Author

alloy commented Feb 8, 2019

@oguzzkilic I'd love to PR it myself, actually. I know what needs to happen, just wanted to bring it up first :)

@alloy
Copy link
Contributor Author

alloy commented Feb 10, 2019

PR'ed #7021

alloy added a commit to alloy/yarn that referenced this issue Feb 11, 2019
cpojer pushed a commit that referenced this issue Mar 19, 2019
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.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants