npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.46k stars 3.15k forks source link

[BUG] workspace scripts do not propagate exit codes #6506

Open JamesHenry opened 1 year ago

JamesHenry commented 1 year ago

Is there an existing issue for this?

This issue exists in the latest npm version

Minimal Setup

package.json

{
  "workspaces": ["child"],
  "scripts": {
    "exit-100": "exit 100"
  }
}

child/package.json

{
  "scripts": {
    "exit-100": "exit 100"
  }
}

Repro Steps

Behavior in root:

npm run exit-100
echo $? # correctly returns 100

Behavior in workspace:

npm run exit-100 --workspace child
echo $? # incorrectly returns 1

# OR

cd child
npm run exit-100
echo $? # incorrectly returns 1

Also note, if you amend the root package.json to remove the workspaces and then repeat those final steps:

cd child
npm run exit-100
echo $? # (now without workspaces config in the level above) correctly returns 100

Environment

mehulkar commented 1 year ago

I have a minimal reproduction repo here as well: https://github.com/mehulkar/turbo-issue-5098 with node 20.2 + npm 9.6.

JamesHenry commented 1 year ago

@mehulkar my guess is you are actually running into https://github.com/npm/cli/issues/6399 and not what I am describing here