Skip to content

Commit ed9e731

Browse files
authored
fix(patch): throw on patch files with no changes (#2554)
1 parent a6312e2 commit ed9e731

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

.yarn/versions/eeae7dcf.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-patch": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-init"
11+
- "@yarnpkg/plugin-interactive-tools"
12+
- "@yarnpkg/plugin-node-modules"
13+
- "@yarnpkg/plugin-npm-cli"
14+
- "@yarnpkg/plugin-pack"
15+
- "@yarnpkg/plugin-pnp"
16+
- "@yarnpkg/plugin-stage"
17+
- "@yarnpkg/plugin-typescript"
18+
- "@yarnpkg/plugin-version"
19+
- "@yarnpkg/plugin-workspace-tools"
20+
- "@yarnpkg/builder"
21+
- "@yarnpkg/core"
22+
- "@yarnpkg/doctor"

packages/acceptance-tests/pkg-tests-specs/sources/protocols/patch.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,22 @@ describe(`Protocols`, () => {
170170
},
171171
),
172172
);
173+
174+
test(
175+
`it should throw on invalid patch files`,
176+
makeTemporaryEnv(
177+
{
178+
dependencies: {[`no-deps`]: `patch:no-deps@1.0.0#my-patch.patch`},
179+
},
180+
async ({path, run, source}) => {
181+
await xfs.writeFilePromise(ppath.join(path, `my-patch.patch`), NO_DEPS_PATCH, {encoding: `utf16le`});
182+
183+
await expect(run(`install`)).rejects.toMatchObject({
184+
code: 1,
185+
stdout: expect.stringContaining(`Unable to parse patch file: No changes found`),
186+
});
187+
},
188+
),
189+
);
173190
});
174191
});

packages/plugin-patch/sources/tools/parse.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ export function interpretParsedPatchFile(files: Array<FileDeets>): ParsedPatchFi
409409
}
410410
}
411411

412+
if (result.length === 0)
413+
throw new Error(`Unable to parse patch file: No changes found. Make sure the patch is a valid UTF8 encoded string`);
414+
412415
return result;
413416
}
414417

0 commit comments

Comments
 (0)