Skip to content

cli: read the version through a static import, so a compiled binary starts - #630

Merged
ronleizrowice-ant merged 2 commits into
anthropics:mainfrom
TurtIeSocks:cli-static-version-import
Oct 5, 2026
Merged

ronleizrowice-ant merged 2 commits into
anthropics:mainfrom
TurtIeSocks:cli-static-version-import

Conversation

@TurtIeSocks

Copy link
Copy Markdown
Contributor

srt built with bun build --compile exits at start with Cannot find module '../package.json'. #571 made getPackageVersion load the manifest with createRequire at runtime, and a single-file binary has no manifest beside it. #592's bundled test compiles a program that imports dist/, not the CLI, so it doesn't reach this.

  • Import the manifest statically instead. dist/cli.js resolves the same file as before, and Bun embeds it in the binary
  • Still no fallback, as the comment says
  • npm run build, typecheck and lint pass, and bun test matches main locally
  • node dist/cli.js --version and the compiled binary both print 0.0.77, and the binary sandboxes as expected on macOS

🤖 Generated with Claude Code

…tarts

`srt` built into a single file with `bun build --compile` exits before
it parses any argument:

    Fatal error: error: Cannot find module '../package.json' from
    '/$bunfs/root/srt-bun'

anthropics#571 made `getPackageVersion` load the manifest with
`createRequire(import.meta.url)('../package.json')`, which is resolved
at run time. From `dist/cli.js` that finds the package's own manifest,
but a compiled binary's module lives in Bun's virtual filesystem and
has no manifest beside it, so the require throws. The CLI calls
`getPackageVersion` while it builds the commander program, so every
invocation fails, not only `--version`.

anthropics#592's new bundled test compiles a program that imports `dist/` with
`bun build --compile`, which is the library path embedders use. It
never compiles `src/cli.ts`, so it does not reach this.

A static JSON import (`with { type: 'json' }`) resolves the same file
for `tsc`'s output, where `dist/cli.js` still reads `../package.json`
at load time as before, and lets Bun embed the manifest in a compiled
binary. The unused `createRequire` import goes, and the comment says
why the import is static. The no-fallback rule the comment states is
unchanged: a missing manifest still fails rather than printing a
made-up version.

Checked on macOS:
- `npm run build`, `npm run typecheck` and `eslint src/cli.ts` pass
- `node dist/cli.js --version` prints 0.0.77
- `bun build --compile --minify src/cli.ts` gives a binary that prints
  0.0.77 and sandboxes as expected: a write to the home folder is
  refused, the network is closed without an allowlist, and with
  `allowedDomains: ["example.com"]` only that host is reachable
- `bun test` gives the same results with and without the change here
  (1201 pass, 4 fail both ways: three need ripgrep installed, one is a
  3 s timing test)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ronleizrowice-ant added a commit that referenced this pull request Oct 2, 2026
Clean. An outside contributor's fix: `srt` compiled to a single file starts.
ronleizrowice-ant added a commit that referenced this pull request Oct 2, 2026
With #630 in, both Docker legs failed here: the image's Node 18 does not
parse the import of package.json. The runner's Node is bound in, as on
#643; bun still comes by checksum, as the bundle has it.

@antdres antdres left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/stamp

@ronleizrowice-ant ronleizrowice-ant left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/stamp

@ronleizrowice-ant
ronleizrowice-ant enabled auto-merge (squash) October 5, 2026 17:20

@ronleizrowice-ant ronleizrowice-ant left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/stamp

@ronleizrowice-ant
ronleizrowice-ant merged commit 232db17 into anthropics:main Oct 5, 2026
16 checks passed
@ronleizrowice-ant ronleizrowice-ant mentioned this pull request Oct 6, 2026
ronleizrowice-ant added a commit that referenced this pull request Oct 7, 2026
New to the bundle: #655, #660 and the version. #643, #639 and #630 come as
squashes of what it held; in the one block git marks, the workflow's, it
keeps its own side, which has the checksummed bun as well.

Two cases of #655 compare two wrapped commands. Here a wrap that names
mount points names a manifest of its own (#584), so the cases take that
name out before they compare.
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.

3 participants