@bytecodealliance/jco 1.11.2-rc.2 → 1.11.3-rc.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/interfaces/wasi-filesystem-types.d.ts +30 -30
- package/obj/js-component-bindgen-component.core.wasm +0 -0
- package/obj/js-component-bindgen-component.js +54 -50
- package/obj/wasm-tools.core.wasm +0 -0
- package/obj/wasm-tools.js +54 -50
- package/package.json +11 -15
- package/src/api.d.ts.map +1 -1
- package/src/api.js +45 -28
- package/src/browser.d.ts.map +1 -1
- package/src/browser.js +12 -8
- package/src/cmd/componentize.d.ts.map +1 -1
- package/src/cmd/opt.d.ts.map +1 -1
- package/src/cmd/opt.js +17 -7
- package/src/cmd/run.d.ts.map +1 -1
- package/src/cmd/run.js +6 -2
- package/src/cmd/transpile.d.ts +14 -14
- package/src/cmd/transpile.d.ts.map +1 -1
- package/src/cmd/transpile.js +89 -35
- package/src/cmd/wasm-tools.d.ts.map +1 -1
- package/src/cmd/wasm-tools.js +22 -10
- package/src/common.d.ts.map +1 -1
- package/src/common.js +86 -75
- package/src/jco.js +419 -216
- package/src/ora-shim.d.ts +1 -0
- package/src/ora-shim.d.ts.map +1 -1
- package/src/ora-shim.js +5 -5
- package/LICENSE +0 -220
package/src/cmd/wasm-tools.js
CHANGED
|
@@ -46,9 +46,10 @@ export async function componentNew(file, opts) {
|
|
|
46
46
|
await $init;
|
|
47
47
|
const source = file ? await readFile(file) : null;
|
|
48
48
|
let adapters = [];
|
|
49
|
-
if (opts.wasiReactor && opts.wasiCommand)
|
|
49
|
+
if (opts.wasiReactor && opts.wasiCommand) {
|
|
50
50
|
throw new Error('Must select one of --wasi-command or --wasi-reactor');
|
|
51
|
-
|
|
51
|
+
}
|
|
52
|
+
if (opts.wasiReactor) {
|
|
52
53
|
adapters = [
|
|
53
54
|
[
|
|
54
55
|
'wasi_snapshot_preview1',
|
|
@@ -62,7 +63,7 @@ export async function componentNew(file, opts) {
|
|
|
62
63
|
).buffer,
|
|
63
64
|
],
|
|
64
65
|
];
|
|
65
|
-
else if (opts.wasiCommand)
|
|
66
|
+
} else if (opts.wasiCommand) {
|
|
66
67
|
adapters = [
|
|
67
68
|
[
|
|
68
69
|
'wasi_snapshot_preview1',
|
|
@@ -76,34 +77,39 @@ export async function componentNew(file, opts) {
|
|
|
76
77
|
).buffer,
|
|
77
78
|
],
|
|
78
79
|
];
|
|
79
|
-
|
|
80
|
+
}
|
|
81
|
+
if (opts.adapt) {
|
|
80
82
|
adapters = adapters.concat(
|
|
81
83
|
await Promise.all(
|
|
82
84
|
opts.adapt.map(async (adapt) => {
|
|
83
85
|
let adapter;
|
|
84
|
-
if (adapt.includes('='))
|
|
85
|
-
|
|
86
|
+
if (adapt.includes('=')) {
|
|
87
|
+
adapter = adapt.split('=');
|
|
88
|
+
} else {
|
|
86
89
|
adapter = [
|
|
87
90
|
basename(adapt).slice(0, -extname(adapt).length),
|
|
88
91
|
adapt,
|
|
89
92
|
];
|
|
93
|
+
}
|
|
90
94
|
adapter[1] = await readFile(adapter[1]);
|
|
91
95
|
return adapter;
|
|
92
96
|
})
|
|
93
97
|
)
|
|
94
98
|
);
|
|
99
|
+
}
|
|
95
100
|
const output = componentNewFn(source, adapters);
|
|
96
101
|
await writeFile(opts.output, output);
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
export async function componentEmbed(file, opts) {
|
|
100
105
|
await $init;
|
|
101
|
-
if (opts.metadata)
|
|
106
|
+
if (opts.metadata) {
|
|
102
107
|
opts.metadata = opts.metadata.map((meta) => {
|
|
103
108
|
const [field, data = ''] = meta.split('=');
|
|
104
109
|
const [name, version = ''] = data.split('@');
|
|
105
110
|
return [field, [[name, version]]];
|
|
106
111
|
});
|
|
112
|
+
}
|
|
107
113
|
const source = file ? await readFile(file) : null;
|
|
108
114
|
opts.binary = source;
|
|
109
115
|
opts.witPath = (isWindows ? '//?/' : '') + resolve(opts.wit);
|
|
@@ -137,18 +143,24 @@ export async function metadataShow(file, opts) {
|
|
|
137
143
|
const indent = ' '.repeat(stack.length);
|
|
138
144
|
if (metaType.tag === 'component') {
|
|
139
145
|
output += c`{bold [component${name ? ' ' + name : ''}]}\n`;
|
|
140
|
-
if (metaType.val > 0)
|
|
146
|
+
if (metaType.val > 0) {
|
|
147
|
+
stack.push(metaType.val);
|
|
148
|
+
}
|
|
141
149
|
} else {
|
|
142
150
|
output += c`{bold [module${name ? ' ' + name : ''}]}\n`;
|
|
143
151
|
}
|
|
144
|
-
if (producers.length === 0)
|
|
152
|
+
if (producers.length === 0) {
|
|
153
|
+
output += `${indent}(no metadata)\n`;
|
|
154
|
+
}
|
|
145
155
|
for (const [field, items] of producers) {
|
|
146
156
|
for (const [name, version] of items) {
|
|
147
157
|
output += `${indent}${(field + ':').padEnd(13, ' ')} ${name}${version ? c`{cyan ${version}}` : ''}\n`;
|
|
148
158
|
}
|
|
149
159
|
}
|
|
150
160
|
output += '\n';
|
|
151
|
-
if (stack[stack.length - 1] === 0)
|
|
161
|
+
if (stack[stack.length - 1] === 0) {
|
|
162
|
+
stack.pop();
|
|
163
|
+
}
|
|
152
164
|
stack[stack.length - 1]--;
|
|
153
165
|
}
|
|
154
166
|
process.stdout.write(output);
|
package/src/common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["common.js"],"names":[],"mappings":"AAWA,+CAEC;AACD,0CAIC;AAED,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["common.js"],"names":[],"mappings":"AAWA,+CAEC;AACD,0CAIC;AAED,0CASC;AAED,mEAcC;AAED,wDAoBC;AAED;;;;GAIG;AACH,6CAEC;AAWD,8FAiCC;AAhHD,gCAA8C;;AAsE9C,yFAMC"}
|
package/src/common.js
CHANGED
|
@@ -9,53 +9,62 @@ import { platform } from 'node:process';
|
|
|
9
9
|
export const isWindows = platform === 'win32';
|
|
10
10
|
|
|
11
11
|
let _showSpinner = false;
|
|
12
|
-
export function setShowSpinner
|
|
13
|
-
|
|
12
|
+
export function setShowSpinner(val) {
|
|
13
|
+
_showSpinner = val;
|
|
14
14
|
}
|
|
15
|
-
export function getShowSpinner
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
export function getShowSpinner() {
|
|
16
|
+
const showSpinner = _showSpinner;
|
|
17
|
+
_showSpinner = false;
|
|
18
|
+
return showSpinner;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function sizeStr
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
export function sizeStr(num) {
|
|
22
|
+
num /= 1024;
|
|
23
|
+
if (num < 1000) {
|
|
24
|
+
return `${fixedDigitDisplay(num, 4)} KiB`;
|
|
25
|
+
}
|
|
26
|
+
num /= 1024;
|
|
27
|
+
if (num < 1000) {
|
|
28
|
+
return `${fixedDigitDisplay(num, 4)} MiB`;
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
export function fixedDigitDisplay
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
export function fixedDigitDisplay(num, maxChars) {
|
|
33
|
+
const significantDigits = String(num).split('.')[0].length;
|
|
34
|
+
let str;
|
|
35
|
+
if (significantDigits >= maxChars - 1) {
|
|
36
|
+
str = String(Math.round(num));
|
|
37
|
+
} else {
|
|
38
|
+
const decimalPlaces = maxChars - significantDigits - 1;
|
|
39
|
+
const rounding = 10 ** decimalPlaces;
|
|
40
|
+
str = String(Math.round(num * rounding) / rounding);
|
|
41
|
+
}
|
|
42
|
+
if (maxChars - str.length < 0) {
|
|
43
|
+
return str;
|
|
44
|
+
}
|
|
45
|
+
return ' '.repeat(maxChars - str.length) + str;
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
export function table
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
let outTable = '';
|
|
49
|
-
for (const row of data) {
|
|
50
|
-
for (const [i, cell] of row.entries()) {
|
|
51
|
-
if (align[i] === 'right')
|
|
52
|
-
outTable += ' '.repeat(colLens[i] - cell.length) + cell;
|
|
53
|
-
else
|
|
54
|
-
outTable += cell + ' '.repeat(colLens[i] - cell.length);
|
|
48
|
+
export function table(data, align = []) {
|
|
49
|
+
if (data.length === 0) {
|
|
50
|
+
return '';
|
|
55
51
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
const colLens = data.reduce(
|
|
53
|
+
(maxLens, cur) => maxLens.map((len, i) => Math.max(len, cur[i].length)),
|
|
54
|
+
data[0].map((cell) => cell.length)
|
|
55
|
+
);
|
|
56
|
+
let outTable = '';
|
|
57
|
+
for (const row of data) {
|
|
58
|
+
for (const [i, cell] of row.entries()) {
|
|
59
|
+
if (align[i] === 'right') {
|
|
60
|
+
outTable += ' '.repeat(colLens[i] - cell.length) + cell;
|
|
61
|
+
} else {
|
|
62
|
+
outTable += cell + ' '.repeat(colLens[i] - cell.length);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
outTable += '\n';
|
|
66
|
+
}
|
|
67
|
+
return outTable;
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
/**
|
|
@@ -63,48 +72,50 @@ export function table (data, align = []) {
|
|
|
63
72
|
*
|
|
64
73
|
* The new directory is created using `fsPromises.mkdtemp()`.
|
|
65
74
|
*/
|
|
66
|
-
export async function getTmpDir
|
|
67
|
-
|
|
75
|
+
export async function getTmpDir() {
|
|
76
|
+
return await mkdtemp(normalize(tmpdir() + sep));
|
|
68
77
|
}
|
|
69
78
|
|
|
70
|
-
async function readFileCli
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
79
|
+
async function readFileCli(file, encoding) {
|
|
80
|
+
try {
|
|
81
|
+
return await readFile(file, encoding);
|
|
82
|
+
} catch {
|
|
83
|
+
throw c`Unable to read file {bold ${file}}`;
|
|
84
|
+
}
|
|
77
85
|
}
|
|
78
|
-
export { readFileCli as readFile }
|
|
86
|
+
export { readFileCli as readFile };
|
|
79
87
|
|
|
80
|
-
export async function spawnIOTmp
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
export async function spawnIOTmp(cmd, input, args) {
|
|
89
|
+
const tmpDir = await getTmpDir();
|
|
90
|
+
try {
|
|
91
|
+
const inFile = resolve(tmpDir, 'in.wasm');
|
|
92
|
+
let outFile = resolve(tmpDir, 'out.wasm');
|
|
85
93
|
|
|
86
|
-
|
|
94
|
+
await writeFile(inFile, input);
|
|
87
95
|
|
|
88
|
-
|
|
96
|
+
const cp = spawn(argv0, [cmd, inFile, ...args, outFile], {
|
|
97
|
+
stdio: 'pipe',
|
|
98
|
+
});
|
|
89
99
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
let stderr = '';
|
|
101
|
+
const p = new Promise((resolve, reject) => {
|
|
102
|
+
cp.stderr.on('data', (data) => (stderr += data.toString()));
|
|
103
|
+
cp.on('error', (e) => {
|
|
104
|
+
reject(e);
|
|
105
|
+
});
|
|
106
|
+
cp.on('exit', (code) => {
|
|
107
|
+
if (code === 0) {
|
|
108
|
+
resolve();
|
|
109
|
+
} else {
|
|
110
|
+
reject(stderr);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
103
114
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
await p;
|
|
116
|
+
var output = await readFile(outFile);
|
|
117
|
+
return output;
|
|
118
|
+
} finally {
|
|
119
|
+
await rm(tmpDir, { recursive: true });
|
|
120
|
+
}
|
|
110
121
|
}
|