@pierre/diffs 1.1.0-beta.5 → 1.1.0-beta.7

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.
@@ -11746,7 +11746,7 @@ function attachResolvedThemes(themes, highlighter$1) {
11746
11746
  }
11747
11747
 
11748
11748
  //#endregion
11749
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/base.js
11749
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/base.js
11750
11750
  var Diff = class {
11751
11751
  diff(oldStr, newStr, options = {}) {
11752
11752
  let callback;
@@ -11970,7 +11970,7 @@ var Diff = class {
11970
11970
  };
11971
11971
 
11972
11972
  //#endregion
11973
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/character.js
11973
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/character.js
11974
11974
  var CharacterDiff = class extends Diff {};
11975
11975
  const characterDiff = new CharacterDiff();
11976
11976
  function diffChars(oldStr, newStr, options) {
@@ -11978,7 +11978,7 @@ function diffChars(oldStr, newStr, options) {
11978
11978
  }
11979
11979
 
11980
11980
  //#endregion
11981
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/util/string.js
11981
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/util/string.js
11982
11982
  function longestCommonPrefix(str1, str2) {
11983
11983
  let i$2;
11984
11984
  for (i$2 = 0; i$2 < str1.length && i$2 < str2.length; i$2++) {
@@ -12087,8 +12087,8 @@ function leadingWs(string) {
12087
12087
  }
12088
12088
 
12089
12089
  //#endregion
12090
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/word.js
12091
- const extendedWordChars = "a-zA-Z0-9_\\u{C0}-\\u{FF}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";
12090
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/word.js
12091
+ const extendedWordChars = "a-zA-Z0-9_\\u{AD}\\u{C0}-\\u{D6}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";
12092
12092
  const tokenizeIncludingWhitespace = new RegExp(`[${extendedWordChars}]+|\\s+|[^${extendedWordChars}]`, "ug");
12093
12093
  var WordDiff = class extends Diff {
12094
12094
  equals(left, right, options) {
@@ -12105,7 +12105,15 @@ var WordDiff = class extends Diff {
12105
12105
  if (segmenter.resolvedOptions().granularity != "word") {
12106
12106
  throw new Error("The segmenter passed must have a granularity of \"word\"");
12107
12107
  }
12108
- parts = Array.from(segmenter.segment(value), (segment) => segment.segment);
12108
+ parts = [];
12109
+ for (const segmentObj of Array.from(segmenter.segment(value))) {
12110
+ const segment = segmentObj.segment;
12111
+ if (parts.length && /\s/.test(parts[parts.length - 1]) && /\s/.test(segment)) {
12112
+ parts[parts.length - 1] += segment;
12113
+ } else {
12114
+ parts.push(segment);
12115
+ }
12116
+ }
12109
12117
  } else {
12110
12118
  parts = value.match(tokenizeIncludingWhitespace) || [];
12111
12119
  }
@@ -12233,7 +12241,7 @@ function diffWordsWithSpace(oldStr, newStr, options) {
12233
12241
  }
12234
12242
 
12235
12243
  //#endregion
12236
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/util/params.js
12244
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/util/params.js
12237
12245
  function generateOptions(options, defaults) {
12238
12246
  if (typeof options === "function") {
12239
12247
  defaults.callback = options;
@@ -12249,7 +12257,7 @@ function generateOptions(options, defaults) {
12249
12257
  }
12250
12258
 
12251
12259
  //#endregion
12252
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/line.js
12260
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/line.js
12253
12261
  var LineDiff = class extends Diff {
12254
12262
  constructor() {
12255
12263
  super(...arguments);
@@ -12302,7 +12310,7 @@ function tokenize(value, options) {
12302
12310
  }
12303
12311
 
12304
12312
  //#endregion
12305
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/sentence.js
12313
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/sentence.js
12306
12314
  function isSentenceEndPunct(char) {
12307
12315
  return char == "." || char == "!" || char == "?";
12308
12316
  }
@@ -12335,7 +12343,7 @@ function diffSentences(oldStr, newStr, options) {
12335
12343
  }
12336
12344
 
12337
12345
  //#endregion
12338
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/css.js
12346
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/css.js
12339
12347
  var CssDiff = class extends Diff {
12340
12348
  tokenize(value) {
12341
12349
  return value.split(/([{}:;,]|\s+)/);
@@ -12347,7 +12355,7 @@ function diffCss(oldStr, newStr, options) {
12347
12355
  }
12348
12356
 
12349
12357
  //#endregion
12350
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/json.js
12358
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/json.js
12351
12359
  var JsonDiff = class extends Diff {
12352
12360
  constructor() {
12353
12361
  super(...arguments);
@@ -12421,7 +12429,7 @@ function canonicalize(obj, stack, replacementStack, replacer, key$1) {
12421
12429
  }
12422
12430
 
12423
12431
  //#endregion
12424
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/array.js
12432
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/array.js
12425
12433
  var ArrayDiff = class extends Diff {
12426
12434
  tokenize(value) {
12427
12435
  return value.slice();
@@ -12439,7 +12447,7 @@ function diffArrays(oldArr, newArr, options) {
12439
12447
  }
12440
12448
 
12441
12449
  //#endregion
12442
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/patch/line-endings.js
12450
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/patch/line-endings.js
12443
12451
  function unixToWin(patch) {
12444
12452
  if (Array.isArray(patch)) {
12445
12453
  return patch.map((p$1) => unixToWin(p$1));
@@ -12479,7 +12487,7 @@ function isWin(patch) {
12479
12487
  }
12480
12488
 
12481
12489
  //#endregion
12482
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/patch/parse.js
12490
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/patch/parse.js
12483
12491
  /**
12484
12492
  * Parses a patch into structured data, in the same structure returned by `structuredPatch`.
12485
12493
  *
@@ -12496,9 +12504,9 @@ function parsePatch(uniDiff) {
12496
12504
  if (/^(---|\+\+\+|@@)\s/.test(line)) {
12497
12505
  break;
12498
12506
  }
12499
- const header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
12500
- if (header) {
12501
- index.index = header[1];
12507
+ const headerMatch = /^(?:Index:|diff(?: -r \w+)+)\s+/.exec(line);
12508
+ if (headerMatch) {
12509
+ index.index = line.substring(headerMatch[0].length).trim();
12502
12510
  }
12503
12511
  i$2++;
12504
12512
  }
@@ -12519,14 +12527,14 @@ function parsePatch(uniDiff) {
12519
12527
  }
12520
12528
  }
12521
12529
  function parseFileHeader(index) {
12522
- const fileHeader = /^(---|\+\+\+)\s+(.*)\r?$/.exec(diffstr[i$2]);
12523
- if (fileHeader) {
12524
- const data = fileHeader[2].split(" ", 2), header = (data[1] || "").trim();
12530
+ const fileHeaderMatch = /^(---|\+\+\+)\s+/.exec(diffstr[i$2]);
12531
+ if (fileHeaderMatch) {
12532
+ const prefix = fileHeaderMatch[1], data = diffstr[i$2].substring(3).trim().split(" ", 2), header = (data[1] || "").trim();
12525
12533
  let fileName = data[0].replace(/\\\\/g, "\\");
12526
- if (/^".*"$/.test(fileName)) {
12534
+ if (fileName.startsWith("\"") && fileName.endsWith("\"")) {
12527
12535
  fileName = fileName.substr(1, fileName.length - 2);
12528
12536
  }
12529
- if (fileHeader[1] === "---") {
12537
+ if (prefix === "---") {
12530
12538
  index.oldFileName = fileName;
12531
12539
  index.oldHeader = header;
12532
12540
  } else {
@@ -12590,7 +12598,7 @@ function parsePatch(uniDiff) {
12590
12598
  }
12591
12599
 
12592
12600
  //#endregion
12593
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/util/distance-iterator.js
12601
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/util/distance-iterator.js
12594
12602
  function distance_iterator_default(start, minLine, maxLine) {
12595
12603
  let wantForward = true, backwardExhausted = false, forwardExhausted = false, localOffset = 1;
12596
12604
  return function iterator() {
@@ -12620,7 +12628,7 @@ function distance_iterator_default(start, minLine, maxLine) {
12620
12628
  }
12621
12629
 
12622
12630
  //#endregion
12623
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/patch/apply.js
12631
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/patch/apply.js
12624
12632
  /**
12625
12633
  * attempts to apply a unified diff patch.
12626
12634
  *
@@ -12839,7 +12847,7 @@ function applyPatches(uniDiff, options) {
12839
12847
  }
12840
12848
 
12841
12849
  //#endregion
12842
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/patch/reverse.js
12850
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/patch/reverse.js
12843
12851
  function reversePatch(structuredPatch$1) {
12844
12852
  if (Array.isArray(structuredPatch$1)) {
12845
12853
  return structuredPatch$1.map((patch) => reversePatch(patch)).reverse();
@@ -12870,7 +12878,22 @@ function reversePatch(structuredPatch$1) {
12870
12878
  }
12871
12879
 
12872
12880
  //#endregion
12873
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/patch/create.js
12881
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/patch/create.js
12882
+ const INCLUDE_HEADERS = {
12883
+ includeIndex: true,
12884
+ includeUnderline: true,
12885
+ includeFileHeaders: true
12886
+ };
12887
+ const FILE_HEADERS_ONLY = {
12888
+ includeIndex: false,
12889
+ includeUnderline: false,
12890
+ includeFileHeaders: true
12891
+ };
12892
+ const OMIT_HEADERS = {
12893
+ includeIndex: false,
12894
+ includeUnderline: false,
12895
+ includeFileHeaders: false
12896
+ };
12874
12897
  function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
12875
12898
  let optionsObj;
12876
12899
  if (!options) {
@@ -12984,17 +13007,27 @@ function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, ne
12984
13007
  * creates a unified diff patch.
12985
13008
  * @param patch either a single structured patch object (as returned by `structuredPatch`) or an array of them (as returned by `parsePatch`)
12986
13009
  */
12987
- function formatPatch(patch) {
13010
+ function formatPatch(patch, headerOptions) {
13011
+ if (!headerOptions) {
13012
+ headerOptions = INCLUDE_HEADERS;
13013
+ }
12988
13014
  if (Array.isArray(patch)) {
12989
- return patch.map(formatPatch).join("\n");
13015
+ if (patch.length > 1 && !headerOptions.includeFileHeaders) {
13016
+ throw new Error("Cannot omit file headers on a multi-file patch. " + "(The result would be unparseable; how would a tool trying to apply " + "the patch know which changes are to which file?)");
13017
+ }
13018
+ return patch.map((p$1) => formatPatch(p$1, headerOptions)).join("\n");
12990
13019
  }
12991
13020
  const ret = [];
12992
- if (patch.oldFileName == patch.newFileName) {
13021
+ if (headerOptions.includeIndex && patch.oldFileName == patch.newFileName) {
12993
13022
  ret.push("Index: " + patch.oldFileName);
12994
13023
  }
12995
- ret.push("===================================================================");
12996
- ret.push("--- " + patch.oldFileName + (typeof patch.oldHeader === "undefined" ? "" : " " + patch.oldHeader));
12997
- ret.push("+++ " + patch.newFileName + (typeof patch.newHeader === "undefined" ? "" : " " + patch.newHeader));
13024
+ if (headerOptions.includeUnderline) {
13025
+ ret.push("===================================================================");
13026
+ }
13027
+ if (headerOptions.includeFileHeaders) {
13028
+ ret.push("--- " + patch.oldFileName + (typeof patch.oldHeader === "undefined" ? "" : " " + patch.oldHeader));
13029
+ ret.push("+++ " + patch.newFileName + (typeof patch.newHeader === "undefined" ? "" : " " + patch.newHeader));
13030
+ }
12998
13031
  for (let i$2 = 0; i$2 < patch.hunks.length; i$2++) {
12999
13032
  const hunk = patch.hunks[i$2];
13000
13033
  if (hunk.oldLines === 0) {
@@ -13019,14 +13052,14 @@ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader
13019
13052
  if (!patchObj) {
13020
13053
  return;
13021
13054
  }
13022
- return formatPatch(patchObj);
13055
+ return formatPatch(patchObj, options === null || options === void 0 ? void 0 : options.headerOptions);
13023
13056
  } else {
13024
13057
  const { callback } = options;
13025
13058
  structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, Object.assign(Object.assign({}, options), { callback: (patchObj) => {
13026
13059
  if (!patchObj) {
13027
13060
  callback(undefined);
13028
13061
  } else {
13029
- callback(formatPatch(patchObj));
13062
+ callback(formatPatch(patchObj, options.headerOptions));
13030
13063
  }
13031
13064
  } }));
13032
13065
  }
@@ -13049,7 +13082,7 @@ function splitLines(text$1) {
13049
13082
  }
13050
13083
 
13051
13084
  //#endregion
13052
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/convert/dmp.js
13085
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/convert/dmp.js
13053
13086
  /**
13054
13087
  * converts a list of change objects to the format returned by Google's [diff-match-patch](https://github.com/google/diff-match-patch) library
13055
13088
  */
@@ -13071,7 +13104,7 @@ function convertChangesToDMP(changes) {
13071
13104
  }
13072
13105
 
13073
13106
  //#endregion
13074
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/convert/xml.js
13107
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/convert/xml.js
13075
13108
  /**
13076
13109
  * converts a list of change objects to a serialized XML format
13077
13110
  */