From a605586df134ee97c95f89c4b4bd6bc73f7aa439 Mon Sep 17 00:00:00 2001 From: Martin von Gagern Date: Fri, 8 Jan 2016 21:24:21 +0100 Subject: [PATCH] save: Use rawSpec when saving git-type specifiers Since npm-package-arg strips a preceding `git+` from urls, and the stripped urls will cause trouble when loading the package the next time, we have to make sure that in this case at least we save the rawSpec not the spec. PR-URL: https://github.com/npm/npm/pull/11091 Fixes: #9679 Credit: @gagern Reviewed-By: @othiym23 Reviewed-By: @iarna --- lib/install/save.js | 4 +++- test/tap/add-remote-git-file.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/install/save.js b/lib/install/save.js index efe0e20ad7c..acbe8c5bb35 100644 --- a/lib/install/save.js +++ b/lib/install/save.js @@ -180,8 +180,10 @@ function computeVersionSpec (child) { pathname: relativePath }) } - } else { + } else if (requested.type === 'hosted') { return requested.spec + } else { + return requested.rawSpec } } diff --git a/test/tap/add-remote-git-file.js b/test/tap/add-remote-git-file.js index 673be4c2854..eff4a62e2ff 100644 --- a/test/tap/add-remote-git-file.js +++ b/test/tap/add-remote-git-file.js @@ -45,6 +45,29 @@ test('cache from repo', function (t) { }) }) +test('save install', function (t) { + process.chdir(pkg) + fs.writeFileSync('package.json', JSON.stringify({ + name: 'parent', + version: '5.4.3' + }, null, 2) + '\n') + var prev = npm.config.get('save') + npm.config.set('save', true) + npm.commands.install('.', [cloneURL], function (er) { + npm.config.set('save', prev) + t.ifError(er, 'npm installed via git') + var pj = JSON.parse(fs.readFileSync('package.json', 'utf-8')) + var dep = pj.dependencies.child + t.equal( + url.parse(dep).protocol, + 'git+file:', + 'npm didn\'t strip the git+ from git+file://' + ) + + t.end() + }) +}) + test('clean', function (t) { cleanup() t.end()