@0x-jerry/x 2.10.0 → 2.11.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.
@@ -0,0 +1,35 @@
1
+ // src/hooks/helper.ts
2
+ function createModuleHook({
3
+ type,
4
+ loader
5
+ }) {
6
+ const resolve = async (specifier, ctx, nextResolve) => {
7
+ const nextResult = await nextResolve(specifier, ctx);
8
+ if (ctx.importAttributes.type !== type) {
9
+ return nextResult;
10
+ }
11
+ return {
12
+ ...nextResult,
13
+ format: type,
14
+ shortCircuit: true
15
+ };
16
+ };
17
+ const load = async (url, ctx, nextLoad) => {
18
+ const nextLoadResult = await nextLoad(url, ctx);
19
+ if (ctx.format !== type) return nextLoadResult;
20
+ if (!nextLoadResult.source) return nextLoadResult;
21
+ const source = await loader(nextLoadResult.source.toString());
22
+ return {
23
+ shortCircuit: true,
24
+ ...source
25
+ };
26
+ };
27
+ return {
28
+ resolve,
29
+ load
30
+ };
31
+ }
32
+
33
+ export {
34
+ createModuleHook
35
+ };
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "2.10.0";
2
+ var version = "2.11.0";
3
3
 
4
4
  export {
5
5
  version
@@ -0,0 +1,20 @@
1
+ import {
2
+ createModuleHook
3
+ } from "../chunk-CY2M62MH.js";
4
+
5
+ // src/hooks/jsonc.ts
6
+ import stripJsonComment from "strip-json-comments";
7
+ var { load, resolve } = createModuleHook({
8
+ type: "jsonc",
9
+ loader(rawSource) {
10
+ const source = stripJsonComment(rawSource);
11
+ return {
12
+ format: "json",
13
+ source
14
+ };
15
+ }
16
+ });
17
+ export {
18
+ load,
19
+ resolve
20
+ };
@@ -1,3 +1,6 @@
1
1
  // src/hooks/register.ts
2
2
  import { register } from "module";
3
- register("./index.js", import.meta.url);
3
+ register("./tsx.js", import.meta.url);
4
+ register("./text.js", import.meta.url);
5
+ register("./jsonc.js", import.meta.url);
6
+ register("./yaml.js", import.meta.url);
@@ -0,0 +1,19 @@
1
+ import {
2
+ createModuleHook
3
+ } from "../chunk-CY2M62MH.js";
4
+
5
+ // src/hooks/text.ts
6
+ var { load, resolve } = createModuleHook({
7
+ type: "text",
8
+ loader(rawSource) {
9
+ const source = `export default ${JSON.stringify(rawSource)};`;
10
+ return {
11
+ format: "module",
12
+ source
13
+ };
14
+ }
15
+ });
16
+ export {
17
+ load,
18
+ resolve
19
+ };
@@ -0,0 +1,6 @@
1
+ // src/hooks/tsx.ts
2
+ import { load, resolve } from "tsx/esm";
3
+ export {
4
+ load,
5
+ resolve
6
+ };
@@ -0,0 +1,20 @@
1
+ import {
2
+ createModuleHook
3
+ } from "../chunk-CY2M62MH.js";
4
+
5
+ // src/hooks/yaml.ts
6
+ import yaml from "yaml";
7
+ var { load, resolve } = createModuleHook({
8
+ type: "yaml",
9
+ loader(rawSource) {
10
+ const source = yaml.parse(rawSource);
11
+ return {
12
+ format: "json",
13
+ source: JSON.stringify(source)
14
+ };
15
+ }
16
+ });
17
+ export {
18
+ load,
19
+ resolve
20
+ };
package/dist/x.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  version
4
- } from "./chunk-VDPUNX7B.js";
4
+ } from "./chunk-J54EX5Y6.js";
5
5
 
6
6
  // src/x.ts
7
7
  import { sliver } from "@0x-jerry/silver";
package/dist/xn.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-ELIYGHQS.js";
7
7
  import {
8
8
  version
9
- } from "./chunk-VDPUNX7B.js";
9
+ } from "./chunk-J54EX5Y6.js";
10
10
 
11
11
  // src/xn.ts
