Skip to content

fix(install): add prepare script so git installs build dist/#165

Open
johnkattenhorn wants to merge 1 commit intoLarsCowe:mainfrom
johnkattenhorn:pr-prepare-script
Open

fix(install): add prepare script so git installs build dist/#165
johnkattenhorn wants to merge 1 commit intoLarsCowe:mainfrom
johnkattenhorn:pr-prepare-script

Conversation

@johnkattenhorn
Copy link
Copy Markdown

Problem

Installing bmalph from git (e.g. npm install -g github:LarsCowe/bmalph or any fork thereof) leaves the CLI broken:

$ npm install -g github:LarsCowe/bmalph
added 24 packages in 8s

$ bmalph --version
/usr/bin/bmalph: line 1: syntax error near unexpected token

Root cause: npm's git-install path runs the prepare lifecycle script, not prepack. The current package.json only defines prepack (which runs when npm pack builds a tarball for registry publishing). So git installs skip the TypeScript build entirely and the installed package has no dist/ directory — bin/bmalph.js imports ../dist/... and crashes at launch.

Regular registry installs (npm install bmalph) work because the tarball published to npm already has dist/ baked in (via prepack).

Fix

Add a prepare script that builds when tsconfig.json is present (git-install case) and no-ops otherwise (tarball-install case):

"prepare": "[ -f tsconfig.json ] && npm run build || true",

The guard ensures the script is safe for both install paths:

  • Git install: tsconfig.json is in the clone → build runs → dist/ populated → CLI works.
  • Registry install: tsconfig.json is not shipped in the tarball (not in the files whitelist) → guard is false → no-op.

Why this matters for forks

Anyone forking bmalph for private or team use (pinning a commit for stability, or prototyping a change before upstreaming) hits this immediately. The fix is one line and is npm-lifecycle-standard.

Test plan

  • npm install in a clone still works — prepare builds dist/ automatically.
  • npm pack still produces a working tarball (prepack handles that path).
  • Manual: npm install -g github:johnkattenhorn/bmalph#pr-prepare-scriptbmalph --version prints version. Before this change: install succeeds but the binary is broken.
  • Local test suite (npm test) — unchanged (4 pre-existing unrelated failures in installer.test.ts about .ralphrc template variants; not affected by this change).

Not in scope

  • The 4 .ralphrc template-variant test failures I spotted during this work. Will follow up with a separate PR for that.

Consumers installing via `npm install -g github:LarsCowe/bmalph` (or
any fork thereof) run npm's `prepare` lifecycle, not `prepack`.
Without a prepare script, `dist/` is never built at install time and
the CLI fails at launch (missing compiled output).

The `[ -f tsconfig.json ]` guard skips compilation in the published
tarball case where tsconfig.json is excluded (via .npmignore or the
`files` whitelist), so the script is a no-op for regular
`npm install bmalph` consumers.

Test plan:
1. From a clean directory: `npm install -g github:LarsCowe/bmalph#pr-prepare-script`
2. `bmalph --version` should print the installed version (previously:
   `/usr/bin/bmalph: cannot execute` because `dist/` missing).
3. Regular npm registry installs (`npm install bmalph`) unchanged —
   tsconfig.json not in the tarball, guard trips, no-op.
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