@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.
@@ -0,0 +1,259 @@
1
+ buffer 6.0.3
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) Feross Aboukhadijeh, and other contributors.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
23
+
24
+
25
+ readable-stream 4.7.0
26
+ Node.js is licensed for use as follows:
27
+
28
+ """
29
+ Copyright Node.js contributors. All rights reserved.
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining a copy
32
+ of this software and associated documentation files (the "Software"), to
33
+ deal in the Software without restriction, including without limitation the
34
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
35
+ sell copies of the Software, and to permit persons to whom the Software is
36
+ furnished to do so, subject to the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be included in
39
+ all copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
46
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
47
+ IN THE SOFTWARE.
48
+ """
49
+
50
+ This license applies to parts of Node.js originating from the
51
+ https://github.com/joyent/node repository:
52
+
53
+ """
54
+ Copyright Joyent, Inc. and other Node contributors. All rights reserved.
55
+ Permission is hereby granted, free of charge, to any person obtaining a copy
56
+ of this software and associated documentation files (the "Software"), to
57
+ deal in the Software without restriction, including without limitation the
58
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
59
+ sell copies of the Software, and to permit persons to whom the Software is
60
+ furnished to do so, subject to the following conditions:
61
+
62
+ The above copyright notice and this permission notice shall be included in
63
+ all copies or substantial portions of the Software.
64
+
65
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
66
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
67
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
68
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
69
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
70
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
71
+ IN THE SOFTWARE.
72
+ """
73
+
74
+
75
+ events 3.3.0
76
+ MIT
77
+
78
+ Copyright Joyent, Inc. and other Node contributors.
79
+
80
+ Permission is hereby granted, free of charge, to any person obtaining a
81
+ copy of this software and associated documentation files (the
82
+ "Software"), to deal in the Software without restriction, including
83
+ without limitation the rights to use, copy, modify, merge, publish,
84
+ distribute, sublicense, and/or sell copies of the Software, and to permit
85
+ persons to whom the Software is furnished to do so, subject to the
86
+ following conditions:
87
+
88
+ The above copyright notice and this permission notice shall be included
89
+ in all copies or substantial portions of the Software.
90
+
91
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
92
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
93
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
94
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
95
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
96
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
97
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
98
+
99
+
100
+ abort-controller 3.0.0
101
+ MIT License
102
+
103
+ Copyright (c) 2017 Toru Nagashima
104
+
105
+ Permission is hereby granted, free of charge, to any person obtaining a copy
106
+ of this software and associated documentation files (the "Software"), to deal
107
+ in the Software without restriction, including without limitation the rights
108
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
109
+ copies of the Software, and to permit persons to whom the Software is
110
+ furnished to do so, subject to the following conditions:
111
+
112
+ The above copyright notice and this permission notice shall be included in all
113
+ copies or substantial portions of the Software.
114
+
115
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
116
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
117
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
118
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
119
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
120
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
121
+ SOFTWARE.
122
+
123
+
124
+ event-target-shim 5.0.1
125
+ The MIT License (MIT)
126
+
127
+ Copyright (c) 2015 Toru Nagashima
128
+
129
+ Permission is hereby granted, free of charge, to any person obtaining a copy
130
+ of this software and associated documentation files (the "Software"), to deal
131
+ in the Software without restriction, including without limitation the rights
132
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
133
+ copies of the Software, and to permit persons to whom the Software is
134
+ furnished to do so, subject to the following conditions:
135
+
136
+ The above copyright notice and this permission notice shall be included in all
137
+ copies or substantial portions of the Software.
138
+
139
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
140
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
141
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
142
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
143
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
144
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
145
+ SOFTWARE.
146
+
147
+
148
+
149
+ base64-js 1.5.1
150
+ The MIT License (MIT)
151
+
152
+ Copyright (c) 2014 Jameson Little
153
+
154
+ Permission is hereby granted, free of charge, to any person obtaining a copy
155
+ of this software and associated documentation files (the "Software"), to deal
156
+ in the Software without restriction, including without limitation the rights
157
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
158
+ copies of the Software, and to permit persons to whom the Software is
159
+ furnished to do so, subject to the following conditions:
160
+
161
+ The above copyright notice and this permission notice shall be included in
162
+ all copies or substantial portions of the Software.
163
+
164
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
165
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
166
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
167
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
168
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
169
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
170
+ THE SOFTWARE.
171
+
172
+
173
+ ieee754 1.2.1
174
+ Copyright 2008 Fair Oaks Labs, Inc.
175
+
176
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
177
+
178
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
179
+
180
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
181
+
182
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
183
+
184
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
185
+
186
+
187
+ string_decoder 1.3.0
188
+ Node.js is licensed for use as follows:
189
+
190
+ """
191
+ Copyright Node.js contributors. All rights reserved.
192
+
193
+ Permission is hereby granted, free of charge, to any person obtaining a copy
194
+ of this software and associated documentation files (the "Software"), to
195
+ deal in the Software without restriction, including without limitation the
196
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
197
+ sell copies of the Software, and to permit persons to whom the Software is
198
+ furnished to do so, subject to the following conditions:
199
+
200
+ The above copyright notice and this permission notice shall be included in
201
+ all copies or substantial portions of the Software.
202
+
203
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
204
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
205
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
206
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
207
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
208
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
209
+ IN THE SOFTWARE.
210
+ """
211
+
212
+ This license applies to parts of Node.js originating from the
213
+ https://github.com/joyent/node repository:
214
+
215
+ """
216
+ Copyright Joyent, Inc. and other Node contributors. All rights reserved.
217
+ Permission is hereby granted, free of charge, to any person obtaining a copy
218
+ of this software and associated documentation files (the "Software"), to
219
+ deal in the Software without restriction, including without limitation the
220
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
221
+ sell copies of the Software, and to permit persons to whom the Software is
222
+ furnished to do so, subject to the following conditions:
223
+
224
+ The above copyright notice and this permission notice shall be included in
225
+ all copies or substantial portions of the Software.
226
+
227
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
228
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
229
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
230
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
231
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
232
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
233
+ IN THE SOFTWARE.
234
+ """
235
+
236
+
237
+
238
+ safe-buffer 5.2.1
239
+ The MIT License (MIT)
240
+
241
+ Copyright (c) Feross Aboukhadijeh
242
+
243
+ Permission is hereby granted, free of charge, to any person obtaining a copy
244
+ of this software and associated documentation files (the "Software"), to deal
245
+ in the Software without restriction, including without limitation the rights
246
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
247
+ copies of the Software, and to permit persons to whom the Software is
248
+ furnished to do so, subject to the following conditions:
249
+
250
+ The above copyright notice and this permission notice shall be included in
251
+ all copies or substantial portions of the Software.
252
+
253
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
254
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
255
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
256
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
257
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
258
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
259
+ THE SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wasm-oj/server",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Node.js compiler and runner host for the WASM-OJ SDK.",
5
5
  "license": "MIT",
