@neon-pixels/scripts 0.3.0 → 0.4.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.
package/README.md CHANGED
@@ -10,15 +10,20 @@ pnpm add -D @neon-pixels/scripts
10
10
 
11
11
  ## `np-audit-gate`
12
12
 
13
- Audits production dependencies and fails on any high or critical advisory that is not on your reviewed allowlist. Moderate and low advisories are counted in the summary but never fail the gate.
13
+ Audits production dependencies (all dependencies with `--include-dev`) and fails on any high or critical advisory that is not on your reviewed allowlist. Moderate and low advisories are counted in the summary but never fail the gate.
14
14
 
15
15
  ```sh
16
16
  pnpm exec np-audit-gate
17
17
  pnpm exec np-audit-gate --allowlist path/to/audit-allowlist.json
18
+ pnpm exec np-audit-gate --include-dev
18
19
  ```
19
20
 
20
21
  Run it from the project root. It picks the package manager from the lockfile (`pnpm-lock.yaml`, `package-lock.json`, or `npm-shrinkwrap.json`) and runs `pnpm audit --prod --json` or `npm audit --omit=dev --json`. A project with no lockfile, or with both kinds, fails.
21
22
 
23
+ `--include-dev` audits every dependency, dev dependencies included, with `pnpm audit --json` or `npm audit --json`. Use it for a site whose framework and build tooling are all dev dependencies, so the default scope covers almost nothing. The default scope is unchanged. The allowlist format, expiry, stale-entry reporting, fail-closed handling, and step summary are the same in both modes, and one allowlist file serves both. The printed result and the step summary heading name the audited scope (`production dependencies` or `all dependencies`), so two runs in one workflow can be told apart.
24
+
25
+ An allowlist entry for an advisory that only exists in a dev dependency is reported as stale in a production-only run, because that run never sees the advisory. Treat the stale warning as expected when you run both scopes from one allowlist.
26
+
22
27
  The gate fails closed: empty output, an audit error (registry down), or an unrecognized JSON shape fails instead of passing, an advisory it cannot identify is never allowlisted, and any severity other than info, low, or moderate blocks.
23
28
 
24
29
  When `GITHUB_STEP_SUMMARY` is set, it appends a severity table, the allowlisted advisories, and any stale allowlist entries.
@@ -92,6 +97,9 @@ Environment variables, all passed by the workflow:
92
97
 
93
98
  - `CURRENT_SHA`: the commit on `main` to compare against the live deploy.
94
99
  - `NETLIFY_SITE_ID` and `NETLIFY_AUTH_TOKEN`: the site and a Netlify personal access token that can read it.
100
+ - `GITHUB_EVENT_NAME`: set by GitHub on every step. Inside a reusable workflow it holds the caller's event, so no input is needed.
101
+
102
+ A manual run (`GITHUB_EVENT_NAME` of `workflow_dispatch`) always deploys: it writes `skip=false`, prints that a manual run always deploys, and never calls Netlify. This covers a rebuild after a Netlify environment variable change, which does not change the commit. Every other event, and an unset `GITHUB_EVENT_NAME`, is decided as described below. In `production-deploy-decide.yml` the `require-ci-workflow` check still runs on a manual run, because a manual run forces the deploy decision, not the CI gate. Requires a `scripts-version` that includes this change; older versions still skip a manual run when the commit is already live.
95
103
 
96
104
  The live commit is the one the site's published deploy was built from (`published_deploy.commit_ref` from `GET /sites/{id}`), so a manual rollback or locked auto-publishing is compared against what visitors are served, not the newest ready deploy.
97
105
 
@@ -182,6 +190,8 @@ pnpm exec np-sync-templates --stack nuxt --check
182
190
 
183
191
  Run it from the repository root. `--stack` is required and is `nuxt`, `vitepress`, or `node`. With `--check` nothing is written: it prints a diff for every file that differs (`-` is the repository's line, `+` the template's) and exits 1, so CI can fail on drift.
184
192
 
193
+ The Dependabot config groups every `@neon-pixels/*` update, of any kind, into its own pull request. The `neon-pixels` group is listed first among the npm groups because Dependabot puts a dependency in the first group that matches it; placed after `minor-and-patch`, it would never receive minor or patch bumps.
194
+
185
195
  It touches only these files, and refuses any path that is a symlink or resolves outside the current directory:
