diff options
author | Rebecca Turner <me@re-becca.org> | 2015-08-14 09:49:54 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-08-21 22:30:51 +0300 |
commit | d395a6b8767853eede6ad4502266ac99504f51a8 (patch) | |
tree | fb8342416ab11abb720750fcada1b57104da4d26 /test | |
parent | d119ea67804e4bd2ea00025bd1d779cf7ec8ca18 (diff) |
diff-trees: Make install order more consistent for directly dependencies
The install order is determined by:
1) The location of the thing to be installed relative to the root module.
2) Dependency order, such that a -> b -> c will install modules as: c, b, a
1 is deterministic, regardless of what's being installed.
But 2 can change the order of things higher in the dep tree. Eg, b, or a
might get sorted earlier if c requires them. This mostly doesn't matter,
but it does mean that if you have two modules with conflicting bins, they
_can_ get installed in different orders. This changes sorts all of the top
level modules to be LAST, in location order (1), and then sorts all the rest
per (2). This ensures that top level modules have a deterministic install
order. (Non top level modules can't have bin conflicts as that's treated
the same as a version conflict and the conflicting module would be hoisted.)
PR-URL: https://github.com/npm/npm/pull/9274
Fixes: #8995
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/dedupe-scoped.js | 4 | ||||
-rw-r--r-- | test/tap/install-order.js | 37 |
2 files changed, 39 insertions, 2 deletions
diff --git a/test/tap/dedupe-scoped.js b/test/tap/dedupe-scoped.js index 27e27d39d..bc352356d 100644 --- a/test/tap/dedupe-scoped.js +++ b/test/tap/dedupe-scoped.js @@ -12,10 +12,10 @@ var modules = join(pkg, 'node_modules') var EXEC_OPTS = { cwd: pkg } var body = function () {/* -- @scope/shared@2.1.6 node_modules/second/node_modules/@scope/shared @scope/shared@2.1.6 node_modules/first/node_modules/@scope/shared -> node_modules/@scope/shared -secondUnique@1.2.0 node_modules/second/node_modules/secondUnique -> node_modules/secondUnique firstUnique@0.6.0 node_modules/first/node_modules/firstUnique -> node_modules/firstUnique +secondUnique@1.2.0 node_modules/second/node_modules/secondUnique -> node_modules/secondUnique +- @scope/shared@2.1.6 node_modules/second/node_modules/@scope/shared */}.toString().split('\n').slice(1, -1) var deduper = { diff --git a/test/tap/install-order.js b/test/tap/install-order.js new file mode 100644 index 000000000..c1c4e9dca --- /dev/null +++ b/test/tap/install-order.js @@ -0,0 +1,37 @@ +'use strict' +var test = require('tap').test +var sortActions = require('../../lib/install/diff-trees.js').sortActions + +var a = { + package: {_location: '/a', _requiredBy: []} +} +var b = { + package: {_location: '/b', _requiredBy: []} +} +var c = { + package: {_location: '/c', _requiredBy: ['/a', '/b']} +} + +test('install-order when installing deps', function (t) { + var plain = [ + ['add', a], + ['add', b], + ['add', c]] + var sorted = [ + ['add', c], + ['add', a], + ['add', b]] + t.isDeeply(sortActions(plain), sorted) + t.end() +}) + +test('install-order when not installing deps', function (t) { + var plain = [ + ['add', a], + ['add', b]] + var sorted = [ + ['add', a], + ['add', b]] + t.isDeeply(sortActions(plain), sorted) + t.end() +}) |