diff --git a/.changeset/cold-trees-rush.md b/.changeset/cold-trees-rush.md new file mode 100644 index 0000000000..53628a7775 --- /dev/null +++ b/.changeset/cold-trees-rush.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-completion": patch +"@pnpm/build-modules": patch +--- + +Improve output of the `pnpm patch` command. diff --git a/patching/plugin-commands-patching/package.json b/patching/plugin-commands-patching/package.json index 60629ee57e..847a932a2e 100644 --- a/patching/plugin-commands-patching/package.json +++ b/patching/plugin-commands-patching/package.json @@ -58,6 +58,7 @@ "@pnpm/read-package-json": "workspace:*", "@pnpm/read-project-manifest": "workspace:*", "@pnpm/store-connection-manager": "workspace:*", + "chalk": "catalog:", "enquirer": "catalog:", "escape-string-regexp": "catalog:", "fast-glob": "catalog:", @@ -67,7 +68,8 @@ "render-help": "catalog:", "safe-execa": "catalog:", "semver": "catalog:", - "tempy": "catalog:" + "tempy": "catalog:", + "terminal-link": "catalog:" }, "peerDependencies": { "@pnpm/logger": "^5.0.0" diff --git a/patching/plugin-commands-patching/src/patch.ts b/patching/plugin-commands-patching/src/patch.ts index 956a798f00..139599d7e3 100644 --- a/patching/plugin-commands-patching/src/patch.ts +++ b/patching/plugin-commands-patching/src/patch.ts @@ -9,6 +9,8 @@ import { } from '@pnpm/store-connection-manager' import pick from 'ramda/src/pick' import renderHelp from 'render-help' +import chalk from 'chalk' +import terminalLink from 'terminal-link' import tempy from 'tempy' import { PnpmError } from '@pnpm/error' import { type ParseWantedDependencyResult } from '@pnpm/parse-wanted-dependency' @@ -101,9 +103,15 @@ export async function handler (opts: PatchCommandOptions, params: string[]): Pro }) } } - return `You can now edit the following folder: ${editDir} + return `Patch: You can now edit the package at: -Once you're done with your changes, run "pnpm patch-commit '${editDir}'"` + ${terminalLink(chalk.blue(editDir), 'file://' + editDir)} + +To commit your changes, run: + + ${chalk.green(`pnpm patch-commit '${editDir}'`)} + +` } function tryPatchWithExistingPatchFile ( diff --git a/patching/plugin-commands-patching/test/patch.test.ts b/patching/plugin-commands-patching/test/patch.test.ts index 22975c9062..6b3e6b7337 100644 --- a/patching/plugin-commands-patching/test/patch.test.ts +++ b/patching/plugin-commands-patching/test/patch.test.ts @@ -928,7 +928,8 @@ describe('patch-remove', () => { }) }) -function getPatchDirFromPatchOutput (output: string) { - const [firstLine] = output.split('\n') - return firstLine.substring(firstLine.indexOf(':') + 1).trim() +function getPatchDirFromPatchOutput (output: string): string { + const match = output.match(/'([^']+)'/) + if (match?.[1] == null) throw new Error('No path in output') + return match[1] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4e6d76afb3..6fedae955a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -603,6 +603,9 @@ catalogs: tempy: specifier: ^1.0.1 version: 1.0.1 + terminal-link: + specifier: ^2.1.1 + version: 2.1.1 touch: specifier: 3.1.0 version: 3.1.0 @@ -3651,6 +3654,9 @@ importers: '@pnpm/store-connection-manager': specifier: workspace:* version: link:../../store/store-connection-manager + chalk: + specifier: 'catalog:' + version: 4.1.2 enquirer: specifier: 'catalog:' version: 2.4.1 @@ -3681,6 +3687,9 @@ importers: tempy: specifier: 'catalog:' version: 1.0.1 + terminal-link: + specifier: 'catalog:' + version: 2.1.1 devDependencies: '@pnpm/plugin-commands-patching': specifier: workspace:* @@ -13056,6 +13065,10 @@ packages: resolution: {integrity: sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==} engines: {node: '>=10'} + supports-hyperlinks@2.3.0: + resolution: {integrity: sha512-RpsAZlpWcDwOPQA22aCH4J0t7L8JmAvsCxfOSEwm7cQs3LshN36QaTkwd70DnBOXDWGssw2eUoc8CaRWT0XunA==} + engines: {node: '>=8'} + supports-preserve-symlinks-flag@1.0.0: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} engines: {node: '>= 0.4'} @@ -13092,6 +13105,10 @@ packages: resolution: {integrity: sha512-wK0Ri4fOGjv/XPy8SBHZChl8CM7uMc5VML7SqiQ0zG7+J5Vr+RMQDoHa2CNT6KHUnTGIXH34UDMkPzAUyapBZg==} engines: {node: '>=8'} + terminal-link@2.1.1: + resolution: {integrity: sha512-un0FmiRUQNr5PJqy9kP7c40F5BOfpGlYTrxonDChEZB7pzZxRNp/bt+ymiy9/npwXya9KH99nJ/GXFIiUkYGFQ==} + engines: {node: '>=8'} + test-exclude@6.0.0: resolution: {integrity: sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==} engines: {node: '>=8'} @@ -20594,6 +20611,11 @@ snapshots: dependencies: has-flag: 4.0.0 + supports-hyperlinks@2.3.0: + dependencies: + has-flag: 4.0.0 + supports-color: 7.2.0 + supports-preserve-symlinks-flag@1.0.0: {} symlink-dir@6.0.0: @@ -20645,6 +20667,11 @@ snapshots: term-size@2.2.1: {} + terminal-link@2.1.1: + dependencies: + ansi-escapes: 4.3.2 + supports-hyperlinks: 2.3.0 + test-exclude@6.0.0: dependencies: '@istanbuljs/schema': 0.1.3 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index b5cdd46be8..d81f71dcfe 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -234,6 +234,7 @@ catalog: tar-stream: ^2.2.0 tar: ^6.2.1 tempy: ^1.0.1 + terminal-link: ^2.1.1 touch: 3.1.0 tree-kill: ^1.2.2 uuid: ^9.0.1