Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

apparent grep issues with npm script execution #17118

Closed
mmase opened this issue Jun 9, 2017 · 1 comment
Closed

apparent grep issues with npm script execution #17118

mmase opened this issue Jun 9, 2017 · 1 comment

Comments

@mmase
Copy link

mmase commented Jun 9, 2017

I'm opening this issue because:

npm is doing something I don't understand.

What's going wrong?

Given the following package.json:

{
  "name": "project",
  "scripts": {
    "css": "npm run postcss",
    "xcss": "npm run postcss",
    "postcss": "echo \"postcss\""
  }
}

Running npm run css will run the postcss script twice. Alternatively, running npm run xcss runs it only once (intended behavior). There seems to be a grep or fuzzy search issue with how scripts are run. This problem is not unique to just 'css,' but it is the use case that brought this to my attention.

...

Example output:

mase@mase-OSX:~/Desktop/project$ npm run css

> project@ css /Users/mase/Desktop/project
> npm run postcss


> project@ postcss /Users/mase/Desktop/project
> echo "postcss"

postcss

> project@ postcss /Users/mase/Desktop/project
> echo "postcss"

postcss
mase@mase-OSX:~/Desktop/project$ npm run xcss

> project@ xcss /Users/mase/Desktop/project
> npm run postcss


> project@ postcss /Users/mase/Desktop/project
> echo "postcss"

postcss

How can the CLI team reproduce the problem?

Described above. First impression is it seems to be related to the word post:

{
  "name": "project",
  "scripts": {
    "abc": "npm run postabc",
    "postabc": "echo \"postabc\""
  }
}

npm run abc also executes postabc twice.

supporting information:

  • npm -v prints: 5.0.3 (Have also reproduced on 3 and 4).
  • node -v prints: v6.11.0
  • npm config get registry prints: https://registry.npmjs.org/
  • Windows, OS X/macOS, or Linux?: MacOS Sierra 10.12.5
@hzoo
Copy link
Contributor

hzoo commented Jun 9, 2017

I think this is specific to using the prefixes pre, post in the name of the npm script

{
  "scripts": {
    "b": "npm run preb",
    "preb": "echo \"a\""
  }
}

https://docs.npmjs.com/misc/scripts

Additionally, arbitrary scripts can be executed by running npm run-script . Pre and post commands with matching names will be run for those as well (e.g. premyscript, myscript, postmyscript).

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

No branches or pull requests

2 participants