Skip to content

Commit

Permalink
fix: link overrides should be able to use absolute path (#7749)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjrhgvbn committed Mar 10, 2024
1 parent 8fc5b22 commit 0963390
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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

0 comments on commit 0963390

Please sign in to comment.