mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-30 10:38:13 -05:00
fix: pnpm link should update overrides in pnpm-workspace.yaml (#9365)
This commit is contained in:
6
.changeset/shiny-mammals-fold.md
Normal file
6
.changeset/shiny-mammals-fold.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-installation": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
`pnpm link` should update overrides in `pnpm-workspace.yaml`, not in `package.json` [#9365](https://github.com/pnpm/pnpm/pull/9365).
|
||||
@@ -36,6 +36,7 @@
|
||||
"@pnpm/command": "workspace:*",
|
||||
"@pnpm/common-cli-options-help": "workspace:*",
|
||||
"@pnpm/config": "workspace:*",
|
||||
"@pnpm/config.config-writer": "workspace:*",
|
||||
"@pnpm/constants": "workspace:*",
|
||||
"@pnpm/core": "workspace:*",
|
||||
"@pnpm/dedupe.check": "workspace:*",
|
||||
|
||||
@@ -2,9 +2,9 @@ import path from 'path'
|
||||
import {
|
||||
docsUrl,
|
||||
tryReadProjectManifest,
|
||||
type ReadProjectManifestOpts,
|
||||
} from '@pnpm/cli-utils'
|
||||
import { UNIVERSAL_OPTIONS } from '@pnpm/common-cli-options-help'
|
||||
import { writeSettings } from '@pnpm/config.config-writer'
|
||||
import { type Config, types as allTypes } from '@pnpm/config'
|
||||
import { DEPENDENCIES_FIELDS, type ProjectManifest, type Project } from '@pnpm/types'
|
||||
import { PnpmError } from '@pnpm/error'
|
||||
@@ -32,6 +32,7 @@ type LinkOpts = Pick<Config,
|
||||
| 'engineStrict'
|
||||
| 'rootProjectManifest'
|
||||
| 'rootProjectManifestDir'
|
||||
| 'overrides'
|
||||
| 'saveDev'
|
||||
| 'saveOptional'
|
||||
| 'saveProd'
|
||||
@@ -171,18 +172,21 @@ export async function handler (
|
||||
})
|
||||
}
|
||||
|
||||
async function addLinkToManifest (opts: ReadProjectManifestOpts, manifest: ProjectManifest, linkedDepDir: string, manifestDir: string) {
|
||||
if (!manifest.pnpm) {
|
||||
manifest.pnpm = {
|
||||
overrides: {},
|
||||
}
|
||||
} else if (!manifest.pnpm.overrides) {
|
||||
manifest.pnpm.overrides = {}
|
||||
}
|
||||
async function addLinkToManifest (opts: LinkOpts, manifest: ProjectManifest, linkedDepDir: string, manifestDir: string) {
|
||||
const { manifest: linkedManifest } = await tryReadProjectManifest(linkedDepDir, opts)
|
||||
const linkedPkgName = linkedManifest?.name ?? path.basename(linkedDepDir)
|
||||
const linkedPkgSpec = `link:${normalize(path.relative(manifestDir, linkedDepDir))}`
|
||||
manifest.pnpm.overrides![linkedPkgName] = linkedPkgSpec
|
||||
opts.overrides = {
|
||||
...opts.overrides,
|
||||
[linkedPkgName]: linkedPkgSpec,
|
||||
}
|
||||
await writeSettings({
|
||||
...opts,
|
||||
workspaceDir: opts.workspaceDir ?? opts.rootProjectManifestDir,
|
||||
updatedSettings: {
|
||||
overrides: opts.overrides,
|
||||
},
|
||||
})
|
||||
if (DEPENDENCIES_FIELDS.every((depField) => manifest[depField]?.[linkedPkgName] == null)) {
|
||||
manifest.dependencies = manifest.dependencies ?? {}
|
||||
manifest.dependencies[linkedPkgName] = linkedPkgSpec
|
||||
|
||||
@@ -7,6 +7,7 @@ import { fixtures } from '@pnpm/test-fixtures'
|
||||
import { logger } from '@pnpm/logger'
|
||||
import { sync as loadJsonFile } from 'load-json-file'
|
||||
import PATH from 'path-name'
|
||||
import { sync as readYamlFile } from 'read-yaml-file'
|
||||
import writePkg from 'write-pkg'
|
||||
import { DEFAULT_OPTS } from './utils'
|
||||
import { type PnpmError } from '@pnpm/error'
|
||||
@@ -148,8 +149,8 @@ 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 manifest = readYamlFile<{ overrides?: Record<string, string> }>('pnpm-workspace.yaml')
|
||||
expect(manifest.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({
|
||||
@@ -393,8 +394,8 @@ test('relative link from workspace package', async () => {
|
||||
workspacePackagePatterns: ['packages/*'],
|
||||
}, ['../../../hello-world-js-bin'])
|
||||
|
||||
const manifest = loadJsonFile<{ pnpm?: { overrides?: Record<string, string> } }>(path.join(workspaceDir, 'package.json'))
|
||||
expect(manifest.pnpm?.overrides?.['@pnpm.e2e/hello-world-js-bin']).toBe('link:../hello-world-js-bin')
|
||||
const manifest = readYamlFile<{ overrides?: Record<string, string> }>(path.join(workspaceDir, 'pnpm-workspace.yaml'))
|
||||
expect(manifest.overrides?.['@pnpm.e2e/hello-world-js-bin']).toBe('link:../hello-world-js-bin')
|
||||
|
||||
const workspace = assertProject(workspaceDir)
|
||||
;[workspace.readLockfile(), workspace.readCurrentLockfile()].forEach(lockfile => {
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
{
|
||||
"path": "../../config/config"
|
||||
},
|
||||
{
|
||||
"path": "../../config/config-writer"
|
||||
},
|
||||
{
|
||||
"path": "../../config/matcher"
|
||||
},
|
||||
|
||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -5371,6 +5371,9 @@ importers:
|
||||
'@pnpm/config':
|
||||
specifier: workspace:*
|
||||
version: link:../../config/config
|
||||
'@pnpm/config.config-writer':
|
||||
specifier: workspace:*
|
||||
version: link:../../config/config-writer
|
||||
'@pnpm/constants':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/constants
|
||||
|
||||
Reference in New Issue
Block a user