Skip to content

Commit 7841e2c

Browse files
Tony SpataroTony Spataromerceyz
committed
fix(core): prevent hangs due to degenerate lockfile diff (#4453)
* Upgrade diff to 5.0.0 * Add maxEditLength to lockfile patch. Fixes #4405. * Prepare fix for release * Upgrade diff to 5.1.0 * Re-resolve typescript 4.7.0-beta from npmjs.org * chore: versions Co-authored-by: Tony Spataro <[email protected]> Co-authored-by: merceyz <[email protected]>
1 parent 00153ea commit 7841e2c

File tree

9 files changed

+85
-34
lines changed

9 files changed

+85
-34
lines changed

.pnp.cjs

Lines changed: 14 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-5.21 KB
Binary file not shown.
5.29 KB
Binary file not shown.
129 KB
Binary file not shown.

.yarn/versions/ff82837d.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/core": patch
4+
"@yarnpkg/plugin-interactive-tools": patch
5+
6+
declined:
7+
- "@yarnpkg/plugin-compat"
8+
- "@yarnpkg/plugin-constraints"
9+
- "@yarnpkg/plugin-dlx"
10+
- "@yarnpkg/plugin-essentials"
11+
- "@yarnpkg/plugin-exec"
12+
- "@yarnpkg/plugin-file"
13+
- "@yarnpkg/plugin-git"
14+
- "@yarnpkg/plugin-github"
15+
- "@yarnpkg/plugin-http"
16+
- "@yarnpkg/plugin-init"
17+
- "@yarnpkg/plugin-link"
18+
- "@yarnpkg/plugin-nm"
19+
- "@yarnpkg/plugin-npm"
20+
- "@yarnpkg/plugin-npm-cli"
21+
- "@yarnpkg/plugin-pack"
22+
- "@yarnpkg/plugin-patch"
23+
- "@yarnpkg/plugin-pnp"
24+
- "@yarnpkg/plugin-pnpm"
25+
- "@yarnpkg/plugin-stage"
26+
- "@yarnpkg/plugin-typescript"
27+
- "@yarnpkg/plugin-version"
28+
- "@yarnpkg/plugin-workspace-tools"
29+
- "@yarnpkg/builder"
30+
- "@yarnpkg/doctor"
31+
- "@yarnpkg/extensions"
32+
- "@yarnpkg/nm"
33+
- "@yarnpkg/pnpify"
34+
- "@yarnpkg/sdks"

packages/plugin-interactive-tools/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"@yarnpkg/libui": "workspace:^",
88
"algoliasearch": "^4.2.0",
99
"clipanion": "^3.2.0-rc.4",
10-
"diff": "^4.0.1",
10+
"diff": "^5.1.0",
1111
"ink": "^3.0.8",
1212
"ink-text-input": "^4.0.1",
1313
"react": "^16.13.1",
@@ -20,7 +20,7 @@
2020
"@yarnpkg/plugin-essentials": "workspace:^"
2121
},
2222
"devDependencies": {
23-
"@types/diff": "^4.0.2",
23+
"@types/diff": "^5.0.0",
2424
"@types/react": "^16.8.0",
2525
"@types/semver": "^7.1.0",
2626
"@yarnpkg/builder": "workspace:^",

packages/yarnpkg-core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"ci-info": "^3.2.0",
2020
"clipanion": "^3.2.0-rc.4",
2121
"cross-spawn": "7.0.3",
22-
"diff": "^4.0.1",
22+
"diff": "^5.1.0",
2323
"globby": "^11.0.1",
2424
"got": "^11.7.0",
2525
"json-file-plus": "^3.3.1",
@@ -42,7 +42,7 @@
4242
"@rollup/plugin-commonjs": "^21.0.1",
4343
"@rollup/plugin-node-resolve": "^11.0.1",
4444
"@types/cross-spawn": "6.0.0",
45-
"@types/diff": "^4.0.2",
45+
"@types/diff": "^5.0.0",
4646
"@types/lodash": "^4.14.136",
4747
"@types/micromatch": "^4.0.1",
4848
"@types/node": "^13.7.0",

packages/yarnpkg-core/sources/Project.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,24 +1535,27 @@ export class Project {
15351535
const newLockfile = normalizeLineEndings(initialLockfile, this.generateLockfile());
15361536

15371537
if (newLockfile !== initialLockfile) {
1538-
const diff = structuredPatch(lockfilePath, lockfilePath, initialLockfile, newLockfile);
1539-
1540-
opts.report.reportSeparator();
1541-
1542-
for (const hunk of diff.hunks) {
1543-
opts.report.reportInfo(null, `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`);
1544-
for (const line of hunk.lines) {
1545-
if (line.startsWith(`+`)) {
1546-
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.ADDED));
1547-
} else if (line.startsWith(`-`)) {
1548-
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.REMOVED));
1549-
} else {
1550-
opts.report.reportInfo(null, formatUtils.pretty(this.configuration, line, `grey`));
1538+
// @ts-expect-error 2345 need to upgrade to diff 5.0.1 or apply patch in yarn's monorepo
1539+
const diff = structuredPatch(lockfilePath, lockfilePath, initialLockfile, newLockfile, undefined, undefined, {maxEditLength: 100});
1540+
1541+
if (diff) {
1542+
opts.report.reportSeparator();
1543+
1544+
for (const hunk of diff.hunks) {
1545+
opts.report.reportInfo(null, `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`);
1546+
for (const line of hunk.lines) {
1547+
if (line.startsWith(`+`)) {
1548+
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.ADDED));
1549+
} else if (line.startsWith(`-`)) {
1550+
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.REMOVED));
1551+
} else {
1552+
opts.report.reportInfo(null, formatUtils.pretty(this.configuration, line, `grey`));
1553+
}
15511554
}
15521555
}
1553-
}
15541556

