@0x-jerry/x 2.12.6 → 2.12.7

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.12.6";
2
+ var version = "2.12.7";
3
3
 
4
4
  export {
5
5
  version
@@ -0,0 +1,81 @@
1
+ // src/utils.ts
2
+ import { existsSync } from "fs";
3
+ import { exec as _exec } from "@0x-jerry/utils/node";
4
+ async function exec(script, params, opt) {
5
+ const cmd = [script, ...params].join(" ");
6
+ await _exec(cmd, opt);
7
+ }
8
+ function exists(path2) {
9
+ return existsSync(path2);
10
+ }
11
+ function flagOptionToStringArray(opt) {
12
+ return Object.entries(opt).flatMap(([_key, value]) => {
13
+ const key = (_key.length === 1 ? "-" : "--") + _key;
14
+ if (typeof value === "string" || typeof value === "number") {
15
+ return [key, String(value)];
16
+ }
17
+ return [key];
18
+ });
19
+ }
20
+
21
+ // src/commands/utils/node.ts
22
+ import { readFile } from "fs/promises";
23
+ import path from "path";
24
+ async function detectPackageRoot(cwd, subProjectInfo) {
25
+ const pkg = await getPkgJson(cwd);
26
+ if (!pkg) {
27
+ return detectParentDir(subProjectInfo);
28
+ }
29
+ const pm = await detectPkgManagerCommand(cwd);
30
+ const info = {
31
+ pkgDir: cwd,
32
+ package: pkg,
33
+ pm,
34
+ subProject: subProjectInfo
35
+ };
36
+ if (pm) {
37
+ return info;
38
+ }
39
+ return detectParentDir(info);
40
+ async function detectParentDir(subProjectInfo2) {
41
+ const parentDir = path.dirname(cwd);
42
+ if (parentDir === cwd) {
43
+ return subProjectInfo2 ?? null;
44
+ }
45
+ return detectPackageRoot(parentDir, subProjectInfo2);
46
+ }
47
+ }
48
+ async function detectPkgManagerCommand(cwd = process.cwd()) {
49
+ const pnpmLockFile = path.join(cwd, "pnpm-lock.yaml");
50
+ if (exists(pnpmLockFile)) {
51
+ return "pnpm";
52
+ }
53
+ const bunLockFile = path.join(cwd, "bun.lock");
54
+ if (exists(bunLockFile)) {
55
+ return "bun";
56
+ }
57
+ const yarnLockFile = path.join(cwd, "yarn.lock");
58
+ if (exists(yarnLockFile)) {
59
+ return "yarn";
60
+ }
61
+ const jsonLockFile = path.join(cwd, "package-lock.json");
62
+ if (exists(jsonLockFile)) {
63
+ return "npm";
64
+ }
65
+ return null;
66
+ }
67
+ async function getPkgJson(cwd = process.cwd()) {
68
+ const jsonFile = path.join(cwd, "package.json");
69
+ try {
70
+ const txt = await readFile(jsonFile, { encoding: "utf-8" });
71
+ return JSON.parse(txt);
72
+ } catch (_error) {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ export {
78
+ exec,
79
+ flagOptionToStringArray,
80
+ detectPackageRoot
81
+ };
package/dist/x.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  version
4
- } from "./chunk-WWG7Y7EF.js";
4
+ } from "./chunk-LBTVWMZC.js";
5
5
 
6
6
  // src/x.ts
7
7
  import { sliver } from "@0x-jerry/silver";
package/dist/xn.js CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ detectPackageRoot,
3
4
  exec,
4
- exists,
5
5
  flagOptionToStringArray
6
- } from "./chunk-ELIYGHQS.js";
6
+ } from "./chunk-RDZVDWJQ.js";
7
7
  import {
8
8
  version
9
- } from "./chunk-WWG7Y7EF.js";
9
+ } from "./chunk-LBTVWMZC.js";
10
10
 
11
11
  // src/xn.ts
12
12
  import { sliver } from "@0x-jerry/silver";
@@ -34,13 +34,12 @@ var DenoDependencyManager = class {
34
34
  };
35
35
 
36
36
  // src/commands/dep/node.ts
37
- import { readFile } from "fs/promises";
38
- import path2, { join } from "path";
39
- import { pathExists as pathExists2 } from "fs-extra";
40
37
  import pc from "picocolors";
