Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
pkglock: add from field back into git dependencies (#20384)
PR-URL: #20384
Credit: @zkat
Reviewed-By: @iarna
  • Loading branch information
zkat committed Apr 20, 2018
1 parent 833046e commit 820f74ae22b7feb875232d46901cc34e9ba995d6
Showing with 21 additions and 5 deletions.
  1. +3 −0 lib/shrinkwrap.js
  2. +18 −5 test/tap/install-shrinkwrapped-git.js
@@ -113,6 +113,9 @@ function shrinkwrapDeps (deps, top, tree, seen) {
var pkginfo = deps[moduleName(child)] = {}
var requested = child.package._requested || getRequested(child) || {}
pkginfo.version = childVersion(top, child, requested)
if (requested.type === 'git' && child.package._from) {
pkginfo.from = child.package._from
}
if (child.fromBundle || child.isInLink) {
pkginfo.bundled = true
} else {
@@ -1,3 +1,5 @@
'use strict'

var fs = require('fs')
var path = require('path')
var resolve = path.resolve
@@ -47,20 +49,30 @@ test('shrinkwrapped git dependency got updated', function (t) {
t.comment('test for https://github.com/npm/npm/issues/12718')

// Prepare the child package git repo with two commits
prepareChildAndGetRefs(function (refs) {
prepareChildAndGetRefs(function (err, refs) {
if (err) { throw err }
chain([
// Install & shrinkwrap child package's first commit
[npm.commands.install, ['git://localhost:1234/child.git#' + refs[0]]],
// Backup node_modules with the first commit
[fs.rename, parentNodeModulesPath, outdatedNodeModulesPath],
// Install & shrinkwrap child package's second commit
[npm.commands.install, ['git://localhost:1234/child.git#' + refs[1]]],
// Install & shrinkwrap child package's latest commit
[npm.commands.install, ['git://localhost:1234/child.git#' + refs[1].substr(0, 8)]],
// Restore node_modules with the first commit
[rimraf, parentNodeModulesPath],
[fs.rename, outdatedNodeModulesPath, parentNodeModulesPath],
// Update node_modules
[npm.commands.install, []]
], function () {
const pkglock = require(path.join(parentPath, 'package-lock.json'))
t.similar(pkglock, {
dependencies: {
child: {
version: `git://localhost:1234/child.git#${refs[1]}`,
from: `git://localhost:1234/child.git#${refs[1].substr(0, 8)}`
}
}
}, 'version and from fields are correct in git-based pkglock dep')
var childPackageJSON = require(path.join(parentNodeModulesPath, 'child', 'package.json'))
t.equal(
childPackageJSON._resolved,
@@ -114,12 +126,13 @@ function prepareChildAndGetRefs (cb) {
git.chainableExec(['add', 'README.md'], opts),
git.chainableExec(['commit', '-m', 'Add README'], opts),
git.chainableExec(['log', '--pretty=format:"%H"', '-2'], opts)
], function () {
], function (err) {
if (err) { return cb(err) }
var gitLogStdout = arguments[arguments.length - 1]
var refs = gitLogStdout[gitLogStdout.length - 1].split('\n').map(function (ref) {
return ref.match(/^"(.+)"$/)[1]
}).reverse() // Reverse refs order: last, first -> first, last
cb(refs)
cb(null, refs)
})
}

0 comments on commit 820f74a

Please sign in to comment.