186
196
 
187
197
  | File | Variants |
@@ -194,7 +204,7 @@ It touches only these files, and refuses any path that is a symlink or resolves
194
204
  | `.husky/post-merge` | none |
195
205
  | `package.json` `engines` | none; sets `engines.node` and leaves every other field alone |
196
206
 
197
- `engines.node` is a range that accepts the version pinned in `.nvmrc`, so tooling that checks `engines` can reject an unsupported Node version (npm and pnpm only warn unless `engine-strict=true` is set in `.npmrc`, which this sync does not manage). The hooks assume npm; the pre-push hooks run `lint`, `typecheck`, and `test:ci` scripts.
207
+ `engines.node` is a range that accepts the version pinned in `.nvmrc`. The Node 22 floor is 22.18.0 because Node runs TypeScript files directly (`node file.ts`) without a flag from that release, and synced projects run `.ts` scripts that way. Odd-numbered releases (Node 23 and 25) are left out on purpose, since they are short-lived and never reach long-term support; the open-ended `>=26.0.0` keeps later majors working without a template change. Tooling that checks `engines` can reject an unsupported Node version (npm and pnpm only warn unless `engine-strict=true` is set in `.npmrc`, which this sync does not manage). The hooks assume npm; the pre-push hooks run `lint`, `typecheck`, and `test:ci` scripts.
198
208
 
199
209
  ### Repo-specific sections
200
210
 
@@ -3,6 +3,38 @@ import { spawnSync } from "node:child_process";
3
3
  import { appendFileSync, existsSync, readFileSync, readdirSync } from "node:fs";
4
4
  import { parseArgs } from "node:util";
5
5
  import { a as isBlocking, i as parseAllowlist, n as entryCovers, o as parseAuditReport, r as isExpired } from "./allowlist-B_zgqKrH.js";
6
+ // src/audit-gate/package-manager.ts
7
+ const LOCKFILES = /* @__PURE__ */ new Map([
8
+ ["pnpm-lock.yaml", "pnpm"],
9
+ ["package-lock.json", "npm"],
10
+ ["npm-shrinkwrap.json", "npm"]
11
+ ]);
12
+ /** Picks the package manager from the lockfiles present in the project. */
13
+ function detectPackageManager(fileNames) {
14
+ const found = new Set(fileNames.flatMap((name) => LOCKFILES.get(name) ?? []));
15
+ if (found.size === 0) throw new Error("no supported lockfile found (pnpm-lock.yaml, package-lock.json, npm-shrinkwrap.json)");
16
+ if (found.size > 1) throw new Error("both npm and pnpm lockfiles found, keep only one");
17
+ return [...found][0];
18
+ }
19
+ const SCOPE_LABELS = {
20
+ production: "production dependencies",
21
+ all: "all dependencies"
22
+ };
23
+ const PRODUCTION_FLAGS = {
24
+ pnpm: "--prod",
25
+ npm: "--omit=dev"
26
+ };
27
+ /** JSON output; the gate does its own severity filtering. */
28
+ function auditCommandFor(packageManager, scope = "production") {
29
+ return {
30
+ command: packageManager,
31
+ args: [
32
+ "audit",
33
+ ...scope === "production" ? [PRODUCTION_FLAGS[packageManager]] : [],
34
+ "--json"
35
+ ]
36
+ };
37
+ }
6
38
  // src/audit-gate/gate.ts
