@orkestrel/sea 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1113 @@
1
+ import { EmitterErrorHandler } from '@orkestrel/emitter';
2
+ import { EmitterHooks } from '@orkestrel/emitter';
3
+ import { EmitterInterface } from '@orkestrel/emitter';
4
+
5
+ export declare class Asset implements AssetInterface {
6
+ readonly key: string;
7
+ readonly content: ArrayBuffer;
8
+ readonly compressed: boolean;
9
+ constructor(input: AssetInput);
10
+ }
11
+
12
+ /**
13
+ * Minimal data needed to create an {@link AssetInterface}.
14
+ *
15
+ * @remarks
16
+ * `key` — the asset's lookup key (e.g. `"client.html.br"`).
17
+ * `content` — raw asset bytes.
18
+ * `compressed` — whether `content` is Brotli-compressed. Default: inferred
19
+ * from a `.br` suffix on `key`.
20
+ */
21
+ export declare interface AssetInput {
22
+ readonly key: string;
23
+ readonly content: ArrayBuffer;
24
+ readonly compressed?: boolean;
25
+ }
26
+
27
+ /**
28
+ * A single named asset wrapping its key, content buffer, and compression flag.
29
+ */
30
+ export declare interface AssetInterface {
31
+ readonly key: string;
32
+ readonly content: ArrayBuffer;
33
+ readonly compressed: boolean;
34
+ }
35
+
36
+ export declare class AssetManager implements AssetManagerInterface {
37
+ #private;
38
+ constructor(options?: AssetManagerOptions);
39
+ get emitter(): EmitterInterface<AssetManagerEventMap>;
40
+ get count(): number;
41
+ asset(key: string): AssetInterface | undefined;
42
+ assets(): readonly AssetInterface[];
43
+ keys(): readonly string[];
44
+ register(input: AssetInput | AssetInput[]): void;
45
+ load(): void;
46
+ clear(): void;
47
+ destroy(): void;
48
+ }
49
+
50
+ /** Events emitted by an {@link AssetManagerInterface}. */
51
+ export declare type AssetManagerEventMap = {
52
+ register: readonly [asset: AssetInterface];
53
+ load: readonly [keys: readonly string[]];
54
+ clear: readonly [];
55
+ error: readonly [error: unknown];
56
+ };
57
+
58
+ /**
59
+ * Named asset collection with SEA and disk loading.
60
+ *
61
+ * @remarks
62
+ * In SEA mode, embedded assets are loaded automatically at construction.
63
+ * Outside SEA, `load()` reads client assets from disk.
64
+ */
65
+ export declare interface AssetManagerInterface {
66
+ readonly emitter: EmitterInterface<AssetManagerEventMap>;
67
+ readonly count: number;
68
+ asset(key: string): AssetInterface | undefined;
69
+ assets(): readonly AssetInterface[];
70
+ keys(): readonly string[];
71
+ register(input: AssetInput | AssetInput[]): void;
72
+ load(): void;
73
+ clear(): void;
74
+ destroy(): void;
75
+ }
76
+
77
+ /**
78
+ * Options for creating an {@link AssetManagerInterface}.
79
+ *
80
+ * @remarks
81
+ * `root` — project root used to resolve on-disk client assets. Default: `process.cwd()`.
82
+ */
83
+ export declare interface AssetManagerOptions {
84
+ readonly on?: EmitterHooks<AssetManagerEventMap>;
85
+ readonly error?: EmitterErrorHandler;
86
+ readonly root?: string;
87
+ }
88
+
89
+ /** File extension indicating Brotli compression */
90
+ export declare const BROTLI_EXTENSION = ".br";
91
+
92
+ /**
93
+ * Build an ELF `PT_NOTE` entry's header bytes (namesz/descsz/type + padded
94
+ * name) for the SEA blob note, without the blob body itself.
95
+ *
96
+ * @remarks
97
+ * A pure leaf extracted from the ELF injector: the blob body is streamed
98
+ * from disk separately (never buffered here) so this only produces the
99
+ * fixed-size note header and reports the total on-disk size the complete
100
+ * note entry (header + 4-byte-padded blob) will occupy, so the caller can
101
+ * size the covering `PT_LOAD`/`PT_NOTE` segments before writing anything.
102
+ * The Node.js SEA runtime matches a note by the first 8 bytes of its name
103
+ * (`strncmp(name, "NODE_SEA", 8)`), so `resource` is written in full but
104
+ * only needs to begin with those 8 bytes to be found at runtime.
105
+ *
106
+ * @param resource - Note name (SEA resource identifier, e.g. `NODE_SEA_BLOB`)
107
+ * @param blobSize - Size in bytes of the SEA blob that will follow the header
108
+ * @returns The note header bytes and the total on-disk size of header + blob
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * const { header, entryTotal } = buildELFNoteHeader('NODE_SEA_BLOB', 4096)
113
+ * ```
114
+ */
115
+ export declare function buildELFNoteHeader(resource: string, blobSize: number): {
116
+ readonly header: Buffer;
117
+ readonly entryTotal: number;
118
+ };
119
+
120
+ /** Asset key for the Brotli-compressed client HTML entry */
121
+ export declare const CLIENT_ASSET_KEY_BR = "client.html.br";
122
+
123
+ /** Asset key for the raw (uncompressed) client HTML entry */
124
+ export declare const CLIENT_ASSET_KEY_RAW = "client.html";
125
+
126
+ /**
127
+ * Compress all compressible files in a directory tree.
128
+ *
129
+ * @param directory - Absolute path to the directory
130
+ * @param options - Compression options
131
+ * @param progress - Optional callback invoked after each file is compressed
132
+ * @returns Compression manifest with all results
133
+ */
134
+ export declare function compressDirectory(directory: string, options?: SEACompressionOptions, progress?: SEAProgressHandler): SEACompressionManifest;
135
+
136
+ /**
137
+ * Brotli-compress a single file, writing the output alongside it.
138
+ *
139
+ * @param input - Absolute path to the source file
140
+ * @param output - Absolute path for the compressed output
141
+ * @param options - Compression options (quality, mode)
142
+ * @returns Compression result with size comparison
143
+ */
144
+ export declare function compressFile(input: string, output: string, options?: SEACompressionOptions): SEACompressionResult;
145
+
146
+ /**
147
+ * Compute a size comparison between original and compressed byte counts.
148
+ *
149
+ * @param original - Original byte count
150
+ * @param compressed - Compressed byte count
151
+ * @returns SEACompressionSize with ratio
152
+ */
153
+ export declare function computeSize(original: number, compressed: number): SEACompressionSize;
154
+
155
+ /**
156
+ * Copy a byte range from one open file descriptor to another, streaming in
157
+ * fixed-size chunks instead of buffering the whole range in memory.
158
+ *
159
+ * @remarks
160
+ * Reads `length` bytes from `source` starting at file offset `start`, in
161
+ * `chunk`-sized reads, and writes each chunk to `target` with a `null`
162
+ * write position so writes land sequentially at `target`'s current file
163
+ * position (rather than at `start`, which is meaningless for `target`). A
164
+ * short read from `source` (fewer bytes returned than requested, including
165
+ * `0` before `length` is exhausted) is treated as a genuine failure and
166
+ * throws rather than silently writing a truncated range.
167
+ *
168
+ * @param source - Open, readable file descriptor to copy from
169
+ * @param target - Open, writable file descriptor to copy to
170
+ * @param start - Byte offset in `source` to begin reading from
171
+ * @param length - Number of bytes to copy; `0` is a no-op
172
+ * @param chunk - Read/write chunk size in bytes, for tuning memory use and
173
+ * exercising the streaming loop in tests. Default: 4 MB.
174
+ * @throws SEAError with code `'OUTPUT'` when `source` is exhausted before
175
+ * `length` bytes have been copied
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * const srcFd = openSync('big.bin', 'r')
180
+ * const dstFd = openSync('out.bin', 'w')
181
+ * copyRange(srcFd, dstFd, 1024, 4096)
182
+ * ```
183
+ */
184
+ export declare function copyRange(source: number, target: number, start: number, length: number, chunk?: number): void;
185
+
186
+ /**
187
+ * Create a single named asset.
188
+ *
189
+ * @param input - Asset key, content, and optional compression flag
190
+ * @returns a new `AssetInterface`
191
+ *
192
+ * @example
193
+ * ```ts
194
+ * const asset = createAsset({ key: 'client.html.br', content: compressedBuffer })
195
+ * ```
196
+ */
197
+ export declare function createAsset(input: AssetInput): AssetInterface;
198
+
199
+ /**
200
+ * Create an asset manager for SEA-embedded or disk-loaded assets.
201
+ *
202
+ * @param options - Asset manager options (root, event hooks)
203
+ * @returns a new `AssetManagerInterface`
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * const manager = createAssetManager({ root: process.cwd() })
208
+ * manager.load()
209
+ * ```
210
+ */
211
+ export declare function createAssetManager(options?: AssetManagerOptions): AssetManagerInterface;
212
+
213
+ /**
214
+ * Build the Node.js `--experimental-sea-config` JSON object for a SEA blob.
215
+ *
216
+ * @remarks
217
+ * A pure leaf extracted from the SEA build orchestrator. The `mainFormat`
218
+ * field (`'commonjs' | 'module'`) exists only in Node >= 25.7 — for a `'cjs'`
219
+ * entry (the default) `mainFormat` is OMITTED entirely so the config still
220
+ * builds on older Node hosts where `'commonjs'` is already the implicit
221
+ * default; for an `'esm'` entry `mainFormat: 'module'` is set explicitly
222
+ * (this requires a Node >= 25.7 build host). Node also documents that
223
+ * `useSnapshot` is incompatible with an ESM entry — combining the two throws.
224
+ *
225
+ * @param entry - SEA entry point options
226
+ * @param blob - Absolute output path for the generated blob
227
+ * @param assets - Optional key→path mapping for embedded assets
228
+ * @param options - Optional blob behavior overrides (cache, snapshot)
229
+ * @returns the SEA config object, ready to be written to disk as JSON
230
+ * @throws SEAError with code `'BLOB'` when `useSnapshot` is combined with an ESM entry
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * const config = createBlobConfig({ path: 'dist/bin/serve.cjs' }, 'dist/bin/sea-prep.blob', undefined)
235
+ * ```
236
+ */
237
+ export declare function createBlobConfig(entry: SEAEntryOptions, blob: string, assets: Readonly<Record<string, string>> | undefined, options?: SEABlobOptions): Readonly<Record<string, unknown>>;
238
+
239
+ /**
240
+ * Create a cross-platform binary resource injector.
241
+ *
242
+ * Detects the executable format (PE, ELF, Mach-O) from the file header
243
+ * and injects the blob using pure TypeScript file I/O — no WASM, no
244
+ * external tools.
245
+ *
246
+ * @param options - Injector options
247
+ * @returns a new `InjectorInterface`
248
+ *
249
+ * @example
250
+ * ```ts
251
+ * const injector = createInjector({
252
+ * executable: 'dist/bin/myapp.exe',
253
+ * resource: 'NODE_SEA_BLOB',
254
+ * blob: 'dist/bin/sea-prep.blob',
255
+ * fuse: 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
256
+ * })
257
+ * injector.inject()
258
+ * ```
259
+ */
260
+ export declare function createInjector(options: InjectorOptions): InjectorInterface;
261
+
262
+ /**
263
+ * Create a new SEA build orchestrator.
264
+ *
265
+ * @param options - SEA build options
266
+ * @returns a new `SEAInterface`
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * const seal = createSEA({
271
+ * name: 'orkestrel',
272
+ * entry: { path: 'dist/bin/serve.cjs' },
273
+ * output: 'dist/sea',
274
+ * assets: { 'index.html.br': 'dist/client/index.html.br' },
275
+ * compression: { paths: ['dist/client'] },
276
+ * })
277
+ * const result = await seal.execute()
278
+ * ```
279
+ */
280
+ export declare function createSEA(options: SEAOptions): SEAInterface;
281
+
282
+ /**
283
+ * Build the `signtool sign` argv for signing a Windows executable.
284
+ *
285
+ * @remarks
286
+ * Requires EXACTLY ONE certificate source — `sign.file` (a `.pfx`/`.p12`
287
+ * file, paired with `sign.password` when present) XOR `sign.thumbprint` (a
288
+ * certificate already installed in the Windows store). When `sign.timestamp`
289
+ * is set it is parsed with the `URL` constructor and must be an `http:` or
290
+ * `https:` URL. The returned argv is passed directly to `runShell` — never
291
+ * through a shell — so nothing in `sign` can be interpreted as a flag or
292
+ * injected into a command line. `sign.password` is NEVER included in a
293
+ * thrown error's message or `context`.
294
+ *
295
+ * @param sign - Windows signing options
296
+ * @param target - Absolute path to the executable to sign
297
+ * @returns The `signtool` argv, ready for `runShell`
298
+ * @throws SEAError with code `'SIGN'` when neither `file` nor `thumbprint` is set
299
+ * @throws SEAError with code `'SIGN'` when both `file` and `thumbprint` are set
300
+ * @throws SEAError with code `'SIGN'` when `timestamp` is not a parseable http(s) URL
301
+ * @throws SEAError with code `'SIGN'` when `digest` is not `'sha1'`, `'sha256'`, `'sha384'`, or `'sha512'`
302
+ *
303
+ * @example
304
+ * ```ts
305
+ * createSignCommand({ thumbprint: 'AABBCCDDEEFF00112233445566778899AABBCCDD' }, 'dist/sea/app.exe')
306
+ * // ['signtool', 'sign', '/fd', 'sha256', '/sha1', 'AABBCCDDEEFF00112233445566778899AABBCCDD', 'dist/sea/app.exe']
307
+ * ```
308
+ */
309
+ export declare function createSignCommand(sign: SEAWindowsSignOptions, target: string): string[];
310
+
311
+ /** Default SEA entry point module format when none is specified */
312
+ export declare const DEFAULT_ENTRY_FORMAT: SEAEntryFormat;
313
+
314
+ /** Default Brotli compression quality level (maximum) */
315
+ export declare const DEFAULT_SEA_COMPRESSION_QUALITY = 11;
316
+
317
+ /** ELF 64-bit class identifier */
318
+ export declare const ELF_CLASS_64 = 2;
319
+
320
+ /** ELF little-endian data encoding */
321
+ export declare const ELF_DATA_LSB = 1;
322
+
323
+ /** ELF magic: 0x7F 'E' 'L' 'F' as a 32-bit big-endian value */
324
+ export declare const ELF_MAGIC = 2135247942;
325
+
326
+ /** ELF program header type: note segment */
327
+ export declare const ELF_PT_NOTE = 4;
328
+
329
+ /**
330
+ * Assert that `path` (resolved against `base`) real-path-resolves to a
331
+ * location inside `base`, defeating a symlink escape.
332
+ *
333
+ * @remarks
334
+ * Resolves `path` against `base`, then dereferences both the resolved path
335
+ * and `base` with `realpathSync` and requires the real resolved path to
336
+ * equal the real base or begin with the real base plus a path separator.
337
+ * Dereferencing BOTH sides means a symlinked base itself (e.g. macOS `/tmp`
338
+ * -> `/private/tmp`) still matches, while a symlink inside the tree that
339
+ * points outside the real base is correctly rejected. A `realpathSync`
340
+ * failure (e.g. `ENOENT`) is wrapped as a coded `SEAError` rather than
341
+ * leaking the raw Node error.
342
+ *
343
+ * @param base - Absolute path to the containing root
344
+ * @param path - Path to validate, resolved against `base` if relative
345
+ * @returns The real (symlink-resolved) contained path
346
+ * @throws SEAError with code `'ASSET'` when the real path escapes `base`
347
+ * @throws SEAError with code `'ASSET'` when the path cannot be resolved
348
+ *
349
+ * @example
350
+ * ```ts
351
+ * ensureContained('/dist/app', 'browser') // '/dist/app/browser' (real path)
352
+ * ensureContained('/dist/app', '../../etc') // throws SEAError('ASSET', ...)
353
+ * ```
354
+ */
355
+ export declare function ensureContained(base: string, path: string): string;
356
+
357
+ /**
358
+ * Assert that a path exists, throwing a coded {@link SEAError} if not.
359
+ *
360
+ * @param path - Absolute or relative path to check
361
+ * @param message - Error message when path is missing
362
+ * @param code - Error code to throw with. Default: `'STATE'`.
363
+ */
364
+ export declare function ensureExists(path: string, message: string, code?: SEAErrorCode): void;
365
+
366
+ /**
367
+ * Assert that an asset key is safe to use as a relative filesystem/archive key.
368
+ *
369
+ * @remarks
370
+ * Rejects an empty key, an absolute path, a key containing a backslash, a
371
+ * Windows drive-relative specifier (e.g. `'C:foo'`), or any `/`-separated
372
+ * segment equal to `'..'` — all of which could escape the intended asset root.
373
+ *
374
+ * @param key - Asset key to validate
375
+ * @throws SEAError with code `'ASSET'` when the key is unsafe
376
+ *
377
+ * @example
378
+ * ```ts
379
+ * ensureSafeKey('client.html.br') // ok
380
+ * ensureSafeKey('../secrets') // throws SEAError('ASSET', ...)
381
+ * ensureSafeKey('C:foo') // throws SEAError('ASSET', ...)
382
+ * ```
383
+ */
384
+ export declare function ensureSafeKey(key: string): void;
385
+
386
+ /**
387
+ * Assert that `name` is a single safe path segment suitable as an output
388
+ * executable base name.
389
+ *
390
+ * @remarks
391
+ * Rejects an empty name, `'.'`, `'..'`, a name containing a `/` or `\`
392
+ * separator, an absolute path, or a Windows drive-relative specifier (e.g.
393
+ * `'C:foo'`) — all of which could redirect the output executable outside
394
+ * the intended output directory.
395
+ *
396
+ * @param name - Output executable base name to validate
397
+ * @throws SEAError with code `'ASSET'` when the name is unsafe
398
+ *
399
+ * @example
400
+ * ```ts
401
+ * ensureSafeName('myapp') // ok
402
+ * ensureSafeName('../evil') // throws SEAError('ASSET', ...)
403
+ * ```
404
+ */
405
+ export declare function ensureSafeName(name: string): void;
406
+
407
+ /**
408
+ * Executable binary format detected from file header magic bytes.
409
+ */
410
+ export declare type ExecutableFormat = 'pe' | 'elf' | 'macho';
411
+
412
+ /**
413
+ * Finalize a built executable by durably flushing it to disk and atomically
414
+ * moving it into place.
415
+ *
416
+ * @remarks
417
+ * Opens `source` for read/write, `fsync`s it to force the OS to flush buffered
418
+ * writes, closes it, then `rename`s it to `target`. Never deletes `target` on
419
+ * failure — the caller retains whatever was previously there. After the file
420
+ * is already in place, the containing directory is fsynced ({@link syncDirectory})
421
+ * as a further durability step so the rename itself survives a crash.
422
+ *
423
+ * @param source - Absolute path to the built (temporary) executable
424
+ * @param target - Absolute path to move the finalized executable to
425
+ * @throws SEAError with code `'OUTPUT'` when any step fails
426
+ *
427
+ * @example
428
+ * ```ts
429
+ * finalizeExecutable('/tmp/build/app.tmp', '/dist/app')
430
+ * ```
431
+ */
432
+ export declare function finalizeExecutable(source: string, target: string): void;
433
+
434
+ /**
435
+ * Format a byte count as a human-readable string.
436
+ *
437
+ * @param bytes - Byte count
438
+ * @returns Formatted string (e.g. `"1.23 MB"`, `"456 KB"`)
439
+ */
440
+ export declare function formatSize(bytes: number): string;
441
+
442
+ export declare class Injector implements InjectorInterface {
443
+ #private;
444
+ constructor(options: InjectorOptions);
445
+ get format(): ExecutableFormat;
446
+ inject(): void;
447
+ }
448
+
449
+ /**
450
+ * Cross-platform binary resource injector.
451
+ *
452
+ * @remarks
453
+ * Injects arbitrary data into PE (Windows), ELF (Linux), and Mach-O (macOS)
454
+ * executables using streaming file I/O. No WASM or external tools required.
455
+ */
456
+ export declare interface InjectorInterface {
457
+ /** Detected executable format of the target binary. */
458
+ readonly format: ExecutableFormat;
459
+ /** Inject the resource data into the executable. */
460
+ inject(): void;
461
+ }
462
+
463
+ /**
464
+ * Mach-O specific injector options.
465
+ *
466
+ * @remarks
467
+ * `segment` — Mach-O segment name. Default: `"NODE_SEA"`.
468
+ */
469
+ export declare interface InjectorMachOOptions {
470
+ readonly segment?: string;
471
+ }
472
+
473
+ /**
474
+ * Options for injecting a resource into an executable.
475
+ *
476
+ * @remarks
477
+ * `executable` — absolute path to the target executable.
478
+ * `resource` — resource identifier (e.g. `"NODE_SEA_BLOB"`).
479
+ * `blob` — absolute path to the data file to inject.
480
+ * `fuse` — when set, patches the fuse from `:0` to `:1` after injection.
481
+ * `macho` — Mach-O specific options; `segment` defaults to `"NODE_SEA"`.
482
+ * `overwrite` — replace an existing resource with the same name. Default: `true`.
483
+ */
484
+ export declare interface InjectorOptions {
485
+ readonly executable: string;
486
+ readonly resource: string;
487
+ readonly blob: string;
488
+ readonly fuse?: string;
489
+ readonly macho?: InjectorMachOOptions;
490
+ readonly overwrite?: boolean;
491
+ }
492
+
493
+ /**
494
+ * Check if a file should be Brotli-compressed based on its extension.
495
+ *
496
+ * @param path - Path to the file
497
+ * @returns True when the file type benefits from compression
498
+ */
499
+ export declare function isCompressible(path: string): boolean;
500
+
501
+ /**
502
+ * Check if a value is a valid {@link ExecutableFormat}.
503
+ *
504
+ * @param value - Value to check
505
+ * @returns True when value is `'pe'`, `'elf'`, or `'macho'`
506
+ */
507
+ export declare function isExecutableFormat(value: unknown): value is ExecutableFormat;
508
+
509
+ /**
510
+ * Check if a file is a Windows PE executable.
511
+ *
512
+ * @param path - Path to the file
513
+ * @returns True when the file has a valid PE signature
514
+ */
515
+ export declare function isPEExecutable(path: string): boolean;
516
+
517
+ /**
518
+ * Check if the current or specified platform is supported for SEA builds.
519
+ *
520
+ * @param platform - Platform identifier to check
521
+ * @returns True when the platform has a known configuration
522
+ */
523
+ export declare function isPlatformSupported(platform?: string): boolean;
524
+
525
+ /**
526
+ * Whether a value is a {@link SEAError}.
527
+ *
528
+ * @param value - The value to test
529
+ * @returns `true` when `value` is a `SEAError`
530
+ *
531
+ * @example
532
+ * ```ts
533
+ * if (isSEAError(caught)) {
534
+ * console.error(caught.code)
535
+ * }
536
+ * ```
537
+ */
538
+ export declare function isSEAError(value: unknown): value is SEAError;
539
+
540
+ /**
541
+ * Whether a value is a {@link ShellError}.
542
+ *
543
+ * @param value - The value to test
544
+ * @returns `true` when `value` is a `ShellError`
545
+ *
546
+ * @example
547
+ * ```ts
548
+ * if (isShellError(caught)) {
549
+ * console.error(caught.stdout.toString())
550
+ * }
551
+ * ```
552
+ */
553
+ export declare function isShellError(value: unknown): value is ShellError;
554
+
555
+ /** Mach-O LC_SEGMENT_64 load command */
556
+ export declare const MACHO_LC_SEGMENT_64 = 25;
557
+
558
+ /** Mach-O 64-bit magic (little-endian) */
559
+ export declare const MACHO_MAGIC_64 = 4277009103;
560
+
561
+ /**
562
+ * Launch the system default browser at an http(s) URL.
563
+ *
564
+ * @remarks
565
+ * A best-effort launch for bundled local-UI apps: dispatches by
566
+ * `process.platform` (`win32` -> `rundll32 url.dll,FileProtocolHandler`,
567
+ * `darwin` -> `open`, else -> `xdg-open`), each invoked with an argv array
568
+ * (never a shell) so the URL cannot be interpreted as a flag or injected
569
+ * into a command line. The child process is spawned `detached` with
570
+ * `stdio: 'ignore'` and immediately `unref()`d so it never keeps the host
571
+ * app alive. Only `http:` and `https:` URLs are accepted — any other
572
+ * scheme (including a string that merely looks like a CLI flag, e.g.
573
+ * `'-e ...'`) fails to parse as an http(s) URL and is rejected before
574
+ * anything is spawned.
575
+ *
576
+ * @param url - Absolute http or https URL to open
577
+ * @throws SEAError with code `'BROWSER'` when `url` is not a parseable absolute URL
578
+ * @throws SEAError with code `'BROWSER'` when `url` is not an `http:`/`https:` URL
579
+ *
580
+ * @example
581
+ * ```ts
582
+ * openBrowser('http://localhost:3000')
583
+ * ```
584
+ */
585
+ export declare function openBrowser(url: string): void;
586
+
587
+ /**
588
+ * Parse the PE header offset from a Windows executable.
589
+ *
590
+ * @param fd - Open file descriptor
591
+ * @returns The offset to the PE signature
592
+ */
593
+ export declare function parsePEOffset(fd: number): number;
594
+
595
+ /**
596
+ * Patch the PE subsystem field in a Windows executable.
597
+ *
598
+ * @param path - Path to the executable
599
+ * @param subsystem - Numeric subsystem value (2 = GUI, 3 = Console)
600
+ */
601
+ export declare function patchPESubsystem(path: string, subsystem: number): void;
602
+
603
+ /**
604
+ * Patch the sentinel fuse in a binary from `:0` to `:1`.
605
+ *
606
+ * Searches the file in 64 MB chunks with overlap to handle any file size.
607
+ * The fuse signals to the Node.js runtime that a SEA blob is present.
608
+ * This is normally handled by the Injector but is also available standalone
609
+ * when using native PE resource injection.
610
+ *
611
+ * @param executable - Absolute path to the executable
612
+ * @param fuse - Sentinel fuse string (without the `:0` suffix)
613
+ */
614
+ export declare function patchSentinelFuse(executable: string, fuse: string): void;
615
+
616
+ /** PE32 optional header magic */
617
+ export declare const PE32_MAGIC = 267;
618
+
619
+ /** PE32+ (64-bit) optional header magic */
620
+ export declare const PE32_PLUS_MAGIC = 523;
621
+
622
+ /** DOS MZ header magic (first 2 bytes of a PE file) */
623
+ export declare const PE_MAGIC = 23117;
624
+
625
+ /** Size of IMAGE_RESOURCE_DATA_ENTRY in bytes */
626
+ export declare const PE_RESOURCE_DATA_ENTRY_SIZE = 16;
627
+
628
+ /** Size of IMAGE_RESOURCE_DIRECTORY in bytes */
629
+ export declare const PE_RESOURCE_DIR_SIZE = 16;
630
+
631
+ /** Size of IMAGE_RESOURCE_DIRECTORY_ENTRY in bytes */
632
+ export declare const PE_RESOURCE_ENTRY_SIZE = 8;
633
+
634
+ /** High bit mask for resource name entry (indicates named vs integer ID) */
635
+ export declare const PE_RESOURCE_NAME_FLAG = 2147483648;
636
+
637
+ /** High bit mask for resource directory entry offset (indicates subdirectory) */
638
+ export declare const PE_RESOURCE_SUBDIR_FLAG = 2147483648;
639
+
640
+ /** PE resource type: RT_RCDATA (raw data) */
641
+ export declare const PE_RT_RCDATA = 10;
642
+
643
+ /** Section contains initialized data */
644
+ export declare const PE_SCN_INITIALIZED_DATA = 64;
645
+
646
+ /** Section is readable */
647
+ export declare const PE_SCN_MEM_READ = 1073741824;
648
+
649
+ /** PE section header size in bytes */
650
+ export declare const PE_SECTION_HEADER_SIZE = 40;
651
+
652
+ /** PE signature: "PE\0\0" as a 32-bit value */
653
+ export declare const PE_SIGNATURE = 17744;
654
+
655
+ /**
656
+ * Get the platform configuration for the current OS.
657
+ *
658
+ * @param platform - Platform identifier. Default: `process.platform`.
659
+ * @returns Platform configuration, or undefined if unsupported
660
+ */
661
+ export declare function platformConfig(platform?: string): SEAPlatform | undefined;
662
+
663
+ /**
664
+ * Read a 16-bit unsigned integer from a file descriptor.
665
+ *
666
+ * @param fd - Open file descriptor
667
+ * @param offset - Byte offset to read from
668
+ * @returns The 16-bit value
669
+ */
670
+ export declare function readU16(fd: number, offset: number): number;
671
+
672
+ /**
673
+ * Run a command synchronously and return stdout.
674
+ *
675
+ * @param command - Command to execute (first element is the binary)
676
+ * @param options - Shell options (cwd, env, timeout, signal)
677
+ * @returns stdout as a Buffer
678
+ * @throws SEAError with code `'STATE'` when `command` is empty
679
+ * @throws SEAError with code `'ABORT'` when `options.signal` is already aborted
680
+ * @throws SEAError with code `'TIMEOUT'` when the command exceeds `options.timeout`
681
+ * @throws ShellError when the command exits with non-zero status
682
+ */
683
+ export declare function runShell(command: string[], options?: SEAShellOptions): Buffer;
684
+
685
+ export declare class SEA implements SEAInterface {
686
+ #private;
687
+ constructor(options: SEAOptions);
688
+ get emitter(): EmitterInterface<SEAEventMap>;
689
+ get status(): SEAStatus;
690
+ execute(): Promise<SEAResult>;
691
+ destroy(): void;
692
+ }
693
+
694
+ /** Resource name for the SEA blob in the executable */
695
+ export declare const SEA_BLOB_RESOURCE = "NODE_SEA_BLOB";
696
+
697
+ /** Maps a {@link SEACompressionMode} to its numeric Brotli mode value */
698
+ export declare const SEA_COMPRESSION_MODE_VALUES: Readonly<Record<SEACompressionMode, number>>;
699
+
700
+ /** Platform-specific SEA build configurations */
701
+ export declare const SEA_PLATFORMS: Readonly<Record<string, SEAPlatform>>;
702
+
703
+ /** SEA sentinel fuse value embedded in the Node.js binary */
704
+ export declare const SEA_SENTINEL_FUSE = "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2";
705
+
706
+ /**
707
+ * Options controlling generated SEA blob behavior.
708
+ *
709
+ * @remarks
710
+ * `cache` — maps to the SEA config `useCodeCache`. Default: `true`.
711
+ * `snapshot` — maps to the SEA config `useSnapshot`. Default: `false`.
712
+ */
713
+ export declare interface SEABlobOptions {
714
+ readonly cache?: boolean;
715
+ readonly snapshot?: boolean;
716
+ }
717
+
718
+ /**
719
+ * Manifest summarizing all compressed assets.
720
+ *
721
+ * @remarks
722
+ * Generated after a full directory compression pass.
723
+ */
724
+ export declare interface SEACompressionManifest {
725
+ readonly assets: readonly SEACompressionResult[];
726
+ readonly total: SEACompressionSize;
727
+ }
728
+
729
+ /**
730
+ * Brotli compression mode.
731
+ *
732
+ * @remarks
733
+ * `generic` — general-purpose data (Brotli mode 0).
734
+ * `text` — UTF-8 text (Brotli mode 1).
735
+ * `font` — WOFF2 font data (Brotli mode 2).
736
+ */
737
+ export declare type SEACompressionMode = 'generic' | 'text' | 'font';
738
+
739
+ /**
740
+ * Options controlling Brotli compression of one or more directories.
741
+ *
742
+ * @remarks
743
+ * `paths` — directories (relative to `SEAOptions.root`) to compress.
744
+ * `mode` — Brotli mode. Default: `'generic'`.
745
+ * `quality` — Brotli quality level (0–11). Default: 11.
746
+ */
747
+ export declare interface SEACompressionOptions {
748
+ readonly paths: readonly string[];
749
+ readonly mode?: SEACompressionMode;
750
+ readonly quality?: number;
751
+ }
752
+
753
+ /**
754
+ * Result of compressing a single file.
755
+ *
756
+ * @remarks
757
+ * `input` — absolute path to the original file.
758
+ * `output` — absolute path to the compressed file.
759
+ * `size` — byte-level comparison.
760
+ */
761
+ export declare interface SEACompressionResult {
762
+ readonly input: string;
763
+ readonly output: string;
764
+ readonly size: SEACompressionSize;
765
+ }
766
+
767
+ /**
768
+ * Size comparison between original and compressed data.
769
+ */
770
+ export declare interface SEACompressionSize {
771
+ readonly original: number;
772
+ readonly compressed: number;
773
+ readonly ratio: number;
774
+ }
775
+
776
+ /**
777
+ * SEA entry point module format.
778
+ *
779
+ * @remarks
780
+ * `cjs` — CommonJS entry (Node default).
781
+ * `esm` — ECMAScript module entry (requires Node >= 25.7).
782
+ */
783
+ export declare type SEAEntryFormat = 'cjs' | 'esm';
784
+
785
+ /**
786
+ * Options describing the SEA entry point.
787
+ *
788
+ * @remarks
789
+ * `path` — path to the entry point to embed.
790
+ * `format` — module format of the entry point. Default: `'cjs'`.
791
+ */
792
+ export declare interface SEAEntryOptions {
793
+ readonly path: string;
794
+ readonly format?: SEAEntryFormat;
795
+ }
796
+
797
+ /**
798
+ * The coded base error for every failure raised by the seal build.
799
+ *
800
+ * @remarks
801
+ * Carries a machine-readable {@link SEAErrorCode} and optional `context`
802
+ * for structured diagnostics. Narrow a caught value with {@link isSEAError}.
803
+ *
804
+ * @example
805
+ * ```ts
806
+ * try {
807
+ * seal.execute()
808
+ * } catch (error) {
809
+ * if (isSEAError(error)) {
810
+ * console.error(error.code, error.context)
811
+ * }
812
+ * }
813
+ * ```
814
+ */
815
+ export declare class SEAError extends Error {
816
+ readonly code: SEAErrorCode;
817
+ readonly context?: Readonly<Record<string, unknown>>;
818
+ constructor(code: SEAErrorCode, message: string, context?: Readonly<Record<string, unknown>>);
819
+ }
820
+
821
+ /**
822
+ * Machine-readable error code carried by every {@link SEAError}.
823
+ *
824
+ * @remarks
825
+ * `PLATFORM` — unsupported or misdetected platform.
826
+ * `ENTRY` — invalid or missing entry point.
827
+ * `ASSET` — invalid asset key or content.
828
+ * `BLOB` — SEA blob generation failure.
829
+ * `FORMAT` — unrecognized executable binary format.
830
+ * `INJECT` — resource injection failure.
831
+ * `FUSE` — sentinel fuse patch failure.
832
+ * `SIGN` — code signing failure.
833
+ * `SHELL` — shell command exited non-zero.
834
+ * `TIMEOUT` — shell command exceeded its timeout.
835
+ * `ABORT` — operation aborted via `AbortSignal`.
836
+ * `OUTPUT` — final executable write/finalize failure.
837
+ * `STATE` — invalid internal state or argument.
838
+ * `BROWSER` — invalid or unsupported URL passed to `openBrowser`.
839
+ */
840
+ export declare type SEAErrorCode = 'PLATFORM' | 'ENTRY' | 'ASSET' | 'BLOB' | 'FORMAT' | 'INJECT' | 'FUSE' | 'SIGN' | 'SHELL' | 'TIMEOUT' | 'ABORT' | 'OUTPUT' | 'STATE' | 'BROWSER';
841
+
842
+ /** Events emitted by a {@link SEAInterface}. */
843
+ export declare type SEAEventMap = {
844
+ compress: readonly [compression: SEACompressionManifest | undefined];
845
+ progress: readonly [progress: SEAProgress];
846
+ blob: readonly [blob: string];
847
+ assemble: readonly [executable: string];
848
+ complete: readonly [result: SEAResult];
849
+ error: readonly [error: unknown];
850
+ };
851
+
852
+ /**
853
+ * SEA build orchestrator.
854
+ *
855
+ * @remarks
856
+ * Compresses assets, generates the SEA blob, copies the Node binary,
857
+ * injects the blob via the built-in Injector, and handles platform-specific signing.
858
+ */
859
+ export declare interface SEAInterface {
860
+ readonly emitter: EmitterInterface<SEAEventMap>;
861
+ readonly status: SEAStatus;
862
+ execute(): Promise<SEAResult>;
863
+ destroy(): void;
864
+ }
865
+
866
+ /**
867
+ * Options for creating a SEA build.
868
+ *
869
+ * @remarks
870
+ * `name` — output executable name (no extension).
871
+ * `entry` — the entry point to embed (path and module format).
872
+ * `output` — directory for the final executable.
873
+ * `assets` — key→path mapping for SEA embedded assets.
874
+ * `compression` — directories to Brotli-compress before embedding.
875
+ * `windows` — Windows-specific build options (console/GUI terminal).
876
+ * `root` — project root directory. Default: `process.cwd()`.
877
+ * `signal` — an `AbortSignal` that cancels the build in progress.
878
+ * `blob` — options controlling generated SEA blob behavior.
879
+ */
880
+ export declare interface SEAOptions {
881
+ readonly on?: EmitterHooks<SEAEventMap>;
882
+ readonly error?: EmitterErrorHandler;
883
+ readonly name: string;
884
+ readonly entry: SEAEntryOptions;
885
+ readonly output: string;
886
+ readonly assets?: Readonly<Record<string, string>>;
887
+ readonly compression?: SEACompressionOptions;
888
+ readonly windows?: SEAWindowsOptions;
889
+ readonly root?: string;
890
+ readonly signal?: AbortSignal;
891
+ readonly blob?: SEABlobOptions;
892
+ }
893
+
894
+ /**
895
+ * Platform-specific SEA build configuration.
896
+ *
897
+ * @remarks
898
+ * Describes the native Node binary and code signing commands.
899
+ */
900
+ export declare interface SEAPlatform {
901
+ readonly executable: string;
902
+ readonly remove?: readonly string[];
903
+ readonly sign?: readonly string[];
904
+ readonly verify?: readonly string[];
905
+ }
906
+
907
+ /**
908
+ * Progress reported while compressing a directory.
909
+ *
910
+ * @remarks
911
+ * `path` — absolute path to the file just compressed.
912
+ * `current` — number of files compressed so far (1-based).
913
+ * `total` — total number of compressible files.
914
+ */
915
+ export declare interface SEAProgress {
916
+ readonly path: string;
917
+ readonly current: number;
918
+ readonly total: number;
919
+ }
920
+
921
+ /**
922
+ * Callback invoked by the framework after each file is compressed.
923
+ */
924
+ export declare type SEAProgressHandler = (result: SEACompressionResult) => void;
925
+
926
+ /**
927
+ * Result of a successful seal build.
928
+ *
929
+ * @remarks
930
+ * `executable` — absolute path to the output binary.
931
+ * `platform` — platform identifier (e.g. `"win32"`, `"darwin"`).
932
+ * `size` — file size of the executable in bytes.
933
+ * `duration` — build time in milliseconds.
934
+ * `compression` — compression manifest when directories were compressed.
935
+ * `signed` — whether the executable was code-signed.
936
+ * `stripped` — whether an existing signature was removed before signing.
937
+ * `terminal` — `true` when a console window is retained, `false` for a
938
+ * GUI-subsystem build; `undefined` on non-Windows platforms.
939
+ */
940
+ export declare interface SEAResult {
941
+ readonly executable: string;
942
+ readonly platform: string;
943
+ readonly size: number;
944
+ readonly duration: number;
945
+ readonly compression?: SEACompressionManifest;
946
+ readonly signed: boolean;
947
+ readonly stripped: boolean;
948
+ readonly terminal?: boolean;
949
+ }
950
+
951
+ /**
952
+ * Options for running a shell command.
953
+ *
954
+ * @remarks
955
+ * `cwd` — working directory. Default: `process.cwd()`.
956
+ * `env` — additional environment variables to merge with `process.env`.
957
+ */
958
+ export declare interface SEAShellOptions {
959
+ readonly cwd?: string;
960
+ readonly env?: Readonly<Record<string, string>>;
961
+ readonly timeout?: number;
962
+ readonly signal?: AbortSignal;
963
+ }
964
+
965
+ /**
966
+ * Overall status of the seal build.
967
+ */
968
+ export declare type SEAStatus = 'idle' | 'active' | 'done' | 'error';
969
+
970
+ /**
971
+ * Windows-specific SEA build options.
972
+ *
973
+ * @remarks
974
+ * `terminal` — whether the built executable keeps a console window (PE
975
+ * console subsystem). Defaults to `true`. Set `false` to build a
976
+ * GUI-subsystem binary that launches without a terminal — warning: when
977
+ * launched without an attached console, a GUI-subsystem Node binary has no
978
+ * valid stdio, so `process.stdout`/`stderr`/`stdin` are detached and console
979
+ * output is discarded; use only for windowless apps.
980
+ * `sign` — Authenticode signing options. When present, the assembled
981
+ * executable is signed with `signtool` (and verified) as the LAST content
982
+ * mutation before the atomic finalize; when absent, the output is unsigned
983
+ * and `SEAResult.signed` is `false` (unchanged default behavior).
984
+ *
985
+ * These options apply only when the build HOST is Windows — there is no
986
+ * cross-compilation, so building on a non-Windows host ignores `windows.*`.
987
+ */
988
+ export declare interface SEAWindowsOptions {
989
+ readonly terminal?: boolean;
990
+ readonly sign?: SEAWindowsSignOptions;
991
+ }
992
+
993
+ /**
994
+ * Windows Authenticode signing options, passed through to `signtool`.
995
+ *
996
+ * @remarks
997
+ * `file` — path to a `.pfx`/`.p12` certificate file (`signtool /f`).
998
+ * `password` — certificate password (`signtool /p`). SENSITIVE — never
999
+ * logged and never included in a thrown error's message or `context`.
1000
+ * `thumbprint` — SHA1 thumbprint of a certificate already installed in the
1001
+ * Windows certificate store (`signtool /sha1`).
1002
+ * `timestamp` — RFC3161 timestamp server URL (`signtool /tr`, paired with
1003
+ * `/td <digest>`).
1004
+ * `digest` — file digest algorithm (`signtool /fd`). Default: `'sha256'`.
1005
+ *
1006
+ * Exactly ONE of `file` or `thumbprint` must be supplied — they identify two
1007
+ * different certificate sources and are mutually exclusive. `password`
1008
+ * pairs with `file` (a store-resident certificate referenced by
1009
+ * `thumbprint` has no associated password to supply here).
1010
+ */
1011
+ export declare interface SEAWindowsSignOptions {
1012
+ readonly file?: string;
1013
+ readonly password?: string;
1014
+ readonly thumbprint?: string;
1015
+ readonly timestamp?: string;
1016
+ readonly digest?: string;
1017
+ }
1018
+
1019
+ /**
1020
+ * An error thrown when a shell command run via `runShell` exits non-zero.
1021
+ *
1022
+ * @remarks
1023
+ * Carries the captured `stdout` and `stderr` buffers from the failed process.
1024
+ * Always carries {@link SEAErrorCode} `'SHELL'`. Narrow a caught value with
1025
+ * {@link isShellError}.
1026
+ *
1027
+ * @example
1028
+ * ```ts
1029
+ * try {
1030
+ * runShell(['codesign', '--sign', '-', path])
1031
+ * } catch (error) {
1032
+ * if (isShellError(error)) {
1033
+ * console.error(error.stderr.toString())
1034
+ * }
1035
+ * }
1036
+ * ```
1037
+ */
1038
+ export declare class ShellError extends SEAError {
1039
+ readonly stdout: Buffer;
1040
+ readonly stderr: Buffer;
1041
+ constructor(message: string, stdout: Buffer, stderr: Buffer);
1042
+ }
1043
+
1044
+ /** File extensions that should NOT be Brotli-compressed */
1045
+ export declare const SKIP_EXTENSIONS: Set<string>;
1046
+
1047
+ /**
1048
+ * Remove the Authenticode signature from a PE executable by zeroing
1049
+ * the security directory entry in the optional header.
1050
+ *
1051
+ * @remarks
1052
+ * If the certificate overlay described by the security directory sits at the
1053
+ * very end of the file (the common case for `signtool`-signed binaries), the
1054
+ * file is truncated to the certificate's start FIRST so the overlay bytes are
1055
+ * discarded rather than left as dead weight for a downstream injector to
1056
+ * bury mid-file. The directory read is bounds-checked so a malformed or
1057
+ * truncated security directory cannot throw unexpectedly — it is simply
1058
+ * skipped and only the directory entry is zeroed.
1059
+ *
1060
+ * @param path - Path to the executable
1061
+ */
1062
+ export declare function stripPESignature(path: string): void;
1063
+
1064
+ /**
1065
+ * Fsync a directory to durably persist a prior file rename/create within it.
1066
+ *
1067
+ * @remarks
1068
+ * A `rename`/`create` is only durable once its CONTAINING directory entry is
1069
+ * flushed — fsyncing the file itself is not enough. `path` is the directory
1070
+ * to fsync (callers pass `dirname(target)`, not the file itself). On Windows
1071
+ * there is no directory file handle to fsync, so this is a no-op there (the
1072
+ * platform lacks the primitive, not a failure). Some filesystems/platforms
1073
+ * return a benign errno for a directory fsync attempt (`EINVAL`, `ENOTSUP`,
1074
+ * `EISDIR`, `EPERM`, `EACCES`) — those are treated as "fsync unsupported
1075
+ * here" and swallowed; anything else (e.g. `ENOENT`, meaning the directory
1076
+ * itself is missing) is a genuine failure and is thrown as a coded `SEAError`.
1077
+ *
1078
+ * @param path - Directory path to fsync
1079
+ * @throws SEAError with code `'OUTPUT'` when the directory sync fails for an
1080
+ * unrecognized reason
1081
+ *
1082
+ * @example
1083
+ * ```ts
1084
+ * syncDirectory('/dist/app/bin')
1085
+ * ```
1086
+ */
1087
+ export declare function syncDirectory(path: string): void;
1088
+
1089
+ /**
1090
+ * Recursively walk a directory and return all file paths.
1091
+ *
1092
+ * @param directory - Directory to walk
1093
+ * @param base - Base directory for relative path calculation
1094
+ * @returns Array of relative file paths
1095
+ */
1096
+ export declare function walkDirectory(directory: string, base?: string): readonly string[];
1097
+
1098
+ /** Windows PE subsystem value: console application */
1099
+ export declare const WINDOWS_SUBSYSTEM_CONSOLE = 3;
1100
+
1101
+ /** Windows PE subsystem value: GUI application (no terminal window) */
1102
+ export declare const WINDOWS_SUBSYSTEM_GUI = 2;
1103
+
1104
+ /**
1105
+ * Write a 16-bit unsigned integer to a file descriptor.
1106
+ *
1107
+ * @param fd - Open file descriptor
1108
+ * @param offset - Byte offset to write at
1109
+ * @param value - The 16-bit value to write
1110
+ */
1111
+ export declare function writeU16(fd: number, offset: number, value: number): void;
1112
+
1113
+ export { }