Skip to content

[BUG] prepack/postpack output is incorrectly suppressed #6816

@ljharb

Description

@ljharb

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

With this example package.json in an empty dir:

{
  "private": true,
  "name": "test",
  "version": "0.0.0",
  "scripts": {
    "prepack": "echo prepack!",
    "postpack": "echo postpack!"
  }
}

and run npm pack --dry-run. You should see the following output, which appears in npm < 9:

> [email protected] prepack
> echo prepack!

prepack!

> [email protected] postpack
> echo postpack!

postpack!
npm notice 
npm notice 📦  [email protected]
npm notice === Tarball Contents === 
npm notice 234B package.json
npm notice === Tarball Details === 
npm notice name:          foo                                     
npm notice version:       0.0.0                                   
npm notice filename:      foo-0.0.0.tgz                           
npm notice package size:  236 B                                   
npm notice unpacked size: 234 B                                   
npm notice shasum:        ba4102210bf70a017cd510276f01cc0c4b5f68d0
npm notice integrity:     sha512-/s4lXyjWKoW7y[...]adUe23zB6HEkw==
npm notice total files:   1                                       
npm notice 
foo-0.0.0.tgz

However, in npm >= 9.0, i get this output:

npm notice 
npm notice 📦  [email protected]
npm notice === Tarball Contents === 
npm notice 234B package.json
npm notice === Tarball Details === 
npm notice name:          foo                                     
npm notice version:       0.0.0                                   
npm notice filename:      foo-0.0.0.tgz                           
npm notice package size:  236 B                                   
npm notice unpacked size: 234 B                                   
npm notice shasum:        ba4102210bf70a017cd510276f01cc0c4b5f68d0
npm notice integrity:     sha512-/s4lXyjWKoW7y[...]adUe23zB6HEkw==
npm notice total files:   1                                       
npm notice 
foo-0.0.0.tgz

Expected Behavior

npm 9+ doesn't suppress output in prepack/postpack scripts (and more broadly, in any lifecycle script that wouldn't be shown to a user who runs npm install/npm ci such that this project is installed (meaning, my own postinstall/preinstall/prepare scripts should always show output, but nobody else's should)

Steps To Reproduce

see above

Environment

  • npm: 10.1.0
  • Node.js: 20.5.1
  • OS Name: Mac OS
  • System Model Name: Macbook Pro
  • npm config: n/a as long as ignore-scripts isn't set

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 10.xRelease 9.xwork is associated with a specific npm 9 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions