-
Notifications
You must be signed in to change notification settings - Fork 27.4k
chore(check-node-modules): make check/reinstall node_modules work across platforms #12792
chore(check-node-modules): make check/reinstall node_modules work across platforms #12792
Conversation
…oss platforms The previous implementations (based on shell scripts) threw errors on Windows, because it was not able to `rm -rf` 'node_modules' (due to the 255 character limit in file-paths). This implementation works consistently across platforms and is heavily based on 'https://github.com/angular/angular/blob/3b9c08676a4c921bbfa847802e08566fb601ba7a/tools/npm/check-node-modules.js'. Fixes angular#11143 Closes angular#11353
This might also be related to #12649. TODO:
|
fs.unlinkSync(curPath); | ||
} | ||
} | ||
} |
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.
Would we care to use rm -rf
on *NIX based systems for performance reasons ?
I didn't bother, because this will be running only rarely and then again npm install
is the main bottleneck.
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.
In the initial discussion, we preferred this. But imo we can see if this works, and then change it back afterwards if it's much slower.
I noticed that this changes the behavior - previously, if there was a mismatch between the current and the cached lock file, it would automatically install, now it only warns It should work with the --reinstall option, but can you actually use this from the grunt level? I tried |
The fact that it doesn't automatically reinstall is a good thing. It gives you a chance to finish what you are doing before wiping out all your node_modules. We should make the force reinstallation process reliable though |
Hmm I'm getting quite a few of these (on Windows): It also takes extremly long. |
Is that the old path too long problem? |
With this PR you force an install by running |
if (nodeModulesOk) { | ||
console.log(':-) npm dependencies are looking good!'); | ||
} else { | ||
console.warn(':-( npm dependencies are stale or in an unknown state!'); |
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.
We ought to make this BIGGER and add a message about how to fix it. Something like:
console.warn('=====================================================================');
console.warn(':-( npm dependencies are stale or in an unknown state!');
console.warn('You can rebuild the dependencies by running `node scripts/npm/check-node-modules.js --reinstall`');
console.warn('=====================================================================');
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.
Very good idea!
It is working well on my Mac |
Strange, Now it finally uninstalled everything and installed. I got this:
But I still get modules are stale error. |
I think this is because, if |
Trying on windows 10 |
Still waiting ... |
I just got the same maxBuffer exception. Will look into this tomorrow. |
I've also got the buffer thing again. This time I've tried with admin rights, and that fixed the purge errors. Btw, they are actually different than path too long errors, it's probably some process holding on to the file. But if it works as admin, it's fine by me. |
I have been looking at the Angular 2 version. They don't bother trying to run |
I tried it a few times on Windows 10 and never got that maxBuffer error. (But it is indeed too slow; it's BTW (as I'm sure you've already figured out :)), if you uncomment line 125 and line 126 you get to see the stdout and stderr of Could that also help with the
@petebacondarwin, you mean you like it as a convenience if you want to update the dependencies ? |
There are two benefits.
|
Agreed :) So, I will make the following changes:
|
Perfick! |
Changes: 1. Make warning about stale dependencies stand out. 2. Check 'node_modules/' and purge at `preinstall` phase. 3. Copy 'npm-shrinkwrap.json' at `postinstall` phase. 4. Just run `npm install` to install dependencies (e.g. in '.travis.yml').
Added a 2nd (squashable upon merging) commit with the aforementioned changes. Unfortunately, I am getting errors when purging from
> angularjs@ preinstall C:\...\angular.js
> node scripts/npm/check-node-modules.js --purge
:-( npm dependencies are stale or in an unknown state!
Purging 'node_modules'...
C:\...\angular.js\scripts\npm\check-node-modules.js:0
(function (exports, require, module, __filename, __dirname) { // Implementatio
^
Error: ENOTEMPTY, directory not empty 'C:\...\angular.js\node_modules\karma\node_modules\chokidar\node_modules'
at Error (native)
at Object.fs.rmdirSync (fs.js:711:18)
at deleteDirSync (C:\...\angular.js\scripts\npm\check-node-modules.js:61:8)
at deleteDirOrFileSync (C:\...\angular.js\scripts\npm\check-node-modules.js:69:7)
at Array.forEach (native)
at deleteDirSync (C:\...\angular.js\scripts\npm\check-node-modules.js:60:26)
at deleteDirOrFileSync (C:\...\angular.js\scripts\npm\check-node-modules.js:69:7)
at Array.forEach (native)
at deleteDirSync (C:\...\angular.js\scripts\npm\check-node-modules.js:60:26)
at deleteDirOrFileSync (C:\...\angular.js\scripts\npm\check-node-modules.js:69:7)
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v0.12.7
npm ERR! npm v2.11.3
npm ERR! code ELIFECYCLE
npm ERR! angularjs@ preinstall: `node scripts/npm/check-node-modules.js --purge`
npm ERR! Exit status 1
... It fails consistently, but on a different directory each time. |
I had this error yesterday. Have you tdied running the cmd prompt / shell as admin |
Well, I tried it again today (with user rights - no admin) and it worked like a charm !? /cc @Narretz , @petebacondarwin |
I think we should merge it and see if it causes any issues / makes it better on Windows. |
I agree. Let's merge this. |
Woohoo! |
Can we cherry pick it to 1.3 and 1.4 too @gkalpak ? |
I guess we could (since it only touches "chore" stuff). |
Go for it. I have only seen it fail on windows. And since even that is intermittent, it is better than we have right now. |
…oss platforms The previous implementations (based on shell scripts) threw errors on Windows, because it was not able to `rm -rf` 'node_modules' (due to the 255 character limit in file-paths). This implementation works consistently across platforms and is heavily based on 'https://github.com/angular/angular/blob/3b9c08676a4c921bbfa847802e08566fb601ba7a/tools/npm/check-node-modules.js'. Fixes #11143 Closes #11353 Closes #12792
…oss platforms The previous implementations (based on shell scripts) threw errors on Windows, because it was not able to `rm -rf` 'node_modules' (due to the 255 character limit in file-paths). This implementation works consistently across platforms and is heavily based on 'https://github.com/angular/angular/blob/3b9c08676a4c921bbfa847802e08566fb601ba7a/tools/npm/check-node-modules.js'. Fixes #11143 Closes #11353 Closes #12792
Smashing! |
The previous implementations (based on shell scripts) threw errors on Windows, because it was not able to
rm -rf
'node_modules' (due to the 255 character limit in file-paths).This implementation works consistently across platforms and is heavily based on 'https://github.com/angular/angular/blob/3b9c08676a4c921bbfa847802e08566fb601ba7a/tools/npm/check-node-modules.js'.
Fixes #11143
Closes #11353