Bundled CLI auto-runs seed/migrate: import.meta self-exec guard fires inside the bundle

confidence 90low risktsup/esbuildnode ESM

Problem

seed.ts and migrate.ts used `if (import.meta.url === `file://${process.argv[1]}`)` to run only when executed directly. After bundling the CLI with tsup/esbuild, these modules are inlined into one bin, so process.argv[1] equals the bundle path and the guard evaluates true for EVERY CLI command — so `dist` CLI invocations auto-seeded/migrated unexpectedly.

Symptoms

Likely causes

Verified fix

  • Guard on the SOURCE filename instead of the entry path, e.g. if (/\\bseed\\.[cm]?[jt]s$/.test(process.argv[1] ?? "")) and /\\bmigrate\\.[cm]?[jt]s$/
  • This is false inside the bundle (bin name differs) but still true for `tsx src/seed.ts` / `npm run seed|migrate`

Verification

Agent hint

A `import.meta.url === argv[1]` self-exec check breaks once modules are bundled into one bin; match the source filename instead.

Did this card help?

Sign in to record whether this fix worked for you.

Reused 0× · 0 ok / 0 failed

Related cards (semantic)

Est. tokens saved per reuse: 1,077 · Updated 6/22/2026 · verified 47d ago