Skip to content

Commit

Permalink
Add maxEditLength to lockfile patch. Fixes yarnpkg#4405.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Spataro committed May 23, 2022
1 parent 342a64a commit cd5f3a8
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/yarnpkg-core/sources/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1568,24 +1568,27 @@ export class Project {
const newLockfile = normalizeLineEndings(initialLockfile, this.generateLockfile());

if (newLockfile !== initialLockfile) {
const diff = structuredPatch(lockfilePath, lockfilePath, initialLockfile, newLockfile);

opts.report.reportSeparator();

for (const hunk of diff.hunks) {
opts.report.reportInfo(null, `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`);
for (const line of hunk.lines) {
if (line.startsWith(`+`)) {
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.ADDED));
} else if (line.startsWith(`-`)) {
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.REMOVED));
} else {
opts.report.reportInfo(null, formatUtils.pretty(this.configuration, line, `grey`));
// @ts-expect-error 2345 need to upgrade to diff 5.0.1 or apply patch in yarn's monorepo
const diff = structuredPatch(lockfilePath, lockfilePath, initialLockfile, newLockfile, undefined, undefined, {maxEditLength: 100});

if (diff) {
opts.report.reportSeparator();

for (const hunk of diff.hunks) {
opts.report.reportInfo(null, `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`);
for (const line of hunk.lines) {
if (line.startsWith(`+`)) {
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.ADDED));
} else if (line.startsWith(`-`)) {
opts.report.reportError(MessageName.FROZEN_LOCKFILE_EXCEPTION, formatUtils.pretty(this.configuration, line, formatUtils.Type.REMOVED));
} else {
opts.report.reportInfo(null, formatUtils.pretty(this.configuration, line, `grey`));
}
}
}
}

opts.report.reportSeparator();
opts.report.reportSeparator();
}

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

0 comments on commit cd5f3a8

Please sign in to comment.