@heojeongbo/wasmgen 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +342 -2
- package/dist/adapters/compiler.d.ts +13 -0
- package/dist/adapters/compiler.js +1 -0
- package/dist/adapters/cpp/bridge.d.ts +2 -0
- package/dist/adapters/cpp/bridge.js +59 -0
- package/dist/adapters/cpp/compiler.d.ts +2 -0
- package/dist/adapters/cpp/compiler.js +32 -0
- package/dist/adapters/cpp/worker.d.ts +1 -0
- package/dist/adapters/cpp/worker.js +7 -0
- package/dist/adapters/go/bridge.d.ts +2 -0
- package/dist/adapters/go/bridge.js +93 -0
- package/dist/adapters/go/compiler.d.ts +2 -0
- package/dist/adapters/go/compiler.js +64 -0
- package/dist/adapters/go/worker.d.ts +1 -0
- package/dist/adapters/go/worker.js +18 -0
- package/dist/application/generate.d.ts +9 -0
- package/dist/application/generate.js +28 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +40 -0
- package/dist/codegen/web.d.ts +5 -0
- package/dist/codegen/web.js +48 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.js +76 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +6 -0
- package/dist/licenses/COMPILER-RT-LICENSE +311 -0
- package/dist/licenses/EMSCRIPTEN-LICENSE +102 -0
- package/dist/licenses/GO-LICENSE +27 -0
- package/dist/licenses/LIBCXX-LICENSE +311 -0
- package/dist/licenses/LIBCXXABI-LICENSE +311 -0
- package/dist/licenses/MUSL-COPYRIGHT +193 -0
- package/dist/licenses/README.md +23 -0
- package/dist/model/config.d.ts +142 -0
- package/dist/model/config.js +18 -0
- package/dist/model/value-types.d.ts +3 -0
- package/dist/model/value-types.js +1 -0
- package/dist/process.d.ts +7 -0
- package/dist/process.js +23 -0
- package/dist/runtime/client.d.ts +17 -0
- package/dist/runtime/client.js +95 -0
- package/dist/runtime/protocol.d.ts +34 -0
- package/dist/runtime/protocol.js +14 -0
- package/dist/runtime/worker.d.ts +6 -0
- package/dist/runtime/worker.js +86 -0
- package/dist/shared/errors.d.ts +2 -0
- package/dist/shared/errors.js +2 -0
- package/dist/storage/output.d.ts +2 -0
- package/dist/storage/output.js +96 -0
- package/package.json +53 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { valueTypes } from './value-types.js';
|
|
3
|
+
const reserved = new Set('await break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof var void while with yield arguments eval dispose constructor prototype __proto__'.split(' '));
|
|
4
|
+
const text = z.string().min(1).refine((value) => Boolean(value.trim()) && !/[\x00-\x1f]/.test(value), 'expected nonempty text without control characters');
|
|
5
|
+
const identifier = text.refine((value) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(value) && !reserved.has(value), 'invalid identifier');
|
|
6
|
+
const exportName = identifier.refine((value) => value !== 'then', 'then is reserved to prevent Promise assimilation');
|
|
7
|
+
const valueType = z.enum(valueTypes);
|
|
8
|
+
const parameter = z.strictObject({ name: identifier, type: valueType });
|
|
9
|
+
const fn = z.strictObject({ symbol: text.optional(), params: z.array(parameter).default([]), result: z.enum([...valueTypes, 'void']), error: z.boolean().optional() });
|
|
10
|
+
const input = z.strictObject({
|
|
11
|
+
name: exportName, language: z.enum(['go', 'cpp']), files: z.array(text).min(1).optional(),
|
|
12
|
+
headers: z.array(text).optional(), include: z.array(text).optional(), package: text.optional(),
|
|
13
|
+
exports: z.record(exportName, fn).refine((value) => Object.keys(value).length > 0, 'expected at least one function'),
|
|
14
|
+
});
|
|
15
|
+
export const configSchema = z.strictObject({
|
|
16
|
+
version: z.literal(1), output: text, input: z.array(input).min(1),
|
|
17
|
+
tools: z.strictObject({ go: text.optional(), cpp: text.optional() }).default({}),
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const valueTypes = ['i32', 'u32', 'f64', 'bool', 'string', 'i32[]', 'u32[]', 'f64[]'];
|
package/dist/process.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
// No shell: paths and compiler arguments are passed as distinct values.
|
|
3
|
+
export function run(command, args, options = {}) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const child = spawn(command, args, { cwd: options.cwd, env: options.env ?? process.env, stdio: ['ignore', 'pipe', 'pipe'], signal: options.signal });
|
|
6
|
+
let stdout = '';
|
|
7
|
+
let stderr = '';
|
|
8
|
+
let failure;
|
|
9
|
+
child.stdout.on('data', (data) => { stdout = (stdout + data).slice(-2_000_000); });
|
|
10
|
+
child.stderr.on('data', (data) => { stderr = (stderr + data).slice(-2_000_000); });
|
|
11
|
+
// An abort emits error before close. Wait for close before callers remove
|
|
12
|
+
// scratch directories that the compiler may still be using.
|
|
13
|
+
child.on('error', (error) => { failure = new Error(`cannot run ${command}: ${error.message}`, { cause: error }); });
|
|
14
|
+
child.on('close', (code) => {
|
|
15
|
+
if (failure)
|
|
16
|
+
reject(failure);
|
|
17
|
+
else if (code === 0)
|
|
18
|
+
resolve(stdout.trim());
|
|
19
|
+
else
|
|
20
|
+
reject(new Error(`${command} exited with ${code}\n${stderr || stdout}`));
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type CallRequest } from './protocol.js';
|
|
2
|
+
export interface ClientOptions {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface Client {
|
|
7
|
+
call(method: string, args: unknown[]): Promise<unknown>;
|
|
8
|
+
dispose(): void;
|
|
9
|
+
}
|
|
10
|
+
export interface WorkerPort {
|
|
11
|
+
postMessage(message: CallRequest): void;
|
|
12
|
+
terminate(): void;
|
|
13
|
+
onerror: ((event: ErrorEvent) => void) | null;
|
|
14
|
+
onmessageerror: (() => void) | null;
|
|
15
|
+
onmessage: ((event: MessageEvent<unknown>) => void) | null;
|
|
16
|
+
}
|
|
17
|
+
export declare function connect(workerFactory: () => WorkerPort, options?: ClientOptions): Promise<Client>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { isResponse } from './protocol.js';
|
|
2
|
+
// Code generated by wasmgen. DO NOT EDIT.
|
|
3
|
+
export function connect(workerFactory, options = {}) {
|
|
4
|
+
const timeoutMs = options.timeoutMs ?? 30_000;
|
|
5
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > 2_147_483_647) {
|
|
6
|
+
return Promise.reject(new TypeError('timeoutMs must be between 1 and 2147483647'));
|
|
7
|
+
}
|
|
8
|
+
if (options.signal?.aborted)
|
|
9
|
+
return Promise.reject(options.signal?.reason ?? new Error('wasmgen aborted'));
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
let worker;
|
|
12
|
+
try {
|
|
13
|
+
worker = workerFactory();
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
reject(error);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let closed = false;
|
|
20
|
+
let ready = false;
|
|
21
|
+
let sequence = 0;
|
|
22
|
+
const pending = new Map();
|
|
23
|
+
const stop = (reason = new Error('wasmgen client disposed')) => {
|
|
24
|
+
if (closed)
|
|
25
|
+
return;
|
|
26
|
+
closed = true;
|
|
27
|
+
clearTimeout(initialTimer);
|
|
28
|
+
options.signal?.removeEventListener('abort', abort);
|
|
29
|
+
worker.terminate();
|
|
30
|
+
if (!ready)
|
|
31
|
+
reject(reason);
|
|
32
|
+
for (const request of pending.values()) {
|
|
33
|
+
clearTimeout(request.timer);
|
|
34
|
+
request.reject(reason);
|
|
35
|
+
}
|
|
36
|
+
pending.clear();
|
|
37
|
+
};
|
|
38
|
+
const abort = () => stop(options.signal?.reason ?? new Error('wasmgen aborted'));
|
|
39
|
+
const initialTimer = setTimeout(() => stop(new Error('wasmgen initialization timed out')), timeoutMs);
|
|
40
|
+
options.signal?.addEventListener('abort', abort, { once: true });
|
|
41
|
+
worker.onerror = (event) => {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
stop(new Error(event.message || 'wasmgen worker failed'));
|
|
44
|
+
};
|
|
45
|
+
worker.onmessageerror = () => stop(new Error('wasmgen worker message could not be decoded'));
|
|
46
|
+
worker.onmessage = ({ data }) => {
|
|
47
|
+
if (closed)
|
|
48
|
+
return;
|
|
49
|
+
if (!isResponse(data)) {
|
|
50
|
+
stop(new Error('invalid worker response'));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (data.type === 'fatal') {
|
|
54
|
+
stop(new Error(data.error));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (data.type === 'ready') {
|
|
58
|
+
if (ready)
|
|
59
|
+
return;
|
|
60
|
+
ready = true;
|
|
61
|
+
clearTimeout(initialTimer);
|
|
62
|
+
resolve({
|
|
63
|
+
call(method, args) {
|
|
64
|
+
if (closed)
|
|
65
|
+
return Promise.reject(new Error('wasmgen client disposed'));
|
|
66
|
+
return new Promise((resolveCall, rejectCall) => {
|
|
67
|
+
const id = ++sequence;
|
|
68
|
+
const timer = setTimeout(() => stop(new Error(`wasmgen call ${method} timed out`)), timeoutMs);
|
|
69
|
+
pending.set(id, { resolve: resolveCall, reject: rejectCall, timer });
|
|
70
|
+
try {
|
|
71
|
+
worker.postMessage({ id, method, args });
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
pending.delete(id);
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
rejectCall(error);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
dispose: () => stop(),
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const request = pending.get(data.id);
|
|
85
|
+
if (!request)
|
|
86
|
+
return;
|
|
87
|
+
pending.delete(data.id);
|
|
88
|
+
clearTimeout(request.timer);
|
|
89
|
+
if (data.ok)
|
|
90
|
+
request.resolve(data.value);
|
|
91
|
+
else
|
|
92
|
+
request.reject(new Error(data.error));
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ResultType, ValueType } from '../model/value-types.js';
|
|
2
|
+
export interface CallRequest {
|
|
3
|
+
id: number;
|
|
4
|
+
method: string;
|
|
5
|
+
args: unknown[];
|
|
6
|
+
}
|
|
7
|
+
export type NativeResult = {
|
|
8
|
+
ok: true;
|
|
9
|
+
value?: unknown;
|
|
10
|
+
} | {
|
|
11
|
+
ok: false;
|
|
12
|
+
error: string;
|
|
13
|
+
};
|
|
14
|
+
export type WorkerResponse = {
|
|
15
|
+
type: 'ready';
|
|
16
|
+
} | {
|
|
17
|
+
type: 'fatal';
|
|
18
|
+
error: string;
|
|
19
|
+
} | ({
|
|
20
|
+
type: 'result';
|
|
21
|
+
id: number;
|
|
22
|
+
} & NativeResult);
|
|
23
|
+
export interface FunctionSchema {
|
|
24
|
+
params: {
|
|
25
|
+
name: string;
|
|
26
|
+
type: ValueType;
|
|
27
|
+
}[];
|
|
28
|
+
result: ResultType;
|
|
29
|
+
}
|
|
30
|
+
export type Schema = Record<string, FunctionSchema>;
|
|
31
|
+
export type NativeCall = (method: string, args: unknown[]) => NativeResult | Promise<NativeResult>;
|
|
32
|
+
export declare function isRequest(value: unknown): value is CallRequest;
|
|
33
|
+
export declare function isResponse(value: unknown): value is WorkerResponse;
|
|
34
|
+
export declare function message(error: unknown): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function object(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); }
|
|
2
|
+
export function isRequest(value) {
|
|
3
|
+
return object(value) && Number.isSafeInteger(value['id']) && typeof value['method'] === 'string' && Array.isArray(value['args']);
|
|
4
|
+
}
|
|
5
|
+
export function isResponse(value) {
|
|
6
|
+
if (!object(value))
|
|
7
|
+
return false;
|
|
8
|
+
if (value['type'] === 'ready')
|
|
9
|
+
return true;
|
|
10
|
+
if (value['type'] === 'fatal')
|
|
11
|
+
return typeof value['error'] === 'string';
|
|
12
|
+
return value['type'] === 'result' && Number.isSafeInteger(value['id']) && (value['ok'] === true || (value['ok'] === false && typeof value['error'] === 'string'));
|
|
13
|
+
}
|
|
14
|
+
export function message(error) { return error instanceof Error ? error.message : String(error); }
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type NativeCall, type Schema, type WorkerResponse } from './protocol.js';
|
|
2
|
+
export interface WorkerScope {
|
|
3
|
+
postMessage(message: WorkerResponse): void;
|
|
4
|
+
onmessage: ((event: MessageEvent<unknown>) => void) | null;
|
|
5
|
+
}
|
|
6
|
+
export declare function serve(initialize: () => Promise<NativeCall>, schema: Schema, scope?: WorkerScope): Promise<void>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { isRequest, message } from './protocol.js';
|
|
2
|
+
// Code generated by wasmgen. DO NOT EDIT.
|
|
3
|
+
function check(value, type, at) {
|
|
4
|
+
if (type === 'void')
|
|
5
|
+
return;
|
|
6
|
+
if (type.endsWith('[]')) {
|
|
7
|
+
if (!Array.isArray(value))
|
|
8
|
+
throw new TypeError(`${at}: expected ${type}`);
|
|
9
|
+
for (let index = 0; index < value.length; index++)
|
|
10
|
+
check(value[index], type.slice(0, -2), `${at}[${index}]`);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
let valid;
|
|
14
|
+
switch (type) {
|
|
15
|
+
case 'string':
|
|
16
|
+
valid = typeof value === 'string';
|
|
17
|
+
break;
|
|
18
|
+
case 'bool':
|
|
19
|
+
valid = typeof value === 'boolean';
|
|
20
|
+
break;
|
|
21
|
+
case 'f64':
|
|
22
|
+
valid = typeof value === 'number' && Number.isFinite(value);
|
|
23
|
+
break;
|
|
24
|
+
case 'i32':
|
|
25
|
+
valid = typeof value === 'number' && Number.isInteger(value) && value >= -2147483648 && value <= 2147483647;
|
|
26
|
+
break;
|
|
27
|
+
case 'u32':
|
|
28
|
+
valid = typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= 4294967295;
|
|
29
|
+
break;
|
|
30
|
+
default: throw new TypeError(`unsupported type ${type}`);
|
|
31
|
+
}
|
|
32
|
+
if (!valid)
|
|
33
|
+
throw new TypeError(`${at}: expected ${type}`);
|
|
34
|
+
}
|
|
35
|
+
export async function serve(initialize, schema, scope = self) {
|
|
36
|
+
let call;
|
|
37
|
+
try {
|
|
38
|
+
call = await initialize();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
scope.postMessage({ type: 'fatal', error: message(error) });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let queue = Promise.resolve();
|
|
45
|
+
let failed = false;
|
|
46
|
+
scope.onmessage = ({ data }) => {
|
|
47
|
+
if (failed)
|
|
48
|
+
return;
|
|
49
|
+
if (!isRequest(data)) {
|
|
50
|
+
failed = true;
|
|
51
|
+
scope.postMessage({ type: 'fatal', error: 'invalid worker request' });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Await native Promises without letting later calls overtake earlier ones.
|
|
55
|
+
queue = queue.then(async () => {
|
|
56
|
+
if (failed)
|
|
57
|
+
return;
|
|
58
|
+
const { id, method, args } = data;
|
|
59
|
+
try {
|
|
60
|
+
if (!Object.hasOwn(schema, method) || !schema[method])
|
|
61
|
+
throw new Error(`unknown function ${method}`);
|
|
62
|
+
const fn = schema[method];
|
|
63
|
+
if (!Array.isArray(args) || args.length !== fn.params.length)
|
|
64
|
+
throw new TypeError(`${method}: expected ${fn.params.length} arguments`);
|
|
65
|
+
fn.params.forEach((param, index) => check(args[index], param.type, `${method}.${param.name}`));
|
|
66
|
+
const result = await call(method, args);
|
|
67
|
+
if (!result.ok)
|
|
68
|
+
throw new Error(result.error);
|
|
69
|
+
// nil Go slices encode as null; the public array contract always returns [].
|
|
70
|
+
const value = fn.result.endsWith('[]') && result.value === null ? [] : result.value;
|
|
71
|
+
check(value, fn.result, `${method} result`);
|
|
72
|
+
scope.postMessage({ type: 'result', id, ok: true, value: fn.result === 'void' ? undefined : value });
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (error instanceof WebAssembly.RuntimeError) {
|
|
76
|
+
failed = true;
|
|
77
|
+
scope.postMessage({ type: 'fatal', error: error.message });
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
scope.postMessage({ type: 'result', id, ok: false, error: message(error) });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}).catch((error) => { failed = true; scope.postMessage({ type: 'fatal', error: message(error) }); });
|
|
84
|
+
};
|
|
85
|
+
scope.postMessage({ type: 'ready' });
|
|
86
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, lstat, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { hasCode } from '../shared/errors.js';
|
|
5
|
+
export async function filesIn(directory, prefix = '') {
|
|
6
|
+
const result = [];
|
|
7
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
8
|
+
const relative = prefix + entry.name;
|
|
9
|
+
if (entry.isSymbolicLink())
|
|
10
|
+
throw new Error(`output contains a symbolic link: ${relative}`);
|
|
11
|
+
if (entry.isDirectory())
|
|
12
|
+
result.push(...await filesIn(path.join(directory, entry.name), relative + '/'));
|
|
13
|
+
else
|
|
14
|
+
result.push(relative);
|
|
15
|
+
}
|
|
16
|
+
return result.sort();
|
|
17
|
+
}
|
|
18
|
+
async function inspectOutput(output) {
|
|
19
|
+
try {
|
|
20
|
+
const info = await lstat(output);
|
|
21
|
+
if (!info.isDirectory() || info.isSymbolicLink())
|
|
22
|
+
throw new Error(`output must be a real directory: ${output}`);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (hasCode(error, 'ENOENT'))
|
|
26
|
+
return false;
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
const files = await filesIn(output);
|
|
30
|
+
if (!files.length)
|
|
31
|
+
return true;
|
|
32
|
+
let manifest;
|
|
33
|
+
try {
|
|
34
|
+
manifest = z.object({ generator: z.literal('wasmgen'), files: z.array(z.string()) }).parse(JSON.parse(await readFile(path.join(output, '.wasmgen.json'), 'utf8')));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw new Error(`refusing to replace output not owned by wasmgen: ${output}`);
|
|
38
|
+
}
|
|
39
|
+
if (manifest.generator !== 'wasmgen' || !Array.isArray(manifest.files))
|
|
40
|
+
throw new Error(`invalid output manifest: ${output}`);
|
|
41
|
+
const owned = new Set([...manifest.files, '.wasmgen.json']);
|
|
42
|
+
for (const file of files)
|
|
43
|
+
if (!owned.has(file))
|
|
44
|
+
throw new Error(`refusing to delete unmanaged output file: ${file}`);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
export async function withOutput(output, build, signal) {
|
|
48
|
+
const parent = path.dirname(output);
|
|
49
|
+
await mkdir(parent, { recursive: true });
|
|
50
|
+
const lock = output + '.wasmgen-lock';
|
|
51
|
+
try {
|
|
52
|
+
await mkdir(lock);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (hasCode(error, 'EEXIST'))
|
|
56
|
+
throw new Error(`another generation owns ${lock}; remove it only if no generator is running`);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
let staging;
|
|
60
|
+
let backup;
|
|
61
|
+
let preserveStaging = false;
|
|
62
|
+
try {
|
|
63
|
+
await inspectOutput(output);
|
|
64
|
+
staging = await mkdtemp(path.join(parent, '.wasmgen-stage-'));
|
|
65
|
+
const result = path.join(staging, 'output');
|
|
66
|
+
await mkdir(result);
|
|
67
|
+
await build(staging, result);
|
|
68
|
+
await writeFile(path.join(result, '.wasmgen.json'), JSON.stringify({ generator: 'wasmgen', version: 1, files: await filesIn(result) }, null, 2) + '\n');
|
|
69
|
+
signal?.throwIfAborted();
|
|
70
|
+
// Check again: an editor may have added an unmanaged file during compilation.
|
|
71
|
+
if (await inspectOutput(output)) {
|
|
72
|
+
backup = path.join(staging, 'previous');
|
|
73
|
+
await rename(output, backup);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
await rename(result, output);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (backup) {
|
|
80
|
+
try {
|
|
81
|
+
await rename(backup, output);
|
|
82
|
+
}
|
|
83
|
+
catch (restoreError) {
|
|
84
|
+
preserveStaging = true;
|
|
85
|
+
throw new AggregateError([error, restoreError], `cannot restore previous output; preserved at ${backup}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
if (staging && !preserveStaging)
|
|
93
|
+
await rm(staging, { recursive: true, force: true });
|
|
94
|
+
await rm(lock, { recursive: true, force: true });
|
|
95
|
+
}
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heojeongbo/wasmgen",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Generate browser WebAssembly modules and typed clients from Go and C++ sources.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"bin": {
|
|
8
|
+
"wasmgen": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=22"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/heojeongbo/wasmgen.git"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public",
|
|
30
|
+
"registry": "https://registry.npmjs.org"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"yaml": "2.9.0",
|
|
34
|
+
"zod": "4.6.7"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"playwright": "1.60.0",
|
|
38
|
+
"typescript": "5.9.3",
|
|
39
|
+
"vite": "7.3.8",
|
|
40
|
+
"@types/node": "24.3.0",
|
|
41
|
+
"tsx": "4.20.4"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsx scripts/build.ts",
|
|
45
|
+
"check": "pnpm run typecheck && pnpm run architecture:check",
|
|
46
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
47
|
+
"typecheck:generated": "tsc --noEmit -p test/types/tsconfig.json",
|
|
48
|
+
"architecture:check": "tsx scripts/check-architecture.ts",
|
|
49
|
+
"test:compile": "tsc -p test/tsconfig.json",
|
|
50
|
+
"test": "pnpm run build && pnpm run test:compile && node --test .test-build/test/*.test.js",
|
|
51
|
+
"test:e2e": "pnpm run build && pnpm run gen:example && pnpm run typecheck:generated && pnpm run test:compile:e2e && node .test-build/test/e2e/run.js",
|
|
52
|
+
"test:package": "pnpm run build && pnpm run gen:example && pnpm run test:compile:e2e && node .test-build/test/e2e/package.js",
|
|
53
|
+
"test:compile:e2e": "tsc -p test/e2e/tsconfig.json",
|
|
54
|
+
"gen:example": "node dist/cli.js gen --config examples/wasmgen.yaml"
|
|
55
|
+
}
|
|
6
56
|
}
|