d73ff9b0fb
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Docker / shell lint / Lint Dockerfile (hadolint) (push) Has been cancelled
Docker / shell lint / Lint docker/ shell scripts (shellcheck) (push) Has been cancelled
Docker Build and Publish / build-amd64 (push) Has been cancelled
Docker Build and Publish / build-arm64 (push) Has been cancelled
Lint (ruff + ty) / ruff + ty diff (push) Has been cancelled
Lint (ruff + ty) / ruff enforcement (blocking) (push) Has been cancelled
Lint (ruff + ty) / Windows footguns (blocking) (push) Has been cancelled
Nix Lockfile Fix / auto-fix-main (push) Has been cancelled
Nix Lockfile Fix / fix (push) Has been cancelled
Nix / nix (macos-latest) (push) Has been cancelled
Nix / nix (ubuntu-latest) (push) Has been cancelled
OSV-Scanner / Scan lockfiles (push) Has been cancelled
Build Skills Index / build-index (push) Has been cancelled
Tests / test (1) (push) Has been cancelled
Tests / test (2) (push) Has been cancelled
Tests / test (3) (push) Has been cancelled
Tests / test (4) (push) Has been cancelled
Tests / test (5) (push) Has been cancelled
Tests / test (6) (push) Has been cancelled
Tests / e2e (push) Has been cancelled
uv.lock check / uv lock --check (push) Has been cancelled
Docker Build and Publish / merge (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
Tests / save-durations (push) Has been cancelled
62 lines
2.2 KiB
JavaScript
62 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
// Bundles src/entry.tsx into a single self-contained dist/entry.js.
|
|
// No runtime node_modules needed.
|
|
import { build } from 'esbuild'
|
|
import { readFileSync, writeFileSync } from 'node:fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { dirname, resolve } from 'node:path'
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
const root = resolve(here, '..')
|
|
const out = resolve(root, 'dist/entry.js')
|
|
|
|
// `react-devtools-core` is only imported when DEV=true at runtime (Ink dev
|
|
// mode). Stub it out so the bundle doesn't carry the dep.
|
|
const stubDevtools = {
|
|
name: 'stub-react-devtools-core',
|
|
setup(b) {
|
|
b.onResolve({ filter: /^react-devtools-core$/ }, args => ({
|
|
path: args.path,
|
|
namespace: 'stub-devtools'
|
|
}))
|
|
b.onLoad({ filter: /.*/, namespace: 'stub-devtools' }, () => ({
|
|
contents: 'export default { initialize() {}, connectToDevTools() {} }',
|
|
loader: 'js'
|
|
}))
|
|
}
|
|
}
|
|
|
|
await build({
|
|
entryPoints: [resolve(root, 'src/entry.tsx')],
|
|
bundle: true,
|
|
platform: 'node',
|
|
format: 'esm',
|
|
target: 'node20',
|
|
outfile: out,
|
|
jsx: 'automatic',
|
|
jsxImportSource: 'react',
|
|
// Skip the prebuilt @hermes/ink bundle — esbuild's __esm helper doesn't
|
|
// await nested async init, which breaks lazy-initialized exports like
|
|
// `render`. Bundling from source sidesteps that.
|
|
alias: { '@hermes/ink': resolve(root, 'packages/hermes-ink/src/entry-exports.ts') },
|
|
plugins: [stubDevtools],
|
|
// Some transitive deps use CommonJS `require(...)` at runtime. ESM bundles
|
|
// don't get a `require` binding automatically, so we inject one.
|
|
banner: {
|
|
js: "import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);"
|
|
},
|
|
logLevel: 'info'
|
|
})
|
|
|
|
// esbuild preserves the shebang from src/entry.tsx into the bundle, but Nix's
|
|
// patchShebangs phase mangles `/usr/bin/env -S node --foo --bar` (it strips
|
|
// the `node` token, leaving a broken interpreter). The hermes_cli launcher
|
|
// always invokes this file as `node dist/entry.js` anyway, so the shebang is
|
|
// redundant — strip it.
|
|
const body = readFileSync(out, 'utf8')
|
|
if (body.startsWith('#!')) {
|
|
writeFileSync(out, body.slice(body.indexOf('\n') + 1))
|
|
}
|
|
|
|
console.log(`built ${out}`)
|