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

[yarn run] Arguments are passed to pre and post scripts #1595

Closed
ryym opened this issue Nov 1, 2016 · 5 comments
Closed

[yarn run] Arguments are passed to pre and post scripts #1595

ryym opened this issue Nov 1, 2016 · 5 comments

Comments

@ryym
Copy link

ryym commented Nov 1, 2016

Do you want to request a feature or report a bug?

bug

What is the current behavior?

When I run a script with arguments by yarn run, the arguments are passed to not only the scripts but also its pre and post scripts.

If the current behavior is a bug, please provide the steps to reproduce.

mkdir tmp
cd tmp
cat << JSON > package.json
{
  "name": "none",
  "private": true,
  "scripts": {
    "pretest": "echo pre-test",
    "test": "echo test",
    "posttest": "echo post-test"
  }
}
JSON
yarn run test -- --arg

will output:

yarn run v0.16.1
$ echo pre-test --arg
pre-test --arg
$ echo test --arg
test --arg
$ echo post-test --arg
post-test --arg
✨  Done in 0.11s.

What is the expected behavior?

The arguments are not passed to pre and post scripts.
npm passes the arguments only to the main script.

$ npm run test -- --arg

> none@ pretest /Users/ryu/work/tmp
> echo pre-test

pre-test

> none@ test /Users/ryu/work/tmp
> echo test "--arg"

test --arg

> none@ posttest /Users/ryu/work/tmp
> echo post-test

post-test

Please mention your node.js, yarn and operating system version.

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.11.6
BuildVersion:   15G1108
$ node --version
v6.9.1
$ npm --version
3.10.8
$ yarn --version
0.16.1
@sebmck
Copy link
Contributor

sebmck commented Nov 1, 2016

Created #1596 to fix this, pending approval.

@sebmck sebmck closed this as completed Nov 1, 2016
@ryym
Copy link
Author

ryym commented Nov 1, 2016

Thank you for your quick response!

@Vivekbhusal
Copy link

Apologies for digging the dead but I am stuck around this issue.

{
  "name": "pre-hook-check",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "preinstall": "echo preinstall",
    "postinstall": "echo postinstall"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "abc": "^0.6.1",
    "preact": "^8.2.5"
  }
}

I want to check for the version of installing package at preinstall and verify that it's version is above "1.0.0" (or other policy) else don't let them install.

I would expect, pre and post hooks/scripts to have same context or access to same context as original script.

If I was doing yarn add preact
Then on preinstall script, I could check the version with yarn info preact version to get the info about the installing package.

@kittens Do you know if I can still achieve this?

@gianpaj
Copy link

gianpaj commented Jan 16, 2018

same question as @Vivekbhusal.

My use case is with React Native. When you uninstall a package you need to run an extra command react-native unlink X and, if already removed the package, the react-native cli will error, having to do this:

  1. yarn add X
  2. react-native unlink X and finally
  3. yarn remove X

🙁

Would be great to be able get the name of the package e.g. from the yarn remove lottie-react-native to be able to run react-native unlink lottie-react-native automatically via preuninstall install.

@jayarjo
Copy link

jayarjo commented Apr 2, 2019

@gianpaj @Vivekbhusal looks like they had support for it and then removed it as a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants