Skip to content

Commit 799af9a

Browse files
author
Tony Spataro
committed
Add maxEditLength to lockfile patch. Fixes #4405.
1 parent fcb51bf commit 799af9a

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

packages/yarnpkg-core/sources/Project.ts

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

15701570
if (newLockfile !== initialLockfile) {
1571-
const diff = structuredPatch(lockfilePath, lockfilePath, initialLockfile, newLockfile);
1572-
1573-
opts.report.reportSeparator();
1574-
1575-
for (const hunk of diff.hunks) {
1576-
opts.report.reportInfo(null, `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`);
1577-
for (const line of hunk.lines) {
1578-
if (line.startsWith(`+`)) {
1579-
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.ADDED));
1580-
} else if (line.startsWith(`-`)) {
1581-
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.REMOVED));
1582-
} else {
1583-
opts.report.reportInfo(null, formatUtils.pretty(this.configuration, line, `grey`));
1571+
// @ts-expect-error 2345 need to upgrade to diff 5.0.1 or apply patch in yarn's monorepo
1572+
const diff = structuredPatch(lockfilePath, lockfilePath, initialLockfile, newLockfile, undefined, undefined, {maxEditLength: 100});
1573+
1574+
if (diff) {
1575+
opts.report.reportSeparator();
1576+
1577+
for (const hunk of diff.hunks) {
1578+
opts.report.reportInfo(null, `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`);
1579+
for (const line of hunk.lines) {
1580+
if (line.startsWith(`+`)) {
1581+
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.ADDED));
1582+
} else if (line.startsWith(`-`)) {
1583+
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.REMOVED));
1584+
} else {
1585+
opts.report.reportInfo(null, formatUtils.pretty(this.configuration, line, `grey`));
1586+
}
15841587
}
15851588
}
1586-
}
15871589

1588-
opts.report.reportSeparator();
1590+
opts.report.reportSeparator();
1591+
}
15891592

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

0 commit comments

Comments
 (0)