diff --git a/tools/npm/check-node-modules.js b/tools/npm/check-node-modules.js index bd4cbd9074..2ab8100bb5 100755 --- a/tools/npm/check-node-modules.js +++ b/tools/npm/check-node-modules.js @@ -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;