@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.
- package/dist/lib/cjs-modules.js +62 -25
- package/dist/lib/cjs-modules.js.map +1 -1
- package/package.json +1 -1
package/dist/lib/cjs-modules.js
CHANGED
|
@@ -1,35 +1,72 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bun CJS interop shim.
|
|
3
3
|
*
|
|
4
|
-
* Bun 1.3.x
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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
|
-
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
1
|
+
{"version":3,"file":"cjs-modules.js","sourceRoot":"","sources":["../../src/lib/cjs-modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,IAAI,MAAM,WAAW,CAAC;AAO7B,iFAAiF;AAEjF,KAAK,UAAU,IAAI,CAAC,GAAW,EAAE,IAAY;IAC3C,MAAM,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,OAAe;IACtC,MAAM,cAAc,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,QAAgB;IACxC,IAAI,CAAC;QACH,MAAM,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC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