@dimm-city/print-md 0.4.1 → 0.5.0-rc.10

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.
package/dist/cli.js CHANGED
@@ -758,6 +758,15 @@ var init_images = __esm(() => {
758
758
  PREFIX_PATTERNS = [/^(?:\.\/|\/)?temp\/images\//, /^(?:\.\/|\/)?images\//];
759
759
  });
760
760
 
761
+ // ../lib/src/lib/markdown/chapter-id.ts
762
+ function canonicalChapterId(p) {
763
+ let s = String(p).replace(/\\/g, "/");
764
+ s = s.replace(/\/{2,}/g, "/");
765
+ while (s.startsWith("./"))
766
+ s = s.slice(2);
767
+ return s;
768
+ }
769
+
761
770
  // ../lib/src/lib/markdown/plugins.ts
762
771
  import { existsSync as existsSync2 } from "node:fs";
763
772
  import { resolve as resolve2, join } from "node:path";
@@ -911,12 +920,13 @@ async function renderChapters(inputDir, opts = {}) {
911
920
  }
912
921
  let bodyContent = "";
913
922
  for (const file of files) {
914
- const filePath = join2(inputDir, file);
923
+ const chapterId = canonicalChapterId(file);
924
+ const filePath = join2(inputDir, chapterId);
915
925
  try {
916
926
  const content = await readFile2(filePath, "utf-8");
917
927
  const rendered = md.render(content);
918
928
  if (opts.wrapChapters) {
919
- const safe = String(file).replace(/&/g, "&").replace(/"/g, """);
929
+ const safe = chapterId.replace(/&/g, "&").replace(/"/g, """);
920
930
  bodyContent += `<div class="pmd-chapter" data-chapter-src="${safe}">
921
931
  ${rendered}
922
932
  </div>
@@ -22693,7 +22703,7 @@ var package_default;
22693
22703
  var init_package = __esm(() => {
22694
22704
  package_default = {
22695
22705
  name: "@dimm-city/print-md-lib",
22696
- version: "0.4.1",
22706
+ version: "0.5.0-rc.10",
22697
22707
  private: true,
22698
22708
  type: "module",
22699
22709
  main: "dist/index.js",
@@ -22724,6 +22734,7 @@ var init_package = __esm(() => {
22724
22734
  },
22725
22735
  dependencies: {
22726
22736
  chokidar: "^5.0.0",
22737
+ diff3: "0.0.3",
22727
22738
  glob: "^13.0.0",
22728
22739
  htmlhint: "^1.9.2",
22729
22740
  "isomorphic-git": "^1.38.4",
@@ -22941,7 +22952,7 @@ var manifest_schema_default = "./manifest.schema-16z94mx1.json";
22941
22952
  var init_manifest_schema = () => {};
22942
22953
 
22943
22954
  // ../lib/src/assets/preview/scripts/pagedjs-interface.js
22944
- var pagedjs_interface_default = "./pagedjs-interface-er3k3jvc.js";
22955
+ var pagedjs_interface_default = "./pagedjs-interface-x79je7c5.js";
22945
22956
  var init_pagedjs_interface = () => {};
22946
22957
 
22947
22958
  // ../lib/src/assets/preview/scripts/pagedjs-bridge.js
@@ -22949,7 +22960,7 @@ var pagedjs_bridge_default = "./pagedjs-bridge-k1a8jxtv.js";
22949
22960
  var init_pagedjs_bridge = () => {};
22950
22961
 
22951
22962
  // ../lib/src/assets/preview/scripts/preview-shell.js
22952
- var preview_shell_default = "./preview-shell-663marwv.js";
22963
+ var preview_shell_default = "./preview-shell-fx145xzs.js";
22953
22964
  var init_preview_shell = () => {};
22954
22965
 
22955
22966
  // ../lib/src/assets/vendor/paged.polyfill.js
@@ -93538,13 +93549,19 @@ function resolveExternalAssetRoots(inputPath, assets) {
93538
93549
  function resolveDestinationForChange(filePath2, inputPath, tempDir, externalRoots) {
93539
93550
  if (filePath2 === inputPath || filePath2.startsWith(inputPath + path6.sep)) {
93540
93551
  const relativePath = path6.relative(inputPath, filePath2);
93541
- return { destPath: path6.join(tempDir, relativePath), relativePath };
93552
+ return {
93553
+ destPath: path6.join(tempDir, relativePath),
93554
+ relativePath: relativePath.replace(/\\/g, "/")
93555
+ };
93542
93556
  }
93543
93557
  for (const root2 of externalRoots) {
93544
93558
  if (filePath2 === root2.src || filePath2.startsWith(root2.src + path6.sep)) {
93545
93559
  const relInRoot = path6.relative(root2.src, filePath2);
93546
93560
  const relativePath = path6.join(root2.destName, relInRoot);
93547
- return { destPath: path6.join(tempDir, relativePath), relativePath };
93561
+ return {
93562
+ destPath: path6.join(tempDir, relativePath),
93563
+ relativePath: relativePath.replace(/\\/g, "/")
93564
+ };
93548
93565
  }
93549
93566
  }
93550
93567
  return null;
@@ -93634,44 +93651,69 @@ function createFileWatcher(state) {
93634
93651
  pollInterval: 50
93635
93652
  }
93636
93653
  });
93637
- watcher.on("all", async (event, filePath2) => {
93638
- debug2(`File ${event}: ${filePath2}`);
93654
+ const pendingChanges = new Map;
93655
+ function scheduleRebuild() {
93639
93656
  if (state.rebuildTimer)
93640
93657
  clearTimeout(state.rebuildTimer);
93641
- state.rebuildTimer = setTimeout(async () => {
93642
- if (state.isRebuilding)
93643
- return;
93644
- state.isRebuilding = true;
93645
- try {
93646
- info("Regenerating preview...");
93647
- const dest = resolveDestinationForChange(filePath2, inputResolved, state.tempDir, externalRoots);
93648
- if (dest) {
93658
+ state.rebuildTimer = setTimeout(runRebuild, DEBOUNCE.FILE_WATCH);
93659
+ }
93660
+ async function runRebuild() {
93661
+ if (state.isRebuilding)
93662
+ return;
93663
+ const changes = [...pendingChanges.entries()];
93664
+ pendingChanges.clear();
93665
+ if (changes.length === 0)
93666
+ return;
93667
+ state.isRebuilding = true;
93668
+ try {
93669
+ info("Regenerating preview...");
93670
+ const dests = [];
93671
+ for (const [changedPath, changedEvent] of changes) {
93672
+ const dest = resolveDestinationForChange(changedPath, inputResolved, state.tempDir, externalRoots);
93673
+ if (!dest)
93674
+ continue;
93675
+ if (existsSync13(changedPath)) {
93649
93676
  await fsp2.mkdir(path6.dirname(dest.destPath), { recursive: true });
93650
- await fsp2.copyFile(filePath2, dest.destPath);
93677
+ await fsp2.copyFile(changedPath, dest.destPath);
93651
93678
  debug2(`Updated: ${dest.relativePath}`);
93652
93679
  }
93653
- if (dest && path6.extname(filePath2).toLowerCase() === ".css") {
93654
- state.previewServer?.broadcastCssUpdate(dest.relativePath);
93655
- info(`CSS hot-swapped: ${dest.relativePath}`);
93656
- return;
93657
- }
93658
- const manifest = await loadManifest(state.currentInputPath);
93659
- const updatedConfig = resolveConfig({}, manifest);
93660
- state.config = updatedConfig;
93661
- await generateAndWriteHtml(state.currentInputPath, state.tempDir, updatedConfig);
93662
- if (incrementalPreviewEnabled() && dest && path6.extname(filePath2).toLowerCase() === ".md") {
93663
- state.previewServer?.broadcastContentUpdate(dest.relativePath);
93664
- info(`Chapter updated: ${dest.relativePath}`);
93665
- } else {
93666
- state.previewServer?.broadcastReload();
93667
- info("Preview updated");
93680
+ dests.push({
93681
+ relativePath: dest.relativePath,
93682
+ ext: path6.extname(changedPath).toLowerCase(),
93683
+ event: changedEvent
93684
+ });
93685
+ }
93686
+ if (dests.length === changes.length && dests.length > 0 && dests.every((d) => d.ext === ".css")) {
93687
+ for (const d of dests) {
93688
+ state.previewServer?.broadcastCssUpdate(d.relativePath);
93689
+ info(`CSS hot-swapped: ${d.relativePath}`);
93668
93690
  }
93669
- } catch (err) {
93670
- error("Failed to regenerate preview:", err);
93671
- } finally {
93672
- state.isRebuilding = false;
93691
+ return;
93673
93692
  }
93674
- }, DEBOUNCE.FILE_WATCH);
93693
+ const manifest = await loadManifest(state.currentInputPath);
93694
+ const updatedConfig = resolveConfig({}, manifest);
93695
+ state.config = updatedConfig;
93696
+ await generateAndWriteHtml(state.currentInputPath, state.tempDir, updatedConfig);
93697
+ const only = dests.length === 1 ? dests[0] : null;
93698
+ if (incrementalPreviewEnabled() && changes.length === 1 && only && only.ext === ".md" && only.event !== "unlink" && only.event !== "unlinkDir") {
93699
+ state.previewServer?.broadcastContentUpdate(canonicalChapterId(only.relativePath));
93700
+ info(`Chapter updated: ${only.relativePath}`);
93701
+ } else {
93702
+ state.previewServer?.broadcastReload();
93703
+ info(changes.length > 1 ? `Preview updated (${changes.length} files changed — full reload)` : "Preview updated");
93704
+ }
93705
+ } catch (err) {
93706
+ error("Failed to regenerate preview:", err);
93707
+ } finally {
93708
+ state.isRebuilding = false;
93709
+ if (pendingChanges.size > 0)
93710
+ scheduleRebuild();
93711
+ }
93712
+ }
93713
+ watcher.on("all", (event, filePath2) => {
93714
+ debug2(`File ${event}: ${filePath2}`);
93715
+ pendingChanges.set(filePath2, event);
93716
+ scheduleRebuild();
93675
93717
  });
93676
93718
  info("Watching for file changes...");
93677
93719
  return watcher;
@@ -94054,6 +94096,20 @@ async function createPreviewServer(state, port, restartPreviewFn) {
94054
94096
  }
94055
94097
  return;
94056
94098
  }
94099
+ if (url.pathname === "/__log" && req.method === "POST") {
94100
+ let body = "";
94101
+ req.on("data", (chunk) => {
94102
+ if (body.length < 2048)
94103
+ body += chunk;
94104
+ });
94105
+ req.on("end", () => {
94106
+ if (body)
94107
+ info(`[preview-shell] ${body.slice(0, 1024)}`);
94108
+ res.writeHead(204);
94109
+ res.end();
94110
+ });
94111
+ return;
94112
+ }
94057
94113
  if (url.pathname === "/__chapter") {
94058
94114
  const file = url.searchParams.get("file");
94059
94115
  if (!file || !state.currentInputPath) {
@@ -94379,6 +94435,108 @@ var init_diagnostics = __esm(() => {
94379
94435
  });
94380
94436
 
94381
94437
  // ../lib/src/lib/project-source.ts
94438
+ import { stat as stat5, readFile as readFile21 } from "node:fs/promises";
94439
+ import os3 from "node:os";
94440
+ import path9 from "node:path";
94441
+ async function isDirectory2(target) {
94442
+ try {
94443
+ return (await stat5(target)).isDirectory();
94444
+ } catch {
94445
+ return false;
94446
+ }
94447
+ }
94448
+ function parseRemoteUrl(configText) {
94449
+ const sectionRe = /\[remote\s+"([^"]+)"\]([^[]*)/g;
94450
+ let firstUrl;
94451
+ let originUrl;
94452
+ let match;
94453
+ while ((match = sectionRe.exec(configText)) !== null) {
94454
+ const name = match[1];
94455
+ const body = match[2] ?? "";
94456
+ const urlMatch = /^\s*url\s*=\s*(.+?)\s*$/m.exec(body);
94457
+ if (!urlMatch)
94458
+ continue;
94459
+ const url = urlMatch[1];
94460
+ if (!url)
94461
+ continue;
94462
+ if (firstUrl === undefined)
94463
+ firstUrl = url;
94464
+ if (name === "origin") {
94465
+ originUrl = url;
94466
+ break;
94467
+ }
94468
+ }
94469
+ return originUrl ?? firstUrl;
94470
+ }
94471
+ function parseHeadBranch(headText) {
94472
+ const match = /^ref:\s*refs\/heads\/(.+?)\s*$/m.exec(headText);
94473
+ return match ? match[1] : undefined;
94474
+ }
94475
+ async function findEnclosingRepoDir(folderPath) {
94476
+ const home = path9.resolve(os3.homedir());
94477
+ let dir = path9.resolve(folderPath);
94478
+ for (let i = 0;i < 64; i++) {
94479
+ const parent = path9.dirname(dir);
94480
+ if (parent === dir)
94481
+ return;
94482
+ dir = parent;
94483
+ if (await isDirectory2(path9.join(dir, ".git")))
94484
+ return dir;
94485
+ if (dir === home)
94486
+ return;
94487
+ }
94488
+ return;
94489
+ }
94490
+ async function readGitDirInfo(gitDir) {
94491
+ let remoteUrl;
94492
+ try {
94493
+ const configText = await readFile21(path9.join(gitDir, "config"), "utf8");
94494
+ remoteUrl = parseRemoteUrl(configText);
94495
+ } catch {
94496
+ remoteUrl = undefined;
94497
+ }
94498
+ let branch;
94499
+ try {
94500
+ const headText = await readFile21(path9.join(gitDir, "HEAD"), "utf8");
94501
+ branch = parseHeadBranch(headText);
94502
+ } catch {
94503
+ branch = undefined;
94504
+ }
94505
+ return { remoteUrl, branch };
94506
+ }
94507
+ function repoSubPath(repoRoot, folderPath) {
94508
+ const rel = path9.relative(path9.resolve(repoRoot), path9.resolve(folderPath));
94509
+ return rel.split(path9.sep).join("/");
94510
+ }
94511
+ async function detectProjectSource(folderPath) {
94512
+ const ownGitDir = path9.join(folderPath, ".git");
94513
+ if (await isDirectory2(ownGitDir)) {
94514
+ const { remoteUrl, branch } = await readGitDirInfo(ownGitDir);
94515
+ return {
94516
+ type: "local-git-folder",
94517
+ path: folderPath,
94518
+ repoRoot: folderPath,
94519
+ subPath: "",
94520
+ hasRemote: remoteUrl !== undefined,
94521
+ ...remoteUrl !== undefined ? { remoteUrl } : {},
94522
+ ...branch !== undefined ? { branch } : {}
94523
+ };
94524
+ }
94525
+ const enclosingRepoDir = await findEnclosingRepoDir(folderPath);
94526
+ if (enclosingRepoDir !== undefined) {
94527
+ const { remoteUrl, branch } = await readGitDirInfo(path9.join(enclosingRepoDir, ".git"));
94528
+ return {
94529
+ type: "local-git-folder",
94530
+ path: folderPath,
94531
+ repoRoot: enclosingRepoDir,
94532
+ subPath: repoSubPath(enclosingRepoDir, folderPath),
94533
+ hasRemote: remoteUrl !== undefined,
94534
+ ...remoteUrl !== undefined ? { remoteUrl } : {},
94535
+ ...branch !== undefined ? { branch } : {}
94536
+ };
94537
+ }
94538
+ return { type: "local-folder", path: folderPath };
94539
+ }
94382
94540
  function capabilitiesFor(source) {
94383
94541
  switch (source.type) {
94384
94542
  case "local-folder":
@@ -94389,7 +94547,6 @@ function capabilitiesFor(source) {
94389
94547
  canSnapshot: false,
94390
94548
  canViewHistory: false,
94391
94549
  canRestoreSnapshot: false,
94392
- canPublish: false,
94393
94550
  canSync: false,
94394
94551
  authManagedByApp: false
94395
94552
  };
@@ -94401,7 +94558,6 @@ function capabilitiesFor(source) {
94401
94558
  canSnapshot: true,
94402
94559
  canViewHistory: true,
94403
94560
  canRestoreSnapshot: true,
94404
- canPublish: source.hasRemote,
94405
94561
  canSync: source.hasRemote,
94406
94562
  authManagedByApp: false
94407
94563
  };
@@ -94413,7 +94569,6 @@ function capabilitiesFor(source) {
94413
94569
  canSnapshot: true,
94414
94570
  canViewHistory: true,
94415
94571
  canRestoreSnapshot: true,
94416
- canPublish: true,
94417
94572
  canSync: true,
94418
94573
  authManagedByApp: true
94419
94574
  };
@@ -96412,20 +96567,20 @@ var require_ignore = __commonJS((exports, module) => {
96412
96567
  var throwError = (message, Ctor) => {
96413
96568
  throw new Ctor(message);
96414
96569
  };
96415
- var checkPath = (path9, originalPath, doThrow) => {
96416
- if (!isString2(path9)) {
96570
+ var checkPath = (path10, originalPath, doThrow) => {
96571
+ if (!isString2(path10)) {
96417
96572
  return doThrow(`path must be a string, but got \`${originalPath}\``, TypeError);
96418
96573
  }
96419
- if (!path9) {
96574
+ if (!path10) {
96420
96575
  return doThrow(`path must not be empty`, TypeError);
96421
96576
  }
96422
- if (checkPath.isNotRelative(path9)) {
96577
+ if (checkPath.isNotRelative(path10)) {
96423
96578
  const r = "`path.relative()`d";
96424
96579
  return doThrow(`path should be a ${r} string, but got "${originalPath}"`, RangeError);
96425
96580
  }
96426
96581
  return true;
96427
96582
  };
96428
- var isNotRelative = (path9) => REGEX_TEST_INVALID_PATH.test(path9);
96583
+ var isNotRelative = (path10) => REGEX_TEST_INVALID_PATH.test(path10);
96429
96584
  checkPath.isNotRelative = isNotRelative;
96430
96585
  checkPath.convert = (p10) => p10;
96431
96586
 
@@ -96468,7 +96623,7 @@ var require_ignore = __commonJS((exports, module) => {
96468
96623
  addPattern(pattern) {
96469
96624
  return this.add(pattern);
96470
96625
  }
96471
- _testOne(path9, checkUnignored) {
96626
+ _testOne(path10, checkUnignored) {
96472
96627
  let ignored = false;
96473
96628
  let unignored = false;
96474
96629
  this._rules.forEach((rule2) => {
@@ -96476,7 +96631,7 @@ var require_ignore = __commonJS((exports, module) => {
96476
96631
  if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
96477
96632
  return;
96478
96633
  }
96479
- const matched = rule2.regex.test(path9);
96634
+ const matched = rule2.regex.test(path10);
96480
96635
  if (matched) {
96481
96636
  ignored = !negative;
96482
96637
  unignored = negative;
@@ -96488,39 +96643,39 @@ var require_ignore = __commonJS((exports, module) => {
96488
96643
  };
96489
96644
  }
96490
96645
  _test(originalPath, cache2, checkUnignored, slices) {
96491
- const path9 = originalPath && checkPath.convert(originalPath);
96492
- checkPath(path9, originalPath, this._allowRelativePaths ? RETURN_FALSE : throwError);
96493
- return this._t(path9, cache2, checkUnignored, slices);
96646
+ const path10 = originalPath && checkPath.convert(originalPath);
96647
+ checkPath(path10, originalPath, this._allowRelativePaths ? RETURN_FALSE : throwError);
96648
+ return this._t(path10, cache2, checkUnignored, slices);
96494
96649
  }
96495
- _t(path9, cache2, checkUnignored, slices) {
96496
- if (path9 in cache2) {
96497
- return cache2[path9];
96650
+ _t(path10, cache2, checkUnignored, slices) {
96651
+ if (path10 in cache2) {
96652
+ return cache2[path10];
96498
96653
  }
96499
96654
  if (!slices) {
96500
- slices = path9.split(SLASH);
96655
+ slices = path10.split(SLASH);
96501
96656
  }
96502
96657
  slices.pop();
96503
96658
  if (!slices.length) {
96504
- return cache2[path9] = this._testOne(path9, checkUnignored);
96659
+ return cache2[path10] = this._testOne(path10, checkUnignored);
96505
96660
  }
96506
96661
  const parent = this._t(slices.join(SLASH) + SLASH, cache2, checkUnignored, slices);
96507
- return cache2[path9] = parent.ignored ? parent : this._testOne(path9, checkUnignored);
96662
+ return cache2[path10] = parent.ignored ? parent : this._testOne(path10, checkUnignored);
96508
96663
  }
96509
- ignores(path9) {
96510
- return this._test(path9, this._ignoreCache, false).ignored;
96664
+ ignores(path10) {
96665
+ return this._test(path10, this._ignoreCache, false).ignored;
96511
96666
  }
96512
96667
  createFilter() {
96513
- return (path9) => !this.ignores(path9);
96668
+ return (path10) => !this.ignores(path10);
96514
96669
  }
96515
96670
  filter(paths) {
96516
96671
  return makeArray(paths).filter(this.createFilter());
96517
96672
  }
96518
- test(path9) {
96519
- return this._test(path9, this._testCache, true);
96673
+ test(path10) {
96674
+ return this._test(path10, this._testCache, true);
96520
96675
  }
96521
96676
  }
96522
96677
  var factory = (options) => new Ignore(options);
96523
- var isPathValid = (path9) => checkPath(path9 && checkPath.convert(path9), path9, RETURN_FALSE);
96678
+ var isPathValid = (path10) => checkPath(path10 && checkPath.convert(path10), path10, RETURN_FALSE);
96524
96679
  factory.isPathValid = isPathValid;
96525
96680
  factory.default = factory;
96526
96681
  module.exports = factory;
@@ -96528,7 +96683,7 @@ var require_ignore = __commonJS((exports, module) => {
96528
96683
  const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
96529
96684
  checkPath.convert = makePosix;
96530
96685
  const REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
96531
- checkPath.isNotRelative = (path9) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path9) || isNotRelative(path9);
96686
+ checkPath.isNotRelative = (path10) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path10) || isNotRelative(path10);
96532
96687
  }
96533
96688
  });
96534
96689
 
@@ -96565,7 +96720,7 @@ var require_lib3 = __commonJS((exports, module) => {
96565
96720
  // ../../node_modules/.bun/diff3@0.0.3/node_modules/diff3/onp.js
96566
96721
  var require_onp = __commonJS((exports, module) => {
96567
96722
  module.exports = function(a_, b_) {
96568
- var a = a_, b = b_, m = a.length, n = b.length, reverse = false, ed2 = null, offset = m + 1, path9 = [], pathposi = [], ses = [], lcs = "", SES_DELETE = -1, SES_COMMON = 0, SES_ADD = 1;
96723
+ var a = a_, b = b_, m = a.length, n = b.length, reverse = false, ed2 = null, offset = m + 1, path10 = [], pathposi = [], ses = [], lcs = "", SES_DELETE = -1, SES_COMMON = 0, SES_ADD = 1;
96569
96724
  var tmp1, tmp2;
96570
96725
  var init = function() {
96571
96726
  if (m >= n) {
@@ -96595,9 +96750,9 @@ var require_onp = __commonJS((exports, module) => {
96595
96750
  var snake = function(k, p10, pp2) {
96596
96751
  var r, x, y;
96597
96752
  if (p10 > pp2) {
96598
- r = path9[k - 1 + offset];
96753
+ r = path10[k - 1 + offset];
96599
96754
  } else {
96600
- r = path9[k + 1 + offset];
96755
+ r = path10[k + 1 + offset];
96601
96756
  }
96602
96757
  y = Math.max(p10, pp2);
96603
96758
  x = y - k;
@@ -96605,7 +96760,7 @@ var require_onp = __commonJS((exports, module) => {
96605
96760
  ++x;
96606
96761
  ++y;
96607
96762
  }
96608
- path9[k + offset] = pathposi.length;
96763
+ path10[k + offset] = pathposi.length;
96609
96764
  pathposi[pathposi.length] = new P(x, y, r);
96610
96765
  return y;
96611
96766
  };
@@ -96663,7 +96818,7 @@ var require_onp = __commonJS((exports, module) => {
96663
96818
  fp2 = {};
96664
96819
  for (i = 0;i < size; ++i) {
96665
96820
  fp2[i] = -1;
96666
- path9[i] = -1;
96821
+ path10[i] = -1;
96667
96822
  }
96668
96823
  p10 = -1;
96669
96824
  do {
@@ -96677,7 +96832,7 @@ var require_onp = __commonJS((exports, module) => {
96677
96832
  fp2[delta + offset] = snake(delta, fp2[delta - 1 + offset] + 1, fp2[delta + 1 + offset]);
96678
96833
  } while (fp2[delta + offset] !== n);
96679
96834
  ed2 = delta + 2 * p10;
96680
- r = path9[delta + offset];
96835
+ r = path10[delta + offset];
96681
96836
  epc = [];
96682
96837
  while (r !== -1) {
96683
96838
  epc[epc.length] = new P(pathposi[r].x, pathposi[r].y, null);
@@ -97307,17 +97462,17 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
97307
97462
  const length = Math.ceil((62 + bpath.length + 1) / 8) * 8;
97308
97463
  const written = Buffer.alloc(length);
97309
97464
  const writer = new BufferCursor(written);
97310
- const stat5 = normalizeStats(entry);
97311
- writer.writeUInt32BE(stat5.ctimeSeconds);
97312
- writer.writeUInt32BE(stat5.ctimeNanoseconds);
97313
- writer.writeUInt32BE(stat5.mtimeSeconds);
97314
- writer.writeUInt32BE(stat5.mtimeNanoseconds);
97315
- writer.writeUInt32BE(stat5.dev);
97316
- writer.writeUInt32BE(stat5.ino);
97317
- writer.writeUInt32BE(stat5.mode);
97318
- writer.writeUInt32BE(stat5.uid);
97319
- writer.writeUInt32BE(stat5.gid);
97320
- writer.writeUInt32BE(stat5.size);
97465
+ const stat6 = normalizeStats(entry);
97466
+ writer.writeUInt32BE(stat6.ctimeSeconds);
97467
+ writer.writeUInt32BE(stat6.ctimeNanoseconds);
97468
+ writer.writeUInt32BE(stat6.mtimeSeconds);
97469
+ writer.writeUInt32BE(stat6.mtimeNanoseconds);
97470
+ writer.writeUInt32BE(stat6.dev);
97471
+ writer.writeUInt32BE(stat6.ino);
97472
+ writer.writeUInt32BE(stat6.mode);
97473
+ writer.writeUInt32BE(stat6.uid);
97474
+ writer.writeUInt32BE(stat6.gid);
97475
+ writer.writeUInt32BE(stat6.size);
97321
97476
  writer.write(entry.oid, 20, "hex");
97322
97477
  writer.writeUInt16BE(renderCacheEntryFlags(entry));
97323
97478
  writer.write(entry.path, bpath.length, "utf8");
@@ -97362,13 +97517,13 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
97362
97517
  };
97363
97518
  }
97364
97519
  async function updateCachedIndexFile(fs5, filepath, cache2) {
97365
- const [stat5, rawIndexFile] = await Promise.all([
97520
+ const [stat6, rawIndexFile] = await Promise.all([
97366
97521
  fs5.lstat(filepath),
97367
97522
  fs5.read(filepath)
97368
97523
  ]);
97369
97524
  const index2 = await GitIndex.from(rawIndexFile);
97370
97525
  cache2.map.set(filepath, index2);
97371
- cache2.stats.set(filepath, stat5);
97526
+ cache2.stats.set(filepath, stat6);
97372
97527
  }
97373
97528
  async function isIndexStale(fs5, filepath, cache2) {
97374
97529
  const savedStats = cache2.stats.get(filepath);
@@ -97412,20 +97567,20 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
97412
97567
  return result;
97413
97568
  }
97414
97569
  }
97415
- function basename3(path9) {
97416
- const last = Math.max(path9.lastIndexOf("/"), path9.lastIndexOf("\\"));
97570
+ function basename3(path10) {
97571
+ const last = Math.max(path10.lastIndexOf("/"), path10.lastIndexOf("\\"));
97417
97572
  if (last > -1) {
97418
- path9 = path9.slice(last + 1);
97573
+ path10 = path10.slice(last + 1);
97419
97574
  }
97420
- return path9;
97575
+ return path10;
97421
97576
  }
97422
- function dirname6(path9) {
97423
- const last = Math.max(path9.lastIndexOf("/"), path9.lastIndexOf("\\"));
97577
+ function dirname6(path10) {
97578
+ const last = Math.max(path10.lastIndexOf("/"), path10.lastIndexOf("\\"));
97424
97579
  if (last === -1)
97425
97580
  return ".";
97426
97581
  if (last === 0)
97427
97582
  return "/";
97428
- return path9.slice(0, last);
97583
+ return path10.slice(0, last);
97429
97584
  }
97430
97585
  function flatFileListToDirectoryStructure(files) {
97431
97586
  const inodes = new Map;
@@ -97763,15 +97918,15 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
97763
97918
  * SPDX-License-Identifier: LGPL-3.0-or-later
97764
97919
  * Copyright (c) James Prevett and other ZenFS contributors.
97765
97920
  */
97766
- function normalizeString(path9, aar) {
97921
+ function normalizeString(path10, aar) {
97767
97922
  let res = "";
97768
97923
  let lastSegmentLength = 0;
97769
97924
  let lastSlash = -1;
97770
97925
  let dots = 0;
97771
97926
  let char = "\x00";
97772
- for (let i = 0;i <= path9.length; ++i) {
97773
- if (i < path9.length)
97774
- char = path9[i];
97927
+ for (let i = 0;i <= path10.length; ++i) {
97928
+ if (i < path10.length)
97929
+ char = path10[i];
97775
97930
  else if (char === "/")
97776
97931
  break;
97777
97932
  else
@@ -97805,9 +97960,9 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
97805
97960
  }
97806
97961
  } else {
97807
97962
  if (res.length > 0)
97808
- res += "/" + path9.slice(lastSlash + 1, i);
97963
+ res += "/" + path10.slice(lastSlash + 1, i);
97809
97964
  else
97810
- res = path9.slice(lastSlash + 1, i);
97965
+ res = path10.slice(lastSlash + 1, i);
97811
97966
  lastSegmentLength = i - lastSlash - 1;
97812
97967
  }
97813
97968
  lastSlash = i;
@@ -97820,20 +97975,20 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
97820
97975
  }
97821
97976
  return res;
97822
97977
  }
97823
- function normalize2(path9) {
97824
- if (!path9.length)
97978
+ function normalize2(path10) {
97979
+ if (!path10.length)
97825
97980
  return ".";
97826
- const isAbsolute2 = path9[0] === "/";
97827
- const trailingSeparator = path9.at(-1) === "/";
97828
- path9 = normalizeString(path9, !isAbsolute2);
97829
- if (!path9.length) {
97981
+ const isAbsolute2 = path10[0] === "/";
97982
+ const trailingSeparator = path10.at(-1) === "/";
97983
+ path10 = normalizeString(path10, !isAbsolute2);
97984
+ if (!path10.length) {
97830
97985
  if (isAbsolute2)
97831
97986
  return "/";
97832
97987
  return trailingSeparator ? "./" : ".";
97833
97988
  }
97834
97989
  if (trailingSeparator)
97835
- path9 += "/";
97836
- return isAbsolute2 ? `/${path9}` : path9;
97990
+ path10 += "/";
97991
+ return isAbsolute2 ? `/${path10}` : path10;
97837
97992
  }
97838
97993
  function join9(...args) {
97839
97994
  if (args.length === 0)
@@ -97941,8 +98096,8 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
97941
98096
  var getPath = (section, subsection, name) => {
97942
98097
  return [lower(section), subsection, lower(name)].filter((a) => a != null).join(".");
97943
98098
  };
97944
- var normalizePath = (path9) => {
97945
- const pathSegments = path9.split(".");
98099
+ var normalizePath = (path10) => {
98100
+ const pathSegments = path10.split(".");
97946
98101
  const section = pathSegments.shift();
97947
98102
  const name = pathSegments.pop();
97948
98103
  const subsection = pathSegments.length ? pathSegments.join(".") : undefined;
@@ -97981,23 +98136,23 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
97981
98136
  [name, value] = extractedVariable;
97982
98137
  }
97983
98138
  }
97984
- const path9 = getPath(section, subsection, name);
97985
- return { line, isSection, section, subsection, name, value, path: path9 };
98139
+ const path10 = getPath(section, subsection, name);
98140
+ return { line, isSection, section, subsection, name, value, path: path10 };
97986
98141
  }) : [];
97987
98142
  }
97988
98143
  static from(text4) {
97989
98144
  return new GitConfig(text4);
97990
98145
  }
97991
- async get(path9, getall = false) {
97992
- const normalizedPath = normalizePath(path9).path;
98146
+ async get(path10, getall = false) {
98147
+ const normalizedPath = normalizePath(path10).path;
97993
98148
  const allValues = this.parsedConfig.filter((config) => config.path === normalizedPath).map(({ section, name, value }) => {
97994
98149
  const fn2 = schema[section] && schema[section][name];
97995
98150
  return fn2 ? fn2(value) : value;
97996
98151
  });
97997
98152
  return getall ? allValues : allValues.pop();
97998
98153
  }
97999
- async getall(path9) {
98000
- return this.get(path9, true);
98154
+ async getall(path10) {
98155
+ return this.get(path10, true);
98001
98156
  }
98002
98157
  async getSubsections(section) {
98003
98158
  return this.parsedConfig.filter((config) => config.isSection && config.section === section).map((config) => config.subsection);
@@ -98005,10 +98160,10 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
98005
98160
  async deleteSection(section, subsection) {
98006
98161
  this.parsedConfig = this.parsedConfig.filter((config) => !(config.section === section && config.subsection === subsection));
98007
98162
  }
98008
- async append(path9, value) {
98009
- return this.set(path9, value, true);
98163
+ async append(path10, value) {
98164
+ return this.set(path10, value, true);
98010
98165
  }
98011
- async set(path9, value, append = false) {
98166
+ async set(path10, value, append = false) {
98012
98167
  const {
98013
98168
  section,
98014
98169
  subsection,
@@ -98016,7 +98171,7 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
98016
98171
  path: normalizedPath,
98017
98172
  sectionPath,
98018
98173
  isSection
98019
- } = normalizePath(path9);
98174
+ } = normalizePath(path10);
98020
98175
  const configIndex = findLastIndex(this.parsedConfig, (config) => config.path === normalizedPath);
98021
98176
  if (value == null) {
98022
98177
  if (configIndex !== -1) {
@@ -98389,13 +98544,13 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
98389
98544
  if (mode === "40000")
98390
98545
  mode = "040000";
98391
98546
  const type = mode2type$1(mode);
98392
- const path9 = buffer.slice(space + 1, nullchar).toString("utf8");
98393
- if (path9.includes("\\") || path9.includes("/")) {
98394
- throw new UnsafeFilepathError(path9);
98547
+ const path10 = buffer.slice(space + 1, nullchar).toString("utf8");
98548
+ if (path10.includes("\\") || path10.includes("/")) {
98549
+ throw new UnsafeFilepathError(path10);
98395
98550
  }
98396
98551
  const oid = buffer.slice(nullchar + 1, nullchar + 21).toString("hex");
98397
98552
  cursor = nullchar + 21;
98398
- _entries.push({ mode, path: path9, oid, type });
98553
+ _entries.push({ mode, path: path10, oid, type });
98399
98554
  }
98400
98555
  return _entries;
98401
98556
  }
@@ -98450,10 +98605,10 @@ If you're a developer and you believe this is a bug in isomorphic-git, please fi
98450
98605
  return Buffer.concat(entries.map((entry) => {
98451
98606
  const mode = Buffer.from(entry.mode.replace(/^0/, ""));
98452
98607
  const space = Buffer.from(" ");
98453
- const path9 = Buffer.from(entry.path, "utf8");
98608
+ const path10 = Buffer.from(entry.path, "utf8");
98454
98609
  const nullchar = Buffer.from([0]);
98455
98610
  const oid = Buffer.from(entry.oid, "hex");
98456
- return Buffer.concat([mode, space, path9, nullchar, oid]);
98611
+ return Buffer.concat([mode, space, path10, nullchar, oid]);
98457
98612
  }));
98458
98613
  }
98459
98614
  entries() {
@@ -100035,21 +100190,21 @@ gpgsig`));
100035
100190
  async stat(entry) {
100036
100191
  if (entry._stat === false) {
100037
100192
  const { fs: fs5, dir } = this;
100038
- let stat5 = await fs5.lstat(`${dir}/${entry._fullpath}`);
100039
- if (!stat5) {
100193
+ let stat6 = await fs5.lstat(`${dir}/${entry._fullpath}`);
100194
+ if (!stat6) {
100040
100195
  throw new Error(`ENOENT: no such file or directory, lstat '${entry._fullpath}'`);
100041
100196
  }
100042
- let type = stat5.isDirectory() ? "tree" : "blob";
100043
- if (type === "blob" && !stat5.isFile() && !stat5.isSymbolicLink()) {
100197
+ let type = stat6.isDirectory() ? "tree" : "blob";
100198
+ if (type === "blob" && !stat6.isFile() && !stat6.isSymbolicLink()) {
100044
100199
  type = "special";
100045
100200
  }
100046
100201
  entry._type = type;
100047
- stat5 = normalizeStats(stat5);
100048
- entry._mode = stat5.mode;
100049
- if (stat5.size === -1 && entry._actualSize) {
100050
- stat5.size = entry._actualSize;
100202
+ stat6 = normalizeStats(stat6);
100203
+ entry._mode = stat6.mode;
100204
+ if (stat6.size === -1 && entry._actualSize) {
100205
+ stat6.size = entry._actualSize;
100051
100206
  }
100052
- entry._stat = stat5;
100207
+ entry._stat = stat6;
100053
100208
  }
100054
100209
  return entry._stat;
100055
100210
  }
@@ -100237,10 +100392,10 @@ gpgsig`));
100237
100392
  } else if (entries.length) {
100238
100393
  await Promise.all(entries.map((entry) => {
100239
100394
  const subpath = join9(filepath, entry);
100240
- return fs5.lstat(subpath).then((stat5) => {
100241
- if (!stat5)
100395
+ return fs5.lstat(subpath).then((stat6) => {
100396
+ if (!stat6)
100242
100397
  return;
100243
- return stat5.isDirectory() ? rmRecursive(fs5, subpath) : fs5.rm(subpath);
100398
+ return stat6.isDirectory() ? rmRecursive(fs5, subpath) : fs5.rm(subpath);
100244
100399
  });
100245
100400
  })).then(() => fs5.rmdir(filepath));
100246
100401
  } else {
@@ -100510,13 +100665,13 @@ gpgsig`));
100510
100665
  dir,
100511
100666
  gitdir: updatedGitdir,
100512
100667
  trees,
100513
- map: async function(path9, [head, workdir, index2]) {
100668
+ map: async function(path10, [head, workdir, index2]) {
100514
100669
  const staged = !await modified(workdir, index2);
100515
- const unmerged = unmergedPaths.includes(path9);
100670
+ const unmerged = unmergedPaths.includes(path10);
100516
100671
  const unmodified = !await modified(index2, head);
100517
100672
  if (staged || unmerged) {
100518
100673
  return head ? {
100519
- path: path9,
100674
+ path: path10,
100520
100675
  mode: await head.mode(),
100521
100676
  oid: await head.oid(),
100522
100677
  type: await head.type(),
@@ -100526,7 +100681,7 @@ gpgsig`));
100526
100681
  if (unmodified)
100527
100682
  return false;
100528
100683
  else
100529
- throw new IndexResetError(path9);
100684
+ throw new IndexResetError(path10);
100530
100685
  }
100531
100686
  });
100532
100687
  await GitIndexManager.acquire({ fs: fs5, gitdir: updatedGitdir, cache: cache2 }, async function(index2) {
@@ -100772,9 +100927,9 @@ gpgsig`));
100772
100927
  const fulfilledPromises = settledPromises.filter((settle) => settle.status === "fulfilled" && settle.value).map((settle) => settle.value);
100773
100928
  return fulfilledPromises;
100774
100929
  }
100775
- async function _getConfig({ fs: fs5, gitdir, path: path9 }) {
100930
+ async function _getConfig({ fs: fs5, gitdir, path: path10 }) {
100776
100931
  const config = await GitConfigManager.get({ fs: fs5, gitdir });
100777
- return config.get(path9);
100932
+ return config.get(path10);
100778
100933
  }
100779
100934
  function assignDefined(target, ...sources) {
100780
100935
  for (const source of sources) {
@@ -102064,14 +102219,14 @@ gpgsig`));
102064
102219
  gitdir,
102065
102220
  trees: [ourTree, baseTree, theirTree],
102066
102221
  map: async function(filepath, [ours, base, theirs]) {
102067
- const path9 = basename3(filepath);
102222
+ const path10 = basename3(filepath);
102068
102223
  const ourChange = await modified(ours, base);
102069
102224
  const theirChange = await modified(theirs, base);
102070
102225
  switch (`${ourChange}-${theirChange}`) {
102071
102226
  case "false-false": {
102072
102227
  return {
102073
102228
  mode: await base.mode(),
102074
- path: path9,
102229
+ path: path10,
102075
102230
  oid: await base.oid(),
102076
102231
  type: await base.type()
102077
102232
  };
@@ -102080,14 +102235,14 @@ gpgsig`));
102080
102235
  if (!theirs && await ours.type() === "tree") {
102081
102236
  return {
102082
102237
  mode: await ours.mode(),
102083
- path: path9,
102238
+ path: path10,
102084
102239
  oid: await ours.oid(),
102085
102240
  type: await ours.type()
102086
102241
  };
102087
102242
  }
102088
102243
  return theirs ? {
102089
102244
  mode: await theirs.mode(),
102090
- path: path9,
102245
+ path: path10,
102091
102246
  oid: await theirs.oid(),
102092
102247
  type: await theirs.type()
102093
102248
  } : undefined;
@@ -102096,14 +102251,14 @@ gpgsig`));
102096
102251
  if (!ours && await theirs.type() === "tree") {
102097
102252
  return {
102098
102253
  mode: await theirs.mode(),
102099
- path: path9,
102254
+ path: path10,
102100
102255
  oid: await theirs.oid(),
102101
102256
  type: await theirs.type()
102102
102257
  };
102103
102258
  }
102104
102259
  return ours ? {
102105
102260
  mode: await ours.mode(),
102106
- path: path9,
102261
+ path: path10,
102107
102262
  oid: await ours.oid(),
102108
102263
  type: await ours.type()
102109
102264
  } : undefined;
@@ -102112,7 +102267,7 @@ gpgsig`));
102112
102267
  if (ours && theirs && await ours.type() === "tree" && await theirs.type() === "tree") {
102113
102268
  return {
102114
102269
  mode: await ours.mode(),
102115
- path: path9,
102270
+ path: path10,
102116
102271
  oid: await ours.oid(),
102117
102272
  type: "tree"
102118
102273
  };
@@ -102121,7 +102276,7 @@ gpgsig`));
102121
102276
  return mergeBlobs({
102122
102277
  fs: fs5,
102123
102278
  gitdir,
102124
- path: path9,
102279
+ path: path10,
102125
102280
  ours,
102126
102281
  base,
102127
102282
  theirs,
@@ -102167,7 +102322,7 @@ gpgsig`));
102167
102322
  mode: await theirs.mode(),
102168
102323
  oid: await theirs.oid(),
102169
102324
  type: "blob",
102170
- path: path9
102325
+ path: path10
102171
102326
  };
102172
102327
  }
102173
102328
  if (base && ours && !theirs && await base.type() === "blob" && await ours.type() === "blob") {
@@ -102184,7 +102339,7 @@ gpgsig`));
102184
102339
  mode: await ours.mode(),
102185
102340
  oid: await ours.oid(),
102186
102341
  type: "blob",
102187
- path: path9
102342
+ path: path10
102188
102343
  };
102189
102344
  }
102190
102345
  if (base && !ours && !theirs && (await base.type() === "blob" || await base.type() === "tree")) {
@@ -102224,11 +102379,11 @@ gpgsig`));
102224
102379
  gitdir,
102225
102380
  trees: [TREE({ ref: results.oid })],
102226
102381
  map: async function(filepath, [entry]) {
102227
- const path9 = `${dir}/${filepath}`;
102382
+ const path10 = `${dir}/${filepath}`;
102228
102383
  if (await entry.type() === "blob") {
102229
102384
  const mode = await entry.mode();
102230
102385
  const content4 = new TextDecoder().decode(await entry.content());
102231
- await fs5.write(path9, content4, { mode });
102386
+ await fs5.write(path10, content4, { mode });
102232
102387
  }
102233
102388
  return true;
102234
102389
  }
@@ -102241,7 +102396,7 @@ gpgsig`));
102241
102396
  async function mergeBlobs({
102242
102397
  fs: fs5,
102243
102398
  gitdir,
102244
- path: path9,
102399
+ path: path10,
102245
102400
  ours,
102246
102401
  base,
102247
102402
  theirs,
@@ -102264,19 +102419,19 @@ gpgsig`));
102264
102419
  if (await ours.oid() === await theirs.oid()) {
102265
102420
  return {
102266
102421
  cleanMerge: true,
102267
- mergeResult: { mode, path: path9, oid: await ours.oid(), type }
102422
+ mergeResult: { mode, path: path10, oid: await ours.oid(), type }
102268
102423
  };
102269
102424
  }
102270
102425
  if (await ours.oid() === baseOid) {
102271
102426
  return {
102272
102427
  cleanMerge: true,
102273
- mergeResult: { mode, path: path9, oid: await theirs.oid(), type }
102428
+ mergeResult: { mode, path: path10, oid: await theirs.oid(), type }
102274
102429
  };
102275
102430
  }
102276
102431
  if (await theirs.oid() === baseOid) {
102277
102432
  return {
102278
102433
  cleanMerge: true,
102279
- mergeResult: { mode, path: path9, oid: await ours.oid(), type }
102434
+ mergeResult: { mode, path: path10, oid: await ours.oid(), type }
102280
102435
  };
102281
102436
  }
102282
102437
  const ourContent = Buffer.from(await ours.content()).toString("utf8");
@@ -102284,7 +102439,7 @@ gpgsig`));
102284
102439
  const { mergedText, cleanMerge } = await mergeDriver({
102285
102440
  branches: [baseName, ourName, theirName],
102286
102441
  contents: [baseContent, ourContent, theirContent],
102287
- path: path9
102442
+ path: path10
102288
102443
  });
102289
102444
  const oid = await _writeObject({
102290
102445
  fs: fs5,
@@ -102293,7 +102448,7 @@ gpgsig`));
102293
102448
  object: Buffer.from(mergedText, "utf8"),
102294
102449
  dryRun
102295
102450
  });
102296
- return { cleanMerge, mergeResult: { mode, path: path9, oid, type } };
102451
+ return { cleanMerge, mergeResult: { mode, path: path10, oid, type } };
102297
102452
  }
102298
102453
  var _TreeMap = {
102299
102454
  stage: STAGE,
@@ -102997,7 +103152,7 @@ gpgsig`));
102997
103152
  const remoteHelpers = new Map;
102998
103153
  remoteHelpers.set("http", GitRemoteHTTP);
102999
103154
  remoteHelpers.set("https", GitRemoteHTTP);
103000
- const parts = parseRemoteUrl({ url });
103155
+ const parts = parseRemoteUrl2({ url });
103001
103156
  if (!parts) {
103002
103157
  throw new UrlParseError(url);
103003
103158
  }
@@ -103007,7 +103162,7 @@ gpgsig`));
103007
103162
  throw new UnknownTransportError(url, parts.transport, parts.transport === "ssh" ? translateSSHtoHTTP(url) : undefined);
103008
103163
  }
103009
103164
  }
103010
- function parseRemoteUrl({ url }) {
103165
+ function parseRemoteUrl2({ url }) {
103011
103166
  if (url.startsWith("git@")) {
103012
103167
  return {
103013
103168
  transport: "ssh",
@@ -104464,43 +104619,43 @@ gpgsig`));
104464
104619
  throw err;
104465
104620
  }
104466
104621
  }
104467
- async function getConfig({ fs: fs5, dir, gitdir = join9(dir, ".git"), path: path9 }) {
104622
+ async function getConfig({ fs: fs5, dir, gitdir = join9(dir, ".git"), path: path10 }) {
104468
104623
  try {
104469
104624
  assertParameter("fs", fs5);
104470
104625
  assertParameter("gitdir", gitdir);
104471
- assertParameter("path", path9);
104626
+ assertParameter("path", path10);
104472
104627
  const fsp3 = new FileSystem(fs5);
104473
104628
  const updatedGitdir = await discoverGitdir({ fsp: fsp3, dotgit: gitdir });
104474
104629
  return await _getConfig({
104475
104630
  fs: fsp3,
104476
104631
  gitdir: updatedGitdir,
104477
- path: path9
104632
+ path: path10
104478
104633
  });
104479
104634
  } catch (err) {
104480
104635
  err.caller = "git.getConfig";
104481
104636
  throw err;
104482
104637
  }
104483
104638
  }
104484
- async function _getConfigAll({ fs: fs5, gitdir, path: path9 }) {
104639
+ async function _getConfigAll({ fs: fs5, gitdir, path: path10 }) {
104485
104640
  const config = await GitConfigManager.get({ fs: fs5, gitdir });
104486
- return config.getall(path9);
104641
+ return config.getall(path10);
104487
104642
  }
104488
104643
  async function getConfigAll({
104489
104644
  fs: fs5,
104490
104645
  dir,
104491
104646
  gitdir = join9(dir, ".git"),
104492
- path: path9
104647
+ path: path10
104493
104648
  }) {
104494
104649
  try {
104495
104650
  assertParameter("fs", fs5);
104496
104651
  assertParameter("gitdir", gitdir);
104497
- assertParameter("path", path9);
104652
+ assertParameter("path", path10);
104498
104653
  const fsp3 = new FileSystem(fs5);
104499
104654
  const updatedGitdir = await discoverGitdir({ fsp: fsp3, dotgit: gitdir });
104500
104655
  return await _getConfigAll({
104501
104656
  fs: fsp3,
104502
104657
  gitdir: updatedGitdir,
104503
- path: path9
104658
+ path: path10
104504
104659
  });
104505
104660
  } catch (err) {
104506
104661
  err.caller = "git.getConfigAll";
@@ -106529,21 +106684,21 @@ gpgsig`));
106529
106684
  fs: _fs,
106530
106685
  dir,
106531
106686
  gitdir = join9(dir, ".git"),
106532
- path: path9,
106687
+ path: path10,
106533
106688
  value,
106534
106689
  append = false
106535
106690
  }) {
106536
106691
  try {
106537
106692
  assertParameter("fs", _fs);
106538
106693
  assertParameter("gitdir", gitdir);
106539
- assertParameter("path", path9);
106694
+ assertParameter("path", path10);
106540
106695
  const fs5 = new FileSystem(_fs);
106541
106696
  const updatedGitdir = await discoverGitdir({ fsp: fs5, dotgit: gitdir });
106542
106697
  const config = await GitConfigManager.get({ fs: fs5, gitdir: updatedGitdir });
106543
106698
  if (append) {
106544
- await config.append(path9, value);
106699
+ await config.append(path10, value);
106545
106700
  } else {
106546
- await config.set(path9, value);
106701
+ await config.set(path10, value);
106547
106702
  }
106548
106703
  await GitConfigManager.save({ fs: fs5, gitdir: updatedGitdir, config });
106549
106704
  } catch (err) {
@@ -106837,9 +106992,9 @@ gpgsig`));
106837
106992
  const stashMgr = new GitStashManager({ fs: fs5, dir, gitdir });
106838
106993
  const stashRefPath = [stashMgr.refStashPath, stashMgr.refLogsStashPath];
106839
106994
  await acquireLock$1(stashRefPath, async () => {
106840
- await Promise.all(stashRefPath.map(async (path9) => {
106841
- if (await fs5.exists(path9)) {
106842
- return fs5.rm(path9);
106995
+ await Promise.all(stashRefPath.map(async (path10) => {
106996
+ if (await fs5.exists(path10)) {
106997
+ return fs5.rm(path10);
106843
106998
  }
106844
106999
  }));
106845
107000
  });
@@ -106992,13 +107147,13 @@ gpgsig`));
106992
107147
  throw err;
106993
107148
  }
106994
107149
  }
106995
- async function getOidAtPath({ fs: fs5, cache: cache2, gitdir: updatedGitdir, tree, path: path9 }) {
106996
- if (typeof path9 === "string")
106997
- path9 = path9.split("/");
106998
- const dirname7 = path9.shift();
107150
+ async function getOidAtPath({ fs: fs5, cache: cache2, gitdir: updatedGitdir, tree, path: path10 }) {
107151
+ if (typeof path10 === "string")
107152
+ path10 = path10.split("/");
107153
+ const dirname7 = path10.shift();
106999
107154
  for (const entry of tree) {
107000
107155
  if (entry.path === dirname7) {
107001
- if (path9.length === 0) {
107156
+ if (path10.length === 0) {
107002
107157
  return entry.oid;
107003
107158
  }
107004
107159
  const { type, object } = await _readObject({
@@ -107009,10 +107164,10 @@ gpgsig`));
107009
107164
  });
107010
107165
  if (type === "tree") {
107011
107166
  const tree2 = GitTree.from(object);
107012
- return getOidAtPath({ fs: fs5, cache: cache2, gitdir: updatedGitdir, tree: tree2, path: path9 });
107167
+ return getOidAtPath({ fs: fs5, cache: cache2, gitdir: updatedGitdir, tree: tree2, path: path10 });
107013
107168
  }
107014
107169
  if (type === "blob") {
107015
- throw new ObjectTypeError(entry.oid, type, "blob", path9.join("/"));
107170
+ throw new ObjectTypeError(entry.oid, type, "blob", path10.join("/"));
107016
107171
  }
107017
107172
  }
107018
107173
  }
@@ -107597,18 +107752,59 @@ gpgsig`));
107597
107752
  // ../lib/src/lib/source-provider.ts
107598
107753
  var exports_source_provider = {};
107599
107754
  __export(exports_source_provider, {
107755
+ withRepoLock: () => withRepoLock,
107756
+ snapshotWorkingTreeUnlocked: () => snapshotWorkingTreeUnlocked,
107757
+ restoreVersionWithBackup: () => restoreVersionWithBackup,
107600
107758
  providerFor: () => providerFor,
107601
- gitDirFor: () => gitDirFor
107759
+ isNoChangesError: () => isNoChangesError,
107760
+ isGitInternalPath: () => isGitInternalPath,
107761
+ hasPendingChanges: () => hasPendingChanges,
107762
+ gitScopeFor: () => gitScopeFor,
107763
+ gitDirFor: () => gitDirFor,
107764
+ gitAuthor: () => gitAuthor,
107765
+ autoSnapshotDelayMs: () => autoSnapshotDelayMs,
107766
+ RESTORE_BACKUP_MESSAGE: () => RESTORE_BACKUP_MESSAGE,
107767
+ HISTORY_PAGE_LIMIT: () => HISTORY_PAGE_LIMIT,
107768
+ AUTO_SNAPSHOT_MIN_MINUTES: () => AUTO_SNAPSHOT_MIN_MINUTES,
107769
+ AUTO_SNAPSHOT_MESSAGE: () => AUTO_SNAPSHOT_MESSAGE,
107770
+ AUTO_SNAPSHOT_MAX_MINUTES: () => AUTO_SNAPSHOT_MAX_MINUTES,
107771
+ AUTO_SNAPSHOT_DEFAULT_MINUTES: () => AUTO_SNAPSHOT_DEFAULT_MINUTES
107602
107772
  });
107603
107773
  import * as fs5 from "node:fs";
107604
- import path9 from "node:path";
107774
+ import path10 from "node:path";
107775
+ function gitScopeFor(source) {
107776
+ return { dir: source.repoRoot || source.path, subPath: source.subPath || "" };
107777
+ }
107778
+ function withRepoLock(projectDir, fn2) {
107779
+ const key = path10.resolve(projectDir);
107780
+ const prev = repoQueues.get(key) ?? Promise.resolve();
107781
+ const run2 = prev.then(fn2, fn2);
107782
+ repoQueues.set(key, run2.catch(() => {
107783
+ return;
107784
+ }));
107785
+ return run2;
107786
+ }
107605
107787
  function gitAuthor(name) {
107606
107788
  const n = (name ?? "").trim();
107607
107789
  return { name: n || DEFAULT_AUTHOR, email: DEFAULT_EMAIL };
107608
107790
  }
107609
- async function stageAll(dir) {
107610
- const status = await import_isomorphic_git.default.statusMatrix({ fs: fs5, dir });
107611
- await Promise.all(status.map(([filepath, , worktreeStatus]) => worktreeStatus === 0 ? import_isomorphic_git.default.remove({ fs: fs5, dir, filepath }) : import_isomorphic_git.default.add({ fs: fs5, dir, filepath })));
107791
+ async function stageAll(dir, subPath, cache2) {
107792
+ const status = await import_isomorphic_git.default.statusMatrix({
107793
+ fs: fs5,
107794
+ dir,
107795
+ cache: cache2,
107796
+ ...subPath ? { filepaths: [subPath] } : {}
107797
+ });
107798
+ await Promise.all(status.map(([filepath, , worktreeStatus]) => worktreeStatus === 0 ? import_isomorphic_git.default.remove({ fs: fs5, dir, filepath, cache: cache2 }) : import_isomorphic_git.default.add({ fs: fs5, dir, filepath, cache: cache2 })));
107799
+ }
107800
+ async function hasPendingChanges(dir, subPath, cache2 = {}) {
107801
+ const status = await import_isomorphic_git.default.statusMatrix({
107802
+ fs: fs5,
107803
+ dir,
107804
+ cache: cache2,
107805
+ ...subPath ? { filepaths: [subPath] } : {}
107806
+ });
107807
+ return status.some(([, head, worktree, stage]) => !(head === 1 && worktree === 1 && stage === 1));
107612
107808
  }
107613
107809
 
107614
107810
  class LocalFolderSourceProvider {
@@ -107620,20 +107816,29 @@ class LocalFolderSourceProvider {
107620
107816
  }
107621
107817
  async initVersionHistory(options) {
107622
107818
  const dir = options.projectDir;
107623
- await import_isomorphic_git.default.init({ fs: fs5, dir, defaultBranch: DEFAULT_BRANCH });
107624
- await stageAll(dir);
107625
- await import_isomorphic_git.default.commit({
107626
- fs: fs5,
107627
- dir,
107628
- message: options.initialMessage?.trim() || "Created project",
107629
- author: gitAuthor(options.authorName)
107819
+ if (await findEnclosingRepoDir(dir) !== undefined) {
107820
+ throw new Error("This folder is already inside a versioned project, so print-md " + "won't create a separate history here.");
107821
+ }
107822
+ return withRepoLock(dir, async () => {
107823
+ const cache2 = {};
107824
+ await import_isomorphic_git.default.init({ fs: fs5, dir, defaultBranch: DEFAULT_BRANCH });
107825
+ await stageAll(dir, undefined, cache2);
107826
+ await import_isomorphic_git.default.commit({
107827
+ fs: fs5,
107828
+ dir,
107829
+ cache: cache2,
107830
+ message: options.initialMessage?.trim() || "Created project",
107831
+ author: gitAuthor(options.authorName)
107832
+ });
107833
+ return {
107834
+ type: "local-git-folder",
107835
+ path: dir,
107836
+ repoRoot: dir,
107837
+ subPath: "",
107838
+ hasRemote: false,
107839
+ branch: DEFAULT_BRANCH
107840
+ };
107630
107841
  });
107631
- return {
107632
- type: "local-git-folder",
107633
- path: dir,
107634
- hasRemote: false,
107635
- branch: DEFAULT_BRANCH
107636
- };
107637
107842
  }
107638
107843
  snapshot() {
107639
107844
  return Promise.reject(new Error("This project has no version history yet. Enable version history first."));
@@ -107641,6 +107846,9 @@ class LocalFolderSourceProvider {
107641
107846
  listHistory() {
107642
107847
  return Promise.resolve([]);
107643
107848
  }
107849
+ listHistoryPage() {
107850
+ return Promise.resolve({ entries: [], hasMore: false });
107851
+ }
107644
107852
  restore() {
107645
107853
  return Promise.reject(new Error("This project has no version history yet. Enable version history first."));
107646
107854
  }
@@ -107649,56 +107857,115 @@ class LocalFolderSourceProvider {
107649
107857
  class LocalGitSourceProvider {
107650
107858
  source;
107651
107859
  capabilities;
107860
+ scope;
107652
107861
  constructor(source) {
107653
107862
  this.source = source;
107654
107863
  this.capabilities = capabilitiesFor(source);
107864
+ this.scope = gitScopeFor(source);
107655
107865
  }
107656
107866
  async initVersionHistory(options) {
107657
- await this.snapshot({
107658
- projectDir: options.projectDir,
107659
- message: options.initialMessage?.trim() || "Created project",
107660
- authorName: options.authorName
107661
- }).catch(() => {
107662
- return;
107663
- });
107867
+ try {
107868
+ await this.snapshot({
107869
+ projectDir: options.projectDir,
107870
+ message: options.initialMessage?.trim() || "Created project",
107871
+ authorName: options.authorName
107872
+ });
107873
+ } catch (e) {
107874
+ if (!isNoChangesError(e))
107875
+ throw e;
107876
+ }
107664
107877
  return this.source;
107665
107878
  }
107666
- async snapshot(options) {
107667
- const dir = options.projectDir;
107668
- await stageAll(dir);
107669
- const author = gitAuthor(options.authorName);
107670
- const id2 = await import_isomorphic_git.default.commit({
107671
- fs: fs5,
107672
- dir,
107673
- message: options.message,
107674
- author
107879
+ snapshot(options) {
107880
+ return withRepoLock(this.scope.dir, () => this.snapshotUnlocked(options));
107881
+ }
107882
+ snapshotUnlocked(options) {
107883
+ return snapshotWorkingTreeUnlocked({
107884
+ ...options,
107885
+ repoRoot: this.scope.dir,
107886
+ ...this.scope.subPath ? { subPath: this.scope.subPath } : {}
107675
107887
  });
107888
+ }
107889
+ async listHistory(projectDir) {
107890
+ return (await this.listHistoryPage(projectDir)).entries;
107891
+ }
107892
+ async listHistoryPage(_projectDir, options = {}) {
107893
+ const { dir, subPath } = this.scope;
107894
+ const limit = Math.min(500, Math.max(1, options.limit ?? HISTORY_PAGE_LIMIT));
107895
+ const before = options.before;
107896
+ let commits;
107897
+ try {
107898
+ commits = await import_isomorphic_git.default.log({
107899
+ fs: fs5,
107900
+ dir,
107901
+ cache: {},
107902
+ depth: limit + 2,
107903
+ ...before ? { ref: before } : {},
107904
+ ...subPath ? { filepath: subPath, force: true } : {}
107905
+ });
107906
+ } catch (e) {
107907
+ if (before && e?.code === "NotFoundError") {
107908
+ return { entries: [], hasMore: false };
107909
+ }
107910
+ throw e;
107911
+ }
107912
+ let filtered = before ? commits.filter((c) => c.oid !== before) : commits;
107913
+ const hasMore = filtered.length > limit;
107914
+ if (hasMore)
107915
+ filtered = filtered.slice(0, limit);
107676
107916
  return {
107677
- id: id2,
107678
- message: options.message,
107679
- timestamp: Date.now(),
107680
- author: author.name
107917
+ entries: filtered.map((c) => ({
107918
+ id: c.oid,
107919
+ message: c.commit.message.trim(),
107920
+ timestamp: c.commit.author.timestamp * 1000,
107921
+ author: c.commit.author.name
107922
+ })),
107923
+ hasMore
107681
107924
  };
107682
107925
  }
107683
- async listHistory(projectDir) {
107684
- const commits = await import_isomorphic_git.default.log({ fs: fs5, dir: projectDir });
107685
- return commits.map((c) => ({
107686
- id: c.oid,
107687
- message: c.commit.message.trim(),
107688
- timestamp: c.commit.author.timestamp * 1000,
107689
- author: c.commit.author.name
107690
- }));
107926
+ restore(options) {
107927
+ return withRepoLock(this.scope.dir, () => this.restoreUnlocked(options));
107691
107928
  }
107692
- async restore(options) {
107929
+ async restoreUnlocked(options) {
107930
+ const { dir, subPath } = this.scope;
107693
107931
  await import_isomorphic_git.default.checkout({
107694
107932
  fs: fs5,
107695
- dir: options.projectDir,
107933
+ dir,
107934
+ cache: {},
107696
107935
  ref: options.id,
107697
107936
  force: true,
107698
- noUpdateHead: true
107937
+ noUpdateHead: true,
107938
+ ...subPath ? { filepaths: [subPath] } : {}
107699
107939
  });
107700
107940
  }
107701
107941
  }
107942
+ async function snapshotWorkingTreeUnlocked(options) {
107943
+ const dir = options.repoRoot ?? options.projectDir;
107944
+ const subPath = options.subPath || undefined;
107945
+ const cache2 = {};
107946
+ if (!await hasPendingChanges(dir, subPath, cache2)) {
107947
+ throw new Error("No changes since the last snapshot — there is nothing new to save.");
107948
+ }
107949
+ await stageAll(dir, subPath, cache2);
107950
+ const author = gitAuthor(options.authorName);
107951
+ const id2 = await import_isomorphic_git.default.commit({
107952
+ fs: fs5,
107953
+ dir,
107954
+ cache: cache2,
107955
+ message: options.message,
107956
+ author
107957
+ });
107958
+ const [head] = await import_isomorphic_git.default.log({ fs: fs5, dir, cache: cache2, depth: 1 });
107959
+ return {
107960
+ id: id2,
107961
+ message: options.message,
107962
+ timestamp: head ? head.commit.author.timestamp * 1000 : Date.now(),
107963
+ author: author.name
107964
+ };
107965
+ }
107966
+ function isNoChangesError(e) {
107967
+ return e instanceof Error && /no changes since the last snapshot/i.test(e.message);
107968
+ }
107702
107969
  function providerFor(source) {
107703
107970
  switch (source.type) {
107704
107971
  case "local-folder":
@@ -107710,18 +107977,58 @@ function providerFor(source) {
107710
107977
  }
107711
107978
  }
107712
107979
  function gitDirFor(projectDir) {
107713
- return path9.join(projectDir, ".git");
107980
+ return path10.join(projectDir, ".git");
107714
107981
  }
107715
- var import_isomorphic_git, DEFAULT_AUTHOR = "print-md", DEFAULT_EMAIL = "noreply@print-md.local", DEFAULT_BRANCH = "main";
107982
+ function autoSnapshotDelayMs(policy) {
107983
+ const enabled = policy?.autoSnapshot ?? true;
107984
+ if (!enabled)
107985
+ return null;
107986
+ const raw = policy?.autoSnapshotMinutes;
107987
+ const minutes = typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? raw : AUTO_SNAPSHOT_DEFAULT_MINUTES;
107988
+ const clamped = Math.min(AUTO_SNAPSHOT_MAX_MINUTES, Math.max(AUTO_SNAPSHOT_MIN_MINUTES, minutes));
107989
+ return clamped * 60000;
107990
+ }
107991
+ function isGitInternalPath(p10) {
107992
+ return p10.split(/[\\/]+/).some((segment) => segment === ".git");
107993
+ }
107994
+ async function restoreVersionWithBackup(options) {
107995
+ const { projectDir, id: id2, authorName } = options;
107996
+ const source = await detectProjectSource(projectDir);
107997
+ if (source.type !== "local-git-folder") {
107998
+ throw new Error("This project has no version history yet. Enable version history first.");
107999
+ }
108000
+ const provider = new LocalGitSourceProvider(source);
108001
+ const scope = gitScopeFor(source);
108002
+ return withRepoLock(scope.dir, async () => {
108003
+ let backupId;
108004
+ if (await hasPendingChanges(scope.dir, scope.subPath || undefined)) {
108005
+ const backup = await provider.snapshotUnlocked({
108006
+ projectDir,
108007
+ message: RESTORE_BACKUP_MESSAGE,
108008
+ authorName
108009
+ });
108010
+ backupId = backup.id;
108011
+ }
108012
+ try {
108013
+ await provider.restoreUnlocked({ projectDir, id: id2 });
108014
+ } catch (cause) {
108015
+ throw new Error(backupId ? "The restore could not be completed, but your work is safe — it was " + `automatically saved as a backup snapshot (${backupId.slice(0, 7)}) ` + "and appears in your version history." : "The restore could not be completed. Your project files were not changed.", { cause });
108016
+ }
108017
+ return { restoredId: id2, backupId };
108018
+ });
108019
+ }
108020
+ var import_isomorphic_git, HISTORY_PAGE_LIMIT = 100, DEFAULT_AUTHOR = "print-md", DEFAULT_EMAIL = "noreply@print-md.local", DEFAULT_BRANCH = "main", repoQueues, RESTORE_BACKUP_MESSAGE = "Automatic backup before restoring an earlier version", AUTO_SNAPSHOT_MESSAGE = "Automatic snapshot", AUTO_SNAPSHOT_MIN_MINUTES = 5, AUTO_SNAPSHOT_MAX_MINUTES, AUTO_SNAPSHOT_DEFAULT_MINUTES = 10;
107716
108021
  var init_source_provider = __esm(() => {
107717
108022
  init_project_source();
107718
108023
  import_isomorphic_git = __toESM(require_isomorphic_git(), 1);
108024
+ repoQueues = new Map;
108025
+ AUTO_SNAPSHOT_MAX_MINUTES = 24 * 60;
107719
108026
  });
107720
108027
 
107721
108028
  // ../lib/src/lib/project-scaffold.ts
107722
- import { access as access2, copyFile as copyFile2, mkdir as mkdir6, readFile as readFile21, writeFile as writeFile7 } from "node:fs/promises";
108029
+ import { access as access2, copyFile as copyFile2, mkdir as mkdir6, readFile as readFile22, writeFile as writeFile7 } from "node:fs/promises";
107723
108030
  import { constants as FS } from "node:fs";
107724
- import path10 from "node:path";
108031
+ import path11 from "node:path";
107725
108032
  function slugifyProjectName(name) {
107726
108033
  return name.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
107727
108034
  }
@@ -107739,7 +108046,7 @@ async function scaffoldProject(options) {
107739
108046
  throw new CreateProjectErrorImpl("invalid-name", `Could not derive a valid folder name from "${name}".`);
107740
108047
  }
107741
108048
  const parentDir = options.parentDir;
107742
- if (!parentDir || !path10.isAbsolute(parentDir)) {
108049
+ if (!parentDir || !path11.isAbsolute(parentDir)) {
107743
108050
  throw new CreateProjectErrorImpl("parent-not-writable", "The save location must be an absolute path.");
107744
108051
  }
107745
108052
  try {
@@ -107747,7 +108054,7 @@ async function scaffoldProject(options) {
107747
108054
  } catch {
107748
108055
  throw new CreateProjectErrorImpl("parent-not-writable", `The chosen save location can't be written to: ${parentDir}`);
107749
108056
  }
107750
- const projectDir = path10.join(parentDir, folderName);
108057
+ const projectDir = path11.join(parentDir, folderName);
107751
108058
  let targetExists = true;
107752
108059
  try {
107753
108060
  await access2(projectDir, FS.F_OK);
@@ -107762,14 +108069,14 @@ async function scaffoldProject(options) {
107762
108069
  const tplManifest = await getAssetPath(`templates/${template}/manifest.yaml`);
107763
108070
  const tplChapter = await getAssetPath(`templates/${template}/chapter-01.md`);
107764
108071
  await mkdir6(projectDir, { recursive: true });
107765
- await mkdir6(path10.join(projectDir, "assets"), { recursive: true });
107766
- await copyFile2(tplManifest, path10.join(projectDir, "manifest.yaml"));
107767
- await copyFile2(tplChapter, path10.join(projectDir, "chapter-01.md"));
108072
+ await mkdir6(path11.join(projectDir, "assets"), { recursive: true });
108073
+ await copyFile2(tplManifest, path11.join(projectDir, "manifest.yaml"));
108074
+ await copyFile2(tplChapter, path11.join(projectDir, "chapter-01.md"));
107768
108075
  } catch (e) {
107769
108076
  throw new CreateProjectErrorImpl("scaffold-io", `Could not create the project files: ${e instanceof Error ? e.message : String(e)}`);
107770
108077
  }
107771
- const manifestPath = path10.join(projectDir, "manifest.yaml");
107772
- const openFile = path10.join(projectDir, "chapter-01.md");
108078
+ const manifestPath = path11.join(projectDir, "manifest.yaml");
108079
+ const openFile = path11.join(projectDir, "chapter-01.md");
107773
108080
  const author = (options.author ?? "").trim() || DEFAULT_AUTHOR2;
107774
108081
  const outputPdf = `${slug}.pdf`;
107775
108082
  const substitutions = {
@@ -107813,7 +108120,7 @@ async function scaffoldProject(options) {
107813
108120
  return result;
107814
108121
  }
107815
108122
  async function fillTemplateFile(filePath2, substitutions) {
107816
- let text4 = await readFile21(filePath2, "utf8");
108123
+ let text4 = await readFile22(filePath2, "utf8");
107817
108124
  for (const [token, value] of Object.entries(substitutions)) {
107818
108125
  text4 = text4.split(token).join(value);
107819
108126
  }
@@ -107832,6 +108139,119 @@ var init_project_scaffold = __esm(() => {
107832
108139
  };
107833
108140
  });
107834
108141
 
108142
+ // ../lib/src/lib/remote-auth/token-store.ts
108143
+ import { chmod, mkdir as mkdir7, readFile as readFile23, writeFile as writeFile8 } from "node:fs/promises";
108144
+ import os4 from "node:os";
108145
+ import path12 from "node:path";
108146
+ function defaultConfigDir() {
108147
+ const override = process.env.PRINT_MD_CONFIG_DIR?.trim();
108148
+ if (override)
108149
+ return override;
108150
+ if (process.platform === "win32" && process.env.APPDATA) {
108151
+ return path12.join(process.env.APPDATA, "print-md");
108152
+ }
108153
+ const xdg = process.env.XDG_CONFIG_HOME?.trim();
108154
+ return path12.join(xdg || path12.join(os4.homedir(), ".config"), "print-md");
108155
+ }
108156
+
108157
+ class FileTokenStore {
108158
+ filePath;
108159
+ queue = Promise.resolve();
108160
+ constructor(filePath2) {
108161
+ this.filePath = filePath2 ?? path12.join(defaultConfigDir(), "credentials.json");
108162
+ }
108163
+ async read() {
108164
+ try {
108165
+ const raw = await readFile23(this.filePath, "utf8");
108166
+ const parsed = JSON.parse(raw);
108167
+ if (parsed && typeof parsed === "object" && parsed.credentials)
108168
+ return parsed;
108169
+ } catch {}
108170
+ return { version: 1, credentials: {} };
108171
+ }
108172
+ async write(data) {
108173
+ await mkdir7(path12.dirname(this.filePath), { recursive: true });
108174
+ await writeFile8(this.filePath, JSON.stringify(data, null, 2), {
108175
+ encoding: "utf8",
108176
+ mode: 384
108177
+ });
108178
+ await chmod(this.filePath, 384);
108179
+ }
108180
+ enqueue(fn2) {
108181
+ const run2 = this.queue.then(fn2, fn2);
108182
+ this.queue = run2.catch(() => {
108183
+ return;
108184
+ });
108185
+ return run2;
108186
+ }
108187
+ get(host) {
108188
+ return this.enqueue(async () => {
108189
+ const data = await this.read();
108190
+ return data.credentials[normalizeHost(host)] ?? null;
108191
+ });
108192
+ }
108193
+ set(host, credential) {
108194
+ return this.enqueue(async () => {
108195
+ const data = await this.read();
108196
+ data.credentials[normalizeHost(host)] = credential;
108197
+ await this.write(data);
108198
+ });
108199
+ }
108200
+ delete(host) {
108201
+ return this.enqueue(async () => {
108202
+ const data = await this.read();
108203
+ delete data.credentials[normalizeHost(host)];
108204
+ await this.write(data);
108205
+ });
108206
+ }
108207
+ list() {
108208
+ return this.enqueue(async () => {
108209
+ const data = await this.read();
108210
+ return Object.values(data.credentials);
108211
+ });
108212
+ }
108213
+ }
108214
+ function normalizeHost(host) {
108215
+ return host.trim().toLowerCase();
108216
+ }
108217
+ var init_token_store = () => {};
108218
+ // ../lib/src/lib/remote-auth/github-repos.ts
108219
+ var init_github_repos = () => {};
108220
+
108221
+ // ../lib/src/lib/remote-auth/clone.ts
108222
+ var init_clone = __esm(() => {
108223
+ init_source_provider();
108224
+ init_token_store();
108225
+ });
108226
+
108227
+ // ../lib/src/lib/remote-auth/test-access.ts
108228
+ var init_test_access = __esm(() => {
108229
+ init_token_store();
108230
+ });
108231
+
108232
+ // ../lib/src/lib/remote-auth/generic-auth.ts
108233
+ var init_generic_auth = __esm(() => {
108234
+ init_test_access();
108235
+ });
108236
+
108237
+ // ../lib/src/lib/remote-auth/diagnose.ts
108238
+ var init_diagnose = __esm(() => {
108239
+ init_project_source();
108240
+ init_generic_auth();
108241
+ init_test_access();
108242
+ init_token_store();
108243
+ });
108244
+
108245
+ // ../lib/src/lib/remote-auth/sync.ts
108246
+ var import_diff3;
108247
+ var init_sync = __esm(() => {
108248
+ init_project_source();
108249
+ init_clone();
108250
+ init_source_provider();
108251
+ init_token_store();
108252
+ import_diff3 = __toESM(require_diff3(), 1);
108253
+ });
108254
+
107835
108255
  // ../lib/src/api/index.ts
107836
108256
  var init_api = __esm(() => {
107837
108257
  init_build_runner();
@@ -107841,6 +108261,13 @@ var init_api = __esm(() => {
107841
108261
  init_project_source();
107842
108262
  init_project_scaffold();
107843
108263
  init_source_provider();
108264
+ init_token_store();
108265
+ init_github_repos();
108266
+ init_clone();
108267
+ init_test_access();
108268
+ init_generic_auth();
108269
+ init_diagnose();
108270
+ init_sync();
107844
108271
  });
107845
108272
 
107846
108273
  // ../lib/src/index.ts
@@ -107854,6 +108281,7 @@ var init_src = __esm(() => {
107854
108281
  init_tool_check();
107855
108282
  init_registry();
107856
108283
  init_manifest();
108284
+ init_image_inspect();
107857
108285
  init_printsafe();
107858
108286
  init_printsafe();
107859
108287
  init_api();
@@ -107936,7 +108364,7 @@ __export(exports_preview, {
107936
108364
  default: () => preview_default
107937
108365
  });
107938
108366
  import { defineCommand as defineCommand2 } from "citty";
107939
- import path11 from "node:path";
108367
+ import path13 from "node:path";
107940
108368
  import fs6 from "node:fs";
107941
108369
  function resolvePort(raw) {
107942
108370
  if (raw === undefined || raw === "")
@@ -107992,7 +108420,7 @@ var init_preview = __esm(() => {
107992
108420
  "skip-post-validate": { type: "boolean", description: "Skip post-build PDF/X validation (pdfx only)" }
107993
108421
  },
107994
108422
  async run({ args }) {
107995
- const inputPath = args.input ? path11.resolve(args.input) : undefined;
108423
+ const inputPath = args.input ? path13.resolve(args.input) : undefined;
107996
108424
  if (inputPath !== undefined) {
107997
108425
  if (!fs6.existsSync(inputPath) || !fs6.statSync(inputPath).isDirectory()) {
107998
108426
  log.error(`Input directory does not exist: ${inputPath}`);
@@ -108055,7 +108483,7 @@ __export(exports_build, {
108055
108483
  default: () => build_default
108056
108484
  });
108057
108485
  import { defineCommand as defineCommand3 } from "citty";
108058
- import path12 from "node:path";
108486
+ import path14 from "node:path";
108059
108487
  function parseFormat2(raw) {
108060
108488
  if (raw === undefined || raw === "")
108061
108489
  return "pdf";
@@ -108103,7 +108531,7 @@ var init_build = __esm(() => {
108103
108531
  const { outDir, pdfFileOverride } = splitOutPath(typeof args.out === "string" ? args.out : undefined, format);
108104
108532
  try {
108105
108533
  await runBuild({
108106
- inputDir: path12.resolve(args.input ?? "."),
108534
+ inputDir: path14.resolve(args.input ?? "."),
108107
108535
  format,
108108
108536
  outDir,
108109
108537
  pdfFileOverride,
@@ -108300,7 +108728,7 @@ __export(exports_preflight, {
108300
108728
  buildPreflightPayload: () => buildPreflightPayload
108301
108729
  });
108302
108730
  import { defineCommand as defineCommand7 } from "citty";
108303
- import { mkdir as mkdir7, writeFile as writeFile8 } from "node:fs/promises";
108731
+ import { mkdir as mkdir8, writeFile as writeFile9 } from "node:fs/promises";
108304
108732
  import { basename as basename3, dirname as dirname6, extname, join as join10, resolve as resolve15 } from "node:path";
108305
108733
  function computeStatus(errors, warnings, missingTools, skippedRequired) {
108306
108734
  if (errors > 0 || skippedRequired)
@@ -108476,10 +108904,10 @@ var init_preflight = __esm(() => {
108476
108904
  const baseName = typeof args.name === "string" && args.name.trim().length > 0 ? args.name.trim() : defaultReportName(pdfPath);
108477
108905
  const jsonPath = join10(reportDir, `${baseName}.json`);
108478
108906
  const markdownPath = join10(reportDir, `${baseName}.md`);
108479
- await mkdir7(reportDir, { recursive: true });
108480
- await writeFile8(jsonPath, `${JSON.stringify(payload, null, 2)}
108907
+ await mkdir8(reportDir, { recursive: true });
108908
+ await writeFile9(jsonPath, `${JSON.stringify(payload, null, 2)}
108481
108909
  `, "utf8");
108482
- await writeFile8(markdownPath, toPreflightMarkdown(payload), "utf8");
108910
+ await writeFile9(markdownPath, toPreflightMarkdown(payload), "utf8");
108483
108911
  log.info(`Preflight status: ${payload.status}`);
108484
108912
  log.info(`JSON report: ${jsonPath}`);
108485
108913
  log.info(`Markdown report: ${markdownPath}`);
@@ -108501,7 +108929,7 @@ var SUBCOMMANDS = {
108501
108929
  audit: () => Promise.resolve().then(() => (init_audit(), exports_audit)).then((m) => m.default),
108502
108930
  preflight: () => Promise.resolve().then(() => (init_preflight(), exports_preflight)).then((m) => m.default)
108503
108931
  };
108504
- var VERSION = "0.4.1";
108932
+ var VERSION = "0.5.0-rc.10";
108505
108933
  var main = defineCommand8({
108506
108934
  meta: {
108507
108935
  name: "print-md",