mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-30 10:38:13 -05:00
fix(plugin-commands-patching): do not create empty patch directory (#7410)
This commit is contained in:
6
.changeset/mean-squids-rule.md
Normal file
6
.changeset/mean-squids-rule.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-patching": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Do not create empty patch directory.
|
||||
@@ -48,7 +48,6 @@ export async function handler (opts: install.InstallCommandOptions & Pick<Config
|
||||
const lockfileDir = opts.lockfileDir ?? opts.dir ?? process.cwd()
|
||||
const patchesDirName = normalizePath(path.normalize(opts.patchesDir ?? 'patches'))
|
||||
const patchesDir = path.join(lockfileDir, patchesDirName)
|
||||
await fs.promises.mkdir(patchesDir, { recursive: true })
|
||||
const patchedPkgManifest = await readPackageJsonFromDir(userDir)
|
||||
const pkgNameAndVersion = `${patchedPkgManifest.name}@${patchedPkgManifest.version}`
|
||||
const gitTarballUrl = await getGitTarballUrlFromLockfile({
|
||||
@@ -67,6 +66,7 @@ export async function handler (opts: install.InstallCommandOptions & Pick<Config
|
||||
if (!patchContent.length) {
|
||||
return `No changes were found to the following directory: ${userDir}`
|
||||
}
|
||||
await fs.promises.mkdir(patchesDir, { recursive: true })
|
||||
|
||||
const patchFileName = pkgNameAndVersion.replace('/', '__')
|
||||
await fs.promises.writeFile(path.join(patchesDir, `${patchFileName}.patch`), patchContent, 'utf8')
|
||||
|
||||
@@ -317,7 +317,7 @@ describe('patch and commit', () => {
|
||||
expect(JSON.parse(fs.readFileSync(path.join(patchDir, 'package.json'), 'utf8')).version).toBe('1.0.0')
|
||||
})
|
||||
|
||||
test('should skip empty patch content', async () => {
|
||||
test('should skip empty patch content and not create patches dir', async () => {
|
||||
const output = await patch.handler(defaultPatchOption, ['is-positive@1.0.0'])
|
||||
const patchDir = getPatchDirFromPatchOutput(output)
|
||||
const result = await patchCommit.handler({
|
||||
@@ -331,6 +331,7 @@ describe('patch and commit', () => {
|
||||
}, [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)
|
||||
expect(fs.existsSync('patches')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user