build: publish a self-contained single-file ESM bundle#22
Conversation
Add a `build:bundle` step that bundles `src/index.ts` into `dist/bundle.js` with `bun build --target=bun --format=esm`, inlining every npm dependency and leaving only `node:` builtins external. The bundle is wired into `postbuild`, so `npm run build` emits it alongside the tsc output, and it ships in the tarball via the existing `dist` files entry plus a new `./bundle` exports subpath. This lets the WorkOS CLI (a Bun-compiled standalone binary) download the tarball at runtime and `import()` the bundle directly, without needing node_modules beside it, while types keep coming from the package's main export as a build-time dependency. Install Bun in the CI and release workflows so the build step can produce the bundle before pack/publish.
Greptile SummaryThis PR adds a self-contained ESM bundle (
Confidence Score: 5/5Safe to merge — the changes are additive build infrastructure with no modifications to runtime logic. All three previously flagged issues (unpinned Bun version, missing types on the bundle export, undocumented Bun prerequisite) are fully addressed. The Bun action is pinned to both a commit SHA and a specific binary version, the ./bundle export correctly declares types pointing at the existing dist/index.d.ts, and the README now documents the Bun build dependency. No new correctness or security issues were found. No files require special attention. Important Files Changed
|
| "postbuild": "chmod +x ./dist/cli.js && npm run build:bundle", | ||
| "build:bundle": "bun build --target=bun --format=esm src/index.ts --outfile dist/bundle.js", |
There was a problem hiding this comment.
npm run build fails locally without Bun installed
postbuild unconditionally calls build:bundle, which invokes bun build. Any contributor who runs npm run build without Bun installed will get a hard failure after the TypeScript compile succeeds — the error message (bun: command not found) is not obvious about the cause. Consider documenting Bun as a dev prerequisite in the README, or making the bundle step opt-in (e.g., a separate build:full script) so standard npm run build continues to work in Node-only environments.
Prompt To Fix With AI
This is a comment left during a code review.
Path: package.json
Line: 67-68
Comment:
**`npm run build` fails locally without Bun installed**
`postbuild` unconditionally calls `build:bundle`, which invokes `bun build`. Any contributor who runs `npm run build` without Bun installed will get a hard failure after the TypeScript compile succeeds — the error message (`bun: command not found`) is not obvious about the cause. Consider documenting Bun as a dev prerequisite in the README, or making the bundle step opt-in (e.g., a separate `build:full` script) so standard `npm run build` continues to work in Node-only environments.
How can I resolve this? If you propose a fix, please make it concise.Address review feedback: pin bun-version 1.3.11 in CI and release workflows so the published bundle is reproducible, add a types condition to the ./bundle export (listed first so TypeScript resolves it — there is no adjacent bundle.d.ts to fall back on), and document Bun as a build prerequisite in the README. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Summary
build:bundlestep that bundlessrc/index.tsintodist/bundle.jsviabun build --target=bun --format=esm, inlining every npm dependency and leaving onlynode:builtins external.postbuild, sonpm run buildemits it alongside the tsc output; it ships in the tarball through the existingdistfiles entry plus a new./bundleexports subpath.import()the bundle directly, with no node_modules needed beside it — while types keep coming from the package's main export as a build-time dependency.