7
39
  const REPORTED_SEVERITIES = [
8
40
  "critical",
@@ -41,10 +73,10 @@ function otherSeverityRows(counts) {
41
73
  return Object.entries(counts).filter(([severity]) => !REPORTED_SEVERITIES.includes(severity)).map(([severity, count]) => `| ${severity} | ${count} |`);
42
74
  }
43
75
  /** Markdown for the GitHub step summary. */
44
- function formatSummary(result) {
76
+ function formatSummary(result, scope = "production") {
45
77
  const { severityCounts } = result;
46
78
  const lines = [
47
- "## Dependency audit",
79
+ `## Dependency audit (${SCOPE_LABELS[scope]})`,
48
80
  "",
49
81
  "| Severity | Advisories |",
50
82
  "| -------- | ---------- |",
@@ -68,46 +100,14 @@ function formatSummary(result) {
68
100
  }
69
101
  return `${lines.join("\n")}\n`;
70
102
  }
71
- // src/audit-gate/package-manager.ts
72
- const LOCKFILES = /* @__PURE__ */ new Map([
73
- ["pnpm-lock.yaml", "pnpm"],
74
- ["package-lock.json", "npm"],
75
- ["npm-shrinkwrap.json", "npm"]
76
- ]);
77
- /** Picks the package manager from the lockfiles present in the project. */
78
- function detectPackageManager(fileNames) {
79
- const found = new Set(fileNames.flatMap((name) => LOCKFILES.get(name) ?? []));
80
- if (found.size === 0) throw new Error("no supported lockfile found (pnpm-lock.yaml, package-lock.json, npm-shrinkwrap.json)");
81
- if (found.size > 1) throw new Error("both npm and pnpm lockfiles found, keep only one");
82
- return [...found][0];
83
- }
84
- /** Production dependencies only, JSON output; the gate does its own filtering. */
85
- function auditCommandFor(packageManager) {
86
- if (packageManager === "pnpm") return {
87
- command: "pnpm",
88
- args: [
89
- "audit",
90
- "--prod",
91
- "--json"
92
- ]
93
- };
94
- return {
95
- command: "npm",
96
- args: [
97
- "audit",
98
- "--omit=dev",
99
- "--json"
100
- ]
101
- };
102
- }
103
103
  const MAX_AUDIT_OUTPUT_BYTES = 67108864;
104
104
  function readAuditOutput(command, result) {
105
105
  if (result.error) throw new Error(`could not run ${command}: ${result.error.message}`);
106
106
  if (result.stdout.trim() === "" && result.stderr.trim() !== "") throw new Error(`${command} audit failed: ${result.stderr.trim()}`);
107
107
  return result.stdout;
108
108
  }
109
- function runAuditCommand(packageManager) {
110
- const { command, args } = auditCommandFor(packageManager);
109
+ function runAuditCommand(packageManager, scope) {
110
+ const { command, args } = auditCommandFor(packageManager, scope);
111
111
  return readAuditOutput(command, spawnSync(command, args, {
112
112
  encoding: "utf-8",
113
113
  maxBuffer: MAX_AUDIT_OUTPUT_BYTES
@@ -128,26 +128,37 @@ function loadAllowlist(environment, explicitPath) {
128
128
  if (content === null && explicitPath !== void 0) throw new Error(`allowlist file not found: ${explicitPath}`);
129
129
  return content === null ? [] : parseAllowlist(content);
130
130
  }
131
- function printResult(result) {
131
+ function printResult(result, scope) {
132
+ console.log(`np-audit-gate: audited ${SCOPE_LABELS[scope]}`);
132
133
  for (const entry of result.staleEntries) console.warn(`np-audit-gate: stale allowlist entry ${entry.id}, remove it`);
133
134
  for (const failure of result.failures) console.error(`np-audit-gate: ${failure}`);
134
- if (result.failures.length === 0) console.log("np-audit-gate: no un-allowlisted high or critical advisories");
135
+ if (result.failures.length === 0) console.log(`np-audit-gate: no un-allowlisted high or critical advisories in ${SCOPE_LABELS[scope]}`);
135
136
  }
136
137
  function runGate(argv, environment) {
137
138
  const { values } = parseArgs({
138
139
  args: argv,
139
- options: { allowlist: { type: "string" } }
140
+ options: {
141
+ allowlist: { type: "string" },
142
+ "include-dev": {
143
+ type: "boolean",
144
+ default: false
145
+ }
146
+ }
140
147
  });
148
+ const scope = values["include-dev"] ? "all" : "production";
141
149
  const allowlist = loadAllowlist(environment, values.allowlist);
142
150
  const packageManager = detectPackageManager(environment.listProjectFiles());
143
- return evaluateAudit(parseAuditReport(environment.runAudit(packageManager)), allowlist, environment.now());
151
+ return {
152
+ result: evaluateAudit(parseAuditReport(environment.runAudit(packageManager, scope)), allowlist, environment.now()),
153
+ scope
154
+ };
144
155
  }
145
156
  /** Runs the gate and returns the process exit code. */
146
157
  function runAuditGate(argv, environment = systemEnvironment) {
147
158
  try {
148
- const result = runGate(argv, environment);
149
- printResult(result);
150
- environment.appendStepSummary(formatSummary(result));
159
+ const { result, scope } = runGate(argv, environment);
160
+ printResult(result, scope);
161
+ environment.appendStepSummary(formatSummary(result, scope));
151
162
  return result.failures.length > 0 ? 1 : 0;
152
163
  } catch (error) {
153
164
  const reason = error instanceof Error ? error.message : String(error);
@@ -31,6 +31,8 @@ const systemEnvironment = {
31
31
  }),
32
32
  appendOutput: (path, text) => appendFileSync(path, text)
33
33
  };
34
+ const MANUAL_RUN_EVENT = "workflow_dispatch";
35
+ const MANUAL_RUN_REASON = "A manual run always deploys.";
34
36
  function log(message) {
35
37
  console.log(`np-should-deploy: ${escapeWorkflowCommand(message)}`);
36
38
  }
@@ -48,6 +50,9 @@ async function lookUpPublishedSha(environment) {
48
50
  return null;
49
51
  }
50
52
  }
53
+ function isManualRun(environment) {
54
+ return environment.variables["GITHUB_EVENT_NAME"] === MANUAL_RUN_EVENT;
55
+ }
51
56
  function writeDecision(environment, deploy) {
52
57
  const outputPath = environment.variables["GITHUB_OUTPUT"];
53
58
  if (!outputPath) {
@@ -63,6 +68,11 @@ async function runShouldDeploy(argv, environment = systemEnvironment) {
63
68
  args: argv,
64
69
  options: {}
65
70
  });
71
+ if (isManualRun(environment)) {
72
+ log(MANUAL_RUN_REASON);
73
+ writeDecision(environment, true);
74
+ return 0;
75
+ }
66
76
  const currentSha = environment.variables["CURRENT_SHA"] || null;
67
77
  const { deploy, reason } = decideDeploy(currentSha, currentSha === null ? null : await lookUpPublishedSha(environment));
68
78
  log(reason);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neon-pixels/scripts",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "CI and deploy scripts for Neon Pixels projects: dependency audit gate, a build-output check that a dependency is absent, GitHub Actions pinning check, migration bookkeeping checks, Lighthouse failure reporting, Netlify production deploy checks, and a sync of hooks, Dependabot, gitleaks, and Node version templates.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,6 +9,12 @@ updates:
9
9
  schedule:
10
10
  interval: weekly
11
11
  groups:
12
+ # Listed first on purpose: Dependabot assigns a dependency to the first
13
+ # group that matches it, so the shared packages must be claimed before
14
+ # `minor-and-patch` can swallow their minor and patch bumps.
15
+ neon-pixels:
16
+ patterns:
17
+ - "@neon-pixels/*"
12
18
  # Collapse all minor and patch bumps into a single PR to reduce churn.
13
19
  minor-and-patch:
14
20
  update-types:
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "engines": {
3
- "node": "^22.17.0 || ^24.0.0 || >=26.0.0"
3
+ "node": "^22.18.0 || ^24.0.0 || >=26.0.0"
4
4
  }
5
5
  }
@@ -9,9 +9,14 @@ updates:
9
9
  schedule:
10
10
  interval: weekly
11
11
  groups:
12
- # Listed first so minor and patch bumps, vite and vitepress included, land
13
- # in one weekly PR. Dependabot assigns an update to the first group that
14
- # matches it.
12
+ # Listed first on purpose: Dependabot assigns a dependency to the first
13
+ # group that matches it, so the shared packages must be claimed before
14
+ # `minor-and-patch` can swallow their minor and patch bumps.
15
+ neon-pixels:
16
+ patterns:
17
+ - "@neon-pixels/*"
18
+ # Kept ahead of `vite-vitepress` so minor and patch bumps, vite and
19
+ # vitepress included, land in one weekly PR.
15
20
  minor-and-patch:
16
21
  update-types:
17
22
  - minor