@0x-jerry/x 2.10.1 → 2.12.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.
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "2.10.1";
2
+ var version = "2.12.0";
3
3
 
4
4
  export {
5
5
  version
@@ -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
+ };
@@ -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-635NMR3B.js";
4
+ } from "./chunk-AVVMCIYS.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-635NMR3B.js";
9
+ } from "./chunk-AVVMCIYS.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-635NMR3B.js";
7
+ } from "./chunk-AVVMCIYS.js";
8
8
 
9
9
  // src/xr.ts
10
10
  import { sliver } from "@0x-jerry/silver";
@@ -147,7 +147,7 @@ async function getAvailableCommands() {
147
147
  var ins = sliver`
148
148
  v${version} @help @autocompletion
149
149
 
150
- xr <@command:command-or-file> #stopEarly, run npm script or ts/js file quickly. ${defaultAction}
150
+ xr <@command|_files:command-or-file> #stopEarly, run npm script or ts/js file quickly. ${defaultAction}
151
151
  `;
152
152
  ins.type("command", async () => {
153
153
  const allScripts = await getAvailableCommands();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0x-jerry/x",
3
- "version": "2.10.1",
3
+ "version": "2.12.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"
@@ -44,7 +47,7 @@
44
47
  "clean": true
45
48
  },
46
49
  "dependencies": {
47
- "@0x-jerry/silver": "^1.1.1",
50
+ "@0x-jerry/silver": "^1.2.1",
48
51
  "@0x-jerry/utils": "^5.0.0",
49
52
  "decompress": "^4.2.1",
50
53
  "fs-extra": "^11.3.1",
@@ -60,11 +63,11 @@
60
63
  },
61
64
  "devDependencies": {
62
65
  "@0x-jerry/x-release": "^2.4.0",
63
- "@biomejs/biome": "^2.2.2",
66
+ "@biomejs/biome": "^2.2.3",
64
67
  "@types/decompress": "^4.2.7",
65
68
  "@types/fs-extra": "^11.0.4",
66
69
  "@types/global-agent": "^3.0.0",
67
- "@types/node": "^24.3.0",
70
+ "@types/node": "^24.3.1",
68
71
  "@types/prompts": "^2.4.9",
69
72
  "@vitest/coverage-v8": "^3.2.4",
70
73
  "tsup": "^8.5.0",
@@ -1,97 +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/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
- };
49
- }
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
- };
61
- }
62
- });
63
-
64
- // src/hooks/utils.ts
65
- function chainHooks(fns) {
66
- const wrapperFn = (a, b, defaultHook) => {
67
- const fn = fns.reduceRight((prev, hook) => {
68
- return (a2, b2) => {
69
- return hook(a2, b2, prev);
70
- };
71
- }, defaultHook);
72
- return fn(a, b);
73
- };
74
- return wrapperFn;
75
- }
76
-
77
- // src/hooks/yaml.ts
78
- import yaml from "yaml";
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
- });
89
-
90
- // src/hooks/index.ts
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));
94
- export {
95
- load,
96
- resolve
97
- };