@orkestrel/sea 0.0.15 → 0.0.17

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.
@@ -1,3 +1,4 @@
1
+ import { isArrayBuffer, isError, isInstance, isString, literalOf } from "@orkestrel/contract";
1
2
  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
3
  import { brotliCompressSync, constants } from "node:zlib";
3
4
  import { dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
@@ -5,7 +6,6 @@ import { detach, executeSync } from "@orkestrel/process/server";
5
6
  import { randomUUID } from "node:crypto";
6
7
  import { Emitter } from "@orkestrel/emitter";
7
8
  import { getAssetKeys, getRawAsset, isSea } from "node:sea";
8
- import { isArrayBuffer } from "@orkestrel/contract";
9
9
  //#region src/server/constants.ts
10
10
  /**
11
11
  * Holds the SEA sentinel fuse value embedded in the Node.js binary,
@@ -191,7 +191,7 @@ var SEAError = class extends Error {
191
191
  * ```
192
192
  */
193
193
  function isSEAError(value) {
194
- return value instanceof SEAError;
194
+ return isInstance(value, SEAError);
195
195
  }
196
196
  /**
197
197
  * Represents an error thrown when a shell command executed through `executeShell` exits non-zero.
@@ -236,7 +236,7 @@ var ShellError = class extends SEAError {
236
236
  * ```
237
237
  */
238
238
  function isShellError(value) {
239
- return value instanceof ShellError;
239
+ return isInstance(value, ShellError);
240
240
  }
241
241
  //#endregion
242
242
  //#region src/server/validators.ts
@@ -253,7 +253,7 @@ function isShellError(value) {
253
253
  * ```
254
254
  */
255
255
  function isExecutableFormat(value) {
256
- return value === "pe" || value === "elf" || value === "macho";
256
+ return literalOf("pe", "elf", "macho")(value);
257
257
  }
258
258
  //#endregion
259
259
  //#region src/server/helpers.ts
@@ -872,7 +872,7 @@ function ensureContained(base, path) {
872
872
  } catch (thrown) {
873
873
  throw new SEAError("ASSET", "Path not found or unresolvable", {
874
874
  path,
875
- cause: thrown instanceof Error ? thrown.message : String(thrown)
875
+ cause: isError(thrown) ? thrown.message : String(thrown)
876
876
  });
877
877
  }
878
878
  if (real !== realBase && !real.startsWith(realBase + sep)) throw new SEAError("ASSET", "Path escapes the build root", {
@@ -939,11 +939,11 @@ function syncDirectory(path) {
939
939
  closeSync(fd);
940
940
  }
941
941
  } catch (thrown) {
942
- const code = thrown instanceof Error && "code" in thrown && typeof thrown.code === "string" ? thrown.code : void 0;
942
+ const code = isError(thrown) && "code" in thrown && isString(thrown.code) ? thrown.code : void 0;
943
943
  if (code === "EINVAL" || code === "ENOTSUP" || code === "EISDIR" || code === "EPERM" || code === "EACCES") return;
944
944
  throw new SEAError("OUTPUT", "Failed to sync output directory", {
945
945
  path,
946
- cause: thrown instanceof Error ? thrown.message : String(thrown)
946
+ cause: isError(thrown) ? thrown.message : String(thrown)
947
947
  });
948
948
  }
949
949
  }
@@ -980,7 +980,7 @@ function finalizeExecutable(source, target) {
980
980
  throw new SEAError("OUTPUT", "Failed to finalize executable", {
981
981
  source,
982
982
  target,
983
- cause: thrown instanceof Error ? thrown.message : String(thrown)
983
+ cause: isError(thrown) ? thrown.message : String(thrown)
984
984
  });
985
985
  }
986
986
  syncDirectory(dirname(target));
@@ -2378,7 +2378,7 @@ var SEA = class {
2378
2378
  try {
2379
2379
  executeShell([...platform.remove, temp], shell);
2380
2380
  } catch (thrown) {
2381
- throw new SEAError("SIGN", "Failed to strip existing signature", { cause: thrown instanceof Error ? thrown.message : String(thrown) });
2381
+ throw new SEAError("SIGN", "Failed to strip existing signature", { cause: isError(thrown) ? thrown.message : String(thrown) });
2382
2382
  }
2383
2383
  stripped = true;
2384
2384
  }
@@ -2395,14 +2395,14 @@ var SEA = class {
2395
2395
  try {
2396
2396
  executeShell([...platform.sign, temp], shell);
2397
2397
  } catch (thrown) {
2398
- throw new SEAError("SIGN", "Failed to sign executable", { cause: thrown instanceof Error ? thrown.message : String(thrown) });
2398
+ throw new SEAError("SIGN", "Failed to sign executable", { cause: isError(thrown) ? thrown.message : String(thrown) });
2399
2399
  }
2400
2400
  if (platform.verify !== void 0) {
2401
2401
  this.#check();
2402
2402
  try {
2403
2403
  executeShell([...platform.verify, temp], shell);
2404
2404
  } catch (thrown) {
2405
- throw new SEAError("SIGN", "Signature verification failed", { cause: thrown instanceof Error ? thrown.message : String(thrown) });
2405
+ throw new SEAError("SIGN", "Signature verification failed", { cause: isError(thrown) ? thrown.message : String(thrown) });
2406
2406
  }
2407
2407
  }
2408
2408
  signed = true;