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

fix: added check for dry-run #7274

Merged
merged 2 commits into from Mar 13, 2024
Merged

fix: added check for dry-run #7274

merged 2 commits into from Mar 13, 2024

Conversation

cod1r
Copy link
Contributor

@cod1r cod1r commented Mar 9, 2024

added a check for dry-run for npm ci so that node_modules won't be deleted.

npm ci --dry-run currently removes the node_modules folder even though the docs say that dry-run, "Indicates that you don't want npm to make any changes and that it should only report what it would have done".

This commit adds a check for dryRun in the npm.flatOptions object which will be true if --dry-run is added on the cli or if dry-run=true is set in .npmrc

closes #7239

  added a check for dry-run for `npm ci` so that node_modules won't be
  deleted

  closes npm#7239
@cod1r cod1r requested a review from a team as a code owner March 9, 2024 19:34
Comment on lines 78 to 87
if (!this.npm.flatOptions.dryRun) {
// Only remove node_modules after we've successfully loaded the virtual
// tree and validated the lockfile
await this.npm.time('npm-ci:rm', async () => {
const path = `${where}/node_modules`
// get the list of entries so we can skip the glob for performance
const entries = await fs.readdir(path, null).catch(er => [])
return Promise.all(entries.map(f => fs.rm(`${path}/${f}`, { force: true, recursive: true })))
})
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it'd be better if, when a dry run, it checked that npm has permissions to rimraf node_modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what you mean by 'permissions'. Sorry this is my first time contributing to npm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't checking for any permissions before so I am confused.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right, but i meant it’d be useful and match the “dry run” semantics

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking permissions in node is mostly done by trying the operation and then reporting to the user if it failed. It's even discouraged for things like fs.access to be used for this purpose. With that in mind I think it's fine for dry-run to simply tell the user what it would try to do. It is not meant to be a test of if npm will eventually be able to succeed. Many other things could go wrong (i.e. running out of disk space).

This PR appears fine as-is (I am not done fully reviewing it but at a glance it appears mostly on the right track).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presumably deleting files wouldn't cause disk space to run out :-)

def that enhancement could be done as a follow through regardless

@wraithgar
Copy link
Member

I don't know if this is a problem for this PR to solve, but technically this dry run is meaningless because Arborist isn't being presented with the same scenario as a true ci run. So the summary output is very wrong.

This doesn't feel like a blocker, as this is better than before.

Copy link
Contributor

@jumoel jumoel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great, thanks for fixing it!

@jumoel jumoel merged commit bdb3c28 into npm:latest Mar 13, 2024
20 checks passed
@github-actions github-actions bot mentioned this pull request Mar 13, 2024
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 ci --dry-run deletes node_modules folders
4 participants