@orkestrel/sea 0.0.8 → 0.0.10

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 interpreted as a flag or injected
585
- * into a command line. The child process is spawned `detached` with
586
- * `stdio: 'ignore'` and immediately `unref()`d so it never keeps the host
587
- * app alive. Only `http:` and `https:` URLs are accepted — any other
588
- * scheme (including a string that merely looks like a CLI flag, e.g.
589
- * `'-e ...'`) fails to parse as an http(s) URL and is rejected before
590
- * anything is spawned.
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
@@ -901,6 +902,7 @@ export declare interface SEAInterface {
901
902
  * `windows` — Windows-specific build options (console/GUI terminal).
902
903
  * `root` — project root directory. Default: `process.cwd()`.
903
904
  * `signal` — an `AbortSignal` that cancels the build in progress.
905
+ * `timeout` — milliseconds allowed for each spawned shell command. Omit to disable the timeout.
904
906
  * `blob` — options controlling generated SEA blob behavior.
905
907
  */
906
908
  export declare interface SEAOptions {
@@ -914,6 +916,7 @@ export declare interface SEAOptions {
914
916
  readonly windows?: SEAWindowsOptions;
915
917
  readonly root?: string;
916
918
  readonly signal?: AbortSignal;
919
+ readonly timeout?: number;
917
920
  readonly blob?: SEABlobOptions;
918
921
  }
919
922
 
@@ -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 interpreted as a flag or injected
585
- * into a command line. The child process is spawned `detached` with
586
- * `stdio: 'ignore'` and immediately `unref()`d so it never keeps the host
587
- * app alive. Only `http:` and `https:` URLs are accepted — any other
588
- * scheme (including a string that merely looks like a CLI flag, e.g.
589
- * `'-e ...'`) fails to parse as an http(s) URL and is rejected before
590
- * anything is spawned.
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
@@ -901,6 +902,7 @@ export declare interface SEAInterface {
901
902
  * `windows` — Windows-specific build options (console/GUI terminal).
902
903
  * `root` — project root directory. Default: `process.cwd()`.
903
904
  * `signal` — an `AbortSignal` that cancels the build in progress.
905
+ * `timeout` — milliseconds allowed for each spawned shell command. Omit to disable the timeout.
904
906
  * `blob` — options controlling generated SEA blob behavior.
905
907
  */
906
908
  export declare interface SEAOptions {
@@ -914,6 +916,7 @@ export declare interface SEAOptions {
914
916
  readonly windows?: SEAWindowsOptions;
915
917
  readonly root?: string;
916
918
  readonly signal?: AbortSignal;
919
+ readonly timeout?: number;
917
920
  readonly blob?: SEABlobOptions;
918
921
  }
919
922
 
@@ -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 { execFileSync, spawn } from "node:child_process";
4
+ import { detach, executeSync } 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 useShell = cmd.endsWith(".cmd") || cmd.endsWith(".bat");
316
- try {
317
- return execFileSync(cmd, args, {
318
- cwd: options?.cwd,
319
- env: options?.env !== void 0 ? {
320
- ...process.env,
321
- ...options.env
322
- } : void 0,
323
- stdio: [
324
- "pipe",
325
- "pipe",
326
- "pipe"
327
- ],
328
- shell: useShell,
329
- timeout: options?.timeout
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 = executeSync({
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 interpreted as a flag or injected
972
- * into a command line. The child process is spawned `detached` with
973
- * `stdio: 'ignore'` and immediately `unref()`d so it never keeps the host
974
- * app alive. Only `http:` and `https:` URLs are accepted — any other
975
- * scheme (including a string that merely looks like a CLI flag, e.g.
976
- * `'-e ...'`) fails to parse as an http(s) URL and is rejected before
977
- * anything is spawned.
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 child = process.platform === "win32" ? spawn("rundll32", ["url.dll,FileProtocolHandler", parsed.href], {
1000
- detached: true,
1001
- stdio: "ignore"
1002
- }) : process.platform === "darwin" ? spawn("open", [parsed.href], {
1003
- detached: true,
1004
- stdio: "ignore"
1005
- }) : spawn("xdg-open", [parsed.href], {
1006
- detached: true,
1007
- stdio: "ignore"
1008
- });
1009
- child.on("error", () => {});
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
@@ -2153,7 +2141,8 @@ var SEA = class {
2153
2141
  configPath
2154
2142
  ], {
2155
2143
  cwd: output,
2156
- ...this.#options.signal === void 0 ? {} : { signal: this.#options.signal }
2144
+ ...this.#options.signal === void 0 ? {} : { signal: this.#options.signal },
2145
+ ...this.#options.timeout === void 0 ? {} : { timeout: this.#options.timeout }
2157
2146
  });
2158
2147
  if (!existsSync(blob)) throw new SEAError("BLOB", "SEA blob generation failed — blob not found", { blob });
2159
2148
  this.#emitter.emit("blob", blob);
@@ -2167,7 +2156,10 @@ var SEA = class {
2167
2156
  const name = process.platform === "win32" ? `${this.#options.name}.exe` : this.#options.name;
2168
2157
  const finalOutput = join(output, name);
2169
2158
  const temp = join(output, `.${this.#options.name}-${randomUUID()}.tmp${ext}`);
2170
- const shell = this.#options.signal === void 0 ? {} : { signal: this.#options.signal };
2159
+ const shell = {
2160
+ ...this.#options.signal === void 0 ? {} : { signal: this.#options.signal },
2161
+ ...this.#options.timeout === void 0 ? {} : { timeout: this.#options.timeout }
2162
+ };
2171
2163
  let signed = false;
2172
2164
  let stripped = false;
2173
2165
  let terminal;