@hyperfrontend/builder/bundle/rolluprollup
Rollup driver: per-format descriptor builders and the per-entry forked-worker dispatcher.
Every format is bundled the same way: build a serializable descriptor and hand it to the worker. The descriptor builders (toEsmBuildDescriptor, toCjsBuildDescriptor, toIifeBuildDescriptor, toUmdBuildDescriptor, toBinBuildDescriptor) translate an entry point plus its format config into a RollupBuildDescriptor, validating externals/globals eagerly so the caller fails before a worker is spawned. dispatchRollupWorker forks a child Node process per entry to run that descriptor in isolation (the per-entry boundary that keeps peak memory bounded), or runRollupWorkerJob runs the same descriptor in-process for tests. The actual Rollup configuration — plugin wiring (json, node-resolve, commonjs, typescript, terser), output options, and onwarn suppression — lives entirely inside the worker's job-runner.ts, which depends only on rollup and the @rollup/plugin-* packages so it can bootstrap before any workspace package is built.
API Reference
ƒ Functions
dispatchRollupWorker(descriptor: RollupBuildDescriptor, options: DispatchRollupWorkerOptions): Promise<RollupWorkerReport>
reportPath is overwritten with a temp-dir path created by this function. Each worker writes a JSON report at the temp path; this function reads it after the child exits and returns the per-job statistics. If the worker exits non-zero or fails to produce a report, the function throws with a label-rich message.
The temp report directory is cleaned up before returning, regardless of success or failure.
Parameters
Returns
Promise<RollupWorkerReport>Example
Dispatching a single ESM build
const report = await dispatchRollupWorker(descriptor, { workerPath: '/abs/dist/.../worker.cjs.js' })@swc-node/register (bootstrap case where builder is building itself for the first time and the dist worker doesn't exist yet). Looks at, in order:
<workspaceRoot>/dist/libs/builder/bundle/rollup/worker/index.cjs.js<workspaceRoot>/node_modules/@hyperfrontend/builder/bundle/rollup/worker/index.cjs.js<workspaceRoot>/libs/builder/src/bundle/rollup/worker/index.ts(with--require \@swc-node/register)
Parameters
| Name | Type | Description |
|---|---|---|
§workspaceRoot | string | Absolute workspace root. |
Returns
RollupWorkerInvocationundefined if no candidate exists.Example
Locating the worker for an in-workspace consumer
const invocation = resolveDefaultRollupWorkerPath('/abs/repo')
if (!invocation) throw new Error('builder rollup worker artifact not found')job and writes the resulting report to job.reportPath. Use this to drive the worker logic in-process; use dispatchRollupWorker to run the same job in a forked Node process.
Parameters
| Name | Type | Description |
|---|---|---|
§job | RollupBuildDescriptor | Descriptor describing the rollup invocation. |
Returns
Promise<RollupWorkerReport>Example
Driving the worker logic in-process for a fixture
const report = await runRollupWorkerJob({ format: 'esm', inputFile: '/abs/in.ts', ... })toBinBuildDescriptor(bin: BinConfig, context: BuildContext, format: BinScriptFormat, formats: BinScriptFormat[], reportPath: string): RollupBuildDescriptor
Bins are self-contained executable scripts: workspace deps are inlined and the worker writes to
<outputPath>/bin/<name>.<ext> with the shebang banner, the resolved bootstrap footer, and chmod 0o755 applied. Output naming convention:
- ESM:
<name>.mjs - CJS only:
<name>.js - CJS alongside ESM:
<name>.cjs.js
Parameters
| Name | Type | Description |
|---|---|---|
§bin | BinConfig | Bin declaration including name, runner, and per-bin bootstrap override. |
§context | BuildContext | Resolved build context. |
§format | BinScriptFormat | Format being built (one of bin.format's entries). |
§formats | BinScriptFormat[] | Full list of formats requested for this bin (drives the CJS filename). |
§reportPath | string | Absolute path the worker will write its JSON report to. |
Returns
RollupBuildDescriptorExample
Producing the descriptor for an `hf-build` CJS bin alongside an ESM twin
const descriptor = toBinBuildDescriptor(bin, context, 'cjs', ['cjs', 'esm'], '/tmp/r.json')toCjsBuildDescriptor(entry: EntryPoint, config: CjsConfig, context: BuildContext, reportPath: string): RollupBuildDescriptor
Parameters
Returns
RollupBuildDescriptorExample
Producing the descriptor for the root entry
const descriptor = toCjsBuildDescriptor(entry, cjsConfig, context, '/tmp/report.json')toEsmBuildDescriptor(entry: EntryPoint, config: EsmConfig, context: BuildContext, reportPath: string): RollupBuildDescriptor
The returned descriptor is fully serializable (no functions), ready to be passed to dispatchRollupWorker.
Parameters
Returns
RollupBuildDescriptorExample
Producing the descriptor for the root entry
const descriptor = toEsmBuildDescriptor(entry, esmConfig, context, '/tmp/report.json')toIifeBuildDescriptor(entry: EntryPoint, config: IifeConfig, context: BuildContext, reportPath: string): RollupBuildDescriptor
Validates the externals/globals pairing eagerly, throwing before the descriptor is returned.
Parameters
Returns
RollupBuildDescriptorExample
Producing the descriptor for an IIFE bundle
const descriptor = toIifeBuildDescriptor(entry, iifeConfig, context, '/tmp/report.json')toUmdBuildDescriptor(entry: EntryPoint, config: UmdConfig, context: BuildContext, reportPath: string): RollupBuildDescriptor
Validates the externals/globals pairing eagerly, throwing before the descriptor is returned.
Parameters
Returns
RollupBuildDescriptorExample
Producing the descriptor for a UMD bundle
const descriptor = toUmdBuildDescriptor(entry, umdConfig, context, '/tmp/report.json')◈ Interfaces
JSON.stringify / JSON.parse — no functions, no class instances. The worker reconstructs
RollupOptions from the descriptor using the same plugin factories the parent would have used in-process.Properties
bin:RollupWorkerBin— null for non-bin entries.bundle:RollupWorkerBundleOutput— null for esm/cjs.bundledDepsPlugin:RollupWorkerBundledDepsPlugin— workspaceRoutes:WorkspaceBundledDepRoute[]— _dependencies/<packageName>(/<sub>)?/index.<ext> chunk. Empty array for descriptors that do not opt into workspace-dep hoisting.package.json#bin executable script. When set, the worker writes the bundle to outputFile (instead of the format's default
index.<fmt>.js filename), prepends the banner and appends the footer, and applies chmod to the produced file so the npm bin symlink is invokable.Captures the format-specific output knobs the worker needs to reconstruct
OutputOptions for a self-contained browser bundle.--require \@swc-node/register when the worker is loaded from TypeScript source during a bootstrap build).reportPath when the worker exits cleanly.◆ Types
type RollupWorkerFormat = "esm" | "cjs" | "iife" | "umd"