-
Notifications
You must be signed in to change notification settings - Fork 43
delete contents of node_modules but keep the dir itself #47
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a reasonable enough idea! Thanks for this patch! I've made a comment about the change itself, and I'm wondering if you could make the patch even better by writing a test that verifies this?
index.js
Outdated
@@ -120,7 +121,9 @@ class Installer { | |||
) | |||
return BB.join( | |||
this.checkLock(), | |||
stat && rimraf(path.join(this.prefix, 'node_modules')) | |||
stat && readdirAsync(path.join(this.prefix, 'node_modules')).then(children => | |||
BB.join(children.map(child => rimraf(path.join(this.prefix, 'node_modules', child)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want this to be BB.all() instead, since that's the one that awaits an array of promises.
There's also an alternative implementation you can do: since rimraf
supports glob
out of the box, rimraf('foo/*')
should delete the contents of foo without removing the directory itself. It might be slightly easier to read the code that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the suggestion!
This should fix npm/npm#21007 |
@tareqhs @zkat Added test, created PR into original fork: tareksha#1 |
Add test to make sure that node_modules/ folder is not deleted
thanks for the tests @surgeboris ! |
Came here to make this PR, and its already here, awesome! To add to case for this change, I'm building a docker image, where I have created the RUN mkdir /srv/project/node_modules \
&& chown -R node /srv/project/node_modules
USER node
RUN npm ci |
Hi, came here just to indicate I reported the same need on our side here : https://npm.community/t/running-npm-ci-without-deleting-old-node-modules-folder-20104/3152. In our case we cannot remove the Other posts about this subject :
So I agree with this PR 👍 and wait it to be merged and integrated inside npm / cli. Thanks, Baptiste |
Hi @zkat , any progress here ? |
@zkat a gentle reminder - you are completely ignoring this PR :) |
Would be great to see it in npm, have issues described above, so can't use npm ci at all. |
@lnikell the authors are completely ignoring this PR although many devs need the fix |
@tareqhs that's very sad, at least I would like to hear some feedback even if it "you should not use it like this, that's why script deletes the whole folder" |
Any update on this? While mounting node_modules as docker volume. npm ci is crashing saying: resource is busy while deleting node_modules folder. |
Hello there, any update on this? |
With the new vscode support for devcontainers this fix has become more urgent. Right now the examples use a full install rather than a "ci" after setting up the container: https://github.com/microsoft/vscode-remote-try-node/blob/master/.devcontainer/devcontainer.json#L8 |
ping |
Out team could really do with this fix for our containerised build too please. |
Any update on this? |
Please file this PR over at https://github.com/npm/libcipm, as this repo is no longer in use, and I am no longer employed at NPM |
Keep
node_modules
directory but delete its contents.In some CI setups
node_modules
is a special directory, e.g. a mounted folder or a symbolic link. For these setups simply deletingnode_modules
won't work, or worse will work but break the CI setup. Deletingnode_modules
is a also a non-trivial deviation from the expected behavior ofnpm install
which means the existing CI setups that are explained above are blocked from migrating tonpm ci
.npm ci
should minimize violent changes and concentrate on the fact we want to reset the installed dependencies and proceed with the regular flow. Keepnode_modules
untouched, doesn't matter how it was created.