Skip to content

Commit

Permalink
save: Use rawSpec when saving git-type specifiers
Browse files Browse the repository at this point in the history
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: npm#11091
Fixes: npm#9679
Credit: @gagern
Reviewed-By: @othiym23
Reviewed-By: @iarna
  • Loading branch information
gagern authored and iarna committed Jan 28, 2016
1 parent bbdc700 commit a605586
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/install/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ function computeVersionSpec (child) {
pathname: relativePath
})
}
} else {
} else if (requested.type === 'hosted') {
return requested.spec
} else {
return requested.rawSpec
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/tap/add-remote-git-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a605586

Please sign in to comment.