@bytecodealliance/jco 1.10.2 → 1.11.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/obj/js-component-bindgen-component.core.wasm +0 -0
- package/obj/js-component-bindgen-component.js +2 -2
- package/obj/wasm-tools.core.wasm +0 -0
- package/obj/wasm-tools.js +2 -2
- package/package.json +18 -6
- package/src/cmd/componentize.js +64 -18
- package/src/cmd/opt.js +233 -202
- package/src/cmd/run.js +117 -73
- package/src/cmd/transpile.d.ts.map +1 -1
- package/src/cmd/transpile.js +643 -530
- package/src/cmd/wasm-tools.js +130 -95
- package/src/jco.js +5 -1
package/src/cmd/wasm-tools.js
CHANGED
|
@@ -1,121 +1,156 @@
|
|
|
1
|
-
import { writeFile } from
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
2
|
import { readFile, isWindows } from '../common.js';
|
|
3
|
-
import { $init, tools } from
|
|
4
|
-
const {
|
|
3
|
+
import { $init, tools } from '../../obj/wasm-tools.js';
|
|
4
|
+
const {
|
|
5
|
+
print: printFn,
|
|
6
|
+
parse: parseFn,
|
|
7
|
+
componentWit: componentWitFn,
|
|
8
|
+
componentNew: componentNewFn,
|
|
9
|
+
componentEmbed: componentEmbedFn,
|
|
10
|
+
metadataAdd: metadataAddFn,
|
|
11
|
+
metadataShow: metadataShowFn,
|
|
12
|
+
} = tools;
|
|
5
13
|
import { resolve, basename, extname } from 'node:path';
|
|
6
14
|
import c from 'chalk-template';
|
|
7
15
|
|
|
8
16
|
export async function parse(file, opts) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
await $init;
|
|
18
|
+
const source = (await readFile(file)).toString();
|
|
19
|
+
const output = parseFn(source);
|
|
20
|
+
await writeFile(opts.output, output);
|
|
13
21
|
}
|
|
14
22
|
|
|
15
23
|
export async function print(file, opts) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
await $init;
|
|
25
|
+
const source = await readFile(file);
|
|
26
|
+
const output = printFn(source);
|
|
27
|
+
if (opts.output) {
|
|
28
|
+
await writeFile(opts.output, output);
|
|
29
|
+
} else {
|
|
30
|
+
console.log(output);
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
export async function componentWit(file, opts) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
await $init;
|
|
36
|
+
const source = await readFile(file);
|
|
37
|
+
const output = componentWitFn(source, opts.document);
|
|
38
|
+
if (opts.output) {
|
|
39
|
+
await writeFile(opts.output, output);
|
|
40
|
+
} else {
|
|
41
|
+
console.log(output);
|
|
42
|
+
}
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
export async function componentNew(file, opts) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
await $init;
|
|
47
|
+
const source = file ? await readFile(file) : null;
|
|
48
|
+
let adapters = [];
|
|
49
|
+
if (opts.wasiReactor && opts.wasiCommand)
|
|
50
|
+
throw new Error('Must select one of --wasi-command or --wasi-reactor');
|
|
51
|
+
if (opts.wasiReactor)
|
|
52
|
+
adapters = [
|
|
53
|
+
[
|
|
54
|
+
'wasi_snapshot_preview1',
|
|
55
|
+
(
|
|
56
|
+
await readFile(
|
|
57
|
+
new URL(
|
|
58
|
+
'../../lib/wasi_snapshot_preview1.reactor.wasm',
|
|
59
|
+
import.meta.url
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
).buffer,
|
|
63
|
+
],
|
|
64
|
+
];
|
|
65
|
+
else if (opts.wasiCommand)
|
|
66
|
+
adapters = [
|
|
67
|
+
[
|
|
68
|
+
'wasi_snapshot_preview1',
|
|
69
|
+
(
|
|
70
|
+
await readFile(
|
|
71
|
+
new URL(
|
|
72
|
+
'../../lib/wasi_snapshot_preview1.command.wasm',
|
|
73
|
+
import.meta.url
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
).buffer,
|
|
77
|
+
],
|
|
78
|
+
];
|
|
79
|
+
if (opts.adapt)
|
|
80
|
+
adapters = adapters.concat(
|
|
81
|
+
await Promise.all(
|
|
82
|
+
opts.adapt.map(async (adapt) => {
|
|
83
|
+
let adapter;
|
|
84
|
+
if (adapt.includes('=')) adapter = adapt.split('=');
|
|
85
|
+
else
|
|
86
|
+
adapter = [
|
|
87
|
+
basename(adapt).slice(0, -extname(adapt).length),
|
|
88
|
+
adapt,
|
|
89
|
+
];
|
|
90
|
+
adapter[1] = await readFile(adapter[1]);
|
|
91
|
+
return adapter;
|
|
92
|
+
})
|
|
93
|
+
)
|
|
94
|
+
);
|
|
95
|
+
const output = componentNewFn(source, adapters);
|
|
96
|
+
await writeFile(opts.output, output);
|
|
59
97
|
}
|
|
60
98
|
|
|
61
99
|
export async function componentEmbed(file, opts) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
100
|
+
await $init;
|
|
101
|
+
if (opts.metadata)
|
|
102
|
+
opts.metadata = opts.metadata.map((meta) => {
|
|
103
|
+
const [field, data = ''] = meta.split('=');
|
|
104
|
+
const [name, version = ''] = data.split('@');
|
|
105
|
+
return [field, [[name, version]]];
|
|
106
|
+
});
|
|
107
|
+
const source = file ? await readFile(file) : null;
|
|
108
|
+
opts.binary = source;
|
|
109
|
+
opts.witPath = (isWindows ? '//?/' : '') + resolve(opts.wit);
|
|
110
|
+
const output = componentEmbedFn(opts);
|
|
111
|
+
await writeFile(opts.output, output);
|
|
74
112
|
}
|
|
75
113
|
|
|
76
114
|
export async function metadataAdd(file, opts) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
115
|
+
await $init;
|
|
116
|
+
const metadata = opts.metadata.map((meta) => {
|
|
117
|
+
const [field, data = ''] = meta.split('=');
|
|
118
|
+
const [name, version = ''] = data.split('@');
|
|
119
|
+
return [field, [[name, version]]];
|
|
120
|
+
});
|
|
121
|
+
const source = await readFile(file);
|
|
122
|
+
const output = metadataAddFn(source, metadata);
|
|
123
|
+
await writeFile(opts.output, output);
|
|
86
124
|
}
|
|
87
125
|
|
|
88
126
|
export async function metadataShow(file, opts) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
127
|
+
await $init;
|
|
128
|
+
const source = await readFile(file);
|
|
129
|
+
let output = '',
|
|
130
|
+
stack = [1];
|
|
131
|
+
const meta = metadataShowFn(source);
|
|
132
|
+
if (opts.json) {
|
|
133
|
+
console.log(JSON.stringify(meta, null, 2));
|
|
134
|
+
} else {
|
|
135
|
+
for (const { name, metaType, producers } of meta) {
|
|
136
|
+
output += ' '.repeat(stack.length - 1);
|
|
137
|
+
const indent = ' '.repeat(stack.length);
|
|
138
|
+
if (metaType.tag === 'component') {
|
|
139
|
+
output += c`{bold [component${name ? ' ' + name : ''}]}\n`;
|
|
140
|
+
if (metaType.val > 0) stack.push(metaType.val);
|
|
141
|
+
} else {
|
|
142
|
+
output += c`{bold [module${name ? ' ' + name : ''}]}\n`;
|
|
143
|
+
}
|
|
144
|
+
if (producers.length === 0) output += `${indent}(no metadata)\n`;
|
|
145
|
+
for (const [field, items] of producers) {
|
|
146
|
+
for (const [name, version] of items) {
|
|
147
|
+
output += `${indent}${(field + ':').padEnd(13, ' ')} ${name}${version ? c`{cyan ${version}}` : ''}\n`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
output += '\n';
|
|
151
|
+
if (stack[stack.length - 1] === 0) stack.pop();
|
|
152
|
+
stack[stack.length - 1]--;
|
|
112
153
|
}
|
|
113
|
-
|
|
114
|
-
output += '\n';
|
|
115
|
-
if (stack[stack.length - 1] === 0)
|
|
116
|
-
stack.pop();
|
|
117
|
-
stack[stack.length - 1]--;
|
|
154
|
+
process.stdout.write(output);
|
|
118
155
|
}
|
|
119
|
-
process.stdout.write(output);
|
|
120
|
-
}
|
|
121
156
|
}
|
package/src/jco.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import c from 'chalk-template';
|
|
2
4
|
import { program, Option } from 'commander';
|
|
5
|
+
|
|
3
6
|
import { opt } from './cmd/opt.js';
|
|
4
7
|
import { transpile, types, guestTypes } from './cmd/transpile.js';
|
|
5
8
|
import { run as runCmd, serve as serveCmd } from './cmd/run.js';
|
|
6
9
|
import { parse, print, componentNew, componentEmbed, metadataAdd, metadataShow, componentWit } from './cmd/wasm-tools.js';
|
|
7
10
|
import { componentize } from './cmd/componentize.js';
|
|
8
|
-
import c from 'chalk-template';
|
|
9
11
|
|
|
10
12
|
program
|
|
11
13
|
.name('jco')
|
|
@@ -34,10 +36,12 @@ program.command('componentize')
|
|
|
34
36
|
.requiredOption('-w, --wit <path>', 'WIT path to build with')
|
|
35
37
|
.option('-n, --world-name <name>', 'WIT world to build')
|
|
36
38
|
.option('--aot', 'Enable Weval AOT compilation of JS')
|
|
39
|
+
.option('--aot-min-stack-size-bytes <number>', 'Set the min stack size to be used during AOT')
|
|
37
40
|
.option('--weval-bin <path>', 'Specify a custom weval binary to use')
|
|
38
41
|
.addOption(new Option('-d, --disable <feature...>', 'disable WASI features').choices(['clocks', 'http', 'random', 'stdio', 'all']))
|
|
39
42
|
// .addOption(new Option('-e, --enable <feature...>', 'enable WASI features').choices(['http']))
|
|
40
43
|
.option('--preview2-adapter <adapter>', 'provide a custom preview2 adapter path')
|
|
44
|
+
.option('--debug-starlingmonkey-build', 'use a debug build of StarlingMonkey')
|
|
41
45
|
.requiredOption('-o, --out <out>', 'output component file')
|
|
42
46
|
.action(asyncAction(componentize));
|
|
43
47
|
|