mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-13 19:16:21 -04:00
feat!: remove deprecated patch options (#10505)
* refactor: remove allowNonAppliedPatches * refactor: remove ignorePatchFailures * refactor: remove `strict` field in groupPatchedDependencies * test: update test failure in package patching * test: fix * docs: update changesets --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
committed by
Zoltan Kochan
parent
f8b4895e0a
commit
7b1c189f2e
@@ -1,9 +1,7 @@
|
||||
import { PnpmError } from '@pnpm/error'
|
||||
import { applyPatch } from '@pnpm/patch-package/dist/applyPatches.js'
|
||||
import { globalWarn } from '@pnpm/logger'
|
||||
|
||||
export interface ApplyPatchToDirOpts {
|
||||
allowFailure?: boolean
|
||||
patchedDir: string
|
||||
patchFilePath: string
|
||||
}
|
||||
@@ -27,12 +25,7 @@ export function applyPatchToDir (opts: ApplyPatchToDirOpts): boolean {
|
||||
process.chdir(cwd)
|
||||
}
|
||||
if (!success) {
|
||||
const message = `Could not apply patch ${opts.patchFilePath} to ${opts.patchedDir}`
|
||||
if (opts.allowFailure) {
|
||||
globalWarn(message)
|
||||
} else {
|
||||
throw new PnpmError('PATCH_FAILED', message)
|
||||
}
|
||||
throw new PnpmError('PATCH_FAILED', `Could not apply patch ${opts.patchFilePath} to ${opts.patchedDir}`)
|
||||
}
|
||||
return success
|
||||
}
|
||||
|
||||
@@ -27,15 +27,13 @@ function prepareDirToPatch () {
|
||||
return dir
|
||||
}
|
||||
|
||||
describe('applyPatchToDir() without allowFailure', () => {
|
||||
const allowFailure = false
|
||||
describe('applyPatchToDir()', () => {
|
||||
it('should succeed when patch is applicable', () => {
|
||||
const patchFilePath = f.find('applicable.patch')
|
||||
const successfullyPatched = f.find('successfully-patched.txt')
|
||||
const patchedDir = prepareDirToPatch()
|
||||
expect(
|
||||
applyPatchToDir({
|
||||
allowFailure,
|
||||
patchFilePath,
|
||||
patchedDir,
|
||||
})
|
||||
@@ -48,7 +46,6 @@ describe('applyPatchToDir() without allowFailure', () => {
|
||||
const patchedDir = prepareDirToPatch()
|
||||
expect(() => {
|
||||
applyPatchToDir({
|
||||
allowFailure,
|
||||
patchFilePath,
|
||||
patchedDir,
|
||||
})
|
||||
@@ -59,7 +56,6 @@ describe('applyPatchToDir() without allowFailure', () => {
|
||||
const patchFilePath = f.find('invalid.patch')
|
||||
expect(() => {
|
||||
applyPatchToDir({
|
||||
allowFailure,
|
||||
patchFilePath,
|
||||
patchedDir: tempDir(),
|
||||
})
|
||||
@@ -68,59 +64,6 @@ describe('applyPatchToDir() without allowFailure', () => {
|
||||
it('should fail if the patch file is not found', () => {
|
||||
expect(() => {
|
||||
applyPatchToDir({
|
||||
allowFailure,
|
||||
patchFilePath: 'does-not-exist.patch',
|
||||
patchedDir: tempDir(),
|
||||
})
|
||||
}).toThrow('Patch file not found')
|
||||
})
|
||||
})
|
||||
|
||||
describe('applyPatchToDir() with allowFailure', () => {
|
||||
const allowFailure = true
|
||||
it('should succeed when patch is applicable', () => {
|
||||
const patchFilePath = f.find('applicable.patch')
|
||||
const successfullyPatched = f.find('successfully-patched.txt')
|
||||
const patchedDir = prepareDirToPatch()
|
||||
expect(
|
||||
applyPatchToDir({
|
||||
allowFailure,
|
||||
patchFilePath,
|
||||
patchedDir,
|
||||
})
|
||||
).toBe(true)
|
||||
const patchTarget = path.join(patchedDir, 'patch-target.txt')
|
||||
expect(fs.readFileSync(patchTarget, 'utf-8')).toBe(fs.readFileSync(successfullyPatched, 'utf-8'))
|
||||
})
|
||||
it('should warn when patch fails to apply', () => {
|
||||
const patchFilePath = f.find('non-applicable.patch')
|
||||
const patchedDir = prepareDirToPatch()
|
||||
expect(
|
||||
applyPatchToDir({
|
||||
allowFailure,
|
||||
patchFilePath,
|
||||
patchedDir,
|
||||
})
|
||||
).toBe(false)
|
||||
expect(jest.mocked(globalWarn).mock.calls).toStrictEqual([[
|
||||
`Could not apply patch ${patchFilePath} to ${patchedDir}`,
|
||||
]])
|
||||
expect(fs.readFileSync(path.join(patchedDir, 'patch-target.txt'), 'utf-8')).toBe(fs.readFileSync(f.find('patch-target.txt'), 'utf-8'))
|
||||
})
|
||||
it('should fail on invalid patch', () => {
|
||||
const patchFilePath = f.find('invalid.patch')
|
||||
expect(() => {
|
||||
applyPatchToDir({
|
||||
allowFailure,
|
||||
patchFilePath,
|
||||
patchedDir: tempDir(),
|
||||
})
|
||||
}).toThrow(`Applying patch "${patchFilePath}" failed: hunk header integrity check failed`)
|
||||
})
|
||||
it('should fail if the patch file is not found', () => {
|
||||
expect(() => {
|
||||
applyPatchToDir({
|
||||
allowFailure,
|
||||
patchFilePath: 'does-not-exist.patch',
|
||||
patchedDir: tempDir(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user