From c2c361efcf8b9aa6733ae0822864f92e84873e24 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 1 Jul 2015 09:19:03 -0700 Subject: [PATCH] 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. --- tools/npm/check-node-modules.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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;