Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/perfect-islands-trade.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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}`,
},
})
})