@bytecodealliance/jco 1.13.3 → 1.15.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/obj/interfaces/wasi-cli-terminal-input.d.ts +1 -2
- package/obj/interfaces/wasi-cli-terminal-output.d.ts +1 -2
- package/obj/interfaces/wasi-filesystem-types.d.ts +2 -4
- package/obj/interfaces/wasi-io-error.d.ts +1 -2
- package/obj/interfaces/wasi-io-streams.d.ts +2 -4
- package/obj/js-component-bindgen-component.core.wasm +0 -0
- package/obj/js-component-bindgen-component.js +92 -96
- package/obj/wasm-tools.core.wasm +0 -0
- package/obj/wasm-tools.js +96 -100
- package/package.json +12 -11
- package/src/cmd/componentize.js +52 -12
- package/src/cmd/opt.js +45 -40
- package/src/cmd/run.js +8 -8
- package/src/cmd/transpile.js +199 -184
- package/src/cmd/types.js +68 -23
- package/src/cmd/wasm-tools.js +6 -6
- package/src/common.js +120 -25
- package/src/jco.js +47 -11
- package/types/api.d.ts.map +1 -0
- package/types/browser.d.ts.map +1 -0
- package/types/common.d.ts +80 -0
- package/types/common.d.ts.map +1 -0
- package/types/jco.d.ts.map +1 -0
- package/types/ora-shim.d.ts.map +1 -0
- package/src/api.d.ts.map +0 -1
- package/src/browser.d.ts.map +0 -1
- package/src/common.d.ts +0 -19
- package/src/common.d.ts.map +0 -1
- package/src/jco.d.ts.map +0 -1
- package/src/ora-shim.d.ts.map +0 -1
- /package/{src → types}/api.d.ts +0 -0
- /package/{src → types}/browser.d.ts +0 -0
- /package/{src → types}/jco.d.ts +0 -0
- /package/{src → types}/ora-shim.d.ts +0 -0
package/src/cmd/types.js
CHANGED
|
@@ -1,27 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { stat } from 'node:fs/promises';
|
|
1
|
+
import { stat, mkdir } from 'node:fs/promises';
|
|
3
2
|
import { extname, basename, resolve } from 'node:path';
|
|
4
3
|
|
|
5
|
-
import c from 'chalk-template';
|
|
6
|
-
|
|
7
4
|
import {
|
|
8
5
|
$init,
|
|
9
6
|
generateTypes,
|
|
10
7
|
} from '../../obj/js-component-bindgen-component.js';
|
|
8
|
+
|
|
11
9
|
import {
|
|
10
|
+
isWindows,
|
|
12
11
|
writeFiles,
|
|
12
|
+
resolveDefaultWITPath,
|
|
13
|
+
styleText,
|
|
13
14
|
ASYNC_WASI_IMPORTS,
|
|
14
15
|
ASYNC_WASI_EXPORTS,
|
|
16
|
+
DEFAULT_ASYNC_MODE,
|
|
15
17
|
} from '../common.js';
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
/** Default relative path for guest type declaration generation */
|
|
20
|
+
const DEFAULT_GUEST_TYPES_OUTPUT_DIR_PATH = './types/generated/wit/guest';
|
|
21
|
+
|
|
22
|
+
/** Default relative path for host type declaration generation */
|
|
23
|
+
const DEFAULT_HOST_TYPES_OUTPUT_DIR_PATH = './types/generated/wit/host';
|
|
18
24
|
|
|
19
25
|
export async function types(witPath, opts) {
|
|
26
|
+
witPath = await resolveDefaultWITPath(witPath);
|
|
27
|
+
|
|
28
|
+
// Use the default output directory if one was not provided
|
|
29
|
+
if (!opts.outDir) {
|
|
30
|
+
await mkdir(DEFAULT_HOST_TYPES_OUTPUT_DIR_PATH, { recursive: true });
|
|
31
|
+
opts.outDir = resolve(DEFAULT_HOST_TYPES_OUTPUT_DIR_PATH);
|
|
32
|
+
console.error(
|
|
33
|
+
`no output directory specified for host type declarations, using [${DEFAULT_HOST_TYPES_OUTPUT_DIR_PATH}]`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
20
37
|
const files = await typesComponent(witPath, opts);
|
|
38
|
+
|
|
21
39
|
await writeFiles(files, opts.quiet ? false : 'Generated Type Files');
|
|
22
40
|
}
|
|
23
41
|
|
|
24
42
|
export async function guestTypes(witPath, opts) {
|
|
43
|
+
witPath = await resolveDefaultWITPath(witPath);
|
|
44
|
+
|
|
45
|
+
// Use the default output directory if one was not provided
|
|
46
|
+
if (!opts.outDir) {
|
|
47
|
+
await mkdir(DEFAULT_GUEST_TYPES_OUTPUT_DIR_PATH, { recursive: true });
|
|
48
|
+
opts.outDir = resolve(DEFAULT_GUEST_TYPES_OUTPUT_DIR_PATH);
|
|
49
|
+
console.error(
|
|
50
|
+
`no output directory specified for guest type declarations, using [${DEFAULT_GUEST_TYPES_OUTPUT_DIR_PATH}]`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
25
54
|
const files = await typesComponent(witPath, { ...opts, guest: true });
|
|
26
55
|
await writeFiles(
|
|
27
56
|
files,
|
|
@@ -47,6 +76,8 @@ export async function guestTypes(witPath, opts) {
|
|
|
47
76
|
* features?: string[] | 'all',
|
|
48
77
|
* asyncWasiImports?: string[],
|
|
49
78
|
* asyncWasiExports?: string[],
|
|
79
|
+
* asyncExports?: string[],
|
|
80
|
+
* asyncImports?: string[],
|
|
50
81
|
* guest?: bool,
|
|
51
82
|
* }} opts
|
|
52
83
|
* @returns {Promise<{ [filename: string]: Uint8Array }>}
|
|
@@ -67,6 +98,7 @@ export async function typesComponent(witPath, opts) {
|
|
|
67
98
|
outDir += '/';
|
|
68
99
|
}
|
|
69
100
|
|
|
101
|
+
// Bulid list of enabled features
|
|
70
102
|
let features = null;
|
|
71
103
|
if (opts.allFeatures) {
|
|
72
104
|
features = { tag: 'all' };
|
|
@@ -76,24 +108,36 @@ export async function typesComponent(witPath, opts) {
|
|
|
76
108
|
features = { tag: 'list', val: opts.features };
|
|
77
109
|
}
|
|
78
110
|
|
|
111
|
+
// Build list of async imports/exports
|
|
112
|
+
let asyncImports = new Set([...(opts.asyncImports ?? [])]);
|
|
79
113
|
if (opts.asyncWasiImports) {
|
|
80
|
-
|
|
114
|
+
ASYNC_WASI_IMPORTS.forEach((v) => asyncImports.add(v));
|
|
81
115
|
}
|
|
116
|
+
let asyncExports = new Set([...(opts.asyncExports ?? [])]);
|
|
82
117
|
if (opts.asyncWasiExports) {
|
|
83
|
-
|
|
118
|
+
ASYNC_WASI_EXPORTS.forEach((v) => asyncExports.add(v));
|
|
84
119
|
}
|
|
85
120
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
121
|
+
// For simple type generation, we choose the "async mode" for the user
|
|
122
|
+
// even though it is not relevant here (JSPI may not be used, as types may
|
|
123
|
+
// be used to generate a guest that is never transpiled).
|
|
124
|
+
let asyncMode = opts.asyncMode ?? DEFAULT_ASYNC_MODE;
|
|
125
|
+
let asyncModeObj;
|
|
126
|
+
if (asyncMode === 'jspi' || asyncExports.size > 0) {
|
|
127
|
+
asyncModeObj = {
|
|
128
|
+
tag: 'jspi',
|
|
129
|
+
val: {
|
|
130
|
+
imports: [...asyncImports],
|
|
131
|
+
exports: [...asyncExports],
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
} else if (asyncMode === 'sync') {
|
|
135
|
+
asyncModeObj = null;
|
|
136
|
+
} else {
|
|
137
|
+
throw new Error(`invalid/unrecognized async mode [${asyncMode}]`);
|
|
138
|
+
}
|
|
96
139
|
|
|
140
|
+
// Run the type generation
|
|
97
141
|
let types;
|
|
98
142
|
const absWitPath = resolve(witPath);
|
|
99
143
|
try {
|
|
@@ -104,7 +148,7 @@ export async function typesComponent(witPath, opts) {
|
|
|
104
148
|
world: opts.worldName,
|
|
105
149
|
features,
|
|
106
150
|
guest: opts.guest ?? false,
|
|
107
|
-
asyncMode,
|
|
151
|
+
asyncMode: asyncModeObj,
|
|
108
152
|
}).map(([name, file]) => [`${outDir}${name}`, file]);
|
|
109
153
|
} catch (err) {
|
|
110
154
|
if (err.toString().includes('does not match previous package name')) {
|
|
@@ -126,17 +170,18 @@ export async function typesComponent(witPath, opts) {
|
|
|
126
170
|
* @param {(string, any) => void} consoleFn
|
|
127
171
|
*/
|
|
128
172
|
async function printWITLayoutHint(witPath) {
|
|
173
|
+
const warningPrefix = styleText(['yellow', 'bold'], 'warning');
|
|
129
174
|
const pathMeta = await stat(witPath);
|
|
130
175
|
let output = '\n';
|
|
131
176
|
if (!pathMeta.isFile() && !pathMeta.isDirectory()) {
|
|
132
|
-
output +=
|
|
177
|
+
output += `${warningPrefix} The supplited WIT path [${witPath}] is neither a file or directory.\n`;
|
|
133
178
|
return output;
|
|
134
179
|
}
|
|
135
180
|
const ftype = pathMeta.isDirectory() ? 'directory' : 'file';
|
|
136
|
-
output +=
|
|
137
|
-
output +=
|
|
138
|
-
output +=
|
|
139
|
-
output +=
|
|
181
|
+
output += `${warningPrefix} Your WIT ${ftype} [${witPath}] may be laid out incorrectly\n`;
|
|
182
|
+
output += `${warningPrefix} Keep in mind the following rules:\n`;
|
|
183
|
+
output += `${warningPrefix} - Top level WIT files are in the same package (i.e. "ns:pkg" in "wit/*.wit")\n`;
|
|
184
|
+
output += `${warningPrefix} - All package dependencies should be in "wit/deps" (i.e. "some:dep" in "wit/deps/some-dep.wit"\n`;
|
|
140
185
|
return output;
|
|
141
186
|
}
|
|
142
187
|
|
package/src/cmd/wasm-tools.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { resolve, basename, extname } from 'node:path';
|
|
1
2
|
import { writeFile } from 'node:fs/promises';
|
|
2
|
-
|
|
3
|
+
|
|
4
|
+
import { readFile, isWindows, styleText } from '../common.js';
|
|
3
5
|
import { $init, tools } from '../../obj/wasm-tools.js';
|
|
4
6
|
const {
|
|
5
7
|
print: printFn,
|
|
@@ -10,8 +12,6 @@ const {
|
|
|
10
12
|
metadataAdd: metadataAddFn,
|
|
11
13
|
metadataShow: metadataShowFn,
|
|
12
14
|
} = tools;
|
|
13
|
-
import { resolve, basename, extname } from 'node:path';
|
|
14
|
-
import c from 'chalk-template';
|
|
15
15
|
|
|
16
16
|
export async function parse(file, opts) {
|
|
17
17
|
await $init;
|
|
@@ -142,19 +142,19 @@ export async function metadataShow(file, opts) {
|
|
|
142
142
|
output += ' '.repeat(stack.length - 1);
|
|
143
143
|
const indent = ' '.repeat(stack.length);
|
|
144
144
|
if (metaType.tag === 'component') {
|
|
145
|
-
output +=
|
|
145
|
+
output += `${styleText('bold', `[component${name ? ' ' + name : ''}]`)}\n`;
|
|
146
146
|
if (metaType.val > 0) {
|
|
147
147
|
stack.push(metaType.val);
|
|
148
148
|
}
|
|
149
149
|
} else {
|
|
150
|
-
output +=
|
|
150
|
+
output += `${styleText('bold', `[module${name ? ' ' + name : ''}]`)}\n`;
|
|
151
151
|
}
|
|
152
152
|
if (producers.length === 0) {
|
|
153
153
|
output += `${indent}(no metadata)\n`;
|
|
154
154
|
}
|
|
155
155
|
for (const [field, items] of producers) {
|
|
156
156
|
for (const [name, version] of items) {
|
|
157
|
-
output += `${indent}${(field + ':').padEnd(13, ' ')} ${name}${version ?
|
|
157
|
+
output += `${indent}${(field + ':').padEnd(13, ' ')} ${name}${version ? `${styleText('cyan', version)}` : ''}\n`;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
output += '\n';
|
package/src/common.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { normalize, resolve, sep, dirname } from 'node:path';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
readFile,
|
|
5
|
+
writeFile,
|
|
6
|
+
rm,
|
|
7
|
+
mkdtemp,
|
|
8
|
+
mkdir,
|
|
9
|
+
stat,
|
|
10
|
+
} from 'node:fs/promises';
|
|
4
11
|
import { spawn } from 'node:child_process';
|
|
5
12
|
import { argv0 } from 'node:process';
|
|
6
13
|
import { platform } from 'node:process';
|
|
7
|
-
|
|
8
|
-
import c from 'chalk-template';
|
|
14
|
+
import * as nodeUtils from 'node:util';
|
|
9
15
|
|
|
10
16
|
export const isWindows = platform === 'win32';
|
|
11
17
|
|
|
@@ -25,6 +31,11 @@ export const ASYNC_WASI_EXPORTS = [
|
|
|
25
31
|
'wasi:http/incoming-handler#handle',
|
|
26
32
|
];
|
|
27
33
|
|
|
34
|
+
export const DEFAULT_ASYNC_MODE = 'sync';
|
|
35
|
+
|
|
36
|
+
/** Path of WIT files by default when one is not specified */
|
|
37
|
+
export const DEFAULT_WIT_PATH = './wit';
|
|
38
|
+
|
|
28
39
|
let _showSpinner = false;
|
|
29
40
|
export function setShowSpinner(val) {
|
|
30
41
|
_showSpinner = val;
|
|
@@ -62,16 +73,23 @@ export function fixedDigitDisplay(num, maxChars) {
|
|
|
62
73
|
return ' '.repeat(maxChars - str.length) + str;
|
|
63
74
|
}
|
|
64
75
|
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Generate tabular output
|
|
78
|
+
*
|
|
79
|
+
* @param {string[][]} rows - data to put in rows
|
|
80
|
+
* @param {string[]} align - alignment of columns
|
|
81
|
+
* @returns string
|
|
82
|
+
*/
|
|
83
|
+
export function table(rows, align = []) {
|
|
84
|
+
if (rows.length === 0) {
|
|
67
85
|
return '';
|
|
68
86
|
}
|
|
69
|
-
const colLens =
|
|
87
|
+
const colLens = rows.reduce(
|
|
70
88
|
(maxLens, cur) => maxLens.map((len, i) => Math.max(len, cur[i].length)),
|
|
71
|
-
|
|
89
|
+
rows[0].map((cell) => cell.length)
|
|
72
90
|
);
|
|
73
91
|
let outTable = '';
|
|
74
|
-
for (const row of
|
|
92
|
+
for (const row of rows) {
|
|
75
93
|
for (const [i, cell] of row.entries()) {
|
|
76
94
|
if (align[i] === 'right') {
|
|
77
95
|
outTable += ' '.repeat(colLens[i] - cell.length) + cell;
|
|
@@ -88,27 +106,52 @@ export function table(data, align = []) {
|
|
|
88
106
|
* Securely creates a temporary directory and returns its path.
|
|
89
107
|
*
|
|
90
108
|
* The new directory is created using `fsPromises.mkdtemp()`.
|
|
109
|
+
*
|
|
110
|
+
* @returns {Promise<string>} A `Promise` that resovles to a created temporary directory path
|
|
91
111
|
*/
|
|
92
112
|
export async function getTmpDir() {
|
|
93
113
|
return await mkdtemp(normalize(tmpdir() + sep));
|
|
94
114
|
}
|
|
95
115
|
|
|
96
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Read a given file, throwing a formatted error if one occurs
|
|
118
|
+
*
|
|
119
|
+
* @param {string} filePath - path to teh file to read
|
|
120
|
+
* @param {encoding} encoding - file encoding
|
|
121
|
+
* @returns {Promise<Buffer>} A promise that resolves to the contents of the file
|
|
122
|
+
*/
|
|
123
|
+
async function readFileCli(filePath, encoding) {
|
|
97
124
|
try {
|
|
98
|
-
return await readFile(
|
|
125
|
+
return await readFile(filePath, encoding);
|
|
99
126
|
} catch {
|
|
100
|
-
throw
|
|
127
|
+
throw `Unable to read file ${styleText('bold', filePath)}`;
|
|
101
128
|
}
|
|
102
129
|
}
|
|
103
130
|
export { readFileCli as readFile };
|
|
104
131
|
|
|
105
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Spawn a command that processes a given wasm binary bytes with some
|
|
134
|
+
* command.
|
|
135
|
+
*
|
|
136
|
+
* The command invocations that are generated by this function
|
|
137
|
+
* take the following form:
|
|
138
|
+
*
|
|
139
|
+
* ```
|
|
140
|
+
* <cmd> <input wasm file> <...arguments> <output wasm file>
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @param {string} cmd - the command to run
|
|
144
|
+
* @param {Buffer<ArrayBufferLike>} inputWasmBytes - bytes that of the input WebAssembly binary
|
|
145
|
+
* @param {string[]} args - arguments to pass to the command (after the input file and before the output file)
|
|
146
|
+
* @returns {Promise<Buffer<ArrayBufferLike>>} A `Promise` that resolves when the command has exited
|
|
147
|
+
*/
|
|
148
|
+
export async function spawnIOTmp(cmd, inputWasmBytes, args) {
|
|
106
149
|
const tmpDir = await getTmpDir();
|
|
107
150
|
try {
|
|
108
151
|
const inFile = resolve(tmpDir, 'in.wasm');
|
|
109
152
|
let outFile = resolve(tmpDir, 'out.wasm');
|
|
110
153
|
|
|
111
|
-
await writeFile(inFile,
|
|
154
|
+
await writeFile(inFile, inputWasmBytes);
|
|
112
155
|
|
|
113
156
|
const cp = spawn(argv0, [cmd, inFile, ...args, outFile], {
|
|
114
157
|
stdio: 'pipe',
|
|
@@ -137,23 +180,75 @@ export async function spawnIOTmp(cmd, input, args) {
|
|
|
137
180
|
}
|
|
138
181
|
}
|
|
139
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Given an object that has file names as keys and file contents as values,
|
|
185
|
+
* write out the files to a their locations.
|
|
186
|
+
*
|
|
187
|
+
* This function also prints out the files that were written
|
|
188
|
+
*
|
|
189
|
+
* @param {Record<string, string>} files - object which contains files to be written out
|
|
190
|
+
* @param {boolean} summaryTitle - whether to print the summary after writing out files
|
|
191
|
+
* @returns {Promise<void>>} A `Promise` that resolves when the fiels are all written
|
|
192
|
+
*
|
|
193
|
+
*/
|
|
140
194
|
export async function writeFiles(files, summaryTitle) {
|
|
141
195
|
await Promise.all(
|
|
142
|
-
Object.entries(files).map(async ([
|
|
143
|
-
await mkdir(dirname(
|
|
144
|
-
await writeFile(
|
|
196
|
+
Object.entries(files).map(async ([filePath, contents]) => {
|
|
197
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
198
|
+
await writeFile(filePath, contents);
|
|
145
199
|
})
|
|
146
200
|
);
|
|
147
201
|
if (!summaryTitle) {
|
|
148
202
|
return;
|
|
149
203
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
)}`);
|
|
204
|
+
|
|
205
|
+
let rows = Object.entries(files).map(([name, source]) => [
|
|
206
|
+
` - ${styleText('italic', name)} `,
|
|
207
|
+
`${styleText(['black', 'italic'], sizeStr(source.length))}`,
|
|
208
|
+
]);
|
|
209
|
+
console.log(`
|
|
210
|
+
${styleText('bold', summaryTitle + ":")}
|
|
211
|
+
|
|
212
|
+
${table(rows)}`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Resolve the deafult WIT path, given a possibly
|
|
217
|
+
*
|
|
218
|
+
* @param {string | undefined} [witPath]
|
|
219
|
+
* @returns {Promise<string>}
|
|
220
|
+
*/
|
|
221
|
+
export async function resolveDefaultWITPath(witPath) {
|
|
222
|
+
if (witPath) {
|
|
223
|
+
return witPath;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Use a default/standard current-folder WIT directory (wit) if we can find it
|
|
227
|
+
const witDirExists = await stat(DEFAULT_WIT_PATH)
|
|
228
|
+
.then((p) => p.isDirectory())
|
|
229
|
+
.catch(() => false);
|
|
230
|
+
if (!witDirExists) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
'Failed to determine WIT directory, please specify WIT directory argument'
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
witPath = resolve(DEFAULT_WIT_PATH);
|
|
236
|
+
console.error(
|
|
237
|
+
`no WIT directory specified, using detected WIT directory @ [${DEFAULT_WIT_PATH}]`
|
|
238
|
+
);
|
|
239
|
+
return witPath;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Partial polyfill for 'node:utils' `styleText()`
|
|
244
|
+
*
|
|
245
|
+
* @param {string | string[]} styles - styles to apply to the given text
|
|
246
|
+
* @param {string} text - text that should be styled
|
|
247
|
+
* @returns {string} The styled string
|
|
248
|
+
*/
|
|
249
|
+
export function styleText(styles, text) {
|
|
250
|
+
if (nodeUtils.styleText) {
|
|
251
|
+
return nodeUtils.styleText(styles, text);
|
|
252
|
+
}
|
|
253
|
+
return text;
|
|
159
254
|
}
|
package/src/jco.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import c from 'chalk-template';
|
|
4
3
|
import { program, Option } from 'commander';
|
|
5
4
|
|
|
6
5
|
import { opt } from './cmd/opt.js';
|
|
@@ -17,15 +16,16 @@ import {
|
|
|
17
16
|
componentWit,
|
|
18
17
|
} from './cmd/wasm-tools.js';
|
|
19
18
|
import { componentize } from './cmd/componentize.js';
|
|
19
|
+
import { styleText } from './common.js';
|
|
20
20
|
|
|
21
21
|
program
|
|
22
22
|
.name('jco')
|
|
23
23
|
.description(
|
|
24
|
-
|
|
24
|
+
`${styleText('bold', "jco - WebAssembly JS Component Tools")}\n JS Component Transpilation Bindgen & Wasm Tools for JS`
|
|
25
25
|
)
|
|
26
26
|
.usage('<command> [options]')
|
|
27
27
|
.enablePositionalOptions()
|
|
28
|
-
.version('1.
|
|
28
|
+
.version('1.15.0');
|
|
29
29
|
|
|
30
30
|
function myParseInt(value) {
|
|
31
31
|
return parseInt(value, 10);
|
|
@@ -41,6 +41,16 @@ function collectOptions(value, previous) {
|
|
|
41
41
|
return previous.concat([value]);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/** Choices for features (enabling/disabling) */
|
|
45
|
+
const FEATURE_CHOICES = [
|
|
46
|
+
'clocks',
|
|
47
|
+
'http',
|
|
48
|
+
'random',
|
|
49
|
+
'stdio',
|
|
50
|
+
'fetch-event',
|
|
51
|
+
'all',
|
|
52
|
+
];
|
|
53
|
+
|
|
44
54
|
program
|
|
45
55
|
.command('componentize')
|
|
46
56
|
.description('Create a component from a JavaScript module')
|
|
@@ -58,9 +68,17 @@ program
|
|
|
58
68
|
new Option(
|
|
59
69
|
'-d, --disable <feature...>',
|
|
60
70
|
'disable WASI features'
|
|
61
|
-
).choices(
|
|
71
|
+
).choices(FEATURE_CHOICES)
|
|
72
|
+
)
|
|
73
|
+
.addOption(
|
|
74
|
+
new Option('--enable <feature...>', 'enable WASI features').choices(
|
|
75
|
+
FEATURE_CHOICES
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
.option(
|
|
79
|
+
'--debug',
|
|
80
|
+
'configure jco for debug (e.g. disable all features except stdio, etc)'
|
|
62
81
|
)
|
|
63
|
-
// .addOption(new Option('-e, --enable <feature...>', 'enable WASI features').choices(['http']))
|
|
64
82
|
.option(
|
|
65
83
|
'--preview2-adapter <adapter>',
|
|
66
84
|
'provide a custom preview2 adapter path'
|
|
@@ -186,10 +204,10 @@ program
|
|
|
186
204
|
.command('types')
|
|
187
205
|
.description('Generate types for the given WIT')
|
|
188
206
|
.usage('<wit-path> -o <out-dir>')
|
|
189
|
-
.argument('<wit-path>', 'path to a WIT file or directory')
|
|
207
|
+
.argument('[<wit-path>]', 'path to a WIT file or directory')
|
|
190
208
|
.option('--name <name>', 'custom output name')
|
|
191
209
|
.option('-n, --world-name <world>', 'WIT world to generate types for')
|
|
192
|
-
.
|
|
210
|
+
.option('-o, --out-dir <out-dir>', 'output directory')
|
|
193
211
|
.option(
|
|
194
212
|
'--tla-compat',
|
|
195
213
|
'generates types for the TLA compat output with an async $init promise export'
|
|
@@ -224,7 +242,7 @@ program
|
|
|
224
242
|
)
|
|
225
243
|
.option(
|
|
226
244
|
'--async-exports <exports...>',
|
|
227
|
-
'EXPERIMENTAL: async component exports (examples: "wasi:cli/run
|
|
245
|
+
'EXPERIMENTAL: async component exports (examples: "ns:pkg/iface#func", "wasi:cli/run@0.2.3#run", "handle")'
|
|
228
246
|
)
|
|
229
247
|
.option('-q, --quiet', 'disable output summary')
|
|
230
248
|
.option(
|
|
@@ -234,16 +252,19 @@ program
|
|
|
234
252
|
[]
|
|
235
253
|
)
|
|
236
254
|
.option('--all-features', 'enable all features')
|
|
255
|
+
.option(
|
|
256
|
+
"--wasm-opt-bin <path-to-wasm-opt>', 'wasm-opt binary path (default: 'binaryen/bin/wasm-opt')"
|
|
257
|
+
)
|
|
237
258
|
.action(asyncAction(types));
|
|
238
259
|
|
|
239
260
|
program
|
|
240
261
|
.command('guest-types')
|
|
241
262
|
.description('(experimental) Generate guest types for the given WIT')
|
|
242
263
|
.usage('<wit-path> -o <out-dir>')
|
|
243
|
-
.argument('<wit-path>', 'path to a WIT file or directory')
|
|
264
|
+
.argument('[<wit-path>]', 'path to a WIT file or directory')
|
|
244
265
|
.option('--name <name>', 'custom output name')
|
|
245
266
|
.option('-n, --world-name <world>', 'WIT world to generate types for')
|
|
246
|
-
.
|
|
267
|
+
.option('-o, --out-dir <out-dir>', 'output directory')
|
|
247
268
|
.option('-q, --quiet', 'disable output summary')
|
|
248
269
|
.option(
|
|
249
270
|
'--feature <feature>',
|
|
@@ -252,6 +273,18 @@ program
|
|
|
252
273
|
[]
|
|
253
274
|
)
|
|
254
275
|
.option('--all-features', 'enable all features')
|
|
276
|
+
.option(
|
|
277
|
+
'--async-exports <exports...>',
|
|
278
|
+
'EXPERIMENTAL: generate async exports (examples: "ns:pkg/iface#func", "wasi:cli/run@0.2.3#run", "handle")'
|
|
279
|
+
)
|
|
280
|
+
.addOption(
|
|
281
|
+
new Option(
|
|
282
|
+
'--async-mode [mode]',
|
|
283
|
+
'EXPERIMENTAL: use async imports and exports'
|
|
284
|
+
)
|
|
285
|
+
.choices(['sync', 'jspi'])
|
|
286
|
+
.preset('sync')
|
|
287
|
+
)
|
|
255
288
|
.action(asyncAction(guestTypes));
|
|
256
289
|
|
|
257
290
|
program
|
|
@@ -345,6 +378,9 @@ program
|
|
|
345
378
|
)
|
|
346
379
|
.option('--asyncify', 'runs Asyncify pass in wasm-opt')
|
|
347
380
|
.option('-q, --quiet')
|
|
381
|
+
.option(
|
|
382
|
+
"--wasm-opt-bin <path-to-wasm-opt>', 'wasm-opt binary path (default: 'binaryen/bin/wasm-opt')"
|
|
383
|
+
)
|
|
348
384
|
.allowExcessArguments(true)
|
|
349
385
|
.action(asyncAction(opt));
|
|
350
386
|
|
|
@@ -450,7 +486,7 @@ function asyncAction(cmd) {
|
|
|
450
486
|
} catch (e) {
|
|
451
487
|
process.stdout.write(`(jco ${cmd.name}) `);
|
|
452
488
|
if (typeof e === 'string') {
|
|
453
|
-
console.error(
|
|
489
|
+
console.error(`${styleText(['red', 'bold'], "Error")}: ${e}\n`);
|
|
454
490
|
} else {
|
|
455
491
|
console.error(e);
|
|
456
492
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.js"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,8BAHW,UAAU,CAAC,GAAoC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,GAAoC,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,2BAHW,UAAU,CAAC,GAAoC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,GAAoC,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,qCAHW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD;;;;GAIG;AACH,qCAJW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,YAC1D,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD;;;GAGG;AACH,0CAHW,UAAU,CAAC,GAA6C,CAAC,CAAC,CAAC,CAAC,GAC3D,OAAO,CAAC,UAAU,CAAC,GAA6C,CAAC,CAAC,CAK7E;AACD;;;;GAIG;AACH,oCAJW,UAAU,CAAC,GAA0C,CAAC,CAAC,CAAC,CAAC,YACzD,UAAU,CAAC,GAA0C,CAAC,CAAC,CAAC,CAAC,GACxD,OAAO,CAAC,UAAU,CAAC,GAA0C,CAAC,CAAC,CAK1E;AACD;;;GAGG;AACH,qCAHW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD,kDAKC;AACD,kDAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.js"],"names":[],"mappings":"AAMA,uDAGC;AAED,4DAGC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export function setShowSpinner(val: any): void;
|
|
2
|
+
export function getShowSpinner(): boolean;
|
|
3
|
+
export function sizeStr(num: any): string;
|
|
4
|
+
export function fixedDigitDisplay(num: any, maxChars: any): string;
|
|
5
|
+
/**
|
|
6
|
+
* Generate tabular output
|
|
7
|
+
*
|
|
8
|
+
* @param {string[][]} rows - data to put in rows
|
|
9
|
+
* @param {string[]} align - alignment of columns
|
|
10
|
+
* @returns string
|
|
11
|
+
*/
|
|
12
|
+
export function table(rows: string[][], align?: string[]): string;
|
|
13
|
+
/**
|
|
14
|
+
* Securely creates a temporary directory and returns its path.
|
|
15
|
+
*
|
|
16
|
+
* The new directory is created using `fsPromises.mkdtemp()`.
|
|
17
|
+
*
|
|
18
|
+
* @returns {Promise<string>} A `Promise` that resovles to a created temporary directory path
|
|
19
|
+
*/
|
|
20
|
+
export function getTmpDir(): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Spawn a command that processes a given wasm binary bytes with some
|
|
23
|
+
* command.
|
|
24
|
+
*
|
|
25
|
+
* The command invocations that are generated by this function
|
|
26
|
+
* take the following form:
|
|
27
|
+
*
|
|
28
|
+
* ```
|
|
29
|
+
* <cmd> <input wasm file> <...arguments> <output wasm file>
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param {string} cmd - the command to run
|
|
33
|
+
* @param {Buffer<ArrayBufferLike>} inputWasmBytes - bytes that of the input WebAssembly binary
|
|
34
|
+
* @param {string[]} args - arguments to pass to the command (after the input file and before the output file)
|
|
35
|
+
* @returns {Promise<Buffer<ArrayBufferLike>>} A `Promise` that resolves when the command has exited
|
|
36
|
+
*/
|
|
37
|
+
export function spawnIOTmp(cmd: string, inputWasmBytes: Buffer<ArrayBufferLike>, args: string[]): Promise<Buffer<ArrayBufferLike>>;
|
|
38
|
+
/**
|
|
39
|
+
* Given an object that has file names as keys and file contents as values,
|
|
40
|
+
* write out the files to a their locations.
|
|
41
|
+
*
|
|
42
|
+
* This function also prints out the files that were written
|
|
43
|
+
*
|
|
44
|
+
* @param {Record<string, string>} files - object which contains files to be written out
|
|
45
|
+
* @param {boolean} summaryTitle - whether to print the summary after writing out files
|
|
46
|
+
* @returns {Promise<void>>} A `Promise` that resolves when the fiels are all written
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
export function writeFiles(files: Record<string, string>, summaryTitle: boolean): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Resolve the deafult WIT path, given a possibly
|
|
52
|
+
*
|
|
53
|
+
* @param {string | undefined} [witPath]
|
|
54
|
+
* @returns {Promise<string>}
|
|
55
|
+
*/
|
|
56
|
+
export function resolveDefaultWITPath(witPath?: string | undefined): Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Partial polyfill for 'node:utils' `styleText()`
|
|
59
|
+
*
|
|
60
|
+
* @param {string | string[]} styles - styles to apply to the given text
|
|
61
|
+
* @param {string} text - text that should be styled
|
|
62
|
+
* @returns {string} The styled string
|
|
63
|
+
*/
|
|
64
|
+
export function styleText(styles: string | string[], text: string): string;
|
|
65
|
+
export const isWindows: boolean;
|
|
66
|
+
export const ASYNC_WASI_IMPORTS: string[];
|
|
67
|
+
export const ASYNC_WASI_EXPORTS: string[];
|
|
68
|
+
export const DEFAULT_ASYNC_MODE: "sync";
|
|
69
|
+
/** Path of WIT files by default when one is not specified */
|
|
70
|
+
export const DEFAULT_WIT_PATH: "./wit";
|
|
71
|
+
export { readFileCli as readFile };
|
|
72
|
+
/**
|
|
73
|
+
* Read a given file, throwing a formatted error if one occurs
|
|
74
|
+
*
|
|
75
|
+
* @param {string} filePath - path to teh file to read
|
|
76
|
+
* @param {encoding} encoding - file encoding
|
|
77
|
+
* @returns {Promise<Buffer>} A promise that resolves to the contents of the file
|
|
78
|
+
*/
|
|
79
|
+
declare function readFileCli(filePath: string, encoding: any): Promise<Buffer>;
|
|
80
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.js"],"names":[],"mappings":"AAuCA,+CAEC;AACD,0CAIC;AAED,0CASC;AAED,mEAcC;AAED;;;;;;GAMG;AACH,4BAJW,MAAM,EAAE,EAAE,UACV,MAAM,EAAE,UAuBlB;AAED;;;;;;GAMG;AACH,6BAFa,OAAO,CAAC,MAAM,CAAC,CAI3B;AAkBD;;;;;;;;;;;;;;;GAeG;AACH,gCALW,MAAM,kBACN,MAAM,CAAC,eAAe,CAAC,QACvB,MAAM,EAAE,GACN,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAmC5C;AAED;;;;;;;;;;GAUG;AACH,kCALW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,gBACtB,OAAO,GACL,OAAO,CAAC,IAAI,CAAC,CAsBzB;AAED;;;;;GAKG;AACH,gDAHW,MAAM,GAAG,SAAS,GAChB,OAAO,CAAC,MAAM,CAAC,CAqB3B;AAED;;;;;;GAMG;AACH,kCAJW,MAAM,GAAG,MAAM,EAAE,QACjB,MAAM,GACJ,MAAM,CAOlB;AA9OD,gCAA8C;AAE9C,0CASE;AAEF,0CAGE;AAEF,iCAAkC,MAAM,CAAC;AAEzC,6DAA6D;AAC7D,+BAAgC,OAAO,CAAC;;AA+ExC;;;;;;GAMG;AACH,uCAJW,MAAM,kBAEJ,OAAO,CAAC,MAAM,CAAC,CAQ3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jco.d.ts","sourceRoot":"","sources":["../src/jco.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ora-shim.d.ts","sourceRoot":"","sources":["../src/ora-shim.js"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,mCAEC;AAED;IACI,cAAU;IACV,aAAS;CACZ"}
|
package/src/api.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["api.js"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,8BAHW,UAAU,CAAC,GAAoC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,GAAoC,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,2BAHW,UAAU,CAAC,GAAoC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,GAAoC,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,qCAHW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD;;;;GAIG;AACH,qCAJW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,YAC1D,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD;;;GAGG;AACH,0CAHW,UAAU,CAAC,GAA6C,CAAC,CAAC,CAAC,CAAC,GAC3D,OAAO,CAAC,UAAU,CAAC,GAA6C,CAAC,CAAC,CAK7E;AACD;;;;GAIG;AACH,oCAJW,UAAU,CAAC,GAA0C,CAAC,CAAC,CAAC,CAAC,YACzD,UAAU,CAAC,GAA0C,CAAC,CAAC,CAAC,CAAC,GACxD,OAAO,CAAC,UAAU,CAAC,GAA0C,CAAC,CAAC,CAK1E;AACD;;;GAGG;AACH,qCAHW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD,kDAKC;AACD,kDAKC"}
|
package/src/browser.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["browser.js"],"names":[],"mappings":"AAMA,uDAGC;AAED,4DAGC"}
|