@jayjiang/byoao 1.0.3 → 1.0.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.
@@ -1,28 +1,52 @@
1
1
  /**
2
2
  * Bun CJS interop shim.
3
3
  *
4
- * Bun 1.3.x does not auto-wrap `module.exports` as an ESM default for CJS
5
- * packages, regardless of whether they have an `exports` field.
4
+ * Bun 1.3.x cannot reliably load the CJS build of packages that have an
5
+ * `exports` field (e.g. fs-extra): `import default` gives "Missing 'default'
6
+ * export" and `createRequire` gives "require() async module".
6
7
  *
7
- * For fs-extra we require the CJS entry file directly (bypassing the
8
- * `exports` field resolution) because Bun 1.3.x treats `require("fs-extra")`
9
- * as an async module when it sees the `exports` field's ESM sibling entry.
8
+ * For fs-extra we build a combined ESM-native namespace from node:fs,
9
+ * node:fs/promises, and fs-extra's own ESM subpath (which deliberately
10
+ * excludes node:fs re-exports).
11
+ *
12
+ * For packages without an `exports` field (handlebars, gray-matter, semver)
13
+ * createRequire works fine in both Bun and Node.js.
10
14
  */
11
15
  import { createRequire } from "node:module";
16
+ // ── node:fs ──────────────────────────────────────────────────────────────────
17
+ import { existsSync, readFileSync, readdirSync, } from "node:fs";
18
+ // ── node:fs/promises ─────────────────────────────────────────────────────────
19
+ import { readFile, writeFile, readdir, } from "node:fs/promises";
20
+ // ── fs-extra ESM subpath ─────────────────────────────────────────────────────
21
+ // "fs-extra/esm" is a proper ESM module with named + default exports.
22
+ // It intentionally omits node:fs re-exports (those come from node:fs above).
23
+ import { copy, ensureDir, pathExists, pathExistsSync, readJson, readJsonSync, writeJson, writeJsonSync, remove, removeSync, } from "fs-extra/esm";
24
+ // Expose a unified `fs` object that matches the subset the codebase uses.
25
+ // Typed as FsExtra so callers keep full type-safety without changing their code.
26
+ export const fs = {
27
+ existsSync,
28
+ readFileSync,
29
+ readdirSync,
30
+ readFile,
31
+ writeFile,
32
+ readdir,
33
+ copy,
34
+ ensureDir,
35
+ pathExists,
36
+ pathExistsSync,
37
+ readJson,
38
+ readJsonSync,
39
+ writeJson,
40
+ writeJsonSync,
41
+ remove,
42
+ removeSync,
43
+ };
44
+ // ── CJS-only packages (no `exports` field — createRequire works in Bun) ──────
12
45
  const _require = createRequire(import.meta.url);
13
- // Bun 1.3.x treats `require("fs-extra")` (via createRequire) as an async module
14
- // due to a bug in how it handles the package's `exports` field — use the CJS
15
- // entry path directly to avoid this. Node.js enforces `exports` and rejects
16
- // that subpath, so we fall back to the normal package name there.
17
- const _fs = ("Bun" in globalThis
18
- ? _require("fs-extra/lib/index.js") // Bun: bypass exports resolution
19
- : _require("fs-extra") // Node.js: normal resolution
20
- );
21
46
  const _matter = _require("gray-matter");
22
47
  const _Handlebars = _require("handlebars");
23
48
  const _semver = _require("semver");
24
49
  const unwrap = (v) => (v["default"] ?? v);
25
- export const fs = unwrap(_fs);
26
50
  export const matter = unwrap(_matter);
27
51
  export const Handlebars = unwrap(_Handlebars);
28
52
  export const semver = unwrap(_semver);
@@ -1 +1 @@
1
- {"version":3,"file":"cjs-modules.js","sourceRoot":"","sources":["../../src/lib/cjs-modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAM5C,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEhD,gFAAgF;AAChF,6EAA6E;AAC7E,6EAA6E;AAC7E,kEAAkE;AAClE,MAAM,GAAG,GAAG,CAAC,KAAK,IAAI,UAAU;IAC9B,CAAC,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAE,iCAAiC;IACtE,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAe,6BAA6B;CACxD,CAAC;AACb,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAY,CAAC;AACnD,MAAM,WAAW,GAAG,QAAQ,CAAC,YAAY,CAAY,CAAC;AACtD,MAAM,OAAO,GAAG,QAAQ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AAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEhD,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAY,CAAC;AACnD,MAAM,WAAW,GAAG,QAAQ,CAAC,YAAY,CAAY,CAAC;AACtD,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAY,CAAC;AAE9C,MAAM,MAAM,GAAG,CAAC,CAAU,EAAE,EAAE,CAC5B,CAAE,CAA6B,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AAEnD,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAsB,CAAC;AAC3D,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAA0B,CAAC;AACvE,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAsB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayjiang/byoao",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Build Your Own AI OS — Obsidian + AI Agent",
5
5
  "type": "module",
6
6
  "engines": {