Skip to content

fix(scripts): make the backfill scripts actually runnable - #161

Merged
gibbsie merged 1 commit into
mainfrom
fix/backfill-script-runnability
Sep 11, 2026
Merged

gibbsie merged 1 commit into
mainfrom
fix/backfill-script-runnability

Conversation

@gibbsie

@gibbsie gibbsie commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

backfill-org-name-reservations.ts could not be run. Operational failures when trying, because three separate defects stacked - and none was caught in review, since the script was verified by unit-testing its exported functions and never executed as a CLI.

  1. backend/tsconfig-json pinned typeRoots: ["-/node_modules/@types"], resolving to backend/node_modules/@types- nonexistent when pm hoists the workspace install to the repo root. Result: TS2580: Cannot find name 'process' This was invisible in a clone that installs inside backend/, which is exactly why it shipped
  2. The script mixed module systems: ESM import statements with a Commons require.main === module entry guard. Fine under ts-node; under Node's native TypeScript execution (23+) the file is ESM and require is undefined
  3. No wired npm script, so invocation depended on npx resolution and the current directory

- tsconfig: drop explicit typeRoots so TS's default upward @types search
  works under both hoisted-to-root and installed-in-backend npm layouts
  (fixes TS2580 'Cannot find name process' when node_modules is hoisted)
- entry guard: detect CJS (require.main === module) vs native ESM
  (typeof require === 'undefined') so main() runs under both ts-node and
  Node's native .ts execution, instead of only ts-node/CommonJS
- wire canonical, directory-independent npm scripts: backfill:org-ids and
  backfill:org-name-reservations
- add a subprocess smoke test that executes each script as a real CLI
  (npm run / ts-node / native node) and asserts on exit code + stderr,
  since unit-testing exported functions alone let this ship unrunnable
- tighten pre-existing 'any' types in backfill-org-ids.ts (blocked
  lint-staged's --max-warnings 0 gate on this now-touched file)

Sibling scripts/backfill-app-stage-vars.ts already uses the same
require.main guard shape but was out of scope (not named in the defect
report); noted for follow-up. src/lambda/backfill-project-org.ts has no
CLI entry point (Lambda-only, manually invoked), so causes (a)/(b) do
not apply to it.
@gibbsie
gibbsie merged commit c63de7e into main Sep 11, 2026
15 checks passed
@gibbsie
gibbsie deleted the fix/backfill-script-runnability branch September 11, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant