Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove broken guard #6

Merged
merged 2 commits into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,20 @@ 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;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoGoCarl in what circumstances did you find this to be necessary when you added this in #5? As far as I can tell it's always true in both npm 2 and 3 as I describe here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a bug; the change you made what was intended!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wearhere Actually, sorry about the previous comment. I meant I would have wanted to check target.match(...). My intentions here were to catch a case where the project that hosts the shared files runs npm install. In this case, the process was running against itself, which was not ideal (but in thinking about it now, in some scenarios, this could be necessary). I would say a better cross-version solution here would be to check to see if the source and the target package names are the same, and reject if that is the case. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a better cross-version solution here would be to check to see if the source and the target package names are the same, and reject if that is the case

Yeah that sounds like it could work!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking this bug here #8


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;
Expand Down
10 changes: 5 additions & 5 deletions src/npm-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -25,4 +25,4 @@ function getMajorVersion() {
module.exports = {
version: getVersion,
majorVersion: getMajorVersion
}
};