Skip to content

Commit c2c361e

Browse files
committed
build(npm): don't rely on fs-extra when purging node_modules
Travis creates an empty node_modules directory when the cache is empty which confuses our current script into thinking that it's ok to require fs-extra. While this is rare, it's better not to depend on anything in node_modules when purging it, so I reimplemented recorsive delete that we use to purse node_modules.
1 parent f020a5c commit c2c361e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

tools/npm/check-node-modules.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ function checkNodeModules(logOutput, purgeIfStale) {
2222
var nodeModulesPath = path.join(PROJECT_ROOT, 'node_modules');
2323

2424
if (fs.existsSync(nodeModulesPath)) {
25-
// lazy-load fs-extra
26-
var fse = require('fs-extra');
27-
fse.removeSync(nodeModulesPath);
25+
_deleteDir(nodeModulesPath);
2826
}
2927
}
3028
}
@@ -47,4 +45,24 @@ function _checkCache(markerFile, cacheMarkerFile) {
4745
}
4846

4947

48+
/**
49+
* Custom implementation of recursive `rm` because we can't rely on the state of node_modules to
50+
* pull in existing module.
51+
*/
52+
function _deleteDir(path) {
53+
if( fs.existsSync(path) ) {
54+
var subpaths = fs.readdirSync(path);
55+
subpaths.forEach(function(subpath) {
56+
var curPath = path + "/" + subpath;
57+
if(fs.lstatSync(curPath).isDirectory()) {
58+
_deleteDir(curPath);
59+
} else {
60+
fs.unlinkSync(curPath);
61+
}
62+
});
63+
fs.rmdirSync(path);
64+
}
65+
}
66+
67+
5068
module.exports = checkNodeModules;

0 commit comments

Comments
 (0)