@simon_he/pi 0.1.17 → 0.1.19

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.
Files changed (3) hide show
  1. package/dist/index.cjs +53 -14
  2. package/dist/index.js +53 -14
  3. package/package.json +10 -10
package/dist/index.cjs CHANGED
@@ -46,7 +46,7 @@ var import_node_process = __toESM(require("process"), 1);
46
46
  var import_node = require("lazy-js-utils/node");
47
47
 
48
48
  // package.json
49
- var version = "0.1.17";
49
+ var version = "0.1.19";
50
50
 
51
51
  // src/help.ts
52
52
  var isZh = import_node_process.default.env.PI_Lang === "zh";
@@ -131,7 +131,7 @@ async function detectNode() {
131
131
  let pkg;
132
132
  try {
133
133
  pkg = await (0, import_node4.getPkg)();
134
- } catch (_) {
134
+ } catch {
135
135
  const cwd = import_node_process3.default.cwd();
136
136
  console.log(import_picocolors2.default.red(`\u5F53\u524D\u76EE\u5F55: ${cwd} \u6CA1\u6709package.json\u6587\u4EF6`));
137
137
  import_node_process3.default.exit(1);
@@ -218,6 +218,8 @@ async function getParams(params) {
218
218
  return params.replace(W, "");
219
219
  if (w.test(params))
220
220
  return params.replace(w, "");
221
+ if (d.test(params))
222
+ return params.replace(d, " -D");
221
223
  }
222
224
  if ((await (0, import_node5.getPkg)())?.workspaces) {
223
225
  if (D.test(params))
@@ -231,12 +233,12 @@ async function getParams(params) {
231
233
  if (Dw.test(params))
232
234
  return params.replace(Dw, " -DW");
233
235
  if (W.test(params))
234
- return params.replace(w, " -W");
236
+ return params.replace(W, " -W");
235
237
  return params;
236
238
  default:
237
- return params;
239
+ return d.test(params) ? params.replace(d, " -D") : params;
238
240
  }
239
- } catch (_) {
241
+ } catch {
240
242
  console.log(
241
243
  import_picocolors3.default.red(
242
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()}`
@@ -319,7 +321,11 @@ async function pi(params, pkg, executor = "ni") {
319
321
  }
320
322
  const newParams = isLatest ? "" : await getParams(params);
321
323
  const runSockets = executor.split(" ")[0] === "npm" ? ` --max-sockets=${maxSockets}` : "";
322
- console.log(import_picocolors4.default.green(isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`));
324
+ console.log(
325
+ import_picocolors4.default.green(
326
+ isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`
327
+ )
328
+ );
323
329
  let { status, result } = await (0, import_node6.useNodeWorker)({
324
330
  params: isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`,
325
331
  stdio,
@@ -387,7 +393,9 @@ async function pil(params) {
387
393
  const { dependencies = {}, devDependencies = {} } = await (0, import_node7.getPkg)();
388
394
  if (!params) {
389
395
  const deps = [
390
- ...Object.keys(dependencies).map((key) => `${key}: ${dependencies[key].replace(/([><~])/g, "\\$1")}`),
396
+ ...Object.keys(dependencies).map(
397
+ (key) => `${key}: ${dependencies[key].replace(/([><~])/g, "\\$1")}`
398
+ ),
391
399
  ...Object.keys(devDependencies).map(
392
400
  (key) => `${key}: ${devDependencies[key].replace(/([><~])/g, "\\$1")}`
393
401
  )
@@ -428,14 +436,45 @@ async function pil(params) {
428
436
  const v = dependencies[i] || devDependencies[i];
429
437
  return `${i}$${v}`;
430
438
  }).join(" ");
431
- const group = {};
432
- const items = command.replace(/\s+/, " ").trim().split(" ").map((i, idx) => [i, suffix[idx] || "-s"]);
433
- for (const [pkg, flag] of items) {
434
- if (!group[flag])
435
- group[flag] = [];
436
- group[flag].push(pkg);
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;
437
450
  }
438
- const cmds = Object.entries(group).map(([flag, pkgs]) => `${pkgs.join(" ")} ${flag}`);
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}` : ""}`);
439
478
  return await pi(cmds, latestPkgname.replace(/@latest/g, ""), "pil");
440
479
  }
441
480
 
package/dist/index.js CHANGED
@@ -25,7 +25,7 @@ import process from "process";
25
25
  import { jsShell } from "lazy-js-utils/node";
26
26
 
27
27
  // package.json
28
- var version = "0.1.17";
28
+ var version = "0.1.19";
29
29
 
30
30
  // src/help.ts
31
31
  var isZh = process.env.PI_Lang === "zh";
@@ -110,7 +110,7 @@ async function detectNode() {
110
110
  let pkg;
111
111
  try {
112
112
  pkg = await getPkg();
113
- } catch (_) {
113
+ } catch {
114
114
  const cwd = process3.cwd();
115
115
  console.log(colors.red(`\u5F53\u524D\u76EE\u5F55: ${cwd} \u6CA1\u6709package.json\u6587\u4EF6`));
116
116
  process3.exit(1);
@@ -197,6 +197,8 @@ async function getParams(params) {
197
197
  return params.replace(W, "");
198
198
  if (w.test(params))
199
199
  return params.replace(w, "");
200
+ if (d.test(params))
201
+ return params.replace(d, " -D");
200
202
  }
201
203
  if ((await getPkg2())?.workspaces) {
202
204
  if (D.test(params))
@@ -210,12 +212,12 @@ async function getParams(params) {
210
212
  if (Dw.test(params))
211
213
  return params.replace(Dw, " -DW");
212
214
  if (W.test(params))
213
- return params.replace(w, " -W");
215
+ return params.replace(W, " -W");
214
216
  return params;
215
217
  default:
216
- return params;
218
+ return d.test(params) ? params.replace(d, " -D") : params;
217
219
  }
218
- } catch (_) {
220
+ } catch {
219
221
  console.log(
220
222
  colors2.red(
221
223
  `${isZh2 ? "package.json\u5E76\u4E0D\u5B58\u5728,\u5728\u4EE5\u4E0B\u76EE\u5F55\u4E2D:" : "package.json has not been found in"} ${process4.cwd()}`
@@ -298,7 +300,11 @@ async function pi(params, pkg, executor = "ni") {
298
300
  }
299
301
  const newParams = isLatest ? "" : await getParams(params);
300
302
  const runSockets = executor.split(" ")[0] === "npm" ? ` --max-sockets=${maxSockets}` : "";
301
- console.log(colors3.green(isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`));
303
+ console.log(
304
+ colors3.green(
305
+ isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`
306
+ )
307
+ );
302
308
  let { status, result } = await useNodeWorker({
303
309
  params: isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`,
304
310
  stdio,
@@ -366,7 +372,9 @@ async function pil(params) {
366
372
  const { dependencies = {}, devDependencies = {} } = await getPkg3();
367
373
  if (!params) {
368
374
  const deps = [
369
- ...Object.keys(dependencies).map((key) => `${key}: ${dependencies[key].replace(/([><~])/g, "\\$1")}`),
375
+ ...Object.keys(dependencies).map(
376
+ (key) => `${key}: ${dependencies[key].replace(/([><~])/g, "\\$1")}`
377
+ ),
370
378
  ...Object.keys(devDependencies).map(
371
379
  (key) => `${key}: ${devDependencies[key].replace(/([><~])/g, "\\$1")}`
372
380
  )
@@ -407,14 +415,45 @@ async function pil(params) {
407
415
  const v = dependencies[i] || devDependencies[i];
408
416
  return `${i}$${v}`;
409
417
  }).join(" ");
410
- const group = {};
411
- const items = command.replace(/\s+/, " ").trim().split(" ").map((i, idx) => [i, suffix[idx] || "-s"]);
412
- for (const [pkg, flag] of items) {
413
- if (!group[flag])
414
- group[flag] = [];
415
- group[flag].push(pkg);
418
+ const tokens = command.replace(/\s+/, " ").trim().split(" ").filter(Boolean);
419
+ const pkgs = tokens.filter((t) => !t.startsWith("-"));
420
+ let globalWorkspaceFlag = null;
421
+ const perFlags = [];
422
+ let assignIdx = 0;
423
+ for (const f of suffix) {
424
+ if (/^-(?:w|W)$/.test(f)) {
425
+ globalWorkspaceFlag = f;
426
+ continue;
427
+ }
428
+ perFlags[assignIdx++] = f;
416
429
  }
417
- const cmds = Object.entries(group).map(([flag, pkgs]) => `${pkgs.join(" ")} ${flag}`);
430
+ const normalizeFlag = (f) => {
431
+ if (!f)
432
+ return "";
433
+ if (/^-s$/i.test(f) || /^-S$/.test(f))
434
+ return "";
435
+ return f;
436
+ };
437
+ const combineWorkspace = (f, w2) => {
438
+ if (!w2)
439
+ return f;
440
+ if (/w/i.test(f))
441
+ return f;
442
+ if (!f)
443
+ return w2;
444
+ if (/d/i.test(f))
445
+ return `-D${w2.slice(1)}`;
446
+ return w2;
447
+ };
448
+ const finalFlags = pkgs.map((_, i) => combineWorkspace(normalizeFlag(perFlags[i]), globalWorkspaceFlag));
449
+ const group = {};
450
+ pkgs.forEach((p, i) => {
451
+ const key = finalFlags[i] || "";
452
+ if (!group[key])
453
+ group[key] = [];
454
+ group[key].push(p);
455
+ });
456
+ const cmds = Object.entries(group).map(([flag, list]) => `${list.join(" ")}${flag ? ` ${flag}` : ""}`);
418
457
  return await pi(cmds, latestPkgname.replace(/@latest/g, ""), "pil");
419
458
  }
420
459
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@simon_he/pi",
3
3
  "type": "module",
4
- "version": "0.1.17",
5
- "packageManager": "pnpm@10.12.1",
4
+ "version": "0.1.19",
5
+ "packageManager": "pnpm@10.18.1",
6
6
  "description": "An intelligent cross-platform package manager and CLI tool that autodetects project environments (Node.mjs, Go, Rust, Python) with beautiful loading animations and smart command execution.",
7
7
  "author": {
8
8
  "name": "Simon He",
@@ -90,23 +90,23 @@
90
90
  "test": "vitest"
91
91
  },
92
92
  "dependencies": {
93
- "ccommand": "^1.0.85",
93
+ "ccommand": "^1.0.87",
94
94
  "fast-glob": "^3.3.3",
95
- "lazy-js-utils": "^0.1.44",
95
+ "lazy-js-utils": "^0.1.47",
96
96
  "ora": "^8.2.0",
97
97
  "picocolors": "^1.1.1",
98
98
  "semver": "^7.7.2"
99
99
  },
100
100
  "devDependencies": {
101
- "@antfu/eslint-config": "^4.15.0",
102
- "@types/node": "^22.15.31",
103
- "bumpp": "^10.2.0",
104
- "eslint": "^9.29.0",
101
+ "@antfu/eslint-config": "^4.19.0",
102
+ "@types/node": "^22.18.1",
103
+ "bumpp": "^10.2.3",
104
+ "eslint": "^9.35.0",
105
105
  "lint-staged": "^13.3.0",
106
106
  "prettier": "^2.8.8",
107
107
  "tsup": "^8.5.0",
108
- "tsx": "^4.20.3",
109
- "typescript": "^5.8.3",
108
+ "tsx": "^4.20.5",
109
+ "typescript": "^5.9.2",
110
110
  "vitest": "^3.2.4"
111
111
  },
112
112
  "lint-staged": {