shippingszn 0.3.0 → 0.5.0

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,4 +1,55 @@
1
+ import { readFileSafe } from "../scan.js";
1
2
  import { findPublicDirs, isAssetEmittedDynamically } from "./helpers.js";
3
+ /**
4
+ * Parse a robots.txt body and return true if the `User-agent: *` block (or
5
+ * any wildcard block) disallows everything (`Disallow: /`). That's a
6
+ * declaration that the site intentionally opts out of all crawling, so we
7
+ * shouldn't nag about a missing sitemap — sitemaps for disallowed sites are
8
+ * contradictory.
9
+ */
10
+ function robotsDisallowsAll(content) {
11
+ const lines = content.split(/\r?\n/);
12
+ let inWildcardBlock = false;
13
+ let sawWildcardBlock = false;
14
+ for (const raw of lines) {
15
+ // Strip comments and trailing whitespace.
16
+ const line = raw.replace(/#.*$/, "").trim();
17
+ if (line === "") {
18
+ // Blank line ends the current block.
19
+ inWildcardBlock = false;
20
+ continue;
21
+ }
22
+ const match = line.match(/^([A-Za-z-]+)\s*:\s*(.*)$/);
23
+ if (!match)
24
+ continue;
25
+ const directive = match[1].toLowerCase();
26
+ const value = match[2].trim();
27
+ if (directive === "user-agent") {
28
+ inWildcardBlock = value === "*";
29
+ if (inWildcardBlock)
30
+ sawWildcardBlock = true;
31
+ continue;
32
+ }
33
+ if (inWildcardBlock && directive === "disallow" && value === "/") {
34
+ return true;
35
+ }
36
+ }
37
+ // If the file has no wildcard block at all, conservatively assume it
38
+ // doesn't disallow everything (some sites only target specific bots).
39
+ void sawWildcardBlock;
40
+ return false;
41
+ }
42
+ async function hasDisallowAllRobots(ctx) {
43
+ const robotsFiles = ctx.files.filter((f) => /(^|\/)robots\.txt$/i.test(f.relPath));
44
+ for (const file of robotsFiles) {
45
+ const content = await readFileSafe(file);
46
+ if (!content)
47
+ continue;
48
+ if (robotsDisallowsAll(content))
49
+ return true;
50
+ }
51
+ return false;
52
+ }
2
53
  export async function checkRobotsTxt(ctx) {
3
54
  const has = ctx.files.some((f) => /(^|\/)robots\.txt$/i.test(f.relPath));
4
55
  if (has)
@@ -26,6 +77,11 @@ export async function checkSitemapXml(ctx) {
26
77
  const dirs = await findPublicDirs(ctx);
27
78
  if (dirs.length === 0)
28
79
  return [];
80
+ // If the project has declared itself non-indexable via robots.txt
81
+ // (User-agent: * / Disallow: /), a sitemap would be contradictory.
82
+ // Suppress the nag — the site owner has made a deliberate choice.
83
+ if (await hasDisallowAllRobots(ctx))
84
+ return [];
29
85
  return [
30
86
  {
31
87
  checkId: "missing-sitemap-xml",
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import * as process from "node:process";
4
4
  import { ALL_CHECKS } from "./checks.js";
5
5
  import { listFiles, getTrackedFiles } from "./scan.js";
6
6
  import { CHECKLIST_ITEMS, permalinkFor } from "./items.js";
7
+ import { publishScan } from "./publish.js";
7
8
  const UNTRACKED_DOWNGRADE = {
8
9
  critical: "lower",
9
10
  high: "lower",
@@ -30,7 +31,7 @@ function applyTrackingAwareSeverity(findings, tracked) {
30
31
  });
31
32
  }
32
33
  const DEFAULT_BASE_URL = "https://shippingszn.com";
33
- const PKG_VERSION = "0.3.0";
34
+ const PKG_VERSION = "0.5.0";
34
35
  function parseArgs(argv) {
35
36
  const opts = {
36
37
  cwd: process.cwd(),
@@ -166,6 +167,20 @@ async function run() {
166
167
  totals,
167
168
  findings: enriched,
168
169
  };
170
+ // Best-effort anonymous publish to the Wall of Launches. Runs once per
171
+ // scan, before any return path. Never blocks on network failure. Full
172
+ // opt-out via SHIPPINGSZN_DISABLE_PUBLISH=1.
173
+ let publishResult = "skipped";
174
+ try {
175
+ publishResult = await publishScan(totals, files.length, {
176
+ cwd: opts.cwd,
177
+ baseUrl: opts.baseUrl,
178
+ scannerVersion: PKG_VERSION,
179
+ });
180
+ }
181
+ catch {
182
+ /* never block on wall publish */
183
+ }
169
184
  if (opts.json) {
170
185
  process.stdout.write(JSON.stringify(report, null, 2) + "\n");
171
186
  return totals.critical > 0 ? 1 : 0;
@@ -184,6 +199,9 @@ async function run() {
184
199
  process.stdout.write(c.dim(`Scanned ${files.length} files in ${opts.cwd}\n\n`));
185
200
  if (enriched.length === 0) {
186
201
  process.stdout.write(c.green("✓ No findings. Nice work — still walk through the full checklist before launch.\n\n"));
202
+ if (publishResult === "published") {
203
+ process.stdout.write(c.dim(`Posted an anonymous summary to the Wall: ${opts.baseUrl}/wall\n(opt out: SHIPPINGSZN_DISABLE_PUBLISH=1)\n\n`));
204
+ }
187
205
  return 0;
188
206
  }
189
207
  // Strip ASCII control characters (including ESC) so a maliciously-named
@@ -208,6 +226,9 @@ async function run() {
208
226
  process.stdout.write("\n");
209
227
  }
210
228
  process.stdout.write(`${c.bold("Summary:")} ${c.red(`${totals.critical} critical`)}, ${c.yellow(`${totals.high} high`)}, ${c.blue(`${totals.medium} medium`)}, ${c.gray(`${totals.lower} lower`)}\n`);
229
+ if (publishResult === "published") {
230
+ process.stdout.write(c.dim(`\nPosted an anonymous summary to the Wall: ${opts.baseUrl}/wall\n(opt out: SHIPPINGSZN_DISABLE_PUBLISH=1)\n`));
231
+ }
211
232
  if (totals.critical > 0) {
212
233
  process.stdout.write(c.red("\nCritical findings detected. Exiting with code 1.\n"));
213
234
  return 1;
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Anonymous auto-publish of scan results to the Wall of Launches at
3
+ * shippingszn.com. Runs once per scan, best-effort. Never blocks the CLI
4
+ * on network failure — if anything goes wrong we fail silently and the
5
+ * scan result still prints normally.
6
+ *
7
+ * Absolute guarantees about the payload: no secrets, no paths, no
8
+ * filenames, no project-name-derived strings. The only thing we send
9
+ * is: files scanned count, findings counts by severity, detected stack
10
+ * tags, scanner version. Users can opt out entirely by setting
11
+ * SHIPPINGSZN_DISABLE_PUBLISH=1 in their environment.
12
+ */
13
+ import { promises as fs } from "node:fs";
14
+ import * as path from "node:path";
15
+ const DEFAULT_BASE_URL = "https://shippingszn.com";
16
+ const PUBLISH_TIMEOUT_MS = 3000;
17
+ function shouldPublish() {
18
+ const v = process.env["SHIPPINGSZN_DISABLE_PUBLISH"] ?? "";
19
+ return v !== "1" && v.toLowerCase() !== "true" && v !== "yes";
20
+ }
21
+ // Detect a small list of tech-stack tags from package.json / manifest
22
+ // files. Deliberately shallow: we only want a handful of widely-known
23
+ // framework tags. Nothing else is read or transmitted.
24
+ async function detectStack(cwd) {
25
+ const tags = new Set();
26
+ try {
27
+ const raw = await fs.readFile(path.join(cwd, "package.json"), "utf8");
28
+ const pkg = JSON.parse(raw);
29
+ const deps = { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
30
+ const has = (n) => n in deps;
31
+ if (has("react"))
32
+ tags.add("react");
33
+ if (has("next"))
34
+ tags.add("next");
35
+ if (has("vue") || has("nuxt"))
36
+ tags.add("vue");
37
+ if (has("svelte") || has("@sveltejs/kit"))
38
+ tags.add("svelte");
39
+ if (has("astro"))
40
+ tags.add("astro");
41
+ if (has("express"))
42
+ tags.add("express");
43
+ if (has("fastify"))
44
+ tags.add("fastify");
45
+ if (has("hono"))
46
+ tags.add("hono");
47
+ if (has("drizzle-orm"))
48
+ tags.add("drizzle");
49
+ if (has("prisma"))
50
+ tags.add("prisma");
51
+ if (has("@supabase/supabase-js"))
52
+ tags.add("supabase");
53
+ if (has("firebase"))
54
+ tags.add("firebase");
55
+ if (has("stripe"))
56
+ tags.add("stripe");
57
+ if (has("typescript"))
58
+ tags.add("ts");
59
+ if (has("vite"))
60
+ tags.add("vite");
61
+ if (has("expo"))
62
+ tags.add("expo");
63
+ if (has("react-native"))
64
+ tags.add("react-native");
65
+ }
66
+ catch {
67
+ /* no package.json — not a node project, that's fine */
68
+ }
69
+ // Language/framework detection beyond node — cheap file-existence checks.
70
+ const checks = [
71
+ ["requirements.txt", "python"],
72
+ ["pyproject.toml", "python"],
73
+ ["Gemfile", "ruby"],
74
+ ["go.mod", "go"],
75
+ ["Cargo.toml", "rust"],
76
+ ["composer.json", "php"],
77
+ ["pom.xml", "java"],
78
+ ["build.gradle", "java"],
79
+ ];
80
+ for (const [file, tag] of checks) {
81
+ try {
82
+ await fs.access(path.join(cwd, file));
83
+ tags.add(tag);
84
+ }
85
+ catch {
86
+ /* not present */
87
+ }
88
+ }
89
+ return [...tags].slice(0, 12);
90
+ }
91
+ export function buildPayload(totals, filesScanned, stack, scannerVersion) {
92
+ const out = {
93
+ filesScanned,
94
+ findingsCritical: totals.critical ?? 0,
95
+ findingsHigh: totals.high ?? 0,
96
+ findingsMedium: totals.medium ?? 0,
97
+ findingsLower: totals.lower ?? 0,
98
+ scannerVersion,
99
+ };
100
+ if (stack.length > 0)
101
+ out.stack = stack;
102
+ return out;
103
+ }
104
+ export async function publishScan(totals, filesScanned, opts) {
105
+ if (!shouldPublish())
106
+ return "skipped";
107
+ const baseUrl = opts.baseUrl ?? DEFAULT_BASE_URL;
108
+ const stack = await detectStack(opts.cwd);
109
+ const payload = buildPayload(totals, filesScanned, stack, opts.scannerVersion);
110
+ const controller = new AbortController();
111
+ const timer = setTimeout(() => controller.abort(), PUBLISH_TIMEOUT_MS);
112
+ try {
113
+ const res = await fetch(`${baseUrl}/api/wall`, {
114
+ method: "POST",
115
+ headers: { "content-type": "application/json" },
116
+ body: JSON.stringify(payload),
117
+ signal: controller.signal,
118
+ });
119
+ clearTimeout(timer);
120
+ return res.ok ? "published" : "failed";
121
+ }
122
+ catch {
123
+ clearTimeout(timer);
124
+ return "failed";
125
+ }
126
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shippingszn",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Read-only CLI scanner that checks a project for common pre-launch issues from the shippingszn.com launch checklist.",
5
5
  "license": "MIT",
6
6
  "type": "module",