run-script incorrectly executes script with name similar to another script


(Billy B) #1

What I Wanted to Do

I’m using run-script as a build tool, so there are scripts that call other scripts.

What Happened Instead

I noticed that certain scripts were executing twice. One thing led to another during the debugging process, and I have what I believe to be a repeatable error: a script named precompile-dev is being executed even though it should not.

Reproduction Steps

  1. Create a package.json with the following scripts property
    “scripts”: {
    “clean”: “echo ‘clean …’”,
    “compile-dev”: “npm run clean && npm run copyfiles-dev”,
    “copyfiles-dev”: “echo ‘copyfiles-dev …’”,
    “precompile-dev”: “echo ‘precompile-dev …’”,
    “test”: “npm run compile-dev”
    }
  2. Typenpm test at the command line.
  3. Expected: clean … and copyfiles-dev scripts will run
  4. Actual: clean and copyfiles-dev run as expected, but precompile-dev also runs even though it is not invoked. This is an error.

Details

Additional debugging leads me to believe this is because there is another script named compile-dev. When I change the name of either, the problem goes away

Platform Info

$ npm --versions
{ 'orm-object-generator': '0.7.24',
  npm: '5.6.0',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  nghttp2: '1.25.0',
  node: '8.11.1',
  openssl: '1.0.2o',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.50',
  zlib: '1.2.11' }
$ node -p process.platform
linux

(Lars Willighagen) #2

This seems to be expected behavior:

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


(Billy B) #3

Ah. Missed that. Thanks so much