@simon_he/pi 0.1.19 → 0.1.21

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/index.cjs CHANGED
@@ -1,770 +1,762 @@
1
- "use strict";
1
+ //#region rolldown:runtime
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
8
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
19
21
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- setup: () => setup
34
- });
35
- module.exports = __toCommonJS(index_exports);
36
- var import_node_path2 = __toESM(require("path"), 1);
37
- var import_node_process9 = __toESM(require("process"), 1);
38
- var import_ccommand3 = require("ccommand");
39
- var import_fast_glob = __toESM(require("fast-glob"), 1);
40
- var import_lazy_js_utils2 = require("lazy-js-utils");
41
- var import_node13 = require("lazy-js-utils/node");
42
- var import_picocolors8 = __toESM(require("picocolors"), 1);
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
43
26
 
44
- // src/help.ts
45
- var import_node_process = __toESM(require("process"), 1);
46
- var import_node = require("lazy-js-utils/node");
27
+ //#endregion
28
+ let node_path = require("node:path");
29
+ node_path = __toESM(node_path);
30
+ let node_process = require("node:process");
31
+ node_process = __toESM(node_process);
32
+ let fast_glob = require("fast-glob");
33
+ fast_glob = __toESM(fast_glob);
34
+ let lazy_js_utils = require("lazy-js-utils");
35
+ let lazy_js_utils_node = require("lazy-js-utils/node");
36
+ let picocolors = require("picocolors");
37
+ picocolors = __toESM(picocolors);
38
+ let node_console = require("node:console");
39
+ let node_fs = require("node:fs");
40
+ node_fs = __toESM(node_fs);
41
+ let node_os = require("node:os");
42
+ node_os = __toESM(node_os);
43
+ let node_module = require("node:module");
47
44
 
48
- // package.json
49
- var version = "0.1.19";
45
+ //#region package.json
46
+ var version = "0.1.21";
50
47
 
