@hyperfrontend/builder/bin/scriptscript
JS bin synthesis primitives: rollup-driven bundling with shebang + bootstrap footer + chmod.
buildJsBin(bin, context) bundles src/bin/<name>.ts with Rollup once per declared format, prepends the #!/usr/bin/env node shebang, appends the resolved bootstrap footer (bin.bootstrap override or defaultBootstrap), writes the output to <outputPath>/bin/<name>.<ext>, and chmods it to 0o755. Output naming is <name>.mjs for ESM, <name>.js when CJS is the only declared format, and <name>.cjs.js when CJS is paired with ESM. defaultBootstrap({ runner, format }) produces the standard footer template — when runner === 'default' the runner reference resolves per-format (module.exports.default for CJS, (await import(import.meta.url)).default for ESM); otherwise the named runner is referenced directly.
API Reference
ƒ Functions
For each declared format (CJS / ESM), forks a rollup worker that bundles
src/bin/<name>.ts, prepends the #!/usr/bin/env node shebang, appends the resolved bootstrap footer (per-bin override or defaultBootstrap), writes the output to <outputPath>/bin/<name>.<ext>, and chmods it to 0o755 so the npm bin symlink is invokable. The worker isolates the heavy bin bundle (rollup + plugins + transitive deps loaded into the child) from the parent process. Output naming follows the convention:
- ESM:
<name>.mjs - CJS only:
<name>.js - CJS alongside ESM:
<name>.cjs.js
Parameters
Returns
Promise<BinOutput[]>BinOutput per emitted JS artifact.Examples
Building a CJS-only bin
const outputs = await buildJsBin({ name: 'cz', format: 'cjs', runner: 'runCz' }, context)Building dual CJS + ESM outputs
const outputs = await buildJsBin({ name: 'hf-build', format: ['cjs', 'esm'] }, context)The footer wires the resolved runner export to
process.argv / process.cwd() / process.stderr / process.stdout, maps the returned exit code to process.exit, and surfaces unexpected rejections by writing to stderr and exiting 1. When
runner === 'default', the runner reference is resolved differently per format: - CJS uses
module.exports.default, available as a top-level reference inside the
- ESM uses
(await import(import.meta.url)).default, which re-imports the bundle's
await is required. Otherwise the supplied named runner is referenced directly, which works for both formats because Rollup preserves the local function name at the file scope.
Parameters
| Name | Type | Description |
|---|---|---|
§options | DefaultBootstrapOptions | Runner name + target format. |
Returns
stringoutput.footer.Examples
Default-export runner for an ESM bin
const footer = defaultBootstrap({ runner: 'default', format: 'esm' })Named runner shared between CJS and ESM outputs
const footer = defaultBootstrap({ runner: 'runCz', format: 'cjs' })