mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
fix: pnpm link should keep the indentations in the updated manifest
This commit is contained in:
5
.changeset/hip-cups-think.md
Normal file
5
.changeset/hip-cups-think.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/read-project-manifest": patch
|
||||
---
|
||||
|
||||
Export `WriteProjectManifest`.
|
||||
6
.changeset/tricky-planets-grab.md
Normal file
6
.changeset/tricky-planets-grab.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-installation": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
`pnpm link` should keep the indentation in the `package.json` file that it updates.
|
||||
@@ -0,0 +1,16 @@
|
||||
import path from 'path'
|
||||
import util from 'util'
|
||||
import { readProjectManifest, type WriteProjectManifest } from '@pnpm/read-project-manifest'
|
||||
import { writeProjectManifest } from '@pnpm/write-project-manifest'
|
||||
|
||||
export async function createProjectManifestWriter (projectDir: string): Promise<WriteProjectManifest> {
|
||||
try {
|
||||
const { writeProjectManifest } = await readProjectManifest(projectDir)
|
||||
return writeProjectManifest
|
||||
} catch (err) {
|
||||
if (util.types.isNativeError(err) && 'code' in err && err.code === 'ERR_PNPM_NO_IMPORTER_MANIFEST_FOUND') {
|
||||
return writeProjectManifest.bind(null, path.join(projectDir, 'package.json')) as WriteProjectManifest
|
||||
}
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import { DEPENDENCIES_FIELDS, type ProjectManifest, type Project } from '@pnpm/t
|
||||
import { PnpmError } from '@pnpm/error'
|
||||
import { arrayOfWorkspacePackagesToMap } from '@pnpm/get-context'
|
||||
import { findWorkspacePackages } from '@pnpm/workspace.find-packages'
|
||||
import { writeProjectManifest } from '@pnpm/write-project-manifest'
|
||||
import {
|
||||
type WorkspacePackages,
|
||||
} from '@pnpm/core'
|
||||
@@ -18,6 +17,7 @@ import { logger } from '@pnpm/logger'
|
||||
import pick from 'ramda/src/pick'
|
||||
import partition from 'ramda/src/partition'
|
||||
import renderHelp from 'render-help'
|
||||
import { createProjectManifestWriter } from './createProjectManifestWriter'
|
||||
import { getSaveType } from './getSaveType'
|
||||
import * as install from './install'
|
||||
|
||||
@@ -128,6 +128,8 @@ export async function handler (
|
||||
})
|
||||
}
|
||||
|
||||
const writeProjectManifest = await createProjectManifestWriter(opts.rootProjectManifestDir)
|
||||
|
||||
// pnpm link
|
||||
if ((params == null) || (params.length === 0)) {
|
||||
const cwd = process.cwd()
|
||||
@@ -139,7 +141,7 @@ export async function handler (
|
||||
|
||||
const newManifest = opts.rootProjectManifest ?? {}
|
||||
await addLinkToManifest(opts, newManifest, cwd, linkOpts.dir)
|
||||
await writeProjectManifest(path.join(opts.rootProjectManifestDir, 'package.json'), newManifest)
|
||||
await writeProjectManifest(newManifest)
|
||||
await install.handler({
|
||||
...linkOpts,
|
||||
frozenLockfileIfExists: false,
|
||||
@@ -160,7 +162,7 @@ export async function handler (
|
||||
})
|
||||
)
|
||||
|
||||
await writeProjectManifest(path.join(opts.rootProjectManifestDir, 'package.json'), newManifest)
|
||||
await writeProjectManifest(newManifest)
|
||||
await install.handler({
|
||||
...linkOpts,
|
||||
frozenLockfileIfExists: false,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import path from 'path'
|
||||
import { docsUrl } from '@pnpm/cli-utils'
|
||||
import { UNIVERSAL_OPTIONS } from '@pnpm/common-cli-options-help'
|
||||
import { writeProjectManifest } from '@pnpm/write-project-manifest'
|
||||
import renderHelp from 'render-help'
|
||||
import { createProjectManifestWriter } from './createProjectManifestWriter'
|
||||
import * as install from './install'
|
||||
|
||||
export const cliOptionsTypes = install.cliOptionsTypes
|
||||
@@ -58,7 +57,8 @@ export async function handler (
|
||||
}
|
||||
}
|
||||
}
|
||||
await writeProjectManifest(path.join(opts.rootProjectManifestDir, 'package.json'), opts.rootProjectManifest)
|
||||
const writeProjectManifest = await createProjectManifestWriter(opts.rootProjectManifestDir)
|
||||
await writeProjectManifest(opts.rootProjectManifest)
|
||||
await install.handler(opts)
|
||||
return undefined
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
readJsonFile,
|
||||
} from './readFile'
|
||||
|
||||
type WriteProjectManifest = (manifest: ProjectManifest, force?: boolean) => Promise<void>
|
||||
export type WriteProjectManifest = (manifest: ProjectManifest, force?: boolean) => Promise<void>
|
||||
|
||||
export async function safeReadProjectManifestOnly (projectDir: string): Promise<ProjectManifest | null> {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user