@hyperfrontend/builder/bin/native/worker

worker

Forked-worker entry script for postject inject. Sits behind the dispatchInjectWorker orchestrator in bin/native/dispatch.ts.

The worker reads a serializable InjectWorkerJob from process.argv[2], clones the Node host binary to the output path, reads the SEA preparation blob, calls postject.inject to embed the blob into the cloned binary, writes a JSON report to job.reportPath, and exits. Process isolation reclaims the ~138 MB Buffer postject allocates while loading + rewriting the host binary, keeping the parent's RSS bounded across the rest of the SEA pipeline (the empirical pre-Phase-11.8 spike was ~1.8 GB at this exact step on memory-constrained hosts).

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

API Reference

ƒ Functions

§function

runInjectWorkerJob(job: InjectWorkerJob): Promise<InjectWorkerReport>

Runs the postject inject for job in the current process and writes the resulting report to job.reportPath.
Call this to drive the worker logic without spawning a new Node process. The inject normally runs in a forked child because postject.inject loads the entire ~121 MB host binary into a Node Buffer and rewrites it with the embedded blob — a single ~138 MB allocation that needs to be reclaimed on process exit rather than retained in the parent's RSS.

Parameters

NameTypeDescription
§job
InjectWorkerJob
Descriptor describing the inject invocation.

Returns

Promise<InjectWorkerReport>
The on-disk report data the worker would have persisted.

Example

Driving the worker logic in-process for a fixture

const report = await runInjectWorkerJob({
  hostBinary: '/opt/node',
  outputBinary: '/tmp/out',
  blobPath: '/tmp/sea.blob',
  resourceName: 'NODE_SEA_BLOB',
  machoSegmentName: 'NODE_SEA',
  sentinelFuse: 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
  reportPath: '/tmp/report.json',
})

Interfaces

§interface

InjectWorkerJob

Serializable inject-worker job descriptor: the contract between dispatchInjectWorker and the forked child. Every field must round-trip through JSON.stringify / JSON.parse — no functions, no class instances.

Properties

§blobPath:string
Absolute path to the SEA preparation blob produced by node --experimental-sea-config.
§hostBinary:string
Absolute path to the Node host binary the worker clones as the injection target.
§machoSegmentName:string
Mach-O segment name used by macOS injection (always NODE_SEA at runtime).
§outputBinary:string
Absolute path the cloned + injected binary lands at.
§reportPath:string
Absolute path the worker writes its JSON report to.
§resourceName:string
SEA resource name for the embedded blob (always NODE_SEA_BLOB at runtime).
§sentinelFuse:string
Sentinel fuse string postject scans for in the host binary. Constructed in-parent to avoid collision.
§interface

InjectWorkerReport

Memory + size summary written to reportPath when the worker exits cleanly.
Captured from the worker process — the parent never observes the ~138 MB postject buffer because the entire load lives and dies in the child.

Properties

§durationMs:number
Worker wall-clock duration in ms.
§endHeapMB:number
Worker process.memoryUsage().heapUsed in MB at end of inject.
§endRssMB:number
Worker process.memoryUsage().rss in MB at end of inject.
§outputSize:number
On-disk size of outputBinary after injection, in bytes.