@jayjiang/byoao 1.0.4 → 1.0.5

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,35 +1,72 @@
1
1
  /**
2
2
  * Bun CJS interop shim.
3
3
  *
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".
4
+ * Bun 1.3.x has a pervasive bug with CJS/ESM interop: it loads CJS sub-modules
5
+ * as ESM and then fails with "Missing 'default' export" for any file that uses
6
+ * `module.exports` instead of `export default`. This affects fs-extra AND its
7
+ * own ESM wrapper (`fs-extra/esm`), making fs-extra completely unusable in Bun.
7
8
  *
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.
9
+ * Solution for fs: build a drop-in replacement from native Node.js APIs.
10
+ * Solution for handlebars/gray-matter/semver: createRequire works fine in Bun
11
+ * for packages that have NO `exports` field.
14
12
  */
15
13
  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.
14
+ import * as nodeFs from "node:fs";
15
+ import * as nodeFsPromises from "node:fs/promises";
16
+ import path from "node:path";
17
+ // ── fs-extra polyfills (native Node.js only) ──────────────────────────────────
18
+ async function copy(src, dest) {
19
+ await nodeFsPromises.cp(src, dest, { recursive: true });
20
+ }
21
+ async function ensureDir(dirPath) {
22
+ await nodeFsPromises.mkdir(dirPath, { recursive: true });
23
+ }
24
+ async function pathExists(filePath) {
25
+ try {
26
+ await nodeFsPromises.access(filePath);
27
+ return true;
28
+ }
29
+ catch {
30
+ return false;
31
+ }
32
+ }
33
+ function pathExistsSync(filePath) {
34
+ return nodeFs.existsSync(filePath);
35
+ }
36
+ async function readJson(filePath) {
37
+ const content = await nodeFsPromises.readFile(filePath, "utf-8");
38
+ return JSON.parse(content);
39
+ }
40
+ function readJsonSync(filePath) {
41
+ return JSON.parse(nodeFs.readFileSync(filePath, "utf-8"));
42
+ }
43
+ async function writeJson(filePath, data, options) {
44
+ const indent = options?.spaces ?? 2;
45
+ await nodeFsPromises.mkdir(path.dirname(filePath), { recursive: true });
46
+ await nodeFsPromises.writeFile(filePath, JSON.stringify(data, null, indent));
47
+ }
48
+ function writeJsonSync(filePath, data, options) {
49
+ const indent = options?.spaces ?? 2;
50
+ nodeFs.mkdirSync(path.dirname(filePath), { recursive: true });
51
+ nodeFs.writeFileSync(filePath, JSON.stringify(data, null, indent));
52
+ }
53
+ async function remove(filePath) {
54
+ await nodeFsPromises.rm(filePath, { recursive: true, force: true });
55
+ }
56
+ function removeSync(filePath) {
57
+ nodeFs.rmSync(filePath, { recursive: true, force: true });
58
+ }
26
59
  export const fs = {
27
- existsSync,
28
- readFileSync,
29
- readdirSync,
30
- readFile,
31
- writeFile,
32
- readdir,
60
+ // node:fs sync
61
+ existsSync: nodeFs.existsSync,
62
+ readFileSync: nodeFs.readFileSync,
63
+ readdirSync: nodeFs.readdirSync,
64
+ // node:fs/promises async
65
+ readFile: nodeFsPromises.readFile,
66
+ writeFile: nodeFsPromises.writeFile,
67
+ readdir: nodeFsPromises.readdir,
68
+ mkdir: nodeFsPromises.mkdir,
69
+ // fs-extra extras (native implementations)
33
70
  copy,
34
71
  ensureDir,
35
72
  pathExists,
@@ -1 +1 @@
1
- {"version":3,"file":"cjs-modules.js","sourceRoot":"","sources":["../../src/lib/cjs-modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,gFAAgF;AAChF,OAAO,EACL,UAAU,EACV,YAAY,EACZ,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,gFAAgF;AAChF,OAAO,EACL,QAAQ,EACR,SAAS,EACT,OAAO,GACR,MAAM,kBAAkB,CAAC;AAE1B,gFAAgF;AAChF,sEAAsE;AACtE,6EAA6E;AAC7E,OAAO,EACL,IAAI,EACJ,SAAS,EACT,UAAU,EACV,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,aAAa,EACb,MAAM,EACN,UAAU,GACX,MAAM,cAAc,CAAC;AAOtB,0EAA0E;AAC1E,iFAAiF;AACjF,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,UAAU;IACV,YAAY;IACZ,WAAW;IACX,QAAQ;IACR,SAAS;IACT,OAAO;IACP,IAAI;IACJ,SAAS;IACT,UAAU;IACV,cAAc;IACd,QAAQ;IACR,YAAY;IACZ,SAAS;IACT,aAAa;IACb,MAAM;IACN,UAAU;CACkB,CAAC;AAE/B,gFAAgF;AAChF,MAAM,QAAQ,GAAG,aAAa,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;AA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AAC,CAAC;AAC5D,CAAC;AAED,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,eAAe;IACf,UAAU,EAAE,MAAM,CAAC,UAAU;IAC7B,YAAY,EAAE,MAAM,CAAC,YAAY;IACjC,WAAW,EAAE,MAAM,CAAC,WAAW;IAC/B,yBAAyB;IACzB,QAAQ,EAAE,cAAc,CAAC,QAAQ;IACjC,SAAS,EAAE,cAAc,CAAC,SAAS;IACnC,OAAO,EAAE,cAAc,CAAC,OAAO;IAC/B,KAAK,EAAE,cAAc,CAAC,KAAK;IAC3B,2CAA2C;IAC3C,IAAI;IACJ,SAAS;IACT,UAAU;IACV,cAAc;IACd,QAAQ;IACR,YAAY;IACZ,SAAS;IACT,aAAa;IACb,MAAM;IACN,UAAU;CACkB,CAAC;AAE/B,gFAAgF;AAChF,MAAM,QAAQ,GAAG,aAAa,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.4",
3
+ "version": "1.0.5",
4
4
  "description": "Build Your Own AI OS — Obsidian + AI Agent",
5
5
  "type": "module",
6
6
  "engines": {