@yarnpkg/plugin-essentials 4.0.0-rc.27 → 4.0.0-rc.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -303,9 +303,6 @@ YarnCommand.usage = clipanion_1.Command.Usage({
303
303
  `$0 install --immutable --immutable-cache --check-cache`,
304
304
  ]],
305
305
  });
306
- const MERGE_CONFLICT_ANCESTOR = `|||||||`;
307
- const MERGE_CONFLICT_END = `>>>>>>>`;
308
- const MERGE_CONFLICT_SEP = `=======`;
309
306
  const MERGE_CONFLICT_START = `<<<<<<<`;
310
307
  async function autofixMergeConflicts(configuration, immutable) {
311
308
  if (!configuration.projectCwd)
@@ -318,22 +315,57 @@ async function autofixMergeConflicts(configuration, immutable) {
318
315
  return false;
319
316
  if (immutable)
320
317
  throw new core_1.ReportError(core_1.MessageName.AUTOMERGE_IMMUTABLE, `Cannot autofix a lockfile when running an immutable install`);
321
- const [left, right] = getVariants(file);
322
- let parsedLeft;
323
- let parsedRight;
324
- try {
325
- parsedLeft = (0, parsers_1.parseSyml)(left);
326
- parsedRight = (0, parsers_1.parseSyml)(right);
327
- }
328
- catch (error) {
329
- throw new core_1.ReportError(core_1.MessageName.AUTOMERGE_FAILED_TO_PARSE, `The individual variants of the lockfile failed to parse`);
330
- }
331
- const merged = {
332
- ...parsedLeft,
333
- ...parsedRight,
334
- };
318
+ const commits = await core_1.execUtils.execvp(`git`, [`rev-parse`, `MERGE_HEAD`, `HEAD`], {
319
+ cwd: configuration.projectCwd,
320
+ });
321
+ if (commits.code !== 0)
322
+ throw new core_1.ReportError(core_1.MessageName.AUTOMERGE_GIT_ERROR, `Git returned an error when trying to find the commits pertaining to the merge conflict`);
323
+ let variants = await Promise.all(commits.stdout.trim().split(/\n/).map(async (hash) => {
324
+ const content = await core_1.execUtils.execvp(`git`, [`show`, `${hash}:./${fslib_1.Filename.lockfile}`], {
325
+ cwd: configuration.projectCwd,
326
+ });
327
+ if (content.code !== 0)
328
+ throw new core_1.ReportError(core_1.MessageName.AUTOMERGE_GIT_ERROR, `Git returned an error when trying to access the lockfile content in ${hash}`);
329
+ try {
330
+ return (0, parsers_1.parseSyml)(content.stdout);
331
+ }
332
+ catch {
333
+ throw new core_1.ReportError(core_1.MessageName.AUTOMERGE_FAILED_TO_PARSE, `A variant of the conflicting lockfile failed to parse`);
334
+ }
335
+ }));
335
336
  // Old-style lockfiles should be filtered out (for example when switching
336
- // from a Yarn 2 branch to a Yarn 1 branch). Fortunately (?), they actually
337
+ // from a Yarn 2 branch to a Yarn 1 branch).
338
+ variants = variants.filter(variant => {
339
+ return !!variant.__metadata;
340
+ });
341
+ for (const variant of variants) {
342
+ // Pre-lockfile v7, the entries weren't normalized (ie we had "foo@x.y.z"
343
+ // in the lockfile rather than "foo@npm:x.y.z")
344
+ if (variant.__metadata.version < 7) {
345
+ for (const key of Object.keys(variant)) {
346
+ if (key === `__metadata`)
347
+ continue;
348
+ const descriptor = core_1.structUtils.parseDescriptor(key, true);
349
+ const normalizedDescriptor = configuration.normalizeDependency(descriptor);
350
+ const newKey = core_1.structUtils.stringifyDescriptor(normalizedDescriptor);
351
+ if (newKey !== key) {
352
+ variant[newKey] = variant[key];
353
+ delete variant[key];
354
+ }
355
+ }
356
+ }
357
+ }
358
+ const merged = Object.assign({}, ...variants);
359
+ // We must keep the lockfile version as small as necessary to force Yarn to
360
+ // refresh the merged-in lockfile metadata that may be missing.
361
+ merged.__metadata.version = Math.min(0, ...variants.map(variant => {
362
+ var _a;
363
+ return (_a = variant.__metadata.version) !== null && _a !== void 0 ? _a : Infinity;
364
+ }));
365
+ merged.__metadata.cacheKey = Math.min(0, ...variants.map(variant => {
366
+ var _a;
367
+ return (_a = variant.__metadata.cacheKey) !== null && _a !== void 0 ? _a : 0;
368
+ }));
337
369
  // parse as valid YAML except that the objects become strings. We can use
338
370
  // that to detect them. Damn, it's really ugly though.
339
371
  for (const [key, value] of Object.entries(merged))
@@ -344,52 +376,3 @@ async function autofixMergeConflicts(configuration, immutable) {
344
376
  });
345
377
  return true;
346
378
  }
