mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-26 00:28:10 -05:00
feat(link): normalize generated link paths in package.json (#9163)
This commit is contained in:
6
.changeset/olive-phones-rule.md
Normal file
6
.changeset/olive-phones-rule.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-installation": patch
|
||||
pnpm: patch
|
||||
---
|
||||
|
||||
Normalize generated link paths in `package.json` [#9163](https://github.com/pnpm/pnpm/pull/9163)
|
||||
@@ -48,7 +48,6 @@
|
||||
"@types/zkochan__table": "catalog:",
|
||||
"delay": "catalog:",
|
||||
"jest-diff": "catalog:",
|
||||
"normalize-path": "catalog:",
|
||||
"path-name": "catalog:",
|
||||
"proxyquire": "catalog:",
|
||||
"read-yaml-file": "catalog:",
|
||||
@@ -108,6 +107,7 @@
|
||||
"is-subdir": "catalog:",
|
||||
"load-json-file": "catalog:",
|
||||
"mem": "catalog:",
|
||||
"normalize-path": "catalog:",
|
||||
"p-filter": "catalog:",
|
||||
"p-limit": "catalog:",
|
||||
"ramda": "catalog:",
|
||||
|
||||
@@ -20,6 +20,7 @@ import renderHelp from 'render-help'
|
||||
import { createProjectManifestWriter } from './createProjectManifestWriter'
|
||||
import { getSaveType } from './getSaveType'
|
||||
import * as install from './install'
|
||||
import normalize from 'normalize-path'
|
||||
|
||||
// @ts-expect-error
|
||||
const isWindows = process.platform === 'win32' || global['FAKE_WINDOWS']
|
||||
@@ -180,7 +181,7 @@ async function addLinkToManifest (opts: ReadProjectManifestOpts, manifest: Proje
|
||||
}
|
||||
const { manifest: linkedManifest } = await tryReadProjectManifest(linkedDepDir, opts)
|
||||
const linkedPkgName = linkedManifest?.name ?? path.basename(linkedDepDir)
|
||||
const linkedPkgSpec = `link:${path.relative(manifestDir, linkedDepDir)}`
|
||||
const linkedPkgSpec = `link:${normalize(path.relative(manifestDir, linkedDepDir))}`
|
||||
manifest.pnpm.overrides![linkedPkgName] = linkedPkgSpec
|
||||
if (DEPENDENCIES_FIELDS.every((depField) => manifest[depField]?.[linkedPkgName] == null)) {
|
||||
manifest.dependencies = manifest.dependencies ?? {}
|
||||
|
||||
@@ -11,7 +11,6 @@ import writePkg from 'write-pkg'
|
||||
import { DEFAULT_OPTS } from './utils'
|
||||
import { type PnpmError } from '@pnpm/error'
|
||||
import { sync as writeYamlFile } from 'write-yaml-file'
|
||||
import normalize from 'normalize-path'
|
||||
|
||||
const f = fixtures(__dirname)
|
||||
|
||||
@@ -149,6 +148,9 @@ test('relative link', async () => {
|
||||
|
||||
project.isExecutable('.bin/hello-world-js-bin')
|
||||
|
||||
const manifest = loadJsonFile<{ pnpm?: { overrides?: Record<string, string> } }>('package.json')
|
||||
expect(manifest.pnpm?.overrides?.['@pnpm.e2e/hello-world-js-bin']).toBe('link:../hello-world-js-bin')
|
||||
|
||||
const wantedLockfile = project.readLockfile()
|
||||
expect(wantedLockfile.importers['.'].dependencies?.['@pnpm.e2e/hello-world-js-bin']).toStrictEqual({
|
||||
specifier: 'link:../hello-world-js-bin',
|
||||
@@ -392,13 +394,13 @@ test('relative link from workspace package', async () => {
|
||||
}, ['../../../hello-world-js-bin'])
|
||||
|
||||
const manifest = loadJsonFile<{ pnpm?: { overrides?: Record<string, string> } }>(path.join(workspaceDir, 'package.json'))
|
||||
expect(normalize(manifest.pnpm?.overrides?.['@pnpm.e2e/hello-world-js-bin'] ?? '')).toBe('link:../hello-world-js-bin')
|
||||
expect(manifest.pnpm?.overrides?.['@pnpm.e2e/hello-world-js-bin']).toBe('link:../hello-world-js-bin')
|
||||
|
||||
const workspace = assertProject(workspaceDir)
|
||||
;[workspace.readLockfile(), workspace.readCurrentLockfile()].forEach(lockfile => {
|
||||
expect(normalize(lockfile.importers['.'].dependencies?.['@pnpm.e2e/hello-world-js-bin'].version ?? ''))
|
||||
expect(lockfile.importers['.'].dependencies?.['@pnpm.e2e/hello-world-js-bin'].version)
|
||||
.toBe('link:../hello-world-js-bin')
|
||||
expect(normalize(lockfile.importers['packages/project'].dependencies?.['@pnpm.e2e/hello-world-js-bin'].version ?? ''))
|
||||
expect(lockfile.importers['packages/project'].dependencies?.['@pnpm.e2e/hello-world-js-bin'].version)
|
||||
.toBe('link:../../../hello-world-js-bin')
|
||||
})
|
||||
|
||||
|
||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -5324,6 +5324,9 @@ importers:
|
||||
mem:
|
||||
specifier: 'catalog:'
|
||||
version: 8.1.1
|
||||
normalize-path:
|
||||
specifier: 'catalog:'
|
||||
version: 3.0.0
|
||||
p-filter:
|
||||
specifier: 'catalog:'
|
||||
version: 2.1.0
|
||||
@@ -5397,9 +5400,6 @@ importers:
|
||||
jest-diff:
|
||||
specifier: 'catalog:'
|
||||
version: 29.7.0
|
||||
normalize-path:
|
||||
specifier: 'catalog:'
|
||||
version: 3.0.0
|
||||
path-name:
|
||||
specifier: 'catalog:'
|
||||
version: 1.0.0
|
||||
|
||||
Reference in New Issue
Block a user