6
6
  "author": "JacobLinCool",
@@ -58,8 +58,8 @@
58
58
  "node": ">=24.18.0 <25"
59
59
  },
60
60
  "dependencies": {
61
- "@wasm-oj/contracts": "0.2.1",
62
- "@wasm-oj/core": "0.2.1",
61
+ "@wasm-oj/contracts": "0.2.3",
62
+ "@wasm-oj/core": "0.2.3",
63
63
  "@wasmer/sdk": "0.10.0",
64
64
  "fflate": "0.8.3"
65
65
  },
@@ -1,44 +0,0 @@
1
- import { C as JAVA_COMPILE_CLASSLIB_ASSET_PATH, D as JAVA_VERSION, E as JAVA_RUNTIME_CLASSLIB_SHA256, S as JAVA_COMPILER_PACKAGE_SHA256, T as JAVA_RUNTIME_CLASSLIB_ASSET_PATH, b as JAVA_COMPILER_COMPRESSED_PACKAGE_SHA256, w as JAVA_COMPILE_CLASSLIB_SHA256, x as JAVA_COMPILER_PACKAGE, y as JAVA_COMPILER_ASSET_PATH } from "./toolchains-C6KuA1yM.js";
2
- //#region src/compiler/java-toolchain.ts
3
- var JAVA_COMPILE_TIMEOUT_MS = 18e4;
4
- Object.freeze({
5
- version: JAVA_VERSION,
6
- package: JAVA_COMPILER_PACKAGE,
7
- compilerAsset: JAVA_COMPILER_ASSET_PATH,
8
- compilerCompressedSha256: JAVA_COMPILER_COMPRESSED_PACKAGE_SHA256,
9
- compilerPackageSha256: JAVA_COMPILER_PACKAGE_SHA256,
10
- compileClasslibAsset: JAVA_COMPILE_CLASSLIB_ASSET_PATH,
11
- compileClasslibSha256: JAVA_COMPILE_CLASSLIB_SHA256,
12
- runtimeClasslibAsset: JAVA_RUNTIME_CLASSLIB_ASSET_PATH,
13
- runtimeClasslibSha256: JAVA_RUNTIME_CLASSLIB_SHA256
14
- });
15
- function javaMainClass(entry, source) {
16
- const className = entry.split("/").at(-1)?.replace(/\.java$/u, "") ?? "";
17
- if (!/^[A-Za-z_$][\w$]*$/u.test(className)) throw new Error(`Java entry '${entry}' must name a valid .java class file.`);
18
- const packageName = source.match(/^\s*package\s+([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\s*;/m)?.[1];
19
- return packageName ? `${packageName}.${className}` : className;
20
- }
21
- function parseJavaDiagnostics(output, fallbackFile) {
22
- const diagnostics = [];
23
- const pattern = /^(.*?\.java):(\d+)(?::(\d+))?:\s*(?:(error|warning):\s*)?(.+)$/gim;
24
- let match;
25
- while ((match = pattern.exec(output)) !== null) diagnostics.push({
26
- severity: match[4]?.toLowerCase() === "warning" ? "warning" : "error",
27
- message: match[5],
28
- file: match[1].replace(/^\/?(?:project|workspace)\//u, ""),
29
- line: Number(match[2]),
30
- column: Number(match[3] ?? 1),
31
- source: "java"
32
- });
33
- if (diagnostics.length === 0 && /(?:error|exception|failed)/iu.test(output)) diagnostics.push({
34
- severity: "error",
35
- message: output.trim().split(/\r?\n/u).filter(Boolean).at(-1) ?? "Java compilation failed.",
36
- file: fallbackFile,
37
- line: 1,
38
- column: 1,
39
- source: "java"
40
- });
41
- return diagnostics;
42
- }
43
- //#endregion
44
- export { javaMainClass as n, parseJavaDiagnostics as r, JAVA_COMPILE_TIMEOUT_MS as t };
@@ -1,4 +0,0 @@
1
- //#region src/compiler/python-toolchain.ts
2
- var PYTHON_COMPILE_TIMEOUT_MS = 18e4;
3
- //#endregion
4
- export { PYTHON_COMPILE_TIMEOUT_MS as t };
@@ -1,90 +0,0 @@
1
- import { A as PYTHON_PACKAGE_ASSET_PATH, O as PYTHON_COMPRESSED_PACKAGE_SHA256, j as PYTHON_PACKAGE_SHA256, k as PYTHON_PACKAGE } from "./chunks/toolchains-C6KuA1yM.js";
2
- import { t as PYTHON_COMPILE_TIMEOUT_MS } from "./chunks/python-toolchain-Dx834o2A.js";
3
- import { writeFileSync } from "node:fs";
4
- import { readFile } from "node:fs/promises";
5
- import { createHash } from "node:crypto";
6
- import path from "node:path";
7
- import { gunzipSync } from "node:zlib";
8
- import { Directory, Runtime, Wasmer, init } from "@wasmer/sdk/node";
9
- //#region src/server/python-stage.mjs
10
- var runtime;
11
- var exitCode = 0;
12
- try {
13
- const encoded = JSON.parse(await readStdin());
14
- await init({ log: "warn" });
15
- runtime = new Runtime({ registry: null });
16
- const pythonFiles = encoded.request.files.filter((file) => file.path.endsWith(".py"));
17
- const project = new Directory(Object.fromEntries(encoded.request.files.map((file) => [`/${file.path}`, file.content])));
18
- await project.createDir("/build");
19
- const packagePath = encoded?.toolchainAssets?.[PYTHON_PACKAGE_ASSET_PATH];
20
- if (typeof packagePath !== "string" || !path.isAbsolute(packagePath)) throw new Error(`The Python compiler stage did not receive absolute asset '${PYTHON_PACKAGE_ASSET_PATH}'.`);
21
- const compressed = await readFile(packagePath);
22
- if (encoded.verifiedToolchain !== true) verifyDigest(packagePath, compressed, PYTHON_COMPRESSED_PACKAGE_SHA256);
23
- const packageBytes = uint8View(gunzipSync(compressed));
24
- if (encoded.verifiedToolchain !== true) verifyDigest(packagePath, packageBytes, PYTHON_PACKAGE_SHA256);
25
- const command = (await Wasmer.fromFile(packageBytes, runtime)).commands.python;
26
- if (!command) throw new Error(`Package '${PYTHON_PACKAGE}' does not expose python.`);
27
- const instance = await command.run({
28
- args: ["-c", compileScript(pythonFiles.map((file) => file.path))],
29
- cwd: "/project",
30
- env: {
31
- PYTHONHOME: "/usr/local",
32
- PYTHONHASHSEED: "0",
33
- PYTHONDONTWRITEBYTECODE: "1"
34
- },
35
- mount: { "/project": project }
36
- });
37
- let timer;
38
- const output = await Promise.race([instance.wait(), new Promise((_, reject) => {
39
- timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Python compilation exceeded ${PYTHON_COMPILE_TIMEOUT_MS} ms.`)), PYTHON_COMPILE_TIMEOUT_MS);
40
- })]);
41
- clearTimeout(timer);
42
- const bytecodeBase64 = {};
43
- if (output.ok) for (const file of pythonFiles) {
44
- const compiledPath = `build/${file.path.replace(/\.py$/, ".pyc")}`;
45
- bytecodeBase64[compiledPath] = Buffer.from(await project.readFile(`/${compiledPath}`)).toString("base64");
46
- }
47
- writeFileSync(3, JSON.stringify({
48
- ok: true,
49
- result: {
50
- success: output.ok,
51
- bytecodeBase64,
52
- stdout: output.stdout,
53
- stderr: output.stderr,
54
- diagnostics: []
55
- }
56
- }));
57
- } catch (error) {
58
- writeFileSync(3, JSON.stringify({
59
- ok: false,
60
- error: error instanceof Error ? error.message : String(error)
61
- }));
62
- exitCode = 1;
63
- } finally {
64
- runtime?.free();
65
- setTimeout(() => process.exit(exitCode), 10);
66
- }
67
- function verifyDigest(filename, bytes, expected) {
68
- const actual = createHash("sha256").update(bytes).digest("hex");
69
- if (actual !== expected) throw new Error(`Pinned Python package '${filename}' has digest ${actual}; expected ${expected}.`);
70
- }
71
- function uint8View(bytes) {
72
- return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
73
- }
74
- function compileScript(files) {
75
- return [
76
- "import pathlib, py_compile",
77
- `files = ${JSON.stringify(files)}`,
78
- "for name in files:",
79
- " output = pathlib.Path('/project/build') / pathlib.Path(name).with_suffix('.pyc')",
80
- " output.parent.mkdir(parents=True, exist_ok=True)",
81
- " py_compile.compile('/project/' + name, cfile=str(output), doraise=True, invalidation_mode=py_compile.PycInvalidationMode.CHECKED_HASH)"
82
- ].join("\n");
83
- }
84
- async function readStdin() {
85
- const chunks = [];
86
- for await (const chunk of process.stdin) chunks.push(chunk);
87
- return Buffer.concat(chunks).toString("utf8");
88
- }
89
- //#endregion
90
- export {};