Skip to content

Comments

fix(libnpmpack): obey foregroundScripts#5430

Closed
winterqt wants to merge 1 commit intonpm:latestfrom
winterqt:pack-foreground-scripts
Closed

fix(libnpmpack): obey foregroundScripts#5430
winterqt wants to merge 1 commit intonpm:latestfrom
winterqt:pack-foreground-scripts

Conversation

@winterqt
Copy link
Contributor

Before this change, npm pack would not respect --foreground-scripts, so when {pre,post}pack scripts were run, the output would be polluted with output from those scripts.

I'm not sure how I'd test the output of this from libnpmpack tests, like the arborist test does. If anyone can give me any pointers on that, I'd be happy to add a test.

Also: tips on decreasing the length of the commit message are appreciated, the cutoff is a bit jarring.

References

Fixes #4121.

@winterqt winterqt requested a review from a team as a code owner August 26, 2022 18:19
@winterqt
Copy link
Contributor Author

winterqt commented Sep 2, 2022

This is failing due to the reduced test coverage. I can't figure out a way to test this behavior just from using libnpmpack -- I'd have to either spawn a new process or mock spawn.

What's the best way to go about this?

@wraithgar
Copy link
Member

This is failing due to the reduced test coverage. I can't figure out a way to test this behavior just from using libnpmpack -- I'd have to either spawn a new process or mock spawn.

What's the best way to go about this?

While we haven't started using it in this repo, mocking spawn is a thing we do in other npm cli subdependencies, and in the npm tests too. We use https://github.com/wraithgar/spawk. For good patterns you can check out the start stop and test tests in the npm cli itself.

tips on decreasing the length of the commit message are appreciated, the cutoff is a bit jarring.

fix: obey foregroundScript would probably suffice. The commit will only end up in the libnpmpack changelog so you don't really need to add that to the scope.

@winterqt winterqt force-pushed the pack-foreground-scripts branch from 2e45bdd to 16fce25 Compare September 3, 2022 01:02
@winterqt
Copy link
Contributor Author

winterqt commented Sep 3, 2022

@wraithgar I attempted to use spawk here, but am running into an issue. The command and arguments that are passed to spawn line up with what I'm mocking, but it still says that it wasn't called. Am I missing something obvious here?

@winterqt winterqt mentioned this pull request Sep 3, 2022
13 tasks
@winterqt
Copy link
Contributor Author

winterqt commented Sep 4, 2022

It looks like overriding child_process.spawn isn't working here, but I don't know why it would work in the other tests but not this one. (Maybe the package boundary?)

@fritzy fritzy force-pushed the latest branch 2 times, most recently from 3037d35 to f3b0c43 Compare September 14, 2022 23:09
@winterqt
Copy link
Contributor Author

Hey @wraithgar, just bumping this in case you forgot about my last comment :)

@wraithgar
Copy link
Member

I did see it. We are currently focused on breaking changes for npm 9 and there isn't any bandwidth right now for anyone to help you on this. If you can figure the tests out, great. If not, this can wait a bit till someone can look at it.

@winterqt winterqt force-pushed the pack-foreground-scripts branch from 16fce25 to a35ed95 Compare October 3, 2022 01:37
@winterqt winterqt force-pushed the pack-foreground-scripts branch from a35ed95 to d3d7dbc Compare October 3, 2022 01:38
@winterqt winterqt changed the title fix(libnpmpack): run scripts in foreground when foregroundScripts === true fix(libnpmpack): obey foregroundScripts Oct 3, 2022
@winterqt
Copy link
Contributor Author

winterqt commented Oct 3, 2022

I figured it out -- spawk needed to be initialized before everything else was imported. (Technically this would work all the same if I moved it before just a subset of the imports, but I figured this is best.)

@winterqt
Copy link
Contributor Author

winterqt commented Oct 3, 2022

I guess I have to update package-lock.json. Do I just run npm ci to do that properly (so I don't update any other versions in the lockfile), or is there some other way to do it?

@wraithgar
Copy link
Member

How did you add spawk? If you used npm install it should have updated the lockfile accordingly.

@wraithgar
Copy link
Member

npm install -D spawk -ws libnpmpack

@winterqt
Copy link
Contributor Author

winterqt commented Oct 4, 2022

npm install -D spawk -ws libnpmpack

After reverting workspaces/libnpmpack/package.json and DEPENDENCIES.md to their state before this commit, and running this command, I get these errors.

@wraithgar
Copy link
Member

Well fiddlesticks. Good news is you found a case that causes that error to happen so we can debug it now. Bad news is you can't install and update the md file. Go ahead and install with --ignore-scripts which will prevent that script from trying to update the md file. We may have to fix it to get CI to go green but at least you can get everything else about the PR ready to go.

Can you also make sure your branch is rebased against latest? It's possible that some things were moved around since you started. Lots of things have been shuffling as part of npm 9.

@wraithgar
Copy link
Member

@winterqt I am so sorry I told you to run the wrong command. It should be -w not -ws.

@wraithgar
Copy link
Member

I feel really bad about this. You've worked really hard on this PR and I know it's probably frustrating that this is the part we're getting blocked on. The PR itself looks great and once we sort the problem of adding spawk out this will land.

@wraithgar
Copy link
Member

In the interest of getting this out today (release day!) I went ahead and fixed the spawk install in another branch, leaving your work in its own commit: #5645

@wraithgar wraithgar closed this Oct 5, 2022
@winterqt winterqt deleted the pack-foreground-scripts branch October 5, 2022 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] "npm pack" ignores --silent when running "prepack" scripts

2 participants