fix(plugin-commands-patching): ignore empty patch content when patch-commit (#6826)

This commit is contained in:
await-ovo
2023-07-19 18:47:29 +08:00
committed by GitHub
parent cd00a79ab2
commit 653e9104c0
4 changed files with 26 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-patching": patch
"pnpm": patch
---
Ignore empty patch content when patch-commit.

View File

@@ -12,6 +12,7 @@
"node": ">=16.14"
},
"scripts": {
"start": "tsc --watch",
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7772 jest",
"test": "pnpm run compile && pnpm run _test",

View File

@@ -56,6 +56,10 @@ export async function handler (opts: install.InstallCommandOptions & Pick<Config
const patchedPkgDir = await preparePkgFilesForDiff(userDir)
const patchContent = await diffFolders(srcDir, patchedPkgDir)
if (!patchContent.length) {
return `No changes were found to the following directory: ${userDir}`
}
const patchFileName = pkgNameAndVersion.replace('/', '__')
await fs.promises.writeFile(path.join(patchesDir, `${patchFileName}.patch`), patchContent, 'utf8')
const { writeProjectManifest, manifest } = await tryReadProjectManifest(lockfileDir)

View File

@@ -309,6 +309,21 @@ describe('patch and commit', () => {
expect(fs.existsSync(patchDir)).toBe(true)
expect(JSON.parse(fs.readFileSync(path.join(patchDir, 'package.json'), 'utf8')).version).toBe('1.0.0')
})
test('should skip empty patch content', async () => {
const output = await patch.handler(defaultPatchOption, ['is-positive@1.0.0'])
const patchDir = getPatchDirFromPatchOutput(output)
const result = await patchCommit.handler({
...DEFAULT_OPTS,
cacheDir,
dir: process.cwd(),
frozenLockfile: false,
fixLockfile: true,
storeDir,
}, [patchDir])
expect(result).toBe(`No changes were found to the following directory: ${patchDir}`)
expect(fs.existsSync('patches/is-positive@1.0.0.patch')).toBe(false)
})
})
describe('prompt to choose version', () => {