1555-
opts.report.reportSeparator();
1557+
opts.report.reportSeparator();
1558+
}
15561559

15571560
throw new ReportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, `The lockfile would have been modified by this install, which is explicitly forbidden.`);
15581561
}

yarn.lock

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,10 +4082,10 @@ __metadata:
40824082
languageName: node
40834083
linkType: hard
40844084

4085-
"@types/diff@npm:^4.0.2":
4086-
version: 4.0.2
4087-
resolution: "@types/diff@npm:4.0.2"
4088-
checksum: 80986254f881e29a146c7258654b0c1ddecbb487dc2eca9ad424dab7a17f54d57f91271526661f4c3bf0bb77903d90bc627b63e389a30711adc622865bc30d94
4085+
"@types/diff@npm:^5.0.0":
4086+
version: 5.0.2
4087+
resolution: "@types/diff@npm:5.0.2"
4088+
checksum: 8fbc419b5aca33f494026bf5f70e026f76367689677ef114f9c078ac738d7dbe96e6dda3fd8290e4a7c35281e2b60b034e3d7e3c968b850cf06a21279e7ddcbe
40894089
languageName: node
40904090
linkType: hard
40914091

@@ -5453,7 +5453,7 @@ __metadata:
54535453
"@rollup/plugin-commonjs": ^21.0.1
54545454
"@rollup/plugin-node-resolve": ^11.0.1
54555455
"@types/cross-spawn": 6.0.0
5456-
"@types/diff": ^4.0.2
5456+
"@types/diff": ^5.0.0
54575457
"@types/lodash": ^4.14.136
54585458
"@types/micromatch": ^4.0.1
54595459
"@types/node": ^13.7.0
@@ -5476,7 +5476,7 @@ __metadata:
54765476
ci-info: ^3.2.0
54775477
clipanion: ^3.2.0-rc.4
54785478
cross-spawn: 7.0.3
5479-
diff: ^4.0.1
5479+
diff: ^5.1.0
54805480
esbuild: "npm:esbuild-wasm@^0.11.20"
54815481
globby: ^11.0.1
54825482
got: ^11.7.0
@@ -5967,7 +5967,7 @@ __metadata:
59675967
version: 0.0.0-use.local
59685968
resolution: "@yarnpkg/plugin-interactive-tools@workspace:packages/plugin-interactive-tools"
59695969
dependencies:
5970-
"@types/diff": ^4.0.2
5970+
"@types/diff": ^5.0.0
59715971
"@types/react": ^16.8.0
59725972
"@types/semver": ^7.1.0
59735973
"@yarnpkg/builder": "workspace:^"
@@ -5977,7 +5977,7 @@ __metadata:
59775977
"@yarnpkg/plugin-essentials": "workspace:^"
59785978
algoliasearch: ^4.2.0
59795979
clipanion: ^3.2.0-rc.4
5980-
diff: ^4.0.1
5980+
diff: ^5.1.0
59815981
ink: ^3.0.8
59825982
ink-text-input: ^4.0.1
59835983
react: ^16.13.1
@@ -10308,6 +10308,13 @@ __metadata:
1030810308
languageName: node
1030910309
linkType: hard
1031010310

10311+
"diff@npm:^5.1.0":
10312+
version: 5.1.0
10313+
resolution: "diff@npm:5.1.0"
10314+
checksum: c7bf0df7c9bfbe1cf8a678fd1b2137c4fb11be117a67bc18a0e03ae75105e8533dbfb1cda6b46beb3586ef5aed22143ef9d70713977d5fb1f9114e21455fba90
10315+
languageName: node
10316+
linkType: hard
10317+
1031110318
"diffie-hellman@npm:^5.0.0":
1031210319
version: 5.0.3
1031310320
resolution: "diffie-hellman@npm:5.0.3"

0 commit comments

Comments
 (0)