@0x-jerry/x 2.7.2 → 2.7.3

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,22 +1,21 @@
1
1
  // src/utils.ts
2
- import { existsSync } from "fs";
3
- import { run } from "@0x-jerry/utils/node";
2
+ import { existsSync } from "node:fs";
3
+ import { exec as _exec } from "@0x-jerry/utils/node";
4
4
  async function exec(script, params, env) {
5
5
  const cmd = [script, ...params].join(" ");
6
- await run(cmd, env);
6
+ await _exec(cmd, { env });
7
7
  }
8
8
  function exists(path) {
9
9
  return existsSync(path);
10
10
  }
11
11
  function flagOptionToStringArray(opt) {
12
- return Object.entries(opt).map(([_key, value]) => {
12
+ return Object.entries(opt).flatMap(([_key, value]) => {
13
13
  const key = (_key.length === 1 ? "-" : "--") + _key;
14
14
  if (typeof value === "string" || typeof value === "number") {
15
15
  return [key, String(value)];
16
- } else {
17
- return [key];
18
16
  }
19
- }).flat();
17
+ return [key];
18
+ });
20
19
  }
21
20
 
22
21
  export {
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "2.7.2";
2
+ var version = "2.7.3";
3
3
 
4
4
  export {
5
5
  version
package/dist/x.js CHANGED
@@ -1,26 +1,27 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  version
4
- } from "./chunk-5L45XIBY.js";
4
+ } from "./chunk-ZU5F6V34.js";
5
5
 
6
6
  // src/x.ts
7
7
  import { sliver } from "@0x-jerry/silver";
8
+ import { bootstrap } from "global-agent";
8
9
 
9
10
  // src/commands/downloadGitRepo.ts
10
- import path from "node:path";
11
- import os from "node:os";
12
11
  import { createWriteStream } from "node:fs";
12
+ import os from "node:os";
13
+ import path from "node:path";
13
14
  import { pipeline } from "node:stream/promises";
14
- import prompts from "prompts";
15
- import pc from "picocolors";
16
- import got from "got";
15
+ import decompress from "decompress";
17
16
  import fs from "fs-extra";
17
+ import got from "got";
18
18
  import ora from "ora";
