The scripts block in package.json is the part of a project nobody reviews. It accretes. On a team it eventually gets a README section nobody updates, and in CI it gets a workflow file that quietly becomes the real list.

Nakodo has no CI and no team, so the scripts block is the entire operator interface: if a thing is not in there or in the scripts/ folder, it does not happen. That makes it worth auditing properly, and the audit turned up one real bug.

Seventeen, and only five are ours

{ "dev": "next dev", "build": "next build", "start": "next start", "lint": "eslint", "typecheck": "tsc --noEmit", "test": "tsx --test \"src/**/*.test.ts\"", "db:generate": "drizzle-kit generate", "db:migrate": "drizzle-kit migrate", "db:studio": "drizzle-kit studio", "research": "tsx scripts/research.ts", "pipeline": "tsx scripts/pipeline.ts", "trigger:dev": "trigger.dev dev", "trigger:deploy": "trigger.dev deploy", "benchmark": "tsx scripts/benchmark-models.ts", "stripe:listen": "stripe listen --forward-to localhost:3000/api/stripe/webhook", "check:social": "tsx scripts/check-social.ts", "indexnow": "tsx scripts/indexnow.ts" } 
Kind Count
A vendor CLI with no arguments of ours 10
tsx pointed at a file in scripts/ 5
A check (typecheck, test) 2

Ten of the seventeen exist only so that I do not have to remember whether the binary is called drizzle-kit or drizzle and whether the subcommand is migrate or push. That is a real function and it is the main one: a scripts block is mostly a spelling aid.

Things that are not in there, each of which is a decision:

  • No format. There is no Prettier in this repo and no formatter config of any kind. Every line is wrapped by hand to about 120 columns, and running prettier --write once would reflow every file in the project into one unreadable diff.
  • No prepare, so no git hooks. Nothing runs on commit.
  • No postinstall. Nothing runs on install.
  • No ci or verify aggregate. pnpm typecheck && pnpm test && pnpm lint is three commands I type, in that order, because typecheck fails fastest.

The thing I did not expect from writing this list out is how much the absence of CI changes what a script is for. With CI, scripts are an API for a machine, so they have to be composable and silent. Without it, every script is something a human types at a prompt and reads the output of, which means the valuable thing about a script is not its exit code but what it prints.

Seven files, five of them reachable

