From e100086e38b3f5f765adc34e23590e834abaa7aa Mon Sep 17 00:00:00 2001 From: webstrand Date: Mon, 11 Jul 2022 07:54:00 -0400 Subject: [PATCH] feat: use irreversible-delete in pnpm patch-commit Avoid retaining a copy of the contents of files deleted during patching --- .changeset/fresh-singers-sparkle.md | 5 +++++ packages/plugin-commands-patching/src/patchCommit.ts | 2 +- packages/plugin-commands-patching/test/patch.test.ts | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/fresh-singers-sparkle.md diff --git a/.changeset/fresh-singers-sparkle.md b/.changeset/fresh-singers-sparkle.md new file mode 100644 index 00000000000..14b1b089381 --- /dev/null +++ b/.changeset/fresh-singers-sparkle.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-patching": minor +--- + +Avoid retaining a copy of the contents of files deleted during patching diff --git a/packages/plugin-commands-patching/src/patchCommit.ts b/packages/plugin-commands-patching/src/patchCommit.ts index d0ad96f364a..34271fbc8c9 100644 --- a/packages/plugin-commands-patching/src/patchCommit.ts +++ b/packages/plugin-commands-patching/src/patchCommit.ts @@ -61,7 +61,7 @@ async function diffFolders (folderA: string, folderB: string) { let stderr!: string try { - const result = await execa('git', ['-c', 'core.safecrlf=false', 'diff', '--src-prefix=a/', '--dst-prefix=b/', '--ignore-cr-at-eol', '--full-index', '--no-index', '--text', folderAN, folderBN], { + const result = await execa('git', ['-c', 'core.safecrlf=false', 'diff', '--src-prefix=a/', '--dst-prefix=b/', '--ignore-cr-at-eol', '--irreversible-delete', '--full-index', '--no-index', '--text', folderAN, folderBN], { cwd: process.cwd(), env: { ...process.env, diff --git a/packages/plugin-commands-patching/test/patch.test.ts b/packages/plugin-commands-patching/test/patch.test.ts index c30bb33bc8e..80807b0e973 100644 --- a/packages/plugin-commands-patching/test/patch.test.ts +++ b/packages/plugin-commands-patching/test/patch.test.ts @@ -28,7 +28,12 @@ test('patch and commit', async () => { }, ['is-positive@1.0.0']) const userPatchDir = output.substring(output.indexOf(':') + 1).trim() + + // sanity check to ensure that the license file contains the expected string + expect(fs.readFileSync(path.join(userPatchDir, 'license'), 'utf8')).toContain('The MIT License (MIT)') + fs.appendFileSync(path.join(userPatchDir, 'index.js'), '// test patching', 'utf8') + fs.unlinkSync(path.join(userPatchDir, 'license')) await patchCommit.handler({ ...DEFAULT_OPTS, @@ -43,4 +48,7 @@ test('patch and commit', async () => { expect(patchContent).toContain('diff --git') expect(patchContent).toContain('// test patching') expect(fs.readFileSync('node_modules/is-positive/index.js', 'utf8')).toContain('// test patching') + + expect(patchContent).not.toContain('The MIT License (MIT)') + expect(fs.existsSync('node_modules/is-positive/license')).toBe(false) })