19
- import decompress from "decompress";
19
+ import pc from "picocolors";
20
+ import prompts from "prompts";
20
21
  async function downloadGitRepo(opt) {
21
22
  let { url, branch = "main", destDir } = opt;
22
23
  if (!url) {
23
- console.log(pc.red(`Please specify git url by using -u,--url`));
24
+ console.log(pc.red("Please specify git url by using -u,--url"));
24
25
  return;
25
26
  }
26
27
  destDir = await checkDest(destDir) || "";
@@ -100,7 +101,6 @@ async function downloadGitBranch(conf, branch) {
100
101
  }
101
102
 
102
103
  // src/x.ts
103
- import { bootstrap } from "global-agent";
104
104
  bootstrap({
105
105
  environmentVariableNamespace: ""
106
106
  });
@@ -115,8 +115,8 @@ t/template [dest], download git repo as a template. ${defaultAction}
115
115
  -b --branch, Git branch.
116
116
  `;
117
117
  async function defaultAction(_, args) {
118
- let [destDir] = _;
119
- let { url, branch = "main" } = args;
118
+ const [destDir] = _;
119
+ const { url, branch = "main" } = args;
120
120
  await downloadGitRepo({
121
121
  url,
122
122
  branch,
package/dist/xn.js CHANGED
@@ -3,17 +3,17 @@ import {
3
3
  exec,
4
4
  exists,
5
5
  flagOptionToStringArray
6
- } from "./chunk-WA6Z2RU3.js";
6
+ } from "./chunk-TTBHFDNB.js";
7
7
  import {
8
8
  version
9
- } from "./chunk-5L45XIBY.js";
9
+ } from "./chunk-ZU5F6V34.js";
10
10
 
11
11
  // src/xn.ts
12
12
  import { sliver } from "@0x-jerry/silver";
13
13
 
14
14
  // src/commands/dep/deno.ts
15
+ import path from "node:path";
15
16
  import { pathExists } from "fs-extra";
16
- import path from "path";
17
17
  var DenoDependencyManager = class {
18
18
  check() {
19
19
  const cwd = process.cwd();
@@ -34,10 +34,10 @@ var DenoDependencyManager = class {
34
34
  };
35
35
 
36
36
  // src/commands/dep/node.ts
37
- import path2, { join } from "path";
38
- import pc from "picocolors";
39
- import { readFile } from "fs/promises";
37
+ import { readFile } from "node:fs/promises";
38
+ import path2, { join } from "node:path";
40
39
  import { pathExists as pathExists2 } from "fs-extra";
40
+ import pc from "picocolors";
41
41
  var NodeDependencyManager = class {
42
42
  async check() {
43
43
  return pathExists2(path2.join(process.cwd(), "package.json"));
@@ -146,14 +146,13 @@ function getTypePackageName(pkg) {
146
146
  if (name.includes("@")) {
147
147
  const [scope, pkgName] = name.split("/");
148
148
  return `@types/${scope.slice(1)}__${pkgName}`;
149
- } else {
150
- return `@types/${name}`;
151
149
  }
150
+ return `@types/${name}`;
152
151
  }
153
152
 
154
153
  // src/commands/dep/rust.ts
154
+ import path3 from "node:path";
155
155
  import { pathExists as pathExists3 } from "fs-extra";
156
- import path3 from "path";
157
156
  var RustDependencyManager = class {
158
157
  check() {
159
158
  return pathExists3(path3.join(process.cwd(), "Cargo.toml"));
@@ -219,6 +218,8 @@ i/install [...modules], Install dependencies. ${installAction}
219
218
 
220
219
  up/upgrade [...modules], Upgrade dependencies. ${upgradeAction}
221
220
 
221
+ -L --latest @bool, upgrade to the latest version.
222
+
222
223
  rm/remove <...modules>, Remove dependencies. ${removeAction}
223
224
 
224
225
  -t --types @bool, remove package's type too, only take effect in node project.
@@ -246,8 +247,9 @@ async function removeAction(_, opt) {
246
247
  function getParameters(opt) {
247
248
  const params = opt._;
248
249
  const otherOpt = { ...opt };
249
- delete otherOpt._;
250
- delete otherOpt["--"];
250
+ otherOpt.L = void 0;
251
+ otherOpt._ = void 0;
252
+ otherOpt["--"] = void 0;
251
253
  return {
252
254
  params,
253
255
  options: otherOpt
package/dist/xr.js CHANGED
@@ -1,93 +1,93 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  exec
4
- } from "./chunk-WA6Z2RU3.js";
4
+ } from "./chunk-TTBHFDNB.js";
5
5
  import {
6
6
  version
7
- } from "./chunk-5L45XIBY.js";
7
+ } from "./chunk-ZU5F6V34.js";
8
8
 
9
9
  // src/xr.ts
10
10
  import { sliver } from "@0x-jerry/silver";
11
11
 
12
12
  // src/commands/run.ts
13
- import path4 from "path";
13
+ import path4 from "node:path";
14
14
  import pc from "picocolors";
15
15
 
16
- // src/commands/run/node.ts
16
+ // src/commands/run/deno.ts
17
+ import { readFile } from "node:fs/promises";
18
+ import path from "node:path";
17
19
  import { pathExists } from "fs-extra";
18
- import path from "path";
19
- import { readdir, readFile } from "fs/promises";
20
+ import { parse } from "jsonc-parser";
21
+ var DenoTaskDetecter = class {
22
+ check(cwd) {
23
+ return pathExists(path.join(cwd, "deno.json")) || pathExists(path.join(cwd, "deno.jsonc"));
24
+ }
25
+ async task(cwd, taskName) {
26
+ return (await this.tasks(cwd))[taskName];
27
+ }
28
+ async tasks(cwd) {
29
+ let tasks = {};
30
+ let denoConfigPath = path.join(cwd, "deno.json");
31
+ if (!await pathExists(denoConfigPath)) {
32
+ denoConfigPath = path.join(cwd, "deno.jsonc");
33
+ }
34
+ if (await pathExists(denoConfigPath)) {
35
+ const text = await readFile(denoConfigPath, "utf8");
36
+ const json = parse(text);
37
+ tasks = json.tasks || {};
38
+ }
39
+ return tasks;
40
+ }
41
+ };
42
+
43
+ // src/commands/run/node.ts
44
+ import { readFile as readFile2, readdir } from "node:fs/promises";
45
+ import path2 from "node:path";
46
+ import { pathExists as pathExists2 } from "fs-extra";
20
47
  var NodeTaskDetecter = class {
21
48
  async binaryPaths(cwd) {
22
49
  const envPaths = [];
23
50
  let dir = cwd;
24
51
  do {
25
- const binPath = path.join(dir, "node_modules", ".bin");
26
- if (await pathExists(binPath)) {
52
+ const binPath = path2.join(dir, "node_modules", ".bin");
53
+ if (await pathExists2(binPath)) {
27
54
  envPaths.push(binPath);
28
55
  }
29
- dir = path.resolve(dir, "..");
30
- } while (dir !== path.resolve(dir, ".."));
56
+ dir = path2.resolve(dir, "..");
57
+ } while (dir !== path2.resolve(dir, ".."));
31
58
  return envPaths;
32
59
  }
33
60
  check(cwd) {
34
- return pathExists(path.join(cwd, "package.json"));
61
+ return pathExists2(path2.join(cwd, "package.json"));
35
62
  }
36
63
  async task(cwd, taskName) {
37
64
  return (await this.tasks(cwd))[taskName];
38
65
  }
39
66
  async tasks(cwd) {
40
- const pkgPath = path.join(cwd, "package.json");
41
- const text = await readFile(pkgPath, "utf8");
67
+ const pkgPath = path2.join(cwd, "package.json");
68
+ const text = await readFile2(pkgPath, "utf8");
42
69
  const json = JSON.parse(text);
43
70
  const tasks = json.scripts || {};
44
71
  {
45
72
  let dir = cwd;
46
73
  do {
47
- const binPath = path.join(dir, "node_modules", ".bin");
48
- if (await pathExists(binPath)) {
74
+ const binPath = path2.join(dir, "node_modules", ".bin");
75
+ if (await pathExists2(binPath)) {
49
76
  const files = await readdir(binPath);
50
77
  for (const filename of files) {
51
78
  tasks[filename] ??= filename;
52
79
  }
53
80
  }
54
- dir = path.resolve(dir, "..");
55
- } while (dir !== path.resolve(dir, ".."));
56
- }
57
- return tasks;
58
- }
59
- };
60
-
61
- // src/commands/run/deno.ts
62
- import { parse } from "jsonc-parser";
63
- import { pathExists as pathExists2 } from "fs-extra";
64
- import path2 from "path";
65
- import { readFile as readFile2 } from "fs/promises";
66
- var DenoTaskDetecter = class {
67
- check(cwd) {
68
- return pathExists2(path2.join(cwd, "deno.json")) || pathExists2(path2.join(cwd, "deno.jsonc"));
69
- }
70
- async task(cwd, taskName) {
71
- return (await this.tasks(cwd))[taskName];
72
- }
73
- async tasks(cwd) {
74
- let tasks = {};
75
- let denoConfigPath = path2.join(cwd, "deno.json");
76
- if (!await pathExists2(denoConfigPath)) {
77
- denoConfigPath = path2.join(cwd, "deno.jsonc");
78
- }
79
- if (await pathExists2(denoConfigPath)) {
80
- const text = await readFile2(denoConfigPath, "utf8");
81
- const json = parse(text);
82
- tasks = json.tasks || {};
81
+ dir = path2.resolve(dir, "..");
82
+ } while (dir !== path2.resolve(dir, ".."));
83
83
  }
84
84
  return tasks;
85
85
  }
86
86
  };
87
87
 
88
88
  // src/commands/run/rust.ts
89
+ import path3 from "node:path";
89
90
  import { pathExists as pathExists3 } from "fs-extra";
90
- import path3 from "path";
91
91
  var RustTaskDetecter = class {
92
92
  check(cwd) {
93
93
  return pathExists3(path3.join(cwd, "Cargo.toml"));
package/package.json CHANGED
@@ -1,69 +1,70 @@
1
- {
2
- "name": "@0x-jerry/x",
3
- "version": "2.7.2",
4
- "repository": {
5
- "type": "git",
6
- "url": "git+https://github.com/0x-jerry/x.git"
7
- },
8
- "author": "Jerry Wang <x.jerry.wang@gmail.com>",
9
- "license": "MIT",
10
- "type": "module",
11
- "publishConfig": {
12
- "access": "public",
13
- "registry": "https://registry.npmjs.org"
14
- },
15
- "files": [
16
- "dist"
17
- ],
18
- "bin": {
19
- "xr": "dist/xr.js",
20
- "xn": "dist/xn.js",
21
- "x": "dist/x.js"
22
- },
23
- "scripts": {
24
- "build": "tsup",
25
- "dev:xr": "tsx src/xr.ts",
26
- "dev:xn": "tsx src/xn.ts",
27
- "dev:x": "tsx src/x.ts",
28
- "test": "vitest run",
29
- "test:watch": "vitest",
30
- "prepublishOnly": "npm run build",
31
- "release": "x-release"
32
- },
33
- "tsup": {
34
- "entry": [
35
- "src/xr.ts",
36
- "src/xn.ts",
37
- "src/x.ts"
38
- ],
39
- "format": [
40
- "esm"
41
- ],
42
- "clean": true
43
- },
44
- "dependencies": {
45
- "@0x-jerry/silver": "^1.0.3",
46
- "@0x-jerry/utils": "^2.4.3",
47
- "decompress": "^4.2.1",
48
- "fs-extra": "^11.2.0",
49
- "global-agent": "^3.0.0",
50
- "got": "^14.4.1",
51
- "jsonc-parser": "^3.3.1",
52
- "ora": "^8.0.1",
53
- "picocolors": "^1.0.1",
54
- "prompts": "^2.4.2"
55
- },
56
- "devDependencies": {
57
- "@0x-jerry/x-release": "^2.2.2",
58
- "@types/decompress": "^4.2.7",
59
- "@types/fs-extra": "^11.0.4",
60
- "@types/global-agent": "^2.1.3",
61
- "@types/node": "^20.14.11",
62
- "@types/prompts": "^2.4.9",
63
- "@vitest/coverage-v8": "^2.0.3",
64
- "tsup": "^8.2.0",
65
- "tsx": "^4.16.2",
66
- "typescript": "^5.5.3",
67
- "vitest": "^2.0.3"
68
- }
1
+ {
2
+ "name": "@0x-jerry/x",
3
+ "version": "2.7.3",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/0x-jerry/x.git"
7
+ },
8
+ "author": "Jerry Wang <x.jerry.wang@gmail.com>",
9
+ "license": "MIT",
10
+ "type": "module",
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "registry": "https://registry.npmjs.org"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "bin": {
19
+ "xr": "dist/xr.js",
20
+ "xn": "dist/xn.js",
21
+ "x": "dist/x.js"
22
+ },
23
+ "scripts": {
24
+ "build": "tsup",
25
+ "dev:xr": "tsx src/xr.ts",
26
+ "dev:xn": "tsx src/xn.ts",
27
+ "dev:x": "tsx src/x.ts",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest",
30
+ "prepublishOnly": "npm run build",
31
+ "release": "x-release"
32
+ },
33
+ "tsup": {
34
+ "entry": [
35
+ "src/xr.ts",
36
+ "src/xn.ts",
37
+ "src/x.ts"
38
+ ],
39
+ "format": [
40
+ "esm"
41
+ ],
42
+ "clean": true
43
+ },
44
+ "dependencies": {
45
+ "@0x-jerry/silver": "^1.1.1",
46
+ "@0x-jerry/utils": "^4.2.2",
47
+ "decompress": "^4.2.1",
48
+ "fs-extra": "^11.3.0",
49
+ "global-agent": "^3.0.0",
50
+ "got": "^14.4.5",
51
+ "jsonc-parser": "^3.3.1",
52
+ "ora": "^8.1.1",
53
+ "picocolors": "^1.1.1",
54
+ "prompts": "^2.4.2"
55
+ },
56
+ "devDependencies": {
57
+ "@0x-jerry/x-release": "^2.2.2",
58
+ "@biomejs/biome": "^1.9.4",
59
+ "@types/decompress": "^4.2.7",
60
+ "@types/fs-extra": "^11.0.4",
61
+ "@types/global-agent": "^2.1.3",
62
+ "@types/node": "^22.10.10",
63
+ "@types/prompts": "^2.4.9",
64
+ "@vitest/coverage-v8": "^3.0.4",
65
+ "tsup": "^8.3.6",
66
+ "tsx": "^4.19.2",
67
+ "typescript": "^5.7.3",
68
+ "vitest": "^3.0.4"
69
+ }
69
70
  }
package/readme.md CHANGED
@@ -1,94 +1,94 @@
1
- # X
2
-
3
- Some useful command for myself.
4
-
5
- ## Install
6
-
7
- ```sh
8
- pnpm i -g @0x-jerry/x
9
- ```
10
-
11
- ## Run task `xr`
12
-
13
- `xr` command can auto detect tasks in `package.json/scripts`, `deno.json/tasks`, and run it. you can also append any parameters.
14
-
15
- Example: In a node project with `pnpm-lock.yaml`. And `package.json` has a script `"test": "vitest run"`
16
-
17
- ```sh
18
- xr test test/*.ts
19
- # equals
20
- vitest run test/*.ts
21
-
22
- # you can also execute binary file in `node_modules/.bin` folder.
23
- xr vite --port 4004
24
- ```
25
-
26
- Example: In a deno project with `deno.json` or `deno.jsonc`. And have a task `"dev": "deno run -A main.ts"`
27
-
28
- ```sh
29
- xr dev
30
- # equals
31
- deno run -A main.ts
32
- ```
33
-
34
- ## Dependency Manager `xn`
35
-
36
- `xn` command can install modules by detect the correct tool, it detects lockfile to decide which dependency manager tools should be used.
37
-
38
- Example: install packages in a node project with `pnpm-lock.yaml`
39
-
40
- ```sh
41
- xn i lodash-es
42
- # equals
43
- pnpm i lodash-es
44
-
45
- xn i lodash-es -D
46
- # equals
47
- pnpm i lodash-es -D
48
-
49
- # -t/--types option support install @types/xx package in one command.
50
- xn i lodash-es --types
51
- # equals
52
- pnpm i lodash-es && pnpm i @types/lodash-es -D
53
- ```
54
-
55
- Example: remove packages in a node project with `pnpm-lock.yaml`
56
-
57
- ```sh
58
- xn rm lodash-es
59
- # equals
60
- pnpm uninstall lodash-es
61
-
62
- xn rm lodash-es -D
63
- # equals
64
- pnpm uninstall lodash-es -D
65
-
66
- # -t/--types option support remove @types/xx package in one command.
67
- xn rm lodash-es --types
68
- # equals
69
- pnpm uninstall lodash-es @types/lodash-es
70
- ```
71
-
72
- `xn` also support rust project.
73
-
74
- Example: in a rust project with `Cargo.toml`
75
-
76
- ```sh
77
- xn i log
78
- # equals
79
- cargo add log
80
-
81
- xn rm log
82
- # equals
83
- cargo remove log
84
- ```
85
-
86
- ## Command Completions
87
-
88
- Add this code to `~/.zshrc`
89
-
90
- ```zsh
91
- source <(x completions)
92
- source <(xr completions)
93
- source <(xn completions)
94
- ```
1
+ # X
2
+
3
+ Some useful command for myself.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm i -g @0x-jerry/x
9
+ ```
10
+
11
+ ## Run task `xr`
12
+
13
+ `xr` command can auto detect tasks in `package.json/scripts`, `deno.json/tasks`, and run it. you can also append any parameters.
14
+
15
+ Example: In a node project with `pnpm-lock.yaml`. And `package.json` has a script `"test": "vitest run"`
16
+
17
+ ```sh
18
+ xr test test/*.ts
19
+ # equals
20
+ vitest run test/*.ts
21
+
22
+ # you can also execute binary file in `node_modules/.bin` folder.
23
+ xr vite --port 4004
24
+ ```
25
+
26
+ Example: In a deno project with `deno.json` or `deno.jsonc`. And have a task `"dev": "deno run -A main.ts"`
27
+
28
+ ```sh
29
+ xr dev
30
+ # equals
31
+ deno run -A main.ts
32
+ ```
33
+
34
+ ## Dependency Manager `xn`
35
+
36
+ `xn` command can install modules by detect the correct tool, it detects lockfile to decide which dependency manager tools should be used.
37
+
38
+ Example: install packages in a node project with `pnpm-lock.yaml`
39
+
40
+ ```sh
41
+ xn i lodash-es
42
+ # equals
43
+ pnpm i lodash-es
44
+
45
+ xn i lodash-es -D
46
+ # equals
47
+ pnpm i lodash-es -D
48
+
49
+ # -t/--types option support install @types/xx package in one command.
50
+ xn i lodash-es --types
51
+ # equals
52
+ pnpm i lodash-es && pnpm i @types/lodash-es -D
53
+ ```
54
+
55
+ Example: remove packages in a node project with `pnpm-lock.yaml`
56
+
57
+ ```sh
58
+ xn rm lodash-es
59
+ # equals
60
+ pnpm uninstall lodash-es
61
+
62
+ xn rm lodash-es -D
63
+ # equals
64
+ pnpm uninstall lodash-es -D
65
+
66
+ # -t/--types option support remove @types/xx package in one command.
67
+ xn rm lodash-es --types
68
+ # equals
69
+ pnpm uninstall lodash-es @types/lodash-es
70
+ ```
71
+
72
+ `xn` also support rust project.
73
+
74
+ Example: in a rust project with `Cargo.toml`
75
+
76
+ ```sh
77
+ xn i log
78
+ # equals
79
+ cargo add log
80
+
81
+ xn rm log
82
+ # equals
83
+ cargo remove log
84
+ ```
85
+
86
+ ## Command Completions
87
+
88
+ Add this code to `~/.zshrc`
89
+
90
+ ```zsh
91
+ source <(x completions)
92
+ source <(xr completions)
93
+ source <(xn completions)
94
+ ```