mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-27 18:46:18 -04:00
fix: link overrides should be able to use absolute path (#7749)
This commit is contained in:
6
.changeset/hungry-mirrors-thank.md
Normal file
6
.changeset/hungry-mirrors-thank.md
Normal file
@@ -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).
|
||||
@@ -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:')) {
|
||||
|
||||
@@ -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({
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user