fix: command suggestion to apply patch on Windows (#8851)

close #7546

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Rantetsu Inori
2024-12-20 17:38:17 +08:00
committed by GitHub
parent 3bc9d5c50e
commit f74070d72f
5 changed files with 20 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-patching": patch
"pnpm": patch
---
Use double quotes in the command suggestion by `pnpm patch` on Windows [#7546](https://github.com/pnpm/pnpm/issues/7546).

View File

@@ -37,6 +37,7 @@
"@pnpm/registry-mock": "catalog:",
"@pnpm/test-fixtures": "workspace:*",
"@pnpm/workspace.filter-packages-from-dir": "workspace:*",
"@types/is-windows": "catalog:",
"@types/normalize-path": "catalog:",
"@types/ramda": "catalog:",
"@types/semver": "catalog:",
@@ -64,6 +65,7 @@
"enquirer": "catalog:",
"escape-string-regexp": "catalog:",
"fast-glob": "catalog:",
"is-windows": "catalog:",
"make-empty-dir": "catalog:",
"normalize-path": "catalog:",
"ramda": "catalog:",

View File

@@ -18,6 +18,7 @@ import { getEditDirPath } from './getEditDirPath'
import { 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> {
return pick([], allTypes)
@@ -122,13 +123,16 @@ export async function handler (opts: PatchCommandOptions, params: string[]): Pro
})
}
}
const quote = isWindows() ? '"' : "'"
return `Patch: You can now edit the package at:
${terminalLink(chalk.blue(editDir), 'file://' + editDir)}
To commit your changes, run:
${chalk.green(`pnpm patch-commit '${editDir}'`)}
${chalk.green(`pnpm patch-commit ${quote}${editDir}${quote}`)}
`
}

View File

@@ -1327,7 +1327,7 @@ describe('patch-remove', () => {
})
function getPatchDirFromPatchOutput (output: string): string {
const match = output.match(/'([^']+)'/)
const match = output.match(/['"]([^'"]+)['"]/)
if (match?.[1] == null) throw new Error('No path in output')
return match[1]
}

6
pnpm-lock.yaml generated
View File

@@ -4096,6 +4096,9 @@ importers:
fast-glob:
specifier: 'catalog:'
version: 3.3.2
is-windows:
specifier: 'catalog:'
version: 1.0.2
make-empty-dir:
specifier: 'catalog:'
version: 3.0.2
@@ -4142,6 +4145,9 @@ importers:
'@pnpm/workspace.filter-packages-from-dir':
specifier: workspace:*
version: link:../../workspace/filter-packages-from-dir
'@types/is-windows':
specifier: 'catalog:'
version: 1.0.2
'@types/normalize-path':
specifier: 'catalog:'
version: 3.0.2