@0x-jerry/x 2.9.3 → 2.10.1
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/{chunk-PM26AGY7.js → chunk-635NMR3B.js} +1 -1
- package/dist/hooks/index.js +71 -100
- package/dist/x.js +1 -2
- package/dist/xn.js +1 -2
- package/dist/xr.js +1 -2
- package/package.json +1 -1
- package/dist/chunk-MLKGABMK.js +0 -9
package/dist/hooks/index.js
CHANGED
|
@@ -1,30 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__export
|
|
3
|
-
} from "../chunk-MLKGABMK.js";
|
|
4
|
-
|
|
5
1
|
// src/hooks/index.ts
|
|
6
2
|
import * as tsx from "tsx/esm";
|
|
7
3
|
|
|
8
4
|
// src/hooks/jsonc.ts
|
|
9
|
-
var jsonc_exports = {};
|
|
10
|
-
__export(jsonc_exports, {
|
|
11
|
-
load: () => load,
|
|
12
|
-
resolve: () => resolve
|
|
13
|
-
});
|
|
14
|
-
import path from "path";
|
|
15
5
|
import stripJsonComment from "strip-json-comments";
|
|
16
6
|
|
|
17
|
-
// src/hooks/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
// src/hooks/helper.ts
|
|
8
|
+
import { readFile } from "fs/promises";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
10
|
+
function createModuleHook({
|
|
11
|
+
type,
|
|
12
|
+
loader
|
|
13
|
+
}) {
|
|
14
|
+
const resolve2 = async (specifier, ctx, nextResolve) => {
|
|
15
|
+
const nextResult = await nextResolve(specifier, ctx);
|
|
16
|
+
if (ctx.importAttributes.type !== type) {
|
|
17
|
+
return nextResult;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
...nextResult,
|
|
21
|
+
format: type,
|
|
22
|
+
shortCircuit: true
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const load2 = async (url, ctx, nextLoad) => {
|
|
26
|
+
if (ctx.format !== type) return nextLoad(url, ctx);
|
|
27
|
+
const raw = await readFile(fileURLToPath(url), "utf-8");
|
|
28
|
+
const source = await loader(raw);
|
|
29
|
+
return {
|
|
30
|
+
shortCircuit: true,
|
|
31
|
+
...source
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
resolve: resolve2,
|
|
36
|
+
load: load2
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/hooks/jsonc.ts
|
|
41
|
+
var jsonc_default = createModuleHook({
|
|
42
|
+
type: "jsonc",
|
|
43
|
+
loader(rawSource) {
|
|
44
|
+
const source = stripJsonComment(rawSource);
|
|
45
|
+
return {
|
|
46
|
+
format: "json",
|
|
47
|
+
source
|
|
48
|
+
};
|
|
22
49
|
}
|
|
23
|
-
|
|
24
|
-
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// src/hooks/text.ts
|
|
53
|
+
var text_default = createModuleHook({
|
|
54
|
+
type: "text",
|
|
55
|
+
loader(rawSource) {
|
|
56
|
+
const source = `export default ${JSON.stringify(rawSource)};`;
|
|
57
|
+
return {
|
|
58
|
+
format: "module",
|
|
59
|
+
source
|
|
60
|
+
};
|
|
25
61
|
}
|
|
26
|
-
|
|
27
|
-
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// src/hooks/utils.ts
|
|
28
65
|
function chainHooks(fns) {
|
|
29
66
|
const wrapperFn = (a, b, defaultHook) => {
|
|
30
67
|
const fn = fns.reduceRight((prev, hook) => {
|
|
@@ -37,90 +74,24 @@ function chainHooks(fns) {
|
|
|
37
74
|
return wrapperFn;
|
|
38
75
|
}
|
|
39
76
|
|
|
40
|
-
// src/hooks/jsonc.ts
|
|
41
|
-
var supportedExtensions = [".jsonc"];
|
|
42
|
-
var FORMAT_TYPE = "jsonc";
|
|
43
|
-
var resolve = async (specifier, ctx, nextResolve) => {
|
|
44
|
-
const nextResult = await nextResolve(specifier, ctx);
|
|
45
|
-
const ext = path.extname(specifier);
|
|
46
|
-
if (!supportedExtensions.includes(ext)) return nextResult;
|
|
47
|
-
return {
|
|
48
|
-
...nextResult,
|
|
49
|
-
format: FORMAT_TYPE
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
var load = async (url, ctx, nextLoad) => {
|
|
53
|
-
const nextResult = await nextLoad(url, ctx);
|
|
54
|
-
if (ctx.format !== FORMAT_TYPE) return nextResult;
|
|
55
|
-
const source = stripJsonComment(sourceToStr(nextResult.source));
|
|
56
|
-
return {
|
|
57
|
-
format: "json",
|
|
58
|
-
source
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// src/hooks/text.ts
|
|
63
|
-
var text_exports = {};
|
|
64
|
-
__export(text_exports, {
|
|
65
|
-
load: () => load2,
|
|
66
|
-
resolve: () => resolve2
|
|
67
|
-
});
|
|
68
|
-
import path2 from "path";
|
|
69
|
-
var supportedExtensions2 = [".txt", ".sql", ".md"];
|
|
70
|
-
var FORMAT_TYPE2 = "text";
|
|
71
|
-
var resolve2 = async (specifier, ctx, nextResolve) => {
|
|
72
|
-
const nextResult = await nextResolve(specifier, ctx);
|
|
73
|
-
const ext = path2.extname(specifier);
|
|
74
|
-
if (!supportedExtensions2.includes(ext)) return nextResult;
|
|
75
|
-
return {
|
|
76
|
-
...nextResult,
|
|
77
|
-
format: FORMAT_TYPE2
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
var load2 = async (url, ctx, nextLoad) => {
|
|
81
|
-
const nextResult = await nextLoad(url, ctx);
|
|
82
|
-
if (ctx.format !== FORMAT_TYPE2) return nextResult;
|
|
83
|
-
const source = `export default ${JSON.stringify(sourceToStr(nextResult.source))};`;
|
|
84
|
-
return {
|
|
85
|
-
format: "module",
|
|
86
|
-
source
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
|
|
90
77
|
// src/hooks/yaml.ts
|
|
91
|
-
var yaml_exports = {};
|
|
92
|
-
__export(yaml_exports, {
|
|
93
|
-
load: () => load3,
|
|
94
|
-
resolve: () => resolve3
|
|
95
|
-
});
|
|
96
|
-
import path3 from "path";
|
|
97
78
|
import yaml from "yaml";
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
};
|
|
109
|
-
var load3 = async (url, ctx, nextLoad) => {
|
|
110
|
-
if (ctx.format !== FORMAT_TYPE3) return nextLoad(url, ctx);
|
|
111
|
-
const nextResult = await nextLoad(url, ctx);
|
|
112
|
-
const source = yaml.parse(sourceToStr(nextResult.source));
|
|
113
|
-
return {
|
|
114
|
-
format: "json",
|
|
115
|
-
source: JSON.stringify(source)
|
|
116
|
-
};
|
|
117
|
-
};
|
|
79
|
+
var yaml_default = createModuleHook({
|
|
80
|
+
type: "yaml",
|
|
81
|
+
loader(rawSource) {
|
|
82
|
+
const source = yaml.parse(rawSource);
|
|
83
|
+
return {
|
|
84
|
+
format: "json",
|
|
85
|
+
source: JSON.stringify(source)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
});
|
|
118
89
|
|
|
119
90
|
// src/hooks/index.ts
|
|
120
|
-
var hooks = [
|
|
121
|
-
var
|
|
122
|
-
var
|
|
91
|
+
var hooks = [jsonc_default, text_default, yaml_default, tsx];
|
|
92
|
+
var resolve = chainHooks(hooks.map((n) => n.resolve));
|
|
93
|
+
var load = chainHooks(hooks.map((n) => n.load));
|
|
123
94
|
export {
|
|
124
|
-
|
|
125
|
-
|
|
95
|
+
load,
|
|
96
|
+
resolve
|
|
126
97
|
};
|
package/dist/x.js
CHANGED
package/dist/xn.js
CHANGED
package/dist/xr.js
CHANGED
package/package.json
CHANGED