Skip to content

Commit 646b6b5

Browse files
authoredJun 1, 2022
fix(arborist): use rawSpec for bundled and shrinkwrapped deps (#4963)
1 parent 825e595 commit 646b6b5

File tree

2 files changed

+116
-1
lines changed

2 files changed

+116
-1
lines changed
 

‎workspaces/arborist/lib/edge.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ class Edge {
9292
return false
9393
}
9494

95-
return depValid(node, this.spec, this.accept, this.from)
95+
// NOTE: this condition means we explicitly do not support overriding
96+
// bundled or shrinkwrapped dependencies
97+
const spec = (node.hasShrinkwrap || node.inShrinkwrap || node.inBundle)
98+
? this.rawSpec
99+
: this.spec
100+
return depValid(node, spec, this.accept, this.from)
96101
}
97102

98103
explain (seen = []) {

‎workspaces/arborist/test/edge.js

+110
Original file line numberDiff line numberDiff line change
@@ -808,3 +808,113 @@ t.same(bundledEdge.explain(), {
808808
bundled: true,
809809
from: bundleParent.explain(),
810810
}, 'bundled edge.explain as expected')
811+
812+
t.test('shrinkwrapped and bundled deps are not overridden and remain valid', (t) => {
813+
const overrides = new OverrideSet({
814+
overrides: {
815+
bar: '^2.0.0',
816+
},
817+
})
818+
819+
const root = {
820+
name: 'root',
821+
packageName: 'root',
822+
edgesOut: new Map(),
823+
edgesIn: new Set(),
824+
explain: () => 'root node explanation',
825+
package: {
826+
name: 'root',
827+
version: '1.2.3',
828+
dependencies: {
829+
foo: '^1.0.0',
830+
},
831+
overrides: {
832+
bar: '^2.0.0',
833+
},
834+
},
835+
get version () {
836+
return this.package.version
837+
},
838+
isTop: true,
839+
parent: null,
840+
overrides,
841+
resolve (n) {
842+
return n === 'foo' ? foo : null
843+
},
844+
addEdgeOut (edge) {
845+
this.edgesOut.set(edge.name, edge)
846+
},
847+
addEdgeIn (edge) {
848+
this.edgesIn.add(edge)
849+
},
850+
}
851+
852+
const foo = {
853+
name: 'foo',
854+
packageName: 'foo',
855+
edgesOut: new Map(),
856+
edgesIn: new Set(),
857+
explain: () => 'foo node explanation',
858+
hasShrinkwrap: true,
859+
package: {
860+
name: 'foo',
861+
version: '1.2.3',
862+
dependencies: {
863+
bar: '^1.0.0',
864+
},
865+
},
866+
get version () {
867+
return this.package.version
868+
},
869+
parent: root,
870+
resolve (n) {
871+
return n === 'bar' ? bar : this.parent.resolve(n)
872+
},
873+
addEdgeOut (edge) {
874+
this.edgesOut.set(edge.name, edge)
875+
},
876+
addEdgeIn (edge) {
877+
this.edgesIn.add(edge)
878+
},
879+
}
880+
foo.overrides = overrides.getNodeRule(foo)
881+
882+
const bar = {
883+
name: 'bar',
884+
packageName: 'bar',
885+
edgesOut: new Map(),
886+
edgesIn: new Set(),
887+
explain: () => 'bar node explanation',
888+
inShrinkwrap: true,
889+
package: {
890+
name: 'bar',
891+
version: '1.2.3',
892+
dependencies: {},
893+
},
894+
get version () {
895+
return this.package.version
896+
},
897+
parent: foo,
898+
resolve (n) {
899+
return this.parent.resolve(n)
900+
},
901+
addEdgeOut (edge) {
902+
this.edgesOut.set(edge.name, edge)
903+
},
904+
addEdgeIn (edge) {
905+
this.edgesIn.add(edge)
906+
},
907+
}
908+
bar.overrides = foo.overrides.getNodeRule(bar)
909+
910+
const edge = new Edge({
911+
from: foo,
912+
type: 'prod',
913+
spec: '^1.0.0',
914+
name: 'bar',
915+
overrides: overrides.getEdgeRule({ name: 'bar', spec: '^1.0.0' }),
916+
})
917+
918+
t.ok(edge.valid, 'edge is valid')
919+
t.end()
920+
})

0 commit comments

Comments
 (0)
Please sign in to comment.