mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-08 15:08:27 -05:00
fix: throw an error when a patch cannot be applied
This commit is contained in:
5
.changeset/short-pandas-leave.md
Normal file
5
.changeset/short-pandas-leave.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/build-modules": patch
|
||||
---
|
||||
|
||||
Throw an error if a patch couldn't be applied.
|
||||
@@ -36,6 +36,7 @@
|
||||
"dependencies": {
|
||||
"@pnpm/calc-dep-state": "workspace:3.0.1",
|
||||
"@pnpm/core-loggers": "workspace:7.0.5",
|
||||
"@pnpm/error": "workspace:3.0.1",
|
||||
"@pnpm/graph-sequencer": "1.0.0",
|
||||
"@pnpm/lifecycle": "workspace:13.1.1",
|
||||
"@pnpm/link-bins": "workspace:7.1.5",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import path from 'path'
|
||||
import { calcDepState, DepsStateCache } from '@pnpm/calc-dep-state'
|
||||
import { skippedOptionalDependencyLogger } from '@pnpm/core-loggers'
|
||||
import PnpmError from '@pnpm/error'
|
||||
import { runPostinstallHooks } from '@pnpm/lifecycle'
|
||||
import linkBins, { linkBinsOfPackages } from '@pnpm/link-bins'
|
||||
import logger from '@pnpm/logger'
|
||||
@@ -151,11 +152,14 @@ function applyPatchToDep (patchDir: string, patchFilePath: string) {
|
||||
// However, "patch" is not available on Windows and "git apply" is hard to execute on a subdirectory of an existing repository
|
||||
const cwd = process.cwd()
|
||||
process.chdir(patchDir)
|
||||
applyPatch({
|
||||
const success = applyPatch({
|
||||
patchFilePath,
|
||||
patchDir: patchDir,
|
||||
})
|
||||
process.chdir(cwd)
|
||||
if (!success) {
|
||||
throw new PnpmError('PATCH_FAILED', `Could not apply patch ${patchFilePath} to ${patchDir}`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function linkBinsOfDependencies (
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
{
|
||||
"path": "../core-loggers"
|
||||
},
|
||||
{
|
||||
"path": "../error"
|
||||
},
|
||||
{
|
||||
"path": "../lifecycle"
|
||||
},
|
||||
|
||||
@@ -352,3 +352,25 @@ test('patch package when the patched package has no dependencies and appears mul
|
||||
'/is-positive/1.0.0_jnbpamcxayl5i4ehrkoext3any',
|
||||
])
|
||||
})
|
||||
|
||||
test('patch package should fail when the patch could not be applied', async () => {
|
||||
prepareEmpty()
|
||||
const patchPath = path.join(f.find('patch-pkg'), 'is-positive@1.0.0.patch')
|
||||
|
||||
const patchedDependencies = {
|
||||
'is-positive@3.1.0': path.relative(process.cwd(), patchPath),
|
||||
}
|
||||
const opts = await testDefaults({
|
||||
fastUnpack: false,
|
||||
sideEffectsCacheRead: true,
|
||||
sideEffectsCacheWrite: true,
|
||||
patchedDependencies,
|
||||
}, {}, {}, { packageImportMethod: 'hardlink' })
|
||||
await expect(install({
|
||||
dependencies: {
|
||||
'is-positive': '3.1.0',
|
||||
},
|
||||
}, opts)).rejects.toThrow(/Could not apply patch/)
|
||||
|
||||
expect(fs.readFileSync('node_modules/is-positive/index.js', 'utf8')).not.toContain('// patched')
|
||||
})
|
||||
|
||||
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
@@ -178,6 +178,7 @@ importers:
|
||||
'@pnpm/build-modules': workspace:9.2.1
|
||||
'@pnpm/calc-dep-state': workspace:3.0.1
|
||||
'@pnpm/core-loggers': workspace:7.0.5
|
||||
'@pnpm/error': workspace:3.0.1
|
||||
'@pnpm/graph-sequencer': 1.0.0
|
||||
'@pnpm/lifecycle': workspace:13.1.1
|
||||
'@pnpm/link-bins': workspace:7.1.5
|
||||
@@ -192,6 +193,7 @@ importers:
|
||||
dependencies:
|
||||
'@pnpm/calc-dep-state': link:../calc-dep-state
|
||||
'@pnpm/core-loggers': link:../core-loggers
|
||||
'@pnpm/error': link:../error
|
||||
'@pnpm/graph-sequencer': 1.0.0
|
||||
'@pnpm/lifecycle': link:../lifecycle
|
||||
'@pnpm/link-bins': link:../link-bins
|
||||
|
||||
2
typings/local.d.ts
vendored
2
typings/local.d.ts
vendored
@@ -172,5 +172,5 @@ declare module 'mdast-util-to-string' {
|
||||
}
|
||||
|
||||
declare module 'patch-package/dist/applyPatches' {
|
||||
export function applyPatch(opts: any): void;
|
||||
export function applyPatch(opts: any): boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user