@simon_he/pi 0.1.19 → 0.1.20
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 +171 -8
- package/dist/index.js +174 -11
- package/package.json +9 -9
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.
|
|
49
|
+
var version = "0.1.20";
|
|
50
50
|
|
|
51
51
|
// src/help.ts
|
|
52
52
|
var isZh = import_node_process.default.env.PI_Lang === "zh";
|
|
@@ -165,6 +165,8 @@ no" | gum filter --placeholder=" \u5F53\u524Dnode\u7248\u672C\u4E0D\u6EE1\u8DB3
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
// src/utils.ts
|
|
168
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
169
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
168
170
|
var import_node_path = __toESM(require("path"), 1);
|
|
169
171
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
170
172
|
var import_lazy_js_utils = require("lazy-js-utils");
|
|
@@ -177,6 +179,7 @@ var w = /\s-w/g;
|
|
|
177
179
|
var D = /\s-D(?!w)/g;
|
|
178
180
|
var d = /\s-d(?!w)/g;
|
|
179
181
|
var isZh2 = import_node_process4.default.env.PI_Lang === "zh";
|
|
182
|
+
var log = console.log;
|
|
180
183
|
async function getParams(params) {
|
|
181
184
|
const root = import_node_process4.default.cwd();
|
|
182
185
|
try {
|
|
@@ -285,6 +288,165 @@ async function getLatestVersion(pkg, isZh6 = true) {
|
|
|
285
288
|
}
|
|
286
289
|
return `${data.join(" ")}${isZh6 ? " \u5B89\u88C5\u6210\u529F! \u{1F60A}" : " successfully! \u{1F60A}"}`;
|
|
287
290
|
}
|
|
291
|
+
async function pushHistory(command) {
|
|
292
|
+
log(
|
|
293
|
+
import_picocolors3.default.bold(
|
|
294
|
+
import_picocolors3.default.blue(`${isZh2 ? "\u5FEB\u6377\u6307\u4EE4" : "shortcut command"}: ${command}`)
|
|
295
|
+
)
|
|
296
|
+
);
|
|
297
|
+
const currentShell = import_node_process4.default.env.SHELL || "/bin/bash";
|
|
298
|
+
const shellName = currentShell.split("/").pop() || "bash";
|
|
299
|
+
let historyFile = "";
|
|
300
|
+
let historyFormat = "bash";
|
|
301
|
+
const home = import_node_process4.default.env.HOME || import_node_os.default.homedir();
|
|
302
|
+
switch (shellName) {
|
|
303
|
+
case "zsh":
|
|
304
|
+
historyFile = import_node_path.default.join(home, ".zsh_history");
|
|
305
|
+
historyFormat = "zsh";
|
|
306
|
+
break;
|
|
307
|
+
case "bash":
|
|
308
|
+
historyFile = import_node_process4.default.env.HISTFILE || import_node_path.default.join(home, ".bash_history");
|
|
309
|
+
historyFormat = "bash";
|
|
310
|
+
break;
|
|
311
|
+
case "fish":
|
|
312
|
+
historyFile = import_node_path.default.join(home, ".local", "share", "fish", "fish_history");
|
|
313
|
+
historyFormat = "fish";
|
|
314
|
+
break;
|
|
315
|
+
default:
|
|
316
|
+
historyFile = import_node_process4.default.env.HISTFILE || import_node_path.default.join(home, ".bash_history");
|
|
317
|
+
historyFormat = "bash";
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
let parseEntries2 = function(content) {
|
|
321
|
+
if (historyFormat === "fish") {
|
|
322
|
+
const lines = content.split(/\r?\n/);
|
|
323
|
+
const blocks = [];
|
|
324
|
+
let buffer = [];
|
|
325
|
+
for (const line of lines) {
|
|
326
|
+
if (line.startsWith("- cmd: ")) {
|
|
327
|
+
if (buffer.length) {
|
|
328
|
+
blocks.push(buffer.join("\n"));
|
|
329
|
+
buffer = [];
|
|
330
|
+
}
|
|
331
|
+
buffer.push(line);
|
|
332
|
+
} else if (buffer.length) {
|
|
333
|
+
buffer.push(line);
|
|
334
|
+
} else if (line.trim() !== "") {
|
|
335
|
+
blocks.push(line);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (buffer.length)
|
|
339
|
+
blocks.push(buffer.join("\n"));
|
|
340
|
+
return blocks.filter(Boolean);
|
|
341
|
+
} else if (historyFormat === "zsh") {
|
|
342
|
+
return content.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
343
|
+
} else {
|
|
344
|
+
const lines = content.split(/\r?\n/);
|
|
345
|
+
const entries2 = [];
|
|
346
|
+
for (let i = 0; i < lines.length; i++) {
|
|
347
|
+
const line = lines[i];
|
|
348
|
+
if (line.startsWith("#")) {
|
|
349
|
+
const next = lines[i + 1] ?? "";
|
|
350
|
+
entries2.push(`${line}
|
|
351
|
+
${next}`);
|
|
352
|
+
i++;
|
|
353
|
+
} else if (line.trim() !== "") {
|
|
354
|
+
entries2.push(line);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return entries2;
|
|
358
|
+
}
|
|
359
|
+
}, extractCommand2 = function(entry) {
|
|
360
|
+
if (historyFormat === "fish") {
|
|
361
|
+
const m = entry.split("\n")[0].match(/^- cmd: (.*)$/);
|
|
362
|
+
return m ? m[1] : entry;
|
|
363
|
+
} else if (historyFormat === "zsh") {
|
|
364
|
+
const m = entry.match(/^[^;]*;(.+)$/);
|
|
365
|
+
return m ? m[1] : entry;
|
|
366
|
+
} else {
|
|
367
|
+
if (entry.startsWith("#")) {
|
|
368
|
+
const parts = entry.split(/\r?\n/);
|
|
369
|
+
return parts[1] ?? parts[0];
|
|
370
|
+
}
|
|
371
|
+
return entry;
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
var parseEntries = parseEntries2, extractCommand = extractCommand2;
|
|
375
|
+
if (!import_node_fs.default.existsSync(historyFile)) {
|
|
376
|
+
log(
|
|
377
|
+
import_picocolors3.default.yellow(
|
|
378
|
+
`${isZh2 ? `\u672A\u627E\u5230 ${shellName} \u5386\u53F2\u6587\u4EF6` : `${shellName} history file not found`}`
|
|
379
|
+
)
|
|
380
|
+
);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const raw = import_node_fs.default.readFileSync(historyFile, "utf8");
|
|
384
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
385
|
+
let newEntry = "";
|
|
386
|
+
if (historyFormat === "zsh") {
|
|
387
|
+
newEntry = `: ${timestamp}:0;${command}`;
|
|
388
|
+
} else if (historyFormat === "fish") {
|
|
389
|
+
newEntry = `- cmd: ${command}
|
|
390
|
+
when: ${timestamp}`;
|
|
391
|
+
} else {
|
|
392
|
+
if (import_node_process4.default.env.HISTTIMEFORMAT) {
|
|
393
|
+
newEntry = `#${timestamp}
|
|
394
|
+
${command}`;
|
|
395
|
+
} else {
|
|
396
|
+
newEntry = command;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const entries = parseEntries2(raw);
|
|
400
|
+
const newEntries = [];
|
|
401
|
+
const newCmd = extractCommand2(newEntry);
|
|
402
|
+
let existingFishBlock = null;
|
|
403
|
+
for (const e of entries) {
|
|
404
|
+
const cmd = extractCommand2(e);
|
|
405
|
+
if (cmd === newCmd) {
|
|
406
|
+
if (historyFormat === "fish") {
|
|
407
|
+
existingFishBlock = e;
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
newEntries.push(e);
|
|
413
|
+
}
|
|
414
|
+
if (historyFormat === "fish" && existingFishBlock) {
|
|
415
|
+
const lines = existingFishBlock.split("\n");
|
|
416
|
+
let hasWhen = false;
|
|
417
|
+
const updated = lines.map((line) => {
|
|
418
|
+
if (line.trim().startsWith("when:") || line.startsWith(" when:")) {
|
|
419
|
+
hasWhen = true;
|
|
420
|
+
return ` when: ${timestamp}`;
|
|
421
|
+
}
|
|
422
|
+
return line;
|
|
423
|
+
});
|
|
424
|
+
if (!hasWhen) {
|
|
425
|
+
updated.splice(1, 0, ` when: ${timestamp}`);
|
|
426
|
+
}
|
|
427
|
+
newEntries.push(updated.join("\n"));
|
|
428
|
+
} else {
|
|
429
|
+
newEntries.push(newEntry);
|
|
430
|
+
}
|
|
431
|
+
let finalContent = "";
|
|
432
|
+
if (historyFormat === "fish") {
|
|
433
|
+
finalContent = `${newEntries.map((e) => e.trimEnd()).join("\n")}
|
|
434
|
+
`;
|
|
435
|
+
} else {
|
|
436
|
+
finalContent = `${newEntries.join("\n")}
|
|
437
|
+
`;
|
|
438
|
+
}
|
|
439
|
+
const tmpPath = `${historyFile}.ccommand.tmp`;
|
|
440
|
+
import_node_fs.default.writeFileSync(tmpPath, finalContent, "utf8");
|
|
441
|
+
import_node_fs.default.renameSync(tmpPath, historyFile);
|
|
442
|
+
} catch (err) {
|
|
443
|
+
log(
|
|
444
|
+
import_picocolors3.default.red(
|
|
445
|
+
`${isZh2 ? `\u274C \u6DFB\u52A0\u5230 ${shellName} \u5386\u53F2\u8BB0\u5F55\u5931\u8D25` : `\u274C Failed to add to ${shellName} history`}${err ? `: ${String(err)}` : ""}`
|
|
446
|
+
)
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
288
450
|
|
|
289
451
|
// src/pi.ts
|
|
290
452
|
var isZh3 = import_node_process5.default.env.PI_Lang === "zh";
|
|
@@ -321,11 +483,7 @@ async function pi(params, pkg, executor = "ni") {
|
|
|
321
483
|
}
|
|
322
484
|
const newParams = isLatest ? "" : await getParams(params);
|
|
323
485
|
const runSockets = executor.split(" ")[0] === "npm" ? ` --max-sockets=${maxSockets}` : "";
|
|
324
|
-
|
|
325
|
-
import_picocolors4.default.green(
|
|
326
|
-
isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`
|
|
327
|
-
)
|
|
328
|
-
);
|
|
486
|
+
const runCmd = isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`;
|
|
329
487
|
let { status, result } = await (0, import_node6.useNodeWorker)({
|
|
330
488
|
params: isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`,
|
|
331
489
|
stdio,
|
|
@@ -354,6 +512,7 @@ async function pi(params, pkg, executor = "ni") {
|
|
|
354
512
|
successMsg += import_picocolors4.default.blue(` ---- \u23F0\uFF1A${costTime}s`);
|
|
355
513
|
if (status === 0) {
|
|
356
514
|
loading_status.succeed(import_picocolors4.default.green(successMsg));
|
|
515
|
+
pushHistory(runCmd);
|
|
357
516
|
} else if (result && result.includes("Not Found - 404")) {
|
|
358
517
|
const _pkg = result.match(/\/[^/:]+:/)?.[0].slice(1, -1);
|
|
359
518
|
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`;
|
|
@@ -466,7 +625,9 @@ async function pil(params) {
|
|
|
466
625
|
return `-D${w2.slice(1)}`;
|
|
467
626
|
return w2;
|
|
468
627
|
};
|
|
469
|
-
const finalFlags = pkgs.map(
|
|
628
|
+
const finalFlags = pkgs.map(
|
|
629
|
+
(_, i) => combineWorkspace(normalizeFlag(perFlags[i]), globalWorkspaceFlag)
|
|
630
|
+
);
|
|
470
631
|
const group = {};
|
|
471
632
|
pkgs.forEach((p, i) => {
|
|
472
633
|
const key = finalFlags[i] || "";
|
|
@@ -474,7 +635,9 @@ async function pil(params) {
|
|
|
474
635
|
group[key] = [];
|
|
475
636
|
group[key].push(p);
|
|
476
637
|
});
|
|
477
|
-
const cmds = Object.entries(group).map(
|
|
638
|
+
const cmds = Object.entries(group).map(
|
|
639
|
+
([flag, list]) => `${list.join(" ")}${flag ? ` ${flag}` : ""}`
|
|
640
|
+
);
|
|
478
641
|
return await pi(cmds, latestPkgname.replace(/@latest/g, ""), "pil");
|
|
479
642
|
}
|
|
480
643
|
|
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.
|
|
28
|
+
var version = "0.1.20";
|
|
29
29
|
|
|
30
30
|
// src/help.ts
|
|
31
31
|
var isZh = process.env.PI_Lang === "zh";
|
|
@@ -97,7 +97,7 @@ function pa() {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// src/pi.ts
|
|
100
|
-
import { log } from "console";
|
|
100
|
+
import { log as log2 } from "console";
|
|
101
101
|
import process5 from "process";
|
|
102
102
|
import { getPkgTool as getPkgTool2, jsShell as jsShell6, useNodeWorker } from "lazy-js-utils/node";
|
|
103
103
|
import colors3 from "picocolors";
|
|
@@ -144,6 +144,8 @@ no" | gum filter --placeholder=" \u5F53\u524Dnode\u7248\u672C\u4E0D\u6EE1\u8DB3
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
// src/utils.ts
|
|
147
|
+
import fs from "fs";
|
|
148
|
+
import os from "os";
|
|
147
149
|
import path from "path";
|
|
148
150
|
import process4 from "process";
|
|
149
151
|
import { isFile } from "lazy-js-utils";
|
|
@@ -156,6 +158,7 @@ var w = /\s-w/g;
|
|
|
156
158
|
var D = /\s-D(?!w)/g;
|
|
157
159
|
var d = /\s-d(?!w)/g;
|
|
158
160
|
var isZh2 = process4.env.PI_Lang === "zh";
|
|
161
|
+
var log = console.log;
|
|
159
162
|
async function getParams(params) {
|
|
160
163
|
const root = process4.cwd();
|
|
161
164
|
try {
|
|
@@ -264,6 +267,165 @@ async function getLatestVersion(pkg, isZh6 = true) {
|
|
|
264
267
|
}
|
|
265
268
|
return `${data.join(" ")}${isZh6 ? " \u5B89\u88C5\u6210\u529F! \u{1F60A}" : " successfully! \u{1F60A}"}`;
|
|
266
269
|
}
|
|
270
|
+
async function pushHistory(command) {
|
|
271
|
+
log(
|
|
272
|
+
colors2.bold(
|
|
273
|
+
colors2.blue(`${isZh2 ? "\u5FEB\u6377\u6307\u4EE4" : "shortcut command"}: ${command}`)
|
|
274
|
+
)
|
|
275
|
+
);
|
|
276
|
+
const currentShell = process4.env.SHELL || "/bin/bash";
|
|
277
|
+
const shellName = currentShell.split("/").pop() || "bash";
|
|
278
|
+
let historyFile = "";
|
|
279
|
+
let historyFormat = "bash";
|
|
280
|
+
const home = process4.env.HOME || os.homedir();
|
|
281
|
+
switch (shellName) {
|
|
282
|
+
case "zsh":
|
|
283
|
+
historyFile = path.join(home, ".zsh_history");
|
|
284
|
+
historyFormat = "zsh";
|
|
285
|
+
break;
|
|
286
|
+
case "bash":
|
|
287
|
+
historyFile = process4.env.HISTFILE || path.join(home, ".bash_history");
|
|
288
|
+
historyFormat = "bash";
|
|
289
|
+
break;
|
|
290
|
+
case "fish":
|
|
291
|
+
historyFile = path.join(home, ".local", "share", "fish", "fish_history");
|
|
292
|
+
historyFormat = "fish";
|
|
293
|
+
break;
|
|
294
|
+
default:
|
|
295
|
+
historyFile = process4.env.HISTFILE || path.join(home, ".bash_history");
|
|
296
|
+
historyFormat = "bash";
|
|
297
|
+
}
|
|
298
|
+
try {
|
|
299
|
+
let parseEntries2 = function(content) {
|
|
300
|
+
if (historyFormat === "fish") {
|
|
301
|
+
const lines = content.split(/\r?\n/);
|
|
302
|
+
const blocks = [];
|
|
303
|
+
let buffer = [];
|
|
304
|
+
for (const line of lines) {
|
|
305
|
+
if (line.startsWith("- cmd: ")) {
|
|
306
|
+
if (buffer.length) {
|
|
307
|
+
blocks.push(buffer.join("\n"));
|
|
308
|
+
buffer = [];
|
|
309
|
+
}
|
|
310
|
+
buffer.push(line);
|
|
311
|
+
} else if (buffer.length) {
|
|
312
|
+
buffer.push(line);
|
|
313
|
+
} else if (line.trim() !== "") {
|
|
314
|
+
blocks.push(line);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (buffer.length)
|
|
318
|
+
blocks.push(buffer.join("\n"));
|
|
319
|
+
return blocks.filter(Boolean);
|
|
320
|
+
} else if (historyFormat === "zsh") {
|
|
321
|
+
return content.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
322
|
+
} else {
|
|
323
|
+
const lines = content.split(/\r?\n/);
|
|
324
|
+
const entries2 = [];
|
|
325
|
+
for (let i = 0; i < lines.length; i++) {
|
|
326
|
+
const line = lines[i];
|
|
327
|
+
if (line.startsWith("#")) {
|
|
328
|
+
const next = lines[i + 1] ?? "";
|
|
329
|
+
entries2.push(`${line}
|
|
330
|
+
${next}`);
|
|
331
|
+
i++;
|
|
332
|
+
} else if (line.trim() !== "") {
|
|
333
|
+
entries2.push(line);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return entries2;
|
|
337
|
+
}
|
|
338
|
+
}, extractCommand2 = function(entry) {
|
|
339
|
+
if (historyFormat === "fish") {
|
|
340
|
+
const m = entry.split("\n")[0].match(/^- cmd: (.*)$/);
|
|
341
|
+
return m ? m[1] : entry;
|
|
342
|
+
} else if (historyFormat === "zsh") {
|
|
343
|
+
const m = entry.match(/^[^;]*;(.+)$/);
|
|
344
|
+
return m ? m[1] : entry;
|
|
345
|
+
} else {
|
|
346
|
+
if (entry.startsWith("#")) {
|
|
347
|
+
const parts = entry.split(/\r?\n/);
|
|
348
|
+
return parts[1] ?? parts[0];
|
|
349
|
+
}
|
|
350
|
+
return entry;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
var parseEntries = parseEntries2, extractCommand = extractCommand2;
|
|
354
|
+
if (!fs.existsSync(historyFile)) {
|
|
355
|
+
log(
|
|
356
|
+
colors2.yellow(
|
|
357
|
+
`${isZh2 ? `\u672A\u627E\u5230 ${shellName} \u5386\u53F2\u6587\u4EF6` : `${shellName} history file not found`}`
|
|
358
|
+
)
|
|
359
|
+
);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const raw = fs.readFileSync(historyFile, "utf8");
|
|
363
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
364
|
+
let newEntry = "";
|
|
365
|
+
if (historyFormat === "zsh") {
|
|
366
|
+
newEntry = `: ${timestamp}:0;${command}`;
|
|
367
|
+
} else if (historyFormat === "fish") {
|
|
368
|
+
newEntry = `- cmd: ${command}
|
|
369
|
+
when: ${timestamp}`;
|
|
370
|
+
} else {
|
|
371
|
+
if (process4.env.HISTTIMEFORMAT) {
|
|
372
|
+
newEntry = `#${timestamp}
|
|
373
|
+
${command}`;
|
|
374
|
+
} else {
|
|
375
|
+
newEntry = command;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const entries = parseEntries2(raw);
|
|
379
|
+
const newEntries = [];
|
|
380
|
+
const newCmd = extractCommand2(newEntry);
|
|
381
|
+
let existingFishBlock = null;
|
|
382
|
+
for (const e of entries) {
|
|
383
|
+
const cmd = extractCommand2(e);
|
|
384
|
+
if (cmd === newCmd) {
|
|
385
|
+
if (historyFormat === "fish") {
|
|
386
|
+
existingFishBlock = e;
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
newEntries.push(e);
|
|
392
|
+
}
|
|
393
|
+
if (historyFormat === "fish" && existingFishBlock) {
|
|
394
|
+
const lines = existingFishBlock.split("\n");
|
|
395
|
+
let hasWhen = false;
|
|
396
|
+
const updated = lines.map((line) => {
|
|
397
|
+
if (line.trim().startsWith("when:") || line.startsWith(" when:")) {
|
|
398
|
+
hasWhen = true;
|
|
399
|
+
return ` when: ${timestamp}`;
|
|
400
|
+
}
|
|
401
|
+
return line;
|
|
402
|
+
});
|
|
403
|
+
if (!hasWhen) {
|
|
404
|
+
updated.splice(1, 0, ` when: ${timestamp}`);
|
|
405
|
+
}
|
|
406
|
+
newEntries.push(updated.join("\n"));
|
|
407
|
+
} else {
|
|
408
|
+
newEntries.push(newEntry);
|
|
409
|
+
}
|
|
410
|
+
let finalContent = "";
|
|
411
|
+
if (historyFormat === "fish") {
|
|
412
|
+
finalContent = `${newEntries.map((e) => e.trimEnd()).join("\n")}
|
|
413
|
+
`;
|
|
414
|
+
} else {
|
|
415
|
+
finalContent = `${newEntries.join("\n")}
|
|
416
|
+
`;
|
|
417
|
+
}
|
|
418
|
+
const tmpPath = `${historyFile}.ccommand.tmp`;
|
|
419
|
+
fs.writeFileSync(tmpPath, finalContent, "utf8");
|
|
420
|
+
fs.renameSync(tmpPath, historyFile);
|
|
421
|
+
} catch (err) {
|
|
422
|
+
log(
|
|
423
|
+
colors2.red(
|
|
424
|
+
`${isZh2 ? `\u274C \u6DFB\u52A0\u5230 ${shellName} \u5386\u53F2\u8BB0\u5F55\u5931\u8D25` : `\u274C Failed to add to ${shellName} history`}${err ? `: ${String(err)}` : ""}`
|
|
425
|
+
)
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
267
429
|
|
|
268
430
|
// src/pi.ts
|
|
269
431
|
var isZh3 = process5.env.PI_Lang === "zh";
|
|
@@ -300,19 +462,15 @@ async function pi(params, pkg, executor = "ni") {
|
|
|
300
462
|
}
|
|
301
463
|
const newParams = isLatest ? "" : await getParams(params);
|
|
302
464
|
const runSockets = executor.split(" ")[0] === "npm" ? ` --max-sockets=${maxSockets}` : "";
|
|
303
|
-
|
|
304
|
-
colors3.green(
|
|
305
|
-
isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`
|
|
306
|
-
)
|
|
307
|
-
);
|
|
465
|
+
const runCmd = isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`;
|
|
308
466
|
let { status, result } = await useNodeWorker({
|
|
309
467
|
params: isLatest ? params.map((p) => `${executor} ${p}`).join(" & ") : `${executor}${newParams ? ` ${newParams}` : runSockets}`,
|
|
310
468
|
stdio,
|
|
311
469
|
errorExit: false
|
|
312
470
|
});
|
|
313
471
|
if (result && result.includes("pnpm versions with respective Node.js version support")) {
|
|
314
|
-
|
|
315
|
-
|
|
472
|
+
log2(result);
|
|
473
|
+
log2(
|
|
316
474
|
colors3.yellow(
|
|
317
475
|
isZh3 ? "\u6B63\u5728\u5C1D\u8BD5\u4F7F\u7528 npm \u518D\u6B21\u6267\u884C..." : "Trying to use npm to run again..."
|
|
318
476
|
)
|
|
@@ -333,6 +491,7 @@ async function pi(params, pkg, executor = "ni") {
|
|
|
333
491
|
successMsg += colors3.blue(` ---- \u23F0\uFF1A${costTime}s`);
|
|
334
492
|
if (status === 0) {
|
|
335
493
|
loading_status.succeed(colors3.green(successMsg));
|
|
494
|
+
pushHistory(runCmd);
|
|
336
495
|
} else if (result && result.includes("Not Found - 404")) {
|
|
337
496
|
const _pkg = result.match(/\/[^/:]+:/)?.[0].slice(1, -1);
|
|
338
497
|
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`;
|
|
@@ -445,7 +604,9 @@ async function pil(params) {
|
|
|
445
604
|
return `-D${w2.slice(1)}`;
|
|
446
605
|
return w2;
|
|
447
606
|
};
|
|
448
|
-
const finalFlags = pkgs.map(
|
|
607
|
+
const finalFlags = pkgs.map(
|
|
608
|
+
(_, i) => combineWorkspace(normalizeFlag(perFlags[i]), globalWorkspaceFlag)
|
|
609
|
+
);
|
|
449
610
|
const group = {};
|
|
450
611
|
pkgs.forEach((p, i) => {
|
|
451
612
|
const key = finalFlags[i] || "";
|
|
@@ -453,7 +614,9 @@ async function pil(params) {
|
|
|
453
614
|
group[key] = [];
|
|
454
615
|
group[key].push(p);
|
|
455
616
|
});
|
|
456
|
-
const cmds = Object.entries(group).map(
|
|
617
|
+
const cmds = Object.entries(group).map(
|
|
618
|
+
([flag, list]) => `${list.join(" ")}${flag ? ` ${flag}` : ""}`
|
|
619
|
+
);
|
|
457
620
|
return await pi(cmds, latestPkgname.replace(/@latest/g, ""), "pil");
|
|
458
621
|
}
|
|
459
622
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simon_he/pi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"packageManager": "pnpm@10.
|
|
4
|
+
"version": "0.1.20",
|
|
5
|
+
"packageManager": "pnpm@10.20.0",
|
|
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",
|
|
@@ -92,21 +92,21 @@
|
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"ccommand": "^1.0.87",
|
|
94
94
|
"fast-glob": "^3.3.3",
|
|
95
|
-
"lazy-js-utils": "^0.1.
|
|
95
|
+
"lazy-js-utils": "^0.1.49",
|
|
96
96
|
"ora": "^8.2.0",
|
|
97
97
|
"picocolors": "^1.1.1",
|
|
98
|
-
"semver": "^7.7.
|
|
98
|
+
"semver": "^7.7.3"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@antfu/eslint-config": "^4.19.0",
|
|
102
|
-
"@types/node": "^22.
|
|
103
|
-
"bumpp": "^10.
|
|
104
|
-
"eslint": "^9.
|
|
102
|
+
"@types/node": "^22.19.0",
|
|
103
|
+
"bumpp": "^10.3.1",
|
|
104
|
+
"eslint": "^9.39.0",
|
|
105
105
|
"lint-staged": "^13.3.0",
|
|
106
106
|
"prettier": "^2.8.8",
|
|
107
107
|
"tsup": "^8.5.0",
|
|
108
|
-
"tsx": "^4.20.
|
|
109
|
-
"typescript": "^5.9.
|
|
108
|
+
"tsx": "^4.20.6",
|
|
109
|
+
"typescript": "^5.9.3",
|
|
110
110
|
"vitest": "^3.2.4"
|
|
111
111
|
},
|
|
112
112
|
"lint-staged": {
|