@wasm-oj/server 0.2.1 → 0.2.3

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,4 +1,4 @@
1
- import { a as deterministicRustLinkerEnvironment, c as RUST_FINAL_OUTPUT_PATH, d as instantiateRustLinkerArguments, f as MountedOutputStabilityObserver, i as deterministicRustCompilerEnvironment, l as RUST_LINKER_COMMAND, n as RUST_TOOLCHAIN, o as rustcDependencyArguments, r as decodeRustToolchainManifest, s as rustcObjectArguments, t as RUST_COMPILE_TIMEOUT_MS, u as RUST_OBJECT_PATH } from "./chunks/rust-toolchain-CJ3sMxPE.js";
1
+ import { a as deterministicRustLinkerEnvironment, c as RUST_FINAL_OUTPUT_PATH, d as instantiateRustLinkerArguments, f as MountedOutputStabilityObserver, i as deterministicRustCompilerEnvironment, l as RUST_LINKER_COMMAND, n as RUST_TOOLCHAIN, o as rustcDependencyArguments, r as decodeRustToolchainManifest, s as rustcObjectArguments, t as RUST_COMPILE_TIMEOUT_MS, u as RUST_OBJECT_PATH } from "./chunks/rust-toolchain-CK5h2WT8.js";
2
2
  import { writeFileSync } from "node:fs";
3
3
  import { readFile } from "node:fs/promises";
4
4
  import { createHash } from "node:crypto";
@@ -1,8 +1,7 @@
1
- import { A as PYTHON_PACKAGE_ASSET_PATH, B as TYPESCRIPT_VERSION, C as JAVA_COMPILE_CLASSLIB_ASSET_PATH, H as toolchainPackageIdentities, M as QUICKJS_PACKAGE, R as RUST_VERSION, T as JAVA_RUNTIME_CLASSLIB_ASSET_PATH, V as toolchainContentIdentity, a as CLANG_PACKAGE_ASSET_PATH, i as CLANG_LIBCXX_PCH_MANIFEST_SHA256, k as PYTHON_PACKAGE, n as CLANG_CC1_PINS_SHA256, o as CLANG_PACKAGE_SHA256, r as CLANG_LIBCXX_PCH_MANIFEST_ASSET_PATH, s as CLANG_VERSION, t as CLANG_CC1_PINS_ASSET_PATH, v as GO_VERSION, y as JAVA_COMPILER_ASSET_PATH, z as TYPESCRIPT_ASSET_PATH } from "./chunks/toolchains-C6KuA1yM.js";
2
- import { f as MountedOutputStabilityObserver, n as RUST_TOOLCHAIN, t as RUST_COMPILE_TIMEOUT_MS } from "./chunks/rust-toolchain-CJ3sMxPE.js";
3
- import { _ as pythonDependencyFiles, g as npmDependencyFiles, h as goDependencyInput, i as GO_TOOLCHAIN, m as cppDependencyInput, n as GO_COMPILE_TIMEOUT_MS, p as assertProjectDependencyEcosystem, v as rustDependencyInput } from "./chunks/go-toolchain-Dbt-lp2L.js";
4
- import { n as javaMainClass, t as JAVA_COMPILE_TIMEOUT_MS } from "./chunks/java-toolchain-DajoRCHu.js";
5
- import { t as PYTHON_COMPILE_TIMEOUT_MS } from "./chunks/python-toolchain-Dx834o2A.js";
1
+ import { A as QUICKJS_PACKAGE, B as toolchainPackageIdentities, C as JAVA_COMPILE_CLASSLIB_SHA256, E as JAVA_VERSION, I as RUST_VERSION, L as TYPESCRIPT_ASSET_PATH, O as PYTHON_PACKAGE, R as TYPESCRIPT_VERSION, S as JAVA_COMPILE_CLASSLIB_ASSET_PATH, T as JAVA_RUNTIME_CLASSLIB_SHA256, a as CLANG_PACKAGE_ASSET_PATH, b as JAVA_COMPILER_PACKAGE, i as CLANG_LIBCXX_PCH_MANIFEST_SHA256, n as CLANG_CC1_PINS_SHA256, o as CLANG_PACKAGE_SHA256, r as CLANG_LIBCXX_PCH_MANIFEST_ASSET_PATH, s as CLANG_VERSION, t as CLANG_CC1_PINS_ASSET_PATH, v as GO_VERSION, w as JAVA_RUNTIME_CLASSLIB_ASSET_PATH, x as JAVA_COMPILER_SHA256, y as JAVA_COMPILER_ASSET_PATH, z as toolchainContentIdentity } from "./chunks/toolchains-uz3XbZGI.js";
2
+ import { f as MountedOutputStabilityObserver, n as RUST_TOOLCHAIN, t as RUST_COMPILE_TIMEOUT_MS } from "./chunks/rust-toolchain-CK5h2WT8.js";
3
+ import { _ as pythonDependencyFiles, g as npmDependencyFiles, h as goDependencyInput, i as GO_TOOLCHAIN, m as cppDependencyInput, n as GO_COMPILE_TIMEOUT_MS, p as assertProjectDependencyEcosystem, v as rustDependencyInput } from "./chunks/go-toolchain-DRQSILaC.js";
4
+ import { t as withProcessKeepalive } from "./chunks/process-keepalive-BWLUz55N.js";
6
5
  import { constants, writeFileSync } from "node:fs";
7
6
  import { deserialize, serialize } from "node:v8";
8
7
  import { access, lstat, mkdtemp, open, readFile, rm, writeFile } from "node:fs/promises";
