@hyperfrontend/builder/bundle/rollup/worker

worker

Forked-worker entry script for per-entry rollup invocations. Sits behind the dispatchRollupWorker orchestrator in bundle/rollup/dispatch.ts.

The worker reads a serializable RollupBuildDescriptor from process.argv[2], reconstructs RollupOptions using the same plugin factories the parent would have used in-process, runs rollup() → bundle.write() → bundle.close(), writes a JSON report to job.reportPath, and exits. Process isolation reclaims the rollup-invocation heap and RSS at exit, keeping the parent bounded across libraries with many entries (per-entry rollup invocations accumulate ~150-225MB heap and V8 retains freed pages even after explicit GC).

runRollupWorkerJob(descriptor) is exported so callers and tests can drive the worker logic without spawning a new Node process.

API Reference§

ƒ Functions

§function

runRollupWorkerJob(job: RollupBuildDescriptor): Promise<RollupWorkerReport>

Runs a single rollup invocation as described by 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
NameTypeDescription
§job
RollupBuildDescriptorDescriptor describing the rollup invocation.
Returns
Promise<RollupWorkerReport>
The on-disk report data the worker would have persisted.
Example

Driving the worker logic in-process for a fixture

const report = await runRollupWorkerJob({ format: 'esm', inputFile: '/abs/in.ts', ... })

◈ Interfaces

§interface

RollupBuildDescriptor

Serializable rollup-build descriptor: the contract between the parent orchestrator and a forked worker. Every field must round-trip through 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:RollupWorkerBinBin-output config carried by ESM / CJS descriptors that emit an executable bin. null for non-bin entries.
§bundle:RollupWorkerBundleOutputBundle-output config carried by IIFE / UMD descriptors. null for esm/cjs.
§bundledDepsPlugin:RollupWorkerBundledDepsPluginWhen set: install the externalize-bundled-deps plugin (esm/cjs only).
§bundleWorkspaceDeps:booleanWhen true, workspace deps are inlined; otherwise treated as external.
§external:string[]Pre-resolved external package list.
§format:RollupWorkerFormatOutput format.
§inputFile:stringAbsolute path to the source TS/JS entry.
§outputDir:stringAbsolute directory the worker writes its output(s) under.
§projectRoot:stringAbsolute project root threaded into the typescript plugin.
§reportPath:stringAbsolute path the worker writes its JSON report to.
§sourcemap:booleanSourcemap toggle threaded into the rollup output.
§tsConfigPath:stringAbsolute tsconfig path threaded into the typescript plugin.
§workspaceRoot:stringAbsolute workspace root threaded into the typescript plugin.
§workspaceRoutes:WorkspaceBundledDepRoute[]Workspace bundled-dep routes consumed by the externalize plugin. When non-empty, imports of these workspace packages (and matching sub-paths) are rerouted to the corresponding _dependencies/<packageName>(/<sub>)?/index.<ext> chunk. Empty array for descriptors that do not opt into workspace-dep hoisting.
§interface

RollupWorkerBin

Bin-output configuration carried by ESM / CJS descriptors when the entry is a 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.
Properties
§banner:stringBanner string prepended to the output (typically the #!/usr/bin/env node shebang).
§chmod:numberFile mode applied via chmodSync after the output is written (e.g. 0o755).
§exports:"none" | "default" | "auto" | "named"Rollup output.exports mode passed through to bundle.write.
§inlineDynamicImports:booleanWhen true, dynamic imports are inlined so the bin remains a single self-contained file.
§outputFile:stringAbsolute path the worker writes the bin output to.
§interface

RollupWorkerBundleOutput

Bundle-output configuration carried by IIFE / UMD descriptors.
Captures the format-specific output knobs the worker needs to reconstruct OutputOptions for a self-contained browser bundle.
Properties
§amdId?:stringUMD-only AMD module identifier.
§globalName:stringGlobal variable name exposed by the bundle.
§globals?:Record<string, string>Global names mapped onto the external dependencies.
§minify:booleanEmit a minified twin alongside the unminified bundle.
§interface

RollupWorkerReport

Memory + size summary written to reportPath when the worker exits cleanly.
Properties
§durationMs:numberWorker wall-clock duration in ms.
§endHeapMB:numberprocess.memoryUsage().heapUsed in MB at end of bundle.
§endRssMB:numberprocess.memoryUsage().rss in MB at end of bundle.
§outputSize:numberTotal on-disk size of every emitted output, in bytes.

◆ Types

§type

RollupWorkerFormat

Output format the rollup worker produces.
type RollupWorkerFormat = "esm" | "cjs" | "iife" | "umd"