41
38
  var NodeDependencyManager = class {
42
39
  async check() {
43
- return pathExists2(path2.join(process.cwd(), "package.json"));
40
+ const cwd = process.cwd();
41
+ const pkgInfo = await detectPackageRoot(cwd);
42
+ return !!pkgInfo;
44
43
  }
45
44
  async install(option) {
46
45
  await runDepManagerCommand("install");
@@ -100,7 +99,9 @@ var depInstallerCommandMapper = {
100
99
  }
101
100
  };
102
101
  async function runDepManagerCommand(action, ...params) {
103
- if (!await getPkgJson()) {
102
+ const cwd = process.cwd();
103
+ const pkgInfo = await detectPackageRoot(cwd);
104
+ if (!pkgInfo) {
104
105
  console.log(
105
106
  yellow(
106
107
  `Can't find package.json! Please ensure that current path is a node project.`
@@ -108,37 +109,9 @@ async function runDepManagerCommand(action, ...params) {
108
109
  );
109
110
  return;
110
111
  }
111
- const depInstallerCommand = await detectPkgManagerCommand();
112
- const actionName = depInstallerCommandMapper[action][depInstallerCommand];
113
- await exec(depInstallerCommand, [actionName, ...params]);
114
- }
115
- async function detectPkgManagerCommand(cwd = process.cwd()) {
116
- const pnpmLockFile = join(cwd, "pnpm-lock.yaml");
117
- if (exists(pnpmLockFile)) {
118
- return "pnpm";
119
- }
120
- const bunLockFile = join(cwd, "bun.lock");
121
- if (exists(bunLockFile)) {
122
- return "bun";
123
- }
124
- const yarnLockFile = join(cwd, "yarn.lock");
125
- if (exists(yarnLockFile)) {
126
- return "yarn";
127
- }
128
- const jsonLockFile = join(cwd, "package-lock.json");
129
- if (exists(jsonLockFile)) {
130
- return "npm";
131
- }
132
- return "pnpm";
133
- }
134
- async function getPkgJson(cwd = process.cwd()) {
135
- const jsonFile = join(cwd, "package.json");
136
- try {
137
- const txt = await readFile(jsonFile, { encoding: "utf-8" });
138
- return JSON.parse(txt);
139
- } catch (_error) {
140
- return false;
141
- }
112
+ const pm = pkgInfo.pm || "pnpm";
113
+ const actionName = depInstallerCommandMapper[action][pm];
114
+ await exec(pm, [actionName, ...params]);
142
115
  }
143
116
  function getTypePackageName(pkg) {
144
117
  const idx = pkg.lastIndexOf("@");
@@ -151,11 +124,11 @@ function getTypePackageName(pkg) {
151
124
  }
152
125
 
153
126
  // src/commands/dep/rust.ts
154
- import path3 from "path";
155
- import { pathExists as pathExists3 } from "fs-extra";
127
+ import path2 from "path";
128
+ import { pathExists as pathExists2 } from "fs-extra";
156
129
  var RustDependencyManager = class {
157
130
  check() {
158
- return pathExists3(path3.join(process.cwd(), "Cargo.toml"));
131
+ return pathExists2(path2.join(process.cwd(), "Cargo.toml"));
159
132
  }
160
133
  async install(option) {
161
134
  await exec("cargo", ["check"]);
package/dist/xr.js CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ detectPackageRoot,
3
4
  exec
4
- } from "./chunk-ELIYGHQS.js";
5
+ } from "./chunk-RDZVDWJQ.js";
5
6
  import {
6
7
  version
7
- } from "./chunk-WWG7Y7EF.js";
8
+ } from "./chunk-LBTVWMZC.js";
8
9
 
9
10
  // src/xr.ts
10
11
  import { sliver } from "@0x-jerry/silver";
@@ -19,8 +20,9 @@ import path from "path";
19
20
  import { pathExists } from "fs-extra";
20
21
  import { parse } from "jsonc-parser";
21
22
  var DenoTaskDetecter = class {
22
- check(cwd) {
23
- return pathExists(path.join(cwd, "deno.json")) || pathExists(path.join(cwd, "deno.jsonc"));
23
+ async check(cwd) {
24
+ const has = await (pathExists(path.join(cwd, "deno.json")) || pathExists(path.join(cwd, "deno.jsonc")));
25
+ return has ? cwd : void 0;
24
26
  }
25
27
  async task(cwd, taskName) {
26
28
  return (await this.tasks(cwd))[taskName];
@@ -41,7 +43,7 @@ var DenoTaskDetecter = class {
41
43
  };
42
44
 
43
45
  // src/commands/run/node.ts
44
- import { readdir, readFile as readFile2 } from "fs/promises";
46
+ import { readdir } from "fs/promises";
45
47
  import path2 from "path";
46
48
  import { pathExists as pathExists2 } from "fs-extra/esm";
47
49
  var NodeTaskDetecter = class {
@@ -57,17 +59,16 @@ var NodeTaskDetecter = class {
57
59
  } while (dir !== path2.resolve(dir, ".."));
58
60
  return envPaths;
59
61
  }
60
- check(cwd) {
61
- return pathExists2(path2.join(cwd, "package.json"));
62
+ async check(cwd) {
63
+ const pkgInfo = await detectPackageRoot(cwd);
64
+ return pkgInfo?.pkgDir;
62
65
  }
63
66
  async task(cwd, taskName) {
64
67
  return (await this.tasks(cwd))[taskName];
65
68
  }
66
69
  async tasks(cwd) {
67
- const pkgPath = path2.join(cwd, "package.json");
68
- const text = await readFile2(pkgPath, "utf8");
69
- const json = JSON.parse(text);
70
- const tasks = json.scripts || {};
70
+ const pkgInfo = await detectPackageRoot(cwd);
71
+ const tasks = pkgInfo?.package.scripts || {};
71
72
  return tasks;
72
73
  }
73
74
  };
@@ -91,8 +92,8 @@ async function getBinariesPairs() {
91
92
  import path3 from "path";
92
93
  import { pathExists as pathExists3 } from "fs-extra";
93
94
  var RustTaskDetecter = class {
94
- check(cwd) {
95
- return pathExists3(path3.join(cwd, "Cargo.toml"));
95
+ async check(cwd) {
96
+ return await pathExists3(path3.join(cwd, "Cargo.toml")) ? cwd : void 0;
96
97
  }
97
98
  async task(_cwd, _taskName) {
98
99
  return "cargo run";
@@ -106,13 +107,14 @@ async function runScript(command, params = []) {
106
107
  new DenoTaskDetecter(),
107
108
  new RustTaskDetecter()
108
109
  ];
109
- const cwd = process.cwd();
110
+ let cwd = process.cwd();
110
111
  for (const taskDetector of taskDetectors) {
111
- if (await taskDetector.check(cwd)) {
112
- const task = await taskDetector.task(cwd, command);
112
+ const workspaceDir = await taskDetector.check(cwd);
113
+ if (workspaceDir) {
114
+ const task = await taskDetector.task(workspaceDir, command);
113
115
  if (task) {
114
- const env = makeEnv(await taskDetector.binaryPaths?.(cwd) || []);
115
- await exec(task, params, { env });
116
+ const env = makeEnv(await taskDetector.binaryPaths?.(workspaceDir) || []);
117
+ await exec(task, params, { env, cwd: workspaceDir });
116
118
  return;
117
119
  }
118
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0x-jerry/x",
3
- "version": "2.12.6",
3
+ "version": "2.12.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/0x-jerry/x.git"
@@ -1,25 +0,0 @@
1
- // src/utils.ts
2
- import { existsSync } from "fs";
3
- import { exec as _exec } from "@0x-jerry/utils/node";
4
- async function exec(script, params, opt) {
5
- const cmd = [script, ...params].join(" ");
6
- await _exec(cmd, opt);
7
- }
8
- function exists(path) {
9
- return existsSync(path);
10
- }
11
- function flagOptionToStringArray(opt) {
12
- return Object.entries(opt).flatMap(([_key, value]) => {
13
- const key = (_key.length === 1 ? "-" : "--") + _key;
14
- if (typeof value === "string" || typeof value === "number") {
15
- return [key, String(value)];
16
- }
17
- return [key];
18
- });
19
- }
20
-
21
- export {
22
- exec,
23
- exists,
24
- flagOptionToStringArray
25
- };