Skip to content

Commit

Permalink
fix: it should possible to use abolute file paths in overrides (#5757)
Browse files Browse the repository at this point in the history
close #5754
  • Loading branch information
zkochan committed Dec 6, 2022
1 parent 3f644a5 commit b11a8c3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/perfect-islands-trade.md
@@ -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).
3 changes: 2 additions & 1 deletion hooks/read-package-hook/src/createVersionsOverrider.ts
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions hooks/read-package-hook/test/createVersionOverrider.test.ts
Expand Up @@ -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}`,
},
})
})

0 comments on commit b11a8c3

Please sign in to comment.