From 7e380d428216292ca50c792ec02d99f165f25be1 Mon Sep 17 00:00:00 2001 From: Jeff Wear Date: Tue, 14 Feb 2017 16:36:01 -0800 Subject: [PATCH 1/2] Fix JSHint warnings --- src/index.js | 8 +++++--- src/npm-version.js | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 3580668..fb71c4b 100644 --- a/src/index.js +++ b/src/index.js @@ -37,19 +37,21 @@ function installFiles(sourceDir, done) { switch (npmv.majorVersion()) { case '1': console.log("[install-files]: WARNING: NPMv1 is not officially supported; unexpected results could occur. Consider upgrading to v2 or later"); + /* falls through */ case '2': source = sourceDir; target = fileInstallingPackagePath && hostPackageDir(fileInstallingPackagePath); break; case null: - console.log("[install-files]: WARNING: Could not determine NPM version"); //Fall back to default + console.log("[install-files]: WARNING: Could not determine NPM version"); + /* falls through */ default: source = path.join(fileInstallingPackagePath, 'node_modules', process.env.npm_package_name, sourceDir); - target = fileInstallingPackagePath + target = fileInstallingPackagePath; } if (fileInstallingPackagePath.match(".+" + process.env.npm_package_name + "$")) { - console.log("[install-files]: Target = self, skipping install") + console.log("[install-files]: Target = self, skipping install"); process.nextTick(() => done()); return; } else if (!target) { diff --git a/src/npm-version.js b/src/npm-version.js index 668b5b2..aad6d3f 100644 --- a/src/npm-version.js +++ b/src/npm-version.js @@ -4,12 +4,12 @@ * @return {String} - The full version as a string, or undefined if not available */ function getVersion() { - var version = undefined; + var version; if (process.env.npm_config_user_agent && process.env.npm_config_user_agent.match(/.*npm\/.+/)) { - var agent = process.env.npm_config_user_agent.split(' ') + var agent = process.env.npm_config_user_agent.split(' '); for (var token of agent) { - if (token.indexOf('npm/') == 0) { - version = token.split('/')[1] + if (token.indexOf('npm/') === 0) { + version = token.split('/')[1]; break; } } @@ -25,4 +25,4 @@ function getMajorVersion() { module.exports = { version: getVersion, majorVersion: getMajorVersion -} +}; From 60a96146f85ccd55876a79487f983f9529aace93 Mon Sep 17 00:00:00 2001 From: Jeff Wear Date: Tue, 14 Feb 2017 16:37:51 -0800 Subject: [PATCH 2/2] Remove broken guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As far as I can tell that `if` statement is _always_ true, since `fileInstallingPath` is the path to the package running the ‘install’ or ‘postInstall’ script, which is the package being installed—which is what `$npm_package_name` refers to. --- src/index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index fb71c4b..884f65b 100644 --- a/src/index.js +++ b/src/index.js @@ -50,11 +50,7 @@ function installFiles(sourceDir, done) { target = fileInstallingPackagePath; } - if (fileInstallingPackagePath.match(".+" + process.env.npm_package_name + "$")) { - console.log("[install-files]: Target = self, skipping install"); - process.nextTick(() => done()); - return; - } else if (!target) { + if (!target) { var error2 = new Error('Could not determine the install destination directory.'); process.nextTick(() => done(error2)); return;