fix: it should possible to use abolute file paths in overrides (#5757)

close #5754
This commit is contained in:
Zoltan Kochan
2022-12-06 11:36:47 +02:00
committed by GitHub
parent 3f644a514d
commit b11a8c363c
3 changed files with 28 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/hooks.read-package-hook": patch
"pnpm": patch
---
It should be possible to use overrides with absolute file paths [#5754](https://github.com/pnpm/pnpm/issues/5754).

View File

@@ -18,7 +18,8 @@ export function createVersionsOverrider (
}
let linkFileTarget: string | undefined
if (override.newPref.startsWith('file:')) {
linkFileTarget = path.join(rootDir, override.newPref.substring(5))
const pkgPath = override.newPref.substring(5)
linkFileTarget = path.isAbsolute(pkgPath) ? pkgPath : path.join(rootDir, pkgPath)
}
return {
...override,

View File

@@ -271,3 +271,23 @@ test('createVersionsOverrider() overrides dependencies with file', () => {
},
})
})
test('createVersionsOverrider() overrides dependencies with file specified with absolute path', () => {
const absolutePath = path.join(__dirname, 'qar')
const overrider = createVersionsOverrider({
qar: `file:${absolutePath}`,
}, process.cwd())
expect(overrider({
name: 'foo',
version: '1.2.0',
dependencies: {
qar: '3.0.0',
},
}, path.resolve('pkg'))).toStrictEqual({
name: 'foo',
version: '1.2.0',
dependencies: {
qar: `file:${absolutePath}`,
},
})
})