Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use irreversible-delete in pnpm patch-commit #5008

Merged
merged 1 commit into from Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .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
2 changes: 1 addition & 1 deletion packages/plugin-commands-patching/src/patchCommit.ts
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-commands-patching/test/patch.test.ts
Expand Up @@ -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,
Expand All @@ -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)
})