51
- // src/help.ts
52
- var isZh = import_node_process.default.env.PI_Lang === "zh";
53
- async function help(argv) {
54
- const arg = argv[0];
55
- if (arg === "-v" || arg === "--version") {
56
- await (0, import_node.jsShell)(
57
- isZh ? `gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" "pi \u7248\u672C: ${version}" "\u8BF7\u4E3A\u6211\u7684\u52AA\u529B\u70B9\u4E00\u4E2A\u884C \u{1F31F}" "\u8C22\u8C22 \u{1F91F}"` : `gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" "pi version: ${version}" "Please give me a \u{1F31F} for my efforts" "Thank you \u{1F91F}"`,
58
- "inherit"
59
- );
60
- import_node_process.default.exit(0);
61
- } else if (arg === "-h" || arg === "--help") {
62
- await (0, import_node.jsShell)(
63
- `gum style --foreground 212 --border-foreground 212 --border double --align left --width 50 --margin "1 2" --padding "1 1" "PI Commands:" "~ pi: install package" "~ pix: npx package" "~ pui: uninstall package" "~ prun: run package script" "~ pinit: package init" "~ pbuild: go build | cargo build" "~ pfind: find monorepo of yarn or pnpm" "~ pa: agent alias" "~ pu: package upgrade" "~ pci: package clean install" "~ pil: package latest install"
64
- `,
65
- "inherit"
66
- );
67
- import_node_process.default.exit(0);
68
- }
48
+ //#endregion
49
+ //#region src/installDeps.ts
50
+ const isZh$6 = node_process.default.env.PI_Lang === "zh";
51
+ const gumDocUrl = "https://github.com/charmbracelet/gum";
52
+ const niDocUrl = "https://github.com/antfu/ni";
53
+ async function installDeps(options = {}) {
54
+ const { gum = true, ni = true, strict = true } = options;
55
+ const platform = node_process.default.platform;
56
+ if (gum && !await (0, lazy_js_utils_node.isInstallPkg)("gum")) if (platform === "darwin") {
57
+ console.log(picocolors.default.cyan(isZh$6 ? "正在为您安装必要的依赖gum..." : "Installing gum..."));
58
+ const { status } = await (0, lazy_js_utils_node.jsShell)("brew install gum", [
59
+ "inherit",
60
+ "pipe",
61
+ "inherit"
62
+ ]);
63
+ if (status === 0) console.log(picocolors.default.cyan(isZh$6 ? "gum 安装成功!" : "gum installed successfully!"));
64
+ else {
65
+ console.log(picocolors.default.red(isZh$6 ? `gum 安装失败,请尝试从官网解决安装问题! ${gumDocUrl}` : `gum installation failed, please try manual install: ${gumDocUrl}`));
66
+ if (strict) node_process.default.exit(1);
67
+ }
68
+ } else console.log(picocolors.default.yellow(isZh$6 ? `未检测到 gum,请根据系统手动安装: ${gumDocUrl}` : `gum not found, please install it manually: ${gumDocUrl}`));
69
+ if (ni && !await (0, lazy_js_utils_node.isInstallPkg)("ni")) {
70
+ console.log(picocolors.default.cyan(isZh$6 ? "正在为您安装必要的依赖ni..." : "Installing ni..."));
71
+ const { status } = await (0, lazy_js_utils_node.jsShell)("npm i -g @antfu/ni", [
72
+ "inherit",
73
+ "pipe",
74
+ "inherit"
75
+ ]);
76
+ if (status === 0) console.log(picocolors.default.cyan(isZh$6 ? "ni 安装成功!" : "ni installed successfully!"));
77
+ else {
78
+ console.log(picocolors.default.red(isZh$6 ? `ni 安装失败,请尝试从官网解决安装问题! ${niDocUrl}` : `ni installation failed, please try manual install: ${niDocUrl}`));
79
+ if (strict) node_process.default.exit(1);
80
+ }
81
+ }
69
82
  }
70
83
 
71
- // src/installDeps.ts
72
- var import_node_process2 = __toESM(require("process"), 1);
73
- var import_node2 = require("lazy-js-utils/node");
74
- var import_picocolors = __toESM(require("picocolors"), 1);
75
- async function installDeps() {
76
- if (!await (0, import_node2.isInstallPkg)("gum")) {
77
- console.log(import_picocolors.default.cyan("\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5\u5FC5\u8981\u7684\u4F9D\u8D56gum..."));
78
- const { status } = await (0, import_node2.jsShell)("brew install gum", [
79
- "inherit",
80
- "pipe",
81
- "inherit"
82
- ]);
83
- if (status === 0) {
84
- console.log(import_picocolors.default.cyan("gum \u5B89\u88C5\u6210\u529F!"));
85
- } else {
86
- console.log(
87
- import_picocolors.default.red(
88
- "gum \u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u4ECE\u5B98\u7F51\u89E3\u51B3\u5B89\u88C5\u95EE\u9898! https://github.com/charmbracelet/gum"
89
- )
90
- );
91
- import_node_process2.default.exit(1);
92
- }
93
- }
94
- if (!await (0, import_node2.isInstallPkg)("ni")) {
95
- console.log(import_picocolors.default.cyan("\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5\u5FC5\u8981\u7684\u4F9D\u8D56ni..."));
96
- const { status } = await (0, import_node2.jsShell)("npm i -g @antfu/ni", [
97
- "inherit",
98
- "pipe",
99
- "inherit"
100
- ]);
101
- if (status === 0) {
102
- console.log(import_picocolors.default.cyan("ni \u5B89\u88C5\u6210\u529F!"));
103
- } else {
104
- console.log(
105
- import_picocolors.default.red(
106
- "ni \u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u4ECE\u5B98\u7F51\u89E3\u51B3\u5B89\u88C5\u95EE\u9898! https://github.com/antfu/ni"
107
- )
108
- );
109
- import_node_process2.default.exit(1);
110
- }
111
- }
84
+ //#endregion
85
+ //#region src/help.ts
86
+ const isZh$5 = node_process.default.env.PI_Lang === "zh";
87
+ async function ensureGum() {
88
+ if (await (0, lazy_js_utils_node.isInstallPkg)("gum")) return true;
89
+ await installDeps({
90
+ gum: true,
91
+ ni: false,
92
+ strict: false
93
+ });
94
+ return await (0, lazy_js_utils_node.isInstallPkg)("gum");
95
+ }
96
+ function printPlainVersion() {
97
+ console.log(isZh$5 ? `pi 版本: ${version}` : `pi version: ${version}`);
98
+ console.log(isZh$5 ? "请为我的努力点一个行 🌟" : "Please give me a 🌟 for my efforts");
99
+ console.log(isZh$5 ? "谢谢 🤟" : "Thank you 🤟");
100
+ }
101
+ function printPlainHelp() {
102
+ console.log([
103
+ "PI Commands:",
104
+ "~ pi: install package",
105
+ "~ pix: npx package",
106
+ "~ pui: uninstall package",
107
+ "~ prun: run package script",
108
+ "~ pinit: package init",
109
+ "~ pbuild: go build | cargo build",
110
+ "~ pfind: find monorepo of yarn or pnpm",
111
+ "~ pa: agent alias",
112
+ "~ pu: package upgrade",
113
+ "~ pci: package clean install",
114
+ "~ pil: package latest install"
115
+ ].join("\n"));
116
+ }
117
+ async function help(argv) {
118
+ const arg = argv[0];
119
+ if (arg === "-v" || arg === "--version") {
120
+ if (await ensureGum()) await (0, lazy_js_utils_node.jsShell)(isZh$5 ? `gum style \
121
+ --foreground 212 --border-foreground 212 --border double \
122
+ --align center --width 50 --margin "1 2" --padding "2 4" \
123
+ "pi 版本: ${version}" "请为我的努力点一个行 🌟" "谢谢 🤟"` : `gum style \
124
+ --foreground 212 --border-foreground 212 --border double \
125
+ --align center --width 50 --margin "1 2" --padding "2 4" \
126
+ "pi version: ${version}" "Please give me a 🌟 for my efforts" "Thank you 🤟"`, "inherit");
127
+ else printPlainVersion();
128
+ node_process.default.exit(0);
129
+ } else if (arg === "-h" || arg === "--help") {
130
+ if (await ensureGum()) await (0, lazy_js_utils_node.jsShell)(`gum style \
131
+ --foreground 212 --border-foreground 212 --border double \
132
+ --align left --width 50 --margin "1 2" --padding "1 1" \
133
+ "PI Commands:" "~ pi: install package" "~ pix: npx package" "~ pui: uninstall package" "~ prun: run package script" "~ pinit: package init" "~ pbuild: go build | cargo build" "~ pfind: find monorepo of yarn or pnpm" "~ pa: agent alias" "~ pu: package upgrade" "~ pci: package clean install" "~ pil: package latest install"
134
+ `, "inherit");
135
+ else printPlainHelp();
136
+ node_process.default.exit(0);
137
+ }
112
138
  }
113
139
 
114
- // src/pa.ts
115
- var import_node3 = require("lazy-js-utils/node");
140
+ //#endregion
141
+ //#region src/pa.ts
116
142
  function pa() {
117
- return (0, import_node3.jsShell)("na");
143
+ return (0, lazy_js_utils_node.jsShell)("na");
118
144
  }
119
145
 
120
- // src/pi.ts
121
- var import_node_console = require("console");
122
- var import_node_process5 = __toESM(require("process"), 1);
123
- var import_node6 = require("lazy-js-utils/node");
124
- var import_picocolors4 = __toESM(require("picocolors"), 1);
125
-
126
- // src/detectNode.ts
127
- var import_node_process3 = __toESM(require("process"), 1);
128
- var import_node4 = require("lazy-js-utils/node");
129
- var import_picocolors2 = __toESM(require("picocolors"), 1);
146
+ //#endregion
147
+ //#region src/detectNode.ts
148
+ const isZh$4 = node_process.default.env.PI_Lang === "zh";
130
149
  async function detectNode() {
131
- let pkg;
132
- try {
133
- pkg = await (0, import_node4.getPkg)();
134
- } catch {
135
- const cwd = import_node_process3.default.cwd();
136
- console.log(import_picocolors2.default.red(`\u5F53\u524D\u76EE\u5F55: ${cwd} \u6CA1\u6709package.json\u6587\u4EF6`));
137
- import_node_process3.default.exit(1);
138
- }
139
- if (pkg.engines?.node) {
140
- const isSafe = require("semver").satisfies(
141
- import_node_process3.default.version,
142
- pkg.engines.node
143
- );
144
- if (!isSafe) {
145
- const { result, status } = await (0, import_node4.jsShell)(
146
- `echo "yes
147
- no" | gum filter --placeholder=" \u5F53\u524Dnode\u7248\u672C\u4E0D\u6EE1\u8DB3 ${pkg.engines.node}\uFF0C\u662F\u5426\u5207\u6362node\u7248\u672C"`,
148
- ["inherit", "pipe", "inherit"]
149
- );
150
- if (status === 0 && result === "yes") {
151
- await (0, import_node4.jsShell)(
152
- `
150
+ let pkg;
151
+ try {
152
+ pkg = await (0, lazy_js_utils_node.getPkg)();
153
+ } catch {
154
+ const cwd = node_process.default.cwd();
155
+ console.log(picocolors.default.red(`当前目录: ${cwd} 没有package.json文件`));
156
+ node_process.default.exit(1);
157
+ }
158
+ if (pkg.engines?.node) {
159
+ const semver = await import("semver");
160
+ const satisfies = semver.satisfies || semver.default?.satisfies;
161
+ if (!satisfies) return;
162
+ if (!satisfies(node_process.default.version, pkg.engines.node)) {
163
+ const hasGum = await (0, lazy_js_utils_node.isInstallPkg)("gum");
164
+ const hasFnm = await (0, lazy_js_utils_node.isInstallPkg)("fnm");
165
+ if (!hasGum || !hasFnm) {
166
+ const missing = [!hasGum ? "gum" : "", !hasFnm ? "fnm" : ""].filter(Boolean).join(", ");
167
+ console.log(picocolors.default.yellow(isZh$4 ? `当前 node 版本不满足 ${pkg.engines.node},未检测到 ${missing},请手动切换版本。` : `Current Node version does not satisfy ${pkg.engines.node}. Missing ${missing}. Please switch manually.`));
168
+ return;
169
+ }
170
+ const { result, status } = await (0, lazy_js_utils_node.jsShell)(`echo "yes\nno" | gum filter --placeholder=" 当前node版本不满足 ${pkg.engines.node},是否切换node版本"`, [
171
+ "inherit",
172
+ "pipe",
173
+ "inherit"
174
+ ]);
175
+ if (status === 0 && result === "yes") await (0, lazy_js_utils_node.jsShell)(`
153
176
  current=$(echo $(fnm current))
154
- registery=$(echo "$(fnm ls)" | sed 's/system//g' | sed 's/default//g' | sed 's/* //g' | sed "s/$current/* $current/g" | gum filter --placeholder=" \u8BF7\u9009\u62E9\u4E00\u4E2Anode\u7248\u672C")
155
- registery=$(echo \${registery// /} | sed 's/*//g')
177
+ registery=$(echo "$(fnm ls)" | sed 's/system//g' | sed 's/default//g' | sed 's/\* //g' | sed "s/$current/\* $current/g" | gum filter --placeholder=" 请选择一个node版本")
178
+ registery=$(echo $\{registery// /} | sed 's/\*//g')
156
179
  if [ $registery ]; then
157
- fnm use \${registery% -*}
180
+ fnm use $\{registery% -*}
158
181
  fi
159
- `,
160
- ["inherit", "pipe", "inherit"]
161
- );
162
- }
163
- }
164
- }
182
+ `, [
183
+ "inherit",
184
+ "pipe",
185
+ "inherit"
186
+ ]);
187
+ }
188
+ }
165
189
  }
166
190
 
167
- // src/utils.ts
168
- var import_node_path = __toESM(require("path"), 1);
169
- var import_node_process4 = __toESM(require("process"), 1);
170
- var import_lazy_js_utils = require("lazy-js-utils");
171
- var import_node5 = require("lazy-js-utils/node");
172
- var import_picocolors3 = __toESM(require("picocolors"), 1);
173
- var DW = /\s-DW/g;
174
- var W = /\s-W/g;
175
- var Dw = /\s-Dw/g;
176
- var w = /\s-w/g;
177
- var D = /\s-D(?!w)/g;
178
- var d = /\s-d(?!w)/g;
179
- var isZh2 = import_node_process4.default.env.PI_Lang === "zh";
191
+ //#endregion
192
+ //#region src/utils.ts
193
+ const DW = /\s-DW/g;
194
+ const W = /\s-W/g;
195
+ const Dw = /\s-Dw/g;
196
+ const w = /\s-w/g;
197
+ const D = /\s-D(?!w)/g;
198
+ const d = /\s-d(?!w)/g;
199
+ const isZh$3 = node_process.default.env.PI_Lang === "zh";
200
+ const log$1 = console.log;
180
201
  async function getParams(params) {
181
- const root = import_node_process4.default.cwd();
182
- try {
183
- switch (await (0, import_node5.getPkgTool)()) {
184
- case "pnpm":
185
- if (!(0, import_lazy_js_utils.isFile)(import_node_path.default.resolve(root, "./pnpm-workspace.yaml"))) {
186
- if (DW.test(params))
187
- return params.replace(DW, " -D");
188
- if (Dw.test(params))
189
- return params.replace(Dw, " -D");
190
- if (W.test(params))
191
- return params.replace(W, "");
192
- if (w.test(params))
193
- return params.replace(w, "");
194
- if (d.test(params))
195
- return params.replace(d, " -D");
196
- }
197
- if ((0, import_lazy_js_utils.isFile)("./pnpm-workspace.yaml")) {
198
- if (D.test(params))
199
- return params.replace(D, " -Dw");
200
- if (d.test(params))
201
- return params.replace(d, " -Dw");
202
- if (!params || Dw.test(params) || w.test(params))
203
- return params;
204
- return `${params} -w`;
205
- }
206
- if (DW.test(params))
207
- return params.replace(DW, " -Dw");
208
- if (W.test(params))
209
- return params.replace(W, " -w");
210
- return params;
211
- case "yarn":
212
- if (!(await (0, import_node5.getPkg)(import_node_path.default.resolve(root, "./package.json")))?.workspaces) {
213
- if (Dw.test(params))
214
- return params.replace(Dw, " -D");
215
- if (DW.test(params))
216
- return params.replace(DW, " -D");
217
- if (W.test(params))
218
- return params.replace(W, "");
219
- if (w.test(params))
220
- return params.replace(w, "");
221
- if (d.test(params))
222
- return params.replace(d, " -D");
223
- }
224
- if ((await (0, import_node5.getPkg)())?.workspaces) {
225
- if (D.test(params))
226
- return params.replace(D, " -DW");
227
- if (d.test(params))
228
- return params.replace(d, " -DW");
229
- if (!params || W.test(params) || DW.test(params))
230
- return params;
231
- return `${params} -W`;
232
- }
233
- if (Dw.test(params))
234
- return params.replace(Dw, " -DW");
235
- if (W.test(params))
236
- return params.replace(W, " -W");
237
- return params;
238
- default:
239
- return d.test(params) ? params.replace(d, " -D") : params;
240
- }
241
- } catch {
242
- console.log(
243
- import_picocolors3.default.red(
244
- `${isZh2 ? "package.json\u5E76\u4E0D\u5B58\u5728,\u5728\u4EE5\u4E0B\u76EE\u5F55\u4E2D:" : "package.json has not been found in"} ${import_node_process4.default.cwd()}`
245
- )
246
- );
247
- import_node_process4.default.exit(1);
248
- }
202
+ const root = node_process.default.cwd();
203
+ try {
204
+ switch (await (0, lazy_js_utils_node.getPkgTool)()) {
205
+ case "pnpm":
206
+ if (!(0, lazy_js_utils.isFile)(node_path.default.resolve(root, "./pnpm-workspace.yaml"))) {
207
+ if (DW.test(params)) return params.replace(DW, " -D");
208
+ if (Dw.test(params)) return params.replace(Dw, " -D");
209
+ if (W.test(params)) return params.replace(W, "");
210
+ if (w.test(params)) return params.replace(w, "");
211
+ if (d.test(params)) return params.replace(d, " -D");
212
+ }
213
+ if ((0, lazy_js_utils.isFile)("./pnpm-workspace.yaml")) {
214
+ if (D.test(params)) return params.replace(D, " -Dw");
215
+ if (d.test(params)) return params.replace(d, " -Dw");
216
+ if (!params || Dw.test(params) || w.test(params)) return params;
217
+ return `${params} -w`;
218
+ }
219
+ if (DW.test(params)) return params.replace(DW, " -Dw");
220
+ if (W.test(params)) return params.replace(W, " -w");
221
+ return params;
222
+ case "yarn":
223
+ if (!(await (0, lazy_js_utils_node.getPkg)(node_path.default.resolve(root, "./package.json")))?.workspaces) {
224
+ if (Dw.test(params)) return params.replace(Dw, " -D");
225
+ if (DW.test(params)) return params.replace(DW, " -D");
226
+ if (W.test(params)) return params.replace(W, "");
227
+ if (w.test(params)) return params.replace(w, "");
228
+ if (d.test(params)) return params.replace(d, " -D");
229
+ }
230
+ if ((await (0, lazy_js_utils_node.getPkg)())?.workspaces) {
231
+ if (D.test(params)) return params.replace(D, " -DW");
232
+ if (d.test(params)) return params.replace(d, " -DW");
233
+ if (!params || W.test(params) || DW.test(params)) return params;
234
+ return `${params} -W`;
235
+ }
236
+ if (Dw.test(params)) return params.replace(Dw, " -DW");
237
+ if (W.test(params)) return params.replace(W, " -W");
238
+ return params;
239
+ default: return d.test(params) ? params.replace(d, " -D") : params;
240
+ }
241
+ } catch {
242
+ console.log(picocolors.default.red(`${isZh$3 ? "package.json并不存在,在以下目录中:" : "package.json has not been found in"} ${node_process.default.cwd()}`));
243
+ node_process.default.exit(1);
244
+ }
249
245
  }
250
246
  async function loading(text, isSilent = false) {
251
- const { color: color4, spinner } = await getStyle();
252
- const ora = (await import("ora")).default;
253
- return ora({
254
- text,
255
- spinner,
256
- color: color4,
257
- isSilent,
258
- discardStdin: true
259
- }).start();
247
+ const { color, spinner } = await getStyle();
248
+ const ora = (await import("ora")).default;
249
+ return ora({
250
+ text,
251
+ spinner,
252
+ color,
253
+ isSilent,
254
+ discardStdin: true
255
+ }).start();
260
256
  }
261
257
  async function getStyle() {
262
- const { PI_COLOR: color4 = "yellow", PI_SPINNER: spinner = "star" } = import_node_process4.default.env;
263
- return {
264
- color: color4,
265
- spinner
266
- };
258
+ const { PI_COLOR: color = "yellow", PI_SPINNER: spinner = "star" } = node_process.default.env;
259
+ return {
260
+ color,
261
+ spinner
262
+ };
263
+ }
264
+ async function getLatestVersion(pkg, isZh = true) {
265
+ const data = [];
266
+ for (const p of pkg.replace(/\s+/, " ").split(" ")) {
267
+ const [pName, v] = p.split("$");
268
+ let { status, result } = await (0, lazy_js_utils_node.jsShell)(`npm view ${pName}`, [
269
+ "inherit",
270
+ "pipe",
271
+ "inherit"
272
+ ]);
273
+ if (status === 0) {
274
+ if (result.startsWith("@")) result = result.slice(1);
275
+ const item = isZh ? `${pName} ${picocolors.default.gray(v)} -> ${result.match(/@(\S+)/)[1]}` : `Installed ${pName} ${picocolors.default.dim(v)} -> latest version:${result.match(/@(\S+)/)[1]}`;
276
+ data.push(item);
277
+ } else throw new Error(result);
278
+ }
279
+ return `${data.join(" ")}${isZh ? " 安装成功! 😊" : " successfully! 😊"}`;
267
280
  }
268
- async function getLatestVersion(pkg, isZh6 = true) {
269
- const data = [];
270
- for (const p of pkg.replace(/\s+/, " ").split(" ")) {
271
- const [pName, v] = p.split("$");
272
- let { status, result } = await (0, import_node5.jsShell)(`npm view ${pName}`, [
273
- "inherit",
274
- "pipe",
275
- "inherit"
276
- ]);
277
- if (status === 0) {
278
- if (result.startsWith("@"))
279
- result = result.slice(1);
280
- const item = isZh6 ? `${pName} ${import_picocolors3.default.gray(v)} -> ${result.match(/@(\S+)/)[1]}` : `Installed ${pName} ${import_picocolors3.default.dim(v)} -> latest version\uFF1A${result.match(/@(\S+)/)[1]}`;
281
- data.push(item);
282
- } else {
283
- throw new Error(result);
284
- }
285
- }
286
- return `${data.join(" ")}${isZh6 ? " \u5B89\u88C5\u6210\u529F! \u{1F60A}" : " successfully! \u{1F60A}"}`;
281
+ async function pushHistory(command) {
282
+ log$1(picocolors.default.bold(picocolors.default.blue(`${isZh$3 ? "快捷指令" : "shortcut command"}: ${command}`)));
283
+ const shellName = (node_process.default.env.SHELL || "/bin/bash").split("/").pop() || "bash";
284
+ let historyFile = "";
285
+ let historyFormat = "bash";
286
+ const home = node_process.default.env.HOME || node_os.default.homedir();
287
+ switch (shellName) {
288
+ case "zsh":
289
+ historyFile = node_path.default.join(home, ".zsh_history");
290
+ historyFormat = "zsh";
291
+ break;
292
+ case "bash":
293
+ historyFile = node_process.default.env.HISTFILE || node_path.default.join(home, ".bash_history");
294
+ historyFormat = "bash";
295
+ break;
296
+ case "fish":
297
+ historyFile = node_path.default.join(home, ".local", "share", "fish", "fish_history");
298
+ historyFormat = "fish";
299
+ break;
300
+ default:
301
+ historyFile = node_process.default.env.HISTFILE || node_path.default.join(home, ".bash_history");
302
+ historyFormat = "bash";
303
+ }
304
+ try {
305
+ if (!node_fs.default.existsSync(historyFile)) {
306
+ log$1(picocolors.default.yellow(`${isZh$3 ? `未找到 ${shellName} 历史文件` : `${shellName} history file not found`}`));
307
+ return;
308
+ }
309
+ const raw = node_fs.default.readFileSync(historyFile, "utf8");
310
+ const timestamp = Math.floor(Date.now() / 1e3);
311
+ let newEntry = "";
312
+ if (historyFormat === "zsh") newEntry = `: ${timestamp}:0;${command}`;
313
+ else if (historyFormat === "fish") newEntry = `- cmd: ${command}\n when: ${timestamp}`;
314
+ else if (node_process.default.env.HISTTIMEFORMAT) newEntry = `#${timestamp}\n${command}`;
315
+ else newEntry = command;
316
+ function parseEntries(content) {
317
+ if (historyFormat === "fish") {
318
+ const lines = content.split(/\r?\n/);
319
+ const blocks = [];
320
+ let buffer = [];
321
+ for (const line of lines) if (line.startsWith("- cmd: ")) {
322
+ if (buffer.length) {
323
+ blocks.push(buffer.join("\n"));
324
+ buffer = [];
325
+ }
326
+ buffer.push(line);
327
+ } else if (buffer.length) buffer.push(line);
328
+ else if (line.trim() !== "") blocks.push(line);
329
+ if (buffer.length) blocks.push(buffer.join("\n"));
330
+ return blocks.filter(Boolean);
331
+ } else if (historyFormat === "zsh") return content.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
332
+ else {
333
+ const lines = content.split(/\r?\n/);
334
+ const entries = [];
335
+ for (let i = 0; i < lines.length; i++) {
336
+ const line = lines[i];
337
+ if (line.startsWith("#")) {
338
+ const next = lines[i + 1] ?? "";
339
+ entries.push(`${line}\n${next}`);
340
+ i++;
341
+ } else if (line.trim() !== "") entries.push(line);
342
+ }
343
+ return entries;
344
+ }
345
+ }
346
+ const entries = parseEntries(raw);
347
+ function extractCommand(entry) {
348
+ if (historyFormat === "fish") {
349
+ const m = entry.split("\n")[0].match(/^- cmd: (.*)$/);
350
+ return m ? m[1] : entry;
351
+ } else if (historyFormat === "zsh") {
352
+ const m = entry.match(/^[^;]*;(.+)$/);
353
+ return m ? m[1] : entry;
354
+ } else {
355
+ if (entry.startsWith("#")) {
356
+ const parts = entry.split(/\r?\n/);
357
+ return parts[1] ?? parts[0];
358
+ }
359
+ return entry;
360
+ }
361
+ }
362
+ const newEntries = [];
363
+ const newCmd = extractCommand(newEntry);
364
+ let existingFishBlock = null;
365
+ for (const e of entries) {
366
+ if (extractCommand(e) === newCmd) {
367
+ if (historyFormat === "fish") {
368
+ existingFishBlock = e;
369
+ continue;
370
+ }
371
+ continue;
372
+ }
373
+ newEntries.push(e);
374
+ }
375
+ if (historyFormat === "fish" && existingFishBlock) {
376
+ const lines = existingFishBlock.split("\n");
377
+ let hasWhen = false;
378
+ const updated = lines.map((line) => {
379
+ if (line.trim().startsWith("when:") || line.startsWith(" when:")) {
380
+ hasWhen = true;
381
+ return ` when: ${timestamp}`;
382
+ }
383
+ return line;
384
+ });
385
+ if (!hasWhen) updated.splice(1, 0, ` when: ${timestamp}`);
386
+ newEntries.push(updated.join("\n"));
387
+ } else newEntries.push(newEntry);
388
+ let finalContent = "";
389
+ if (historyFormat === "fish") finalContent = `${newEntries.map((e) => e.trimEnd()).join("\n")}\n`;
390
+ else finalContent = `${newEntries.join("\n")}\n`;
391
+ const tmpPath = `${historyFile}.ccommand.tmp`;
392
+ node_fs.default.writeFileSync(tmpPath, finalContent, "utf8");
393
+ node_fs.default.renameSync(tmpPath, historyFile);
394
+ } catch (err) {
395
+ log$1(picocolors.default.red(`${isZh$3 ? `❌ 添加到 ${shellName} 历史记录失败` : `❌ Failed to add to ${shellName} history`}${err ? `: ${String(err)}` : ""}`));
396
+ }
287
397
  }
288
398
 
289
- // src/pi.ts
290
- var isZh3 = import_node_process5.default.env.PI_Lang === "zh";
399
+ //#endregion
400
+ //#region src/pi.ts
401
+ const isZh$2 = node_process.default.env.PI_Lang === "zh";
291
402
  async function pi(params, pkg, executor = "ni") {
292
- await detectNode();
293
- const text = pkg ? `Installing ${params} ...` : "Updating dependency ...";
294
- const isLatest = executor === "pil";
295
- const start = Date.now();
296
- let successMsg = "";
297
- if (isLatest) {
298
- successMsg = await getLatestVersion(pkg, isZh3);
299
- } else {
300
- successMsg = pkg ? isZh3 ? `${pkg} \u5B89\u88C5\u6210\u529F! \u{1F60A}` : `Installed ${pkg} successfully! \u{1F60A}` : isZh3 ? "\u4F9D\u8D56\u66F4\u65B0\u6210\u529F! \u{1F60A}" : "Updated dependency successfully! \u{1F60A}";
301
- }
302
- const failMsg = pkg ? isZh3 ? `${params} \u5B89\u88C5\u5931\u8D25 \u{1F62D}` : `Failed to install ${params} \u{1F62D}` : isZh3 ? "\u4F9D\u8D56\u66F4\u65B0\u5931\u8D25 \u{1F62D}" : "Failed to update dependency \u{1F62D}";
303
- const isSilent = import_node_process5.default.env.PI_SILENT === "true";
304
- let stdio = isSilent ? "inherit" : ["inherit", "pipe", "inherit"];
305
- let loading_status;
306
- const { PI_DEFAULT, PI_MaxSockets: sockets } = import_node_process5.default.env;
307
- const pkgTool = await (0, import_node6.getPkgTool)();
308
- const maxSockets = sockets || 4;
309
- const install = !params ? "install" : "add";
310
- if (pkgTool === "npm") {
311
- if (PI_DEFAULT) {
312
- executor = `${PI_DEFAULT} ${install}`;
313
- loading_status = await loading(text, isSilent);
314
- } else {
315
- stdio = "inherit";
316
- executor = "ni";
317
- }
318
- } else {
319
- executor = `${pkgTool} ${install}`;
320
- loading_status = await loading(text, isSilent);
321
- }
322
- const newParams = isLatest ? "" : await getParams(params);
323
- const runSockets = executor.split(" ")[0] === "npm" ? ` --max-sockets=${maxSockets}` : "";
324
- console.log(
325
- import_picocolors4.default.green(
326
- isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`
327
- )
328
- );
329
- let { status, result } = await (0, import_node6.useNodeWorker)({
330
- params: isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`,
331
- stdio,
332
- errorExit: false
333
- });
334
- if (result && result.includes("pnpm versions with respective Node.js version support")) {
335
- (0, import_node_console.log)(result);
336
- (0, import_node_console.log)(
337
- import_picocolors4.default.yellow(
338
- isZh3 ? "\u6B63\u5728\u5C1D\u8BD5\u4F7F\u7528 npm \u518D\u6B21\u6267\u884C..." : "Trying to use npm to run again..."
339
- )
340
- );
341
- const { status: newStatus, result: newResult } = await (0, import_node6.jsShell)(
342
- `npm install${newParams ? ` ${newParams}` : runSockets}`,
343
- {
344
- stdio
345
- }
346
- );
347
- status = newStatus;
348
- result = newResult;
349
- }
350
- if (stdio === "inherit")
351
- loading_status = await loading("");
352
- const end = Date.now();
353
- const costTime = (end - start) / 1e3;
354
- successMsg += import_picocolors4.default.blue(` ---- \u23F0\uFF1A${costTime}s`);
355
- if (status === 0) {
356
- loading_status.succeed(import_picocolors4.default.green(successMsg));
357
- } else if (result && result.includes("Not Found - 404")) {
358
- const _pkg = result.match(/\/[^/:]+:/)?.[0].slice(1, -1);
359
- const _result = isZh3 ? `${_pkg} \u5305\u540D\u53EF\u80FD\u6709\u8BEF\u6216\u8005\u7248\u672C\u53F7\u4E0D\u5B58\u5728\uFF0C\u5E76\u4E0D\u80FD\u5728npm\u4E2D\u641C\u7D22\u5230\uFF0C\u8BF7\u68C0\u67E5` : `${_pkg} the package name may be wrong, and cannot be found in npm, please check`;
360
- loading_status.fail(import_picocolors4.default.red(result ? `${failMsg}
361
- ${_result}` : failMsg));
362
- } else {
363
- loading_status.fail(import_picocolors4.default.red(result ? `${failMsg}
364
- ${result}` : failMsg));
365
- }
366
- if (result) {
367
- const reg = /ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE\u2009 In : No matching version found for\s+([^@]+)/;
368
- const match = result.match(reg);
369
- if (match) {
370
- const dep = match[1];
371
- (0, import_node6.jsShell)(`pi ${dep}@latest`);
372
- }
373
- }
374
- import_node_process5.default.exit();
403
+ await detectNode();
404
+ const text = pkg ? `Installing ${params} ...` : "Updating dependency ...";
405
+ const isLatest = executor === "pil";
406
+ const start = Date.now();
407
+ let successMsg = "";
408
+ if (isLatest) successMsg = await getLatestVersion(pkg, isZh$2);
409
+ else successMsg = pkg ? isZh$2 ? `${pkg} 安装成功! 😊` : `Installed ${pkg} successfully! 😊` : isZh$2 ? "依赖更新成功! 😊" : "Updated dependency successfully! 😊";
410
+ const failMsg = pkg ? isZh$2 ? `${params} 安装失败 😭` : `Failed to install ${params} 😭` : isZh$2 ? "依赖更新失败 😭" : "Failed to update dependency 😭";
411
+ const isSilent = node_process.default.env.PI_SILENT === "true";
412
+ let stdio = isSilent ? "inherit" : [
413
+ "inherit",
414
+ "pipe",
415
+ "inherit"
416
+ ];
417
+ let loading_status;
418
+ const { PI_DEFAULT, PI_MaxSockets: sockets } = node_process.default.env;
419
+ const pkgTool = await (0, lazy_js_utils_node.getPkgTool)();
420
+ const maxSockets = sockets || 4;
421
+ const install = !params ? "install" : "add";
422
+ if (pkgTool === "npm") if (PI_DEFAULT) {
423
+ executor = `${PI_DEFAULT} ${install}`;
424
+ loading_status = await loading(text, isSilent);
425
+ } else {
426
+ stdio = "inherit";
427
+ executor = "ni";
428
+ }
429
+ else {
430
+ executor = `${pkgTool} ${install}`;
431
+ loading_status = await loading(text, isSilent);
432
+ }
433
+ const newParams = isLatest ? "" : await getParams(params);
434
+ const runSockets = executor.split(" ")[0] === "npm" ? ` --max-sockets=${maxSockets}` : "";
435
+ const latestParams = Array.isArray(params) ? params : params ? [params] : [];
436
+ const cmdList = isLatest ? latestParams.map((p) => `${executor} ${p}`) : [`${executor}${newParams ? ` ${newParams}` : runSockets}`];
437
+ const runCmd = isLatest ? cmdList.join(" & ") : cmdList[0];
438
+ const runCommands = async (commands) => {
439
+ const results = await Promise.all(commands.map((command) => (0, lazy_js_utils_node.useNodeWorker)({
440
+ params: command,
441
+ stdio,
442
+ errorExit: false
443
+ })));
444
+ const failed = results.find((r) => r.status !== 0);
445
+ const merged = results.map((r) => r.result).filter(Boolean).join("\n");
446
+ return {
447
+ status: failed ? failed.status : 0,
448
+ result: failed?.result || merged
449
+ };
450
+ };
451
+ let { status, result } = await runCommands(cmdList);
452
+ if (result && result.includes("pnpm versions with respective Node.js version support")) {
453
+ (0, node_console.log)(result);
454
+ (0, node_console.log)(picocolors.default.yellow(isZh$2 ? "正在尝试使用 npm 再次执行..." : "Trying to use npm to run again..."));
455
+ const fallbackCommands = isLatest ? latestParams.map((p) => `npm install ${p}`) : [`npm install${newParams ? ` ${newParams}` : runSockets}`];
456
+ const fallbackResults = await Promise.all(fallbackCommands.map((command) => (0, lazy_js_utils_node.jsShell)(command, { stdio })));
457
+ const fallbackFailed = fallbackResults.find((r) => r.status !== 0);
458
+ const fallbackMerged = fallbackResults.map((r) => r.result).filter(Boolean).join("\n");
459
+ status = fallbackFailed ? fallbackFailed.status : 0;
460
+ result = fallbackFailed?.result || fallbackMerged;
461
+ }
462
+ if (stdio === "inherit") loading_status = await loading("");
463
+ const costTime = (Date.now() - start) / 1e3;
464
+ successMsg += picocolors.default.blue(` ---- ⏰:${costTime}s`);
465
+ if (status === 0) {
466
+ loading_status.succeed(picocolors.default.green(successMsg));
467
+ pushHistory(runCmd);
468
+ } else if (result && result.includes("Not Found - 404")) {
469
+ const _pkg = result.match(/\/[^/:]+:/)?.[0].slice(1, -1);
470
+ const _result = isZh$2 ? `${_pkg} 包名可能有误或者版本号不存在,并不能在npm中搜索到,请检查` : `${_pkg} the package name may be wrong, and cannot be found in npm, please check`;
471
+ loading_status.fail(picocolors.default.red(result ? `${failMsg}\n${_result}` : failMsg));
472
+ } else loading_status.fail(picocolors.default.red(result ? `${failMsg}\n${result}` : failMsg));
473
+ if (result) {
474
+ const match = result.match(/ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE\u2009 In : No matching version found for\s+([^@]+)/);
475
+ if (match) {
476
+ const dep = match[1];
477
+ (0, lazy_js_utils_node.jsShell)(`pi ${dep}@latest`);
478
+ }
479
+ }
480
+ node_process.default.exit();
375
481
  }
376
482
 
377
- // src/pci.ts
483
+ //#endregion
484
+ //#region src/pci.ts
378
485
  function pci(params, pkg) {
379
- return pi(params, pkg, "nci");
486
+ return pi(params, pkg, "nci");
380
487
  }
381
488
 
382
- // src/pfind.ts
383
- var import_ccommand = require("ccommand");
489
+ //#endregion
490
+ //#region src/require.ts
491
+ const entry = node_process.default.argv[1];
492
+ const base = entry ? node_path.default.resolve(entry) : node_path.default.join(node_process.default.cwd(), "index.js");
493
+ const localRequire = (0, node_module.createRequire)(base);
494
+
495
+ //#endregion
496
+ //#region src/pfind.ts
384
497
  function pfind(params) {
385
- return (0, import_ccommand.ccommand)(`find ${params}`);
498
+ const { ccommand } = localRequire("ccommand");
499
+ return ccommand(`find ${params}`);
386
500
  }
387
501
 
388
- // src/pil.ts
389
- var import_node_process6 = __toESM(require("process"), 1);
390
- var import_node7 = require("lazy-js-utils/node");
391
- var import_picocolors5 = __toESM(require("picocolors"), 1);
502
+ //#endregion
503
+ //#region src/pil.ts
392
504
  async function pil(params) {
393
- const { dependencies = {}, devDependencies = {} } = await (0, import_node7.getPkg)();
394
- if (!params) {
395
- const deps = [
396
- ...Object.keys(dependencies).map(
397
- (key) => `${key}: ${dependencies[key].replace(/([><~])/g, "\\$1")}`
398
- ),
399
- ...Object.keys(devDependencies).map(
400
- (key) => `${key}: ${devDependencies[key].replace(/([><~])/g, "\\$1")}`
401
- )
402
- ];
403
- const { result: choose, status } = await (0, import_node7.jsShell)(
404
- `echo ${deps.join(
405
- ","
406
- )} | sed "s/,/\\n/g" | gum filter --no-limit --placeholder=" \u{1F914}${import_node_process6.default.env.PI_Lang === "zh" ? "\u8BF7\u9009\u62E9\u4E00\u4E2A\u9700\u8981\u83B7\u53D6\u6700\u65B0\u7248\u672C\u7684\u4F9D\u8D56" : "Please select a dependency that needs to obtain the latest version."}"`,
407
- {
408
- stdio: ["inherit", "pipe", "inherit"]
409
- }
410
- );
411
- if (status === 130) {
412
- console.log(import_picocolors5.default.dim("\u5DF2\u53D6\u6D88"));
413
- import_node_process6.default.exit(0);
414
- } else if (status !== 0) {
415
- throw new Error(choose);
416
- }
417
- const names = choose.trim().split("\n").map((i) => {
418
- const name = i.split(": ")[0];
419
- if (name in devDependencies)
420
- return `${name}@latest -D`;
421
- return `${name}@latest -S`;
422
- });
423
- params = names.join(" ");
424
- }
425
- let latestPkgname = params;
426
- const reg = /\s(-[dws]+)/gi;
427
- const suffix = [];
428
- const command = latestPkgname = (await getParams(params)).replace(
429
- reg,
430
- (_, k) => {
431
- suffix.push(k);
432
- return "";
433
- }
434
- );
435
- latestPkgname = latestPkgname.replace(/@latest/g, "").split(" ").filter(Boolean).map((i) => {
436
- const v = dependencies[i] || devDependencies[i];
437
- return `${i}$${v}`;
438
- }).join(" ");
439
- const tokens = command.replace(/\s+/, " ").trim().split(" ").filter(Boolean);
440
- const pkgs = tokens.filter((t) => !t.startsWith("-"));
441
- let globalWorkspaceFlag = null;
442
- const perFlags = [];
443
- let assignIdx = 0;
444
- for (const f of suffix) {
445
- if (/^-(?:w|W)$/.test(f)) {
446
- globalWorkspaceFlag = f;
447
- continue;
448
- }
449
- perFlags[assignIdx++] = f;
450
- }
451
- const normalizeFlag = (f) => {
452
- if (!f)
453
- return "";
454
- if (/^-s$/i.test(f) || /^-S$/.test(f))
455
- return "";
456
- return f;
457
- };
458
- const combineWorkspace = (f, w2) => {
459
- if (!w2)
460
- return f;
461
- if (/w/i.test(f))
462
- return f;
463
- if (!f)
464
- return w2;
465
- if (/d/i.test(f))
466
- return `-D${w2.slice(1)}`;
467
- return w2;
468
- };
469
- const finalFlags = pkgs.map((_, i) => combineWorkspace(normalizeFlag(perFlags[i]), globalWorkspaceFlag));
470
- const group = {};
471
- pkgs.forEach((p, i) => {
472
- const key = finalFlags[i] || "";
473
- if (!group[key])
474
- group[key] = [];
475
- group[key].push(p);
476
- });
477
- const cmds = Object.entries(group).map(([flag, list]) => `${list.join(" ")}${flag ? ` ${flag}` : ""}`);
478
- return await pi(cmds, latestPkgname.replace(/@latest/g, ""), "pil");
505
+ const isZh = node_process.default.env.PI_Lang === "zh";
506
+ const { dependencies = {}, devDependencies = {} } = await (0, lazy_js_utils_node.getPkg)();
507
+ if (!params) {
508
+ if (!await (0, lazy_js_utils_node.isInstallPkg)("gum")) {
509
+ console.log(picocolors.default.yellow(isZh ? "未检测到 gum,请先安装 gum 后再选择依赖。" : "gum not found. Please install gum before selecting dependencies."));
510
+ node_process.default.exit(1);
511
+ }
512
+ const { result: choose, status } = await (0, lazy_js_utils_node.jsShell)(`echo ${[...Object.keys(dependencies).map((key) => `${key}: ${dependencies[key].replace(/([><~])/g, "\\$1")}`), ...Object.keys(devDependencies).map((key) => `${key}: ${devDependencies[key].replace(/([><~])/g, "\\$1")}`)].join(",")} | sed "s/,/\\n/g" | gum filter --no-limit --placeholder=" 🤔${node_process.default.env.PI_Lang === "zh" ? "请选择一个需要获取最新版本的依赖" : "Please select a dependency that needs to obtain the latest version."}"`, { stdio: [
513
+ "inherit",
514
+ "pipe",
515
+ "inherit"
516
+ ] });
517
+ if (status === 130) {
518
+ console.log(picocolors.default.dim("已取消"));
519
+ node_process.default.exit(0);
520
+ } else if (status !== 0) throw new Error(choose);
521
+ params = choose.trim().split("\n").map((i) => {
522
+ const name = i.split(": ")[0];
523
+ if (name in devDependencies) return `${name}@latest -D`;
524
+ return `${name}@latest -S`;
525
+ }).join(" ");
526
+ }
527
+ let latestPkgname = params;
528
+ const reg = /\s(-[dws]+)/gi;
529
+ const suffix = [];
530
+ const command = latestPkgname = (await getParams(params)).replace(reg, (_, k) => {
531
+ suffix.push(k);
532
+ return "";
533
+ });
534
+ latestPkgname = latestPkgname.replace(/@latest/g, "").split(" ").filter(Boolean).map((i) => {
535
+ return `${i}$${dependencies[i] || devDependencies[i]}`;
536
+ }).join(" ");
537
+ const pkgs = command.replace(/\s+/, " ").trim().split(" ").filter(Boolean).filter((t) => !t.startsWith("-"));
538
+ let globalWorkspaceFlag = null;
539
+ const perFlags = [];
540
+ let assignIdx = 0;
541
+ for (const f of suffix) {
542
+ if (/^-(?:w|W)$/.test(f)) {
543
+ globalWorkspaceFlag = f;
544
+ continue;
545
+ }
546
+ perFlags[assignIdx++] = f;
547
+ }
548
+ const normalizeFlag = (f) => {
549
+ if (!f) return "";
550
+ if (/^-s$/i.test(f) || /^-S$/.test(f)) return "";
551
+ return f;
552
+ };
553
+ const combineWorkspace = (f, w) => {
554
+ if (!w) return f;
555
+ if (/w/i.test(f)) return f;
556
+ if (!f) return w;
557
+ if (/d/i.test(f)) return `-D${w.slice(1)}`;
558
+ return w;
559
+ };
560
+ const finalFlags = pkgs.map((_, i) => combineWorkspace(normalizeFlag(perFlags[i]), globalWorkspaceFlag));
561
+ const group = {};
562
+ pkgs.forEach((p, i) => {
563
+ const key = finalFlags[i] || "";
564
+ if (!group[key]) group[key] = [];
565
+ group[key].push(p);
566
+ });
567
+ return await pi(Object.entries(group).map(([flag, list]) => `${list.join(" ")}${flag ? ` ${flag}` : ""}`), latestPkgname.replace(/@latest/g, ""), "pil");
479
568
  }
480
569
 
481
- // src/pinit.ts
482
- var import_node8 = require("lazy-js-utils/node");
570
+ //#endregion
571
+ //#region src/pinit.ts
483
572
  async function pinit() {
484
- console.log("Initializing project...");
485
- switch (await (0, import_node8.getPkgTool)()) {
486
- case "npm":
487
- (0, import_node8.jsShell)("npm init -y");
488
- return;
489
- case "yarn":
490
- (0, import_node8.jsShell)("yarn init -y");
491
- return;
492
- case "pnpm":
493
- (0, import_node8.jsShell)("pnpm init -y");
494
- return;
495
- default:
496
- (0, import_node8.jsShell)("npm init -y");
497
- }
573
+ console.log("Initializing project...");
574
+ switch (await (0, lazy_js_utils_node.getPkgTool)()) {
575
+ case "npm":
576
+ await (0, lazy_js_utils_node.jsShell)("npm init -y");
577
+ return;
578
+ case "yarn":
579
+ await (0, lazy_js_utils_node.jsShell)("yarn init -y");
580
+ return;
581
+ case "pnpm":
582
+ await (0, lazy_js_utils_node.jsShell)("pnpm init -y");
583
+ return;
584
+ default: await (0, lazy_js_utils_node.jsShell)("npm init -y");
585
+ }
498
586
  }
499
587
 
500
- // src/pio.ts
501
- var import_node_process7 = __toESM(require("process"), 1);
502
- var import_node9 = require("lazy-js-utils/node");
503
- var import_picocolors6 = __toESM(require("picocolors"), 1);
588
+ //#endregion
589
+ //#region src/pio.ts
504
590
  async function pio(params, pkg, executor = "ni") {
505
- const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "Updated dependency successfully! \u{1F60A}";
506
- const failMsg = pkg ? `Failed to install ${pkg} \u{1F62D}` : "Failed to update dependency! \u{1F62D}";
507
- const offline = "--prefer-offline";
508
- const newParams = await getParams(params);
509
- const { status, result } = await (0, import_node9.useNodeWorker)({
510
- params: `${executor} ${newParams} ${offline}`,
511
- stdio: "inherit"
512
- });
513
- const loading_status = await loading("");
514
- if (status === 0)
515
- loading_status.succeed(import_picocolors6.default.green(successMsg));
516
- else
517
- loading_status.fail(import_picocolors6.default.red(result ? `${result}
518
-
519
- ${failMsg}` : failMsg));
520
- import_node_process7.default.exit();
591
+ const successMsg = pkg ? `Installed ${pkg} successfully! 😊` : "Updated dependency successfully! 😊";
592
+ const failMsg = pkg ? `Failed to install ${pkg} 😭` : "Failed to update dependency! 😭";
593
+ const { status, result } = await (0, lazy_js_utils_node.useNodeWorker)({
594
+ params: `${executor} ${await getParams(params)} --prefer-offline`,
595
+ stdio: "inherit"
596
+ });
597
+ const loading_status = await loading("");
598
+ if (status === 0) loading_status.succeed(picocolors.default.green(successMsg));
599
+ else loading_status.fail(picocolors.default.red(result ? `${result}\n\n${failMsg}` : failMsg));
600
+ node_process.default.exit();
521
601
  }
522
602
 
523
- // src/pix.ts
524
- var import_node10 = require("lazy-js-utils/node");
603
+ //#endregion
604
+ //#region src/pix.ts
525
605
  async function pix(params) {
526
- switch (await (0, import_node10.getPkgTool)()) {
527
- case "bun":
528
- return (0, import_node10.jsShell)(`bunx ${params}`);
529
- default:
530
- return (0, import_node10.jsShell)(`npx ${params}`);
531
- }
606
+ switch (await (0, lazy_js_utils_node.getPkgTool)()) {
607
+ case "bun": return (0, lazy_js_utils_node.jsShell)(`bunx ${params}`);
608
+ default: return (0, lazy_js_utils_node.jsShell)(`npx ${params}`);
609
+ }
532
610
  }
533
611
 
534
- // src/prun.ts
535
- var import_ccommand2 = require("ccommand");
612
+ //#endregion
613
+ //#region src/prun.ts
536
614
  function prun(params) {
537
- return (0, import_ccommand2.ccommand)(params);
615
+ const { ccommand } = localRequire("ccommand");
616
+ return ccommand(params);
538
617
  }
539
618
 
540
- // src/pu.ts
541
- var import_node11 = require("lazy-js-utils/node");
619
+ //#endregion
620
+ //#region src/pu.ts
542
621
  function pu() {
543
- return (0, import_node11.jsShell)("nu");
622
+ return (0, lazy_js_utils_node.jsShell)("nu");
544
623
  }
545
624
 
546
- // src/pui.ts
547
- var import_node_process8 = __toESM(require("process"), 1);
548
- var import_node12 = require("lazy-js-utils/node");
549
- var import_picocolors7 = __toESM(require("picocolors"), 1);
550
- var isZh4 = import_node_process8.default.env.PI_Lang === "zh";
625
+ //#endregion
626
+ //#region src/pui.ts
627
+ const isZh$1 = node_process.default.env.PI_Lang === "zh";
551
628
  async function pui(params, pkg) {
552
- const text = `${isZh4 ? "\u6B63\u5728\u4E3A\u60A8\u5378\u8F7D" : "Uninstalling"} ${pkg} ...`;
553
- if (!params) {
554
- const { dependencies = {}, devDependencies = {} } = await (0, import_node12.getPkg)();
555
- const deps = [
556
- ...Object.keys(dependencies).map((key) => `${key}: ${dependencies[key]}`),
557
- ...Object.keys(devDependencies).map(
558
- (key) => `${key}: ${devDependencies[key]}`
559
- )
560
- ];
561
- const { result: choose, status: status2 } = await (0, import_node12.jsShell)(
562
- `echo ${deps.join(
563
- ","
564
- )} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}${import_node_process8.default.env.PI_Lang === "zh" ? "\u8BF7\u9009\u62E9\u4E00\u4E2A\u9700\u8981\u5220\u9664\u4F9D\u8D56" : "Please select a dependency to get the latest version."}"`,
565
- ["inherit", "pipe", "inherit"]
566
- );
567
- if (status2 === 130) {
568
- console.log(import_picocolors7.default.dim("\u5DF2\u53D6\u6D88"));
569
- import_node_process8.default.exit(0);
570
- } else if (status2 !== 0) {
571
- throw new Error(choose);
572
- }
573
- pkg = params = choose.split(": ")[0];
574
- }
575
- const start = Date.now();
576
- let successMsg = isZh4 ? `${pkg}\u5378\u8F7D\u6210\u529F! \u{1F60A}` : `UnInstalled ${pkg} successfully! \u{1F60A}`;
577
- const failMsg = isZh4 ? `${pkg}\u5378\u8F7D\u5931\u8D25 \u{1F62D}` : `Failed to uninstall ${pkg} \u{1F62D}`;
578
- if (!pkg) {
579
- console.log(
580
- import_picocolors7.default.yellow(
581
- isZh4 ? "\u9700\u8981\u6307\u5B9A\u8981\u5378\u8F7D\u7684\u5305\u540D\uFF01" : "Need to specify an uninstall package name!"
582
- )
583
- );
584
- import_node_process8.default.exit(1);
585
- }
586
- const loading_status = await loading(text);
587
- const { status, result } = await (0, import_node12.useNodeWorker)(`nun ${params}`);
588
- const end = Date.now();
589
- const costTime = (end - start) / 1e3;
590
- successMsg += import_picocolors7.default.blue(` ---- \u23F0\uFF1A${costTime}s`);
591
- if (status === 0)
592
- loading_status.succeed(import_picocolors7.default.green(successMsg));
593
- else
594
- loading_status.fail(import_picocolors7.default.red(result ? `${failMsg}
595
- ${result}` : failMsg));
596
- import_node_process8.default.exit();
629
+ const text = `${isZh$1 ? "正在为您卸载" : "Uninstalling"} ${pkg} ...`;
630
+ if (!params) {
631
+ const { dependencies = {}, devDependencies = {} } = await (0, lazy_js_utils_node.getPkg)();
632
+ const { result: choose, status } = await (0, lazy_js_utils_node.jsShell)(`echo ${[...Object.keys(dependencies).map((key) => `${key}: ${dependencies[key]}`), ...Object.keys(devDependencies).map((key) => `${key}: ${devDependencies[key]}`)].join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" 🤔${node_process.default.env.PI_Lang === "zh" ? "请选择一个需要删除依赖" : "Please select a dependency to get the latest version."}"`, [
633
+ "inherit",
634
+ "pipe",
635
+ "inherit"
636
+ ]);
637
+ if (status === 130) {
638
+ console.log(picocolors.default.dim("已取消"));
639
+ node_process.default.exit(0);
640
+ } else if (status !== 0) throw new Error(choose);
641
+ pkg = params = choose.split(": ")[0];
642
+ }
643
+ const start = Date.now();
644
+ let successMsg = isZh$1 ? `${pkg}卸载成功! 😊` : `UnInstalled ${pkg} successfully! 😊`;
645
+ const failMsg = isZh$1 ? `${pkg}卸载失败 😭` : `Failed to uninstall ${pkg} 😭`;
646
+ if (!pkg) {
647
+ console.log(picocolors.default.yellow(isZh$1 ? "需要指定要卸载的包名!" : "Need to specify an uninstall package name!"));
648
+ node_process.default.exit(1);
649
+ }
650
+ const loading_status = await loading(text);
651
+ const { status, result } = await (0, lazy_js_utils_node.useNodeWorker)(`nun ${params}`);
652
+ const costTime = (Date.now() - start) / 1e3;
653
+ successMsg += picocolors.default.blue(` ---- ⏰:${costTime}s`);
654
+ if (status === 0) loading_status.succeed(picocolors.default.green(successMsg));
655
+ else loading_status.fail(picocolors.default.red(result ? `${failMsg}\n${result}` : failMsg));
656
+ node_process.default.exit();
597
657
  }
598
658
 
599
- // src/index.ts
600
- var rootPath = import_node_process9.default.cwd();
601
- var runMap = {
602
- pi,
603
- "pi.mjs": pi,
604
- pix,
605
- "pix.mjs": pix,
606
- pa,
607
- "pa.mjs": pa,
608
- pui,
609
- "pui.mjs": pui,
610
- pu,
611
- "pu.mjs": pu,
612
- pil,
613
- "pil.mjs": pil,
614
- pci,
615
- "pci.mjs": pci,
616
- prun,
617
- "prun.mjs": prun,
618
- pinit,
619
- "pinit.mjs": pinit,
620
- pfind,
621
- "pfind.mjs": pfind,
622
- pio,
623
- "pio.mjs": pio
659
+ //#endregion
660
+ //#region src/index.ts
661
+ let rootPath = node_process.default.cwd();
662
+ const runMap = {
663
+ pi,
664
+ "pi.mjs": pi,
665
+ pix,
666
+ "pix.mjs": pix,
667
+ pa,
668
+ "pa.mjs": pa,
669
+ pui,
670
+ "pui.mjs": pui,
671
+ pu,
672
+ "pu.mjs": pu,
673
+ pil,
674
+ "pil.mjs": pil,
675
+ pci,
676
+ "pci.mjs": pci,
677
+ prun,
678
+ "prun.mjs": prun,
679
+ pinit,
680
+ "pinit.mjs": pinit,
681
+ pfind,
682
+ "pfind.mjs": pfind,
683
+ pio,
684
+ "pio.mjs": pio
624
685
  };
625
- var isZh5 = import_node_process9.default.env.PI_Lang === "zh";
686
+ const isZh = node_process.default.env.PI_Lang === "zh";
626
687
  async function setup() {
627
- const cmd = import_node_process9.default.argv[1];
628
- let exec = "";
629
- if ((0, import_lazy_js_utils2.isWin)()) {
630
- const last = cmd.lastIndexOf("\\") + 1;
631
- exec = cmd.slice(last, cmd.length).split(".").slice(0, -1).join(".");
632
- } else {
633
- const last = cmd.lastIndexOf("/") + 1;
634
- exec = cmd.slice(last, cmd.length);
635
- }
636
- const argv = import_node_process9.default.argv.slice(2);
637
- await help(argv);
638
- let params = (0, import_lazy_js_utils2.spaceFormat)(argv.join(" ")).trim();
639
- if (!await (0, import_node13.hasPkg)(rootPath)) {
640
- if (await (0, import_node13.isGo)(rootPath)) {
641
- if (exec === "pi") {
642
- const loading_status = await loading(
643
- `${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5" : "Installing"} ${params} ...
644
- `
645
- );
646
- const { status } = params ? await (0, import_node13.useNodeWorker)(`go get ${params}`) : await (0, import_node13.useNodeWorker)("go mod tidy");
647
- if (status === 0) {
648
- loading_status.succeed(
649
- import_picocolors8.default.green(isZh5 ? "\u5B89\u88C5\u6210\u529F! \u{1F60A}" : "Installed successfully! \u{1F60A}")
650
- );
651
- } else {
652
- loading_status.fail(
653
- import_picocolors8.default.red(isZh5 ? "\u5B89\u88C5\u5931\u8D25 \u{1F62D}" : "Failed to install \u{1F62D}")
654
- );
655
- }
656
- } else if (exec === "pui") {
657
- const loading_status = await loading(
658
- `${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5378\u8F7D" : "Uninstalling"} ${params} ...
659
- `
660
- );
661
- const { status } = await (0, import_node13.useNodeWorker)(`go clean ${params}`);
662
- if (status === 0) {
663
- loading_status.succeed(
664
- import_picocolors8.default.green(isZh5 ? "\u5378\u8F7D\u6210\u529F! \u{1F60A}" : "Uninstalled successfully! \u{1F60A}")
665
- );
666
- } else {
667
- loading_status.fail(
668
- import_picocolors8.default.red(isZh5 ? "\u5378\u8F7D\u5931\u8D25 \u{1F62D}" : "Failed to uninstall \u{1F62D}")
669
- );
670
- }
671
- } else if (exec === "prun") {
672
- const match = params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go";
673
- const target = (await (0, import_fast_glob.default)(match))[0];
674
- return target ? await (0, import_node13.jsShell)(`go run ${target}`, "inherit") : (0, import_ccommand3.ccommand)(params);
675
- } else if (exec === "pinit") {
676
- await (0, import_node13.jsShell)(`go mod init ${params}`, "inherit");
677
- } else if (exec === "pbuild") {
678
- await (0, import_node13.jsShell)(`go build ${params}`, "inherit");
679
- } else {
680
- console.log(
681
- import_picocolors8.default.red(
682
- isZh5 ? "\u5F53\u524D\u6307\u4EE4\u8FD8\u4E0D\u652F\u6301" : "The commands is not supported"
683
- )
684
- );
685
- }
686
- import_node_process9.default.exit();
687
- }
688
- let projectPath = "";
689
- if (params && !await (0, import_node13.isRust)()) {
690
- projectPath = params.split(" ")[0];
691
- rootPath = import_node_path2.default.resolve(rootPath, projectPath);
692
- params = params.replace(projectPath, "").trim();
693
- }
694
- if (await (0, import_node13.isRust)(rootPath)) {
695
- if (exec === "pi") {
696
- const loading_status = await loading(
697
- `${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5" : "Installing"} ${params} ...
698
- `
699
- );
700
- const { status } = await (0, import_node13.useNodeWorker)(
701
- `cargo install ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`
702
- );
703
- if (status === 0) {
704
- loading_status.succeed(
705
- import_picocolors8.default.green(isZh5 ? "\u5B89\u88C5\u6210\u529F! \u{1F60A}" : "Installed successfully! \u{1F60A}")
706
- );
707
- } else {
708
- loading_status.fail(
709
- import_picocolors8.default.red(isZh5 ? "\u5B89\u88C5\u5931\u8D25 \u{1F62D}" : "Failed to install \u{1F62D}")
710
- );
711
- }
712
- } else if (exec === "pui") {
713
- const loading_status = await loading(
714
- `${isZh5 ? "\u6B63\u5728\u4E3A\u60A8\u5378\u8F7D" : "Uninstalling"} ${params} ...
715
- `
716
- );
717
- const { status } = await (0, import_node13.useNodeWorker)(
718
- `cargo uninstall ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`
719
- );
720
- if (status === 0) {
721
- loading_status.succeed(
722
- import_picocolors8.default.green(isZh5 ? "\u5378\u8F7D\u6210\u529F! \u{1F60A}" : "Uninstalled successfully! \u{1F60A}")
723
- );
724
- } else {
725
- loading_status.fail(
726
- import_picocolors8.default.red(isZh5 ? "\u5378\u8F7D\u5931\u8D25 \u{1F62D}" : "Failed to uninstall \u{1F62D}")
727
- );
728
- }
729
- } else if (exec === "prun") {
730
- await (0, import_node13.jsShell)(
731
- `cargo run ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
732
- "inherit"
733
- );
734
- } else if (exec === "pinit") {
735
- await (0, import_node13.jsShell)(
736
- `cargo init ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
737
- "inherit"
738
- );
739
- } else if (exec === "pbuild") {
740
- await (0, import_node13.jsShell)(
741
- `cargo build ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`,
742
- "inherit"
743
- );
744
- } else {
745
- console.log(
746
- import_picocolors8.default.red(
747
- isZh5 ? "\u5F53\u524D\u6307\u4EE4\u8FD8\u4E0D\u652F\u6301" : "The commands is not supported"
748
- )
749
- );
750
- }
751
- import_node_process9.default.exit();
752
- }
753
- if (!runMap[exec]) {
754
- console.log(
755
- import_picocolors8.default.yellow(
756
- isZh5 ? "\u547D\u4EE4\u4E0D\u5B58\u5728, \u8BF7\u6267\u884C pi -h \u67E5\u770B\u5E2E\u52A9" : "The command does not exist, please execute pi -h to view the help"
757
- )
758
- );
759
- return;
760
- }
761
- }
762
- const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
763
- await installDeps();
764
- runMap[exec](params, pkg);
688
+ const cmd = node_process.default.argv[1];
689
+ let exec = "";
690
+ if ((0, lazy_js_utils.isWin)()) {
691
+ const last = cmd.lastIndexOf("\\") + 1;
692
+ exec = cmd.slice(last, cmd.length).split(".").slice(0, -1).join(".");
693
+ } else {
694
+ const last = cmd.lastIndexOf("/") + 1;
695
+ exec = cmd.slice(last, cmd.length);
696
+ }
697
+ const argv = node_process.default.argv.slice(2);
698
+ await help(argv);
699
+ let params = (0, lazy_js_utils.spaceFormat)(argv.join(" ")).trim();
700
+ if (!await (0, lazy_js_utils_node.hasPkg)(rootPath)) {
701
+ if (await (0, lazy_js_utils_node.isGo)(rootPath)) {
702
+ if (exec === "pi") {
703
+ const loading_status = await loading(`${isZh ? "正在为您安装" : "Installing"} ${params} ...\n`);
704
+ const { status } = params ? await (0, lazy_js_utils_node.useNodeWorker)(`go get ${params}`) : await (0, lazy_js_utils_node.useNodeWorker)("go mod tidy");
705
+ if (status === 0) loading_status.succeed(picocolors.default.green(isZh ? "安装成功! 😊" : "Installed successfully! 😊"));
706
+ else loading_status.fail(picocolors.default.red(isZh ? "安装失败 😭" : "Failed to install 😭"));
707
+ } else if (exec === "pui") {
708
+ const loading_status = await loading(`${isZh ? "正在为您卸载" : "Uninstalling"} ${params} ...\n`);
709
+ const { status } = await (0, lazy_js_utils_node.useNodeWorker)(`go clean ${params}`);
710
+ if (status === 0) loading_status.succeed(picocolors.default.green(isZh ? "卸载成功! 😊" : "Uninstalled successfully! 😊"));
711
+ else loading_status.fail(picocolors.default.red(isZh ? "卸载失败 😭" : "Failed to uninstall 😭"));
712
+ } else if (exec === "prun") {
713
+ const target = (await (0, fast_glob.default)(params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go"))[0];
714
+ if (target) return await (0, lazy_js_utils_node.jsShell)(`go run ${target}`, "inherit");
715
+ const { ccommand } = localRequire("ccommand");
716
+ return ccommand(params);
717
+ } else if (exec === "pinit") await (0, lazy_js_utils_node.jsShell)(`go mod init ${params}`, "inherit");
718
+ else if (exec === "pbuild") await (0, lazy_js_utils_node.jsShell)(`go build ${params}`, "inherit");
719
+ else console.log(picocolors.default.red(isZh ? "当前指令还不支持" : "The commands is not supported"));
720
+ node_process.default.exit();
721
+ }
722
+ let projectPath = "";
723
+ if (params && !await (0, lazy_js_utils_node.isRust)()) {
724
+ projectPath = params.split(" ")[0];
725
+ rootPath = node_path.default.resolve(rootPath, projectPath);
726
+ params = params.replace(projectPath, "").trim();
727
+ }
728
+ if (await (0, lazy_js_utils_node.isRust)(rootPath)) {
729
+ if (exec === "pi") {
730
+ const loading_status = await loading(`${isZh ? "正在为您安装" : "Installing"} ${params} ...\n`);
731
+ const { status } = await (0, lazy_js_utils_node.useNodeWorker)(`cargo install ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`);
732
+ if (status === 0) loading_status.succeed(picocolors.default.green(isZh ? "安装成功! 😊" : "Installed successfully! 😊"));
733
+ else loading_status.fail(picocolors.default.red(isZh ? "安装失败 😭" : "Failed to install 😭"));
734
+ } else if (exec === "pui") {
735
+ const loading_status = await loading(`${isZh ? "正在为您卸载" : "Uninstalling"} ${params} ...\n`);
736
+ const { status } = await (0, lazy_js_utils_node.useNodeWorker)(`cargo uninstall ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`);
737
+ if (status === 0) loading_status.succeed(picocolors.default.green(isZh ? "卸载成功! 😊" : "Uninstalled successfully! 😊"));
738
+ else loading_status.fail(picocolors.default.red(isZh ? "卸载失败 😭" : "Failed to uninstall 😭"));
739
+ } else if (exec === "prun") await (0, lazy_js_utils_node.jsShell)(`cargo run ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`, "inherit");
740
+ else if (exec === "pinit") await (0, lazy_js_utils_node.jsShell)(`cargo init ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`, "inherit");
741
+ else if (exec === "pbuild") await (0, lazy_js_utils_node.jsShell)(`cargo build ${params}${projectPath ? `--manifest-path=./${projectPath}/Cargo.toml` : ""}`, "inherit");
742
+ else console.log(picocolors.default.red(isZh ? "当前指令还不支持" : "The commands is not supported"));
743
+ node_process.default.exit();
744
+ }
745
+ }
746
+ const handler = runMap[exec];
747
+ if (!handler) {
748
+ if (exec === "pbuild" || exec === "pbuild.mjs") console.log(picocolors.default.yellow(isZh ? "pbuild 仅支持 Go/Rust 项目(go build / cargo build)。" : "pbuild is only supported for Go/Rust projects (go build / cargo build)."));
749
+ else console.log(picocolors.default.yellow(isZh ? "命令不存在, 请执行 pi -h 查看帮助" : "The command does not exist, please execute pi -h to view the help"));
750
+ return;
751
+ }
752
+ const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
753
+ await installDeps();
754
+ await handler(params, pkg);
765
755
  }
766
- setup();
767
- // Annotate the CommonJS export names for ESM import in node:
768
- 0 && (module.exports = {
769
- setup
756
+ if (!node_process.default.env.PI_TEST) setup().catch((error) => {
757
+ console.error(error);
758
+ node_process.default.exit(1);
770
759
  });
760
+
761
+ //#endregion
762
+ exports.setup = setup;