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: link overrides should be able to use absolute path #7749

Merged
merged 4 commits into from
Mar 10, 2024
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/hungry-mirrors-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/hooks.read-package-hook": patch
"pnpm": patch
---

Link overrides should be able to use absolute path [#7749](https://github.com/pnpm/pnpm/pull/7749).
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 @@ -17,7 +17,8 @@ export function createVersionsOverrider (
.map((override) => {
let linkTarget: string | undefined
if (override.newPref.startsWith('link:')) {
linkTarget = path.join(rootDir, override.newPref.substring(5))
const pkgPath = override.newPref.substring(5)
linkTarget = path.isAbsolute(pkgPath) ? pkgPath : path.join(rootDir, pkgPath)
}
let linkFileTarget: string | undefined
if (override.newPref.startsWith('file:')) {
Expand Down
22 changes: 22 additions & 0 deletions hooks/read-package-hook/test/createVersionOverrider.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path'
import { createVersionsOverrider } from '../lib/createVersionsOverrider'
import normalizePath from 'normalize-path'

test('createVersionsOverrider() matches sub-ranges', () => {
const overrider = createVersionsOverrider({
Expand Down Expand Up @@ -148,6 +149,27 @@ test('createVersionsOverrider() overrides dependencies with links', () => {
})
})

test('createVersionsOverrider() overrides dependencies with absolute links', () => {
const qarAbsolutePath = path.resolve(process.cwd(), './qar')
const overrider = createVersionsOverrider({
qar: `link:${qarAbsolutePath}`,
}, 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: `link:${normalizePath(path.relative(path.resolve('pkg'), qarAbsolutePath))}`,
},
})
})

test('createVersionsOverrider() overrides dependency of pkg matched by name and version', () => {
const overrider = createVersionsOverrider({
'yargs@^7.1.0>yargs-parser': '^20.0.0',
Expand Down