From 101d2477698bef77cfce6f0ed686acba99a3e574 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Wed, 1 Aug 2018 23:06:56 -0700 Subject: [PATCH 1/6] inflate-shrinkwrap: Insure modules deep in a linked tree are isInLink Fixes: https://npm.community/t/npm-install-for-package-with-local-dependency-fails/754 Credit: @iarna Credit: @jhecking --- lib/install/inflate-shrinkwrap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/install/inflate-shrinkwrap.js b/lib/install/inflate-shrinkwrap.js index bf1ab7065724c..395cc11191309 100644 --- a/lib/install/inflate-shrinkwrap.js +++ b/lib/install/inflate-shrinkwrap.js @@ -177,7 +177,7 @@ function makeFakeChild (name, topPath, tree, sw, requested) { realpath: requested.type === 'directory' ? requested.fetchSpec : childPath(tree.realpath, pkg), location: (tree.location === '/' ? '' : tree.location + '/') + pkg.name, isLink: requested.type === 'directory', - isInLink: tree.isLink, + isInLink: tree.isLink || tree.isInLink, swRequires: sw.requires }) tree.children.push(child) From 381c55e2781884ed4fd9e3d1aa6f11ce262b1c31 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Wed, 1 Aug 2018 23:42:14 -0700 Subject: [PATCH 2/6] shrinkwrap: Don't iterate into linked deps --- lib/shrinkwrap.js | 5 ++++- test/tap/spec-local-specifiers.js | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/shrinkwrap.js b/lib/shrinkwrap.js index 90a4426523cab..80e4cd17955d0 100644 --- a/lib/shrinkwrap.js +++ b/lib/shrinkwrap.js @@ -110,6 +110,8 @@ function shrinkwrapDeps (deps, top, tree, seen) { var childIsOnlyDev = isOnlyDev(child) var pkginfo = deps[moduleName(child)] = {} var requested = getRequested(child) || child.package._requested || {} + var linked = child.isLink || child.isInLInk + var linkedFromHere = linked && path.relative(top.realpath, child.realpath)[0] !== '.' pkginfo.version = childVersion(top, child, requested) if (requested.type === 'git' && child.package._from) { pkginfo.from = child.package._from @@ -139,7 +141,8 @@ function shrinkwrapDeps (deps, top, tree, seen) { pkginfo.requires[moduleName(required)] = childRequested(top, required, requested) }) } - if (child.children.length) { + // only iterate into links when they're + if (child.children.length && (!child.isLink || linkedFromHere)) { pkginfo.dependencies = {} shrinkwrapDeps(pkginfo.dependencies, top, child, seen) } diff --git a/test/tap/spec-local-specifiers.js b/test/tap/spec-local-specifiers.js index d149b7ea0ea3a..3601eee5f3c5f 100644 --- a/test/tap/spec-local-specifiers.js +++ b/test/tap/spec-local-specifiers.js @@ -585,9 +585,7 @@ test('save behavior', function (t) { var deps = pjson.dependencies || {} t.is(deps['sb-transitive'], 'file:../sb-transitive', 'package.json') var sdep = shrinkwrap.dependencies['sb-transitive'] || {} - var tdep = sdep.dependencies.sbta - t.like(tdep, {bundled: true, version: 'file:../sb-transitive/sbta'}, 'npm-shrinkwrap.json transitive dep') - t.like(sdep, {bundled: null, version: 'file:../sb-transitive'}, 'npm-shrinkwrap.json direct dep') + t.like(sdep, {bundled: null, dependencies: null, version: 'file:../sb-transitive'}, 'npm-shrinkwrap.json direct dep') t.done() }) }) From 76a368c9377aaad34f59750d6ba0137a2778f0db Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Wed, 1 Aug 2018 23:41:48 -0700 Subject: [PATCH 3/6] shrinkwrap: Don't record linked deps as bundled --- lib/shrinkwrap.js | 4 ++-- test/tap/shrinkwrap-local-dependency.js | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/shrinkwrap.js b/lib/shrinkwrap.js index 80e4cd17955d0..f860c23df760e 100644 --- a/lib/shrinkwrap.js +++ b/lib/shrinkwrap.js @@ -116,7 +116,7 @@ function shrinkwrapDeps (deps, top, tree, seen) { if (requested.type === 'git' && child.package._from) { pkginfo.from = child.package._from } - if (child.fromBundle || child.isInLink) { + if (child.fromBundle && !linked) { pkginfo.bundled = true } else { if (isRegistry(requested)) { @@ -141,7 +141,7 @@ function shrinkwrapDeps (deps, top, tree, seen) { pkginfo.requires[moduleName(required)] = childRequested(top, required, requested) }) } - // only iterate into links when they're + // iterate into children on non-links and links contained within the top level package if (child.children.length && (!child.isLink || linkedFromHere)) { pkginfo.dependencies = {} shrinkwrapDeps(pkginfo.dependencies, top, child, seen) diff --git a/test/tap/shrinkwrap-local-dependency.js b/test/tap/shrinkwrap-local-dependency.js index 58974ad72431a..d1c33b99a5a0b 100644 --- a/test/tap/shrinkwrap-local-dependency.js +++ b/test/tap/shrinkwrap-local-dependency.js @@ -20,8 +20,7 @@ var shrinkwrap = { version: 'file:' + unixFormatPath(path.join('mods', 'mod2')), dependencies: { mod1: { - version: 'file:' + unixFormatPath(path.join('mods', 'mod1')), - bundled: true + version: 'file:' + unixFormatPath(path.join('mods', 'mod1')) } } } From c3a0ec1096c36bb4fa83d21fa1c567c91d300fda Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Tue, 11 Sep 2018 15:19:49 -0700 Subject: [PATCH 4/6] Update shrinkwrap.js --- lib/shrinkwrap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shrinkwrap.js b/lib/shrinkwrap.js index f860c23df760e..5495892a25afb 100644 --- a/lib/shrinkwrap.js +++ b/lib/shrinkwrap.js @@ -110,7 +110,7 @@ function shrinkwrapDeps (deps, top, tree, seen) { var childIsOnlyDev = isOnlyDev(child) var pkginfo = deps[moduleName(child)] = {} var requested = getRequested(child) || child.package._requested || {} - var linked = child.isLink || child.isInLInk + var linked = child.isLink || child.isInLink var linkedFromHere = linked && path.relative(top.realpath, child.realpath)[0] !== '.' pkginfo.version = childVersion(top, child, requested) if (requested.type === 'git' && child.package._from) { From 52b5011d91e0e98ccdd10ab3063a2837d35dfadd Mon Sep 17 00:00:00 2001 From: JT Turner Date: Thu, 25 Oct 2018 15:00:50 -0700 Subject: [PATCH 5/6] tests: add tests for sub path local installs --- .gitignore | 1 + test/tap/install-at-sub-path-locally.js | 69 +++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 test/tap/install-at-sub-path-locally.js diff --git a/.gitignore b/.gitignore index 065c0438da279..68d4dd36d2d3d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ npm-debug.log /test/*/*/node_modules /test/packages/npm-test-depends-on-spark/which-spark.log /test/packages/test-package/random-data.txt +/test/npm_cache /test/root /node_modules/.bin /html/doc/ diff --git a/test/tap/install-at-sub-path-locally.js b/test/tap/install-at-sub-path-locally.js new file mode 100644 index 0000000000000..e16b75179ebaf --- /dev/null +++ b/test/tap/install-at-sub-path-locally.js @@ -0,0 +1,69 @@ +var fs = require('graceful-fs') +var path = require('path') + +var mkdirp = require('mkdirp') +var osenv = require('osenv') +var rimraf = require('rimraf') +var test = require('tap').test + +var common = require('../common-tap.js') + +var pkg = path.join(__dirname, 'install-at-sub-path-locally') + +var EXEC_OPTS = { cwd: pkg, stdio: [0, 1, 2] } + +var json = { + name: 'install-at-sub-path-locally-mock', + version: '0.0.0' +} + +var target = '../package@1.2.3' + +test('setup', function (t) { + cleanup() + t.end() +}) + +test('\'npm install ../package@1.2.3\' should install local pkg from sub path', function (t) { + setup() + common.npm(['install', '--loglevel=silent', target], EXEC_OPTS, function (err, code) { + if (err) throw err + var p = path.resolve(pkg, 'node_modules/install-at-sub-path-locally-mock/package.json') + t.equal(code, 0, 'npm install exited with code') + t.ok(JSON.parse(fs.readFileSync(p, 'utf8'))) + t.end() + }) +}) + +test('\'running npm install ../package@1.2.3\' should not break on sub path re-install', function (t) { + common.npm(['install', '--loglevel=silent', target], EXEC_OPTS, function (err, code) { + if (err) throw err + var p = path.resolve(pkg, 'node_modules/install-at-sub-path-locally-mock/package.json') + t.equal(code, 0, 'npm install exited with code') + t.ok(JSON.parse(fs.readFileSync(p, 'utf8'))) + t.end() + }) +}) + +test('cleanup', function (t) { + cleanup() + t.end() +}) + +function cleanup () { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) + rimraf.sync(path.resolve(pkg, target)) +} + +function setup () { + cleanup() + var root = path.resolve(pkg, target) + mkdirp.sync(root) + fs.writeFileSync( + path.join(root, 'package.json'), + JSON.stringify(json, null, 2) + ) + mkdirp.sync(path.resolve(pkg, 'node_modules')) + process.chdir(pkg) +} From f32221e7208e3a52219f58a4b31f54d371090073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 14 Jan 2019 14:43:02 -0800 Subject: [PATCH 6/6] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 68d4dd36d2d3d..065c0438da279 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ npm-debug.log /test/*/*/node_modules /test/packages/npm-test-depends-on-spark/which-spark.log /test/packages/test-package/random-data.txt -/test/npm_cache /test/root /node_modules/.bin /html/doc/