@mu-crew/mu 3.11.2 → 3.12.0

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.
@@ -14,4 +14,4 @@ export {
14
14
  defaultStateDir,
15
15
  xdgStateHome
16
16
  };
17
- //# sourceMappingURL=chunk-4PACTXAB.js.map
17
+ //# sourceMappingURL=chunk-L2ABBTYG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state-dir.ts"],"sourcesContent":["// The mu state directory, resolved from builtins only so the CLI\n// bootstrap (src/main.ts) can locate its compile cache before it loads\n// any of the CLI graph. db.ts re-exports defaultStateDir.\n\nimport { homedir } from \"node:os\";\nimport { isAbsolute, join } from \"node:path\";\n\n/**\n * Resolve the canonical mu state directory:\n * MU_STATE_DIR > $XDG_STATE_HOME/mu (absolute only) > ~/.local/state/mu\n */\nexport function defaultStateDir(): string {\n if (process.env.MU_STATE_DIR) return process.env.MU_STATE_DIR;\n return join(xdgStateHome(homedir()), \"mu\");\n}\n\n/**\n * The mu cache directory, `$XDG_CACHE_HOME/mu` (absolute only) else\n * `~/.cache/mu`: files mu can lose at any time, such as copies of data\n * that lives elsewhere too.\n */\nexport function defaultCacheDir(): string {\n const xdg = process.env.XDG_CACHE_HOME;\n return join(xdg !== undefined && isAbsolute(xdg) ? xdg : join(homedir(), \".cache\"), \"mu\");\n}\n\n/** `$XDG_STATE_HOME`, or `<home>/.local/state` when it is unset, empty,\n * or relative: the XDG spec says such a value must be ignored, and a\n * relative one would scatter state across every cwd mu runs in. */\nexport function xdgStateHome(home: string): string {\n const xdg = process.env.XDG_STATE_HOME;\n return xdg !== undefined && isAbsolute(xdg) ? xdg : join(home, \".local\", \"state\");\n}\n"],"mappings":";AAIA,SAAS,eAAe;AACxB,SAAS,YAAY,YAAY;AAM1B,SAAS,kBAA0B;AACxC,MAAI,QAAQ,IAAI,aAAc,QAAO,QAAQ,IAAI;AACjD,SAAO,KAAK,aAAa,QAAQ,CAAC,GAAG,IAAI;AAC3C;AAeO,SAAS,aAAa,MAAsB;AACjD,QAAM,MAAM,QAAQ,IAAI;AACxB,SAAO,QAAQ,UAAa,WAAW,GAAG,IAAI,MAAM,KAAK,MAAM,UAAU,OAAO;AAClF;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  defaultStateDir,
3
3
  xdgStateHome
4
- } from "./chunk-4PACTXAB.js";
4
+ } from "./chunk-L2ABBTYG.js";
5
5
 
6
6
  // src/capture.ts
7
7
  var UNRESOLVED = "<unresolved>";
@@ -311,7 +311,7 @@ function openDb(options = {}) {
311
311
  const db = new Database(path, { readonly: options.readonly ?? false });
312
312
  if (!options.readonly) {
313
313
  db.pragma("busy_timeout = 5000");
314
- const detectedVersion = detectExistingSchemaVersion(db);
314
+ const detectedVersion = db.transaction(() => detectExistingSchemaVersion(db))();
315
315
  if (detectedVersion !== null && detectedVersion > CURRENT_SCHEMA_VERSION) {
316
316
  try {
317
317
  db.close();
@@ -326,7 +326,7 @@ function openDb(options = {}) {
326
326
  }
327
327
  throw new SchemaTooOldError(detectedVersion, MIN_ACCEPTED_SCHEMA_VERSION);
328
328
  }
329
- db.pragma("journal_mode = WAL");
329
+ setWalMode(db);
330
330
  db.pragma("foreign_keys = ON");
331
331
  if (detectedVersion !== CURRENT_SCHEMA_VERSION || !schemaIsCurrent(db)) applySchema(db);
332
332
  seedMachineIdentity(db);
@@ -418,6 +418,22 @@ var SchemaTooNewError = class extends Error {
418
418
  return [{ intent: "Check which mu is on PATH", command: "which mu && mu --version" }];
419
419
  }
420
420
  };
421
+ var WAL_SWITCH_RETRY_MS = 5e3;
422
+ function setWalMode(db) {
423
+ const deadline = Date.now() + WAL_SWITCH_RETRY_MS;
424
+ const pause = new Int32Array(new SharedArrayBuffer(4));
425
+ for (; ; ) {
426
+ try {
427
+ db.pragma("journal_mode = WAL");
428
+ return;
429
+ } catch (err) {
430
+ const code = err.code;
431
+ const busy = typeof code === "string" && code.startsWith("SQLITE_BUSY");
432
+ if (!busy || Date.now() >= deadline) throw err;
433
+ Atomics.wait(pause, 0, 0, 10 + Math.floor(Math.random() * 20));
434
+ }
435
+ }
436
+ }
421
437
  function detectExistingSchemaVersion(db) {
422
438
  const hasVersionTable = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='schema_version'").get();
423
439
  if (hasVersionTable) {
@@ -2789,4 +2805,4 @@ export {
2789
2805
  ingestFromDb,
2790
2806
  transportNextSteps
2791
2807
  };
2792
- //# sourceMappingURL=chunk-WYBOR4FX.js.map
2808
+ //# sourceMappingURL=chunk-R2SVBZAB.js.map