@codemod.com/codemod-sandbox 0.1.0 → 0.1.2
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.
- package/dist/src/node-exports.d.ts +1 -1
- package/dist/src/node.d.ts +8 -0
- package/dist/src/node.js +18 -2
- package/package.json +2 -2
- package/sandbox.wasm +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
export { NodeSandbox } from "./node.js";
|
|
1
|
+
export { NodeSandbox, type LogEntry } from "./node.js";
|
package/dist/src/node.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import type { ModuleSpec, Sandbox } from "./types.js";
|
|
2
2
|
import type { UUID } from "./types.js";
|
|
3
3
|
export { NodeSandbox };
|
|
4
|
+
export interface LogEntry {
|
|
5
|
+
timestamp: number;
|
|
6
|
+
level: "info" | "warn" | "error";
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
4
9
|
declare class NodeSandbox implements Sandbox {
|
|
5
10
|
private readonly runtimeBuffer;
|
|
6
11
|
private sandbox;
|
|
12
|
+
private logs;
|
|
7
13
|
constructor(buffer?: Buffer);
|
|
8
14
|
initializeTreeSitter(locateFile: (path: string) => string): Promise<void>;
|
|
9
15
|
setupParser(lang: string, path: string): Promise<void>;
|
|
16
|
+
getLogs(): LogEntry[];
|
|
17
|
+
clearLogs(): void;
|
|
10
18
|
private getWasmInstance;
|
|
11
19
|
getWasmExports(): Promise<{
|
|
12
20
|
scanFind: (src: string, configs: any[]) => any;
|
package/dist/src/node.js
CHANGED
|
@@ -10,6 +10,7 @@ async function loadWasmRuntime() {
|
|
|
10
10
|
class NodeSandbox {
|
|
11
11
|
runtimeBuffer;
|
|
12
12
|
sandbox = null;
|
|
13
|
+
logs = [];
|
|
13
14
|
constructor(buffer) {
|
|
14
15
|
this.runtimeBuffer = buffer ? Promise.resolve(buffer) : loadWasmRuntime();
|
|
15
16
|
}
|
|
@@ -21,6 +22,12 @@ class NodeSandbox {
|
|
|
21
22
|
const instance = await this.getWasmInstance();
|
|
22
23
|
return instance.setupParser(lang, path);
|
|
23
24
|
}
|
|
25
|
+
getLogs() {
|
|
26
|
+
return this.logs;
|
|
27
|
+
}
|
|
28
|
+
clearLogs() {
|
|
29
|
+
this.logs = [];
|
|
30
|
+
}
|
|
24
31
|
async getWasmInstance() {
|
|
25
32
|
if (this.sandbox) {
|
|
26
33
|
return this.sandbox;
|
|
@@ -28,8 +35,16 @@ class NodeSandbox {
|
|
|
28
35
|
const wasmBytes = await this.runtimeBuffer;
|
|
29
36
|
const wasiInstance = new WASI([], [], [
|
|
30
37
|
new OpenFile(new WasiFile([])), // stdin
|
|
31
|
-
ConsoleStdout.lineBuffered((message) =>
|
|
32
|
-
|
|
38
|
+
ConsoleStdout.lineBuffered((message) => this.logs.push({
|
|
39
|
+
timestamp: Date.now(),
|
|
40
|
+
level: "info",
|
|
41
|
+
message,
|
|
42
|
+
})),
|
|
43
|
+
ConsoleStdout.lineBuffered((message) => this.logs.push({
|
|
44
|
+
timestamp: Date.now(),
|
|
45
|
+
level: "warn",
|
|
46
|
+
message,
|
|
47
|
+
})),
|
|
33
48
|
]);
|
|
34
49
|
const sandboxFactory = factory();
|
|
35
50
|
const { instance } = await WebAssembly.instantiate(wasmBytes, {
|
|
@@ -62,6 +77,7 @@ class NodeSandbox {
|
|
|
62
77
|
if (!moduleCode) {
|
|
63
78
|
return { $error: `Unable to find module "${moduleName}"` };
|
|
64
79
|
}
|
|
80
|
+
this.clearLogs();
|
|
65
81
|
const instance = await this.getWasmInstance();
|
|
66
82
|
const executionResult = await instance.run_module(sessionId, operation, moduleName, moduleRegistry, moduleCode, JSON.stringify(moduleInputs));
|
|
67
83
|
return JSON.parse(executionResult);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemod.com/codemod-sandbox",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Codemod Javascript Sandbox",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"scripts": {
|
|
15
15
|
"prepack": "pnpm run build",
|
|
16
|
-
"build:rs": "cd ../.. && cargo run -p codemod-sandbox-build --color=always -- -r",
|
|
16
|
+
"build:rs": "cd ../.. && cargo run -p codemod-sandbox-build --color=always -- -r --optimize",
|
|
17
17
|
"copy-runtime-files": "pnpm run build:rs && tsx scripts/copy-runtime-files.ts",
|
|
18
18
|
"generate-type-declarations": "tsx scripts/generate-type-declarations.ts",
|
|
19
19
|
"build:tsc": "pnpm run generate-type-declarations && tsc --project tsconfig.build.json --pretty",
|
package/sandbox.wasm
CHANGED
|
Binary file
|