Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] postpack script runs BEFORE the tarball has been generated and moved to its final destination. #2220

Closed
palavrov opened this issue Nov 22, 2020 · 8 comments
Assignees
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 7.x work is associated with a specific npm 7 release

Comments

@palavrov
Copy link

Current Behavior:

postpack script runs BEFORE the tarball has been generated and moved to its final destination.

Expected Behavior:

As is in the documentation:

Runs AFTER the tarball has been generated and moved to its final destination.

Steps To Reproduce:

copy this package.json to an empty directory

{
  "name": "postpacktest",
  "version": "1.0.0",
  "scripts": {
    "prepack": "rm postpacktest-1.0.0.tgz",
    "postpack": "ls -al"
  }
}

run:
npm pack
and then
ls -al

Environment:

*nix

@palavrov palavrov added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Nov 22, 2020
@nlf
Copy link
Contributor

nlf commented Nov 23, 2020

what version of node? what version of npm? some key pieces of our issue template are missing here, but I'm unable to reproduce this in npm@7.0.13

@nlf nlf self-assigned this Nov 23, 2020
@palavrov
Copy link
Author

$ node --version
v15.1.0

$ npm --version
7.0.8

If you check the source will see that, libnpmpack is called here:

const tarballData = await libpack(arg, opts)

which calls post pack life cycle script here:
https://github.com/npm/libnpmpack/blob/c4f8b823e9f206113bef3e59419f7aa93c619acb/index.js#L33
and then the file will be written here:
await writeFile(filename, tarballData)

@nlf
Copy link
Contributor

nlf commented Nov 23, 2020

indeed! good find, thanks for reporting it!

@nlf nlf removed the Needs Triage needs review for next steps label Nov 23, 2020
@palavrov
Copy link
Author

IMHO one easy fix will be to conditionally of dryrun pass the output path to the libnpmpack method as parameter so it could write the file if the path is not null/undefined between the pre and post pack life cycle scripts execution.

@palavrov
Copy link
Author

BTW publish command suffer from the same problem as it doesn't rely on the pack command but call libnpmpack directly and if I'm not wrong it doesn't write the .tgz file on the disk at all.

Which is another problem as it breaks my postpack hooks to cleanup package.json content on pack and publish - the only way was to pipe the .tgz archive on postpack.

@wraithgar wraithgar added the Priority 1 high priority issue label Jul 1, 2021
@flavioleggio
Copy link

Still not working on node v16.13.0.
Any updates?

@martin770
Copy link

I updated my project from npm 6.14.13 (node.js 14.17.1) to npm 8.4.1 (node.js 16.13.2), and am also running into this issue. I have a 'prepack' script to run eslint and unit tests, and I have a 'postpack' script to move the packaged tarball into a different folder. After upgrading npm and running npm pack, my postpack script fails to move the .tgz file because it has not yet been created when the postpack step triggers. If I comment out the code in my postpack script, I can see my script run and THEN the tarball is created.

According to the npm documentation
postpack: Runs AFTER the tarball has been generated but before it is moved to its final destination (if at all, publish does not save the tarball locally)

@nlf
Copy link
Contributor

nlf commented Feb 10, 2022

this is fixed in npm@8.5.0, which was just published today. thanks for your patience on this one folks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

5 participants