$ wc -l scripts/*.ts 565 scripts/benchmark-models.ts 423 scripts/simulate-replies.ts 402 scripts/try-prompts.ts 251 scripts/pipeline.ts 131 scripts/check-social.ts 80 scripts/indexnow.ts 48 scripts/research.ts 1900 total 

Five of those seven are named by a script. simulate-replies.ts and try-prompts.ts are not, and are run as pnpm tsx scripts/try-prompts.ts <case>. There is no reason for that beyond the order things were written in, and the effect is that two of the seven exist only if you already know they exist. ls scripts/ is not a thing anybody does; pnpm run is.

That is the first fix: a name for each. A script surface that is not complete is worse than one that is verbose, because the incomplete one teaches you not to trust it.

Every file documents itself in a comment

The convention across all seven is identical, and it was not planned: the file opens with what it is for, then its usage lines, then the first import.

// Announces pages to IndexNow (Bing, Yandex, Seznam, Naver) now, rather than // waiting for the hourly cron. See src/lib/seo/indexnow.ts. // pnpm indexnow pages new, changed or removed since the last announcement // pnpm indexnow --all every page // pnpm indexnow /guides/x ... just these pages // add --dry-run to list them without sending // Works from the live sitemap (nakodo.app/sitemap.xml), not this checkout, so // it only announces pages that are deployed. 

Not one of the seven has a --help flag. Three of them print a usage string when you get it wrong (pipeline, benchmark and research, the three that take subcommands or a required argument), and the other four print whatever the error was.

I have come round to thinking the comment is the better of the two, for a reason that has nothing to do with effort. A --help string is code: it can be out of date while the file still compiles and the tests still pass. A comment at the top of a 48 line file is read by the next person who opens the file for any reason at all, which is the same person who is about to change the behaviour. The comment above is also doing something a --help could not, which is telling you that the script reads the deployed sitemap rather than your working tree. You can go and fetch that file yourself and see exactly what the script will see. One of the other six opens by saying roughly what a run will cost in third-party API calls and in real money, which is precisely the sort of thing that belongs next to the code that spends it and nowhere else.

The one that has two sources of truth

pipeline.ts is 251 lines and fronts 14 subcommands. Its header comment documents all 14, in a 23 line block. Its dispatcher is 14 string comparisons:

const [command, ...args] = process.argv.slice(2); if (command === "launch") { const { launchCampaign } = await import("@/lib/pipeline/launch"); if (!args[0]) throw new Error("Usage: pnpm pipeline launch <campaignId>"); console.log(await launchCampaign(args[0])); return; } 

Then, at the bottom, the thing you actually see when you get it wrong:

console.error( "Usage: pnpm pipeline launch <campaignId> | run [--seconds N] [--max-searches N] [--once] | " + "status [campaignId] | recontacts | restat | icons | twins [--apply] | analyze [campaignId] | " + "rescore [campaignId] | maintenance | claim <email>", ); process.exit(1); 

Count them: eleven. The header documents fourteen. Three subcommands exist, work, and are invisible to anyone who types pnpm pipeline and reads the answer. They were added later, each time to the header and not to the string, which is exactly how a second source of truth fails: not by being wrong on the day it was written, but by being the copy nobody is looking at while they edit.

The fix is not "remember to update both". It is one array:

const COMMANDS = [ { name: "launch", args: "<campaignId>", help: "..." }, // ... ] as const; 

and then the dispatcher, the usage string and a --help all read from it, so adding a command without documenting it becomes impossible rather than discouraged. That is the shape of every documentation fix that has ever actually held.

Twenty-seven lazy imports in a 251 line file

Worth a note because it reads like a mistake and is not:

$ grep -c 'await import(' scripts/pipeline.ts 27 

Nothing at the top of that file imports anything from the app except dotenv. Every subcommand imports its own dependencies inside its own branch. The reason is startup: a static import of the app's database module opens a connection, and a static import of the queue pulls in the scheduler, so a file with fourteen static imports would connect to everything in order to run pnpm pipeline status. With the imports inside the branches, the only modules loaded are the ones that particular subcommand needs.

A secondary and more valuable effect is that a broken module only breaks the subcommands that use it. A typo in the keyword module does not stop me running claim to hand a campaign to a new account.

The line that every script needs and the app does not

All seven files start with the same two lines after the comment:

import { config } from "dotenv"; config({ path: [".env.local", ".env"], quiet: true }); 

Next loads .env.local for you, in next dev, in next build and at runtime. tsx scripts/whatever.ts is a plain Node process and gets none of that, so a script that imports the app's database module will reach for process.env.DATABASE_URL and find nothing. The ordering matters too: .env.local first, so a local override wins, and quiet: true so it does not print a banner into output I am reading as data.

It is two lines, it is in seven files, and it is the sort of duplication I keep deciding not to fix. A shared scripts/env.ts would have to be imported first, and an import whose position in the file is load bearing is a worse trap than a repeated line.

None of those 1,900 lines are tested

"test": "tsx --test \"src/**/*.test.ts\"" 

62 test files, all under src/. The glob cannot reach scripts/, so the 1,900 lines above have no tests at all, and pnpm lint does cover them only because eslint with no path argument lints everything that is not ignored.

I am comfortable with that for five of the seven, which are thin command line wrappers over library code in src/ that is itself tested. I am less comfortable about the two biggest, which contain real logic about how results are presented and compared. The honest summary is that the split is not a policy, it is just where the glob happens to stop.

What I am changing

  • A package.json entry for each of the two unreachable files.
  • One COMMANDS array in pipeline.ts feeding the dispatcher, the usage string and a new --help.
  • A --help flag on all seven, printing the header comment's usage lines, because the comment is already the canonical copy and a flag that reads from it cannot drift.
  • Leave the missing format script missing, and write that down somewhere better than a blog post.

If you want to run the audit on your own project, the two questions that found everything above were: which of my scripts point at code I wrote, and which files in my scripts folder are not named by any of them. Both are one command, and the second one is the one with the surprise in it.