claude-crap 0.3.1 → 0.3.3

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-crap-plugin",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": true,
5
5
  "description": "Runtime dependencies for the claude-crap plugin bundle",
6
6
  "type": "module",
@@ -94,13 +94,12 @@ export async function startDashboard(options: StartDashboardOptions): Promise<Da
94
94
  await fastify.register(fastifyStatic, {
95
95
  root: publicRoot,
96
96
  prefix: "/",
97
- decorateReply: false,
98
97
  });
99
98
 
100
99
  // ------------------------------------------------------------------
101
100
  // /api/health — liveness probe
102
101
  // ------------------------------------------------------------------
103
- fastify.get("/api/health", async () => ({ status: "ok", server: "claude-crap", version: "0.1.0" }));
102
+ fastify.get("/api/health", async () => ({ status: "ok", server: "claude-crap", version: "0.3.2" }));
104
103
 
105
104
  // ------------------------------------------------------------------
106
105
  // /api/score — live project score
@@ -117,8 +116,14 @@ export async function startDashboard(options: StartDashboardOptions): Promise<Da
117
116
  fastify.get("/api/sarif", async () => sarifStore.toSarifDocument());
118
117
 
119
118
  // ------------------------------------------------------------------
120
- // / — static SPA fallback (Fastify-static handles index.html)
119
+ // / — explicit SPA fallback for index.html
121
120
  // ------------------------------------------------------------------
121
+ // @fastify/static sometimes doesn't serve index.html on GET / when
122
+ // API routes are registered on the same prefix. Explicit fallback
123
+ // ensures the dashboard always loads.
124
+ fastify.get("/", async (_request, reply) => {
125
+ return reply.sendFile("index.html");
126
+ });
122
127
 
123
128
  await fastify.listen({ port: config.dashboardPort, host: "127.0.0.1" });
124
129
  const url = `http://127.0.0.1:${config.dashboardPort}`;
@@ -19,6 +19,8 @@
19
19
  * @module scanner/auto-scan
20
20
  */
21
21
 
22
+ import { existsSync } from "node:fs";
23
+ import { join } from "node:path";
22
24
  import type { Logger } from "pino";
23
25
  import { detectScanners, type ScannerDetection } from "./detector.js";
24
26
  import { runScanner, type ScannerRunResult } from "./runner.js";
@@ -106,6 +108,32 @@ export async function autoScan(
106
108
  "auto-scan: detection complete",
107
109
  );
108
110
 
