Skip to content

Commit 8f6eb6b

Browse files
authored
fix(arborist): fix file dep making wrong link (#8312)
Fixes #8302 @owlstronaut This was caused by 815311b
1 parent 9cb9d50 commit 8f6eb6b

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

workspaces/arborist/lib/arborist/reify.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -871,13 +871,9 @@ module.exports = cls => class Reifier extends cls {
871871
return relative(dir, resolve(rootDir, overridePath))
872872
}
873873

874-
// Fallback: derive the package name from node.resolved in a platform-agnostic way
874+
// Fallback: derive the file path from node.resolved in a platform-agnostic way
875875
const filePath = node.resolved.replace(/^file:/, '')
876-
// A node.package.name could be different than the folder name
877-
const pathParts = filePath.split(/[\\/]/)
878-
const packageName = pathParts[pathParts.length - 1]
879-
880-
return join('..', packageName)
876+
return join(filePath)
881877
}
882878

883879
#registryResolved (resolved) {

workspaces/arborist/test/arborist/reify.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3209,7 +3209,7 @@ t.test('root overrides with file: paths are visible to workspaces', async t => {
32093209
const path = t.testdir({
32103210
'package.json': JSON.stringify({
32113211
name: 'root',
3212-
workspaces: ['hello'],
3212+
workspaces: ['hello', 'nested/goodbye'],
32133213
dependencies: {},
32143214
overrides: {
32153215
print: 'file:./print',
@@ -3224,6 +3224,17 @@ t.test('root overrides with file: paths are visible to workspaces', async t => {
32243224
},
32253225
}),
32263226
},
3227+
nested: {
3228+
goodbye: {
3229+
'package.json': JSON.stringify({
3230+
name: 'second',
3231+
version: '1.0.0',
3232+
dependencies: {
3233+
print: '../print',
3234+
},
3235+
}),
3236+
},
3237+
},
32273238
print: {
32283239
'package.json': JSON.stringify({
32293240
name: 'print',
@@ -3237,6 +3248,7 @@ t.test('root overrides with file: paths are visible to workspaces', async t => {
32373248
await reify(path)
32383249

32393250
const printSymlink = fs.readlinkSync(resolve(path, 'node_modules/print'))
3251+
const secondSymlink = fs.readlinkSync(resolve(path, 'node_modules/second'))
32403252

32413253
// Create a platform-agnostic way to compare symlink targets
32423254
const normalizeLinkTarget = target => {
@@ -3254,6 +3266,12 @@ t.test('root overrides with file: paths are visible to workspaces', async t => {
32543266
'../print',
32553267
'print symlink points to ../print (normalized for platform)'
32563268
)
3269+
3270+
t.equal(
3271+
normalizeLinkTarget(secondSymlink),
3272+
'../nested/goodbye',
3273+
'print symlink points to ../nested/goodbye (normalized for platform)'
3274+
)
32573275
})
32583276

32593277
t.test('should preserve exact ranges, missing actual tree', async (t) => {

0 commit comments

Comments
 (0)