sunnah 1.1.3 → 1.1.4
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.
Potentially problematic release.
This version of sunnah might be problematic. Click here for more details.
- package/bin/index.js +28 -7
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -172,19 +172,31 @@ function animateInstall(pkgName) {
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
// ── Check
|
|
176
|
-
|
|
175
|
+
// ── Check installed status ONCE at startup, cache forever ───────────────────
|
|
176
|
+
// Calling npm on every render was freezing the terminal. We run one
|
|
177
|
+
// 'npm list -g' at startup, parse the output, and never shell out again.
|
|
178
|
+
function buildInstalledCache() {
|
|
179
|
+
const cache = new Map();
|
|
180
|
+
let out = "";
|
|
177
181
|
try {
|
|
178
|
-
execSync(`${NPM} list -g
|
|
179
|
-
|
|
182
|
+
out = execSync(`${NPM} list -g --depth=0`, {
|
|
183
|
+
encoding: "utf8",
|
|
180
184
|
shell: isWin,
|
|
185
|
+
timeout: 8000,
|
|
186
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
181
187
|
});
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return false;
|
|
188
|
+
} catch (e) {
|
|
189
|
+
out = e.stdout || "";
|
|
185
190
|
}
|
|
191
|
+
for (const p of PACKAGES) {
|
|
192
|
+
cache.set(p.name, out.includes(p.name));
|
|
193
|
+
}
|
|
194
|
+
return cache;
|
|
186
195
|
}
|
|
187
196
|
|
|
197
|
+
let installedCache = new Map();
|
|
198
|
+
const isInstalled = (name) => installedCache.get(name) ?? false;
|
|
199
|
+
|
|
188
200
|
// ── Render the interactive list ───────────────────────────────────────────────
|
|
189
201
|
const DIV_W = () => Math.min(W() - 2, 70);
|
|
190
202
|
|
|
@@ -326,6 +338,7 @@ async function main() {
|
|
|
326
338
|
|
|
327
339
|
// --list
|
|
328
340
|
if (flags.some((f) => f === "--list" || f === "-l")) {
|
|
341
|
+
installedCache = buildInstalledCache();
|
|
329
342
|
const div = gray("─".repeat(60));
|
|
330
343
|
console.log("");
|
|
331
344
|
console.log(div);
|
|
@@ -353,6 +366,13 @@ async function main() {
|
|
|
353
366
|
process.exit(1);
|
|
354
367
|
}
|
|
355
368
|
|
|
369
|
+
// Build installed cache once — never call npm during rendering
|
|
370
|
+
process.stdout.write(
|
|
371
|
+
"\n " + "\x1b[90m" + "Checking installed packages…" + "\x1b[0m",
|
|
372
|
+
);
|
|
373
|
+
installedCache = buildInstalledCache();
|
|
374
|
+
process.stdout.write("\r\x1b[K");
|
|
375
|
+
|
|
356
376
|
readline.emitKeypressEvents(process.stdin);
|
|
357
377
|
process.stdin.setRawMode(true);
|
|
358
378
|
hideCursor();
|
|
@@ -454,6 +474,7 @@ async function main() {
|
|
|
454
474
|
console.log("");
|
|
455
475
|
|
|
456
476
|
await animateInstall(p.name);
|
|
477
|
+
installedCache.set(p.name, true); // update cache
|
|
457
478
|
|
|
458
479
|
console.log(
|
|
459
480
|
` ${green("✓")} ${bold(green(p.label))} installed successfully`,
|