mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-25 16:18:06 -05:00
fix(plugin-commands-patching): ignore empty patch content when patch-commit (#6826)
This commit is contained in:
6
.changeset/modern-penguins-bow.md
Normal file
6
.changeset/modern-penguins-bow.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-patching": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Ignore empty patch content when patch-commit.
|
||||
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user