npm / cli

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

[BUG] Regression: custom scripts not executed on dependencies from custom registry #4821

Open Cactusbone opened 2 years ago

Cactusbone commented 2 years ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

Using npm i --foreground-scripts (or npm ci --foreground-scripts after the first install), no logs from install script are emitted for a package with a custom registry.

It does work when packages are on the main npm registry.

I've created a package to reproduce this: https://gitlab.com/Cactusbone/test-npm-scripts and I'm using @nexhome/yorkie to check normal behaviour (main registry)

Increasing verbosity in npm logs did not show anything, there's only one line with my package npm timing reifyNode:node_modules/@cactusbone/test-npm-scripts Completed in 75ms

The expected line npm info run @cactusbone/test-npm-scripts@1.0.0 install is never produced.

Expected Behavior

Scripts from packages on a custom registry should be executed.

This is working on npm 6, but not on npm 7 and npm 8

Steps To Reproduce

  1. To demonstrate we'll be using https://gitlab.com/Cactusbone/test-npm-scripts package.
  2. With a package.json containing
    "dependencies": {
    "@cactusbone/test-npm-scripts": "^1.0.0"
    },
  3. and a .npmrc file with @cactusbone:registry=https://gitlab.com/api/v4/packages/npm/
  4. run npm i --foreground-scripts
  5. no logs are produced.

To ensure this is okay from npm registry, I also added "@nexhome/yorkie": "^2.0.8", as a dependency, and this package does produce logs upon installation.

Environment

; "project" config from C:\Prod\test-npm-script-app.npmrc

@cactusbone:registry = "https://gitlab.com/api/v4/packages/npm/"

; "env" config from environment

prefix = "C:\Program Files (x86)\Nodist\bin"

; node bin location = C:\Program Files (x86)\Nodist\v-x64\16.15.0\node.exe ; node version = v16.15.0 ; npm local prefix = C:\Prod\test-npm-script-app ; npm version = 8.8.0 ; cwd = C:\Prod\test-npm-script-app ; HOME = C:\Users\cka ; Run npm config ls -l to show all defaults.



I've also tried it under WSL (ubuntu 20.04 on windows, with nvm, node v16.15.0 and npm v8.5.5), and results are the same

# Work arounds:
- use npm 6 or earlier
- use git link instead of registry

It is also possible to trigger the scripts by using `npm explore @cactusbone/test-npm-scripts -- npm install`
Cactusbone commented 1 year ago

still not working with npm 9.3.1

ylc1234567 commented 1 year ago

Possibly not a bug but a removed feature : https://github.com/npm/cli/issues/3056

Cactusbone commented 1 year ago

Possibly not a bug but a removed feature : #3056

The removed feature in NPM 7 is "console output" by default, It now requires --foreground-scripts to be displayed. However install script from dependencies from either official NPM registry or git dependencies works normally.

What's currently broken is script from dependencies from other NPM registries

Cactusbone commented 10 months ago

still not working with npm 10.2.4

Cactusbone commented 8 months ago

I've found another workaround, by declaring an install script at the app level:

"install": "npm explore @cactusbone/test-npm-scripts -- npm install",

This ensures that npm i at the app level call the install script of the lib

Kenneth-Sills commented 3 months ago

Confirmed not working with 10.8.2.

EDIT: Seeing the Gitlab URL for your registry, this may actually be a duplicate of https://github.com/npm/cli/issues/5380, also related to Gitlab #344107.