347
- function getVariants(file) {
348
- const variants = [[], []];
349
- const lines = file.split(/\r?\n/g);
350
- let skip = false;
351
- while (lines.length > 0) {
352
- const line = lines.shift();
353
- if (typeof line === `undefined`)
354
- throw new Error(`Assertion failed: Some lines should remain`);
355
- if (line.startsWith(MERGE_CONFLICT_START)) {
356
- // get the first variant
357
- while (lines.length > 0) {
358
- const conflictLine = lines.shift();
359
- if (typeof conflictLine === `undefined`)
360
- throw new Error(`Assertion failed: Some lines should remain`);
361
- if (conflictLine === MERGE_CONFLICT_SEP) {
362
- skip = false;
363
- break;
364
- }
365
- else if (skip || conflictLine.startsWith(MERGE_CONFLICT_ANCESTOR)) {
366
- skip = true;
367
- continue;
368
- }
369
- else {
370
- variants[0].push(conflictLine);
371
- }
372
- }
373
- // get the second variant
374
- while (lines.length > 0) {
375
- const conflictLine = lines.shift();
376
- if (typeof conflictLine === `undefined`)
377
- throw new Error(`Assertion failed: Some lines should remain`);
378
- if (conflictLine.startsWith(MERGE_CONFLICT_END)) {
379
- break;
380
- }
381
- else {
382
- variants[1].push(conflictLine);
383
- }
384
- }
385
- }
386
- else {
387
- variants[0].push(line);
388
- variants[1].push(line);
389
- }
390
- }
391
- return [
392
- variants[0].join(`\n`),
393
- variants[1].join(`\n`),
394
- ];
395
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarnpkg/plugin-essentials",
3
- "version": "4.0.0-rc.27",
3
+ "version": "4.0.0-rc.29",
4
4
  "stableVersion": "3.2.3",
5
5
  "license": "BSD-2-Clause",
6
6
  "main": "./lib/index.js",
@@ -9,8 +9,8 @@
9
9
  "./package.json": "./package.json"
10
10
  },
11
11
  "dependencies": {
12
- "@yarnpkg/fslib": "^3.0.0-rc.27",
13
- "@yarnpkg/parsers": "^3.0.0-rc.27",
12
+ "@yarnpkg/fslib": "^3.0.0-rc.29",
13
+ "@yarnpkg/parsers": "^3.0.0-rc.29",
14
14
  "ci-info": "^3.2.0",
15
15
  "clipanion": "^3.2.0-rc.10",
16
16
  "enquirer": "^2.3.6",
@@ -21,17 +21,17 @@
21
21
  "typanion": "^3.3.0"
22
22
  },
23
23
  "peerDependencies": {
24
- "@yarnpkg/cli": "^4.0.0-rc.27",
25
- "@yarnpkg/core": "^4.0.0-rc.27",
26
- "@yarnpkg/plugin-git": "^3.0.0-rc.27"
24
+ "@yarnpkg/cli": "^4.0.0-rc.29",
25
+ "@yarnpkg/core": "^4.0.0-rc.29",
26
+ "@yarnpkg/plugin-git": "^3.0.0-rc.29"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/lodash": "^4.14.136",
30
30
  "@types/micromatch": "^4.0.1",
31
31
  "@types/semver": "^7.1.0",
32
- "@yarnpkg/cli": "^4.0.0-rc.27",
33
- "@yarnpkg/core": "^4.0.0-rc.27",
34
- "@yarnpkg/plugin-git": "^3.0.0-rc.27"
32
+ "@yarnpkg/cli": "^4.0.0-rc.29",
33
+ "@yarnpkg/core": "^4.0.0-rc.29",
34
+ "@yarnpkg/plugin-git": "^3.0.0-rc.29"
35
35
  },
36
36
  "repository": {
37
37
  "type": "git",