@biffo/cli 0.276.2 → 0.276.4

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.
Files changed (2) hide show
  1. package/dist/index.js +35 -33
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -584,6 +584,7 @@ import { join as join6 } from "path";
584
584
  import { execa as execa2 } from "execa";
585
585
 
586
586
  // src/lib/core-upgrade.ts
587
+ import { isUtf8 } from "buffer";
587
588
  import {
588
589
  chmodSync,
589
590
  existsSync as existsSync5,
@@ -737,8 +738,12 @@ var gitMergeFile = async (base, ours, theirs) => {
737
738
  rmSync(dir, { recursive: true, force: true });
738
739
  }
739
740
  };
740
- function read(root, rel) {
741
- return readFileSync4(join5(root, rel), "utf8");
741
+ function readFile(root, rel) {
742
+ const buffer = readFileSync4(join5(root, rel));
743
+ return { buffer, text: isUtf8(buffer) ? buffer.toString("utf8") : null };
744
+ }
745
+ function contentOf(file) {
746
+ return file.text ?? file.buffer;
742
747
  }
743
748
  var EMPTY_SUMMARY = () => ({
744
749
  unchanged: 0,
@@ -795,41 +800,46 @@ async function classify(path, base, ours, theirs, opts, mergeFile, isDeclaredDiv
795
800
  return { path, status: "keep-ours", conflicted: false, orphaned: true };
796
801
  }
797
802
  if (!inBase && inTheirs) {
798
- const theirsContent2 = read(opts.theirsDir, path);
799
- if (!inOurs) return { path, status: "added", conflicted: false, content: theirsContent2 };
800
- const oursContent2 = read(opts.oursDir, path);
801
- if (oursContent2 === theirsContent2) return { path, status: "unchanged", conflicted: false };
802
- return { path, status: "add-conflict", conflicted: true, content: theirsContent2 };
803
+ const theirsFile2 = readFile(opts.theirsDir, path);
804
+ if (!inOurs) return { path, status: "added", conflicted: false, content: contentOf(theirsFile2) };
805
+ const oursFile2 = readFile(opts.oursDir, path);
806
+ if (oursFile2.buffer.equals(theirsFile2.buffer))
807
+ return { path, status: "unchanged", conflicted: false };
808
+ return { path, status: "add-conflict", conflicted: true, content: contentOf(theirsFile2) };
803
809
  }
804
810
  if (inBase && !inTheirs) {
805
811
  if (!inOurs) return { path, status: "removed", conflicted: false };
806
- const baseContent2 = read(opts.baseDir, path);
807
- const oursContent2 = read(opts.oursDir, path);
808
- if (oursContent2 === baseContent2) return { path, status: "removed", conflicted: false };
812
+ const baseFile2 = readFile(opts.baseDir, path);
813
+ const oursFile2 = readFile(opts.oursDir, path);
814
+ if (oursFile2.buffer.equals(baseFile2.buffer))
815
+ return { path, status: "removed", conflicted: false };
809
816
  return { path, status: "remove-conflict", conflicted: true };
810
817
  }
811
- const baseContent = read(opts.baseDir, path);
812
- const theirsContent = read(opts.theirsDir, path);
818
+ const baseFile = readFile(opts.baseDir, path);
819
+ const theirsFile = readFile(opts.theirsDir, path);
813
820
  if (!inOurs) {
814
821
  if (isDeclaredDivergent(path)) {
815
822
  noteDivergenceSkip(path);
816
823
  return { path, status: "removed", conflicted: false };
817
824
  }
818
- return { path, status: "restored", conflicted: false, content: theirsContent };
825
+ return { path, status: "restored", conflicted: false, content: contentOf(theirsFile) };
819
826
  }
820
- const oursContent = read(opts.oursDir, path);
821
- const oursChanged = oursContent !== baseContent;
822
- const theirsChanged = theirsContent !== baseContent;
827
+ const oursFile = readFile(opts.oursDir, path);
828
+ const oursChanged = !oursFile.buffer.equals(baseFile.buffer);
829
+ const theirsChanged = !theirsFile.buffer.equals(baseFile.buffer);
823
830
  if (!theirsChanged) {
824
831
  return { path, status: oursChanged ? "keep-ours" : "unchanged", conflicted: false };
825
832
  }
826
833
  if (!oursChanged) {
827
- return { path, status: "take-theirs", conflicted: false, content: theirsContent };
834
+ return { path, status: "take-theirs", conflicted: false, content: contentOf(theirsFile) };
828
835
  }
829
- if (oursContent === theirsContent) {
836
+ if (oursFile.buffer.equals(theirsFile.buffer)) {
830
837
  return { path, status: "unchanged", conflicted: false };
831
838
  }
832
- const { conflicted, content } = await mergeFile(baseContent, oursContent, theirsContent);
839
+ if (baseFile.text === null || oursFile.text === null || theirsFile.text === null) {
840
+ return { path, status: "conflict", conflicted: true, content: contentOf(theirsFile) };
841
+ }
842
+ const { conflicted, content } = await mergeFile(baseFile.text, oursFile.text, theirsFile.text);
833
843
  return { path, status: conflicted ? "conflict" : "merged", conflicted, content };
834
844
  }
835
845
  function applyUpgradePlan(instanceDir, plan, theirsDir) {
@@ -941,7 +951,7 @@ var GitAdapter = class {
941
951
  * scaffold's throwaway temp dir inherits.
942
952
  */
943
953
  async configuredIdentity(cwd) {
944
- const read2 = async (key) => {
954
+ const read = async (key) => {
945
955
  try {
946
956
  const { stdout } = await execa2("git", ["config", "--get", key], cwd ? { cwd } : {});
947
957
  return stdout.trim() || null;
@@ -949,7 +959,7 @@ var GitAdapter = class {
949
959
  return null;
950
960
  }
951
961
  };
952
- return { name: await read2("user.name"), email: await read2("user.email") };
962
+ return { name: await read("user.name"), email: await read("user.email") };
953
963
  }
954
964
  async isGitRepo(cwd) {
955
965
  try {
@@ -2651,7 +2661,7 @@ function findMigrationTestPairings(changes, divergedBodies) {
2651
2661
  for (const change of changes) {
2652
2662
  if (!TEST_PATH_RE.test(change.path)) continue;
2653
2663
  const content = change.content;
2654
- if (content === void 0) continue;
2664
+ if (typeof content !== "string") continue;
2655
2665
  for (const d of divergedBodies) {
2656
2666
  if (content.includes(d.file)) {
2657
2667
  pairings.push({ testPath: change.path, migration: d.file, instanceFile: d.instanceFile });
@@ -2792,7 +2802,7 @@ var VERBATIM_STATUSES = /* @__PURE__ */ new Set(["take-theirs", "added", "add-co
2792
2802
  var DERIVED_STATUSES = /* @__PURE__ */ new Set(["merged", "conflict"]);
2793
2803
  var defaultGit3 = (args) => execFileSync4("git", args, { encoding: "utf8" });
2794
2804
  function blobId(content) {
2795
- const bytes = Buffer.from(content, "utf8");
2805
+ const bytes = Buffer.isBuffer(content) ? content : Buffer.from(content, "utf8");
2796
2806
  return createHash2("sha1").update(`blob ${String(bytes.length)}\0`).update(bytes).digest("hex");
2797
2807
  }
2798
2808
  function tagBlobIds(repo, tag, git) {
@@ -2839,7 +2849,7 @@ function assertTargetFidelity(options) {
2839
2849
  source = "output";
2840
2850
  } else if (DERIVED_STATUSES.has(entry.status)) {
2841
2851
  const abs = join9(options.theirsDir, entry.path);
2842
- content = existsSync8(abs) ? readFileSync6(abs, "utf8") : void 0;
2852
+ content = existsSync8(abs) ? readFileSync6(abs) : void 0;
2843
2853
  source = "merge-input";
2844
2854
  } else {
2845
2855
  continue;
@@ -2851,15 +2861,7 @@ function assertTargetFidelity(options) {
2851
2861
  findings.push({ path: entry.path, reason: "absent-from-tag", source });
2852
2862
  continue;
2853
2863
  }
2854
- if (blobId(content) === expected) continue;
2855
- let tagText;
2856
- try {
2857
- tagText = git(["-C", options.templateRepo, "show", `${tag}:${entry.path}`]);
2858
- } catch {
2859
- findings.push({ path: entry.path, reason: "content-differs", source });
2860
- continue;
2861
- }
2862
- if (tagText !== content) {
2864
+ if (blobId(content) !== expected) {
2863
2865
  findings.push({ path: entry.path, reason: "content-differs", source });
2864
2866
  }
2865
2867
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.276.2",
3
+ "version": "0.276.4",
4
4
  "description": "Biffo project scaffolding CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",