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.
This commit is contained in:
Igor Minar 2015-07-01 09:19:03 -07:00
parent f020a5cdea
commit c2c361efcf
1 changed files with 21 additions and 3 deletions

View File

@ -22,9 +22,7 @@ function checkNodeModules(logOutput, purgeIfStale) {
var nodeModulesPath = path.join(PROJECT_ROOT, 'node_modules');
if (fs.existsSync(nodeModulesPath)) {
// lazy-load fs-extra
var fse = require('fs-extra');
fse.removeSync(nodeModulesPath);
_deleteDir(nodeModulesPath);
}
}
}
@ -47,4 +45,24 @@ function _checkCache(markerFile, cacheMarkerFile) {
}
/**
* Custom implementation of recursive `rm` because we can't rely on the state of node_modules to
* pull in existing module.
*/
function _deleteDir(path) {
if( fs.existsSync(path) ) {
var subpaths = fs.readdirSync(path);
subpaths.forEach(function(subpath) {
var curPath = path + "/" + subpath;
if(fs.lstatSync(curPath).isDirectory()) {
_deleteDir(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}
module.exports = checkNodeModules;