@bytecodealliance/jco 1.16.1 → 1.17.1
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/README.md +6 -6
- package/obj/interfaces/wasi-filesystem-types.d.ts +29 -28
- package/obj/js-component-bindgen-component.core.wasm +0 -0
- package/obj/js-component-bindgen-component.core2.wasm +0 -0
- package/obj/js-component-bindgen-component.js +7821 -5929
- package/obj/wasm-tools.core.wasm +0 -0
- package/obj/wasm-tools.core2.wasm +0 -0
- package/obj/wasm-tools.js +7827 -5805
- package/package.json +94 -95
- package/src/api.js +5 -14
- package/src/browser.js +1 -1
- package/src/cmd/componentize.d.ts +1 -1
- package/src/cmd/componentize.js +14 -18
- package/src/cmd/opt.d.ts +10 -7
- package/src/cmd/opt.js +44 -96
- package/src/cmd/run.d.ts +1 -1
- package/src/cmd/run.js +31 -48
- package/src/cmd/transpile.d.ts +44 -39
- package/src/cmd/transpile.js +253 -316
- package/src/cmd/types.d.ts +15 -12
- package/src/cmd/types.js +27 -36
- package/src/cmd/wasm-tools.d.ts +1 -1
- package/src/cmd/wasm-tools.js +27 -44
- package/src/common.js +43 -57
- package/src/jco.js +200 -347
- package/types/api.d.ts.map +1 -1
- package/types/common.d.ts.map +1 -1
package/src/cmd/run.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { rm, mkdir, writeFile, symlink } from
|
|
2
|
-
import { basename, resolve, extname } from
|
|
3
|
-
import { spawn } from
|
|
4
|
-
import process from
|
|
5
|
-
import { fileURLToPath, pathToFileURL } from
|
|
1
|
+
import { rm, mkdir, writeFile, symlink } from "node:fs/promises";
|
|
2
|
+
import { basename, resolve, extname } from "node:path";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
6
|
|
|
7
|
-
import { getTmpDir, styleText } from
|
|
8
|
-
import { transpile } from
|
|
7
|
+
import { getTmpDir, styleText } from "../common.js";
|
|
8
|
+
import { transpile } from "./transpile.js";
|
|
9
9
|
|
|
10
|
-
const DEFAULT_SERVE_HOST =
|
|
10
|
+
const DEFAULT_SERVE_HOST = "localhost";
|
|
11
11
|
|
|
12
12
|
export async function run(componentPath, args, opts) {
|
|
13
13
|
// Ensure that `args` is an array
|
|
@@ -31,7 +31,7 @@ export async function run(componentPath, args, opts) {
|
|
|
31
31
|
console.error(e);
|
|
32
32
|
process.exit(1);
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
`,
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -40,7 +40,7 @@ export async function serve(componentPath, args, opts) {
|
|
|
40
40
|
let { port, host } = opts;
|
|
41
41
|
if (port === undefined) {
|
|
42
42
|
tryFindPort = true;
|
|
43
|
-
port =
|
|
43
|
+
port = "8000";
|
|
44
44
|
}
|
|
45
45
|
// Ensure that `args` is an array
|
|
46
46
|
args = [...args];
|
|
@@ -54,8 +54,8 @@ export async function serve(componentPath, args, opts) {
|
|
|
54
54
|
const server = new HTTPServer(mod.incomingHandler);
|
|
55
55
|
let port = ${port};
|
|
56
56
|
${
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
tryFindPort
|
|
58
|
+
? `
|
|
59
59
|
while (true) {
|
|
60
60
|
try {
|
|
61
61
|
server.listen(port, ${JSON.stringify(host)});
|
|
@@ -67,19 +67,17 @@ export async function serve(componentPath, args, opts) {
|
|
|
67
67
|
port++;
|
|
68
68
|
}
|
|
69
69
|
`
|
|
70
|
-
|
|
71
|
-
}
|
|
70
|
+
: `server.listen(port, ${JSON.stringify(host)})`
|
|
71
|
+
}
|
|
72
72
|
console.error(\`Server listening @ ${host}:${port}...\`);
|
|
73
|
-
|
|
73
|
+
`,
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
async function runComponent(componentPath, args, opts, executor) {
|
|
78
78
|
const jcoImport = opts.jcoImport ? resolve(opts.jcoImport) : null;
|
|
79
79
|
|
|
80
|
-
const name = basename(
|
|
81
|
-
componentPath.slice(0, -extname(componentPath).length || Infinity)
|
|
82
|
-
);
|
|
80
|
+
const name = basename(componentPath.slice(0, -extname(componentPath).length || Infinity));
|
|
83
81
|
const outDir = opts.jcoDir || (await getTmpDir());
|
|
84
82
|
if (opts.jcoDir) {
|
|
85
83
|
await mkdir(outDir, { recursive: true });
|
|
@@ -98,57 +96,48 @@ async function runComponent(componentPath, args, opts, executor) {
|
|
|
98
96
|
importBindings: opts.jcoImportBindings,
|
|
99
97
|
});
|
|
100
98
|
} catch (e) {
|
|
101
|
-
throw new Error(
|
|
99
|
+
throw new Error("Unable to transpile command for execution", {
|
|
102
100
|
cause: e,
|
|
103
101
|
});
|
|
104
102
|
}
|
|
105
103
|
|
|
106
|
-
await writeFile(
|
|
107
|
-
resolve(outDir, 'package.json'),
|
|
108
|
-
JSON.stringify({ type: 'module' })
|
|
109
|
-
);
|
|
104
|
+
await writeFile(resolve(outDir, "package.json"), JSON.stringify({ type: "module" }));
|
|
110
105
|
|
|
111
106
|
let preview2ShimPath;
|
|
112
107
|
try {
|
|
113
108
|
preview2ShimPath = resolve(
|
|
114
|
-
fileURLToPath(
|
|
115
|
-
|
|
116
|
-
),
|
|
117
|
-
'../../../'
|
|
109
|
+
fileURLToPath(import.meta.resolve("@bytecodealliance/preview2-shim")),
|
|
110
|
+
"../../../",
|
|
118
111
|
);
|
|
119
112
|
} catch (err) {
|
|
120
|
-
let msg = `${styleText([
|
|
113
|
+
let msg = `${styleText(["red", "bold"], "error")} Failed to resolve ${styleText("bold", "@bytecodealliance/preview2-shim")}, ensure it is installed.`;
|
|
121
114
|
msg += `\nERROR:\n${err.toString()}`;
|
|
122
115
|
throw new Error(msg);
|
|
123
116
|
}
|
|
124
117
|
|
|
125
|
-
const modulesDir = resolve(outDir,
|
|
118
|
+
const modulesDir = resolve(outDir, "node_modules", "@bytecodealliance");
|
|
126
119
|
await mkdir(modulesDir, { recursive: true });
|
|
127
120
|
|
|
128
121
|
try {
|
|
129
|
-
await symlink(
|
|
130
|
-
preview2ShimPath,
|
|
131
|
-
resolve(modulesDir, 'preview2-shim'),
|
|
132
|
-
'dir'
|
|
133
|
-
);
|
|
122
|
+
await symlink(preview2ShimPath, resolve(modulesDir, "preview2-shim"), "dir");
|
|
134
123
|
} catch (e) {
|
|
135
|
-
if (e.code !==
|
|
124
|
+
if (e.code !== "EEXIST") {
|
|
136
125
|
throw e;
|
|
137
126
|
}
|
|
138
127
|
}
|
|
139
128
|
|
|
140
|
-
const runPath = resolve(outDir,
|
|
129
|
+
const runPath = resolve(outDir, "_run.js");
|
|
141
130
|
await writeFile(
|
|
142
131
|
runPath,
|
|
143
132
|
`
|
|
144
|
-
${jcoImport ? `import ${JSON.stringify(pathToFileURL(jcoImport))}` :
|
|
133
|
+
${jcoImport ? `import ${JSON.stringify(pathToFileURL(jcoImport))}` : ""}
|
|
145
134
|
import process from 'node:process';
|
|
146
135
|
try {
|
|
147
136
|
process.argv[1] = "${name}";
|
|
148
137
|
} catch {}
|
|
149
138
|
const mod = await import('./${name}.js');
|
|
150
139
|
${executor}
|
|
151
|
-
|
|
140
|
+
`,
|
|
152
141
|
);
|
|
153
142
|
|
|
154
143
|
const nodePath = process.env.JCO_RUN_PATH || process.argv[0];
|
|
@@ -156,18 +145,12 @@ async function runComponent(componentPath, args, opts, executor) {
|
|
|
156
145
|
process.exitCode = await new Promise((resolve, reject) => {
|
|
157
146
|
const cp = spawn(
|
|
158
147
|
nodePath,
|
|
159
|
-
[
|
|
160
|
-
|
|
161
|
-
? process.env.JCO_RUN_ARGS.split(' ')
|
|
162
|
-
: []),
|
|
163
|
-
runPath,
|
|
164
|
-
...args,
|
|
165
|
-
],
|
|
166
|
-
{ stdio: 'inherit' }
|
|
148
|
+
[...(process.env.JCO_RUN_ARGS ? process.env.JCO_RUN_ARGS.split(" ") : []), runPath, ...args],
|
|
149
|
+
{ stdio: "inherit" },
|
|
167
150
|
);
|
|
168
151
|
|
|
169
|
-
cp.on(
|
|
170
|
-
cp.on(
|
|
152
|
+
cp.on("error", reject);
|
|
153
|
+
cp.on("exit", resolve);
|
|
171
154
|
});
|
|
172
155
|
} finally {
|
|
173
156
|
try {
|
package/src/cmd/transpile.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Command } from
|
|
1
|
+
import type { Command } from "commander";
|
|
2
2
|
|
|
3
3
|
export function types(witPath: any, opts: any): Promise<void>;
|
|
4
4
|
|
|
@@ -20,22 +20,24 @@ export function guestTypes(witPath: any, opts: any): Promise<void>;
|
|
|
20
20
|
* }} opts
|
|
21
21
|
* @returns {Promise<{ [filename: string]: Uint8Array }>}
|
|
22
22
|
*/
|
|
23
|
-
export function typesComponent(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
export function typesComponent(
|
|
24
|
+
witPath: string,
|
|
25
|
+
opts: {
|
|
26
|
+
name?: string;
|
|
27
|
+
worldName?: string;
|
|
28
|
+
instantiation?: "async" | "sync";
|
|
29
|
+
tlaCompat?: boolean;
|
|
30
|
+
asyncMode?: string;
|
|
31
|
+
asyncImports?: string[];
|
|
32
|
+
asyncExports?: string[];
|
|
33
|
+
outDir?: string;
|
|
34
|
+
features?: string[] | "all";
|
|
35
|
+
guest?: boolean;
|
|
36
|
+
},
|
|
37
|
+
): Promise<{
|
|
35
38
|
[filename: string]: Uint8Array;
|
|
36
39
|
}>;
|
|
37
40
|
|
|
38
|
-
|
|
39
41
|
export function transpile(
|
|
40
42
|
componentPath: string,
|
|
41
43
|
opts: TranspilationOptions,
|
|
@@ -44,8 +46,8 @@ export function transpile(
|
|
|
44
46
|
|
|
45
47
|
type TranspilationOptions = {
|
|
46
48
|
name: string;
|
|
47
|
-
instantiation?:
|
|
48
|
-
importBindings?:
|
|
49
|
+
instantiation?: "async" | "sync";
|
|
50
|
+
importBindings?: "js" | "optimized" | "hybrid" | "direct-optimized";
|
|
49
51
|
map?: Record<string, string>;
|
|
50
52
|
asyncMode?: string;
|
|
51
53
|
asyncImports?: string[];
|
|
@@ -70,7 +72,7 @@ type TranspilationOptions = {
|
|
|
70
72
|
type TranspilationResult = {
|
|
71
73
|
files: FileBytes;
|
|
72
74
|
imports: string[];
|
|
73
|
-
exports: [string,
|
|
75
|
+
exports: [string, "function" | "instance"][];
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
/**
|
|
@@ -100,28 +102,31 @@ type TranspilationResult = {
|
|
|
100
102
|
* }} opts
|
|
101
103
|
* @returns {Promise<{ files: { [filename: string]: Uint8Array }, imports: string[], exports: [string, 'function' | 'instance'][] }>}
|
|
102
104
|
*/
|
|
103
|
-
export function transpileComponent(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
105
|
+
export function transpileComponent(
|
|
106
|
+
component: Uint8Array,
|
|
107
|
+
opts?: {
|
|
108
|
+
name: string;
|
|
109
|
+
instantiation?: "async" | "sync";
|
|
110
|
+
importBindings?: "js" | "optimized" | "hybrid" | "direct-optimized";
|
|
111
|
+
map?: Record<string, string>;
|
|
112
|
+
asyncMode?: string;
|
|
113
|
+
asyncImports?: string[];
|
|
114
|
+
asyncExports?: string[];
|
|
115
|
+
validLiftingOptimization?: boolean;
|
|
116
|
+
tracing?: boolean;
|
|
117
|
+
nodejsCompat?: boolean;
|
|
118
|
+
tlaCompat?: boolean;
|
|
119
|
+
base64Cutoff?: boolean;
|
|
120
|
+
js?: boolean;
|
|
121
|
+
minify?: boolean;
|
|
122
|
+
optimize?: boolean;
|
|
123
|
+
namespacedExports?: boolean;
|
|
124
|
+
outDir?: string;
|
|
125
|
+
multiMemory?: boolean;
|
|
126
|
+
experimentalIdlImports?: boolean;
|
|
127
|
+
optArgs?: string[];
|
|
128
|
+
},
|
|
129
|
+
): Promise<{
|
|
125
130
|
files: {
|
|
126
131
|
[filename: string]: Uint8Array;
|
|
127
132
|
};
|