111
+ // If ESLint is detected (e.g. in package.json) but has no config file,
112
+ // bootstrap will create one before we try to scan.
113
+ const eslintConfigFiles = [
114
+ "eslint.config.js", "eslint.config.mjs", "eslint.config.cjs",
115
+ "eslint.config.ts", "eslint.config.mts", "eslint.config.cts",
116
+ ".eslintrc.js", ".eslintrc.cjs", ".eslintrc.yaml",
117
+ ".eslintrc.yml", ".eslintrc.json",
118
+ ];
119
+ const eslintDetected = available.some((d) => d.scanner === "eslint");
120
+ const hasEslintConfig = eslintConfigFiles.some((f) => existsSync(join(workspaceRoot, f)));
121
+
122
+ if (eslintDetected && !hasEslintConfig) {
123
+ logger.info("auto-scan: ESLint detected but no config — running bootstrap");
124
+ try {
125
+ const bootstrapResult = await bootstrapScanner(workspaceRoot, sarifStore, logger);
126
+ if (bootstrapResult.autoScanResult) {
127
+ return bootstrapResult.autoScanResult;
128
+ }
129
+ } catch (err) {
130
+ logger.warn(
131
+ { err: (err as Error).message },
132
+ "auto-scan: bootstrap config creation failed",
133
+ );
134
+ }
135
+ }
136
+
109
137
  if (available.length === 0) {
110
138
  // No scanners configured — try to bootstrap one automatically.
111
139
  logger.info("auto-scan: no scanners found, attempting bootstrap");
@@ -137,7 +137,14 @@ export default tseslint.config(
137
137
  js.configs.recommended,
138
138
  ...tseslint.configs.recommended,
139
139
  {
140
- ignores: ["dist/", "node_modules/", "coverage/"],
140
+ ignores: [
141
+ "dist/",
142
+ "node_modules/",
143
+ "coverage/",
144
+ "**/bundle/",
145
+ "**/vendor/",
146
+ "**/*.min.js",
147
+ ],
141
148
  },
142
149
  );
143
150
  `;
@@ -148,7 +155,14 @@ export default tseslint.config(
148
155
  export default [
149
156
  js.configs.recommended,
150
157
  {
151
- ignores: ["dist/", "node_modules/", "coverage/"],
158
+ ignores: [
159
+ "dist/",
160
+ "node_modules/",
161
+ "coverage/",
162
+ "**/bundle/",
163
+ "**/vendor/",
164
+ "**/*.min.js",
165
+ ],
152
166
  },
153
167
  ];
154
168
  `;
@@ -292,7 +306,12 @@ export async function bootstrapScanner(
292
306
  const detections = await detectScanners(workspaceRoot);
293
307
  const available = detections.filter((d) => d.available);
294
308
 
295
- if (available.length > 0) {
309
+ // A scanner is truly "configured" only if it also has a config
310
+ // file. ESLint in package.json without eslint.config.mjs will crash.
311
+ const eslintNeedsConfig = available.some((d) => d.scanner === "eslint")
312
+ && !detections.some((d) => d.scanner === "eslint" && d.configPath);
313
+
314
+ if (available.length > 0 && !eslintNeedsConfig) {
296
315
  const existingScanners = available.map((d) => d.scanner);
297
316
  logger.info(
298
317
  { existingScanners },
@@ -319,21 +338,32 @@ export async function bootstrapScanner(
319
338
  "bootstrap: detected project type",
320
339
  );
321
340
 
322
- // 3. Install scanner
341
+ // 3. Install scanner (skip npm install if already in package.json)
323
342
  if (recommendation.canAutoInstall) {
324
- // JS/TS: auto-install ESLint
325
343
  const isTypeScript = projectType === "typescript";
326
- const packages = isTypeScript
327
- ? ["eslint", "@eslint/js", "typescript-eslint"]
328
- : ["eslint", "@eslint/js"];
329
-
330
- const installStep = await npmInstall(workspaceRoot, packages);
331
- steps.push(installStep);
332
-
333
- if (installStep.success) {
334
- const configStep = writeEslintConfigFile(workspaceRoot, isTypeScript);
335
- steps.push(configStep);
344
+ const eslintAlreadyInstalled = available.some((d) => d.scanner === "eslint");
345
+
346
+ if (!eslintAlreadyInstalled) {
347
+ const packages = isTypeScript
348
+ ? ["eslint", "@eslint/js", "typescript-eslint"]
349
+ : ["eslint", "@eslint/js"];
350
+ const installStep = await npmInstall(workspaceRoot, packages);
351
+ steps.push(installStep);
352
+ if (!installStep.success) {
353
+ // npm install failed — skip config creation, fall through to result
354
+ return buildResult(projectType, steps, null);
355
+ }
356
+ } else {
357
+ steps.push({
358
+ action: "npm install eslint",
359
+ success: true,
360
+ detail: "eslint already in package.json — skipped install",
361
+ });
336
362
  }
363
+
364
+ // Always create config if missing
365
+ const configStep = writeEslintConfigFile(workspaceRoot, isTypeScript);
366
+ steps.push(configStep);
337
367
  } else {
338
368
  // Python / Java / C# / Unknown: return instructions
339
369
  steps.push({
@@ -409,18 +439,31 @@ export async function bootstrapScanner(
409
439
  }
410
440
 
411
441
  // 5. Build result
442
+ return buildResult(projectType, steps, autoScanResult, recommendation);
443
+ }
444
+
445
+ /**
446
+ * Build a BootstrapResult from the collected steps and optional scan result.
447
+ */
448
+ function buildResult(
449
+ projectType: ProjectType,
450
+ steps: BootstrapStep[],
451
+ autoScanResult: AutoScanResult | null,
452
+ recommendation?: { scanner: KnownScanner; canAutoInstall: boolean; installInstructions: string },
453
+ ): BootstrapResult {
454
+ const success = steps.every((s) => s.success);
412
455
  const findings = autoScanResult?.totalFindings ?? 0;
413
- const scannerInstalled = recommendation.canAutoInstall && installSucceeded;
456
+ const scanner = recommendation?.scanner ?? "unknown";
414
457
 
415
458
  let summary: string;
416
- if (scannerInstalled && autoScanResult) {
417
- summary = `Installed ${recommendation.scanner} for ${projectType} project. Auto-scan found ${findings} finding(s).`;
418
- } else if (scannerInstalled) {
419
- summary = `Installed ${recommendation.scanner} for ${projectType} project. Auto-scan did not run.`;
420
- } else if (!recommendation.canAutoInstall) {
421
- summary = `Detected ${projectType} project. Install ${recommendation.scanner} manually: ${recommendation.installInstructions}`;
459
+ if (success && autoScanResult) {
460
+ summary = `Configured ${scanner} for ${projectType} project. Scan found ${findings} finding(s).`;
461
+ } else if (success && recommendation && !recommendation.canAutoInstall) {
462
+ summary = `Detected ${projectType} project. Install ${scanner} manually: ${recommendation.installInstructions}`;
463
+ } else if (success) {
464
+ summary = `Configured ${scanner} for ${projectType} project.`;
422
465
  } else {
423
- summary = `Failed to install ${recommendation.scanner}. Check the error details in the steps.`;
466
+ summary = `Failed to configure ${scanner}. Check the error details in the steps.`;
424
467
  }
425
468
 
426
469
  return {
@@ -429,7 +472,7 @@ export async function bootstrapScanner(
429
472
  existingScanners: [],
430
473
  steps,
431
474
  autoScanResult,
432
- success: installSucceeded,
475
+ success,
433
476
  summary,
434
477
  };
435
478
  }
@@ -124,8 +124,14 @@ export function runScanner(
124
124
  const durationMs = Date.now() - start;
125
125
 
126
126
  // For scanners where non-zero exit means "findings exist",
127
- // we still have valid output in stdout.
128
- if (err && !cmd.nonZeroIsNormal) {
127
+ // we still have valid output in stdout. But if the scanner
128
+ // crashed (e.g. ESLint with no config file), treat it as a
129
+ // real failure even when nonZeroIsNormal is set.
130
+ const isFatalError = cmd.nonZeroIsNormal
131
+ && err
132
+ && (!stdout?.trim() || stderr?.includes("Oops!") || stderr?.includes("couldn't find"));
133
+
134
+ if (err && (!cmd.nonZeroIsNormal || isFatalError)) {
129
135
  // Stryker: check if the output file was written despite the error
130
136
  if (cmd.outputFile && existsSync(cmd.outputFile)) {
131
137
  try {