@orkestrel/sea 0.0.13 → 0.0.15
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.
- package/README.md +16 -11
- package/dist/src/server/index.cjs +632 -386
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +650 -250
- package/dist/src/server/index.d.ts +650 -250
- package/dist/src/server/index.js +617 -380
- package/dist/src/server/index.js.map +1 -1
- package/package.json +16 -19
|
@@ -1,15 +1,74 @@
|
|
|
1
|
-
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
-
import { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
-
import { EmitterInterface } from '@orkestrel/emitter';
|
|
1
|
+
import type { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
+
import type { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
+
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Aligns an ELF note component size to its four-byte boundary.
|
|
7
7
|
*
|
|
8
8
|
* @param value - Component size to align
|
|
9
9
|
* @returns The value rounded up to the next multiple of four
|
|
10
10
|
*/
|
|
11
11
|
export declare function alignELFNoteSize(value: number): number;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Rounds a value up to the next multiple of an alignment boundary.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* The shared alignment leaf behind every binary-format writer in this package:
|
|
18
|
+
* PE section and file alignment, ELF note and page alignment, and Mach-O page
|
|
19
|
+
* alignment all round the same way. `alignment` must be a nonzero power of two
|
|
20
|
+
* ({@link isPowerOfTwo} is the guard the PE injector applies before using a
|
|
21
|
+
* value read out of a header as a divisor).
|
|
22
|
+
*
|
|
23
|
+
* @param value - Value to align
|
|
24
|
+
* @param alignment - Alignment boundary to round up to
|
|
25
|
+
* @returns The value rounded up to the next multiple of `alignment`
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* alignTo(10, 4) // 12
|
|
30
|
+
* alignTo(4096, 4096) // 4096 — already aligned
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function alignTo(value: number, alignment: number): number;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Appends a source file to a target file, streaming in fixed-size chunks.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* Reads `source` in `chunk`-sized reads and appends each chunk to `target`, so
|
|
40
|
+
* a multi-hundred-megabyte blob is never fully buffered. A read returning zero
|
|
41
|
+
* bytes ends the copy, which is the normal end-of-file signal for a source that
|
|
42
|
+
* shrank between the size read and the copy.
|
|
43
|
+
*
|
|
44
|
+
* @param target - Path of the file to append to
|
|
45
|
+
* @param source - Path of the file to append
|
|
46
|
+
* @param chunk - Read/append chunk size in bytes. Default: 4 MB.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* appendFile('dist/sea/app', 'dist/sea/sea-prep.blob')
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function appendFile(target: string, source: string, chunk?: number): void;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Holds one named asset's key, bytes, and compression state.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* `compressed` is inferred from a `.br` suffix on the key whenever the input
|
|
60
|
+
* leaves it unset, so a Brotli output registered under its own name reports itself
|
|
61
|
+
* correctly without the caller restating it.
|
|
62
|
+
*
|
|
63
|
+
* @param input - The asset's key, content bytes, and optional compression flag
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const asset = new Asset({ key: 'client.html.br', content: compressedBuffer })
|
|
68
|
+
* asset.key // 'client.html.br'
|
|
69
|
+
* asset.compressed // true
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
13
72
|
export declare class Asset implements AssetInterface {
|
|
14
73
|
readonly key: string;
|
|
15
74
|
readonly content: ArrayBuffer;
|
|
@@ -18,10 +77,10 @@ export declare class Asset implements AssetInterface {
|
|
|
18
77
|
}
|
|
19
78
|
|
|
20
79
|
/**
|
|
21
|
-
*
|
|
80
|
+
* Holds the minimal data needed to create an {@link AssetInterface}.
|
|
22
81
|
*
|
|
23
82
|
* @remarks
|
|
24
|
-
* `key` — the asset's lookup key (
|
|
83
|
+
* `key` — the asset's lookup key (for example `"client.html.br"`).
|
|
25
84
|
* `content` — raw asset bytes.
|
|
26
85
|
* `compressed` — whether `content` is Brotli-compressed. Default: inferred
|
|
27
86
|
* from a `.br` suffix on `key`.
|
|
@@ -33,7 +92,7 @@ export declare interface AssetInput {
|
|
|
33
92
|
}
|
|
34
93
|
|
|
35
94
|
/**
|
|
36
|
-
*
|
|
95
|
+
* Represents a single named asset wrapping its key, content buffer, and compression flag.
|
|
37
96
|
*/
|
|
38
97
|
export declare interface AssetInterface {
|
|
39
98
|
readonly key: string;
|
|
@@ -41,6 +100,29 @@ export declare interface AssetInterface {
|
|
|
41
100
|
readonly compressed: boolean;
|
|
42
101
|
}
|
|
43
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Collects named assets from a SEA blob or from disk and serves them by key.
|
|
105
|
+
*
|
|
106
|
+
* @remarks
|
|
107
|
+
* Construction registers every asset embedded in the running SEA blob, so an
|
|
108
|
+
* executable built by this package reaches its assets without touching the
|
|
109
|
+
* filesystem. Outside SEA mode that step registers nothing, and `load()` reads
|
|
110
|
+
* the paths `options.assets` configures instead.
|
|
111
|
+
*
|
|
112
|
+
* @param options - Asset manager options: the project root, the key→path mapping
|
|
113
|
+
* `load()` reads, and the event hooks
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const manager = new AssetManager({
|
|
118
|
+
* root: process.cwd(),
|
|
119
|
+
* assets: { 'client.html.br': 'dist/client/client.html.br' },
|
|
120
|
+
* })
|
|
121
|
+
* manager.load()
|
|
122
|
+
* manager.asset('client.html.br')
|
|
123
|
+
* manager.destroy()
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
44
126
|
export declare class AssetManager implements AssetManagerInterface {
|
|
45
127
|
#private;
|
|
46
128
|
constructor(options?: AssetManagerOptions);
|
|
@@ -49,13 +131,13 @@ export declare class AssetManager implements AssetManagerInterface {
|
|
|
49
131
|
asset(key: string): AssetInterface | undefined;
|
|
50
132
|
assets(): readonly AssetInterface[];
|
|
51
133
|
keys(): readonly string[];
|
|
52
|
-
register(input: AssetInput | AssetInput[]): void;
|
|
134
|
+
register(input: AssetInput | readonly AssetInput[]): void;
|
|
53
135
|
load(): void;
|
|
54
136
|
clear(): void;
|
|
55
137
|
destroy(): void;
|
|
56
138
|
}
|
|
57
139
|
|
|
58
|
-
/**
|
|
140
|
+
/** Lists the events emitted by an {@link AssetManagerInterface}. */
|
|
59
141
|
export declare type AssetManagerEventMap = {
|
|
60
142
|
readonly register: readonly [asset: AssetInterface];
|
|
61
143
|
readonly load: readonly [keys: readonly string[]];
|
|
@@ -64,41 +146,80 @@ export declare type AssetManagerEventMap = {
|
|
|
64
146
|
};
|
|
65
147
|
|
|
66
148
|
/**
|
|
67
|
-
*
|
|
149
|
+
* Represents a named asset collection with SEA and disk loading.
|
|
68
150
|
*
|
|
69
151
|
* @remarks
|
|
70
152
|
* In SEA mode, embedded assets are loaded automatically at construction.
|
|
71
|
-
* Outside SEA, `load()` reads
|
|
153
|
+
* Outside SEA, `load()` reads the paths `assets` configures from disk.
|
|
72
154
|
*/
|
|
73
155
|
export declare interface AssetManagerInterface {
|
|
156
|
+
/** Holds the emitter reporting the register, load, clear, and error events. */
|
|
74
157
|
readonly emitter: EmitterInterface<AssetManagerEventMap>;
|
|
158
|
+
/** Holds the number of assets registered so far. */
|
|
75
159
|
readonly count: number;
|
|
160
|
+
/** Looks up one registered asset by key. */
|
|
76
161
|
asset(key: string): AssetInterface | undefined;
|
|
162
|
+
/** Lists every registered asset, in registration order. */
|
|
77
163
|
assets(): readonly AssetInterface[];
|
|
164
|
+
/** Lists every registered asset key, in registration order. */
|
|
78
165
|
keys(): readonly string[];
|
|
79
|
-
|
|
166
|
+
/** Registers one asset, or every asset of a list. */
|
|
167
|
+
register(input: AssetInput | readonly AssetInput[]): void;
|
|
168
|
+
/** Loads the configured assets from disk, and registers nothing inside SEA mode. */
|
|
80
169
|
load(): void;
|
|
170
|
+
/** Removes every registered asset without destroying the manager. */
|
|
81
171
|
clear(): void;
|
|
172
|
+
/** Clears every registered asset and tears down the emitter. */
|
|
82
173
|
destroy(): void;
|
|
83
174
|
}
|
|
84
175
|
|
|
85
176
|
/**
|
|
86
|
-
*
|
|
177
|
+
* Configures the creation of an {@link AssetManagerInterface}.
|
|
87
178
|
*
|
|
88
179
|
* @remarks
|
|
89
|
-
* `root`
|
|
180
|
+
* `root` — project root used to resolve the configured `assets` paths. Default: `process.cwd()`.
|
|
181
|
+
* `assets` — key→path mapping for the assets `load()` reads from disk. Each path is
|
|
182
|
+
* relative to `root`. `load()` registers every path that exists under its key and
|
|
183
|
+
* emits one `error` for each configured path that is missing.
|
|
90
184
|
*/
|
|
91
185
|
export declare interface AssetManagerOptions {
|
|
92
186
|
readonly on?: EmitterHooks<AssetManagerEventMap>;
|
|
93
187
|
readonly error?: EmitterErrorHandler;
|
|
94
188
|
readonly root?: string;
|
|
189
|
+
readonly assets?: Readonly<Record<string, string>>;
|
|
95
190
|
}
|
|
96
191
|
|
|
97
|
-
/**
|
|
192
|
+
/** Names the file extension indicating Brotli compression, `.br`. */
|
|
98
193
|
export declare const BROTLI_EXTENSION = ".br";
|
|
99
194
|
|
|
100
195
|
/**
|
|
101
|
-
*
|
|
196
|
+
* Builds the Node.js `--experimental-sea-config` JSON object for a SEA blob.
|
|
197
|
+
*
|
|
198
|
+
* @remarks
|
|
199
|
+
* A pure leaf extracted from the SEA build orchestrator. The `mainFormat`
|
|
200
|
+
* field (`'commonjs' | 'module'`) exists only in Node >= 25.7 — for a `'cjs'`
|
|
201
|
+
* entry (the default) `mainFormat` is omitted entirely so the config still
|
|
202
|
+
* builds on older Node hosts where `'commonjs'` is already the implicit
|
|
203
|
+
* default; for an `'esm'` entry `mainFormat: 'module'` is set explicitly
|
|
204
|
+
* (this requires a Node >= 25.7 build host). Node also documents that
|
|
205
|
+
* `useSnapshot` is incompatible with an ESM entry — combining the two throws.
|
|
206
|
+
*
|
|
207
|
+
* @param entry - SEA entry point options
|
|
208
|
+
* @param blob - Absolute output path for the generated blob
|
|
209
|
+
* @param assets - Optional key→path mapping for embedded assets
|
|
210
|
+
* @param options - Optional blob behavior overrides (cache, snapshot)
|
|
211
|
+
* @returns the SEA config object, ready to be written to disk as JSON
|
|
212
|
+
* @throws SEAError with code `'BLOB'` when `useSnapshot` is combined with an ESM entry
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const config = buildBlobConfig({ path: 'dist/bin/serve.cjs' }, 'dist/bin/sea-prep.blob', undefined)
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
export declare function buildBlobConfig(entry: SEAEntryOptions, blob: string, assets: Readonly<Record<string, string>> | undefined, options?: SEABlobOptions): Readonly<Record<string, unknown>>;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Builds an ELF `PT_NOTE` entry's header bytes (namesz/descsz/type + padded
|
|
102
223
|
* name) for the SEA blob note, without the blob body itself.
|
|
103
224
|
*
|
|
104
225
|
* @remarks
|
|
@@ -111,48 +232,69 @@ export declare const BROTLI_EXTENSION = ".br";
|
|
|
111
232
|
* (`strncmp(name, "NODE_SEA", 8)`), so `resource` is written in full but
|
|
112
233
|
* only needs to begin with those 8 bytes to be found at runtime.
|
|
113
234
|
*
|
|
114
|
-
* @param resource - Note name (SEA resource identifier,
|
|
235
|
+
* @param resource - Note name (SEA resource identifier, for example `NODE_SEA_BLOB`)
|
|
115
236
|
* @param blobSize - Size in bytes of the SEA blob that will follow the header
|
|
116
237
|
* @returns The note header bytes and the total on-disk size of header + blob
|
|
117
238
|
*
|
|
118
239
|
* @example
|
|
119
240
|
* ```ts
|
|
120
|
-
* const { header,
|
|
241
|
+
* const { header, total } = buildELFNoteHeader('NODE_SEA_BLOB', 4096)
|
|
121
242
|
* ```
|
|
122
243
|
*/
|
|
123
|
-
export declare function buildELFNoteHeader(resource: string, blobSize: number):
|
|
124
|
-
readonly header: Buffer;
|
|
125
|
-
readonly entryTotal: number;
|
|
126
|
-
};
|
|
244
|
+
export declare function buildELFNoteHeader(resource: string, blobSize: number): ELFNoteHeader;
|
|
127
245
|
|
|
128
|
-
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
246
|
+
/**
|
|
247
|
+
* Builds the `signtool sign` argv for signing a Windows executable.
|
|
248
|
+
*
|
|
249
|
+
* @remarks
|
|
250
|
+
* Requires exactly one certificate source — `sign.file` (a `.pfx`/`.p12`
|
|
251
|
+
* file, paired with `sign.password` when present) XOR `sign.thumbprint` (a
|
|
252
|
+
* certificate already installed in the Windows store). When `sign.timestamp`
|
|
253
|
+
* is set it is parsed with the `URL` constructor and must be an `http:` or
|
|
254
|
+
* `https:` URL. The returned argv is passed directly to `executeShell` — never
|
|
255
|
+
* through a shell — so nothing in `sign` can be interpreted as a flag or
|
|
256
|
+
* injected into a command line. `sign.password` is never included in a
|
|
257
|
+
* thrown error's message or `context`.
|
|
258
|
+
*
|
|
259
|
+
* @param sign - Windows signing options
|
|
260
|
+
* @param target - Absolute path to the executable to sign
|
|
261
|
+
* @returns The `signtool` argv, ready for `executeShell`
|
|
262
|
+
* @throws SEAError with code `'SIGN'` when neither `file` nor `thumbprint` is set
|
|
263
|
+
* @throws SEAError with code `'SIGN'` when both `file` and `thumbprint` are set
|
|
264
|
+
* @throws SEAError with code `'SIGN'` when `timestamp` is not a parseable http(s) URL
|
|
265
|
+
* @throws SEAError with code `'SIGN'` when `digest` is not `'sha1'`, `'sha256'`, `'sha384'`, or `'sha512'`
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* buildSignCommand({ thumbprint: 'AABBCCDDEEFF00112233445566778899AABBCCDD' }, 'dist/sea/app.exe')
|
|
270
|
+
* // ['signtool', 'sign', '/fd', 'sha256', '/sha1', 'AABBCCDDEEFF00112233445566778899AABBCCDD', 'dist/sea/app.exe']
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
export declare function buildSignCommand(sign: SEAWindowsSignOptions, target: string): readonly string[];
|
|
133
274
|
|
|
134
275
|
/**
|
|
135
|
-
*
|
|
276
|
+
* Compresses all compressible files in a directory tree.
|
|
136
277
|
*
|
|
137
278
|
* @param directory - Absolute path to the directory
|
|
138
|
-
* @param options -
|
|
279
|
+
* @param options - Brotli options (quality, mode)
|
|
139
280
|
* @param progress - Optional callback invoked after each file is compressed
|
|
140
281
|
* @returns Compression manifest with all results
|
|
141
282
|
*/
|
|
142
|
-
export declare function compressDirectory(directory: string, options?:
|
|
283
|
+
export declare function compressDirectory(directory: string, options?: SEABrotliOptions, progress?: SEACompressionHandler): SEACompressionManifest;
|
|
143
284
|
|
|
144
285
|
/**
|
|
145
|
-
* Brotli-
|
|
286
|
+
* Brotli-compresses a single file, writing the output alongside it.
|
|
146
287
|
*
|
|
147
288
|
* @param input - Absolute path to the source file
|
|
148
289
|
* @param output - Absolute path for the compressed output
|
|
149
|
-
* @param options -
|
|
290
|
+
* @param options - Brotli options (quality, mode)
|
|
150
291
|
* @returns Compression result with size comparison
|
|
292
|
+
* @throws SEAError with code `'OUTPUT'` when `output` is an existing symlink
|
|
151
293
|
*/
|
|
152
|
-
export declare function compressFile(input: string, output: string, options?:
|
|
294
|
+
export declare function compressFile(input: string, output: string, options?: SEABrotliOptions): SEACompressionResult;
|
|
153
295
|
|
|
154
296
|
/**
|
|
155
|
-
*
|
|
297
|
+
* Computes a size comparison between original and compressed byte counts.
|
|
156
298
|
*
|
|
157
299
|
* @param original - Original byte count
|
|
158
300
|
* @param compressed - Compressed byte count
|
|
@@ -161,7 +303,7 @@ export declare function compressFile(input: string, output: string, options?: SE
|
|
|
161
303
|
export declare function computeSize(original: number, compressed: number): SEACompressionSize;
|
|
162
304
|
|
|
163
305
|
/**
|
|
164
|
-
*
|
|
306
|
+
* Copies a byte range from one open file descriptor to another, streaming in
|
|
165
307
|
* fixed-size chunks instead of buffering the whole range in memory.
|
|
166
308
|
*
|
|
167
309
|
* @remarks
|
|
@@ -192,7 +334,9 @@ export declare function computeSize(original: number, compressed: number): SEACo
|
|
|
192
334
|
export declare function copyRange(source: number, target: number, start: number, length: number, chunk?: number): void;
|
|
193
335
|
|
|
194
336
|
/**
|
|
195
|
-
*
|
|
337
|
+
* Creates one named asset from a key and a content buffer and returns it as an
|
|
338
|
+
* `AssetInterface`, with `compressed` inferred from the key where the input leaves
|
|
339
|
+
* it unset.
|
|
196
340
|
*
|
|
197
341
|
* @param input - Asset key, content, and optional compression flag
|
|
198
342
|
* @returns a new `AssetInterface`
|
|
@@ -205,7 +349,8 @@ export declare function copyRange(source: number, target: number, start: number,
|
|
|
205
349
|
export declare function createAsset(input: AssetInput): AssetInterface;
|
|
206
350
|
|
|
207
351
|
/**
|
|
208
|
-
*
|
|
352
|
+
* Creates an asset collection and returns it as an `AssetManagerInterface`, already
|
|
353
|
+
* carrying whatever assets the running SEA blob embeds.
|
|
209
354
|
*
|
|
210
355
|
* @param options - Asset manager options (root, event hooks)
|
|
211
356
|
* @returns a new `AssetManagerInterface`
|
|
@@ -219,37 +364,13 @@ export declare function createAsset(input: AssetInput): AssetInterface;
|
|
|
219
364
|
export declare function createAssetManager(options?: AssetManagerOptions): AssetManagerInterface;
|
|
220
365
|
|
|
221
366
|
/**
|
|
222
|
-
*
|
|
367
|
+
* Creates a resource injector bound to one target executable and returns it as an
|
|
368
|
+
* `InjectorInterface`, with the executable's format already detected from its header.
|
|
223
369
|
*
|
|
224
370
|
* @remarks
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
* builds on older Node hosts where `'commonjs'` is already the implicit
|
|
229
|
-
* default; for an `'esm'` entry `mainFormat: 'module'` is set explicitly
|
|
230
|
-
* (this requires a Node >= 25.7 build host). Node also documents that
|
|
231
|
-
* `useSnapshot` is incompatible with an ESM entry — combining the two throws.
|
|
232
|
-
*
|
|
233
|
-
* @param entry - SEA entry point options
|
|
234
|
-
* @param blob - Absolute output path for the generated blob
|
|
235
|
-
* @param assets - Optional key→path mapping for embedded assets
|
|
236
|
-
* @param options - Optional blob behavior overrides (cache, snapshot)
|
|
237
|
-
* @returns the SEA config object, ready to be written to disk as JSON
|
|
238
|
-
* @throws SEAError with code `'BLOB'` when `useSnapshot` is combined with an ESM entry
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* ```ts
|
|
242
|
-
* const config = createBlobConfig({ path: 'dist/bin/serve.cjs' }, 'dist/bin/sea-prep.blob', undefined)
|
|
243
|
-
* ```
|
|
244
|
-
*/
|
|
245
|
-
export declare function createBlobConfig(entry: SEAEntryOptions, blob: string, assets: Readonly<Record<string, string>> | undefined, options?: SEABlobOptions): Readonly<Record<string, unknown>>;
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Create a cross-platform binary resource injector.
|
|
249
|
-
*
|
|
250
|
-
* Detects the executable format (PE, ELF, Mach-O) from the file header
|
|
251
|
-
* and injects the blob using pure TypeScript file I/O — no WASM, no
|
|
252
|
-
* external tools.
|
|
371
|
+
* The format detected at construction — PE, ELF, or Mach-O — selects the strategy
|
|
372
|
+
* `inject` takes. Every write runs through pure TypeScript file I/O, so the injector
|
|
373
|
+
* needs no WASM and no external tool.
|
|
253
374
|
*
|
|
254
375
|
* @param options - Injector options
|
|
255
376
|
* @returns a new `InjectorInterface`
|
|
@@ -268,84 +389,115 @@ export declare function createBlobConfig(entry: SEAEntryOptions, blob: string, a
|
|
|
268
389
|
export declare function createInjector(options: InjectorOptions): InjectorInterface;
|
|
269
390
|
|
|
270
391
|
/**
|
|
271
|
-
*
|
|
392
|
+
* Creates a SEA build orchestrator over the given options and returns it as a
|
|
393
|
+
* `SEAInterface`, the published contract a caller holds instead of the `SEA` class.
|
|
272
394
|
*
|
|
273
395
|
* @param options - SEA build options
|
|
274
396
|
* @returns a new `SEAInterface`
|
|
275
397
|
*
|
|
276
|
-
* @example
|
|
398
|
+
* @example Build a single executable
|
|
277
399
|
* ```ts
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
400
|
+
* import { createSEA, formatSize } from '@orkestrel/sea'
|
|
401
|
+
*
|
|
402
|
+
* const sea = createSEA({
|
|
403
|
+
* name: 'myapp',
|
|
404
|
+
* entry: { path: 'dist/server/serve.cjs' },
|
|
405
|
+
* output: 'dist/sea',
|
|
406
|
+
* assets: { 'model.gguf': 'models/model.gguf' },
|
|
407
|
+
* compression: { paths: ['dist/app/browser'], mode: 'text' },
|
|
408
|
+
* windows: { terminal: false },
|
|
409
|
+
* timeout: 30_000,
|
|
284
410
|
* })
|
|
285
|
-
* const result = await seal.execute()
|
|
286
|
-
* ```
|
|
287
|
-
*/
|
|
288
|
-
export declare function createSEA(options: SEAOptions): SEAInterface;
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Build the `signtool sign` argv for signing a Windows executable.
|
|
292
|
-
*
|
|
293
|
-
* @remarks
|
|
294
|
-
* Requires EXACTLY ONE certificate source — `sign.file` (a `.pfx`/`.p12`
|
|
295
|
-
* file, paired with `sign.password` when present) XOR `sign.thumbprint` (a
|
|
296
|
-
* certificate already installed in the Windows store). When `sign.timestamp`
|
|
297
|
-
* is set it is parsed with the `URL` constructor and must be an `http:` or
|
|
298
|
-
* `https:` URL. The returned argv is passed directly to `runShell` — never
|
|
299
|
-
* through a shell — so nothing in `sign` can be interpreted as a flag or
|
|
300
|
-
* injected into a command line. `sign.password` is NEVER included in a
|
|
301
|
-
* thrown error's message or `context`.
|
|
302
|
-
*
|
|
303
|
-
* @param sign - Windows signing options
|
|
304
|
-
* @param target - Absolute path to the executable to sign
|
|
305
|
-
* @returns The `signtool` argv, ready for `runShell`
|
|
306
|
-
* @throws SEAError with code `'SIGN'` when neither `file` nor `thumbprint` is set
|
|
307
|
-
* @throws SEAError with code `'SIGN'` when both `file` and `thumbprint` are set
|
|
308
|
-
* @throws SEAError with code `'SIGN'` when `timestamp` is not a parseable http(s) URL
|
|
309
|
-
* @throws SEAError with code `'SIGN'` when `digest` is not `'sha1'`, `'sha256'`, `'sha384'`, or `'sha512'`
|
|
310
411
|
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
412
|
+
* const result = await sea.execute()
|
|
413
|
+
* process.stdout.write(
|
|
414
|
+
* `${result.executable} ${formatSize(result.size)} ${String(result.duration)}ms\n`,
|
|
415
|
+
* )
|
|
315
416
|
* ```
|
|
316
417
|
*/
|
|
317
|
-
export declare function
|
|
418
|
+
export declare function createSEA(options: SEAOptions): SEAInterface;
|
|
318
419
|
|
|
319
|
-
/**
|
|
420
|
+
/** Names the default SEA entry point module format when none is specified, `cjs`. */
|
|
320
421
|
export declare const DEFAULT_ENTRY_FORMAT: SEAEntryFormat;
|
|
321
422
|
|
|
322
|
-
/**
|
|
423
|
+
/** Holds the default Brotli compression quality level, 11, the maximum Brotli accepts. */
|
|
323
424
|
export declare const DEFAULT_SEA_COMPRESSION_QUALITY = 11;
|
|
324
425
|
|
|
325
|
-
/** ELF 64-bit class identifier */
|
|
426
|
+
/** Holds the ELF 64-bit class identifier, 2. */
|
|
326
427
|
export declare const ELF_CLASS_64 = 2;
|
|
327
428
|
|
|
328
|
-
/** ELF little-endian data encoding */
|
|
429
|
+
/** Holds the ELF little-endian data encoding, 1. */
|
|
329
430
|
export declare const ELF_DATA_LSB = 1;
|
|
330
431
|
|
|
331
|
-
/**
|
|
432
|
+
/**
|
|
433
|
+
* Holds the ELF magic, 0x7f454c46, the bytes 0x7F `E` `L` `F` read as a 32-bit
|
|
434
|
+
* big-endian value.
|
|
435
|
+
*/
|
|
332
436
|
export declare const ELF_MAGIC = 2135247942;
|
|
333
437
|
|
|
334
|
-
/**
|
|
438
|
+
/** Holds the page size an injected ELF segment is aligned to, 0x1000. */
|
|
439
|
+
export declare const ELF_PAGE_SIZE = 4096;
|
|
440
|
+
|
|
441
|
+
/** Holds the ELF segment permission flag marking a segment readable, 4. */
|
|
442
|
+
export declare const ELF_PF_R = 4;
|
|
443
|
+
|
|
444
|
+
/** Holds the ELF program header type for a loadable segment, 1. */
|
|
445
|
+
export declare const ELF_PT_LOAD = 1;
|
|
446
|
+
|
|
447
|
+
/** Holds the ELF program header type for a note segment, 4. */
|
|
335
448
|
export declare const ELF_PT_NOTE = 4;
|
|
336
449
|
|
|
450
|
+
/** Holds the ELF program header type for the program header table itself, 6. */
|
|
451
|
+
export declare const ELF_PT_PHDR = 6;
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Holds an ELF `PT_NOTE` entry's header bytes and the on-disk size of the whole entry.
|
|
455
|
+
*
|
|
456
|
+
* @remarks
|
|
457
|
+
* `header` — the namesz/descsz/type words followed by the NUL-terminated,
|
|
458
|
+
* four-byte-padded note name.
|
|
459
|
+
* `total` — bytes the complete entry occupies on disk: `header` plus the
|
|
460
|
+
* four-byte-padded blob written after it.
|
|
461
|
+
*/
|
|
462
|
+
export declare interface ELFNoteHeader {
|
|
463
|
+
readonly header: Buffer;
|
|
464
|
+
readonly total: number;
|
|
465
|
+
}
|
|
466
|
+
|
|
337
467
|
/**
|
|
338
|
-
*
|
|
468
|
+
* Holds one ELF64 program header entry.
|
|
469
|
+
*
|
|
470
|
+
* @remarks
|
|
471
|
+
* Transliterates the `Elf64_Phdr` structure of the ELF64 specification field for
|
|
472
|
+
* field, with the `p_` prefix dropped: `type` is `p_type`, `flags` is `p_flags`,
|
|
473
|
+
* `offset` is `p_offset`, `vaddr` is `p_vaddr`, `paddr` is `p_paddr`, `filesz` is
|
|
474
|
+
* `p_filesz`, `memsz` is `p_memsz`, and `align` is `p_align`. Every 64-bit field is
|
|
475
|
+
* carried as a `number` because an executable's offsets stay far inside the safe
|
|
476
|
+
* integer range.
|
|
477
|
+
*/
|
|
478
|
+
export declare interface ELFProgramHeader {
|
|
479
|
+
readonly type: number;
|
|
480
|
+
readonly flags: number;
|
|
481
|
+
readonly offset: number;
|
|
482
|
+
readonly vaddr: number;
|
|
483
|
+
readonly paddr: number;
|
|
484
|
+
readonly filesz: number;
|
|
485
|
+
readonly memsz: number;
|
|
486
|
+
readonly align: number;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Asserts that `path` (resolved against `base`) real-path-resolves to a
|
|
339
491
|
* location inside `base`, defeating a symlink escape.
|
|
340
492
|
*
|
|
341
493
|
* @remarks
|
|
342
494
|
* Resolves `path` against `base`, then dereferences both the resolved path
|
|
343
495
|
* and `base` with `realpathSync` and requires the real resolved path to
|
|
344
496
|
* equal the real base or begin with the real base plus a path separator.
|
|
345
|
-
* Dereferencing
|
|
497
|
+
* Dereferencing both sides means a symlinked base itself (for example macOS `/tmp`
|
|
346
498
|
* -> `/private/tmp`) still matches, while a symlink inside the tree that
|
|
347
499
|
* points outside the real base is correctly rejected. A `realpathSync`
|
|
348
|
-
* failure (
|
|
500
|
+
* failure (for example `ENOENT`) is wrapped as a coded `SEAError` rather than
|
|
349
501
|
* leaking the raw Node error.
|
|
350
502
|
*
|
|
351
503
|
* @param base - Absolute path to the containing root
|
|
@@ -363,20 +515,21 @@ export declare const ELF_PT_NOTE = 4;
|
|
|
363
515
|
export declare function ensureContained(base: string, path: string): string;
|
|
364
516
|
|
|
365
517
|
/**
|
|
366
|
-
*
|
|
518
|
+
* Asserts that a path exists, throwing a coded {@link SEAError} if not.
|
|
367
519
|
*
|
|
368
520
|
* @param path - Absolute or relative path to check
|
|
369
521
|
* @param message - Error message when path is missing
|
|
370
522
|
* @param code - Error code to throw with. Default: `'STATE'`.
|
|
523
|
+
* @throws SEAError with `code` (default `'STATE'`) when `path` does not exist
|
|
371
524
|
*/
|
|
372
525
|
export declare function ensureExists(path: string, message: string, code?: SEAErrorCode): void;
|
|
373
526
|
|
|
374
527
|
/**
|
|
375
|
-
*
|
|
528
|
+
* Asserts that an asset key is safe to use as a relative filesystem/archive key.
|
|
376
529
|
*
|
|
377
530
|
* @remarks
|
|
378
531
|
* Rejects an empty key, an absolute path, a key containing a backslash, a
|
|
379
|
-
* Windows drive-relative specifier (
|
|
532
|
+
* Windows drive-relative specifier (for example `'C:foo'`), or any `/`-separated
|
|
380
533
|
* segment equal to `'..'` — all of which could escape the intended asset root.
|
|
381
534
|
*
|
|
382
535
|
* @param key - Asset key to validate
|
|
@@ -392,13 +545,13 @@ export declare function ensureExists(path: string, message: string, code?: SEAEr
|
|
|
392
545
|
export declare function ensureSafeKey(key: string): void;
|
|
393
546
|
|
|
394
547
|
/**
|
|
395
|
-
*
|
|
548
|
+
* Asserts that `name` is a single safe path segment suitable as an output
|
|
396
549
|
* executable base name.
|
|
397
550
|
*
|
|
398
551
|
* @remarks
|
|
399
552
|
* Rejects an empty name, `'.'`, `'..'`, a name containing a `/` or `\`
|
|
400
|
-
* separator, an absolute path, or a Windows drive-relative specifier (
|
|
401
|
-
* `'C:foo'`) — all of which could redirect the output executable outside
|
|
553
|
+
* separator, an absolute path, or a Windows drive-relative specifier (for
|
|
554
|
+
* example `'C:foo'`) — all of which could redirect the output executable outside
|
|
402
555
|
* the intended output directory.
|
|
403
556
|
*
|
|
404
557
|
* @param name - Output executable base name to validate
|
|
@@ -413,12 +566,25 @@ export declare function ensureSafeKey(key: string): void;
|
|
|
413
566
|
export declare function ensureSafeName(name: string): void;
|
|
414
567
|
|
|
415
568
|
/**
|
|
416
|
-
*
|
|
569
|
+
* Names an executable binary format detected from file header magic bytes.
|
|
417
570
|
*/
|
|
418
571
|
export declare type ExecutableFormat = 'pe' | 'elf' | 'macho';
|
|
419
572
|
|
|
420
573
|
/**
|
|
421
|
-
*
|
|
574
|
+
* Executes a command synchronously and returns stdout.
|
|
575
|
+
*
|
|
576
|
+
* @param command - Command to execute (first element is the binary)
|
|
577
|
+
* @param options - Shell options (cwd, env, timeout, signal)
|
|
578
|
+
* @returns stdout as a Buffer
|
|
579
|
+
* @throws SEAError with code `'STATE'` when `command` is empty
|
|
580
|
+
* @throws SEAError with code `'ABORT'` when `options.signal` is already aborted
|
|
581
|
+
* @throws SEAError with code `'TIMEOUT'` when the command exceeds `options.timeout`
|
|
582
|
+
* @throws ShellError when the command exits with non-zero status
|
|
583
|
+
*/
|
|
584
|
+
export declare function executeShell(command: readonly string[], options?: SEAShellOptions): Buffer;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Finalizes a built executable by durably flushing it to disk and atomically
|
|
422
588
|
* moving it into place.
|
|
423
589
|
*
|
|
424
590
|
* @remarks
|
|
@@ -440,13 +606,39 @@ export declare type ExecutableFormat = 'pe' | 'elf' | 'macho';
|
|
|
440
606
|
export declare function finalizeExecutable(source: string, target: string): void;
|
|
441
607
|
|
|
442
608
|
/**
|
|
443
|
-
*
|
|
609
|
+
* Formats a byte count as a human-readable string.
|
|
444
610
|
*
|
|
445
611
|
* @param bytes - Byte count
|
|
446
|
-
* @returns Formatted string (
|
|
612
|
+
* @returns Formatted string (for example `"1.23 MB"`, `"456 KB"`)
|
|
447
613
|
*/
|
|
448
614
|
export declare function formatSize(bytes: number): string;
|
|
449
615
|
|
|
616
|
+
/**
|
|
617
|
+
* Writes a named resource into a PE, ELF, or Mach-O executable in place.
|
|
618
|
+
*
|
|
619
|
+
* @remarks
|
|
620
|
+
* The format is detected from the file's magic bytes at construction, and each
|
|
621
|
+
* format takes its own strategy: PE adds an `RT_RCDATA` resource by rebuilding the
|
|
622
|
+
* resource directory, ELF appends a `PT_NOTE` segment carrying the blob as note
|
|
623
|
+
* data, and Mach-O appends an `LC_SEGMENT_64` load command with one section. The
|
|
624
|
+
* blob is streamed from disk in every case, so its size is bounded by the
|
|
625
|
+
* filesystem rather than by memory.
|
|
626
|
+
*
|
|
627
|
+
* @param options - Injector options: the target executable, the resource name, the
|
|
628
|
+
* blob path, and the optional sentinel fuse and Mach-O segment
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```ts
|
|
632
|
+
* const injector = new Injector({
|
|
633
|
+
* executable: 'dist/sea/myapp.exe',
|
|
634
|
+
* resource: 'NODE_SEA_BLOB',
|
|
635
|
+
* blob: 'dist/sea/sea-prep.blob',
|
|
636
|
+
* fuse: 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
|
|
637
|
+
* })
|
|
638
|
+
* injector.format // 'pe' | 'elf' | 'macho'
|
|
639
|
+
* injector.inject()
|
|
640
|
+
* ```
|
|
641
|
+
*/
|
|
450
642
|
export declare class Injector implements InjectorInterface {
|
|
451
643
|
#private;
|
|
452
644
|
constructor(options: InjectorOptions);
|
|
@@ -455,21 +647,21 @@ export declare class Injector implements InjectorInterface {
|
|
|
455
647
|
}
|
|
456
648
|
|
|
457
649
|
/**
|
|
458
|
-
*
|
|
650
|
+
* Represents a cross-platform binary resource injector.
|
|
459
651
|
*
|
|
460
652
|
* @remarks
|
|
461
653
|
* Injects arbitrary data into PE (Windows), ELF (Linux), and Mach-O (macOS)
|
|
462
654
|
* executables using streaming file I/O. No WASM or external tools required.
|
|
463
655
|
*/
|
|
464
656
|
export declare interface InjectorInterface {
|
|
465
|
-
/**
|
|
657
|
+
/** Holds the detected executable format of the target binary. */
|
|
466
658
|
readonly format: ExecutableFormat;
|
|
467
|
-
/**
|
|
659
|
+
/** Injects the resource data into the executable. */
|
|
468
660
|
inject(): void;
|
|
469
661
|
}
|
|
470
662
|
|
|
471
663
|
/**
|
|
472
|
-
* Mach-O specific injector
|
|
664
|
+
* Configures Mach-O specific injector behavior.
|
|
473
665
|
*
|
|
474
666
|
* @remarks
|
|
475
667
|
* `segment` — Mach-O segment name. Default: `"NODE_SEA"`.
|
|
@@ -479,11 +671,11 @@ export declare interface InjectorMachOOptions {
|
|
|
479
671
|
}
|
|
480
672
|
|
|
481
673
|
/**
|
|
482
|
-
*
|
|
674
|
+
* Configures the injection of a resource into an executable.
|
|
483
675
|
*
|
|
484
676
|
* @remarks
|
|
485
677
|
* `executable` — absolute path to the target executable.
|
|
486
|
-
* `resource` — resource identifier (
|
|
678
|
+
* `resource` — resource identifier (for example `"NODE_SEA_BLOB"`).
|
|
487
679
|
* `blob` — absolute path to the data file to inject.
|
|
488
680
|
* `fuse` — when set, patches the fuse from `:0` to `:1` after injection.
|
|
489
681
|
* `macho` — Mach-O specific options; `segment` defaults to `"NODE_SEA"`.
|
|
@@ -499,50 +691,57 @@ export declare interface InjectorOptions {
|
|
|
499
691
|
}
|
|
500
692
|
|
|
501
693
|
/**
|
|
502
|
-
*
|
|
694
|
+
* Checks whether a file's extension is outside `SKIP_EXTENSIONS`, so Brotli
|
|
695
|
+
* compression applies to it.
|
|
503
696
|
*
|
|
504
697
|
* @param path - Path to the file
|
|
505
|
-
* @returns True
|
|
698
|
+
* @returns True if the file type benefits from compression; false otherwise
|
|
506
699
|
*/
|
|
507
700
|
export declare function isCompressible(path: string): boolean;
|
|
508
701
|
|
|
509
702
|
/**
|
|
510
|
-
*
|
|
703
|
+
* Checks whether a value is a valid {@link ExecutableFormat}.
|
|
511
704
|
*
|
|
512
705
|
* @param value - Value to check
|
|
513
|
-
* @returns True
|
|
706
|
+
* @returns True if value is `'pe'`, `'elf'`, or `'macho'`; false otherwise
|
|
707
|
+
*
|
|
708
|
+
* @example
|
|
709
|
+
* ```ts
|
|
710
|
+
* isExecutableFormat('elf') // true
|
|
711
|
+
* isExecutableFormat('coff') // false
|
|
712
|
+
* ```
|
|
514
713
|
*/
|
|
515
714
|
export declare function isExecutableFormat(value: unknown): value is ExecutableFormat;
|
|
516
715
|
|
|
517
716
|
/**
|
|
518
|
-
*
|
|
717
|
+
* Checks whether a file is a Windows PE executable.
|
|
519
718
|
*
|
|
520
719
|
* @param path - Path to the file
|
|
521
|
-
* @returns True
|
|
720
|
+
* @returns True if the file has a valid PE signature; false otherwise
|
|
522
721
|
*/
|
|
523
722
|
export declare function isPEExecutable(path: string): boolean;
|
|
524
723
|
|
|
525
724
|
/**
|
|
526
|
-
*
|
|
725
|
+
* Checks whether the current or named platform is supported for SEA builds.
|
|
527
726
|
*
|
|
528
727
|
* @param platform - Platform identifier to check
|
|
529
|
-
* @returns True
|
|
728
|
+
* @returns True if the platform has a known configuration; false otherwise
|
|
530
729
|
*/
|
|
531
730
|
export declare function isPlatformSupported(platform?: string): boolean;
|
|
532
731
|
|
|
533
732
|
/**
|
|
534
|
-
*
|
|
733
|
+
* Checks whether a number is a nonzero power of two.
|
|
535
734
|
*
|
|
536
735
|
* @param value - Number to check
|
|
537
|
-
* @returns True
|
|
736
|
+
* @returns True if the value is a positive power of two; false otherwise
|
|
538
737
|
*/
|
|
539
738
|
export declare function isPowerOfTwo(value: number): boolean;
|
|
540
739
|
|
|
541
740
|
/**
|
|
542
|
-
*
|
|
741
|
+
* Checks whether a value is a {@link SEAError}.
|
|
543
742
|
*
|
|
544
743
|
* @param value - The value to test
|
|
545
|
-
* @returns
|
|
744
|
+
* @returns True if `value` is a `SEAError`; false otherwise
|
|
546
745
|
*
|
|
547
746
|
* @example
|
|
548
747
|
* ```ts
|
|
@@ -554,10 +753,10 @@ export declare function isPowerOfTwo(value: number): boolean;
|
|
|
554
753
|
export declare function isSEAError(value: unknown): value is SEAError;
|
|
555
754
|
|
|
556
755
|
/**
|
|
557
|
-
*
|
|
756
|
+
* Checks whether a value is a {@link ShellError}.
|
|
558
757
|
*
|
|
559
758
|
* @param value - The value to test
|
|
560
|
-
* @returns
|
|
759
|
+
* @returns True if `value` is a `ShellError`; false otherwise
|
|
561
760
|
*
|
|
562
761
|
* @example
|
|
563
762
|
* ```ts
|
|
@@ -568,14 +767,14 @@ export declare function isSEAError(value: unknown): value is SEAError;
|
|
|
568
767
|
*/
|
|
569
768
|
export declare function isShellError(value: unknown): value is ShellError;
|
|
570
769
|
|
|
571
|
-
/** Mach-O LC_SEGMENT_64 load command */
|
|
770
|
+
/** Holds the Mach-O `LC_SEGMENT_64` load command, 0x19. */
|
|
572
771
|
export declare const MACHO_LC_SEGMENT_64 = 25;
|
|
573
772
|
|
|
574
|
-
/** Mach-O 64-bit magic
|
|
773
|
+
/** Holds the Mach-O 64-bit magic, 0xfeedfacf, in little-endian byte order. */
|
|
575
774
|
export declare const MACHO_MAGIC_64 = 4277009103;
|
|
576
775
|
|
|
577
776
|
/**
|
|
578
|
-
*
|
|
777
|
+
* Launches the system default browser at an http(s) URL.
|
|
579
778
|
*
|
|
580
779
|
* @remarks
|
|
581
780
|
* A best-effort launch for bundled local-UI apps: dispatches by
|
|
@@ -587,7 +786,7 @@ export declare const MACHO_MAGIC_64 = 4277009103;
|
|
|
587
786
|
* outlives the host app and never keeps it alive, and it swallows the async
|
|
588
787
|
* host fault an absent opener binary raises. Only `http:` and `https:` URLs
|
|
589
788
|
* are accepted — any other scheme (including a string that merely looks like a
|
|
590
|
-
* CLI flag,
|
|
789
|
+
* CLI flag, for example `'-e ...'`) fails to parse as an http(s) URL and is rejected
|
|
591
790
|
* before anything is spawned.
|
|
592
791
|
*
|
|
593
792
|
* @param url - Absolute http or https URL to open
|
|
@@ -602,15 +801,7 @@ export declare const MACHO_MAGIC_64 = 4277009103;
|
|
|
602
801
|
export declare function openBrowser(url: string): void;
|
|
603
802
|
|
|
604
803
|
/**
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
* @param fd - Open file descriptor
|
|
608
|
-
* @returns The offset to the PE signature
|
|
609
|
-
*/
|
|
610
|
-
export declare function parsePEOffset(fd: number): number;
|
|
611
|
-
|
|
612
|
-
/**
|
|
613
|
-
* Patch the PE subsystem field in a Windows executable.
|
|
804
|
+
* Patches the PE subsystem field in a Windows executable.
|
|
614
805
|
*
|
|
615
806
|
* @param path - Path to the executable
|
|
616
807
|
* @param subsystem - Numeric subsystem value (2 = GUI, 3 = Console)
|
|
@@ -618,76 +809,180 @@ export declare function parsePEOffset(fd: number): number;
|
|
|
618
809
|
export declare function patchPESubsystem(path: string, subsystem: number): void;
|
|
619
810
|
|
|
620
811
|
/**
|
|
621
|
-
*
|
|
812
|
+
* Patches the sentinel fuse in a binary from `:0` to `:1`.
|
|
622
813
|
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
814
|
+
* @remarks
|
|
815
|
+
* Searches the file in 64 MB chunks with overlap to handle any file size. The fuse
|
|
816
|
+
* signals to the Node.js runtime that a SEA blob is present. The `Injector` class
|
|
817
|
+
* normally applies this patch, and it stays available standalone for a build that
|
|
818
|
+
* injects the PE resource natively instead.
|
|
627
819
|
*
|
|
628
820
|
* @param executable - Absolute path to the executable
|
|
629
821
|
* @param fuse - Sentinel fuse string (without the `:0` suffix)
|
|
822
|
+
* @throws SEAError with code `'FUSE'` when the fuse value cannot be read
|
|
823
|
+
* @throws SEAError with code `'FUSE'` when the fuse carries a value other than `:0` or `:1`
|
|
824
|
+
* @throws SEAError with code `'FUSE'` when the fuse is not found in the executable
|
|
630
825
|
*/
|
|
631
826
|
export declare function patchSentinelFuse(executable: string, fuse: string): void;
|
|
632
827
|
|
|
633
|
-
/** PE32 optional header magic */
|
|
828
|
+
/** Holds the PE32 optional header magic, 0x10b. */
|
|
634
829
|
export declare const PE32_MAGIC = 267;
|
|
635
830
|
|
|
636
|
-
/** PE32+
|
|
831
|
+
/** Holds the PE32+ optional header magic, 0x20b, the 64-bit form. */
|
|
637
832
|
export declare const PE32_PLUS_MAGIC = 523;
|
|
638
833
|
|
|
639
|
-
/** DOS MZ header magic
|
|
834
|
+
/** Holds the DOS MZ header magic, 0x5a4d, the first two bytes of a PE file. */
|
|
640
835
|
export declare const PE_MAGIC = 23117;
|
|
641
836
|
|
|
642
|
-
/**
|
|
837
|
+
/** Holds the size of `IMAGE_RESOURCE_DATA_ENTRY` in bytes, 16. */
|
|
643
838
|
export declare const PE_RESOURCE_DATA_ENTRY_SIZE = 16;
|
|
644
839
|
|
|
645
|
-
/**
|
|
840
|
+
/** Holds the size of `IMAGE_RESOURCE_DIRECTORY` in bytes, 16. */
|
|
646
841
|
export declare const PE_RESOURCE_DIR_SIZE = 16;
|
|
647
842
|
|
|
648
|
-
/**
|
|
843
|
+
/** Holds the size of `IMAGE_RESOURCE_DIRECTORY_ENTRY` in bytes, 8. */
|
|
649
844
|
export declare const PE_RESOURCE_ENTRY_SIZE = 8;
|
|
650
845
|
|
|
651
|
-
/**
|
|
846
|
+
/**
|
|
847
|
+
* Holds the high bit mask marking a resource entry as named rather than
|
|
848
|
+
* integer-identified, 0x80000000.
|
|
849
|
+
*/
|
|
652
850
|
export declare const PE_RESOURCE_NAME_FLAG = 2147483648;
|
|
653
851
|
|
|
654
|
-
/**
|
|
852
|
+
/**
|
|
853
|
+
* Holds the high bit mask marking a resource directory entry offset as a
|
|
854
|
+
* subdirectory, 0x80000000.
|
|
855
|
+
*/
|
|
655
856
|
export declare const PE_RESOURCE_SUBDIR_FLAG = 2147483648;
|
|
656
857
|
|
|
657
|
-
/** PE resource type
|
|
858
|
+
/** Holds the PE resource type `RT_RCDATA` for raw data, 10. */
|
|
658
859
|
export declare const PE_RT_RCDATA = 10;
|
|
659
860
|
|
|
660
|
-
/**
|
|
861
|
+
/** Marks a section as containing initialized data, 0x00000040. */
|
|
661
862
|
export declare const PE_SCN_INITIALIZED_DATA = 64;
|
|
662
863
|
|
|
663
|
-
/**
|
|
864
|
+
/** Marks a section as readable, 0x40000000. */
|
|
664
865
|
export declare const PE_SCN_MEM_READ = 1073741824;
|
|
665
866
|
|
|
666
|
-
/** PE section header size in bytes */
|
|
867
|
+
/** Holds the PE section header size in bytes, 40. */
|
|
667
868
|
export declare const PE_SECTION_HEADER_SIZE = 40;
|
|
668
869
|
|
|
669
|
-
/** PE signature
|
|
870
|
+
/** Holds the PE signature, 0x00004550, the bytes `PE\0\0` read as a 32-bit value. */
|
|
670
871
|
export declare const PE_SIGNATURE = 17744;
|
|
671
872
|
|
|
672
873
|
/**
|
|
673
|
-
*
|
|
874
|
+
* Holds one language entry of a PE resource name directory.
|
|
674
875
|
*
|
|
675
|
-
* @
|
|
676
|
-
* @
|
|
876
|
+
* @remarks
|
|
877
|
+
* `leafIndex` addresses the {@link PEResourceLeaf} this entry's bytes come from,
|
|
878
|
+
* within the leaf list the injector gathered from the original executable. A
|
|
879
|
+
* `leafIndex` of `-1` marks the entry the injector is adding, whose bytes are
|
|
880
|
+
* streamed from the blob file rather than copied from an existing leaf.
|
|
881
|
+
*/
|
|
882
|
+
export declare interface PEResourceEntry {
|
|
883
|
+
readonly language: number;
|
|
884
|
+
readonly codePage: number;
|
|
885
|
+
readonly leafIndex: number;
|
|
886
|
+
readonly dataSize: number;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Holds one leaf of a PE resource directory tree.
|
|
891
|
+
*
|
|
892
|
+
* @remarks
|
|
893
|
+
* Flattens the path a resource takes through the three directory levels of the PE
|
|
894
|
+
* `IMAGE_RESOURCE_DIRECTORY` tree — type, name, language — onto the
|
|
895
|
+
* `IMAGE_RESOURCE_DATA_ENTRY` it ends at. A level identifies its entry either by
|
|
896
|
+
* integer id or by name, so `typeId` and `nameId` carry the integer form and
|
|
897
|
+
* `typeName` and `nameName` the named form, whichever the entry used. `dataRVA` and
|
|
898
|
+
* `dataSize` are the data entry's `OffsetToData` and `Size` fields.
|
|
899
|
+
*/
|
|
900
|
+
export declare interface PEResourceLeaf {
|
|
901
|
+
readonly typeId: number;
|
|
902
|
+
readonly typeName: string | undefined;
|
|
903
|
+
readonly nameId: number;
|
|
904
|
+
readonly nameName: string | undefined;
|
|
905
|
+
readonly language: number;
|
|
906
|
+
readonly codePage: number;
|
|
907
|
+
readonly dataRVA: number;
|
|
908
|
+
readonly dataSize: number;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* Holds one PE section table entry.
|
|
913
|
+
*
|
|
914
|
+
* @remarks
|
|
915
|
+
* Transliterates the PE `IMAGE_SECTION_HEADER` structure: `name` is `Name` with its
|
|
916
|
+
* NUL padding stripped, `virtualSize` is `Misc.VirtualSize`, `virtualAddress` is
|
|
917
|
+
* `VirtualAddress`, `rawSize` is `SizeOfRawData`, `rawOffset` is
|
|
918
|
+
* `PointerToRawData`, and `characteristics` is `Characteristics`. `headerOffset` is
|
|
919
|
+
* not a header field: it records the file offset the entry was read from, so a
|
|
920
|
+
* later write lands on the same bytes.
|
|
921
|
+
*/
|
|
922
|
+
export declare interface PESection {
|
|
923
|
+
readonly name: string;
|
|
924
|
+
readonly virtualSize: number;
|
|
925
|
+
readonly virtualAddress: number;
|
|
926
|
+
readonly rawSize: number;
|
|
927
|
+
readonly rawOffset: number;
|
|
928
|
+
readonly characteristics: number;
|
|
929
|
+
readonly headerOffset: number;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* Reads the PE header offset from a Windows executable.
|
|
934
|
+
*
|
|
935
|
+
* @param fd - Open file descriptor
|
|
936
|
+
* @returns The offset to the PE signature
|
|
937
|
+
* @throws SEAError with code `'FORMAT'` when fewer than four bytes are readable at `0x3c`
|
|
677
938
|
*/
|
|
678
|
-
export declare function
|
|
939
|
+
export declare function readPEOffset(fd: number): number;
|
|
679
940
|
|
|
680
941
|
/**
|
|
681
|
-
*
|
|
942
|
+
* Reads a 16-bit unsigned integer from a file descriptor.
|
|
682
943
|
*
|
|
683
944
|
* @param fd - Open file descriptor
|
|
684
945
|
* @param offset - Byte offset to read from
|
|
685
946
|
* @returns The 16-bit value
|
|
947
|
+
* @throws SEAError with code `'FORMAT'` when fewer than two bytes are readable at `offset`
|
|
686
948
|
*/
|
|
687
949
|
export declare function readU16(fd: number, offset: number): number;
|
|
688
950
|
|
|
689
951
|
/**
|
|
690
|
-
*
|
|
952
|
+
* Reads a 32-bit unsigned little-endian integer from a file descriptor.
|
|
953
|
+
*
|
|
954
|
+
* @param fd - Open file descriptor
|
|
955
|
+
* @param offset - Byte offset to read from
|
|
956
|
+
* @returns The 32-bit value
|
|
957
|
+
* @throws SEAError with code `'FORMAT'` when fewer than four bytes are readable at `offset`
|
|
958
|
+
*
|
|
959
|
+
* @example
|
|
960
|
+
* ```ts
|
|
961
|
+
* const fd = openSync('app.exe', 'r')
|
|
962
|
+
* readU32(fd, 0x3c) // the PE header offset
|
|
963
|
+
* ```
|
|
964
|
+
*/
|
|
965
|
+
export declare function readU32(fd: number, offset: number): number;
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* Reads a 64-bit unsigned little-endian integer from a file descriptor.
|
|
969
|
+
*
|
|
970
|
+
* @param fd - Open file descriptor
|
|
971
|
+
* @param offset - Byte offset to read from
|
|
972
|
+
* @returns The 64-bit value, as a `bigint`
|
|
973
|
+
* @throws SEAError with code `'FORMAT'` when fewer than eight bytes are readable at `offset`
|
|
974
|
+
*
|
|
975
|
+
* @example
|
|
976
|
+
* ```ts
|
|
977
|
+
* const fd = openSync('app', 'r')
|
|
978
|
+
* readU64(fd, 32) // the ELF program header table offset
|
|
979
|
+
* ```
|
|
980
|
+
*/
|
|
981
|
+
export declare function readU64(fd: number, offset: number): bigint;
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* Redacts password arguments from a shell command, so the command is safe to
|
|
985
|
+
* include in an error message.
|
|
691
986
|
*
|
|
692
987
|
* @param command - Command arguments to redact
|
|
693
988
|
* @returns A copy with values following password flags replaced by a marker
|
|
@@ -695,18 +990,37 @@ export declare function readU16(fd: number, offset: number): number;
|
|
|
695
990
|
export declare function redactCommand(command: readonly string[]): readonly string[];
|
|
696
991
|
|
|
697
992
|
/**
|
|
698
|
-
*
|
|
993
|
+
* Resolves the effective platform configuration.
|
|
699
994
|
*
|
|
700
|
-
* @param
|
|
701
|
-
* @
|
|
702
|
-
* @returns stdout as a Buffer
|
|
703
|
-
* @throws SEAError with code `'STATE'` when `command` is empty
|
|
704
|
-
* @throws SEAError with code `'ABORT'` when `options.signal` is already aborted
|
|
705
|
-
* @throws SEAError with code `'TIMEOUT'` when the command exceeds `options.timeout`
|
|
706
|
-
* @throws ShellError when the command exits with non-zero status
|
|
995
|
+
* @param platform - Platform identifier. Default: `process.platform`.
|
|
996
|
+
* @returns Platform configuration, or undefined if unsupported
|
|
707
997
|
*/
|
|
708
|
-
export declare function
|
|
998
|
+
export declare function resolvePlatform(platform?: string): SEAPlatform | undefined;
|
|
709
999
|
|
|
1000
|
+
/**
|
|
1001
|
+
* Runs a Node.js single executable application build to completion.
|
|
1002
|
+
*
|
|
1003
|
+
* @remarks
|
|
1004
|
+
* `execute` compresses the configured directories, generates the SEA blob, copies
|
|
1005
|
+
* the host Node binary, injects the blob with an {@link Injector}, signs the
|
|
1006
|
+
* result where the platform supports it, and moves the finished executable into
|
|
1007
|
+
* place atomically. Each stage reports on `emitter`, and every failure throws a
|
|
1008
|
+
* coded `SEAError` after an `error` event carrying it.
|
|
1009
|
+
*
|
|
1010
|
+
* @param options - SEA build options: the output name, the entry point, the output
|
|
1011
|
+
* directory, and the optional assets, compression, Windows, and blob settings
|
|
1012
|
+
*
|
|
1013
|
+
* @example
|
|
1014
|
+
* ```ts
|
|
1015
|
+
* const sea = new SEA({
|
|
1016
|
+
* name: 'myapp',
|
|
1017
|
+
* entry: { path: 'dist/server/serve.cjs' },
|
|
1018
|
+
* output: 'dist/sea',
|
|
1019
|
+
* })
|
|
1020
|
+
* const result = await sea.execute()
|
|
1021
|
+
* sea.destroy()
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
710
1024
|
export declare class SEA implements SEAInterface {
|
|
711
1025
|
#private;
|
|
712
1026
|
constructor(options: SEAOptions);
|
|
@@ -716,20 +1030,29 @@ export declare class SEA implements SEAInterface {
|
|
|
716
1030
|
destroy(): void;
|
|
717
1031
|
}
|
|
718
1032
|
|
|
719
|
-
/**
|
|
1033
|
+
/** Names the SEA blob resource in the executable, `NODE_SEA_BLOB`. */
|
|
720
1034
|
export declare const SEA_BLOB_RESOURCE = "NODE_SEA_BLOB";
|
|
721
1035
|
|
|
722
|
-
/**
|
|
1036
|
+
/**
|
|
1037
|
+
* Maps a {@link SEACompressionMode} to its numeric Brotli mode value: `generic`
|
|
1038
|
+
* to 0, `text` to 1, and `font` to 2.
|
|
1039
|
+
*/
|
|
723
1040
|
export declare const SEA_COMPRESSION_MODE_VALUES: Readonly<Record<SEACompressionMode, number>>;
|
|
724
1041
|
|
|
725
|
-
/**
|
|
1042
|
+
/**
|
|
1043
|
+
* Holds the platform-specific SEA build configurations, keyed by
|
|
1044
|
+
* `process.platform` for `win32`, `darwin`, and `linux`.
|
|
1045
|
+
*/
|
|
726
1046
|
export declare const SEA_PLATFORMS: Readonly<Record<string, SEAPlatform>>;
|
|
727
1047
|
|
|
728
|
-
/**
|
|
1048
|
+
/**
|
|
1049
|
+
* Holds the SEA sentinel fuse value embedded in the Node.js binary,
|
|
1050
|
+
* `NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2`.
|
|
1051
|
+
*/
|
|
729
1052
|
export declare const SEA_SENTINEL_FUSE = "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2";
|
|
730
1053
|
|
|
731
1054
|
/**
|
|
732
|
-
*
|
|
1055
|
+
* Controls generated SEA blob behavior.
|
|
733
1056
|
*
|
|
734
1057
|
* @remarks
|
|
735
1058
|
* `cache` — maps to the SEA config `useCodeCache`. Default: `true`.
|
|
@@ -741,7 +1064,24 @@ export declare interface SEABlobOptions {
|
|
|
741
1064
|
}
|
|
742
1065
|
|
|
743
1066
|
/**
|
|
744
|
-
*
|
|
1067
|
+
* Controls how Brotli encodes one file.
|
|
1068
|
+
*
|
|
1069
|
+
* @remarks
|
|
1070
|
+
* `mode` — Brotli mode. Default: `'generic'`.
|
|
1071
|
+
* `quality` — Brotli quality level (0–11). Default: 11.
|
|
1072
|
+
*/
|
|
1073
|
+
export declare interface SEABrotliOptions {
|
|
1074
|
+
readonly mode?: SEACompressionMode;
|
|
1075
|
+
readonly quality?: number;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* Describes the callback `compressDirectory` invokes after each file it compresses.
|
|
1080
|
+
*/
|
|
1081
|
+
export declare type SEACompressionHandler = (result: SEACompressionResult) => void;
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* Summarizes all compressed assets.
|
|
745
1085
|
*
|
|
746
1086
|
* @remarks
|
|
747
1087
|
* Generated after a full directory compression pass.
|
|
@@ -752,7 +1092,7 @@ export declare interface SEACompressionManifest {
|
|
|
752
1092
|
}
|
|
753
1093
|
|
|
754
1094
|
/**
|
|
755
|
-
* Brotli compression mode.
|
|
1095
|
+
* Names a Brotli compression mode.
|
|
756
1096
|
*
|
|
757
1097
|
* @remarks
|
|
758
1098
|
* `generic` — general-purpose data (Brotli mode 0).
|
|
@@ -762,21 +1102,17 @@ export declare interface SEACompressionManifest {
|
|
|
762
1102
|
export declare type SEACompressionMode = 'generic' | 'text' | 'font';
|
|
763
1103
|
|
|
764
1104
|
/**
|
|
765
|
-
*
|
|
1105
|
+
* Controls Brotli compression of one or more directories.
|
|
766
1106
|
*
|
|
767
1107
|
* @remarks
|
|
768
|
-
* `paths`
|
|
769
|
-
* `mode` — Brotli mode. Default: `'generic'`.
|
|
770
|
-
* `quality` — Brotli quality level (0–11). Default: 11.
|
|
1108
|
+
* `paths` — directories (relative to `SEAOptions.root`) to compress.
|
|
771
1109
|
*/
|
|
772
|
-
export declare interface SEACompressionOptions {
|
|
1110
|
+
export declare interface SEACompressionOptions extends SEABrotliOptions {
|
|
773
1111
|
readonly paths: readonly string[];
|
|
774
|
-
readonly mode?: SEACompressionMode;
|
|
775
|
-
readonly quality?: number;
|
|
776
1112
|
}
|
|
777
1113
|
|
|
778
1114
|
/**
|
|
779
|
-
*
|
|
1115
|
+
* Represents the result of compressing a single file.
|
|
780
1116
|
*
|
|
781
1117
|
* @remarks
|
|
782
1118
|
* `input` — absolute path to the original file.
|
|
@@ -790,7 +1126,7 @@ export declare interface SEACompressionResult {
|
|
|
790
1126
|
}
|
|
791
1127
|
|
|
792
1128
|
/**
|
|
793
|
-
*
|
|
1129
|
+
* Represents a size comparison between original and compressed data.
|
|
794
1130
|
*/
|
|
795
1131
|
export declare interface SEACompressionSize {
|
|
796
1132
|
readonly original: number;
|
|
@@ -799,7 +1135,7 @@ export declare interface SEACompressionSize {
|
|
|
799
1135
|
}
|
|
800
1136
|
|
|
801
1137
|
/**
|
|
802
|
-
* SEA entry point module format.
|
|
1138
|
+
* Names the SEA entry point module format.
|
|
803
1139
|
*
|
|
804
1140
|
* @remarks
|
|
805
1141
|
* `cjs` — CommonJS entry (Node default).
|
|
@@ -808,7 +1144,7 @@ export declare interface SEACompressionSize {
|
|
|
808
1144
|
export declare type SEAEntryFormat = 'cjs' | 'esm';
|
|
809
1145
|
|
|
810
1146
|
/**
|
|
811
|
-
*
|
|
1147
|
+
* Describes the SEA entry point.
|
|
812
1148
|
*
|
|
813
1149
|
* @remarks
|
|
814
1150
|
* `path` — path to the entry point to embed.
|
|
@@ -820,7 +1156,7 @@ export declare interface SEAEntryOptions {
|
|
|
820
1156
|
}
|
|
821
1157
|
|
|
822
1158
|
/**
|
|
823
|
-
*
|
|
1159
|
+
* Represents the coded base error for every failure raised by the SEA build.
|
|
824
1160
|
*
|
|
825
1161
|
* @remarks
|
|
826
1162
|
* Carries a machine-readable {@link SEAErrorCode} and optional `context`
|
|
@@ -829,7 +1165,7 @@ export declare interface SEAEntryOptions {
|
|
|
829
1165
|
* @example
|
|
830
1166
|
* ```ts
|
|
831
1167
|
* try {
|
|
832
|
-
*
|
|
1168
|
+
* sea.execute()
|
|
833
1169
|
* } catch (error) {
|
|
834
1170
|
* if (isSEAError(error)) {
|
|
835
1171
|
* console.error(error.code, error.context)
|
|
@@ -844,7 +1180,7 @@ export declare class SEAError extends Error {
|
|
|
844
1180
|
}
|
|
845
1181
|
|
|
846
1182
|
/**
|
|
847
|
-
*
|
|
1183
|
+
* Names the machine-readable error code carried by every {@link SEAError}.
|
|
848
1184
|
*
|
|
849
1185
|
* @remarks
|
|
850
1186
|
* `PLATFORM` — unsupported or misdetected platform.
|
|
@@ -853,18 +1189,20 @@ export declare class SEAError extends Error {
|
|
|
853
1189
|
* `BLOB` — SEA blob generation failure.
|
|
854
1190
|
* `FORMAT` — unrecognized executable binary format.
|
|
855
1191
|
* `INJECT` — resource injection failure.
|
|
1192
|
+
* `ROOM` — host binary layout the injector cannot write into: no room for a new
|
|
1193
|
+
* section entry or load command, or a `__LINKEDIT` layout it does not support.
|
|
856
1194
|
* `FUSE` — sentinel fuse patch failure.
|
|
857
1195
|
* `SIGN` — code signing failure.
|
|
858
1196
|
* `SHELL` — shell command exited non-zero.
|
|
859
1197
|
* `TIMEOUT` — shell command exceeded its timeout.
|
|
860
|
-
* `ABORT` — operation aborted
|
|
1198
|
+
* `ABORT` — operation aborted through `AbortSignal`.
|
|
861
1199
|
* `OUTPUT` — final executable write/finalize failure.
|
|
862
1200
|
* `STATE` — invalid internal state or argument.
|
|
863
1201
|
* `BROWSER` — invalid or unsupported URL passed to `openBrowser`.
|
|
864
1202
|
*/
|
|
865
|
-
export declare type SEAErrorCode = 'PLATFORM' | 'ENTRY' | 'ASSET' | 'BLOB' | 'FORMAT' | 'INJECT' | 'FUSE' | 'SIGN' | 'SHELL' | 'TIMEOUT' | 'ABORT' | 'OUTPUT' | 'STATE' | 'BROWSER';
|
|
1203
|
+
export declare type SEAErrorCode = 'PLATFORM' | 'ENTRY' | 'ASSET' | 'BLOB' | 'FORMAT' | 'INJECT' | 'ROOM' | 'FUSE' | 'SIGN' | 'SHELL' | 'TIMEOUT' | 'ABORT' | 'OUTPUT' | 'STATE' | 'BROWSER';
|
|
866
1204
|
|
|
867
|
-
/**
|
|
1205
|
+
/** Lists the events emitted by a {@link SEAInterface}. */
|
|
868
1206
|
export declare type SEAEventMap = {
|
|
869
1207
|
readonly compress: readonly [compression: SEACompressionManifest | undefined];
|
|
870
1208
|
readonly progress: readonly [progress: SEAProgress];
|
|
@@ -875,21 +1213,29 @@ export declare type SEAEventMap = {
|
|
|
875
1213
|
};
|
|
876
1214
|
|
|
877
1215
|
/**
|
|
878
|
-
* SEA build orchestrator.
|
|
1216
|
+
* Represents a SEA build orchestrator.
|
|
879
1217
|
*
|
|
880
1218
|
* @remarks
|
|
881
1219
|
* Compresses assets, generates the SEA blob, copies the Node binary,
|
|
882
|
-
* injects the blob
|
|
1220
|
+
* injects the blob through the built-in Injector, and handles platform-specific signing.
|
|
883
1221
|
*/
|
|
884
1222
|
export declare interface SEAInterface {
|
|
1223
|
+
/** Holds the emitter reporting each build stage as it completes. */
|
|
885
1224
|
readonly emitter: EmitterInterface<SEAEventMap>;
|
|
1225
|
+
/** Holds the phase the build has reached. */
|
|
886
1226
|
readonly status: SEAStatus;
|
|
1227
|
+
/**
|
|
1228
|
+
* Runs the compress, blob, and assemble stages and returns the build result.
|
|
1229
|
+
*
|
|
1230
|
+
* @throws SEAError with the `SEAErrorCode` of the stage that failed, after `status` becomes `'error'`
|
|
1231
|
+
*/
|
|
887
1232
|
execute(): Promise<SEAResult>;
|
|
1233
|
+
/** Tears down the emitter. */
|
|
888
1234
|
destroy(): void;
|
|
889
1235
|
}
|
|
890
1236
|
|
|
891
1237
|
/**
|
|
892
|
-
*
|
|
1238
|
+
* Configures the creation of a SEA build.
|
|
893
1239
|
*
|
|
894
1240
|
* @remarks
|
|
895
1241
|
* `name` — output executable name (no extension).
|
|
@@ -921,7 +1267,7 @@ export declare interface SEAOptions {
|
|
|
921
1267
|
}
|
|
922
1268
|
|
|
923
1269
|
/**
|
|
924
|
-
*
|
|
1270
|
+
* Represents a platform-specific SEA build configuration.
|
|
925
1271
|
*
|
|
926
1272
|
* @remarks
|
|
927
1273
|
* Describes the native Node binary and code signing commands.
|
|
@@ -934,10 +1280,10 @@ export declare interface SEAPlatform {
|
|
|
934
1280
|
}
|
|
935
1281
|
|
|
936
1282
|
/**
|
|
937
|
-
*
|
|
1283
|
+
* Represents the progress reported while compressing a directory.
|
|
938
1284
|
*
|
|
939
1285
|
* @remarks
|
|
940
|
-
* `path` — absolute path to the file
|
|
1286
|
+
* `path` — absolute path to the file compressed most recently.
|
|
941
1287
|
* `current` — number of files compressed so far (1-based).
|
|
942
1288
|
* `total` — total number of compressible files.
|
|
943
1289
|
*/
|
|
@@ -948,16 +1294,11 @@ export declare interface SEAProgress {
|
|
|
948
1294
|
}
|
|
949
1295
|
|
|
950
1296
|
/**
|
|
951
|
-
*
|
|
952
|
-
*/
|
|
953
|
-
export declare type SEAProgressHandler = (result: SEACompressionResult) => void;
|
|
954
|
-
|
|
955
|
-
/**
|
|
956
|
-
* Result of a successful seal build.
|
|
1297
|
+
* Represents the result of a successful SEA build.
|
|
957
1298
|
*
|
|
958
1299
|
* @remarks
|
|
959
1300
|
* `executable` — absolute path to the output binary.
|
|
960
|
-
* `platform` — platform identifier (
|
|
1301
|
+
* `platform` — platform identifier (for example `"win32"`, `"darwin"`).
|
|
961
1302
|
* `size` — file size of the executable in bytes.
|
|
962
1303
|
* `duration` — build time in milliseconds.
|
|
963
1304
|
* `compression` — compression manifest when directories were compressed.
|
|
@@ -978,7 +1319,7 @@ export declare interface SEAResult {
|
|
|
978
1319
|
}
|
|
979
1320
|
|
|
980
1321
|
/**
|
|
981
|
-
*
|
|
1322
|
+
* Configures the execution of a shell command.
|
|
982
1323
|
*
|
|
983
1324
|
* @remarks
|
|
984
1325
|
* `cwd` — working directory. Default: `process.cwd()`.
|
|
@@ -992,12 +1333,12 @@ export declare interface SEAShellOptions {
|
|
|
992
1333
|
}
|
|
993
1334
|
|
|
994
1335
|
/**
|
|
995
|
-
*
|
|
1336
|
+
* Names the overall status of the SEA build.
|
|
996
1337
|
*/
|
|
997
1338
|
export declare type SEAStatus = 'idle' | 'active' | 'done' | 'error';
|
|
998
1339
|
|
|
999
1340
|
/**
|
|
1000
|
-
* Windows-specific SEA build
|
|
1341
|
+
* Configures Windows-specific SEA build behavior.
|
|
1001
1342
|
*
|
|
1002
1343
|
* @remarks
|
|
1003
1344
|
* `terminal` — whether the built executable keeps a console window (PE
|
|
@@ -1007,11 +1348,11 @@ export declare type SEAStatus = 'idle' | 'active' | 'done' | 'error';
|
|
|
1007
1348
|
* valid stdio, so `process.stdout`/`stderr`/`stdin` are detached and console
|
|
1008
1349
|
* output is discarded; use only for windowless apps.
|
|
1009
1350
|
* `sign` — Authenticode signing options. When present, the assembled
|
|
1010
|
-
* executable is signed with `signtool` (and verified) as the
|
|
1351
|
+
* executable is signed with `signtool` (and verified) as the last content
|
|
1011
1352
|
* mutation before the atomic finalize; when absent, the output is unsigned
|
|
1012
|
-
* and `SEAResult.signed` is `false
|
|
1353
|
+
* and `SEAResult.signed` is `false`.
|
|
1013
1354
|
*
|
|
1014
|
-
* These options apply only when the build
|
|
1355
|
+
* These options apply only when the build host is Windows — there is no
|
|
1015
1356
|
* cross-compilation, so building on a non-Windows host ignores `windows.*`.
|
|
1016
1357
|
*/
|
|
1017
1358
|
export declare interface SEAWindowsOptions {
|
|
@@ -1020,11 +1361,11 @@ export declare interface SEAWindowsOptions {
|
|
|
1020
1361
|
}
|
|
1021
1362
|
|
|
1022
1363
|
/**
|
|
1023
|
-
* Windows Authenticode signing options
|
|
1364
|
+
* Describes the Windows Authenticode signing options passed through to `signtool`.
|
|
1024
1365
|
*
|
|
1025
1366
|
* @remarks
|
|
1026
1367
|
* `file` — path to a `.pfx`/`.p12` certificate file (`signtool /f`).
|
|
1027
|
-
* `password` — certificate password (`signtool /p`).
|
|
1368
|
+
* `password` — certificate password (`signtool /p`). Sensitive: never
|
|
1028
1369
|
* logged and never included in a thrown error's message or `context`.
|
|
1029
1370
|
* `thumbprint` — SHA1 thumbprint of a certificate already installed in the
|
|
1030
1371
|
* Windows certificate store (`signtool /sha1`).
|
|
@@ -1032,7 +1373,7 @@ export declare interface SEAWindowsOptions {
|
|
|
1032
1373
|
* `/td <digest>`).
|
|
1033
1374
|
* `digest` — file digest algorithm (`signtool /fd`). Default: `'sha256'`.
|
|
1034
1375
|
*
|
|
1035
|
-
* Exactly
|
|
1376
|
+
* Exactly one of `file` or `thumbprint` must be supplied — they identify two
|
|
1036
1377
|
* different certificate sources and are mutually exclusive. `password`
|
|
1037
1378
|
* pairs with `file` (a store-resident certificate referenced by
|
|
1038
1379
|
* `thumbprint` has no associated password to supply here).
|
|
@@ -1046,7 +1387,7 @@ export declare interface SEAWindowsSignOptions {
|
|
|
1046
1387
|
}
|
|
1047
1388
|
|
|
1048
1389
|
/**
|
|
1049
|
-
*
|
|
1390
|
+
* Represents an error thrown when a shell command executed through `executeShell` exits non-zero.
|
|
1050
1391
|
*
|
|
1051
1392
|
* @remarks
|
|
1052
1393
|
* Carries the captured `stdout` and `stderr` buffers from the failed process.
|
|
@@ -1056,7 +1397,7 @@ export declare interface SEAWindowsSignOptions {
|
|
|
1056
1397
|
* @example
|
|
1057
1398
|
* ```ts
|
|
1058
1399
|
* try {
|
|
1059
|
-
*
|
|
1400
|
+
* executeShell(['codesign', '--sign', '-', path])
|
|
1060
1401
|
* } catch (error) {
|
|
1061
1402
|
* if (isShellError(error)) {
|
|
1062
1403
|
* console.error(error.stderr.toString())
|
|
@@ -1070,38 +1411,59 @@ export declare class ShellError extends SEAError {
|
|
|
1070
1411
|
constructor(message: string, stdout: Buffer, stderr: Buffer);
|
|
1071
1412
|
}
|
|
1072
1413
|
|
|
1073
|
-
/**
|
|
1074
|
-
|
|
1414
|
+
/**
|
|
1415
|
+
* Lists the file extensions Brotli compression skips, the already-compressed
|
|
1416
|
+
* archive, image, font, and media formats.
|
|
1417
|
+
*/
|
|
1418
|
+
export declare const SKIP_EXTENSIONS: ReadonlySet<string>;
|
|
1075
1419
|
|
|
1076
1420
|
/**
|
|
1077
|
-
*
|
|
1421
|
+
* Removes the Authenticode signature from a PE executable by zeroing
|
|
1078
1422
|
* the security directory entry in the optional header.
|
|
1079
1423
|
*
|
|
1080
1424
|
* @remarks
|
|
1081
1425
|
* If the certificate overlay described by the security directory sits at the
|
|
1082
1426
|
* very end of the file (the common case for `signtool`-signed binaries), the
|
|
1083
|
-
* file is truncated to the certificate's start
|
|
1427
|
+
* file is truncated to the certificate's start first so the overlay bytes are
|
|
1084
1428
|
* discarded rather than left as dead weight for a downstream injector to
|
|
1085
1429
|
* bury mid-file. The directory read is bounds-checked so a malformed or
|
|
1086
|
-
* truncated security directory cannot throw unexpectedly — it is
|
|
1087
|
-
*
|
|
1430
|
+
* truncated security directory cannot throw unexpectedly — it is skipped
|
|
1431
|
+
* and only the directory entry is zeroed.
|
|
1088
1432
|
*
|
|
1089
1433
|
* @param path - Path to the executable
|
|
1090
1434
|
*/
|
|
1091
1435
|
export declare function stripPESignature(path: string): void;
|
|
1092
1436
|
|
|
1093
1437
|
/**
|
|
1094
|
-
*
|
|
1438
|
+
* Truncates a NUL-padded binary name field at its first NUL character.
|
|
1439
|
+
*
|
|
1440
|
+
* @remarks
|
|
1441
|
+
* Binary name fields (PE section names, Mach-O segment and section names, ELF
|
|
1442
|
+
* note names) are fixed-width and NUL-padded, so the decoded string carries
|
|
1443
|
+
* trailing NUL characters that no comparison against a literal name matches.
|
|
1444
|
+
*
|
|
1445
|
+
* @param value - Decoded fixed-width name field
|
|
1446
|
+
* @returns The value up to, but excluding, its first NUL character
|
|
1447
|
+
*
|
|
1448
|
+
* @example
|
|
1449
|
+
* ```ts
|
|
1450
|
+
* stripTrailingNulls('.rsrc\0\0\0') // '.rsrc'
|
|
1451
|
+
* ```
|
|
1452
|
+
*/
|
|
1453
|
+
export declare function stripTrailingNulls(value: string): string;
|
|
1454
|
+
|
|
1455
|
+
/**
|
|
1456
|
+
* Fsyncs a directory to durably persist a prior file rename/create within it.
|
|
1095
1457
|
*
|
|
1096
1458
|
* @remarks
|
|
1097
|
-
* A `rename`/`create` is only durable once its
|
|
1459
|
+
* A `rename`/`create` is only durable once its containing directory entry is
|
|
1098
1460
|
* flushed — fsyncing the file itself is not enough. `path` is the directory
|
|
1099
1461
|
* to fsync (callers pass `dirname(target)`, not the file itself). On Windows
|
|
1100
1462
|
* there is no directory file handle to fsync, so this is a no-op there (the
|
|
1101
1463
|
* platform lacks the primitive, not a failure). Some filesystems/platforms
|
|
1102
1464
|
* return a benign errno for a directory fsync attempt (`EINVAL`, `ENOTSUP`,
|
|
1103
1465
|
* `EISDIR`, `EPERM`, `EACCES`) — those are treated as "fsync unsupported
|
|
1104
|
-
* here" and swallowed; anything else (
|
|
1466
|
+
* here" and swallowed; anything else (for example `ENOENT`, meaning the directory
|
|
1105
1467
|
* itself is missing) is a genuine failure and is thrown as a coded `SEAError`.
|
|
1106
1468
|
*
|
|
1107
1469
|
* @param path - Directory path to fsync
|
|
@@ -1116,7 +1478,8 @@ export declare function stripPESignature(path: string): void;
|
|
|
1116
1478
|
export declare function syncDirectory(path: string): void;
|
|
1117
1479
|
|
|
1118
1480
|
/**
|
|
1119
|
-
*
|
|
1481
|
+
* Walks a directory recursively and returns every file path it finds, relative to
|
|
1482
|
+
* the base and skipping symlinks.
|
|
1120
1483
|
*
|
|
1121
1484
|
* @param directory - Directory to walk
|
|
1122
1485
|
* @param base - Base directory for relative path calculation
|
|
@@ -1124,14 +1487,17 @@ export declare function syncDirectory(path: string): void;
|
|
|
1124
1487
|
*/
|
|
1125
1488
|
export declare function walkDirectory(directory: string, base?: string): readonly string[];
|
|
1126
1489
|
|
|
1127
|
-
/** Windows PE subsystem value
|
|
1490
|
+
/** Holds the Windows PE subsystem value for a console application, 3. */
|
|
1128
1491
|
export declare const WINDOWS_SUBSYSTEM_CONSOLE = 3;
|
|
1129
1492
|
|
|
1130
|
-
/**
|
|
1493
|
+
/**
|
|
1494
|
+
* Holds the Windows PE subsystem value for a GUI application, 2, which launches
|
|
1495
|
+
* without a terminal window.
|
|
1496
|
+
*/
|
|
1131
1497
|
export declare const WINDOWS_SUBSYSTEM_GUI = 2;
|
|
1132
1498
|
|
|
1133
1499
|
/**
|
|
1134
|
-
*
|
|
1500
|
+
* Writes a 16-bit unsigned integer to a file descriptor.
|
|
1135
1501
|
*
|
|
1136
1502
|
* @param fd - Open file descriptor
|
|
1137
1503
|
* @param offset - Byte offset to write at
|
|
@@ -1139,4 +1505,38 @@ export declare const WINDOWS_SUBSYSTEM_GUI = 2;
|
|
|
1139
1505
|
*/
|
|
1140
1506
|
export declare function writeU16(fd: number, offset: number, value: number): void;
|
|
1141
1507
|
|
|
1508
|
+
/**
|
|
1509
|
+
* Writes a 32-bit unsigned little-endian integer to a file descriptor.
|
|
1510
|
+
*
|
|
1511
|
+
* @remarks
|
|
1512
|
+
* Coerces `value` with `>>> 0` before writing, so a negative or out-of-range
|
|
1513
|
+
* number lands as its unsigned 32-bit representation rather than throwing.
|
|
1514
|
+
*
|
|
1515
|
+
* @param fd - Open file descriptor
|
|
1516
|
+
* @param offset - Byte offset to write at
|
|
1517
|
+
* @param value - The 32-bit value to write
|
|
1518
|
+
*
|
|
1519
|
+
* @example
|
|
1520
|
+
* ```ts
|
|
1521
|
+
* const fd = openSync('app.exe', 'r+')
|
|
1522
|
+
* writeU32(fd, 0x3c, 0x100)
|
|
1523
|
+
* ```
|
|
1524
|
+
*/
|
|
1525
|
+
export declare function writeU32(fd: number, offset: number, value: number): void;
|
|
1526
|
+
|
|
1527
|
+
/**
|
|
1528
|
+
* Writes a 64-bit unsigned little-endian integer to a file descriptor.
|
|
1529
|
+
*
|
|
1530
|
+
* @param fd - Open file descriptor
|
|
1531
|
+
* @param offset - Byte offset to write at
|
|
1532
|
+
* @param value - The 64-bit value to write
|
|
1533
|
+
*
|
|
1534
|
+
* @example
|
|
1535
|
+
* ```ts
|
|
1536
|
+
* const fd = openSync('app', 'r+')
|
|
1537
|
+
* writeU64(fd, 32, 8192n)
|
|
1538
|
+
* ```
|
|
1539
|
+
*/
|
|
1540
|
+
export declare function writeU64(fd: number, offset: number, value: bigint): void;
|
|
1541
|
+
|
|
1142
1542
|
export { }
|