From e8aafe393ce7e5a16accd719530370fea0b591be Mon Sep 17 00:00:00 2001 From: NullVoxPopuli Date: Tue, 20 Dec 2022 19:59:17 -0500 Subject: [PATCH] fix: patch should print instructions about how to commit the changes (#5809) Co-authored-by: Zoltan Kochan --- .changeset/bright-apricots-rest.md | 6 ++++++ packages/plugin-commands-patching/src/patch.ts | 4 +++- .../plugin-commands-patching/test/patch.test.ts | 15 ++++++++++----- 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 .changeset/bright-apricots-rest.md diff --git a/.changeset/bright-apricots-rest.md b/.changeset/bright-apricots-rest.md new file mode 100644 index 00000000000..b710f8265a6 --- /dev/null +++ b/.changeset/bright-apricots-rest.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-patching": patch +"pnpm": patch +--- + +`pnpm patch` should print instructions about how to commit the changes. diff --git a/packages/plugin-commands-patching/src/patch.ts b/packages/plugin-commands-patching/src/patch.ts index 30659004d80..f500cccd985 100644 --- a/packages/plugin-commands-patching/src/patch.ts +++ b/packages/plugin-commands-patching/src/patch.ts @@ -53,5 +53,7 @@ export async function handler (opts: PatchCommandOptions, params: string[]) { } const editDir = opts.editDir ?? tempy.directory() await writePackage(params[0], editDir, opts) - return `You can now edit the following folder: ${editDir}` + return `You can now edit the following folder: ${editDir} + +Once you're done with your changes, run "pnpm patch-commit ${editDir}"` } diff --git a/packages/plugin-commands-patching/test/patch.test.ts b/packages/plugin-commands-patching/test/patch.test.ts index cc446eb6c7d..95d5229b59f 100644 --- a/packages/plugin-commands-patching/test/patch.test.ts +++ b/packages/plugin-commands-patching/test/patch.test.ts @@ -36,7 +36,7 @@ describe('patch and commit', () => { test('patch and commit', async () => { const output = await patch.handler(defaultPatchOption, ['is-positive@1.0.0']) - const patchDir = output.substring(output.indexOf(':') + 1).trim() + const patchDir = getPatchDirFromPatchOutput(output) const tempDir = os.tmpdir() // temp dir depends on the operating system (@see tempy) // store patch files in a temporary directory when not given editDir option @@ -71,7 +71,7 @@ describe('patch and commit', () => { const editDir = path.join(tempy.directory()) const output = await patch.handler({ ...defaultPatchOption, editDir }, ['is-positive@1.0.0']) - const patchDir = output.substring(output.indexOf(':') + 1).trim() + const patchDir = getPatchDirFromPatchOutput(output) expect(patchDir).toBe(editDir) expect(fs.existsSync(patchDir)).toBe(true) @@ -98,7 +98,7 @@ describe('patch and commit', () => { const editDir = path.join(tempy.directory()) + (os.platform() === 'win32' ? '\\' : '/') const output = await patch.handler({ ...defaultPatchOption, editDir }, ['is-positive@1.0.0']) - const patchDir = output.substring(output.indexOf(':') + 1).trim() + const patchDir = getPatchDirFromPatchOutput(output) expect(patchDir).toBe(editDir) expect(fs.existsSync(patchDir)).toBe(true) @@ -141,7 +141,7 @@ describe('patching should work when there is a no EOL in the patched file', () = }) it('should work when adding content on a newline', async () => { const output = await patch.handler(defaultPatchOption, ['safe-execa@0.1.2']) - const userPatchDir = output.substring(output.indexOf(':') + 1).trim() + const userPatchDir = getPatchDirFromPatchOutput(output) const tempDir = os.tmpdir() expect(userPatchDir).toContain(tempDir) @@ -167,7 +167,7 @@ describe('patching should work when there is a no EOL in the patched file', () = }) it('should work fine when new content is appended', async () => { const output = await patch.handler(defaultPatchOption, ['safe-execa@0.1.2']) - const userPatchDir = output.substring(output.indexOf(':') + 1).trim() + const userPatchDir = getPatchDirFromPatchOutput(output) const tempDir = os.tmpdir() expect(userPatchDir).toContain(tempDir) @@ -190,3 +190,8 @@ describe('patching should work when there is a no EOL in the patched file', () = expect(fs.readFileSync('node_modules/safe-execa/lib/index.js', 'utf8')).toContain('//# sourceMappingURL=index.js.map// patch without newline') }) }) + +function getPatchDirFromPatchOutput (output: string) { + const [firstLine] = output.split('\n') + return firstLine.substring(firstLine.indexOf(':') + 1).trim() +}