| 1 |
const t = require('tap') |
| 2 |
const PlaceDep = require('../lib/place-dep.js') |
| 3 |
const { KEEP } = require('../lib/can-place-dep.js') |
| 4 |
|
| 5 |
// for diffing trees when we place something |
| 6 |
const { strict } = require('tcompare') |
| 7 |
|
| 8 |
const { normalizePaths } = require('./fixtures/utils.js') |
| 9 |
|
| 10 |
const Node = require('../lib/node.js') |
| 11 |
const Link = require('../lib/link.js') |
| 12 |
const OverrideSet = require('../lib/override-set.js') |
| 13 |
|
| 14 |
t.test('placement tests', t => { |
| 15 |
const path = '/some/path' |
| 16 |
|
| 17 |
// boilerplate so we can define a bunch of test cases declaratively |
| 18 |
const runTest = (desc, options) => { |
| 19 |
const { |
| 20 |
// the tree we're placing a dep within |
| 21 |
tree, |
| 22 |
// the location of the node with the dependency |
| 23 |
nodeLoc, |
| 24 |
// the dep being added |
| 25 |
dep, |
| 26 |
// array of nodes representing the dep's peer group |
| 27 |
peerSet, |
| 28 |
// an extra function for running assertions after placement |
| 29 |
test, |
| 30 |
// do we expect this to fail with ERESOLVE? |
| 31 |
error = false, |
| 32 |
// --prefer-dedupe set? |
| 33 |
preferDedupe = false, |
| 34 |
// --force set? |
| 35 |
force = false, |
| 36 |
// is this the thing that the user is explicitly installing? |
| 37 |
explicitRequest, |
| 38 |
// the names passed to `npm update foo bar baz` for example. |
| 39 |
updateNames = [], |
| 40 |
// an audit report, telling us which nodes are vulnerable |
| 41 |
auditReport = null, |
| 42 |
// --strict-peer-deps set? |
| 43 |
strictPeerDeps = false, |
| 44 |
// --legacy-peer-deps set? |
| 45 |
legacyPeerDeps = false, |
| 46 |
// installing with --global or --global-style? |
| 47 |
installStrategy = 'hoisted', |
| 48 |
} = options |
| 49 |
|
| 50 |
const node = tree.inventory.get(nodeLoc) |
| 51 |
const edge = node.edgesOut.get(dep.name) |
| 52 |
if (!dep.satisfies(edge)) { |
| 53 |
edge.peerConflicted = true |
| 54 |
} |
| 55 |
const vr = new Node({ |
| 56 |
sourceReference: node, |
| 57 |
path: node.path, |
| 58 |
pkg: { ...node.package }, |
| 59 |
children: peerSet, |
| 60 |
}) |
| 61 |
dep.parent = vr |
| 62 |
|
| 63 |
// mark any invalid edges in the virtual root as peerConflicted |
| 64 |
for (const child of vr.children.values()) { |
| 65 |
for (const edgeIn of child.edgesIn) { |
| 66 |
if (edgeIn.invalid) { |
| 67 |
edgeIn.peerConflicted = true |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
const place = () => { |
| 73 |
return new PlaceDep({ |
| 74 |
edge, |
| 75 |
dep, |
| 76 |
preferDedupe, |
| 77 |
force, |
| 78 |
explicitRequest, |
| 79 |
updateNames, |
| 80 |
auditReport, |
| 81 |
strictPeerDeps, |
| 82 |
legacyPeerDeps, |
| 83 |
installStrategy, |
| 84 |
}) |
| 85 |
} |
| 86 |
|
| 87 |
t.test(desc, t => { |
| 88 |
const before = normalizePaths(tree.toJSON()) |
| 89 |
|
| 90 |
// the 'error' arg is the ERESOLVE we expect to get |
| 91 |
if (error) { |
| 92 |
const thrown = t.throws(place) |
| 93 |
t.matchSnapshot(normalizePaths(thrown), 'thrown error') |
| 94 |
const after = normalizePaths(tree.toJSON()) |
| 95 |
t.strictSame(before, after, 'tree should not change') |
| 96 |
t.end() |
| 97 |
|
| 98 |
// any time we have an error, we should NOT get that error |
| 99 |
// when run in force or legacyPeerDeps mode |
| 100 |
runTest(desc + ', force', { |
| 101 |
...options, |
| 102 |
error: false, |
| 103 |
force: true, |
| 104 |
legacyPeerDeps: false, |
| 105 |
}) |
| 106 |
if (!edge.peer && !legacyPeerDeps) { |
| 107 |
runTest(desc + ', legacyPeerDeps', { |
| 108 |
...options, |
| 109 |
error: false, |
| 110 |
force: false, |
| 111 |
legacyPeerDeps: true, |
| 112 |
peerSet: [], |
| 113 |
}) |
| 114 |
} |
| 115 |
return |
| 116 |
} |
| 117 |
|
| 118 |
const warnings = [] |
| 119 |
const onwarn = (level, ...msg) => { |
| 120 |
if (level === 'warn') { |
| 121 |
warnings.push(msg) |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
process.on('log', onwarn) |
| 126 |
let pd |
| 127 |
try { |
| 128 |
pd = place() |
| 129 |
} catch (er) { |
| 130 |
console.error(require('node:util').inspect(er, { depth: Infinity })) |
| 131 |
throw er |
| 132 |
} |
| 133 |
process.removeListener('log', onwarn) |
| 134 |
|
| 135 |
if (test) { |
| 136 |
test(t, tree, pd) |
| 137 |
} |
| 138 |
|
| 139 |
const after = normalizePaths(tree.toJSON()) |
| 140 |
const { diff } = strict(after, before) |
| 141 |
|
| 142 |
if (pd.needEvaluation.size) { |
| 143 |
t.matchSnapshot([...pd.needEvaluation] |
| 144 |
.map(n => `${n.location} ${n.version}`)) |
| 145 |
} |
| 146 |
t.matchSnapshot(diff, 'changes to tree') |
| 147 |
t.matchSnapshot(normalizePaths(warnings), 'warnings') |
| 148 |
t.matchSnapshot([pd, ...pd.allChildren].map(c => { |
| 149 |
if (c.canPlace && c.canPlace.canPlace === KEEP) { |
| 150 |
t.equal(c.placed, null, 'should not place if result is KEEP') |
| 151 |
} |
| 152 |
return normalizePaths({ |
| 153 |
...(c.parent ? { parent: c.parent.name } : {}), |
| 154 |
edge: `{ ${ |
| 155 |
c.edge.from.location || 'ROOT' |
| 156 |
} ${c.edge.type} ${c.edge.name}@${c.edge.spec} }`, |
| 157 |
dep: `${c.dep.name}@${c.dep.version}`, |
| 158 |
canPlace: c.canPlace && c.canPlace.canPlace, |
| 159 |
canPlaceSelf: c.canPlaceSelf && c.canPlaceSelf.canPlaceSelf, |
| 160 |
placed: c.placed && c.placed.location, |
| 161 |
checks: new Map([...pd.checks].map(([target, cpd]) => |
| 162 |
[target.location, [cpd.canPlace, cpd.canPlaceSelf]])), |
| 163 |
}) |
| 164 |
}), 'placements') |
| 165 |
|
| 166 |
t.end() |
| 167 |
}) |
| 168 |
} |
| 169 |
|
| 170 |
runTest('basic placement of a production dep', { |
| 171 |
tree: new Node({ |
| 172 |
path, |
| 173 |
pkg: { dependencies: { foo: '1' } }, |
| 174 |
}), |
| 175 |
dep: new Node({ pkg: { name: 'foo', version: '1.0.0' } }), |
| 176 |
nodeLoc: '', |
| 177 |
}) |
| 178 |
|
| 179 |
runTest('explicit placement of a production dep', { |
| 180 |
tree: new Node({ |
| 181 |
path, |
| 182 |
pkg: { dependencies: { foo: '1' } }, |
| 183 |
}), |
| 184 |
dep: new Node({ pkg: { name: 'foo', version: '1.0.0' } }), |
| 185 |
nodeLoc: '', |
| 186 |
explicitRequest: true, |
| 187 |
}) |
| 188 |
|
| 189 |
runTest('dedupe a transitive dependency', { |
| 190 |
tree: new Node({ |
| 191 |
path, |
| 192 |
pkg: { dependencies: { foo: '1', baz: '1' } }, |
| 193 |
children: [ |
| 194 |
{ pkg: { name: 'foo', version: '1.0.0', dependencies: { bar: '1' } } }, |
| 195 |
{ pkg: { name: 'baz', version: '1.0.0', dependencies: { bar: '1' } } }, |
| 196 |
], |
| 197 |
}), |
| 198 |
dep: new Node({ pkg: { name: 'bar', version: '1.0.0' } }), |
| 199 |
nodeLoc: 'node_modules/foo', |
| 200 |
}) |
| 201 |
|
| 202 |
runTest('upgrade a transitive dependency', { |
| 203 |
tree: new Node({ |
| 204 |
path, |
| 205 |
pkg: { dependencies: { foo: '1', baz: '1' } }, |
| 206 |
children: [ |
| 207 |
{ pkg: { name: 'foo', version: '1.0.0', dependencies: { bar: '1' } } }, |
| 208 |
{ pkg: { name: 'baz', version: '1.0.0', dependencies: { bar: '1' } } }, |
| 209 |
{ pkg: { name: 'bar', version: '1.0.0' } }, |
| 210 |
], |
| 211 |
}), |
| 212 |
dep: new Node({ pkg: { name: 'bar', version: '1.0.1' } }), |
| 213 |
nodeLoc: 'node_modules/foo', |
| 214 |
}) |
| 215 |
|
| 216 |
runTest('nest a transitive dependency', { |
| 217 |
tree: new Node({ |
| 218 |
path, |
| 219 |
pkg: { dependencies: { foo: '1', baz: '1' } }, |
| 220 |
children: [ |
| 221 |
{ pkg: { name: 'foo', version: '1.0.0', dependencies: { bar: '1' } } }, |
| 222 |
{ pkg: { name: 'baz', version: '1.0.0', dependencies: { bar: '1.0.0' } } }, |
| 223 |
{ pkg: { name: 'bar', version: '1.0.1' } }, |
| 224 |
], |
| 225 |
}), |
| 226 |
dep: new Node({ pkg: { name: 'bar', version: '1.0.0' } }), |
| 227 |
nodeLoc: 'node_modules/baz', |
| 228 |
test: (t, tree) => { |
| 229 |
const foobar = tree.children.get('foo').resolve('bar') |
| 230 |
t.equal(foobar.location, 'node_modules/bar') |
| 231 |
t.equal(foobar.version, '1.0.1') |
| 232 |
const bazbar = tree.children.get('baz').resolve('bar') |
| 233 |
t.equal(bazbar.location, 'node_modules/baz/node_modules/bar') |
| 234 |
t.equal(bazbar.version, '1.0.0') |
| 235 |
}, |
| 236 |
}) |
| 237 |
|
| 238 |
runTest('accept an older transitive dependency', { |
| 239 |
tree: new Node({ |
| 240 |
path, |
| 241 |
pkg: { dependencies: { foo: '1', baz: '1' } }, |
| 242 |
children: [ |
| 243 |
{ pkg: { name: 'foo', version: '1.0.0', dependencies: { bar: '1' } } }, |
| 244 |
{ pkg: { name: 'baz', version: '1.0.0', dependencies: { bar: '1.0.0' } } }, |
| 245 |
{ pkg: { name: 'bar', version: '1.0.0' } }, |
| 246 |
], |
| 247 |
}), |
| 248 |
dep: new Node({ pkg: { name: 'bar', version: '1.0.1' } }), |
| 249 |
nodeLoc: 'node_modules/foo', |
| 250 |
test: (t, tree) => { |
| 251 |
const foobar = tree.children.get('foo').resolve('bar') |
| 252 |
t.equal(foobar.location, 'node_modules/bar') |
| 253 |
t.equal(foobar.version, '1.0.0') |
| 254 |
const bazbar = tree.children.get('baz').resolve('bar') |
| 255 |
t.equal(bazbar.location, 'node_modules/bar') |
| 256 |
t.equal(bazbar.version, '1.0.0') |
| 257 |
}, |
| 258 |
}) |
| 259 |
|
| 260 |
runTest('nest even though unnecessary, because legacy bundling', { |
| 261 |
tree: new Node({ |
| 262 |
path, |
| 263 |
pkg: { dependencies: { foo: '1', baz: '1' } }, |
| 264 |
children: [ |
| 265 |
{ pkg: { name: 'foo', version: '1.0.0', dependencies: { bar: '1' } } }, |
| 266 |
{ pkg: { name: 'baz', version: '1.0.0', dependencies: { bar: '1.0.0' } } }, |
| 267 |
], |
| 268 |
}), |
| 269 |
dep: new Node({ pkg: { name: 'bar', version: '1.0.0' } }), |
| 270 |
nodeLoc: 'node_modules/foo', |
| 271 |
installStrategy: 'nested', |
| 272 |
test: (t, tree) => { |
| 273 |
const foobar = tree.children.get('foo').resolve('bar') |
| 274 |
t.equal(foobar.location, 'node_modules/foo/node_modules/bar') |
| 275 |
t.equal(foobar.version, '1.0.0') |
| 276 |
const bazbar = tree.children.get('baz').resolve('bar') |
| 277 |
t.equal(bazbar, null) |
| 278 |
}, |
| 279 |
}) |
| 280 |
|
| 281 |
runTest('nest because globalStyle', { |
| 282 |
tree: new Node({ |
| 283 |
path, |
| 284 |
pkg: { dependencies: { foo: '1', baz: '1' } }, |
| 285 |
children: [ |
| 286 |
{ pkg: { name: 'foo', version: '1.0.0', dependencies: { bar: '1' } } }, |
| 287 |
], |
| 288 |
}), |
| 289 |
dep: new Node({ pkg: { name: 'bar', version: '1.0.0' } }), |
| 290 |
nodeLoc: 'node_modules/foo', |
| 291 |
installStrategy: 'shallow', |
| 292 |
test: (t, tree) => { |
| 293 |
const foobar = tree.children.get('foo').resolve('bar') |
| 294 |
t.equal(foobar.location, 'node_modules/foo/node_modules/bar') |
| 295 |
}, |
| 296 |
}) |
| 297 |
|
| 298 |
runTest('nest only 1 level due to globalStyle', { |
| 299 |
tree: new Node({ |
| 300 |
path, |
| 301 |
pkg: { dependencies: { foo: '1', baz: '1' } }, |
| 302 |
children: [ |
| 303 |
{ |
| 304 |
pkg: { |
| 305 |
name: 'foo', |
| 306 |
version: '1.0.0', |
| 307 |
dependencies: { bar: '1' }, |
| 308 |
}, |
| 309 |
children: [ |
| 310 |
{ |
| 311 |
pkg: { |
| 312 |
name: 'bar', |
| 313 |
version: '1.0.0', |
| 314 |
dependencies: { baz: '' }, |
| 315 |
}, |
| 316 |
}, |
| 317 |
], |
| 318 |
}, |
| 319 |
], |
| 320 |
}), |
| 321 |
dep: new Node({ pkg: { name: 'baz', version: '1.0.0' } }), |
| 322 |
nodeLoc: 'node_modules/foo/node_modules/bar', |
| 323 |
installStrategy: 'shallow', |
| 324 |
test: (t, tree) => { |
| 325 |
const foobar = tree.children.get('foo').resolve('bar') |
| 326 |
const foobarbaz = foobar.resolve('baz') |
| 327 |
t.equal(foobar.location, 'node_modules/foo/node_modules/bar') |
| 328 |
t.equal(foobarbaz.location, 'node_modules/foo/node_modules/baz') |
| 329 |
}, |
| 330 |
}) |
| 331 |
|
| 332 |
runTest('prefer to dedupe rather than nest', { |
| 333 |
tree: new Node({ |
| 334 |
path, |
| 335 |
pkg: { dependencies: { foo: '1', baz: '1' } }, |
| 336 |
children: [ |
| 337 |
{ pkg: { name: 'foo', version: '1.0.0', dependencies: { bar: '1' } } }, |
| 338 |
{ pkg: { name: 'baz', version: '1.0.0', dependencies: { bar: '1.0.0' } } }, |
| 339 |
{ pkg: { name: 'bar', version: '1.0.1' } }, |
| 340 |
], |
| 341 |
}), |
| 342 |
dep: new Node({ pkg: { name: 'bar', version: '1.0.0' } }), |
| 343 |
nodeLoc: 'node_modules/baz', |
| 344 |
preferDedupe: true, |
| 345 |
test: (t, tree) => { |
| 346 |
const foobar = tree.children.get('foo').resolve('bar') |
| 347 |
t.equal(foobar.location, 'node_modules/bar') |
| 348 |
t.equal(foobar.version, '1.0.0') |
| 349 |
const bazbar = tree.children.get('baz').resolve('bar') |
| 350 |
t.equal(bazbar.location, 'node_modules/bar') |
| 351 |
t.equal(bazbar.version, '1.0.0') |
| 352 |
}, |
| 353 |
}) |
| 354 |
|
| 355 |
runTest('dep with load error', { |
| 356 |
tree: new Node({ |
| 357 |
path, |
| 358 |
pkg: { dependencies: { foo: '1' } }, |
| 359 |
}), |
| 360 |
dep: new Node({ |
| 361 |
error: Object.assign(new Error('oops'), { code: 'testing' }), |
| 362 |
name: 'foo', |
| 363 |
}), |
| 364 |
nodeLoc: '', |
| 365 |
}) |
| 366 |
|
| 367 |
// root -> (x, y@1) |
| 368 |
// +-- x -> ([email protected]) |
| 369 |
// | +-- [email protected] (replacing with 1.1.2, got KEEP at the root) |
| 370 |
// +-- [email protected] (updated already from 1.0.0) |
| 371 |
runTest('keep, but dedupe', { |
| 372 |
tree: new Node({ |
| 373 |
path, |
| 374 |
pkg: { dependencies: { x: '', y: '1', z: 'file:z' } }, |
| 375 |
children: [ |
| 376 |
{ pkg: { name: 'y', version: '1.1.2' } }, |
| 377 |
{ |
| 378 |
pkg: { name: 'x', version: '1.0.0', dependencies: { y: '1.1' } }, |
| 379 |
children: [{ pkg: { name: 'y', version: '1.1.0' } }], |
| 380 |
}, |
| 381 |
], |
| 382 |
fsChildren: [ |
| 383 |
{ |
| 384 |
path: `${path}/z`, |
| 385 |
pkg: { name: 'z', version: '1.2.3', dependencies: { y: '1' } }, |
| 386 |
// this will get deduped out |
| 387 |
children: [{ pkg: { name: 'y', version: '1.1.2' } }], |
| 388 |
}, |
| 389 |
], |
| 390 |
}), |
| 391 |
dep: new Node({ pkg: { name: 'y', version: '1.1.2' } }), |
| 392 |
updateNames: ['y'], |
| 393 |
nodeLoc: 'node_modules/x', |
| 394 |
test: (t, tree) => { |
| 395 |
const x = tree.children.get('x') |
| 396 |
const y = x.resolve('y') |
| 397 |
t.equal(y.location, 'node_modules/y') |
| 398 |
t.equal(y.version, '1.1.2') |
| 399 |
const z = tree.inventory.get('z') |
| 400 |
const zy = z.resolve('y') |
| 401 |
t.equal(zy.location, y.location, 'y bundled under z is removed') |
| 402 |
}, |
| 403 |
}) |
| 404 |
|
| 405 |
// y depends on z@1, everything else depends on z@2, so every y has a z dupe |
| 406 |
// root -> (y@1, x, z@2, a, k@file:k) |
| 407 |
// +-- a -> ([email protected], [email protected]) |
| 408 |
// | +-- [email protected] |
| 409 |
// | +-- [email protected] -> (z@1, file:v) (will not be deduped) |
| 410 |
// | +fs [email protected] -> (z@2) |
| 411 |
// | | +-- [email protected] |
| 412 |
// | +-- [email protected] |
| 413 |
// +-- [email protected] |
| 414 |
// +-- [email protected] (will be pruned upon replacement) |
| 415 |
// +-- [email protected] -> (z@1, f) (replacing with 1.2.2) |
| 416 |
// | +-- [email protected] |
| 417 |
// +-- x -> ([email protected], z@2) |
| 418 |
// +-- [email protected] -> (z@1, w@1) (got REPLACE at the root, will dedupe) |
| 419 |
// +-- [email protected] |
| 420 |
// root/k -> ([email protected]) |
| 421 |
// +-- [email protected] -> (z@1) (will dedupe) |
| 422 |
// +-- [email protected] (will be pruned when y sibling removed) |
| 423 |
runTest('replace higher up, and dedupe descendants', { |
| 424 |
tree: new Node({ |
| 425 |
path, |
| 426 |
pkg: { dependencies: { y: '1', z: '2', a: '', x: '' } }, |
| 427 |
children: [ |
| 428 |
{ |
| 429 |
pkg: { name: 'a', version: '1.0.0', dependencies: { y: '1.0.0', z: '2.0.0' } }, |
| 430 |
children: [ |
| 431 |
{ pkg: { name: 'z', version: '2.0.0' } }, |
| 432 |
{ |
| 433 |
pkg: { name: 'y', dependencies: { z: '1' } }, |
| 434 |
children: [{ pkg: { name: 'z', version: '1.0.0' } }], |
| 435 |
}, |
| 436 |
], |
| 437 |
}, |
| 438 |
{ pkg: { name: 'f', version: '1.0.0', dependencies: { g: '' } } }, |
| 439 |
{ pkg: { name: 'g', version: '1.0.0' } }, |
| 440 |
{ |
| 441 |
pkg: { name: 'y', version: '1.1.0', dependencies: { z: '1', f: '' } }, |
| 442 |
children: [{ pkg: { name: 'z', version: '1.0.0' } }], |
| 443 |
}, |
| 444 |
{ pkg: { name: 'z', version: '2.1.0' } }, |
| 445 |
{ |
| 446 |
pkg: { name: 'x', version: '1.0.0', dependencies: { y: '1.2', z: '2' } }, |
| 447 |
children: [{ |
| 448 |
pkg: { name: 'y', version: '1.2.0', dependencies: { z: '1' } }, |
| 449 |
children: [{ pkg: { name: 'z', version: '1.0.0' } }], |
| 450 |
}], |
| 451 |
}, |
| 452 |
], |
| 453 |
// root/k -> ([email protected]) |
| 454 |
// +-- [email protected] -> (z@1) (will dedupe) |
| 455 |
// +-- [email protected] |
| 456 |
fsChildren: [ |
| 457 |
{ |
| 458 |
pkg: { name: 'k', dependencies: { y: '1.2' } }, |
| 459 |
path: `${path}/k`, |
| 460 |
children: [ |
| 461 |
{ pkg: { name: 'y', version: '1.2.0', dependencies: { z: '1' } } }, |
| 462 |
{ pkg: { name: 'z', version: '1.0.0' } }, |
| 463 |
], |
| 464 |
}, |
| 465 |
], |
| 466 |
}), |
| 467 |
dep: new Node({ pkg: { name: 'y', version: '1.2.2', dependencies: { z: '1' } } }), |
| 468 |
auditReport: { |
| 469 |
isVulnerable: node => node.name === 'y' && node.version === '1.2.0', |
| 470 |
}, |
| 471 |
nodeLoc: 'node_modules/x', |
| 472 |
test: (t, tree) => { |
| 473 |
const x = tree.children.get('x') |
| 474 |
const y = x.resolve('y') |
| 475 |
t.equal(y.location, 'node_modules/y') |
| 476 |
t.equal(y.version, '1.2.2') |
| 477 |
t.equal(tree.resolve('f'), null) |
| 478 |
t.equal(tree.resolve('g'), null) |
| 479 |
const z = tree.resolve('z') |
| 480 |
t.equal(z.location, 'node_modules/z') |
| 481 |
t.equal(z.version, '2.1.0') |
| 482 |
const k = tree.inventory.get('k') |
| 483 |
t.equal(k.children.size, 0, 'children of fsChild all deduped out') |
| 484 |
}, |
| 485 |
}) |
| 486 |
|
| 487 |
// root -> (a@1, b) |
| 488 |
// +-- [email protected] |
| 489 |
// +-- b -> (c@link:c, [email protected]) |
| 490 |
// +-- [email protected] |
| 491 |
// root/node_modules/b/c -> ([email protected]) |
| 492 |
// +-- [email protected] |
| 493 |
// |
| 494 |
// place [email protected] for b, dedupe all other a's |
| 495 |
runTest('replace higher up, and dedupe descendants', { |
| 496 |
tree: new Node({ |
| 497 |
path, |
| 498 |
pkg: { dependencies: { a: '1', b: '' } }, |
| 499 |
children: [ |
| 500 |
{ pkg: { name: 'a', version: '1.0.0' } }, |
| 501 |
{ |
| 502 |
pkg: { |
| 503 |
name: 'b', |
| 504 |
version: '1.0.0', |
| 505 |
dependencies: { |
| 506 |
c: 'file:c', |
| 507 |
a: '1.1', |
| 508 |
}, |
| 509 |
}, |
| 510 |
fsChildren: [ |
| 511 |
{ |
| 512 |
path: `${path}/node_modules/b/c`, |
| 513 |
pkg: { |
| 514 |
name: 'c', |
| 515 |
version: '1.0.0', |
| 516 |
dependencies: { a: '1.1.1' }, |
| 517 |
}, |
| 518 |
children: [{ pkg: { name: 'a', version: '1.1.1' } }], |
| 519 |
}, |
| 520 |
], |
| 521 |
}, |
| 522 |
], |
| 523 |
}), |
| 524 |
dep: new Node({ pkg: { name: 'a', version: '1.1.1' } }), |
| 525 |
nodeLoc: 'node_modules/b', |
| 526 |
test: (t, tree) => { |
| 527 |
const a = [...tree.inventory.query('name', 'a')].map(a => a.location) |
| 528 |
t.strictSame(a, ['node_modules/a'], 'should be left with one a') |
| 529 |
}, |
| 530 |
}) |
| 531 |
|
| 532 |
// a -> (b@1, c@1) |
| 533 |
// +-- c@1 |
| 534 |
// +-- b -> PEEROPTIONAL(v) (c@2) |
| 535 |
// +-- c@2 -> (v) |
| 536 |
// place v for c@2, should end up at a, skipping over b |
| 537 |
runTest('skip over peer dependents in the ancestry walkup', { |
| 538 |
tree: new Node({ |
| 539 |
path, |
| 540 |
pkg: { dependencies: { a: '' } }, |
| 541 |
children: [ |
| 542 |
{ |
| 543 |
pkg: { name: 'a', version: '1.0.0', dependencies: { b: '1.0.0', c: '1.0.0' } }, |
| 544 |
}, |
| 545 |
{ pkg: { name: 'c', version: '1.0.0' } }, |
| 546 |
{ |
| 547 |
pkg: { |
| 548 |
name: 'b', |
| 549 |
version: '1.0.0', |
| 550 |
dependencies: { c: '2' }, |
| 551 |
peerDependencies: { v: '' }, |
| 552 |
}, |
| 553 |
children: [{ |
| 554 |
pkg: { name: 'c', version: '2.0.0', dependencies: { v: '1' } }, |
| 555 |
}], |
| 556 |
}, |
| 557 |
], |
| 558 |
}), |
| 559 |
dep: new Node({ pkg: { name: 'v', version: '1.0.0' } }), |
| 560 |
nodeLoc: 'node_modules/b/node_modules/c', |
| 561 |
test: (t, tree) => t.ok(tree.children.get('v')), |
| 562 |
}) |
| 563 |
|
| 564 |
// root -> (a@1, x) |
| 565 |
// x -> (a@2, b@1) |
| 566 |
// a@1 -> (b@1) |
| 567 |
// a@2 -> (b@2) |
| 568 |
// b@1 -> (c@1) |
| 569 |
// b@2 -> (c@2) |
| 570 |
// |
| 571 |
// root |
| 572 |
// +-- c@1 |
| 573 |
// +-- b@1 |
| 574 |
// +-- x |
| 575 |
// +-- b@1 |
| 576 |
// +-- a |
| 577 |
// +-- b@2 |
| 578 |
// place c@2 for b@2, should land in a |
| 579 |
runTest('do not shadow inappropriately', { |
| 580 |
tree: new Node({ |
| 581 |
path, |
| 582 |
pkg: { dependencies: { x: '', a: '1' } }, |
| 583 |
children: [ |
| 584 |
{ pkg: { name: 'a', version: '1.0.0' } }, |
| 585 |
{ pkg: { name: 'c', version: '1.0.0' } }, |
| 586 |
{ |
| 587 |
pkg: { name: 'x', version: '1.0.0', dependencies: { a: '2', b: '1' } }, |
| 588 |
children: [ |
| 589 |
{ pkg: { name: 'b', version: '1.0.0', dependencies: { c: '1' } } }, |
| 590 |
{ |
| 591 |
pkg: { name: 'a', version: '2.0.0', dependencies: { b: '2' } }, |
| 592 |
children: [ |
| 593 |
{ pkg: { name: 'b', version: '2.0.0', dependencies: { c: '2' } } }, |
| 594 |
], |
| 595 |
}, |
| 596 |
], |
| 597 |
}, |
| 598 |
], |
| 599 |
}), |
| 600 |
dep: new Node({ pkg: { name: 'c', version: '2.0.0' } }), |
| 601 |
nodeLoc: 'node_modules/x/node_modules/a/node_modules/b', |
| 602 |
test: (t, tree) => { |
| 603 |
const c = tree.children.get('c') |
| 604 |
const x = tree.children.get('x') |
| 605 |
const xa = x.resolve('a') |
| 606 |
const xab = xa.resolve('b') |
| 607 |
const xabc = xab.resolve('c') |
| 608 |
t.equal(c.version, '1.0.0') |
| 609 |
t.equal(xabc.parent, xa) |
| 610 |
t.equal(xab.parent, xa) |
| 611 |
t.equal(xa.parent, x) |
| 612 |
}, |
| 613 |
}) |
| 614 |
|
| 615 |
// pathologically nested dep cycle |
| 616 |
// a1 -> b1 -> a2 -> b2 -> a1 |
| 617 |
runTest('pathologically nested dependency cycle', { |
| 618 |
tree: new Node({ |
| 619 |
path, |
| 620 |
pkg: { dependencies: { a: '1' } }, |
| 621 |
children: [ |
| 622 |
{ pkg: { name: 'a', version: '1.0.0', dependencies: { b: '1' } } }, |
| 623 |
{ |
| 624 |
pkg: { name: 'b', version: '1.0.0', dependencies: { a: '2' } }, |
| 625 |
children: [ |
| 626 |
{ pkg: { name: 'a', version: '2.0.0', dependencies: { b: '2' } } }, |
| 627 |
{ |
| 628 |
pkg: { name: 'b', version: '2.0.0', dependencies: { a: '1' } }, |
| 629 |
children: [ |
| 630 |
{ pkg: { name: 'a', version: '1.0.0', dependencies: { b: '1' } } }, |
| 631 |
], |
| 632 |
}, |
| 633 |
], |
| 634 |
}, |
| 635 |
], |
| 636 |
}), |
| 637 |
dep: new Node({ |
| 638 |
pkg: { name: 'b', version: '1.0.0', dependencies: { a: '2' } }, |
| 639 |
}), |
| 640 |
nodeLoc: 'node_modules/b/node_modules/b/node_modules/a', |
| 641 |
}) |
| 642 |
|
| 643 |
// peer dep shenanigans |
| 644 |
runTest('basic placement of a production dep with peer deps', { |
| 645 |
tree: new Node({ |
| 646 |
path, |
| 647 |
pkg: { dependencies: { foo: '1' } }, |
| 648 |
}), |
| 649 |
dep: new Node({ |
| 650 |
pkg: { name: 'foo', version: '1.0.0', peerDependencies: { bar: '' } }, |
| 651 |
}), |
| 652 |
nodeLoc: '', |
| 653 |
peerSet: [ |
| 654 |
{ pkg: { name: 'bar', version: '1.0.0', peerDependencies: { baz: '' } } }, |
| 655 |
{ pkg: { name: 'baz', version: '1.0.0' } }, |
| 656 |
], |
| 657 |
}) |
| 658 |
|
| 659 |
runTest('bounce off an existing dep that is newer, preferDedupe', { |
| 660 |
tree: new Node({ |
| 661 |
path, |
| 662 |
pkg: { name: 'project', version: '1.2.3', dependencies: { a: '1', c: '2.0.0' } }, |
| 663 |
children: [ |
| 664 |
{ pkg: { name: 'b', version: '2.3.4' } }, |
| 665 |
{ pkg: { name: 'c', version: '2.0.0', dependencies: { b: '2.0.0' } } }, |
| 666 |
{ pkg: { name: 'a', version: '1.2.3', dependencies: { b: '2' } } }, |
| 667 |
], |
| 668 |
}), |
| 669 |
nodeLoc: 'node_modules/c', |
| 670 |
dep: new Node({ |
| 671 |
pkg: { name: 'b', version: '2.0.0', peerDependencies: { a: '3' } }, |
| 672 |
}), |
| 673 |
peerSet: [ |
| 674 |
{ pkg: { name: 'a', version: '3.0.0' } }, |
| 675 |
], |
| 676 |
preferDedupe: true, |
| 677 |
}) |
| 678 |
|
| 679 |
runTest('peer with peers', { |
| 680 |
tree: new Node({ |
| 681 |
path, |
| 682 |
pkg: { name: 'project', version: '1.2.3', dependencies: { a: '1.x' } }, |
| 683 |
}), |
| 684 |
nodeLoc: '', |
| 685 |
dep: new Node({ |
| 686 |
pkg: { name: 'a', version: '1.2.3', peerDependencies: { b: '1' } }, |
| 687 |
}), |
| 688 |
peerSet: [ |
| 689 |
{ pkg: { name: 'b', version: '1.2.3', peerDependencies: { c: '1' } } }, |
| 690 |
{ pkg: { name: 'c', version: '1.2.3' } }, |
| 691 |
], |
| 692 |
}) |
| 693 |
|
| 694 |
runTest('cycle of peers', { |
| 695 |
tree: new Node({ |
| 696 |
path, |
| 697 |
pkg: { name: 'project', version: '1.2.3', dependencies: { a: '1.x' } }, |
| 698 |
}), |
| 699 |
nodeLoc: '', |
| 700 |
dep: new Node({ |
| 701 |
pkg: { name: 'a', version: '1.2.3', peerDependencies: { b: '1' } }, |
| 702 |
}), |
| 703 |
peerSet: [ |
| 704 |
{ pkg: { name: 'b', version: '1.2.3', peerDependencies: { c: '1' } } }, |
| 705 |
{ pkg: { name: 'c', version: '1.2.3', peerDependencies: { a: '1' } } }, |
| 706 |
], |
| 707 |
}) |
| 708 |
|
| 709 |
runTest('cycle of peers hanging off entry node', { |
| 710 |
tree: new Node({ |
| 711 |
path, |
| 712 |
pkg: { name: 'project', version: '1.2.3', dependencies: { a: '1.x' } }, |
| 713 |
}), |
| 714 |
nodeLoc: '', |
| 715 |
dep: new Node({ |
| 716 |
pkg: { name: 'a', version: '1.2.3', peerDependencies: { b: '1' } }, |
| 717 |
}), |
| 718 |
peerSet: [ |
| 719 |
{ pkg: { name: 'b', version: '1.2.3', peerDependencies: { c: '1' } } }, |
| 720 |
{ pkg: { name: 'c', version: '1.2.3', peerDependencies: { d: '1' } } }, |
| 721 |
{ pkg: { name: 'd', version: '1.2.3', peerDependencies: { b: '1' } } }, |
| 722 |
], |
| 723 |
}) |
| 724 |
|
| 725 |
runTest('peers with peerConflicted edges in peerSet', { |
| 726 |
tree: new Node({ |
| 727 |
path, |
| 728 |
pkg: { name: 'project', version: '1.2.3', dependencies: { a: '1.x' } }, |
| 729 |
}), |
| 730 |
nodeLoc: '', |
| 731 |
dep: new Node({ |
| 732 |
pkg: { name: 'a', version: '1.2.3', peerDependencies: { b: '1' } }, |
| 733 |
}), |
| 734 |
peerSet: [ |
| 735 |
{ pkg: { name: 'b', version: '1.2.3', peerDependencies: { c: '1' } } }, |
| 736 |
{ pkg: { name: 'c', version: '1.2.3', peerDependencies: { b: '2', a: '2' } } }, |
| 737 |
], |
| 738 |
}) |
| 739 |
|
| 740 |
runTest('peers with peerConflicted edges in peerSet from dependent', { |
| 741 |
tree: new Node({ |
| 742 |
path, |
| 743 |
pkg: { |
| 744 |
name: 'project', |
| 745 |
version: '1.2.3', |
| 746 |
dependencies: { |
| 747 |
a: '1.x', |
| 748 |
c: '2.x', |
| 749 |
}, |
| 750 |
}, |
| 751 |
children: [ |
| 752 |
{ pkg: { name: 'c', version: '2.0.1', peerDependencies: { b: '2', a: '2' } } }, |
| 753 |
], |
| 754 |
}), |
| 755 |
nodeLoc: '', |
| 756 |
dep: new Node({ |
| 757 |
pkg: { name: 'a', version: '1.2.3', peerDependencies: { b: '1' } }, |
| 758 |
}), |
| 759 |
peerSet: [ |
| 760 |
{ pkg: { name: 'b', version: '1.2.3', peerDependencies: { c: '1' } } }, |
| 761 |
{ pkg: { name: 'c', version: '2.2.3', peerDependencies: { b: '2', a: '2' } } }, |
| 762 |
], |
| 763 |
}) |
| 764 |
|
| 765 |
runTest('peers with peerConflicted edges in peerSet from dependent', { |
| 766 |
tree: new Node({ |
| 767 |
path, |
| 768 |
pkg: { |
| 769 |
name: 'project', |
| 770 |
version: '1.2.3', |
| 771 |
dependencies: { |
| 772 |
a: '1.x', |
| 773 |
c: '2.x', |
| 774 |
}, |
| 775 |
}, |
| 776 |
children: [ |
| 777 |
{ pkg: { name: 'c', version: '2.0.1', peerDependencies: { b: '2', a: '2' } } }, |
| 778 |
], |
| 779 |
}), |
| 780 |
nodeLoc: '', |
| 781 |
dep: new Node({ |
| 782 |
pkg: { name: 'a', version: '1.2.3', peerDependencies: { b: '1' } }, |
| 783 |
}), |
| 784 |
peerSet: [ |
| 785 |
{ pkg: { name: 'b', version: '1.2.3', peerDependencies: { c: '1' } } }, |
| 786 |
{ pkg: { name: 'c', version: '2.2.3', peerDependencies: { b: '2', a: '2' } } }, |
| 787 |
], |
| 788 |
}) |
| 789 |
|
| 790 |
runTest('replacing existing peer set', { |
| 791 |
tree: new Node({ |
| 792 |
path, |
| 793 |
pkg: { |
| 794 |
name: 'project', |
| 795 |
version: '1.2.3', |
| 796 |
dependencies: { |
| 797 |
a: '1.x', |
| 798 |
c: '2.x', |
| 799 |
}, |
| 800 |
}, |
| 801 |
children: [ |
| 802 |
{ pkg: { name: 'a', version: '1.0.1', peerDependencies: { b: '1' } } }, |
| 803 |
{ pkg: { name: 'b', version: '1.0.1', peerDependencies: { c: '1' } } }, |
| 804 |
{ pkg: { name: 'c', version: '2.0.1', peerDependencies: { b: '2', a: '2' } } }, |
| 805 |
], |
| 806 |
}), |
| 807 |
nodeLoc: '', |
| 808 |
dep: new Node({ |
| 809 |
pkg: { name: 'a', version: '1.2.3', peerDependencies: { b: '1' } }, |
| 810 |
}), |
| 811 |
peerSet: [ |
| 812 |
{ pkg: { name: 'b', version: '1.2.3', peerDependencies: { c: '1' } } }, |
| 813 |
{ pkg: { name: 'c', version: '2.2.3', peerDependencies: { b: '2', a: '2' } } }, |
| 814 |
], |
| 815 |
explicitRequest: true, |
| 816 |
}) |
| 817 |
|
| 818 |
runTest('existing peer set which can be pushed deeper, no current', { |
| 819 |
tree: new Node({ |
| 820 |
path, |
| 821 |
pkg: { |
| 822 |
name: 'project', |
| 823 |
version: '1.2.3', |
| 824 |
dependencies: { |
| 825 |
a: '1.x', |
| 826 |
d: '2.x', |
| 827 |
}, |
| 828 |
}, |
| 829 |
children: [ |
| 830 |
{ pkg: { name: 'a', version: '1.0.1', dependencies: { b: '1' } } }, |
| 831 |
{ pkg: { name: 'b', version: '1.0.1', peerDependencies: { c: '1' } } }, |
| 832 |
{ pkg: { name: 'c', version: '1.0.1' } }, |
| 833 |
], |
| 834 |
}), |
| 835 |
nodeLoc: '', |
| 836 |
dep: new Node({ |
| 837 |
pkg: { name: 'd', version: '2.2.2', peerDependencies: { b: '2' } }, |
| 838 |
}), |
| 839 |
peerSet: [ |
| 840 |
{ pkg: { name: 'b', version: '2.2.2', peerDependencies: { c: '2' } } }, |
| 841 |
{ pkg: { name: 'c', version: '2.2.2' } }, |
| 842 |
], |
| 843 |
explicitRequest: true, |
| 844 |
}) |
| 845 |
|
| 846 |
runTest('existing peer set which can be pushed deeper, with invalid current', { |
| 847 |
tree: new Node({ |
| 848 |
path, |
| 849 |
pkg: { |
| 850 |
name: 'project', |
| 851 |
version: '1.2.3', |
| 852 |
dependencies: { |
| 853 |
a: '1.x', |
| 854 |
d: '2.x', |
| 855 |
}, |
| 856 |
}, |
| 857 |
children: [ |
| 858 |
{ pkg: { name: 'a', version: '1.0.1', dependencies: { b: '1' } } }, |
| 859 |
{ pkg: { name: 'b', version: '1.0.1', peerDependencies: { c: '1' } } }, |
| 860 |
{ pkg: { name: 'c', version: '1.0.1' } }, |
| 861 |
{ pkg: { name: 'd', version: '1.1.1', peerDependencies: { b: '1' } } }, |
| 862 |
], |
| 863 |
}), |
| 864 |
nodeLoc: '', |
| 865 |
dep: new Node({ |
| 866 |
pkg: { name: 'd', version: '2.2.2', peerDependencies: { b: '2' } }, |
| 867 |
}), |
| 868 |
peerSet: [ |
| 869 |
{ pkg: { name: 'b', version: '2.2.2', peerDependencies: { c: '2' } } }, |
| 870 |
{ pkg: { name: 'c', version: '2.2.2' } }, |
| 871 |
], |
| 872 |
explicitRequest: true, |
| 873 |
}) |
| 874 |
|
| 875 |
// root -> (a@1, d@1) |
| 876 |
// [email protected] -> (b@1) |
| 877 |
// [email protected] -> PEER(c@1) |
| 878 |
// [email protected] -> PEER(b@1) |
| 879 |
// [email protected] -> PEER(b@2) |
| 880 |
// [email protected] -> PEER(c@2) |
| 881 |
// |
| 882 |
// root |
| 883 |
// +-- [email protected] |
| 884 |
// +-- [email protected] <-- can be pushed under a, along with c & d |
| 885 |
// +-- [email protected] |
| 886 |
// +-- [email protected] |
| 887 |
// PLACE([email protected]<[email protected], [email protected]>) |
| 888 |
runTest('existing peer set which can be pushed deeper, with valid current', { |
| 889 |
tree: new Node({ |
| 890 |
path, |
| 891 |
pkg: { |
| 892 |
name: 'project', |
| 893 |
version: '1.2.3', |
| 894 |
dependencies: { |
| 895 |
a: '1.x', |
| 896 |
d: '1.x', |
| 897 |
}, |
| 898 |
}, |
| 899 |
children: [ |
| 900 |
{ pkg: { name: 'a', version: '1.0.1', dependencies: { b: '1' } } }, |
| 901 |
{ pkg: { name: 'b', version: '1.0.1', peerDependencies: { c: '1' } } }, |
| 902 |
{ pkg: { name: 'c', version: '1.0.1' } }, |
| 903 |
{ pkg: { name: 'd', version: '1.1.1', peerDependencies: { b: '1' } } }, |
| 904 |
], |
| 905 |
}), |
| 906 |
nodeLoc: '', |
| 907 |
dep: new Node({ |
| 908 |
pkg: { name: 'd', version: '1.2.2', peerDependencies: { b: '2' } }, |
| 909 |
}), |
| 910 |
peerSet: [ |
| 911 |
{ pkg: { name: 'b', version: '2.2.2', peerDependencies: { c: '2' } } }, |
| 912 |
{ pkg: { name: 'c', version: '2.2.2' } }, |
| 913 |
], |
| 914 |
explicitRequest: true, |
| 915 |
}) |
| 916 |
|
| 917 |
runTest('existing peer set which can be pushed deeper, conflict on peer', { |
| 918 |
tree: new Node({ |
| 919 |
path, |
| 920 |
pkg: { |
| 921 |
name: 'project', |
| 922 |
version: '1.2.3', |
| 923 |
dependencies: { |
| 924 |
a: '1.x', |
| 925 |
d: '1.x', |
| 926 |
}, |
| 927 |
}, |
| 928 |
children: [ |
| 929 |
{ pkg: { name: 'a', version: '1.0.1', dependencies: { bb: '1' } } }, |
| 930 |
{ pkg: { name: 'bb', version: '1.0.1', peerDependencies: { c: '1' } } }, |
| 931 |
{ pkg: { name: 'c', version: '1.0.1' } }, |
| 932 |
{ pkg: { name: 'd', version: '1.1.1', peerDependencies: { c: '1' } } }, |
| 933 |
], |
| 934 |
}), |
| 935 |
nodeLoc: '', |
| 936 |
dep: new Node({ |
| 937 |
pkg: { name: 'd', version: '1.2.2', peerDependencies: { b: '2' } }, |
| 938 |
}), |
| 939 |
peerSet: [ |
| 940 |
{ pkg: { name: 'b', version: '2.2.2', peerDependencies: { c: '2' } } }, |
| 941 |
{ pkg: { name: 'c', version: '2.2.2' } }, |
| 942 |
], |
| 943 |
explicitRequest: true, |
| 944 |
}) |
| 945 |
|
| 946 |
runTest('existing peer set cannot be pushed deeper, but new dep set can', { |
| 947 |
tree: new Node({ |
| 948 |
path, |
| 949 |
pkg: { |
| 950 |
name: 'project', |
| 951 |
version: '1.2.3', |
| 952 |
dependencies: { |
| 953 |
a: '1.x', |
| 954 |
d: '2.x', |
| 955 |
}, |
| 956 |
}, |
| 957 |
children: [ |
| 958 |
{ pkg: { name: 'a', version: '1.0.1', dependencies: { b: '1' } } }, |
| 959 |
{ pkg: { name: 'd', version: '2.2.2', peerDependencies: { b: '2' } } }, |
| 960 |
{ pkg: { name: 'b', version: '2.2.2', peerDependencies: { c: '2' } } }, |
| 961 |
{ pkg: { name: 'c', version: '2.2.2' } }, |
| 962 |
], |
| 963 |
}), |
| 964 |
nodeLoc: 'node_modules/a', |
| 965 |
dep: new Node({ |
| 966 |
pkg: { name: 'b', version: '1.0.1', peerDependencies: { c: '1' } }, |
| 967 |
}), |
| 968 |
peerSet: [ |
| 969 |
{ pkg: { name: 'c', version: '1.0.1' } }, |
| 970 |
], |
| 971 |
explicitRequest: true, |
| 972 |
}) |
| 973 |
|
| 974 |
runTest('nest peer set under dependent node', { |
| 975 |
tree: new Node({ |
| 976 |
path, |
| 977 |
pkg: { |
| 978 |
name: 'project', |
| 979 |
version: '1.2.3', |
| 980 |
dependencies: { |
| 981 |
a: '1.x', |
| 982 |
d: '2.x', |
| 983 |
}, |
| 984 |
}, |
| 985 |
children: [ |
| 986 |
{ pkg: { name: 'a', version: '1.0.1', dependencies: { b: '1' } } }, |
| 987 |
{ pkg: { name: 'd', version: '2.2.2', peerDependencies: { b: '2' } } }, |
| 988 |
{ pkg: { name: 'b', version: '2.2.2', peerDependencies: { c: '2' } } }, |
| 989 |
{ pkg: { name: 'c', version: '2.2.2' } }, |
| 990 |
], |
| 991 |
}), |
| 992 |
nodeLoc: 'node_modules/a', |
| 993 |
dep: new Node({ |
| 994 |
pkg: { name: 'b', version: '1.0.1', peerDependencies: { c: '1' } }, |
| 995 |
}), |
| 996 |
peerSet: [ |
| 997 |
{ pkg: { name: 'c', version: '1.0.1' } }, |
| 998 |
], |
| 999 |
explicitRequest: true, |
| 1000 |
}) |
| 1001 |
|
| 1002 |
// root -> (a@1, d@2) |
| 1003 |
// a@1 -> PEER(b@1) |
| 1004 |
// b@1 -> PEER(c@1) |
| 1005 |
// b@2 -> PEER(c@2) |
| 1006 |
// d@2 -> PEER(b@2) |
| 1007 |
// |
| 1008 |
// root |
| 1009 |
// +-- a@1 |
| 1010 |
// +-- b@2 (peer from d@2) |
| 1011 |
// +-- c@2 (peer from b@2) |
| 1012 |
// +-- d@2 |
| 1013 |
// place b@1(c@1) for a@1, expect ERESOLVE, because b conflicts, and |
| 1014 |
// neither can be pushed deeper. |
| 1015 |
runTest('existing peer set cannot be pushed deeper, neither can new set', { |
| 1016 |
tree: new Node({ |
| 1017 |
path, |
| 1018 |
pkg: { |
| 1019 |
name: 'project', |
| 1020 |
version: '1.2.3', |
| 1021 |
dependencies: { |
| 1022 |
a: '1.x', |
| 1023 |
d: '2.x', |
| 1024 |
}, |
| 1025 |
}, |
| 1026 |
children: [ |
| 1027 |
{ pkg: { name: 'a', version: '1.0.1', peerDependencies: { b: '1' } } }, |
| 1028 |
{ pkg: { name: 'd', version: '2.2.2', peerDependencies: { b: '2' } } }, |
| 1029 |
{ pkg: { name: 'b', version: '2.2.2', peerDependencies: { c: '2' } } }, |
| 1030 |
{ pkg: { name: 'c', version: '2.2.2' } }, |
| 1031 |
], |
| 1032 |
}), |
| 1033 |
nodeLoc: 'node_modules/a', |
| 1034 |
dep: new Node({ |
| 1035 |
pkg: { name: 'b', version: '1.0.1', peerDependencies: { c: '1' } }, |
| 1036 |
}), |
| 1037 |
peerSet: [ |
| 1038 |
{ pkg: { name: 'c', version: '1.0.1' } }, |
| 1039 |
], |
| 1040 |
explicitRequest: true, |
| 1041 |
error: true, |
| 1042 |
}) |
| 1043 |
|
| 1044 |
// root -> (a@1, d@1) |
| 1045 |
// a@1 -> (bb@1) PEER(c) |
| 1046 |
// bb@1 -> PEER(c@1) |
| 1047 |
// [email protected] -> PEER(c@1) |
| 1048 |
// [email protected] -> PEER(b@2) |
| 1049 |
// b@2 -> PEER(c@2) |
| 1050 |
// |
| 1051 |
// root |
| 1052 |
// +-- a@1 -> (bb@1) PEER(c) |
| 1053 |
// +-- bb@1 -> PEER(c@1) |
| 1054 |
// +-- c@1 |
| 1055 |
// +-- [email protected] -> PEER(c@1) |
| 1056 |
// |
| 1057 |
// place [email protected](b@2 c@2) and receive ERESOLVE, because |
| 1058 |
// the c@2 peer dep cannot be placed. |
| 1059 |
runTest('existing peer set cannot be pushed deeper, neither can new set, conflict on peer xyz', { |
| 1060 |
tree: new Node({ |
| 1061 |
path, |
| 1062 |
pkg: { |
| 1063 |
name: 'project', |
| 1064 |
version: '1.2.3', |
| 1065 |
dependencies: { |
| 1066 |
a: '1.x', |
| 1067 |
d: '1.x', |
| 1068 |
}, |
| 1069 |
}, |
| 1070 |
children: [ |
| 1071 |
// the bb dep could be nested, but it has a peerDep on c, and |
| 1072 |
// a would be fine with the c@2, but can't nest its c@1 dep |
| 1073 |
{ pkg: { name: 'a', version: '1.0.1', dependencies: { bb: '1' }, peerDependencies: { c: '*' } } }, |
| 1074 |
{ pkg: { name: 'bb', version: '1.0.1', peerDependencies: { c: '1' } } }, |
| 1075 |
{ pkg: { name: 'c', version: '1.0.1' } }, |
| 1076 |
{ pkg: { name: 'd', version: '1.1.1', peerDependencies: { c: '1' } } }, |
| 1077 |
], |
| 1078 |
}), |
| 1079 |
nodeLoc: '', |
| 1080 |
dep: new Node({ |
| 1081 |
pkg: { name: 'd', version: '1.2.2', peerDependencies: { b: '2' } }, |
| 1082 |
}), |
| 1083 |
peerSet: [ |
| 1084 |
{ pkg: { name: 'b', version: '2.2.2', peerDependencies: { c: '2' } } }, |
| 1085 |
{ pkg: { name: 'c', version: '2.2.2' } }, |
| 1086 |
], |
| 1087 |
explicitRequest: true, |
| 1088 |
error: true, |
| 1089 |
}) |
| 1090 |
|
| 1091 |
// root -> (a@1, d@1) |
| 1092 |
// [email protected] -> (bb@1), PEER(c) |
| 1093 |
// [email protected] -> (cc@1), PEER(c) |
| 1094 |
// [email protected] -> PEER(dd@1) |
| 1095 |
// [email protected] -> PEER(c@1) |
| 1096 |
// [email protected] -> PEER(c) |
| 1097 |
// [email protected] -> PEER(b@2) |
| 1098 |
// [email protected] -> PEER(c@2) |
| 1099 |
// |
| 1100 |
// root |
| 1101 |
// +-- [email protected] |
| 1102 |
// +-- [email protected] |
| 1103 |
// +-- [email protected] |
| 1104 |
// +-- [email protected] |
| 1105 |
// +-- [email protected] |
| 1106 |
// +-- [email protected] |
| 1107 |
// |
| 1108 |
// PLACE [email protected] in root. peerSet(b@2, c@2) |
| 1109 |
// REPLACE [email protected] |
| 1110 |
// OK b@2 (no current, no conflicting edges) |
| 1111 |
// [email protected] -> [email protected]? |
| 1112 |
// entry edges: |
| 1113 |
// root->(a): no replacement |
| 1114 |
// a->(c): replacement satisfies |
| 1115 |
// a->(bb): not a peer edge |
| 1116 |
// >> can replace |
| 1117 |
// a->(bb): |
| 1118 |
// bb->(c): replacement satisfies |
| 1119 |
// bb->(cc): not a peer edge |
| 1120 |
// root->(d): is cpd peerEntryEdge, skip |
| 1121 |
// bb->(cc): no replacement |
| 1122 |
// dd->(cc): not a peer edge |
| 1123 |
// >> can replace |
| 1124 |
|
| 1125 |
runTest('existing peer set cannot be pushed deeper, neither can new set, conflict on deep peer', { |
| 1126 |
tree: new Node({ |
| 1127 |
path, |
| 1128 |
pkg: { |
| 1129 |
name: 'project', |
| 1130 |
version: '1.2.3', |
| 1131 |
dependencies: { |
| 1132 |
a: '1.x', |
| 1133 |
d: '1.x', |
| 1134 |
}, |
| 1135 |
}, |
| 1136 |
children: [ |
| 1137 |
// the bb dep could be nested, but it has a peerDep on c, and |
| 1138 |
// a would be fine with the c@2, but can't nest its c@1 dep |
| 1139 |
{ pkg: { name: 'a', version: '1.0.1', dependencies: { bb: '1' }, peerDependencies: { c: '*' } } }, |
| 1140 |
{ pkg: { name: 'bb', version: '1.0.1', dependencies: { cc: '1' }, peerDependencies: { c: '*' } } }, |
| 1141 |
{ pkg: { name: 'cc', version: '1.0.1', peerDependencies: { dd: '1' } } }, |
| 1142 |
{ pkg: { name: 'dd', version: '1.0.1', peerDependencies: { c: '1' } } }, |
| 1143 |
{ pkg: { name: 'c', version: '1.0.1' } }, |
| 1144 |
{ pkg: { name: 'd', version: '1.1.1', peerDependencies: { c: '1' } } }, |
| 1145 |
], |
| 1146 |
}), |
| 1147 |
nodeLoc: '', |
| 1148 |
dep: new Node({ |
| 1149 |
pkg: { name: 'd', version: '1.2.2', peerDependencies: { b: '2' } }, |
| 1150 |
}), |
| 1151 |
peerSet: [ |
| 1152 |
{ pkg: { name: 'b', version: '2.2.2', peerDependencies: { c: '2' } } }, |
| 1153 |
{ pkg: { name: 'c', version: '2.2.2' } }, |
| 1154 |
], |
| 1155 |
explicitRequest: true, |
| 1156 |
error: true, |
| 1157 |
}) |
| 1158 |
|
| 1159 |
runTest('existing peer set cannot be pushed deeper, neither can new set, replacement satisfies', { |
| 1160 |
tree: new Node({ |
| 1161 |
path, |
| 1162 |
pkg: { |
| 1163 |
name: 'project', |
| 1164 |
version: '1.2.3', |
| 1165 |
dependencies: { |
| 1166 |
a: '1.x', |
| 1167 |
d: '1.x', |
| 1168 |
}, |
| 1169 |
}, |
| 1170 |
children: [ |
| 1171 |
// the bb dep could be nested, but it has a peerDep on c, and |
| 1172 |
// a would be fine with the c@2, but can't nest its c@1 dep |
| 1173 |
{ pkg: { name: 'a', version: '1.0.1', dependencies: { bb: '1' }, peerDependencies: { c: '*' } } }, |
| 1174 |
{ pkg: { name: 'bb', version: '1.0.1', dependencies: { cc: '1' }, peerDependencies: { c: '*' } } }, |
| 1175 |
{ pkg: { name: 'cc', version: '1.0.1', dependencies: { dd: '1' }, peerDependencies: { c: '*' } } }, |
| 1176 |
{ pkg: { name: 'dd', version: '1.0.1', peerDependencies: { c: '1' } } }, |
| 1177 |
{ pkg: { name: 'c', version: '1.0.1' } }, |
| 1178 |
{ pkg: { name: 'd', version: '1.1.1', peerDependencies: { c: '1' } } }, |
| 1179 |
], |
| 1180 |
}), |
| 1181 |
nodeLoc: '', |
| 1182 |
dep: new Node({ |
| 1183 |
pkg: { name: 'd', version: '1.2.2', peerDependencies: { b: '2' } }, |
| 1184 |
}), |
| 1185 |
peerSet: [ |
| 1186 |
{ pkg: { name: 'b', version: '2.2.2', peerDependencies: { c: '1' } } }, |
| 1187 |
{ pkg: { name: 'c', version: '1.2.2' } }, |
| 1188 |
], |
| 1189 |
explicitRequest: true, |
| 1190 |
}) |
| 1191 |
|
| 1192 |
// root -> (a) |
| 1193 |
// a -> (b, c) PEER(p) |
| 1194 |
// b -> (c@1, d@2) PEER(p) |
| 1195 |
// c@1 -> (d@1) PEER(p) |
| 1196 |
// c@2 -> (d@2) PEER(p) |
| 1197 |
// d@1 -> PEER(p@1) |
| 1198 |
// d@2 -> PEER(p@2) |
| 1199 |
// root |
| 1200 |
// +-- a |
| 1201 |
// +-- b |
| 1202 |
// | +-- c@1 |
| 1203 |
// | +-- d@1 <-- cannot place p@1 peer dep! |
| 1204 |
// +-- p@2 |
| 1205 |
// +-- c@2 |
| 1206 |
// +-- d@2 |
| 1207 |
runTest('peer all the way down, conflict but not ours', { |
| 1208 |
tree: new Node({ |
| 1209 |
path, |
| 1210 |
pkg: { dependencies: { a: '' } }, |
| 1211 |
children: [ |
| 1212 |
{ |
| 1213 |
pkg: { |
| 1214 |
name: 'a', |
| 1215 |
version: '1.0.0', |
| 1216 |
dependencies: { b: '', c: '' }, |
| 1217 |
peerDependencies: { p: '' }, |
| 1218 |
}, |
| 1219 |
}, |
| 1220 |
{ |
| 1221 |
pkg: { |
| 1222 |
name: 'b', |
| 1223 |
version: '1.0.0', |
| 1224 |
dependencies: { c: '1', d: '2' }, |
| 1225 |
peerDependencies: { p: '' }, |
| 1226 |
}, |
| 1227 |
children: [ |
| 1228 |
{ |
| 1229 |
pkg: { |
| 1230 |
name: 'c', |
| 1231 |
version: '1.0.0', |
| 1232 |
dependencies: { d: '1' }, // <-- the dep we'll try to place |
| 1233 |
peerDependencies: { p: '' }, |
| 1234 |
}, |
| 1235 |
}, |
| 1236 |
], |
| 1237 |
}, |
| 1238 |
{ pkg: { name: 'p', version: '2.0.0' } }, |
| 1239 |
{ pkg: { name: 'c', version: '2.0.0', peerDependencies: { p: '' } } }, |
| 1240 |
{ pkg: { name: 'd', version: '2.0.0', peerDependencies: { p: '2' } } }, |
| 1241 |
], |
| 1242 |
}), |
| 1243 |
dep: new Node({ |
| 1244 |
pkg: { name: 'd', version: '1.0.0', peerDependencies: { p: '1' } }, |
| 1245 |
}), |
| 1246 |
peerSet: [{ pkg: { name: 'p', version: '1.0.0' } }], |
| 1247 |
nodeLoc: 'node_modules/b/node_modules/c', |
| 1248 |
}) |
| 1249 |
|
| 1250 |
// root -> (a@1, b@2) |
| 1251 |
// a@1 -> PEER(b@1) |
| 1252 |
// b@1 -> PEER(c@1) |
| 1253 |
// c@1 -> PEER(d@1) |
| 1254 |
// d@1 -> PEER(e@1) |
| 1255 |
// e@1 -> PEER(a@1) |
| 1256 |
// a@2 -> PEER(b@2) |
| 1257 |
// b@2 -> PEER(c@2) |
| 1258 |
// c@2 -> PEER(d@2) |
| 1259 |
// d@2 -> PEER(e@2) |
| 1260 |
// e@2 -> PEER(a@2) |
| 1261 |
// root |
| 1262 |
// +-- a@1 |
| 1263 |
// +-- b@1 |
| 1264 |
// +-- c@1 |
| 1265 |
// +-- d@1 |
| 1266 |
// +-- e@1 |
| 1267 |
// place b@2, peerSet (c@2, d@2, e@2, a@2) |
| 1268 |
runTest('prod dep directly on conflicted peer, newer', { |
| 1269 |
tree: new Node({ |
| 1270 |
path, |
| 1271 |
pkg: { dependencies: { a: '1', b: '2' } }, |
| 1272 |
children: [ |
| 1273 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { b: '1' } } }, |
| 1274 |
{ pkg: { name: 'b', version: '1.0.0', peerDependencies: { c: '1' } } }, |
| 1275 |
{ pkg: { name: 'c', version: '1.0.0', peerDependencies: { d: '1' } } }, |
| 1276 |
{ pkg: { name: 'd', version: '1.0.0', peerDependencies: { e: '1' } } }, |
| 1277 |
{ pkg: { name: 'e', version: '1.0.0', peerDependencies: { a: '1' } } }, |
| 1278 |
], |
| 1279 |
}), |
| 1280 |
dep: new Node({ |
| 1281 |
pkg: { name: 'b', version: '2.0.0', peerDependencies: { c: '2' } }, |
| 1282 |
}), |
| 1283 |
peerSet: [ |
| 1284 |
{ pkg: { name: 'a', version: '2.0.0', peerDependencies: { b: '2' } } }, |
| 1285 |
{ pkg: { name: 'c', version: '2.0.0', peerDependencies: { d: '2' } } }, |
| 1286 |
{ pkg: { name: 'd', version: '2.0.0', peerDependencies: { e: '2' } } }, |
| 1287 |
{ pkg: { name: 'e', version: '2.0.0', peerDependencies: { a: '2' } } }, |
| 1288 |
], |
| 1289 |
nodeLoc: '', |
| 1290 |
error: true, |
| 1291 |
}) |
| 1292 |
|
| 1293 |
runTest('prod dep directly on conflicted peer, force, end of first step', { |
| 1294 |
tree: new Node({ |
| 1295 |
path, |
| 1296 |
pkg: { dependencies: { a: '1', b: '2' } }, |
| 1297 |
children: [ |
| 1298 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { b: '1' } } }, |
| 1299 |
{ pkg: { name: 'b', version: '2.0.0', peerDependencies: { c: '2' } } }, |
| 1300 |
{ pkg: { name: 'c', version: '2.0.0', peerDependencies: { d: '2' } } }, |
| 1301 |
{ pkg: { name: 'd', version: '2.0.0', peerDependencies: { e: '2' } } }, |
| 1302 |
{ pkg: { name: 'e', version: '2.0.0', peerDependencies: { a: '2' } } }, |
| 1303 |
], |
| 1304 |
}), |
| 1305 |
dep: new Node({ |
| 1306 |
pkg: { name: 'a', version: '2.0.0', peerDependencies: { b: '2' } }, |
| 1307 |
}), |
| 1308 |
peerSet: [ |
| 1309 |
{ pkg: { name: 'a', version: '2.0.0', peerDependencies: { b: '2' } } }, |
| 1310 |
{ pkg: { name: 'b', version: '2.0.0', peerDependencies: { c: '2' } } }, |
| 1311 |
{ pkg: { name: 'c', version: '2.0.0', peerDependencies: { d: '2' } } }, |
| 1312 |
{ pkg: { name: 'd', version: '2.0.0', peerDependencies: { e: '2' } } }, |
| 1313 |
{ pkg: { name: 'e', version: '2.0.0', peerDependencies: { a: '2' } } }, |
| 1314 |
], |
| 1315 |
nodeLoc: 'node_modules/e', |
| 1316 |
force: true, |
| 1317 |
}) |
| 1318 |
|
| 1319 |
// same as above test, but this time, the root has a@2, and |
| 1320 |
// we are attempting to add b@1 |
| 1321 |
runTest('prod dep directly on conflicted peer, older', { |
| 1322 |
tree: new Node({ |
| 1323 |
path, |
| 1324 |
pkg: { dependencies: { a: '2', b: '1' } }, |
| 1325 |
children: [ |
| 1326 |
{ pkg: { name: 'a', version: '2.0.0', peerDependencies: { b: '2' } } }, |
| 1327 |
{ pkg: { name: 'b', version: '2.0.0', peerDependencies: { c: '2' } } }, |
| 1328 |
{ pkg: { name: 'c', version: '2.0.0', peerDependencies: { d: '2' } } }, |
| 1329 |
{ pkg: { name: 'd', version: '2.0.0', peerDependencies: { e: '2' } } }, |
| 1330 |
{ pkg: { name: 'e', version: '2.0.0', peerDependencies: { a: '2' } } }, |
| 1331 |
], |
| 1332 |
}), |
| 1333 |
dep: new Node({ |
| 1334 |
pkg: { name: 'b', version: '1.0.0', peerDependencies: { c: '1' } }, |
| 1335 |
}), |
| 1336 |
peerSet: [ |
| 1337 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { b: '1' } } }, |
| 1338 |
{ pkg: { name: 'c', version: '1.0.0', peerDependencies: { d: '1' } } }, |
| 1339 |
{ pkg: { name: 'd', version: '1.0.0', peerDependencies: { e: '1' } } }, |
| 1340 |
{ pkg: { name: 'e', version: '1.0.0', peerDependencies: { a: '1' } } }, |
| 1341 |
], |
| 1342 |
nodeLoc: '', |
| 1343 |
error: true, |
| 1344 |
}) |
| 1345 |
|
| 1346 |
runTest('prod dep directly on conflicted peer, older, force', { |
| 1347 |
tree: new Node({ |
| 1348 |
path, |
| 1349 |
pkg: { dependencies: { a: '2', b: '1' } }, |
| 1350 |
children: [ |
| 1351 |
{ pkg: { name: 'a', version: '2.0.0', peerDependencies: { b: '2' } } }, |
| 1352 |
{ pkg: { name: 'b', version: '2.0.0', peerDependencies: { c: '2' } } }, |
| 1353 |
{ pkg: { name: 'c', version: '2.0.0', peerDependencies: { d: '2' } } }, |
| 1354 |
{ pkg: { name: 'd', version: '2.0.0', peerDependencies: { e: '2' } } }, |
| 1355 |
{ pkg: { name: 'e', version: '2.0.0', peerDependencies: { a: '2' } } }, |
| 1356 |
], |
| 1357 |
}), |
| 1358 |
dep: new Node({ |
| 1359 |
pkg: { name: 'b', version: '1.0.0', peerDependencies: { c: '1' } }, |
| 1360 |
}), |
| 1361 |
peerSet: [ |
| 1362 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { b: '1' } } }, |
| 1363 |
{ pkg: { name: 'c', version: '1.0.0', peerDependencies: { d: '1' } } }, |
| 1364 |
{ pkg: { name: 'd', version: '1.0.0', peerDependencies: { e: '1' } } }, |
| 1365 |
{ pkg: { name: 'e', version: '1.0.0', peerDependencies: { a: '1' } } }, |
| 1366 |
], |
| 1367 |
nodeLoc: '', |
| 1368 |
force: true, |
| 1369 |
}) |
| 1370 |
|
| 1371 |
// root -> (c@1||2, a@2) |
| 1372 |
// a@1 -> PEER(b@1) |
| 1373 |
// a@2 -> PEER(b@2) |
| 1374 |
// b@1 -> PEER(c@1) |
| 1375 |
// b@2 -> PEER(c@2) |
| 1376 |
// c@1 -> PEER(d@1) |
| 1377 |
// c@2 -> PEER(d@2) |
| 1378 |
// |
| 1379 |
// root |
| 1380 |
// +-- a@1 |
| 1381 |
// +-- b@1 |
| 1382 |
// +-- c@1 |
| 1383 |
// +-- d@1 |
| 1384 |
// |
| 1385 |
// place a@2 peerSet(b@2, c@2, d@2) |
| 1386 |
// |
| 1387 |
// peer group (c@1, d@1) can be replaced, because the entry node c has a |
| 1388 |
// valid replacement. |
| 1389 |
|
| 1390 |
runTest('have replacement for conflicted entry node', { |
| 1391 |
tree: new Node({ |
| 1392 |
path, |
| 1393 |
pkg: { dependencies: { a: '2', c: '1||2' } }, |
| 1394 |
children: [ |
| 1395 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { b: '1' } } }, |
| 1396 |
{ pkg: { name: 'b', version: '1.0.0', peerDependencies: { c: '1' } } }, |
| 1397 |
{ pkg: { name: 'c', version: '1.0.0', peerDependencies: { d: '1' } } }, |
| 1398 |
{ pkg: { name: 'd', version: '1.0.0' } }, |
| 1399 |
], |
| 1400 |
}), |
| 1401 |
dep: new Node({ |
| 1402 |
pkg: { name: 'a', version: '2.0.0', peerDependencies: { b: '2' } }, |
| 1403 |
}), |
| 1404 |
peerSet: [ |
| 1405 |
{ pkg: { name: 'b', version: '2.0.0', peerDependencies: { c: '2' } } }, |
| 1406 |
{ pkg: { name: 'c', version: '2.0.0', peerDependencies: { d: '2' } } }, |
| 1407 |
{ pkg: { name: 'd', version: '2.0.0' } }, |
| 1408 |
], |
| 1409 |
nodeLoc: '', |
| 1410 |
}) |
| 1411 |
|
| 1412 |
// v@4 -> PEER(a@1||2) |
| 1413 |
// y@1 -> PEER(d@1) |
| 1414 |
// a@1 -> PEER(b@1) |
| 1415 |
// b@1 -> PEER(c@1) |
| 1416 |
// c@1 -> PEER(d@1) |
| 1417 |
// d@1 -> PEER(e@1) |
| 1418 |
// e@1 -> PEER(a@1) |
| 1419 |
// a@2 -> PEER(b@2) |
| 1420 |
// b@2 -> PEER(c@2) |
| 1421 |
// c@2 -> PEER(d@2) |
| 1422 |
// d@2 -> PEER(e@2) |
| 1423 |
// e@2 -> PEER(a@2) |
| 1424 |
// |
| 1425 |
// root |
| 1426 |
// +-- v@4 |
| 1427 |
// +-- a@2 |
| 1428 |
// +-- b@2 |
| 1429 |
// +-- c@2 |
| 1430 |
// +-- d@2 |
| 1431 |
// +-- e@2 |
| 1432 |
// |
| 1433 |
// place y@1 (a@1, b@1, c@1, d@1, e@1), OK, because all peers replaced |
| 1434 |
runTest('replacing overlapping peer sets', { |
| 1435 |
tree: new Node({ |
| 1436 |
path, |
| 1437 |
pkg: { dependencies: { v: '4', y: '1' } }, |
| 1438 |
children: [ |
| 1439 |
{ |
| 1440 |
pkg: { |
| 1441 |
name: 'v', |
| 1442 |
version: '4.0.0', |
| 1443 |
peerDependencies: { a: '1||2', x: '2' }, |
| 1444 |
peerDependenciesMeta: { x: { optional: true } }, |
| 1445 |
}, |
| 1446 |
}, |
| 1447 |
{ pkg: { name: 'a', version: '2.0.0', peerDependencies: { b: '2' } } }, |
| 1448 |
{ pkg: { name: 'b', version: '2.0.0', peerDependencies: { c: '2' } } }, |
| 1449 |
{ pkg: { name: 'c', version: '2.0.0', peerDependencies: { d: '2' } } }, |
| 1450 |
{ pkg: { name: 'd', version: '2.0.0', peerDependencies: { e: '2' } } }, |
| 1451 |
{ pkg: { name: 'e', version: '2.0.0', peerDependencies: { a: '2' } } }, |
| 1452 |
], |
| 1453 |
}), |
| 1454 |
dep: new Node({ |
| 1455 |
pkg: { name: 'y', version: '1.0.0', peerDependencies: { d: '1' } }, |
| 1456 |
}), |
| 1457 |
peerSet: [ |
| 1458 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { b: '1' } } }, |
| 1459 |
{ pkg: { name: 'b', version: '1.0.0', peerDependencies: { c: '1' } } }, |
| 1460 |
{ pkg: { name: 'c', version: '1.0.0', peerDependencies: { d: '1' } } }, |
| 1461 |
{ pkg: { name: 'd', version: '1.0.0', peerDependencies: { e: '1' } } }, |
| 1462 |
{ pkg: { name: 'e', version: '1.0.0', peerDependencies: { a: '1' } } }, |
| 1463 |
], |
| 1464 |
nodeLoc: '', |
| 1465 |
}) |
| 1466 |
|
| 1467 |
// same as above, but the new peer set only overlaps _part_ of the existing |
| 1468 |
// v@4 -> PEER(a@1||2) |
| 1469 |
// y@1 -> PEER(d@1) |
| 1470 |
// a@1 -> PEER(c@1) |
| 1471 |
// c@1 -> PEER(e@1) |
| 1472 |
// e@1 -> PEER(a@1) |
| 1473 |
// a@2 -> PEER(b@2) |
| 1474 |
// b@2 -> PEER(c@2) |
| 1475 |
// c@2 -> PEER(d@2) |
| 1476 |
// d@2 -> PEER(e@2) |
| 1477 |
// e@2 -> PEER(a@2) |
| 1478 |
// |
| 1479 |
// root |
| 1480 |
// +-- v@4 |
| 1481 |
// +-- a@2 |
| 1482 |
// +-- b@2 |
| 1483 |
// +-- c@2 |
| 1484 |
// +-- d@2 |
| 1485 |
// +-- e@2 |
| 1486 |
// |
| 1487 |
// place y@1 (a@1, c@1, e@1), OK, because all peers replaced |
| 1488 |
runTest('replacing partially overlapping peer sets, subset', { |
| 1489 |
tree: new Node({ |
| 1490 |
path, |
| 1491 |
pkg: { dependencies: { v: '4', y: '1' } }, |
| 1492 |
children: [ |
| 1493 |
{ |
| 1494 |
pkg: { |
| 1495 |
name: 'v', |
| 1496 |
version: '4.0.0', |
| 1497 |
peerDependencies: { a: '1||2', x: '2' }, |
| 1498 |
peerDependenciesMeta: { x: { optional: true } }, |
| 1499 |
}, |
| 1500 |
}, |
| 1501 |
{ pkg: { name: 'a', version: '2.0.0', peerDependencies: { b: '2' } } }, |
| 1502 |
{ pkg: { name: 'b', version: '2.0.0', peerDependencies: { c: '2' } } }, |
| 1503 |
{ pkg: { name: 'c', version: '2.0.0', peerDependencies: { d: '2' } } }, |
| 1504 |
{ pkg: { name: 'd', version: '2.0.0', peerDependencies: { e: '2' } } }, |
| 1505 |
{ pkg: { name: 'e', version: '2.0.0', peerDependencies: { a: '2' } } }, |
| 1506 |
], |
| 1507 |
}), |
| 1508 |
dep: new Node({ |
| 1509 |
pkg: { name: 'y', version: '1.0.0', peerDependencies: { d: '1' } }, |
| 1510 |
}), |
| 1511 |
peerSet: [ |
| 1512 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { c: '1' } } }, |
| 1513 |
{ pkg: { name: 'c', version: '1.0.0', peerDependencies: { e: '1' } } }, |
| 1514 |
{ pkg: { name: 'e', version: '1.0.0', peerDependencies: { a: '1' } } }, |
| 1515 |
], |
| 1516 |
nodeLoc: '', |
| 1517 |
}) |
| 1518 |
|
| 1519 |
// same as above, but now the existing one has 3, replacement has 5 |
| 1520 |
// v@4 -> PEER(a@1||2) |
| 1521 |
// y@1 -> PEER(d@1) |
| 1522 |
// a@1 -> PEER(b@1) |
| 1523 |
// b@1 -> PEER(c@1) |
| 1524 |
// c@1 -> PEER(d@1) |
| 1525 |
// d@1 -> PEER(e@1) |
| 1526 |
// e@1 -> PEER(a@1) |
| 1527 |
// a@2 -> PEER(c@2) |
| 1528 |
// c@2 -> PEER(e@2) |
| 1529 |
// e@2 -> PEER(a@2) |
| 1530 |
// |
| 1531 |
// root |
| 1532 |
// +-- v@4 |
| 1533 |
// +-- a@2 |
| 1534 |
// +-- c@2 |
| 1535 |
// +-- e@2 |
| 1536 |
// |
| 1537 |
// place y@1 (a@1, b@1, c@1, d@1, e@1), OK, because all peers replaced |
| 1538 |
runTest('replacing partially overlapping peer sets, superset', { |
| 1539 |
tree: new Node({ |
| 1540 |
path, |
| 1541 |
pkg: { dependencies: { v: '4', y: '1' } }, |
| 1542 |
children: [ |
| 1543 |
{ |
| 1544 |
pkg: { |
| 1545 |
name: 'v', |
| 1546 |
version: '4.0.0', |
| 1547 |
peerDependencies: { a: '1||2', x: '2' }, |
| 1548 |
peerDependenciesMeta: { x: { optional: true } }, |
| 1549 |
}, |
| 1550 |
}, |
| 1551 |
{ pkg: { name: 'a', version: '2.0.0', peerDependencies: { c: '2' } } }, |
| 1552 |
{ pkg: { name: 'c', version: '2.0.0', peerDependencies: { e: '2' } } }, |
| 1553 |
{ pkg: { name: 'e', version: '2.0.0', peerDependencies: { a: '2' } } }, |
| 1554 |
], |
| 1555 |
}), |
| 1556 |
dep: new Node({ |
| 1557 |
pkg: { name: 'y', version: '1.0.0', peerDependencies: { d: '1' } }, |
| 1558 |
}), |
| 1559 |
peerSet: [ |
| 1560 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { b: '1' } } }, |
| 1561 |
{ pkg: { name: 'b', version: '1.0.0', peerDependencies: { c: '1' } } }, |
| 1562 |
{ pkg: { name: 'c', version: '1.0.0', peerDependencies: { d: '1' } } }, |
| 1563 |
{ pkg: { name: 'd', version: '1.0.0', peerDependencies: { e: '1' } } }, |
| 1564 |
{ pkg: { name: 'e', version: '1.0.0', peerDependencies: { a: '1' } } }, |
| 1565 |
], |
| 1566 |
nodeLoc: '', |
| 1567 |
}) |
| 1568 |
|
| 1569 |
// partly overlapping peer sets that diverge |
| 1570 |
// v -> PEER(a@1||2, x@1) |
| 1571 |
// a@1 -> PEER(c@1, d@1) |
| 1572 |
// a@2 -> PEER(c@2, e@1) |
| 1573 |
// x@1 -> PEER(y@1) |
| 1574 |
// y@1 -> PEER(a@1||2) |
| 1575 |
// w -> PEER(a@1, j@1) |
| 1576 |
// j@1 -> PEER(y@1) |
| 1577 |
// root |
| 1578 |
// +-- v |
| 1579 |
// +-- a@2 |
| 1580 |
// +-- c@2 |
| 1581 |
// +-- e@1 |
| 1582 |
// +-- x@1 |
| 1583 |
// +-- y@1 |
| 1584 |
// place w(a@1, j@1, y@1, c@1, d@1), OK |
| 1585 |
runTest('replacing partially overlapping divergent peer sets', { |
| 1586 |
tree: new Node({ |
| 1587 |
path, |
| 1588 |
pkg: { dependencies: { v: '', w: '' } }, |
| 1589 |
children: [ |
| 1590 |
{ |
| 1591 |
pkg: { |
| 1592 |
name: 'v', |
| 1593 |
version: '1.0.0', |
| 1594 |
peerDependencies: { a: '1||2', x: '1' }, |
| 1595 |
}, |
| 1596 |
}, |
| 1597 |
{ pkg: { name: 'a', version: '2.0.0', peerDependencies: { c: '2', e: '1' } } }, |
| 1598 |
{ pkg: { name: 'c', version: '2.0.0' } }, |
| 1599 |
{ pkg: { name: 'e', version: '1.0.0' } }, |
| 1600 |
{ pkg: { name: 'x', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1601 |
{ pkg: { name: 'y', version: '1.0.0', peerDependencies: { a: '1||2' } } }, |
| 1602 |
], |
| 1603 |
}), |
| 1604 |
dep: new Node({ |
| 1605 |
pkg: { name: 'w', version: '1.0.0', peerDependencies: { a: '1', j: '1' } }, |
| 1606 |
}), |
| 1607 |
peerSet: [ |
| 1608 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { c: '1', d: '1' } } }, |
| 1609 |
{ pkg: { name: 'j', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1610 |
{ pkg: { name: 'y', version: '1.0.0', peerDependencies: { a: '1||2' } } }, |
| 1611 |
{ pkg: { name: 'c', version: '1.0.0' } }, |
| 1612 |
{ pkg: { name: 'd', version: '1.0.0' } }, |
| 1613 |
], |
| 1614 |
nodeLoc: '', |
| 1615 |
}) |
| 1616 |
|
| 1617 |
// root -> (a@1, b@2) |
| 1618 |
// a@1 -> PEER(x@1) |
| 1619 |
// x@1 -> PEER(y@1) |
| 1620 |
// b@2 -> PEER(k@2) |
| 1621 |
// k@2 -> PEER(y@2) |
| 1622 |
// root |
| 1623 |
// +-- a@1 |
| 1624 |
// +-- x@1 |
| 1625 |
// +-- y@1 |
| 1626 |
// place b@2(k@2, y@2) and get a conflict on the y peerdep |
| 1627 |
runTest('fail with ERESOLVE on deep peer dep', { |
| 1628 |
tree: new Node({ |
| 1629 |
path, |
| 1630 |
pkg: { dependencies: { a: '1', b: '2' } }, |
| 1631 |
children: [ |
| 1632 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { x: '1' } } }, |
| 1633 |
{ pkg: { name: 'x', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1634 |
{ pkg: { name: 'y', version: '1.0.0' } }, |
| 1635 |
], |
| 1636 |
}), |
| 1637 |
dep: new Node({ |
| 1638 |
pkg: { name: 'b', version: '2.0.0', peerDependencies: { k: '2' } }, |
| 1639 |
}), |
| 1640 |
peerSet: [ |
| 1641 |
{ pkg: { name: 'k', version: '2.0.0', peerDependencies: { y: '2' } } }, |
| 1642 |
{ pkg: { name: 'y', version: '2.0.0' } }, |
| 1643 |
], |
| 1644 |
nodeLoc: '', |
| 1645 |
error: true, |
| 1646 |
}) |
| 1647 |
|
| 1648 |
// same as above, but not ours, so we override it |
| 1649 |
// root -> (v) |
| 1650 |
// v -> (a@1, b@2) |
| 1651 |
// a@1 -> PEER(x@1) |
| 1652 |
// x@1 -> PEER(y@1) |
| 1653 |
// b@2 -> PEER(k@2) |
| 1654 |
// k@2 -> PEER(y@2) |
| 1655 |
// root |
| 1656 |
// +-- v |
| 1657 |
// +-- a@1 |
| 1658 |
// +-- x@1 |
| 1659 |
// +-- y@1 |
| 1660 |
// place b@2(k@2, y@2) and override a conflict on the y peerdep |
| 1661 |
runTest('warn ERESOLVE on deep peer dep', { |
| 1662 |
tree: new Node({ |
| 1663 |
path, |
| 1664 |
pkg: { dependencies: { v: '' } }, |
| 1665 |
children: [ |
| 1666 |
{ |
| 1667 |
pkg: { |
| 1668 |
name: 'v', |
| 1669 |
version: '1.0.0', |
| 1670 |
dependencies: { a: '1', b: '2' }, |
| 1671 |
// this keeps either the a or b set from nesting the conflicted y |
| 1672 |
peerDependencies: { y: '' }, |
| 1673 |
}, |
| 1674 |
}, |
| 1675 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { x: '1' } } }, |
| 1676 |
{ pkg: { name: 'x', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1677 |
{ pkg: { name: 'y', version: '1.0.0' } }, |
| 1678 |
], |
| 1679 |
}), |
| 1680 |
dep: new Node({ |
| 1681 |
pkg: { name: 'b', version: '2.0.0', peerDependencies: { k: '2' } }, |
| 1682 |
}), |
| 1683 |
peerSet: [ |
| 1684 |
{ pkg: { name: 'k', version: '2.0.0', peerDependencies: { y: '2' } } }, |
| 1685 |
{ pkg: { name: 'y', version: '2.0.0' } }, |
| 1686 |
], |
| 1687 |
nodeLoc: 'node_modules/v', |
| 1688 |
}) |
| 1689 |
runTest('warn ERESOLVE on deep peer dep, step 2', { |
| 1690 |
tree: new Node({ |
| 1691 |
path, |
| 1692 |
pkg: { dependencies: { v: '' } }, |
| 1693 |
children: [ |
| 1694 |
{ |
| 1695 |
pkg: { |
| 1696 |
name: 'v', |
| 1697 |
version: '1.0.0', |
| 1698 |
dependencies: { a: '1', b: '2' }, |
| 1699 |
peerDependencies: { y: '' }, |
| 1700 |
}, |
| 1701 |
}, |
| 1702 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { x: '1' } } }, |
| 1703 |
{ pkg: { name: 'x', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1704 |
{ pkg: { name: 'y', version: '1.0.0' } }, |
| 1705 |
{ pkg: { name: 'b', version: '2.0.0', peerDependencies: { k: '2' } } }, |
| 1706 |
{ pkg: { name: 'k', version: '2.0.0', peerDependencies: { y: '2' } } }, |
| 1707 |
], |
| 1708 |
}), |
| 1709 |
dep: new Node({ pkg: { name: 'y', version: '2.0.0' } }), |
| 1710 |
nodeLoc: 'node_modules/k', |
| 1711 |
}) |
| 1712 |
runTest('warn ERESOLVE on deep peer dep, step 2, but with override', { |
| 1713 |
tree: new Node({ |
| 1714 |
path, |
| 1715 |
pkg: { dependencies: { v: '' } }, |
| 1716 |
children: [ |
| 1717 |
{ |
| 1718 |
pkg: { |
| 1719 |
name: 'v', |
| 1720 |
version: '1.0.0', |
| 1721 |
dependencies: { a: '1', b: '2' }, |
| 1722 |
peerDependencies: { y: '' }, |
| 1723 |
}, |
| 1724 |
}, |
| 1725 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { x: '1' } } }, |
| 1726 |
{ pkg: { name: 'x', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1727 |
{ pkg: { name: 'y', version: '1.0.0' } }, |
| 1728 |
{ pkg: { name: 'b', version: '2.0.0', peerDependencies: { k: '2' } } }, |
| 1729 |
{ pkg: { name: 'k', version: '2.0.0', peerDependencies: { y: '2' } } }, |
| 1730 |
], |
| 1731 |
}), |
| 1732 |
dep: new Node({ pkg: { name: 'y', version: '1.0.0' } }), |
| 1733 |
nodeLoc: 'node_modules/k', |
| 1734 |
}) |
| 1735 |
runTest('warn ERESOLVE on deep peer dep, step 2, override, no current', { |
| 1736 |
tree: new Node({ |
| 1737 |
path, |
| 1738 |
pkg: { dependencies: { v: '' } }, |
| 1739 |
children: [ |
| 1740 |
{ |
| 1741 |
pkg: { |
| 1742 |
name: 'v', |
| 1743 |
version: '1.0.0', |
| 1744 |
dependencies: { a: '1', b: '2' }, |
| 1745 |
peerDependencies: { y: '' }, |
| 1746 |
}, |
| 1747 |
}, |
| 1748 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { x: '1' } } }, |
| 1749 |
{ pkg: { name: 'x', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1750 |
// prod dep on k to exercise some isMine checking code paths |
| 1751 |
{ pkg: { name: 'b', version: '2.0.0', dependencies: { k: '2' }, peerDependencies: { c: '2' } } }, |
| 1752 |
{ pkg: { name: 'c', version: '2.0.0', peerDependencies: { k: '2' } } }, |
| 1753 |
{ pkg: { name: 'k', version: '2.0.0', peerDependencies: { y: '2' } } }, |
| 1754 |
], |
| 1755 |
}), |
| 1756 |
dep: new Node({ pkg: { name: 'y', version: '1.0.0' } }), |
| 1757 |
nodeLoc: 'node_modules/k', |
| 1758 |
}) |
| 1759 |
runTest('warn ERESOLVE on less deep peer dep, step 2, override, no current', { |
| 1760 |
tree: new Node({ |
| 1761 |
path, |
| 1762 |
pkg: { dependencies: { v: '' } }, |
| 1763 |
children: [ |
| 1764 |
{ |
| 1765 |
pkg: { |
| 1766 |
name: 'v', |
| 1767 |
version: '1.0.0', |
| 1768 |
dependencies: { a: '1', b: '2' }, |
| 1769 |
peerDependencies: { y: '' }, |
| 1770 |
}, |
| 1771 |
}, |
| 1772 |
{ pkg: { name: 'a', version: '1.0.0', peerDependencies: { x: '1' } } }, |
| 1773 |
{ pkg: { name: 'x', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1774 |
// prod dep, and no peer dep, on k to exercise some isMine checks |
| 1775 |
{ pkg: { name: 'b', version: '2.0.0', dependencies: { k: '2' }, peerDependencies: { y: '' } } }, |
| 1776 |
{ pkg: { name: 'k', version: '2.0.0', peerDependencies: { y: '2' } } }, |
| 1777 |
], |
| 1778 |
}), |
| 1779 |
dep: new Node({ pkg: { name: 'y', version: '1.0.0' } }), |
| 1780 |
nodeLoc: 'node_modules/k', |
| 1781 |
}) |
| 1782 |
|
| 1783 |
runTest('clobber and nest a peer set in favor of a root dep', { |
| 1784 |
tree: new Node({ |
| 1785 |
path, |
| 1786 |
pkg: { dependencies: { a: '1', x: '2' } }, |
| 1787 |
children: [ |
| 1788 |
{ pkg: { name: 'a', version: '1.0.0', dependencies: { b: '1' } } }, |
| 1789 |
{ pkg: { name: 'b', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1790 |
{ pkg: { name: 'y', version: '1.0.0' } }, |
| 1791 |
], |
| 1792 |
}), |
| 1793 |
dep: new Node({ |
| 1794 |
pkg: { name: 'x', version: '2.0.0', peerDependencies: { y: '2' } }, |
| 1795 |
}), |
| 1796 |
peerSet: [ |
| 1797 |
{ pkg: { name: 'y', version: '2.0.0' } }, |
| 1798 |
], |
| 1799 |
explicitRequest: true, |
| 1800 |
nodeLoc: '', |
| 1801 |
}) |
| 1802 |
runTest('clobber and nest a peer set in favor of a root dep, step 2', { |
| 1803 |
tree: new Node({ |
| 1804 |
path, |
| 1805 |
pkg: { dependencies: { a: '1', x: '2' } }, |
| 1806 |
children: [ |
| 1807 |
{ pkg: { name: 'a', version: '1.0.0', dependencies: { b: '1' } } }, |
| 1808 |
{ pkg: { name: 'b', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1809 |
{ pkg: { name: 'y', version: '1.0.0' } }, |
| 1810 |
{ pkg: { name: 'x', version: '2.0.0', peerDependencies: { y: '2' } } }, |
| 1811 |
], |
| 1812 |
}), |
| 1813 |
dep: new Node({ |
| 1814 |
pkg: { name: 'y', version: '2.0.0' }, |
| 1815 |
}), |
| 1816 |
nodeLoc: 'node_modules/x', |
| 1817 |
}) |
| 1818 |
|
| 1819 |
runTest('clobber and nest a non-peer dep in favor of a root dep peer', { |
| 1820 |
tree: new Node({ |
| 1821 |
path, |
| 1822 |
pkg: { dependencies: { a: '1', x: '2' } }, |
| 1823 |
children: [ |
| 1824 |
{ pkg: { name: 'a', version: '1.0.0', dependencies: { b: '1' } } }, |
| 1825 |
{ pkg: { name: 'b', version: '1.0.0', dependencies: { y: '1' } } }, |
| 1826 |
{ pkg: { name: 'y', version: '1.0.0' } }, |
| 1827 |
], |
| 1828 |
}), |
| 1829 |
dep: new Node({ |
| 1830 |
pkg: { name: 'x', version: '2.0.0', peerDependencies: { y: '2' } }, |
| 1831 |
}), |
| 1832 |
peerSet: [ |
| 1833 |
{ pkg: { name: 'y', version: '2.0.0' } }, |
| 1834 |
], |
| 1835 |
explicitRequest: true, |
| 1836 |
nodeLoc: '', |
| 1837 |
}) |
| 1838 |
runTest('clobber and nest a non-peer dep in favor of a root dep peer, step 2', { |
| 1839 |
tree: new Node({ |
| 1840 |
path, |
| 1841 |
pkg: { dependencies: { a: '1', x: '2' } }, |
| 1842 |
children: [ |
| 1843 |
{ pkg: { name: 'a', version: '1.0.0', dependencies: { b: '1' } } }, |
| 1844 |
{ pkg: { name: 'b', version: '1.0.0', dependencies: { y: '1' } } }, |
| 1845 |
{ pkg: { name: 'y', version: '1.0.0' } }, |
| 1846 |
{ pkg: { name: 'x', version: '2.0.0', peerDependencies: { y: '2' } } }, |
| 1847 |
], |
| 1848 |
}), |
| 1849 |
dep: new Node({ |
| 1850 |
pkg: { name: 'y', version: '2.0.0' }, |
| 1851 |
}), |
| 1852 |
nodeLoc: 'node_modules/x', |
| 1853 |
}) |
| 1854 |
|
| 1855 |
runTest('nest peer set of non-root dep', { |
| 1856 |
tree: new Node({ |
| 1857 |
path, |
| 1858 |
pkg: { dependencies: { a: '1', k: '2' } }, |
| 1859 |
children: [ |
| 1860 |
{ pkg: { name: 'a', version: '1.0.0', dependencies: { b: '1' } } }, |
| 1861 |
{ pkg: { name: 'b', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1862 |
{ pkg: { name: 'y', version: '1.0.0' } }, |
| 1863 |
{ pkg: { name: 'k', version: '2.0.0', dependencies: { x: '2' } } }, |
| 1864 |
], |
| 1865 |
}), |
| 1866 |
dep: new Node({ |
| 1867 |
pkg: { name: 'x', version: '2.0.0', peerDependencies: { y: '2' } }, |
| 1868 |
}), |
| 1869 |
peerSet: [ |
| 1870 |
{ pkg: { name: 'y', version: '2.0.0' } }, |
| 1871 |
], |
| 1872 |
nodeLoc: 'node_modules/k', |
| 1873 |
test: (t, tree) => { |
| 1874 |
const k = tree.children.get('k') |
| 1875 |
const x = k.resolve('x') |
| 1876 |
const y = x.resolve('y') |
| 1877 |
t.equal(y.location, 'node_modules/k/node_modules/y') |
| 1878 |
t.equal(x.location, 'node_modules/k/node_modules/x') |
| 1879 |
}, |
| 1880 |
}) |
| 1881 |
runTest('nest peer set of non-root dep, step 2', { |
| 1882 |
tree: new Node({ |
| 1883 |
path, |
| 1884 |
pkg: { dependencies: { a: '1', k: '2' } }, |
| 1885 |
children: [ |
| 1886 |
{ pkg: { name: 'a', version: '1.0.0', dependencies: { b: '1' } } }, |
| 1887 |
{ pkg: { name: 'b', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1888 |
{ pkg: { name: 'y', version: '1.0.0' } }, |
| 1889 |
{ |
| 1890 |
pkg: { name: 'k', version: '2.0.0', dependencies: { x: '2' } }, |
| 1891 |
children: [ |
| 1892 |
{ pkg: { name: 'x', version: '2.0.0', peerDependencies: { y: '2' } } }, |
| 1893 |
], |
| 1894 |
}, |
| 1895 |
], |
| 1896 |
}), |
| 1897 |
dep: new Node({ pkg: { name: 'y', version: '2.0.0' } }), |
| 1898 |
nodeLoc: 'node_modules/k/node_modules/x', |
| 1899 |
test: (t, tree) => { |
| 1900 |
const k = tree.children.get('k') |
| 1901 |
const x = k.resolve('x') |
| 1902 |
const y = x.resolve('y') |
| 1903 |
t.equal(y.location, 'node_modules/k/node_modules/y') |
| 1904 |
t.equal(x.location, 'node_modules/k/node_modules/x') |
| 1905 |
}, |
| 1906 |
}) |
| 1907 |
runTest('replace peer set of non-root dep already in root, step 2', { |
| 1908 |
tree: new Node({ |
| 1909 |
path, |
| 1910 |
pkg: { dependencies: { a: '1', k: '2' } }, |
| 1911 |
children: [ |
| 1912 |
{ pkg: { name: 'a', version: '1.0.0', dependencies: { b: '1', y: '1' } } }, |
| 1913 |
{ pkg: { name: 'b', version: '1.0.0', peerDependencies: { y: '1' } } }, |
| 1914 |
{ pkg: { name: 'y', version: '1.0.0' } }, |
| 1915 |
{ pkg: { name: 'k', version: '2.0.0', dependencies: { l: '2' } } }, |
| 1916 |
{ pkg: { name: 'l', version: '2.0.0', dependencies: { x: '2', y: '2' } } }, |
| 1917 |
{ pkg: { name: 'x', version: '2.0.0', peerDependencies: { y: '2' } } }, |
| 1918 |
], |
| 1919 |
}), |
| 1920 |
dep: new Node({ pkg: { name: 'y', version: '2.0.0' } }), |
| 1921 |
nodeLoc: 'node_modules/x', |
| 1922 |
test: (t, tree) => { |
| 1923 |
const k = tree.children.get('k') |
| 1924 |
const x = k.resolve('x') |
| 1925 |
const y = x.resolve('y') |
| 1926 |
t.equal(y.location, 'node_modules/y') |
| 1927 |
t.equal(x.location, 'node_modules/x') |
| 1928 |
t.equal(y.version, '2.0.0') |
| 1929 |
}, |
| 1930 |
}) |
| 1931 |
|
| 1932 |
runTest('place a link dep', { |
| 1933 |
tree: new Node({ |
| 1934 |
path, |
| 1935 |
pkg: { dependencies: { x: 'file:x' } }, |
| 1936 |
fsChildren: [ |
| 1937 |
{ path: `${path}/x`, pkg: { name: 'x', version: '1.2.3' } }, |
| 1938 |
], |
| 1939 |
}), |
| 1940 |
dep: new Link({ |
| 1941 |
realpath: `${path}/x`, |
| 1942 |
pkg: { name: 'x', version: '1.2.3' }, |
| 1943 |
}), |
| 1944 |
nodeLoc: '', |
| 1945 |
}) |
| 1946 |
|
| 1947 |
const overrides = new OverrideSet({ |
| 1948 |
overrides: { bar: '2' }, |
| 1949 |
}) |
| 1950 |
runTest('place a dep with an override', { |
| 1951 |
tree: new Node({ |
| 1952 |
path, |
| 1953 |
pkg: { |
| 1954 |
dependencies: { foo: '1' }, |
| 1955 |
overrides: { bar: '2' }, |
| 1956 |
}, |
| 1957 |
overrides, |
| 1958 |
}), |
| 1959 |
dep: new Node({ |
| 1960 |
pkg: { name: 'foo', version: '1.0.0' }, |
| 1961 |
overrides, |
| 1962 |
}), |
| 1963 |
nodeLoc: '', |
| 1964 |
}) |
| 1965 |
|
| 1966 |
// https://github.com/npm/arborist/issues/325 |
| 1967 |
runTest('prune competing peerSet that can be nested, 1', { |
| 1968 |
tree: new Node({ |
| 1969 |
path, |
| 1970 |
pkg: { dependencies: { a: '' } }, |
| 1971 |
children: [ |
| 1972 |
{ |
| 1973 |
pkg: { |
| 1974 |
name: 'a', |
| 1975 |
version: '1.0.0', |
| 1976 |
dependencies: { |
| 1977 |
j: '1', |
| 1978 |
x: '', |
| 1979 |
y: '', |
| 1980 |
}, |
| 1981 |
}, |
| 1982 |
}, |
| 1983 |
{ pkg: { name: 'j', version: '1.0.0' } }, |
| 1984 |
{ pkg: { name: 'x', version: '1.0.0', peerDependencies: { j: '1' } } }, |
| 1985 |
], |
| 1986 |
}), |
| 1987 |
dep: new Node({ |
| 1988 |
pkg: { name: 'y', version: '1.0.0', peerDependencies: { j: '2' } }, |
| 1989 |
}), |
| 1990 |
peerSet: [ |
| 1991 |
{ pkg: { name: 'j', version: '2.0.0' } }, |
| 1992 |
], |
| 1993 |
nodeLoc: 'node_modules/a', |
| 1994 |
}) |
| 1995 |
|
| 1996 |
runTest('prune competing peerSet that can be nested, 2', { |
| 1997 |
tree: new Node({ |
| 1998 |
path, |
| 1999 |
pkg: { dependencies: { a: '' } }, |
| 2000 |
children: [ |
| 2001 |
{ |
| 2002 |
pkg: { |
| 2003 |
name: 'a', |
| 2004 |
version: '1.0.0', |
| 2005 |
dependencies: { |
| 2006 |
j: '1', |
| 2007 |
x: '', |
| 2008 |
y: '', |
| 2009 |
}, |
| 2010 |
}, |
| 2011 |
}, |
| 2012 |
{ pkg: { name: 'j', version: '1.0.0' } }, |
| 2013 |
{ pkg: { name: 'x', version: '1.0.0', peerDependencies: { j: '1' } } }, |
| 2014 |
{ pkg: { name: 'y', version: '1.0.0', peerDependencies: { j: '2' } } }, |
| 2015 |
], |
| 2016 |
}), |
| 2017 |
dep: new Node({ pkg: { name: 'j', version: '2.0.0' } }), |
| 2018 |
nodeLoc: 'node_modules/y', |
| 2019 |
test: (t, tree, pd) => { |
| 2020 |
t.equal(tree.children.get('x'), undefined) |
| 2021 |
t.equal(tree.children.get('j').version, '2.0.0') |
| 2022 |
t.equal([...pd.needEvaluation][0], tree.children.get('a')) |
| 2023 |
}, |
| 2024 |
}) |
| 2025 |
|
| 2026 |
t.end() |
| 2027 |
}) |