From 4b1f257e37ebd2bbce58958da9f05befa340fca8 Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Thu, 29 Jan 2015 12:36:50 -0800 Subject: [PATCH] Don't shell out for find --- tools/files.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ tools/meteor-npm.js | 16 +++++++--------- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/tools/files.js b/tools/files.js index e2641377ec..4e29777469 100644 --- a/tools/files.js +++ b/tools/files.js @@ -466,6 +466,51 @@ files.cp_r = function (from, to, options) { }); }; +// Get every path in dir recursively +files.getPathsInDir = function (dir, options) { + if (! files.exists(dir)) { + // There are no paths in this dir, so don't do anything + return; + } + + var oldCwd = process.cwd(); + + var cwd = options && options.cwd; + if (cwd) { + if (! files.exists(cwd)) { + throw new Error("Specified current working directory doesn't exist:" + + cwd); + } + + process.chdir(cwd); + } + + var output = []; + + _.each(files.readdir(dir), function (entry) { + var newPath = files.pathJoin(dir, entry); + output.push(newPath); + + if (files.stat(newPath).isDirectory()) { + output = output.concat(files.getPathsInDir(newPath)); + } + }); + + process.chdir(oldCwd); + + return output; +}; + +files.findPathsWithRegex = function (dir, regex, options) { + var allPaths = files.getPathsInDir(dir, { + cwd: options.cwd + }); + + return _.filter(allPaths, function (path) { + return path.match(regex); + }); +}; + // Copies a file, which is expected to exist. Parent directories of "to" do not // have to exist. Treats symbolic links transparently (copies the contents, not // the link itself, and it's an error if the link doesn't point to a file). diff --git a/tools/meteor-npm.js b/tools/meteor-npm.js index 62c2959dfd..65ff233af7 100644 --- a/tools/meteor-npm.js +++ b/tools/meteor-npm.js @@ -497,17 +497,15 @@ var installNpmModule = function (name, version, dir) { if (process.platform !== "win32") { // If we are on a unixy file system, we should not build a package that // can't be used on Windows. - var output = utils.execFileSync("bash", ["-c", "find . | grep ':'"], - {cwd: files.pathJoin(dir, "node_modules", name)}); - console.log(files.pathJoin(dir, name)); + var pathsWithColons = files.findPathsWithRegex(".", new RegExp(":"), + { cwd: dir }); - if (output.success) { - var lines = output.stdout.split("\n"); - - var firstTen = lines.slice(0, 10); - if (lines.length > 10) { - firstTen.push("... " + (lines.length - 10) + " paths omitted."); + if (pathsWithColons.length) { + var firstTen = pathsWithColons.slice(0, 10); + if (pathsWithColons.length > 10) { + firstTen.push("... " + (pathsWithColons.length - 10) + + " paths omitted."); } buildmessage.error(