@orkestrel/sea 0.0.7 → 0.0.9
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.
|
@@ -581,13 +581,14 @@ export declare const MACHO_MAGIC_64 = 4277009103;
|
|
|
581
581
|
* A best-effort launch for bundled local-UI apps: dispatches by
|
|
582
582
|
* `process.platform` (`win32` -> `rundll32 url.dll,FileProtocolHandler`,
|
|
583
583
|
* `darwin` -> `open`, else -> `xdg-open`), each invoked with an argv array
|
|
584
|
-
* (never a shell) so the URL cannot be
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
584
|
+
* through `@orkestrel/process`'s `detach` (never a shell) so the URL cannot be
|
|
585
|
+
* interpreted as a flag or injected into a command line. `detach` spawns the
|
|
586
|
+
* child detached, with its stdio discarded and unreferenced, so the opener
|
|
587
|
+
* outlives the host app and never keeps it alive, and it swallows the async
|
|
588
|
+
* host fault an absent opener binary raises. Only `http:` and `https:` URLs
|
|
589
|
+
* are accepted — any other scheme (including a string that merely looks like a
|
|
590
|
+
* CLI flag, e.g. `'-e ...'`) fails to parse as an http(s) URL and is rejected
|
|
591
|
+
* before anything is spawned.
|
|
591
592
|
*
|
|
592
593
|
* @param url - Absolute http or https URL to open
|
|
593
594
|
* @throws SEAError with code `'BROWSER'` when `url` is not a parseable absolute URL
|
|
@@ -894,7 +895,9 @@ export declare interface SEAInterface {
|
|
|
894
895
|
* `name` — output executable name (no extension).
|
|
895
896
|
* `entry` — the entry point to embed (path and module format).
|
|
896
897
|
* `output` — directory for the final executable.
|
|
897
|
-
* `assets` — key→path mapping for SEA embedded assets.
|
|
898
|
+
* `assets` — key→path mapping for SEA embedded assets. When compression
|
|
899
|
+
* writes a mapped path's Brotli output, the blob embeds that output under the
|
|
900
|
+
* original key without mutating this record. Other entries keep their paths.
|
|
898
901
|
* `compression` — directories to Brotli-compress before embedding.
|
|
899
902
|
* `windows` — Windows-specific build options (console/GUI terminal).
|
|
900
903
|
* `root` — project root directory. Default: `process.cwd()`.
|
|
@@ -581,13 +581,14 @@ export declare const MACHO_MAGIC_64 = 4277009103;
|
|
|
581
581
|
* A best-effort launch for bundled local-UI apps: dispatches by
|
|
582
582
|
* `process.platform` (`win32` -> `rundll32 url.dll,FileProtocolHandler`,
|
|
583
583
|
* `darwin` -> `open`, else -> `xdg-open`), each invoked with an argv array
|
|
584
|
-
* (never a shell) so the URL cannot be
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
584
|
+
* through `@orkestrel/process`'s `detach` (never a shell) so the URL cannot be
|
|
585
|
+
* interpreted as a flag or injected into a command line. `detach` spawns the
|
|
586
|
+
* child detached, with its stdio discarded and unreferenced, so the opener
|
|
587
|
+
* outlives the host app and never keeps it alive, and it swallows the async
|
|
588
|
+
* host fault an absent opener binary raises. Only `http:` and `https:` URLs
|
|
589
|
+
* are accepted — any other scheme (including a string that merely looks like a
|
|
590
|
+
* CLI flag, e.g. `'-e ...'`) fails to parse as an http(s) URL and is rejected
|
|
591
|
+
* before anything is spawned.
|
|
591
592
|
*
|
|
592
593
|
* @param url - Absolute http or https URL to open
|
|
593
594
|
* @throws SEAError with code `'BROWSER'` when `url` is not a parseable absolute URL
|
|
@@ -894,7 +895,9 @@ export declare interface SEAInterface {
|
|
|
894
895
|
* `name` — output executable name (no extension).
|
|
895
896
|
* `entry` — the entry point to embed (path and module format).
|
|
896
897
|
* `output` — directory for the final executable.
|
|
897
|
-
* `assets` — key→path mapping for SEA embedded assets.
|
|
898
|
+
* `assets` — key→path mapping for SEA embedded assets. When compression
|
|
899
|
+
* writes a mapped path's Brotli output, the blob embeds that output under the
|
|
900
|
+
* original key without mutating this record. Other entries keep their paths.
|
|
898
901
|
* `compression` — directories to Brotli-compress before embedding.
|
|
899
902
|
* `windows` — Windows-specific build options (console/GUI terminal).
|
|
900
903
|
* `root` — project root directory. Default: `process.cwd()`.
|
package/dist/src/server/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appendFileSync, chmodSync, closeSync, copyFileSync, existsSync, fstatSync, fsyncSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
2
2
|
import { brotliCompressSync, constants } from "node:zlib";
|
|
3
3
|
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { detach, runSync } from "@orkestrel/process/server";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
6
|
import { Emitter } from "@orkestrel/emitter";
|
|
7
7
|
import { getAssetKeys, getRawAsset, isSea } from "node:sea";
|
|
@@ -312,33 +312,21 @@ function runShell(command, options) {
|
|
|
312
312
|
const [cmd, ...args] = command;
|
|
313
313
|
if (cmd === void 0) throw new SEAError("STATE", "Command array must not be empty");
|
|
314
314
|
if (options?.signal?.aborted === true) throw new SEAError("ABORT", "Shell command aborted", { command: redactCommand(command) });
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
});
|
|
331
|
-
} catch (thrown) {
|
|
332
|
-
if (!(thrown instanceof Error)) throw thrown;
|
|
333
|
-
const redacted = redactCommand(command);
|
|
334
|
-
if (("code" in thrown && typeof thrown.code === "string" ? thrown.code : void 0) === "ETIMEDOUT") throw new SEAError("TIMEOUT", "Shell command timed out", {
|
|
335
|
-
command: redacted,
|
|
336
|
-
timeout: options?.timeout
|
|
337
|
-
});
|
|
338
|
-
const stdout = "stdout" in thrown && Buffer.isBuffer(thrown.stdout) ? thrown.stdout : Buffer.alloc(0);
|
|
339
|
-
const stderr = "stderr" in thrown && Buffer.isBuffer(thrown.stderr) ? thrown.stderr : Buffer.alloc(0);
|
|
340
|
-
throw new ShellError("Command failed: " + redacted.join(" "), stdout, stderr);
|
|
341
|
-
}
|
|
315
|
+
const result = runSync({
|
|
316
|
+
file: cmd,
|
|
317
|
+
arguments: args,
|
|
318
|
+
...options?.env !== void 0 ? { environment: options.env } : {}
|
|
319
|
+
}, {
|
|
320
|
+
...options?.cwd !== void 0 ? { workspace: options.cwd } : {},
|
|
321
|
+
...options?.timeout !== void 0 ? { timeout: options.timeout } : {},
|
|
322
|
+
strict: false
|
|
323
|
+
});
|
|
324
|
+
if (result.expired) throw new SEAError("TIMEOUT", "Shell command timed out", {
|
|
325
|
+
command: redactCommand(command),
|
|
326
|
+
timeout: options?.timeout
|
|
327
|
+
});
|
|
328
|
+
if (result.failed) throw new ShellError("Command failed: " + redactCommand(command).join(" "), Buffer.from(result.stdout, "utf-8"), Buffer.from(result.stderr, "utf-8"));
|
|
329
|
+
return Buffer.from(result.stdout, "utf-8");
|
|
342
330
|
}
|
|
343
331
|
/**
|
|
344
332
|
* Compute a size comparison between original and compressed byte counts.
|
|
@@ -968,13 +956,14 @@ function patchSentinelFuse(executable, fuse) {
|
|
|
968
956
|
* A best-effort launch for bundled local-UI apps: dispatches by
|
|
969
957
|
* `process.platform` (`win32` -> `rundll32 url.dll,FileProtocolHandler`,
|
|
970
958
|
* `darwin` -> `open`, else -> `xdg-open`), each invoked with an argv array
|
|
971
|
-
* (never a shell) so the URL cannot be
|
|
972
|
-
*
|
|
973
|
-
*
|
|
974
|
-
*
|
|
975
|
-
*
|
|
976
|
-
*
|
|
977
|
-
*
|
|
959
|
+
* through `@orkestrel/process`'s `detach` (never a shell) so the URL cannot be
|
|
960
|
+
* interpreted as a flag or injected into a command line. `detach` spawns the
|
|
961
|
+
* child detached, with its stdio discarded and unreferenced, so the opener
|
|
962
|
+
* outlives the host app and never keeps it alive, and it swallows the async
|
|
963
|
+
* host fault an absent opener binary raises. Only `http:` and `https:` URLs
|
|
964
|
+
* are accepted — any other scheme (including a string that merely looks like a
|
|
965
|
+
* CLI flag, e.g. `'-e ...'`) fails to parse as an http(s) URL and is rejected
|
|
966
|
+
* before anything is spawned.
|
|
978
967
|
*
|
|
979
968
|
* @param url - Absolute http or https URL to open
|
|
980
969
|
* @throws SEAError with code `'BROWSER'` when `url` is not a parseable absolute URL
|
|
@@ -996,18 +985,17 @@ function openBrowser(url) {
|
|
|
996
985
|
url,
|
|
997
986
|
protocol: parsed.protocol
|
|
998
987
|
});
|
|
999
|
-
const
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
child.unref();
|
|
988
|
+
const command = process.platform === "win32" ? {
|
|
989
|
+
file: "rundll32",
|
|
990
|
+
arguments: ["url.dll,FileProtocolHandler", parsed.href]
|
|
991
|
+
} : process.platform === "darwin" ? {
|
|
992
|
+
file: "open",
|
|
993
|
+
arguments: [parsed.href]
|
|
994
|
+
} : {
|
|
995
|
+
file: "xdg-open",
|
|
996
|
+
arguments: [parsed.href]
|
|
997
|
+
};
|
|
998
|
+
detach(command);
|
|
1011
999
|
}
|
|
1012
1000
|
//#endregion
|
|
1013
1001
|
//#region src/server/injectors/Injector.ts
|
|
@@ -2040,7 +2028,7 @@ var SEA = class {
|
|
|
2040
2028
|
this.#check();
|
|
2041
2029
|
const compression = this.#compress(root);
|
|
2042
2030
|
this.#check();
|
|
2043
|
-
const blob = this.#blob(root);
|
|
2031
|
+
const blob = this.#blob(root, compression);
|
|
2044
2032
|
this.#check();
|
|
2045
2033
|
const assembled = this.#assemble(root, blob);
|
|
2046
2034
|
const size = statSync(assembled.executable).size;
|
|
@@ -2135,7 +2123,7 @@ var SEA = class {
|
|
|
2135
2123
|
this.#emitter.emit("compress", manifest);
|
|
2136
2124
|
return manifest;
|
|
2137
2125
|
}
|
|
2138
|
-
#blob(root) {
|
|
2126
|
+
#blob(root, compression) {
|
|
2139
2127
|
const entry = resolve(root, this.#options.entry.path);
|
|
2140
2128
|
ensureExists(entry, `Entry not found: ${this.#options.entry.path}`, "ENTRY");
|
|
2141
2129
|
const output = resolve(root, this.#options.output);
|
|
@@ -2145,7 +2133,7 @@ var SEA = class {
|
|
|
2145
2133
|
const config = createBlobConfig({
|
|
2146
2134
|
path: entry,
|
|
2147
2135
|
...this.#options.entry.format === void 0 ? {} : { format: this.#options.entry.format }
|
|
2148
|
-
}, blob, this.#assets(root), this.#options.blob);
|
|
2136
|
+
}, blob, this.#assets(root, compression), this.#options.blob);
|
|
2149
2137
|
writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
2150
2138
|
runShell([
|
|
2151
2139
|
process.execPath,
|
|
@@ -2273,9 +2261,14 @@ var SEA = class {
|
|
|
2273
2261
|
...terminal === void 0 ? {} : { terminal }
|
|
2274
2262
|
};
|
|
2275
2263
|
}
|
|
2276
|
-
#assets(root) {
|
|
2264
|
+
#assets(root, compression) {
|
|
2265
|
+
const outputs = /* @__PURE__ */ new Map();
|
|
2266
|
+
for (const result of compression?.assets ?? []) outputs.set(result.input, result.output);
|
|
2277
2267
|
const assets = {};
|
|
2278
|
-
for (const [name, path] of Object.entries(this.#options.assets ?? {}))
|
|
2268
|
+
for (const [name, path] of Object.entries(this.#options.assets ?? {})) {
|
|
2269
|
+
const input = ensureContained(root, path);
|
|
2270
|
+
assets[name] = outputs.get(input) ?? input;
|
|
2271
|
+
}
|
|
2279
2272
|
return assets;
|
|
2280
2273
|
}
|
|
2281
2274
|
};
|