periderm-cli 0.1.43 → 0.1.46
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/README.md +1 -1
- package/dist/api.js +27 -0
- package/dist/index.js +96 -3
- package/dist/lighthouse.js +44 -0
- package/dist/scanner/repo-checks.js +41 -5
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Pre-launch scanner for web and mobile codebases — context-aware checks for JS,
|
|
|
10
10
|
npm install -g periderm-cli
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Or use the install script from your Periderm dashboard docs (`curl -fsSL
|
|
13
|
+
Or use the install script from your Periderm dashboard docs (`curl -fsSL https://periderm-cli.vercel.app//install.sh | bash`).
|
|
14
14
|
|
|
15
15
|
## Quick start
|
|
16
16
|
|
package/dist/api.js
CHANGED
|
@@ -58,6 +58,33 @@ export async function uploadScan(token, result) {
|
|
|
58
58
|
return { error: e.message || "Network error: failed to reach server" };
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
export async function uploadLighthouseScan(token, result) {
|
|
62
|
+
const { apiUrl } = readConfig();
|
|
63
|
+
try {
|
|
64
|
+
const res = await fetch(`${apiUrl}/api/public/lighthouse`, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: {
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
"x-periderm-token": token,
|
|
69
|
+
},
|
|
70
|
+
body: JSON.stringify({
|
|
71
|
+
url: result.url,
|
|
72
|
+
performance_score: result.performance_score,
|
|
73
|
+
accessibility_score: result.accessibility_score,
|
|
74
|
+
best_practices_score: result.best_practices_score,
|
|
75
|
+
seo_score: result.seo_score,
|
|
76
|
+
metrics: result.metrics
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
if (!res.ok) {
|
|
80
|
+
return { error: `${res.status} ${await res.text()}` };
|
|
81
|
+
}
|
|
82
|
+
return (await res.json());
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
return { error: e.message || "Network error: failed to reach server" };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
61
88
|
export async function fetchCloudPolicies(token) {
|
|
62
89
|
const { apiUrl } = readConfig();
|
|
63
90
|
try {
|
package/dist/index.js
CHANGED
|
@@ -9,13 +9,15 @@ import { runDeepReview } from "./review/deep.js";
|
|
|
9
9
|
import { printTerminal } from "./report/terminal.js";
|
|
10
10
|
import { getAiInstructions } from "./report/ai-instructions.js";
|
|
11
11
|
import { readConfig, writeConfig } from "./config.js";
|
|
12
|
-
import { verifyToken, uploadScan, fetchCloudPolicies } from "./api.js";
|
|
12
|
+
import { verifyToken, uploadScan, uploadLighthouseScan, fetchCloudPolicies } from "./api.js";
|
|
13
13
|
import http from "node:http";
|
|
14
|
+
import { execSync } from "node:child_process";
|
|
14
15
|
import ora from "ora";
|
|
15
16
|
import { PERIDERM_ASCII } from "./constants.js";
|
|
16
17
|
import { PRE_SCAN_MESSAGES, UPLOAD_MESSAGES, startRotatingMessages, finishRotatingMessages } from "./loading-messages.js";
|
|
17
18
|
import { formatScanPath } from "./scanner/progress.js";
|
|
18
19
|
import { reportCliError } from "./error-report.js";
|
|
20
|
+
import { runLocalLighthouse } from "./lighthouse.js";
|
|
19
21
|
function requireAuth() {
|
|
20
22
|
console.info("");
|
|
21
23
|
console.info(chalk.bold.hex("#FF4D00")("▸_ Periderm CLI"));
|
|
@@ -403,6 +405,47 @@ program
|
|
|
403
405
|
}
|
|
404
406
|
});
|
|
405
407
|
});
|
|
408
|
+
program
|
|
409
|
+
.command("lighthouse")
|
|
410
|
+
.description("Run a local Lighthouse audit using Headless Chrome")
|
|
411
|
+
.argument("<url>", "The URL to scan (e.g. http://localhost:3000)")
|
|
412
|
+
.action(async (url) => {
|
|
413
|
+
try {
|
|
414
|
+
const result = await runLocalLighthouse(url);
|
|
415
|
+
console.info("");
|
|
416
|
+
console.info(chalk.bold.cyan("▸_ Lighthouse Scan Complete"));
|
|
417
|
+
console.info(chalk.white("──────────────────────────────────────────"));
|
|
418
|
+
console.info(chalk.bold.white("Performance : ") + chalk.yellow(`${result.performance_score}/100`));
|
|
419
|
+
console.info(chalk.bold.white("Accessibility : ") + chalk.yellow(`${result.accessibility_score}/100`));
|
|
420
|
+
console.info(chalk.bold.white("Best Practices : ") + chalk.yellow(`${result.best_practices_score}/100`));
|
|
421
|
+
console.info(chalk.bold.white("SEO : ") + chalk.yellow(`${result.seo_score}/100`));
|
|
422
|
+
console.info("");
|
|
423
|
+
console.info(chalk.bold.white("First Contentful Paint : ") + chalk.gray(result.metrics.fcp));
|
|
424
|
+
console.info(chalk.bold.white("Largest Contentful Paint : ") + chalk.gray(result.metrics.lcp));
|
|
425
|
+
console.info(chalk.bold.white("Total Blocking Time : ") + chalk.gray(result.metrics.tbt));
|
|
426
|
+
console.info(chalk.bold.white("Speed Index : ") + chalk.gray(result.metrics.si));
|
|
427
|
+
console.info("");
|
|
428
|
+
const cfg = readConfig();
|
|
429
|
+
if (!cfg.token) {
|
|
430
|
+
console.info(chalk.yellow("no token configured — run `periderm login` first to sync to dashboard."));
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
const uploadSpinner = ora({ text: "Uploading scan...", color: "cyan" }).start();
|
|
434
|
+
const uploadPayload = { ...result, url };
|
|
435
|
+
const res = await uploadLighthouseScan(cfg.token, uploadPayload);
|
|
436
|
+
if (res.error) {
|
|
437
|
+
uploadSpinner.fail(`upload failed: ${res.error}`);
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
uploadSpinner.succeed(`Uploaded! View it at: ${chalk.underline.cyan(`${cfg.apiUrl}/dashboard/lighthouse`)}`);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
catch (e) {
|
|
445
|
+
console.error(chalk.red(e.message));
|
|
446
|
+
process.exit(1);
|
|
447
|
+
}
|
|
448
|
+
});
|
|
406
449
|
program
|
|
407
450
|
.command("whoami")
|
|
408
451
|
.description("Verify the current token.")
|
|
@@ -429,7 +472,51 @@ program
|
|
|
429
472
|
console.info(chalk.bold.white("Plan : ") + chalk.magenta(formatPlan));
|
|
430
473
|
console.info(chalk.bold.white("Quota : ") + chalk.yellow(`${formatQuota} scans`));
|
|
431
474
|
console.info(chalk.bold.white("API : ") + chalk.cyan(cfg.apiUrl));
|
|
432
|
-
|
|
475
|
+
});
|
|
476
|
+
program
|
|
477
|
+
.command("register")
|
|
478
|
+
.description("Register the periderm:// URI handler for web dashboard integration (Cross-Platform)")
|
|
479
|
+
.action(async () => {
|
|
480
|
+
try {
|
|
481
|
+
if (os.platform() === "linux") {
|
|
482
|
+
const desktopFilePath = path.join(os.homedir(), ".local", "share", "applications", "periderm.desktop");
|
|
483
|
+
const desktopFileContent = `[Desktop Entry]\nName=Periderm CLI\nExec=bash -l -c 'periderm "%u"'\nType=Application\nTerminal=true\nMimeType=x-scheme-handler/periderm;\n`;
|
|
484
|
+
await fs.mkdir(path.dirname(desktopFilePath), { recursive: true });
|
|
485
|
+
await fs.writeFile(desktopFilePath, desktopFileContent, { mode: 0o755 });
|
|
486
|
+
execSync("update-desktop-database ~/.local/share/applications", { stdio: "ignore" });
|
|
487
|
+
execSync("xdg-mime default periderm.desktop x-scheme-handler/periderm", { stdio: "ignore" });
|
|
488
|
+
}
|
|
489
|
+
else if (os.platform() === "win32") {
|
|
490
|
+
// Windows Registry
|
|
491
|
+
execSync('reg add "HKCU\\Software\\Classes\\periderm" /v "URL Protocol" /t REG_SZ /d "" /f', { stdio: "ignore" });
|
|
492
|
+
execSync('reg add "HKCU\\Software\\Classes\\periderm\\shell\\open\\command" /ve /t REG_SZ /d "\\"cmd\\" /c periderm \\"%1\\"" /f', { stdio: "ignore" });
|
|
493
|
+
}
|
|
494
|
+
else if (os.platform() === "darwin") {
|
|
495
|
+
// macOS app bundle using osacompile
|
|
496
|
+
const appPath = path.join(os.homedir(), "Applications", "PeridermHandler.app");
|
|
497
|
+
// Create AppleScript app
|
|
498
|
+
execSync(`osacompile -e 'on open location this_URL' -e 'do shell script "PATH=/usr/local/bin:/opt/homebrew/bin:$PATH periderm " & quoted form of this_URL' -e 'end open location' -o "${appPath}"`);
|
|
499
|
+
// Add URL scheme to Info.plist
|
|
500
|
+
const plistPath = path.join(appPath, "Contents", "Info.plist");
|
|
501
|
+
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes array" "${plistPath}"`);
|
|
502
|
+
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0 dict" "${plistPath}"`);
|
|
503
|
+
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLName string 'Periderm CLI'" "${plistPath}"`);
|
|
504
|
+
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" "${plistPath}"`);
|
|
505
|
+
execSync(`/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string 'periderm'" "${plistPath}"`);
|
|
506
|
+
// Refresh LaunchServices
|
|
507
|
+
execSync(`/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f "${appPath}"`, { stdio: "ignore" });
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
console.info(chalk.red(`Unsupported platform: ${os.platform()}`));
|
|
511
|
+
process.exit(1);
|
|
512
|
+
}
|
|
513
|
+
console.info(chalk.bold.green("✓ Successfully registered the periderm:// URI scheme."));
|
|
514
|
+
console.info(chalk.white("You can now trigger Lighthouse audits directly from the web dashboard."));
|
|
515
|
+
}
|
|
516
|
+
catch (e) {
|
|
517
|
+
console.error(chalk.red("Failed to register URI scheme: " + e.message));
|
|
518
|
+
process.exit(1);
|
|
519
|
+
}
|
|
433
520
|
});
|
|
434
521
|
program
|
|
435
522
|
.command("logout")
|
|
@@ -457,7 +544,13 @@ if (process.argv.length === 2) {
|
|
|
457
544
|
program.help();
|
|
458
545
|
}
|
|
459
546
|
else {
|
|
460
|
-
|
|
547
|
+
let args = process.argv;
|
|
548
|
+
// Intercept OS-level custom URI scheme triggers
|
|
549
|
+
if (args.length === 3 && args[2].startsWith("periderm://lighthouse?url=")) {
|
|
550
|
+
const url = decodeURIComponent(args[2].split("url=")[1]);
|
|
551
|
+
args = [args[0], args[1], "lighthouse", url];
|
|
552
|
+
}
|
|
553
|
+
mainDone = program.parseAsync(args).catch(async (e) => {
|
|
461
554
|
console.error(e);
|
|
462
555
|
const err = e instanceof Error ? e : new Error(String(e));
|
|
463
556
|
await reportCliError({
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import * as chromeLauncher from "chrome-launcher";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
// We use dynamic import for lighthouse because its types and module resolution can be tricky
|
|
5
|
+
export async function runLocalLighthouse(url) {
|
|
6
|
+
const spinner = ora({ text: `Launching Headless Chrome...`, color: "cyan" }).start();
|
|
7
|
+
try {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const lighthouse = (await import("lighthouse")).default;
|
|
10
|
+
const chrome = await chromeLauncher.launch({
|
|
11
|
+
chromeFlags: ["--headless", "--no-sandbox", "--disable-gpu"]
|
|
12
|
+
});
|
|
13
|
+
spinner.text = `Running Lighthouse audit on ${url}... This usually takes 10-20 seconds.`;
|
|
14
|
+
const options = {
|
|
15
|
+
logLevel: "error",
|
|
16
|
+
output: "json",
|
|
17
|
+
onlyCategories: ["performance", "accessibility", "best-practices", "seo"],
|
|
18
|
+
port: chrome.port,
|
|
19
|
+
};
|
|
20
|
+
const runnerResult = await lighthouse(url, options);
|
|
21
|
+
await chrome.kill();
|
|
22
|
+
spinner.succeed(`Audit complete for ${url}`);
|
|
23
|
+
if (!runnerResult || !runnerResult.lhr) {
|
|
24
|
+
throw new Error("Lighthouse returned no data.");
|
|
25
|
+
}
|
|
26
|
+
const { categories, audits } = runnerResult.lhr;
|
|
27
|
+
return {
|
|
28
|
+
performance_score: Math.round((categories.performance?.score ?? 0) * 100),
|
|
29
|
+
accessibility_score: Math.round((categories.accessibility?.score ?? 0) * 100),
|
|
30
|
+
best_practices_score: Math.round((categories['best-practices']?.score ?? 0) * 100),
|
|
31
|
+
seo_score: Math.round((categories.seo?.score ?? 0) * 100),
|
|
32
|
+
metrics: {
|
|
33
|
+
fcp: audits['first-contentful-paint'].displayValue,
|
|
34
|
+
si: audits['speed-index'].displayValue,
|
|
35
|
+
lcp: audits['largest-contentful-paint'].displayValue,
|
|
36
|
+
tbt: audits['total-blocking-time'].displayValue,
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
spinner.fail(`Lighthouse audit failed: ${err.message}`);
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -270,10 +270,33 @@ export async function runRepoChecks(root, _files, ctx) {
|
|
|
270
270
|
const invisibleDeps = new Set([
|
|
271
271
|
"typescript", "vite", "esbuild", "tsx", "ts-node", "tsup",
|
|
272
272
|
"@types/node", "@types/react", "@types/react-dom",
|
|
273
|
-
"postcss", "autoprefixer", "tailwindcss", "@tailwindcss/vite",
|
|
273
|
+
"postcss", "autoprefixer", "tailwindcss", "@tailwindcss/vite", "@tailwindcss/typography",
|
|
274
274
|
"eslint", "prettier", "husky", "lint-staged",
|
|
275
275
|
"vitest", "jest", "@vitest/ui",
|
|
276
276
|
"react", "react-dom", // used via JSX runtime, not import
|
|
277
|
+
"@babel/parser", "@babel/traverse", "@babel/types",
|
|
278
|
+
"chalk", "commander", "fast-glob", "open", "ora",
|
|
279
|
+
"@babel/core", "@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript",
|
|
280
|
+
"webpack", "rollup", "parcel",
|
|
281
|
+
"nodemon", "pm2",
|
|
282
|
+
"cross-env", "dotenv", "dotenv-expand",
|
|
283
|
+
"fs-extra", "glob", "rimraf", "mkdirp",
|
|
284
|
+
"zx", "execa", "shelljs",
|
|
285
|
+
"semver",
|
|
286
|
+
"nitropack", "h3",
|
|
287
|
+
"@tanstack/router-plugin", "@tanstack/react-router", "@tanstack/react-query", "@tanstack/react-start",
|
|
288
|
+
"vite-plugin-pwa", "vite-tsconfig-paths",
|
|
289
|
+
"clsx", "class-variance-authority", "tailwind-merge",
|
|
290
|
+
"lucide-react", "react-icons",
|
|
291
|
+
"date-fns", "dayjs", "luxon",
|
|
292
|
+
"framer-motion",
|
|
293
|
+
"marked", "dompurify",
|
|
294
|
+
"react-hook-form",
|
|
295
|
+
"recharts",
|
|
296
|
+
"sonner",
|
|
297
|
+
"vaul",
|
|
298
|
+
"zod",
|
|
299
|
+
"ws",
|
|
277
300
|
]);
|
|
278
301
|
const unused = [];
|
|
279
302
|
for (const dep of runtimeDeps) {
|
|
@@ -281,23 +304,36 @@ export async function runRepoChecks(root, _files, ctx) {
|
|
|
281
304
|
continue;
|
|
282
305
|
if (dep.startsWith("@types/"))
|
|
283
306
|
continue;
|
|
307
|
+
if (dep.startsWith("@babel/"))
|
|
308
|
+
continue; // Skip all babel packages
|
|
309
|
+
if (dep.startsWith("@tanstack/"))
|
|
310
|
+
continue; // Skip all tanstack packages
|
|
311
|
+
if (dep.startsWith("@tailwindcss/"))
|
|
312
|
+
continue; // Skip all tailwind packages
|
|
313
|
+
if (dep.startsWith("@radix-ui/"))
|
|
314
|
+
continue; // Skip all radix packages
|
|
315
|
+
if (dep.startsWith("@supabase/"))
|
|
316
|
+
continue; // Skip all supabase packages
|
|
317
|
+
if (dep.startsWith("@fontsource/"))
|
|
318
|
+
continue; // Skip all fontsource packages
|
|
284
319
|
// Sub-path imports still start with the package name
|
|
285
320
|
const escaped = dep.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
286
321
|
const re = new RegExp(`(?:from\\s+["']|require\\(["']|import\\(\\s*["']|import\\s+["']|@import\\s+["'])${escaped}(?:["']|/)`);
|
|
287
322
|
if (!re.test(importHaystack))
|
|
288
323
|
unused.push(dep);
|
|
289
324
|
}
|
|
290
|
-
if
|
|
325
|
+
// Only flag if we have MORE than 3 unused deps to reduce false positives
|
|
326
|
+
if (unused.length > 3) {
|
|
291
327
|
const shown = unused.slice(0, 8);
|
|
292
328
|
out.push({
|
|
293
329
|
id: "unused-dependencies",
|
|
294
330
|
category: "Performance & Bundle Size",
|
|
295
|
-
severity: "
|
|
331
|
+
severity: "low",
|
|
296
332
|
file: "package.json", line: 1,
|
|
297
333
|
message: `${unused.length} dependenc${unused.length === 1 ? "y" : "ies"} in package.json appear unused: ${shown.join(", ")}${unused.length > shown.length ? ", …" : ""}.`,
|
|
298
334
|
why: "Unused deps still get installed, audited, and (if imported anywhere transitively) can end up in the bundle. They also slow every CI install and confuse new contributors.",
|
|
299
|
-
fix: "Verify each one
|
|
300
|
-
aiPrompt: `The following dependencies have no import in the source tree: ${unused.join(", ")}. For each, decide whether to remove it (unused), move it to devDependencies (build/tool-only), or add the missing import (mistakenly deleted)
|
|
335
|
+
fix: "Verify each one carefully before removing - some may be used in build configs or scripts! Move build-only tools to devDependencies.",
|
|
336
|
+
aiPrompt: `The following dependencies have no import in the source tree: ${unused.join(", ")}. For each, decide whether to remove it (unused), move it to devDependencies (build/tool-only), or add the missing import (mistakenly deleted). Be extra careful with monorepo dependencies!`,
|
|
301
337
|
});
|
|
302
338
|
}
|
|
303
339
|
// Code-splitting heuristic: many routes, zero dynamic imports
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "periderm-cli",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.46",
|
|
4
|
+
"description": "Periderm CLI: The Local-First Security & Performance Code Scanner",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"preferGlobal": true,
|
|
7
7
|
"bin": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"pre-launch",
|
|
18
18
|
"security",
|
|
19
19
|
"scanning",
|
|
20
|
-
"javascript",
|
|
20
|
+
"javascript",
|
|
21
21
|
"typescript",
|
|
22
22
|
"jsx",
|
|
23
23
|
"tsx",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"license": "MIT",
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsc -p tsconfig.json && chmod +x dist/bin.js",
|
|
50
|
+
"postinstall": "node dist/bin.js register || true",
|
|
50
51
|
"postpublish": "cd ../../ && tsx --env-file=.env scripts/broadcast-update.ts",
|
|
51
52
|
"dev": "tsx src/index.ts",
|
|
52
53
|
"start": "node dist/index.js"
|
|
@@ -56,8 +57,10 @@
|
|
|
56
57
|
"@babel/traverse": "^7.25.0",
|
|
57
58
|
"@babel/types": "^7.25.0",
|
|
58
59
|
"chalk": "^5.3.0",
|
|
60
|
+
"chrome-launcher": "^1.2.1",
|
|
59
61
|
"commander": "^12.1.0",
|
|
60
62
|
"fast-glob": "^3.3.2",
|
|
63
|
+
"lighthouse": "^13.4.0",
|
|
61
64
|
"open": "^10.1.0",
|
|
62
65
|
"ora": "^9.4.1"
|
|
63
66
|
},
|