periderm-cli 0.1.76 → 0.1.78
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.js +38 -5
- package/dist/report/agent-rules.js +73 -0
- package/dist/report/ai-instructions.js +102 -83
- package/dist/report/markdown.js +5 -4
- package/dist/review/deep.js +18 -1
- package/dist/scanner/checks.js +62 -19
- package/dist/scanner/compliance-checks.js +361 -0
- package/dist/scanner/context-agent.js +1 -1
- package/dist/scanner/index.js +43 -20
- package/dist/scanner/metrics.js +107 -14
- package/dist/scanner/ml-predictor.js +21 -15
- package/dist/scanner/policy-checks.js +10 -13
- package/dist/scanner/project-context.js +16 -0
- package/dist/scanner/repo-checks.js +112 -37
- package/dist/scanner/walk.js +68 -21
- package/package.json +1 -1
|
@@ -20,6 +20,17 @@ function resolveModelPath() {
|
|
|
20
20
|
];
|
|
21
21
|
return candidates.find((p) => fs.existsSync(p)) ?? null;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Load the forest from an already-parsed object. The web server uses this because bundlers
|
|
25
|
+
* (Vercel/nitro) don't ship assets/defect_model.json next to the compiled code.
|
|
26
|
+
*/
|
|
27
|
+
export function loadPredictorModel(model) {
|
|
28
|
+
if (ready || !Array.isArray(model) || model.length === 0)
|
|
29
|
+
return;
|
|
30
|
+
forest = model;
|
|
31
|
+
ready = true;
|
|
32
|
+
debugMl(`model provided in-process — ${forest.length} trees`);
|
|
33
|
+
}
|
|
23
34
|
export async function initPredictor() {
|
|
24
35
|
if (ready)
|
|
25
36
|
return;
|
|
@@ -50,22 +61,17 @@ function predictTree(tree, features) {
|
|
|
50
61
|
idx = features[feat] <= threshold ? left : right;
|
|
51
62
|
}
|
|
52
63
|
}
|
|
53
|
-
|
|
64
|
+
/** Mean defect probability across the forest (0–1), or null when the model isn't loaded. */
|
|
65
|
+
export function predictDefectProbability(metrics) {
|
|
54
66
|
if (!forest)
|
|
55
|
-
return
|
|
56
|
-
const features = [
|
|
57
|
-
metrics.loc,
|
|
58
|
-
metrics.wmc,
|
|
59
|
-
metrics.npm,
|
|
60
|
-
metrics.max_cc,
|
|
61
|
-
metrics.avg_cc,
|
|
62
|
-
];
|
|
63
|
-
// Average defect probability across all trees (majority vote)
|
|
67
|
+
return null;
|
|
68
|
+
const features = [metrics.loc, metrics.wmc, metrics.npm, metrics.max_cc, metrics.avg_cc];
|
|
64
69
|
let totalP = 0;
|
|
65
|
-
for (const tree of forest)
|
|
70
|
+
for (const tree of forest)
|
|
66
71
|
totalP += predictTree(tree, features);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
return totalP / forest.length;
|
|
73
|
+
}
|
|
74
|
+
/** Kept for backwards compatibility: true when probability > 0.5. */
|
|
75
|
+
export async function predictDefect(metrics) {
|
|
76
|
+
return (predictDefectProbability(metrics) ?? 0) > 0.5;
|
|
71
77
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import fs from "node:fs/promises";
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
import {
|
|
7
|
+
import { collectLegalText } from "./compliance-checks.js";
|
|
8
8
|
async function readMaybe(p) {
|
|
9
9
|
try {
|
|
10
10
|
return await fs.readFile(p, "utf8");
|
|
@@ -15,10 +15,10 @@ async function readMaybe(p) {
|
|
|
15
15
|
}
|
|
16
16
|
/** Signals that user data is sent to trackers, ad networks, or data brokers. */
|
|
17
17
|
const TRACKING_IN_CODE = [
|
|
18
|
-
[
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
],
|
|
18
|
+
[/gtag\s*\(|googletagmanager|google-analytics|GA_MEASUREMENT_ID/i, "Google Analytics / gtag"],
|
|
19
|
+
// GA4 measurement IDs are always uppercase and quoted, e.g. "G-AB12CD34EF".
|
|
20
|
+
// Must stay case-sensitive: with /i this matched Tailwind classes like `bg-background`.
|
|
21
|
+
[/['"`]G-[A-Z0-9]{8,12}['"`]/, "Google Analytics / gtag"],
|
|
22
22
|
[/fbq\s*\(|facebook\.net\/en_US\/fbevents|connect\.facebook\.net/i, "Meta / Facebook Pixel"],
|
|
23
23
|
[/posthog\.(?:capture|init)|import\s+posthog/i, "PostHog analytics"],
|
|
24
24
|
[/mixpanel\.(?:track|init)|from\s+['"]mixpanel/i, "Mixpanel"],
|
|
@@ -88,18 +88,15 @@ export const POLICY_SIGNAL_COUNT = TRACKING_IN_CODE.length + COOKIE_TRACKING_IN_
|
|
|
88
88
|
export async function runPolicyChecks(root, files) {
|
|
89
89
|
const out = [];
|
|
90
90
|
const relFiles = files.map((f) => path.relative(root, f));
|
|
91
|
-
const
|
|
91
|
+
const legal = await collectLegalText(root);
|
|
92
|
+
const legalPaths = legal.files;
|
|
92
93
|
if (legalPaths.length === 0)
|
|
93
94
|
return { findings: out, legalPagesFound: 0, signalsChecked: 0 };
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const content = await readMaybe(path.join(root, rel));
|
|
97
|
-
if (content)
|
|
98
|
-
legalText += `\n${content}`;
|
|
99
|
-
}
|
|
100
|
-
if (!legalText.trim()) {
|
|
95
|
+
// Policy text loaded from a DB/CMS isn't in the repo, so we can't cross-reference it.
|
|
96
|
+
if (legal.dynamic || !legal.text.trim()) {
|
|
101
97
|
return { findings: out, legalPagesFound: legalPaths.length, signalsChecked: 0 };
|
|
102
98
|
}
|
|
99
|
+
const legalText = legal.text;
|
|
103
100
|
const legalLower = legalText.toLowerCase();
|
|
104
101
|
// Collect what the codebase actually does
|
|
105
102
|
const codeSignals = new Map(); // label -> first file
|
|
@@ -80,9 +80,25 @@ export function isInternalPath(rel, ctx) {
|
|
|
80
80
|
const norm = rel.replace(/\\/g, "/");
|
|
81
81
|
return ctx.internalPathRe.some((re) => re.test(norm));
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Obligations that follow the user, not the page: a renewal disclosure on a dashboard billing page
|
|
85
|
+
* or an age gate on an "internal" signup still applies. Only an explicit skip_check_ids opts out.
|
|
86
|
+
*/
|
|
87
|
+
const PATH_INDEPENDENT_IDS = new Set([
|
|
88
|
+
"subscription-no-renewal-terms",
|
|
89
|
+
"coppa-no-age-gate",
|
|
90
|
+
"coppa-age-not-asked",
|
|
91
|
+
"session-replay-unmasked",
|
|
92
|
+
"session-replay-no-consent",
|
|
93
|
+
"email-no-unsubscribe",
|
|
94
|
+
"email-no-postal-address",
|
|
95
|
+
"dmca-no-agent",
|
|
96
|
+
]);
|
|
83
97
|
export function shouldSkipFinding(finding, ctx) {
|
|
84
98
|
if (ctx.skipCheckIds.has(finding.id))
|
|
85
99
|
return true;
|
|
100
|
+
if (PATH_INDEPENDENT_IDS.has(finding.id))
|
|
101
|
+
return false;
|
|
86
102
|
if (ctx.skipCategories.has(finding.category))
|
|
87
103
|
return true;
|
|
88
104
|
const rel = finding.file.replace(/\\/g, "/");
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import fs from "node:fs/promises";
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
import fg from "fast-glob";
|
|
8
7
|
import { detectFaviconPresent } from "./project-context.js";
|
|
9
|
-
import {
|
|
8
|
+
import { collectLegalText } from "./compliance-checks.js";
|
|
9
|
+
import { listProjectFiles } from "./walk.js";
|
|
10
10
|
async function exists(p) {
|
|
11
11
|
try {
|
|
12
12
|
await fs.access(p);
|
|
@@ -133,7 +133,8 @@ export async function runRepoChecks(root, _files, ctx) {
|
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
else {
|
|
136
|
-
const
|
|
136
|
+
const legal = await collectLegalText(root);
|
|
137
|
+
const legalFilePaths = legal.files.map((rel) => path.join(root, rel));
|
|
137
138
|
if (legalFilePaths.length === 0) {
|
|
138
139
|
out.push({
|
|
139
140
|
id: "missing-legal-docs",
|
|
@@ -147,7 +148,8 @@ export async function runRepoChecks(root, _files, ctx) {
|
|
|
147
148
|
aiPrompt: "Generate a standard Privacy Policy and Terms of Service route for this application.",
|
|
148
149
|
});
|
|
149
150
|
}
|
|
150
|
-
else if (pkgRaw) {
|
|
151
|
+
else if (pkgRaw && !legal.dynamic) {
|
|
152
|
+
// (Pages that load their text from a DB/CMS can't be verified here — see collectLegalText.)
|
|
151
153
|
let combinedSource = pkgRaw;
|
|
152
154
|
for (const abs of _files) {
|
|
153
155
|
const rel = path.relative(root, abs);
|
|
@@ -160,12 +162,7 @@ export async function runRepoChecks(root, _files, ctx) {
|
|
|
160
162
|
const hasAuth = /supabase|clerk|firebase|next-auth|auth0|createClient.*auth/i.test(combinedSource);
|
|
161
163
|
const hasPayments = /stripe|braintree|paypal|lemonsqueezy/i.test(combinedSource);
|
|
162
164
|
const hasAnalytics = /posthog|mixpanel|segment|amplitude|google-analytics|gtag\s*\(|fbq\s*\(|plausible|hotjar/i.test(combinedSource);
|
|
163
|
-
|
|
164
|
-
for (const p of legalFilePaths) {
|
|
165
|
-
const content = await readMaybe(p);
|
|
166
|
-
if (content)
|
|
167
|
-
combinedLegalContent += content.toLowerCase();
|
|
168
|
-
}
|
|
165
|
+
const combinedLegalContent = legal.text;
|
|
169
166
|
const legalFile = path.relative(root, legalFilePaths[0]);
|
|
170
167
|
if (hasAuth && !/account|email|password|authentication|login/i.test(combinedLegalContent)) {
|
|
171
168
|
out.push({
|
|
@@ -449,15 +446,7 @@ export async function runRepoChecks(root, _files, ctx) {
|
|
|
449
446
|
// ─────────────────────────────────────────────────────────────────────
|
|
450
447
|
// Unused CSS classes (skip Tailwind / CSS-modules)
|
|
451
448
|
// ─────────────────────────────────────────────────────────────────────
|
|
452
|
-
const cssFiles = await
|
|
453
|
-
"**/*.css",
|
|
454
|
-
"!**/node_modules/**",
|
|
455
|
-
"!**/dist/**",
|
|
456
|
-
"!**/build/**",
|
|
457
|
-
"!**/.next/**",
|
|
458
|
-
"!**/.output/**",
|
|
459
|
-
"!**/*.module.css",
|
|
460
|
-
], { cwd: root, absolute: true, dot: false });
|
|
449
|
+
const cssFiles = (await listProjectFiles(root, "css")).filter((f) => !f.endsWith(".module.css"));
|
|
461
450
|
if (cssFiles.length) {
|
|
462
451
|
// Build a haystack of everything CSS classes might be referenced from.
|
|
463
452
|
let refHaystack = "";
|
|
@@ -515,27 +504,113 @@ export async function runRepoChecks(root, _files, ctx) {
|
|
|
515
504
|
// ─────────────────────────────────────────────────────────────────────
|
|
516
505
|
// Security Definer RPC Check (Supabase/PostgreSQL)
|
|
517
506
|
// ─────────────────────────────────────────────────────────────────────
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
507
|
+
// Migrations are timestamp-prefixed: apply them in order.
|
|
508
|
+
const sqlFiles = (await listProjectFiles(root, "sql")).sort();
|
|
509
|
+
out.push(...(await checkDefinerFunctions(root, sqlFiles)));
|
|
510
|
+
return out;
|
|
511
|
+
}
|
|
512
|
+
const UNTRUSTED_ROLE_RE = /\b(public|anon|authenticated)\b/i;
|
|
513
|
+
const CALLER_GUARD_RE = /auth\.uid\s*\(\s*\)|auth\.role\s*\(\s*\)|auth\.jwt\s*\(\s*\)|has_role\s*\(|current_setting\s*\(\s*'request\.jwt|current_user\s*(<>|!=|=)|session_user/i;
|
|
514
|
+
function normFnName(raw) {
|
|
515
|
+
return raw
|
|
516
|
+
.replace(/"/g, "")
|
|
517
|
+
.replace(/^public\./i, "")
|
|
518
|
+
.trim()
|
|
519
|
+
.toLowerCase();
|
|
520
|
+
}
|
|
521
|
+
async function checkDefinerFunctions(root, sqlFiles) {
|
|
522
|
+
const fns = new Map();
|
|
523
|
+
const createRe = /create\s+(?:or\s+replace\s+)?function\s+([\w."]+)\s*\(([\s\S]*?)\)\s*returns\s+([\w.\s]+?)\s+(?:language|as|security|set|stable|immutable|volatile)/gi;
|
|
524
|
+
for (const abs of sqlFiles) {
|
|
525
|
+
const sql = await readMaybe(abs);
|
|
526
|
+
if (!sql)
|
|
522
527
|
continue;
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
528
|
+
const rel = path.relative(root, abs);
|
|
529
|
+
// Process statements in order so a GRANT/REVOKE after a CREATE applies to it.
|
|
530
|
+
const events = [];
|
|
531
|
+
let m;
|
|
532
|
+
while ((m = createRe.exec(sql))) {
|
|
533
|
+
const name = normFnName(m[1]);
|
|
534
|
+
const startIdx = m.index;
|
|
535
|
+
// The function ends at the closing dollar-quote of its body ($$ or $tag$).
|
|
536
|
+
const after = sql.slice(startIdx);
|
|
537
|
+
const dq = after.match(/\$(\w*)\$/);
|
|
538
|
+
let endIdx = sql.length;
|
|
539
|
+
if (dq?.index !== undefined) {
|
|
540
|
+
const tag = dq[0];
|
|
541
|
+
const close = after.indexOf(tag, dq.index + tag.length);
|
|
542
|
+
const tail = close === -1 ? after.length : close + tag.length;
|
|
543
|
+
const semi = after.indexOf(";", tail);
|
|
544
|
+
endIdx = startIdx + (semi === -1 ? tail : semi + 1);
|
|
537
545
|
}
|
|
546
|
+
const stmt = sql.slice(startIdx, endIdx);
|
|
547
|
+
// Only the body counts as evidence of a caller check — not the function's own name.
|
|
548
|
+
const bodyMatch = stmt.match(/\$(\w*)\$([\s\S]*?)\$\1\$/);
|
|
549
|
+
const body = bodyMatch ? bodyMatch[2] : stmt;
|
|
550
|
+
const returns = m[3].toLowerCase();
|
|
551
|
+
const line = sql.slice(0, startIdx).split("\n").length;
|
|
552
|
+
events.push({
|
|
553
|
+
index: startIdx,
|
|
554
|
+
apply: () => {
|
|
555
|
+
const prev = fns.get(name);
|
|
556
|
+
fns.set(name, {
|
|
557
|
+
file: rel,
|
|
558
|
+
line,
|
|
559
|
+
definer: /security\s+definer/i.test(stmt),
|
|
560
|
+
guarded: CALLER_GUARD_RE.test(body),
|
|
561
|
+
writes: /\b(insert\s+into|update\s+[\w."]+\s+set|delete\s+from|truncate|drop\s|alter\s|grant\s|execute\s)/i.test(body),
|
|
562
|
+
boolHelper: /^(has|is|can)_/.test(name) && /^bool(ean)?$/.test(returns.trim()),
|
|
563
|
+
trigger: /\btrigger\b/.test(returns),
|
|
564
|
+
// CREATE OR REPLACE keeps existing privileges; a brand-new function is PUBLIC-executable.
|
|
565
|
+
exposed: prev ? prev.exposed : true,
|
|
566
|
+
});
|
|
567
|
+
},
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
const privRe = /(grant|revoke)\s+(?:all|execute)(?:\s+privileges)?\s+on\s+function\s+([\w."]+)\s*(?:\([^)]*\))?\s+(to|from)\s+([^;]+);/gi;
|
|
571
|
+
while ((m = privRe.exec(sql))) {
|
|
572
|
+
const verb = m[1].toLowerCase();
|
|
573
|
+
const name = normFnName(m[2]);
|
|
574
|
+
const roles = m[4];
|
|
575
|
+
events.push({
|
|
576
|
+
index: m.index,
|
|
577
|
+
apply: () => {
|
|
578
|
+
const fn = fns.get(name);
|
|
579
|
+
if (!fn)
|
|
580
|
+
return;
|
|
581
|
+
if (verb === "grant" && UNTRUSTED_ROLE_RE.test(roles))
|
|
582
|
+
fn.exposed = true;
|
|
583
|
+
if (verb === "revoke") {
|
|
584
|
+
const revoked = roles.toLowerCase();
|
|
585
|
+
// Fully closed only when PUBLIC is revoked (anon/authenticated inherit from it) or both are.
|
|
586
|
+
if (/\bpublic\b/.test(revoked) ||
|
|
587
|
+
(/\banon\b/.test(revoked) && /\bauthenticated\b/.test(revoked))) {
|
|
588
|
+
fn.exposed = false;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
});
|
|
538
593
|
}
|
|
594
|
+
events.sort((a, b) => a.index - b.index).forEach((e) => e.apply());
|
|
595
|
+
}
|
|
596
|
+
const out = [];
|
|
597
|
+
for (const [name, fn] of fns) {
|
|
598
|
+
if (!fn.definer || fn.trigger || !fn.exposed || fn.guarded)
|
|
599
|
+
continue;
|
|
600
|
+
// Read-only has_/is_/can_ boolean helpers are the standard pattern for RLS policies.
|
|
601
|
+
if (fn.boolHelper && !fn.writes)
|
|
602
|
+
continue;
|
|
603
|
+
out.push({
|
|
604
|
+
id: "definer-rpc-execute",
|
|
605
|
+
category: "Security & Permissions",
|
|
606
|
+
severity: fn.writes ? "critical" : "high",
|
|
607
|
+
file: fn.file,
|
|
608
|
+
line: fn.line,
|
|
609
|
+
message: `SECURITY DEFINER function \`${name}\` can be called by anon/authenticated users and never checks who the caller is.`,
|
|
610
|
+
why: "SECURITY DEFINER functions run with their owner's privileges (usually postgres), bypassing Row Level Security. Postgres lets PUBLIC execute new functions by default, and Supabase exposes them as RPC endpoints — so any visitor can call this one with any arguments.",
|
|
611
|
+
fix: `Either revoke access (REVOKE EXECUTE ON FUNCTION ${name} FROM PUBLIC, anon, authenticated;) and call it only from the service role, or add a caller check at the top (e.g. IF auth.uid() IS DISTINCT FROM _user_id THEN RAISE EXCEPTION 'forbidden'; END IF;), or make it SECURITY INVOKER.`,
|
|
612
|
+
aiPrompt: `In ${fn.file} near line ${fn.line}, the SECURITY DEFINER function ${name} is executable by untrusted roles and has no auth check. Add a new migration that either revokes EXECUTE from PUBLIC, anon and authenticated (if only the server calls it), or adds an auth.uid()/has_role() guard at the start of the function body.`,
|
|
613
|
+
});
|
|
539
614
|
}
|
|
540
615
|
return out;
|
|
541
616
|
}
|
package/dist/scanner/walk.js
CHANGED
|
@@ -1,28 +1,75 @@
|
|
|
1
1
|
import fg from "fast-glob";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
const CODE_EXTS = "ts,tsx,js,jsx,mjs,cjs,dart,swift";
|
|
6
|
+
const BASE_IGNORES = [
|
|
7
|
+
"!**/node_modules/**",
|
|
8
|
+
"!**/dist/**",
|
|
9
|
+
"!**/build/**",
|
|
10
|
+
"!**/.next/**",
|
|
11
|
+
"!**/.output/**",
|
|
12
|
+
"!**/.vercel/**",
|
|
13
|
+
"!**/.git/**",
|
|
14
|
+
"!**/coverage/**",
|
|
15
|
+
"!**/*.d.ts",
|
|
16
|
+
"!**/routeTree.gen.*",
|
|
17
|
+
"!**/scripts/**",
|
|
18
|
+
"!**/test.js",
|
|
19
|
+
"!**/test2.js",
|
|
20
|
+
"!**/test-server.js",
|
|
21
|
+
"!**/fix-*.mjs",
|
|
22
|
+
"!**/*.{test,spec}.{ts,tsx,js,jsx,mjs,cjs}",
|
|
23
|
+
];
|
|
24
|
+
/** Skip Periderm's own CLI package when scanning the Periderm repo — but never a user's packages/cli. */
|
|
25
|
+
async function isPeridermCliPackage(root) {
|
|
26
|
+
try {
|
|
27
|
+
const pkg = JSON.parse(await fs.readFile(path.join(root, "packages/cli/package.json"), "utf8"));
|
|
28
|
+
return pkg?.name === "periderm-cli";
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Files git would track (tracked + untracked, minus .gitignore'd), or null outside a git repo.
|
|
36
|
+
* Without this, gitignored datasets, vendored docs and generated output get scanned and drown
|
|
37
|
+
* the report in findings nobody can act on.
|
|
38
|
+
*/
|
|
39
|
+
function gitVisibleFiles(root) {
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
execFile("git", ["-C", root, "ls-files", "-z", "--cached", "--others", "--exclude-standard"], { maxBuffer: 64 * 1024 * 1024 }, (err, stdout) => {
|
|
42
|
+
if (err)
|
|
43
|
+
return resolve(null);
|
|
44
|
+
const set = new Set(stdout
|
|
45
|
+
.split("\0")
|
|
46
|
+
.filter(Boolean)
|
|
47
|
+
.map((rel) => path.resolve(root, rel)));
|
|
48
|
+
resolve(set.size ? set : null);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const gitCache = new Map();
|
|
53
|
+
/** List project files with the given extensions, honouring Periderm's ignores and .gitignore. */
|
|
54
|
+
export async function listProjectFiles(root, exts, extraIgnores = []) {
|
|
55
|
+
const ignores = [...BASE_IGNORES];
|
|
56
|
+
if (await isPeridermCliPackage(root))
|
|
57
|
+
ignores.push("!packages/cli/**");
|
|
21
58
|
// Cloud policy ignores: normalize to negated globs
|
|
22
|
-
|
|
23
|
-
|
|
59
|
+
ignores.push(...extraIgnores.map((ig) => (ig.startsWith("!") ? ig : `!${ig}`)));
|
|
60
|
+
// A one-item brace like "*.{sql}" is matched literally by fast-glob, so only use braces for lists.
|
|
61
|
+
const pattern = exts.includes(",") ? `**/*.{${exts}}` : `**/*.${exts}`;
|
|
62
|
+
const files = await fg([pattern, ...ignores], {
|
|
24
63
|
cwd: root,
|
|
25
64
|
absolute: true,
|
|
26
65
|
dot: false,
|
|
27
66
|
});
|
|
67
|
+
const key = path.resolve(root);
|
|
68
|
+
if (!gitCache.has(key))
|
|
69
|
+
gitCache.set(key, gitVisibleFiles(root));
|
|
70
|
+
const visible = await gitCache.get(key);
|
|
71
|
+
return visible ? files.filter((f) => visible.has(path.resolve(f))) : files;
|
|
72
|
+
}
|
|
73
|
+
export async function walk(root, extraIgnores = []) {
|
|
74
|
+
return listProjectFiles(root, CODE_EXTS, extraIgnores);
|
|
28
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "periderm-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.78",
|
|
4
4
|
"description": "Periderm CLI: A pre-launch checklist to catch user-losing bugs, legal liabilities, revenue leaks, runaway cloud bills and so many more before you ship.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"preferGlobal": true,
|