@orkestrel/sea 0.0.8 → 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 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
@@ -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
@@ -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, 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 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 = 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 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