Prepare Hunk for npm packaging and install verification#8
Conversation
| BUN_TMPDIR="${repo_root}/.bun-tmp" \ | ||
| BUN_INSTALL="${repo_root}/.bun-install" \ | ||
| bun build "${repo_root}/src/main.tsx" \ | ||
| --target bun \ | ||
| --format esm \ | ||
| --outdir "${outdir}" \ | ||
| --entry-naming main.js | ||
|
|
||
| chmod 0755 "${outdir}/main.js" | ||
|
|
||
| printf 'Built %s\n' "${outdir}/main.js" |
There was a problem hiding this comment.
Bug: The build-npm.sh script doesn't add a #!/usr/bin/env bun shebang to the bundled output, which will cause execution to fail in Node.js-only environments.
Severity: CRITICAL
Suggested Fix
Modify scripts/build-npm.sh to explicitly prepend #!/usr/bin/env bun to the bundled output file after the bun build command. For example: { printf '#!/usr/bin/env bun\n'; cat "${outdir}/main.js"; } > "${outdir}/main.js.tmp" && mv "${outdir}/main.js.tmp" "${outdir}/main.js".
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: scripts/build-npm.sh#L10-L20
Potential issue: The `build-npm.sh` script bundles `src/main.tsx`, which contains
Bun-specific APIs like `Bun.stdin.stream()`. However, the script fails to prepend the
necessary `#!/usr/bin/env bun` shebang to the final executable. When a user on a system
with only Node.js installed runs the command after `npm install -g`, the operating
system will not know to use the Bun runtime. This will lead to execution errors, such as
`ReferenceError: Bun is not defined`, because the script will be run by the wrong
interpreter or fail to run at all. This breaks the npm distribution for users without a
global Bun installation.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
I checked this one end-to-end and did not apply the suggested shebang change. bun build --target bun is already preserving the #!/usr/bin/env bun shebang from src/main.tsx, so the bundled entrypoint is executable under Bun as-is.
The failing PR check turned out to be a different issue: the pack verifier was requiring CONTRIBUTING.md and SECURITY.md even though those docs only exist in the stacked follow-up PR. I fixed the verifier to require those files only when they exist in the repo, and also normalized the npm bin path so npm no longer needs to correct it during publish.
Responded by pi-coding-agent using openai/gpt-5.
5bf0a78 to
d6b8e44
Compare
Summary
hunkdiffand point thehunkbin at a built Bun runtime bundlebuild:npm,prepack, and pack-surface verificationnpm install -gsmoke checkValidation
npm install -gsmoke run