12
12
  import { sliver } from "@0x-jerry/silver";
package/dist/xr.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-ELIYGHQS.js";
5
5
  import {
6
6
  version
7
- } from "./chunk-VDPUNX7B.js";
7
+ } from "./chunk-J54EX5Y6.js";
8
8
 
9
9
  // src/xr.ts
10
10
  import { sliver } from "@0x-jerry/silver";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0x-jerry/x",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/0x-jerry/x.git"
@@ -35,8 +35,11 @@
35
35
  "src/xr.ts",
36
36
  "src/xn.ts",
37
37
  "src/x.ts",
38
- "src/hooks/index.ts",
39
- "src/hooks/register.ts"
38
+ "src/hooks/register.ts",
39
+ "src/hooks/text.ts",
40
+ "src/hooks/jsonc.ts",
41
+ "src/hooks/yaml.ts",
42
+ "src/hooks/tsx.ts"
40
43
  ],
41
44
  "format": [
42
45
  "esm"
@@ -1,105 +0,0 @@
1
- // src/hooks/index.ts
2
- import * as tsx from "tsx/esm";
3
-
4
- // src/hooks/jsonc.ts
5
- import stripJsonComment from "strip-json-comments";
6
-
7
- // src/hooks/utils.ts
8
- function sourceToStr(source) {
9
- if (!source) return "";
10
- if (source instanceof ArrayBuffer) {
11
- return Buffer.from(source).toString("utf-8");
12
- }
13
- if (typeof source === "string") {
14
- return source;
15
- }
16
- return Buffer.from(source.buffer).toString("utf-8");
17
- }
18
- function chainHooks(fns) {
19
- const wrapperFn = (a, b, defaultHook) => {
20
- const fn = fns.reduceRight((prev, hook) => {
21
- return (a2, b2) => {
22
- return hook(a2, b2, prev);
23
- };
24
- }, defaultHook);
25
- return fn(a, b);
26
- };
27
- return wrapperFn;
28
- }
29
-
30
- // src/hooks/helper.ts
31
- function createModuleHook({
32
- type,
33
- loader
34
- }) {
35
- const resolve2 = async (specifier, ctx, nextResolve) => {
36
- const nextResult = await nextResolve(specifier, ctx);
37
- if (ctx.importAttributes.type !== type) {
38
- return nextResult;
39
- }
40
- return {
41
- ...nextResult,
42
- format: type,
43
- shortCircuit: true
44
- };
45
- };
46
- const load2 = async (url, ctx, nextLoad) => {
47
- const nextResult = await nextLoad(url, ctx);
48
- if (ctx.format !== type) return nextResult;
49
- const source = await loader(sourceToStr(nextResult.source));
50
- return {
51
- shortCircuit: true,
52
- ...source
53
- };
54
- };
55
- return {
56
- resolve: resolve2,
57
- load: load2
58
- };
59
- }
60
-
61
- // src/hooks/jsonc.ts
62
- var jsonc_default = createModuleHook({
63
- type: "jsonc",
64
- loader(rawSource) {
65
- const source = stripJsonComment(rawSource);
66
- return {
67
- format: "json",
68
- source
69
- };
70
- }
71
- });
72
-
73
- // src/hooks/text.ts
74
- var text_default = createModuleHook({
75
- type: "text",
76
- loader(rawSource) {
77
- const source = `export default ${JSON.stringify(rawSource)};`;
78
- return {
79
- format: "module",
80
- source
81
- };
82
- }
83
- });
84
-
85
- // src/hooks/yaml.ts
86
- import yaml from "yaml";
87
- var yaml_default = createModuleHook({
88
- type: "yaml",
89
- loader(rawSource) {
90
- const source = yaml.parse(rawSource);
91
- return {
92
- format: "json",
93
- source: JSON.stringify(source)
94
- };
95
- }
96
- });
97
-
98
- // src/hooks/index.ts
99
- var hooks = [jsonc_default, text_default, yaml_default, tsx];
100
- var resolve = chainHooks(hooks.map((n) => n.resolve));
101
- var load = chainHooks(hooks.map((n) => n.load));
102
- export {
103
- load,
104
- resolve
105
- };