mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-30 10:38:13 -05:00
feat: setting patchedDependencies write to pnpm-workspace.yaml (#9248)
close #9305 Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
5
.changeset/silly-pants-march.md
Normal file
5
.changeset/silly-pants-march.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-patching": patch
|
||||
---
|
||||
|
||||
When executing the `patch-commit` command, if `patchedDependencies` does not exist in `package.json`, the configuration will be written to `pnpm-workspace.yaml`.
|
||||
@@ -34,6 +34,7 @@
|
||||
"dependencies": {
|
||||
"@pnpm/cli-utils": "workspace:*",
|
||||
"@pnpm/config": "workspace:*",
|
||||
"@pnpm/config.config-writer": "workspace:*",
|
||||
"@pnpm/constants": "workspace:*",
|
||||
"@pnpm/crypto.hash": "workspace:*",
|
||||
"@pnpm/error": "workspace:*",
|
||||
@@ -51,6 +52,7 @@
|
||||
"@pnpm/store-connection-manager": "workspace:*",
|
||||
"@pnpm/store-path": "workspace:*",
|
||||
"@pnpm/types": "workspace:*",
|
||||
"@pnpm/workspace.read-manifest": "workspace:*",
|
||||
"chalk": "catalog:",
|
||||
"enquirer": "catalog:",
|
||||
"escape-string-regexp": "catalog:",
|
||||
|
||||
@@ -16,7 +16,6 @@ import { writePackage } from './writePackage'
|
||||
import { getEditDirPath } from './getEditDirPath'
|
||||
import { type GetPatchedDependencyResult, getPatchedDependency } from './getPatchedDependency'
|
||||
import { writeEditDirState } from './stateFile'
|
||||
import { tryReadProjectManifest } from '@pnpm/read-project-manifest'
|
||||
import isWindows from 'is-windows'
|
||||
|
||||
export function rcOptionsTypes (): Record<string, unknown> {
|
||||
@@ -56,6 +55,7 @@ export function help (): string {
|
||||
|
||||
export type PatchCommandOptions = Pick<Config,
|
||||
| 'dir'
|
||||
| 'patchedDependencies'
|
||||
| 'registries'
|
||||
| 'tag'
|
||||
| 'storeDir'
|
||||
@@ -104,23 +104,14 @@ export async function handler (opts: PatchCommandOptions, params: string[]): Pro
|
||||
applyToAll: patchedDep.applyToAll,
|
||||
})
|
||||
|
||||
if (!opts.ignoreExisting) {
|
||||
let rootProjectManifest = opts.rootProjectManifest
|
||||
if (!opts.sharedWorkspaceLockfile) {
|
||||
const { manifest } = await tryReadProjectManifest(lockfileDir)
|
||||
if (manifest) {
|
||||
rootProjectManifest = manifest
|
||||
}
|
||||
}
|
||||
if (rootProjectManifest?.pnpm?.patchedDependencies) {
|
||||
tryPatchWithExistingPatchFile({
|
||||
allowFailure: patchedDep.applyToAll,
|
||||
patchedDep,
|
||||
patchedDir: editDir,
|
||||
patchedDependencies: rootProjectManifest.pnpm.patchedDependencies,
|
||||
lockfileDir,
|
||||
})
|
||||
}
|
||||
if (!opts.ignoreExisting && opts.patchedDependencies) {
|
||||
tryPatchWithExistingPatchFile({
|
||||
allowFailure: patchedDep.applyToAll,
|
||||
patchedDep,
|
||||
patchedDir: editDir,
|
||||
patchedDependencies: opts.patchedDependencies,
|
||||
lockfileDir,
|
||||
})
|
||||
}
|
||||
|
||||
const quote = isWindows() ? '"' : "'"
|
||||
|
||||
@@ -2,13 +2,13 @@ import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { docsUrl } from '@pnpm/cli-utils'
|
||||
import { type Config, types as allTypes } from '@pnpm/config'
|
||||
import { writeSettings } from '@pnpm/config.config-writer'
|
||||
import { createShortHash } from '@pnpm/crypto.hash'
|
||||
import { PnpmError } from '@pnpm/error'
|
||||
import { packlist } from '@pnpm/fs.packlist'
|
||||
import { globalWarn } from '@pnpm/logger'
|
||||
import { install } from '@pnpm/plugin-commands-installation'
|
||||
import { readPackageJsonFromDir } from '@pnpm/read-package-json'
|
||||
import { tryReadProjectManifest } from '@pnpm/read-project-manifest'
|
||||
import { getStorePath } from '@pnpm/store-path'
|
||||
import { type ProjectRootDir } from '@pnpm/types'
|
||||
import { glob } from 'tinyglobby'
|
||||
@@ -49,7 +49,7 @@ export function help (): string {
|
||||
})
|
||||
}
|
||||
|
||||
type PatchCommitCommandOptions = install.InstallCommandOptions & Pick<Config, 'patchesDir' | 'rootProjectManifest' | 'rootProjectManifestDir'>
|
||||
type PatchCommitCommandOptions = install.InstallCommandOptions & Pick<Config, 'patchesDir' | 'rootProjectManifest' | 'rootProjectManifestDir' | 'patchedDependencies'>
|
||||
|
||||
export async function handler (opts: PatchCommitCommandOptions, params: string[]): Promise<string | undefined> {
|
||||
const userDir = params[0]
|
||||
@@ -99,32 +99,22 @@ export async function handler (opts: PatchCommitCommandOptions, params: string[]
|
||||
|
||||
const patchFileName = patchKey.replace('/', '__')
|
||||
await fs.promises.writeFile(path.join(patchesDir, `${patchFileName}.patch`), patchContent, 'utf8')
|
||||
const { writeProjectManifest, manifest } = await tryReadProjectManifest(lockfileDir)
|
||||
|
||||
const rootProjectManifest = (!opts.sharedWorkspaceLockfile ? manifest : (opts.rootProjectManifest ?? manifest)) ?? {}
|
||||
|
||||
if (!rootProjectManifest.pnpm) {
|
||||
rootProjectManifest.pnpm = {
|
||||
patchedDependencies: {},
|
||||
}
|
||||
} else if (!rootProjectManifest.pnpm.patchedDependencies) {
|
||||
rootProjectManifest.pnpm.patchedDependencies = {}
|
||||
}
|
||||
rootProjectManifest.pnpm.patchedDependencies![patchKey] = `${patchesDirName}/${patchFileName}.patch`
|
||||
await writeProjectManifest(rootProjectManifest)
|
||||
|
||||
if (opts?.selectedProjectsGraph?.[lockfileDir]) {
|
||||
opts.selectedProjectsGraph[lockfileDir].package.manifest = rootProjectManifest
|
||||
}
|
||||
|
||||
if (opts?.allProjectsGraph?.[lockfileDir].package.manifest) {
|
||||
opts.allProjectsGraph[lockfileDir].package.manifest = rootProjectManifest
|
||||
const patchedDependencies = {
|
||||
...opts.patchedDependencies,
|
||||
[patchKey]: `${patchesDirName}/${patchFileName}.patch`,
|
||||
}
|
||||
await writeSettings({
|
||||
...opts,
|
||||
workspaceDir: opts.workspaceDir ?? opts.rootProjectManifestDir,
|
||||
updatedSettings: {
|
||||
patchedDependencies,
|
||||
},
|
||||
})
|
||||
|
||||
return install.handler({
|
||||
...opts,
|
||||
patchedDependencies: rootProjectManifest!.pnpm!.patchedDependencies!,
|
||||
rootProjectManifest,
|
||||
patchedDependencies,
|
||||
rawLocalConfig: {
|
||||
...opts.rawLocalConfig,
|
||||
'frozen-lockfile': false,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import path from 'path'
|
||||
import fs from 'fs/promises'
|
||||
import { docsUrl } from '@pnpm/cli-utils'
|
||||
import { writeSettings } from '@pnpm/config.config-writer'
|
||||
import { install } from '@pnpm/plugin-commands-installation'
|
||||
import { type Config, types as allTypes } from '@pnpm/config'
|
||||
import { tryReadProjectManifest } from '@pnpm/read-project-manifest'
|
||||
import { PnpmError } from '@pnpm/error'
|
||||
import { type ProjectRootDir } from '@pnpm/types'
|
||||
import renderHelp from 'render-help'
|
||||
@@ -28,14 +28,12 @@ export function help (): string {
|
||||
})
|
||||
}
|
||||
|
||||
export type PatchRemoveCommandOptions = install.InstallCommandOptions & Pick<Config, 'dir' | 'lockfileDir' | 'patchesDir' | 'rootProjectManifest'>
|
||||
export type PatchRemoveCommandOptions = install.InstallCommandOptions & Pick<Config, 'dir' | 'lockfileDir' | 'patchesDir' | 'rootProjectManifest' | 'patchedDependencies'>
|
||||
|
||||
export async function handler (opts: PatchRemoveCommandOptions, params: string[]): Promise<void> {
|
||||
let patchesToRemove = params
|
||||
const lockfileDir = (opts.lockfileDir ?? opts.dir ?? process.cwd()) as ProjectRootDir
|
||||
const { writeProjectManifest, manifest } = await tryReadProjectManifest(lockfileDir)
|
||||
const rootProjectManifest = opts.rootProjectManifest ?? manifest ?? {}
|
||||
const patchedDependencies = rootProjectManifest.pnpm?.patchedDependencies ?? {}
|
||||
const patchedDependencies = opts.patchedDependencies ?? {}
|
||||
|
||||
if (!params.length) {
|
||||
const allPatches = Object.keys(patchedDependencies)
|
||||
@@ -64,13 +62,7 @@ export async function handler (opts: PatchRemoveCommandOptions, params: string[]
|
||||
const patchFile = path.join(lockfileDir, patchedDependencies[patch])
|
||||
patchesDirs.add(path.dirname(patchFile))
|
||||
await fs.rm(patchFile, { force: true })
|
||||
delete rootProjectManifest.pnpm!.patchedDependencies![patch]
|
||||
if (!Object.keys(rootProjectManifest.pnpm!.patchedDependencies!).length) {
|
||||
delete rootProjectManifest.pnpm!.patchedDependencies
|
||||
if (!Object.keys(rootProjectManifest.pnpm!).length) {
|
||||
delete rootProjectManifest.pnpm
|
||||
}
|
||||
}
|
||||
delete patchedDependencies![patch]
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -83,15 +75,13 @@ export async function handler (opts: PatchRemoveCommandOptions, params: string[]
|
||||
} catch {}
|
||||
}))
|
||||
|
||||
await writeProjectManifest(rootProjectManifest)
|
||||
|
||||
if (opts?.selectedProjectsGraph?.[lockfileDir]) {
|
||||
opts.selectedProjectsGraph[lockfileDir].package.manifest = rootProjectManifest
|
||||
}
|
||||
|
||||
if (opts?.allProjectsGraph?.[lockfileDir].package.manifest) {
|
||||
opts.allProjectsGraph[lockfileDir].package.manifest = rootProjectManifest
|
||||
}
|
||||
await writeSettings({
|
||||
...opts,
|
||||
workspaceDir: opts.workspaceDir ?? opts.rootProjectManifestDir,
|
||||
updatedSettings: {
|
||||
patchedDependencies: Object.keys(patchedDependencies).length ? patchedDependencies : undefined,
|
||||
},
|
||||
})
|
||||
|
||||
return install.handler(opts)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { prepare, preparePackages, tempDir } from '@pnpm/prepare'
|
||||
import { install } from '@pnpm/plugin-commands-installation'
|
||||
import { filterPackagesFromDir } from '@pnpm/workspace.filter-packages-from-dir'
|
||||
import { sync as writeYamlFile } from 'write-yaml-file'
|
||||
import { readWorkspaceManifest } from '@pnpm/workspace.read-manifest'
|
||||
import tempy from 'tempy'
|
||||
import { patch, patchCommit, patchRemove } from '@pnpm/plugin-commands-patching'
|
||||
import { readProjectManifest } from '@pnpm/read-project-manifest'
|
||||
@@ -92,8 +93,8 @@ describe('patch and commit', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive@1.0.0': 'patches/is-positive@1.0.0.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/is-positive@1.0.0.patch', 'utf8')
|
||||
@@ -129,8 +130,8 @@ describe('patch and commit', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive': 'patches/is-positive.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/is-positive.patch', 'utf8')
|
||||
@@ -169,8 +170,8 @@ describe('patch and commit', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive@1.0.0': 'patches/is-positive@1.0.0.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/is-positive@1.0.0.patch', 'utf8')
|
||||
@@ -201,8 +202,8 @@ describe('patch and commit', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive@1.0.0': 'patches/is-positive@1.0.0.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/is-positive@1.0.0.patch', 'utf8')
|
||||
@@ -233,8 +234,8 @@ describe('patch and commit', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive@1.0.0': 'patches/is-positive@1.0.0.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/is-positive@1.0.0.patch', 'utf8')
|
||||
@@ -277,8 +278,8 @@ describe('patch and commit', () => {
|
||||
storeDir,
|
||||
}, [path.relative(process.cwd(), patchDir)])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive@1.0.0': 'patches/is-positive@1.0.0.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/is-positive@1.0.0.patch', 'utf8')
|
||||
@@ -389,8 +390,8 @@ describe('patch and commit', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive@1.0.0': 'ts/custom-patches/is-positive@1.0.0.patch',
|
||||
})
|
||||
expect(fs.existsSync(path.normalize(patchesDir))).toBe(true)
|
||||
@@ -446,15 +447,16 @@ describe('patch and commit', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive@1.0.0': 'patches/is-positive@1.0.0.patch',
|
||||
})
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(fs.existsSync('patches/is-positive@1.0.0.patch')).toBe(true)
|
||||
|
||||
// re-patch
|
||||
fs.rmSync(patchDir, { recursive: true })
|
||||
output = await patch.handler({ ...defaultPatchOption, rootProjectManifest: manifest }, ['is-positive@1.0.0'])
|
||||
output = await patch.handler({ ...defaultPatchOption, rootProjectManifest: manifest, patchedDependencies: workspaceManifest?.patchedDependencies }, ['is-positive@1.0.0'])
|
||||
patchDir = getPatchDirFromPatchOutput(output)
|
||||
|
||||
expect(fs.existsSync(patchDir)).toBe(true)
|
||||
@@ -479,15 +481,16 @@ describe('patch and commit', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive': 'patches/is-positive.patch',
|
||||
})
|
||||
expect(fs.existsSync('patches/is-positive.patch')).toBe(true)
|
||||
|
||||
// re-patch
|
||||
fs.rmSync(patchDir, { recursive: true })
|
||||
output = await patch.handler({ ...defaultPatchOption, rootProjectManifest: manifest }, ['is-positive'])
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
output = await patch.handler({ ...defaultPatchOption, rootProjectManifest: manifest, patchedDependencies: workspaceManifest?.patchedDependencies }, ['is-positive'])
|
||||
patchDir = getPatchDirFromPatchOutput(output)
|
||||
|
||||
expect(fs.existsSync(patchDir)).toBe(true)
|
||||
@@ -530,8 +533,8 @@ describe('patch and commit', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive@1.0.0': 'patches/is-positive@1.0.0.patch',
|
||||
})
|
||||
expect(fs.existsSync('patches/is-positive@1.0.0.patch')).toBe(true)
|
||||
@@ -606,8 +609,8 @@ describe('patch and commit', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive@1.0.0': 'patches/is-positive@1.0.0.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/is-positive@1.0.0.patch', 'utf8')
|
||||
@@ -682,8 +685,8 @@ describe('multiple versions', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'@pnpm.e2e/console-log': 'patches/@pnpm.e2e__console-log.patch',
|
||||
})
|
||||
|
||||
@@ -791,8 +794,8 @@ describe('prompt to choose version', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'chalk@5.3.0': 'patches/chalk@5.3.0.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/chalk@5.3.0.patch', 'utf8')
|
||||
@@ -858,8 +861,8 @@ describe('prompt to choose version', () => {
|
||||
storeDir,
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
chalk: 'patches/chalk.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/chalk.patch', 'utf8')
|
||||
@@ -916,8 +919,8 @@ describe('patching should work when there is a no EOL in the patched file', () =
|
||||
fixLockfile: true,
|
||||
}, [userPatchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'safe-execa@0.1.2': 'patches/safe-execa@0.1.2.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/safe-execa@0.1.2.patch', 'utf8')
|
||||
@@ -945,8 +948,8 @@ describe('patching should work when there is a no EOL in the patched file', () =
|
||||
fixLockfile: true,
|
||||
}, [userPatchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'safe-execa@0.1.2': 'patches/safe-execa@0.1.2.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/safe-execa@0.1.2.patch', 'utf8')
|
||||
@@ -1041,7 +1044,9 @@ describe('patch and commit in workspaces', () => {
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual(undefined)
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive@1.0.0': 'patches/is-positive@1.0.0.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/is-positive@1.0.0.patch', 'utf8')
|
||||
@@ -1103,7 +1108,9 @@ describe('patch and commit in workspaces', () => {
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual(undefined)
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'is-positive@1.0.0': 'patches/is-positive@1.0.0.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/is-positive@1.0.0.patch', 'utf8')
|
||||
@@ -1144,6 +1151,7 @@ describe('patch and commit in workspaces', () => {
|
||||
fs.unlinkSync(path.join(patchDir, 'license'))
|
||||
|
||||
// patch-commit
|
||||
let workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
await patchCommit.handler({
|
||||
...DEFAULT_OPTS,
|
||||
allProjects,
|
||||
@@ -1151,6 +1159,7 @@ describe('patch and commit in workspaces', () => {
|
||||
selectedProjectsGraph,
|
||||
dir: process.cwd(),
|
||||
rootProjectManifestDir: process.cwd(),
|
||||
patchedDependencies: workspaceManifest?.patchedDependencies,
|
||||
cacheDir,
|
||||
storeDir,
|
||||
lockfileDir: process.cwd(),
|
||||
@@ -1167,9 +1176,11 @@ describe('patch and commit in workspaces', () => {
|
||||
|
||||
// re-patch project-1
|
||||
fs.rmSync(patchDir, { recursive: true })
|
||||
workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
output = await patch.handler({
|
||||
...defaultPatchOption,
|
||||
dir: process.cwd(),
|
||||
patchedDependencies: workspaceManifest?.patchedDependencies,
|
||||
}, ['is-positive@1.0.0'])
|
||||
patchDir = getPatchDirFromPatchOutput(output)
|
||||
expect(fs.existsSync(patchDir)).toBe(true)
|
||||
@@ -1244,7 +1255,9 @@ describe('patch and commit in workspaces', () => {
|
||||
}, [patchDir])
|
||||
|
||||
const { manifest } = await readProjectManifest(process.cwd())
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual({
|
||||
expect(manifest.pnpm?.patchedDependencies).toStrictEqual(undefined)
|
||||
const workspaceManifest = await readWorkspaceManifest(process.cwd())
|
||||
expect(workspaceManifest!.patchedDependencies).toStrictEqual({
|
||||
'hi@1.0.0': 'patches/hi@1.0.0.patch',
|
||||
})
|
||||
const patchContent = fs.readFileSync('patches/hi@1.0.0.patch', 'utf8')
|
||||
@@ -1335,12 +1348,12 @@ describe('patch-remove', () => {
|
||||
defaultPatchRemoveOption = {
|
||||
...DEFAULT_OPTS,
|
||||
dir: process.cwd(),
|
||||
cacheDir,
|
||||
storeDir,
|
||||
}
|
||||
|
||||
await install.handler({
|
||||
...DEFAULT_OPTS,
|
||||
cacheDir,
|
||||
storeDir,
|
||||
...defaultPatchRemoveOption,
|
||||
dir: process.cwd(),
|
||||
saveLockfile: true,
|
||||
})
|
||||
@@ -1356,7 +1369,11 @@ describe('patch-remove', () => {
|
||||
fs.mkdirSync(path.join(process.cwd(), 'patches'))
|
||||
fs.writeFileSync(path.join(process.cwd(), 'patches/is-positive@1.0.0.patch'), 'test patch content', 'utf8')
|
||||
|
||||
await patchRemove.handler(defaultPatchRemoveOption, ['is-positive@1.0.0'])
|
||||
await patchRemove.handler({
|
||||
...defaultPatchRemoveOption,
|
||||
rootProjectManifest: manifest,
|
||||
patchedDependencies: manifest.pnpm.patchedDependencies,
|
||||
}, ['is-positive@1.0.0'])
|
||||
|
||||
const { manifest: newManifest } = await readProjectManifest(process.cwd())
|
||||
expect(newManifest!.pnpm!).toBeUndefined()
|
||||
@@ -1376,7 +1393,11 @@ describe('patch-remove', () => {
|
||||
prompt.mockResolvedValue({
|
||||
patches: ['is-positive@1.0.0', 'chalk@4.1.2'],
|
||||
})
|
||||
await patchRemove.handler(defaultPatchRemoveOption, [])
|
||||
await patchRemove.handler({
|
||||
...defaultPatchRemoveOption,
|
||||
rootProjectManifest: manifest,
|
||||
patchedDependencies: manifest.pnpm.patchedDependencies,
|
||||
}, [])
|
||||
expect(prompt.mock.calls[0][0].choices).toEqual(expect.arrayContaining(['is-positive@1.0.0', 'chalk@4.1.2']))
|
||||
prompt.mockClear()
|
||||
|
||||
@@ -1385,7 +1406,7 @@ describe('patch-remove', () => {
|
||||
})
|
||||
|
||||
test('should throw error when there is no patch to remove', async () => {
|
||||
await expect(() => patchRemove.handler(defaultPatchRemoveOption, []))
|
||||
await expect(() => patchRemove.handler({ ...defaultPatchRemoveOption, patchedDependencies: {} }, []))
|
||||
.rejects.toThrow('There are no patches that need to be removed')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
{
|
||||
"path": "../../config/config"
|
||||
},
|
||||
{
|
||||
"path": "../../config/config-writer"
|
||||
},
|
||||
{
|
||||
"path": "../../config/pick-registry-for-package"
|
||||
},
|
||||
@@ -75,6 +78,9 @@
|
||||
{
|
||||
"path": "../../workspace/filter-packages-from-dir"
|
||||
},
|
||||
{
|
||||
"path": "../../workspace/read-manifest"
|
||||
},
|
||||
{
|
||||
"path": "../apply-patch"
|
||||
}
|
||||
|
||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -4200,6 +4200,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
|
||||
@@ -4251,6 +4254,9 @@ importers:
|
||||
'@pnpm/types':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/types
|
||||
'@pnpm/workspace.read-manifest':
|
||||
specifier: workspace:*
|
||||
version: link:../../workspace/read-manifest
|
||||
chalk:
|
||||
specifier: 'catalog:'
|
||||
version: 4.1.2
|
||||
|
||||
Reference in New Issue
Block a user