@@ -108,7 +107,7 @@ Object.freeze({
108
107
  var decoder$3 = new TextDecoder();
109
108
  async function decodeClangPins(bytes) {
110
109
  const digest = await sha256Hex(bytes);
111
- if (digest !== "66c4604dccd3f89d8e1472bf4432367d7396cce4a01279b1a1db445f229dba72") throw new Error(`The pinned cc1 manifest drifted from its contract: expected ${CLANG_CC1_PINS_SHA256}, received ${digest}. Regenerate it with scripts/pin-clang-cc1-argv.mjs and update CLANG_CC1_PINS_SHA256.`);
110
+ if (digest !== "895eee17c63b1112c84adcc4ddbcb38e0c18e53bff15f50a8689b9b82d87b1ff") throw new Error(`The pinned cc1 manifest drifted from its contract: expected ${CLANG_CC1_PINS_SHA256}, received ${digest}. Regenerate it with scripts/pin-clang-cc1-argv.mjs and update CLANG_CC1_PINS_SHA256.`);
112
111
  const parsed = JSON.parse(decoder$3.decode(bytes));
113
112
  if (parsed.schema !== WASM_OJ_SCHEMAS.clangPins) throw new Error(`Unsupported cc1 pin schema '${parsed.schema}'.`);
114
113
  for (const key of [
@@ -562,8 +561,8 @@ Object.freeze({
562
561
  });
563
562
  new TextEncoder();
564
563
  Object.freeze({
565
- runtimeCoreWasmSha256: "e4c7fca566ff5ba66931e0cf11cacbf37610d35c36d5f3ee97d719468a2f6466",
566
- runtimeSourceRootSha256: "0140ecc6ed5060eae465e73db6822bcde32295734517de84929a537e3c45e663",
564
+ runtimeCoreWasmSha256: "1e297ad276694e9fb8a23afdc6ccc0b2ae56a223ced19d5cae26fe4661daa11e",
565
+ runtimeSourceRootSha256: "27c52cb1887aa8a7e0d8a238514fc8881cf86c68267e2a1691f110423692e2b6",
567
566
  wasmerNativeVersion: "7.2.1",
568
567
  wasmerSdkVersion: "0.10.0",
569
568
  wasmerSdkWasmSha256: "49a6646209f5ab5e7c737eac33407d87d9a9959ac83e5ecaaab9261b2323589e",
@@ -574,7 +573,7 @@ Object.freeze({
574
573
  * Release verification independently checks the component bytes before this
575
574
  * identity is admitted into a calibrated release.
576
575
  */
577
- var WASM_OJ_RUNTIME_IDENTITY_SHA256 = "59414bf4fa5191d0942c0e190c69d32f3a2251461b8eb41aaba32598baab1d5f";
576
+ var WASM_OJ_RUNTIME_IDENTITY_SHA256 = "d3e44cafdc1c17a7e6bd4591ef04ec8161af805a519b5bbff437b15e5accd442";
578
577
  //#endregion
579
578
  //#region src/core/cost-profile.ts
580
579
  function coordinates(language, target, optimization) {
@@ -623,34 +622,6 @@ function parseClangDiagnostics(output) {
623
622
  });
624
623
  return diagnostics;
625
624
  }
626
- function parsePythonDiagnostics(output) {
627
- const diagnostics = [];
628
- const lines = output.split(/\r?\n/);
629
- for (let index = 0; index < lines.length; index += 1) {
630
- const location = lines[index].match(/^\s*File "([^"]+)", line (\d+)/);
631
- if (!location) continue;
632
- let column = 1;
633
- let message = "Python compilation failed";
634
- const caret = (lines[index + 2] ?? "").indexOf("^");
635
- if (caret >= 0) column = caret + 1;
636
- for (let cursor = index + 1; cursor < Math.min(lines.length, index + 6); cursor += 1) {
637
- const error = lines[cursor].match(/^([A-Za-z]+(?:Error|Exception)):\s*(.+)$/);
638
- if (error) {
639
- message = `${error[1]}: ${error[2]}`;
640
- break;
641
- }
642
- }
643
- diagnostics.push({
644
- file: projectPath(location[1]),
645
- line: Number(location[2]),
646
- column,
647
- severity: "error",
648
- message,
649
- source: "python"
650
- });
651
- }
652
- return diagnostics;
653
- }
654
625
  function parseTypeScriptDiagnostics(output) {
655
626
  const diagnostics = [];
656
627
  const pattern = /^(.*?)\((\d+),(\d+)\):\s+(error|warning|message)\s+TS(\d+):\s+(.+)$/gm;
@@ -774,14 +745,14 @@ var WASM_OJ_LIBCXX_PCH_HEADER = `#pragma once
774
745
  var decoder$1 = new TextDecoder();
775
746
  async function decodeLibcxxPchManifest(bytes) {
776
747
  const digest = await sha256Hex(bytes);
777
- if (digest !== "d126c99e951a7302d4ea2b66da4ed64d3d74e9d319d562518867c8d8c97a06b8") throw new Error(`Pinned libc++ PCH manifest digest mismatch: expected ${CLANG_LIBCXX_PCH_MANIFEST_SHA256}, received ${digest}.`);
748
+ if (digest !== "9bbe41d77c786f1c36169369c909268530b05726e1581683f6edd9a2983eebd0") throw new Error(`Pinned libc++ PCH manifest digest mismatch: expected ${CLANG_LIBCXX_PCH_MANIFEST_SHA256}, received ${digest}.`);
778
749
  let value;
779
750
  try {
780
751
  value = JSON.parse(decoder$1.decode(bytes));
781
752
  } catch (error) {
782
753
  throw new Error("Pinned libc++ PCH manifest is not valid JSON.", { cause: error });
783
754
  }
784
- if (!isRecord(value) || value.schema !== WASM_OJ_SCHEMAS.clangLibcxxPch || value.version !== "22.0.0-git20542-10" || value.clangPackageSha256 !== "21ded33b9c6d4e1aaad5528c940bdaf6c3e84be77ea8f522f018ca7289a2a224" || value.clangPinsSha256 !== "66c4604dccd3f89d8e1472bf4432367d7396cce4a01279b1a1db445f229dba72" || value.header !== WASM_OJ_LIBCXX_PCH_HEADER || !isRecord(value.profiles)) throw new Error("Pinned libc++ PCH manifest is not admitted by the active Clang toolchain contract.");
755
+ if (!isRecord(value) || value.schema !== WASM_OJ_SCHEMAS.clangLibcxxPch || value.version !== "22.0.0-git20542-10" || value.clangPackageSha256 !== "21ded33b9c6d4e1aaad5528c940bdaf6c3e84be77ea8f522f018ca7289a2a224" || value.clangPinsSha256 !== "895eee17c63b1112c84adcc4ddbcb38e0c18e53bff15f50a8689b9b82d87b1ff" || value.header !== WASM_OJ_LIBCXX_PCH_HEADER || !isRecord(value.profiles)) throw new Error("Pinned libc++ PCH manifest is not admitted by the active Clang toolchain contract.");
785
756
  if (value.headerSha256 !== await sha256Hex(WASM_OJ_LIBCXX_PCH_HEADER)) throw new Error("Pinned libc++ PCH header digest does not match its canonical source.");
786
757
  const manifestProfiles = value.profiles;
787
758
  const profiles = Object.fromEntries(await Promise.all(["cpp-debug", "cpp-release"].map(async (profile) => {
@@ -925,6 +896,7 @@ if hasattr(_os, "getrandom"):
925
896
 
926
897
  _entry = _sys.argv[1]
927
898
  _sys.argv = [_entry, *_sys.argv[2:]]
899
+ _sys.path[0] = _os.path.dirname(_entry)
928
900
  _runpy.run_path(_entry, run_name="__main__")
929
901
  `;
930
902
  //#endregion
@@ -1445,6 +1417,9 @@ function canonicalRuntimeBundleFiles(files) {
1445
1417
  return canonicalFileRecord(files);
1446
1418
  }
1447
1419
  //#endregion
1420
+ //#region src/runtime/quickjs/stdlib.generated.ts
1421
+ var QUICKJS_BUFFER_DECLARATION = "declare module \"buffer\" {\nexport class Buffer extends Uint8Array {\n length: number\n write(string: string, offset?: number, length?: number, encoding?: string): number;\n toString(encoding?: string, start?: number, end?: number): string;\n toJSON(): { type: 'Buffer', data: any[] };\n equals(otherBuffer: Buffer): boolean;\n compare(otherBuffer: Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number;\n copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;\n slice(start?: number, end?: number): Buffer;\n writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;\n writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;\n writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;\n writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;\n readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number;\n readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number;\n readIntLE(offset: number, byteLength: number, noAssert?: boolean): number;\n readIntBE(offset: number, byteLength: number, noAssert?: boolean): number;\n readUInt8(offset: number, noAssert?: boolean): number;\n readUInt16LE(offset: number, noAssert?: boolean): number;\n readUInt16BE(offset: number, noAssert?: boolean): number;\n readUInt32LE(offset: number, noAssert?: boolean): number;\n readUInt32BE(offset: number, noAssert?: boolean): number;\n readBigUInt64LE(offset: number): BigInt;\n readBigUInt64BE(offset: number): BigInt;\n readInt8(offset: number, noAssert?: boolean): number;\n readInt16LE(offset: number, noAssert?: boolean): number;\n readInt16BE(offset: number, noAssert?: boolean): number;\n readInt32LE(offset: number, noAssert?: boolean): number;\n readInt32BE(offset: number, noAssert?: boolean): number;\n readBigInt64LE(offset: number): BigInt;\n readBigInt64BE(offset: number): BigInt;\n readFloatLE(offset: number, noAssert?: boolean): number;\n readFloatBE(offset: number, noAssert?: boolean): number;\n readDoubleLE(offset: number, noAssert?: boolean): number;\n readDoubleBE(offset: number, noAssert?: boolean): number;\n reverse(): this;\n swap16(): Buffer;\n swap32(): Buffer;\n swap64(): Buffer;\n writeUInt8(value: number, offset: number, noAssert?: boolean): number;\n writeUInt16LE(value: number, offset: number, noAssert?: boolean): number;\n writeUInt16BE(value: number, offset: number, noAssert?: boolean): number;\n writeUInt32LE(value: number, offset: number, noAssert?: boolean): number;\n writeUInt32BE(value: number, offset: number, noAssert?: boolean): number;\n writeBigUInt64LE(value: number, offset: number): BigInt;\n writeBigUInt64BE(value: number, offset: number): BigInt;\n writeInt8(value: number, offset: number, noAssert?: boolean): number;\n writeInt16LE(value: number, offset: number, noAssert?: boolean): number;\n writeInt16BE(value: number, offset: number, noAssert?: boolean): number;\n writeInt32LE(value: number, offset: number, noAssert?: boolean): number;\n writeInt32BE(value: number, offset: number, noAssert?: boolean): number;\n writeBigInt64LE(value: number, offset: number): BigInt;\n writeBigInt64BE(value: number, offset: number): BigInt;\n writeFloatLE(value: number, offset: number, noAssert?: boolean): number;\n writeFloatBE(value: number, offset: number, noAssert?: boolean): number;\n writeDoubleLE(value: number, offset: number, noAssert?: boolean): number;\n writeDoubleBE(value: number, offset: number, noAssert?: boolean): number;\n fill(value: any, offset?: number, end?: number): this;\n indexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number;\n lastIndexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number;\n includes(value: string | number | Buffer, byteOffset?: number, encoding?: string): boolean;\n\n /**\n * Allocates a new buffer containing the given {str}.\n *\n * @param str String to store in buffer.\n * @param encoding encoding to use, optional. Default is 'utf8'\n */\n constructor (str: string, encoding?: string);\n /**\n * Allocates a new buffer of {size} octets.\n *\n * @param size count of octets to allocate.\n */\n constructor (size: number);\n /**\n * Allocates a new buffer containing the given {array} of octets.\n *\n * @param array The octets to store.\n */\n constructor (array: Uint8Array);\n /**\n * Produces a Buffer backed by the same allocated memory as\n * the given {ArrayBuffer}.\n *\n *\n * @param arrayBuffer The ArrayBuffer with which to share memory.\n */\n constructor (arrayBuffer: ArrayBuffer);\n /**\n * Allocates a new buffer containing the given {array} of octets.\n *\n * @param array The octets to store.\n */\n constructor (array: any[]);\n /**\n * Copies the passed {buffer} data onto a new {Buffer} instance.\n *\n * @param buffer The buffer to copy.\n */\n constructor (buffer: Buffer);\n prototype: Buffer;\n /**\n * Allocates a new Buffer using an {array} of octets.\n *\n * @param array\n */\n static from(array: any[]): Buffer;\n /**\n * When passed a reference to the .buffer property of a TypedArray instance,\n * the newly created Buffer will share the same allocated memory as the TypedArray.\n * The optional {byteOffset} and {length} arguments specify a memory range\n * within the {arrayBuffer} that will be shared by the Buffer.\n *\n * @param arrayBuffer The .buffer property of a TypedArray or a new ArrayBuffer()\n * @param byteOffset\n * @param length\n */\n static from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;\n /**\n * Copies the passed {buffer} data onto a new Buffer instance.\n *\n * @param buffer\n */\n static from(buffer: Buffer | Uint8Array): Buffer;\n /**\n * Creates a new Buffer containing the given JavaScript string {str}.\n * If provided, the {encoding} parameter identifies the character encoding.\n * If not provided, {encoding} defaults to 'utf8'.\n *\n * @param str\n */\n static from(str: string, encoding?: string): Buffer;\n /**\n * Returns true if {obj} is a Buffer\n *\n * @param obj object to test.\n */\n static isBuffer(obj: any): obj is Buffer;\n /**\n * Returns true if {encoding} is a valid encoding argument.\n * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'\n *\n * @param encoding string to test.\n */\n static isEncoding(encoding: string): boolean;\n /**\n * Gives the actual byte length of a string. encoding defaults to 'utf8'.\n * This is not the same as String.prototype.length since that returns the number of characters in a string.\n *\n * @param string string to test.\n * @param encoding encoding used to evaluate (defaults to 'utf8')\n */\n static byteLength(string: string, encoding?: string): number;\n /**\n * Returns a buffer which is the result of concatenating all the buffers in the list together.\n *\n * If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer.\n * If the list has exactly one item, then the first item of the list is returned.\n * If the list has more than one item, then a new Buffer is created.\n *\n * @param list An array of Buffer objects to concatenate\n * @param totalLength Total length of the buffers when concatenated.\n * If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly.\n */\n static concat(list: Uint8Array[], totalLength?: number): Buffer;\n /**\n * The same as buf1.compare(buf2).\n */\n static compare(buf1: Uint8Array, buf2: Uint8Array): number;\n /**\n * Allocates a new buffer of {size} octets.\n *\n * @param size count of octets to allocate.\n * @param fill if specified, buffer will be initialized by calling buf.fill(fill).\n * If parameter is omitted, buffer will be filled with zeros.\n * @param encoding encoding used for call to buf.fill while initializing\n */\n static alloc(size: number, fill?: string | Buffer | number, encoding?: string): Buffer;\n /**\n * Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents\n * of the newly created Buffer are unknown and may contain sensitive data.\n *\n * @param size count of octets to allocate\n */\n static allocUnsafe(size: number): Buffer;\n /**\n * Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents\n * of the newly created Buffer are unknown and may contain sensitive data.\n *\n * @param size count of octets to allocate\n */\n static allocUnsafeSlow(size: number): Buffer;\n}\n\nconst buffer: { Buffer: typeof Buffer }; export default buffer;\n}\n";
1422
+ //#endregion
1448
1423
  //#region src/core/quickjs-runtime.ts
1449
1424
  var QUICKJS_STD_MODULE_DECLARATION = String.raw`
1450
1425
  declare module "std" {
@@ -1453,9 +1428,80 @@ declare module "std" {
1453
1428
  in: { readAsString(): string };
1454
1429
  out: { puts(value: string): void };
1455
1430
  };
1456
- export = std;
1431
+ export default std;
1432
+ export const err: typeof std.err;
1433
+ export const out: typeof std.out;
1434
+ const input: typeof std.in;
1435
+ export { input as in };
1457
1436
  }
1458
1437
  `;
1438
+ var QUICKJS_NODE_MODULE_DECLARATION = QUICKJS_BUFFER_DECLARATION + String.raw`
1439
+ type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "utf-16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";
1440
+ type Buffer = import("buffer").Buffer;
1441
+ declare const Buffer: typeof import("buffer").Buffer;
1442
+ interface NodeReadable extends AsyncIterable<Buffer | string> {
1443
+ on(event: "data", callback: (chunk: Buffer | string) => void): this;
1444
+ on(event: "readable" | "end" | "close", callback: () => void): this;
1445
+ on(event: "error", callback: (error: Error) => void): this;
1446
+ setEncoding(encoding: BufferEncoding): this;
1447
+ read(size?: number): Buffer | string | null;
1448
+ resume(): this;
1449
+ pause(): this;
1450
+ pipe<T extends NodeWritable>(destination: T, options?: { end?: boolean }): T;
1451
+ }
1452
+ interface NodeWritable {
1453
+ write(value: string | Uint8Array, callback?: (error?: Error | null) => void): boolean;
1454
+ write(value: string | Uint8Array, encoding?: BufferEncoding, callback?: (error?: Error | null) => void): boolean;
1455
+ end(value?: string | Uint8Array): this;
1456
+ on(event: "error", callback: (error: Error) => void): this;
1457
+ on(event: "drain" | "finish" | "close", callback: () => void): this;
1458
+ }
1459
+ interface NodeProcess {
1460
+ stdin: NodeReadable;
1461
+ stdout: NodeWritable;
1462
+ stderr: NodeWritable;
1463
+ env: Record<string, string | undefined>;
1464
+ argv: string[];
1465
+ nextTick(callback: (...args: any[]) => void, ...args: any[]): void;
1466
+ }
1467
+ declare const process: NodeProcess;
1468
+ declare module "fs" {
1469
+ export function readFileSync(file: number | string, options?: null | { encoding?: null }): Buffer;
1470
+ export function readFileSync(file: number | string, options: BufferEncoding | { encoding: BufferEncoding }): string;
1471
+ export function readSync(fd: number, buffer: ArrayBufferView, offset?: number, length?: number, position?: number | null): number;
1472
+ export function writeFileSync(file: number | string, data: string | ArrayBufferView, options?: BufferEncoding | { encoding?: BufferEncoding }): void;
1473
+ export function writeSync(fd: number, buffer: ArrayBufferView, offset?: number, length?: number, position?: number | null): number;
1474
+ export function writeSync(fd: number, value: string, position?: number | null, encoding?: BufferEncoding): number;
1475
+ const fs: { readFileSync: typeof readFileSync; readSync: typeof readSync; writeFileSync: typeof writeFileSync; writeSync: typeof writeSync };
1476
+ export default fs;
1477
+ }
1478
+ declare module "node:fs" { export * from "fs"; export { default } from "fs"; }
1479
+ declare module "process" { const value: NodeProcess; export default value; export const stdin: NodeReadable; export const stdout: NodeWritable; export const stderr: NodeWritable; export const nextTick: NodeProcess["nextTick"]; export const env: NodeProcess["env"]; export const argv: string[]; }
1480
+ declare module "node:process" { export * from "process"; export { default } from "process"; }
1481
+ declare module "node:buffer" { export * from "buffer"; export { default } from "buffer"; }
1482
+ declare module "readline" {
1483
+ export class Interface implements AsyncIterable<string> {
1484
+ constructor(options: { input: NodeReadable; output?: NodeWritable; terminal?: boolean; crlfDelay?: number });
1485
+ on(event: "line", callback: (line: string) => void): this;
1486
+ on(event: "close" | "pause" | "resume", callback: () => void): this;
1487
+ on(event: "error", callback: (error: Error) => void): this;
1488
+ close(): void;
1489
+ pause(): this;
1490
+ resume(): this;
1491
+ [Symbol.asyncIterator](): AsyncIterator<string>;
1492
+ }
1493
+ export function createInterface(options: { input: NodeReadable; output?: NodeWritable; terminal?: boolean; crlfDelay?: number }): Interface;
1494
+ const readline: { createInterface: typeof createInterface; Interface: typeof Interface };
1495
+ export default readline;
1496
+ }
1497
+ declare module "node:readline" { export * from "readline"; export { default } from "readline"; }
1498
+ `;
1499
+ var QUICKJS_COMMONJS_DECLARATION = String.raw`
1500
+ declare function require(name: "fs" | "node:fs"): typeof import("fs");
1501
+ declare function require(name: "readline" | "node:readline"): typeof import("readline");
1502
+ declare function require(name: "buffer" | "node:buffer"): typeof import("buffer");
1503
+ declare function require(name: "process" | "node:process"): NodeProcess;
1504
+ `;
1459
1505
  //#endregion
1460
1506
  //#region src/compiler/language-driver.ts
1461
1507
  /** Internal registry for WASM-OJ's built-in compiler pipelines. */
@@ -1577,50 +1623,29 @@ function sumFileSize(files) {
1577
1623
  async function buildPython(project, cacheKey, requestId) {
1578
1624
  const started = performance.now();
1579
1625
  const dependencies = pythonDependencyFiles(project);
1580
- const compilerFiles = [...project.files, ...dependencies.sourceFiles];
1581
- const pythonFiles = compilerFiles.filter((file) => file.path.endsWith(".py"));
1582
- progress(requestId, "compiling", `Byte-compiling ${pythonFiles.length} Python file${pythonFiles.length === 1 ? "" : "s"}`, .55);
1583
- const frontend = await requireHost().compilePython({ files: compilerFiles });
1584
- if (!frontend.success) return {
1585
- success: false,
1586
- diagnostics: ensureFailureDiagnostic(frontend.diagnostics, {
1587
- file: project.config.entry,
1588
- source: "python",
1589
- message: frontend.stderr.trim() || "Python byte-compilation failed without a diagnostic."
1590
- }),
1591
- stdout: frontend.stdout,
1592
- stderr: frontend.stderr,
1593
- cacheHit: false
1594
- };
1626
+ progress(requestId, "compiling", "Packaging Python sources", .55);
1595
1627
  const files = Object.fromEntries(project.files.map((file) => [file.path, file.content]));
1596
- Object.assign(files, dependencies.artifactFiles);
1628
+ Object.assign(files, dependencies);
1597
1629
  files[PYTHON_RUNNER_PATH] = PYTHON_DETERMINISTIC_RUNNER;
1598
- for (const file of pythonFiles) {
1599
- const compiledPath = `build/${file.path.replace(/\.py$/, ".pyc")}`;
1600
- const bytecode = frontend.bytecode[compiledPath];
1601
- if (!bytecode) throw new Error(`Python stage omitted '${compiledPath}'.`);
1602
- files[compiledPath] = bytecode;
1603
- }
1604
- const entry = `build/${project.config.entry.replace(/\.py$/, ".pyc")}`;
1630
+ const entry = project.config.entry;
1605
1631
  const manifest = createRuntimeBundleManifest(project, PYTHON_PACKAGE, "python", entry);
1606
1632
  files["wasm-oj.manifest.json"] = manifest;
1607
1633
  const bundleFiles = canonicalRuntimeBundleFiles(files);
1608
- const artifact = {
1609
- kind: "runtime-bundle",
1610
- ...createArtifactBase(project, cacheKey, started, sumFileSize(bundleFiles), toolchainPackageIdentities("python")),
1611
- name: `${project.name}.python-${project.config.target}.json`,
1612
- runtimePackage: PYTHON_PACKAGE,
1613
- command: "python",
1614
- entry,
1615
- files: bundleFiles,
1616
- manifest
1617
- };
1618
1634
  return {
1619
1635
  success: true,
1620
- diagnostics: frontend.diagnostics,
1621
- artifact,
1622
- stdout: frontend.stdout,
1623
- stderr: frontend.stderr,
1636
+ diagnostics: [],
1637
+ artifact: {
1638
+ kind: "runtime-bundle",
1639
+ ...createArtifactBase(project, cacheKey, started, sumFileSize(bundleFiles), toolchainPackageIdentities("python")),
1640
+ name: `${project.name}.python-${project.config.target}.json`,
1641
+ runtimePackage: PYTHON_PACKAGE,
1642
+ command: "python",
1643
+ entry,
1644
+ files: bundleFiles,
1645
+ manifest
1646
+ },
1647
+ stdout: "",
1648
+ stderr: "",
1624
1649
  cacheHit: false
1625
1650
  };
1626
1651
  }
@@ -1677,7 +1702,7 @@ async function buildJava(project, cacheKey, requestId) {
1677
1702
  stderr: "",
1678
1703
  cacheHit: false
1679
1704
  };
1680
- progress(requestId, "compiling", `Compiling Java ${javaMainClass(entry.path, entry.content)}`, .3);
1705
+ progress(requestId, "compiling", `Compiling Java ${entry.path}`, .3);
1681
1706
  const compiled = await requireHost().compileJava({
1682
1707
  entry: project.config.entry,
1683
1708
  files: project.files,
@@ -1732,9 +1757,8 @@ async function transpileScriptProject(project, requestId) {
1732
1757
  files: {
1733
1758
  ...Object.fromEntries(project.files.map((file) => [`/project/${file.path}`, file.content])),
1734
1759
  ...Object.fromEntries(Object.entries(dependencyFiles).filter(([, contents]) => typeof contents === "string").map(([path, contents]) => [`/project/${path}`, contents])),
1735
- [declarationPath]: QUICKJS_STD_MODULE_DECLARATION
1760
+ [declarationPath]: QUICKJS_STD_MODULE_DECLARATION + QUICKJS_NODE_MODULE_DECLARATION + QUICKJS_COMMONJS_DECLARATION
1736
1761
  },
1737
- javascript: project.config.language === "javascript",
1738
1762
  sources: [
1739
1763
  declarationPath,
1740
1764
  ...scriptFiles.map((file) => `/project/${file.path}`),
@@ -1776,40 +1800,54 @@ async function buildScript(project, cacheKey, requestId) {
1776
1800
  stderr: "",
1777
1801
  cacheHit: false
1778
1802
  };
1779
- progress(requestId, "compiling", `Compiling ${project.config.language === "typescript" ? "TypeScript" : "JavaScript"} with TypeScript/WASI`, .5);
1780
- const { files, output, response } = await transpileScriptProject(project, requestId);
1781
- const diagnostics = parseTypeScriptDiagnostics(response?.diagnostics ?? "");
1782
- const emittedOutputsPresent = emittedSourceFiles(project).every((file) => Object.hasOwn(files, emittedScriptPath(file.path)));
1783
- if (!output.ok || !response || response.status !== 0 || !emittedOutputsPresent || diagnostics.some((diagnostic) => diagnostic.severity === "error")) return {
1784
- success: false,
1785
- diagnostics: ensureFailureDiagnostic(diagnostics, {
1786
- file: project.config.entry,
1787
- source: "typescript",
1788
- message: output.stderr.trim() || response?.diagnostics.trim() || `TypeScript 7.0.2 did not return every compiled output.`
1789
- }),
1790
- stdout: "",
1791
- stderr: output.stderr,
1792
- cacheHit: false
1793
- };
1803
+ let files;
1804
+ let diagnostics = [];
1805
+ let stderr = "";
1806
+ if (project.config.language === "javascript") {
1807
+ progress(requestId, "compiling", "Preparing JavaScript modules", .5);
1808
+ files = {
1809
+ ...Object.fromEntries(emittedSourceFiles(project).map((file) => [file.path, file.content])),
1810
+ ...npmDependencyFiles(project)
1811
+ };
1812
+ } else {
1813
+ progress(requestId, "compiling", "Compiling TypeScript with TypeScript/WASI", .5);
1814
+ const transpiled = await transpileScriptProject(project, requestId);
1815
+ files = transpiled.files;
1816
+ stderr = transpiled.output.stderr;
1817
+ diagnostics = parseTypeScriptDiagnostics(transpiled.response?.diagnostics ?? "");
1818
+ const emittedOutputsPresent = emittedSourceFiles(project).every((file) => Object.hasOwn(files, emittedScriptPath(file.path)));
1819
+ if (!transpiled.output.ok || !transpiled.response || transpiled.response.status !== 0 || !emittedOutputsPresent || diagnostics.some((diagnostic) => diagnostic.severity === "error")) return {
1820
+ success: false,
1821
+ diagnostics: ensureFailureDiagnostic(diagnostics, {
1822
+ file: project.config.entry,
1823
+ source: "typescript",
1824
+ message: stderr.trim() || transpiled.response?.diagnostics.trim() || `TypeScript 7.0.2 did not return every compiled output.`
1825
+ }),
1826
+ stdout: "",
1827
+ stderr,
1828
+ cacheHit: false
1829
+ };
1830
+ }
1794
1831
  const entry = emittedScriptPath(project.config.entry);
1795
1832
  const manifest = createRuntimeBundleManifest(project, QUICKJS_PACKAGE, "qjs", entry);
1796
1833
  files["wasm-oj.manifest.json"] = manifest;
1797
1834
  const bundleFiles = canonicalRuntimeBundleFiles(files);
1835
+ const artifact = {
1836
+ kind: "runtime-bundle",
1837
+ ...createArtifactBase(project, cacheKey, started, sumFileSize(bundleFiles), toolchainPackageIdentities(project.config.language)),
1838
+ name: `${project.name}.${project.config.language === "typescript" ? "typescript" : "javascript"}-${project.config.target}.json`,
1839
+ runtimePackage: QUICKJS_PACKAGE,
1840
+ command: "qjs",
1841
+ entry,
1842
+ files: bundleFiles,
1843
+ manifest
1844
+ };
1798
1845
  return {
1799
1846
  success: true,
1800
1847
  diagnostics,
1801
- artifact: {
1802
- kind: "runtime-bundle",
1803
- ...createArtifactBase(project, cacheKey, started, sumFileSize(bundleFiles), toolchainPackageIdentities(project.config.language)),
1804
- name: `${project.name}.${project.config.language === "typescript" ? "typescript" : "javascript"}-${project.config.target}.json`,
1805
- runtimePackage: QUICKJS_PACKAGE,
1806
- command: "qjs",
1807
- entry,
1808
- files: bundleFiles,
1809
- manifest
1810
- },
1848
+ artifact,
1811
1849
  stdout: "",
1812
- stderr: output.stderr,
1850
+ stderr,
1813
1851
  cacheHit: false
1814
1852
  };
1815
1853
  }
@@ -1880,6 +1918,19 @@ function clearCompilerHostCaches() {
1880
1918
  typescriptCompilerBytes = void 0;
1881
1919
  }
1882
1920
  //#endregion
1921
+ //#region src/compiler/java-toolchain.ts
1922
+ var JAVA_COMPILE_TIMEOUT_MS = 18e4;
1923
+ Object.freeze({
1924
+ version: JAVA_VERSION,
1925
+ package: JAVA_COMPILER_PACKAGE,
1926
+ compilerAsset: JAVA_COMPILER_ASSET_PATH,
1927
+ compilerSha256: JAVA_COMPILER_SHA256,
1928
+ compileClasslibAsset: JAVA_COMPILE_CLASSLIB_ASSET_PATH,
1929
+ compileClasslibSha256: JAVA_COMPILE_CLASSLIB_SHA256,
1930
+ runtimeClasslibAsset: JAVA_RUNTIME_CLASSLIB_ASSET_PATH,
1931
+ runtimeClasslibSha256: JAVA_RUNTIME_CLASSLIB_SHA256
1932
+ });
1933
+ //#endregion
1883
1934
  //#region src/server/wasmer-runtime.ts
1884
1935
  var initialization;
1885
1936
  async function initializeServerWasmerSdk() {
@@ -2045,7 +2096,6 @@ function sameRecord(expected, actual) {
2045
2096
  var SERVER_STAGE_SCRIPTS = Object.freeze([
2046
2097
  "server-build-stage.mjs",
2047
2098
  "server-runner-stage.mjs",
2048
- "python-stage.mjs",
2049
2099
  "rustc-stage.mjs",
2050
2100
  "go-stage.mjs",
2051
2101
  "java-stage.mjs"
@@ -2137,7 +2187,6 @@ var ServerCompiler = class {
2137
2187
  loadToolchainAsset: (assetPath) => this.loadToolchainAsset(assetPath),
2138
2188
  loadToolchainFile: (assetPath) => this.loadToolchainFile(assetPath),
2139
2189
  compileRust: (request) => this.compileRust(request),
2140
- compilePython: (request) => this.compilePython(request),
2141
2190
  compileGo: (request) => this.compileGo(request),
2142
2191
  compileJava: (request) => this.compileJava(request),
2143
2192
  progress: (_requestId, phase, label, value) => {
@@ -2339,14 +2388,6 @@ var ServerCompiler = class {
2339
2388
  wasm: result.wasmBase64 ? new Uint8Array(Buffer.from(result.wasmBase64, "base64")) : void 0
2340
2389
  };
2341
2390
  }
2342
- async compilePython(request) {
2343
- const result = await this.runCompilerStage("python-stage.mjs", { request }, PYTHON_COMPILE_TIMEOUT_MS, [PYTHON_PACKAGE_ASSET_PATH]);
2344
- return {
2345
- ...result,
2346
- bytecode: Object.fromEntries(Object.entries(result.bytecodeBase64).map(([path, base64]) => [path, new Uint8Array(Buffer.from(base64, "base64"))])),
2347
- diagnostics: parsePythonDiagnostics(`${result.stderr}\n${result.stdout}`)
2348
- };
2349
- }
2350
2391
  async compileGo(request) {
2351
2392
  const result = await this.runCompilerStage("go-stage.mjs", {
2352
2393
  compilerExecutable: this.compilerExecutable,
@@ -2512,21 +2553,6 @@ async function buildServerProjectInProcess(options, project, cacheKey, onProgres
2512
2553
  }
2513
2554
  }
2514
2555
  //#endregion
2515
- //#region src/server/process-keepalive.mjs
2516
- /**
2517
- * Keep Node alive while a promise is backed only by a foreign async runtime.
2518
- * Top-level await does not itself create a referenced libuv handle, so Node can
2519
- * otherwise exit with code 13 while a Wasmer SDK operation is still pending.
2520
- */
2521
- async function withProcessKeepalive(promise) {
2522
- const keepalive = setInterval(() => void 0, 6e4);
2523
- try {
2524
- return await promise;
2525
- } finally {
2526
- clearInterval(keepalive);
2527
- }
2528
- }
2529
- //#endregion
2530
2556
  //#region src/server/server-build-stage.mjs
2531
2557
  var SERVER_BUILD_REQUEST_LIMIT_BYTES = 805306368;
2532
2558
  try {
@@ -1,4 +1,5 @@
1
- import { O as PYTHON_COMPRESSED_PACKAGE_SHA256, j as PYTHON_PACKAGE_SHA256, k as PYTHON_PACKAGE } from "./chunks/toolchains-C6KuA1yM.js";
1
+ import { D as PYTHON_COMPRESSED_PACKAGE_SHA256, O as PYTHON_PACKAGE, k as PYTHON_PACKAGE_SHA256 } from "./chunks/toolchains-uz3XbZGI.js";
2
+ import { t as withProcessKeepalive } from "./chunks/process-keepalive-BWLUz55N.js";
2
3
  import { writeFileSync } from "node:fs";
3
4
  import { serialize } from "node:v8";
4
5
  import { readFile } from "node:fs/promises";
@@ -17,14 +18,14 @@ var response;
17
18
  var exitCode = 0;
18
19
  try {
19
20
  const input = parseInput(JSON.parse(await readStdin()));
20
- await init({ log: "warn" });
21
+ await withProcessKeepalive(init({ log: "warn" }));
21
22
  runtime = new Runtime({ registry: null });
22
23
  const packagePath = input.toolchainAsset;
23
24
  const compressed = await readFile(packagePath);
24
25
  if (!input.verifiedToolchain) verifyDigest(packagePath, compressed, PYTHON_COMPRESSED_PACKAGE_SHA256);
25
26
  const expanded = uint8View(gunzipSync(compressed));
26
27
  if (!input.verifiedToolchain) verifyDigest(packagePath, expanded, PYTHON_PACKAGE_SHA256);
27
- pkg = await Wasmer.fromFile(expanded, runtime);
28
+ pkg = await withProcessKeepalive(Wasmer.fromFile(expanded, runtime));
28
29
  const commandMap = pkg.commands;
29
30
  commands = uniqueCommands(commandMap);
30
31
  const command = commandMap[input.request.command];
@@ -34,14 +35,15 @@ try {
34
35
  bytes = command.binary().slice();
35
36
  if (!WebAssembly.validate(bytes)) throw new Error(`Package '${input.request.packageSpecifier}' command '${input.request.command}' returned invalid WebAssembly.`);
36
37
  } else {
37
- const output = await (await command.run({
38
+ const instance = await withProcessKeepalive(command.run({
38
39
  args: input.request.args,
39
40
  env: {
40
41
  PYTHONHOME: "/usr/local",
41
42
  PYTHONHASHSEED: "0",
42
43
  PYTHONDONTWRITEBYTECODE: "1"
43
44
  }
44
- })).wait();
45
+ }));
46
+ const output = await withProcessKeepalive(instance.wait());
45
47
  if (!output.ok) throw new Error(`Unable to export runtime files from ${input.request.packageSpecifier}: exit ${output.code}: ${boundedText(output.stderr)}`);
46
48
  bytes = output.stdoutBytes.slice();
47
49
  }