@bytecodealliance/jco
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -16,2 +16,7 @@ export namespace WasiIoStreams { | ||
export class InputStream { | ||
read(len: bigint): Uint8Array; | ||
blockingRead(len: bigint): Uint8Array; | ||
} | ||
export class OutputStream { | ||
@@ -23,6 +28,1 @@ checkWrite(): bigint; | ||
} | ||
export class InputStream { | ||
read(len: bigint): Uint8Array; | ||
blockingRead(len: bigint): Uint8Array; | ||
} |
{ | ||
"name": "@bytecodealliance/jco", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "JavaScript tooling for working with WebAssembly Components", | ||
@@ -21,3 +21,3 @@ "author": "Guy Bedford", | ||
"dependencies": { | ||
"@bytecodealliance/preview2-shim": "^0.16.1", | ||
"@bytecodealliance/preview2-shim": "^0.16.2", | ||
"binaryen": "^116.0.0", | ||
@@ -31,3 +31,3 @@ "chalk-template": "^1", | ||
"devDependencies": { | ||
"@bytecodealliance/componentize-js": "^0.8.0", | ||
"@bytecodealliance/componentize-js": "^0.8.3", | ||
"@types/node": "^18.11.17", | ||
@@ -59,3 +59,3 @@ "@typescript-eslint/eslint-plugin": "^5.41.0", | ||
"build:types:preview2-shim": "cargo xtask generate wasi-types", | ||
"lint": "eslint -c eslintrc.cjs lib/**/*.js packages/*/lib/**/*.js", | ||
"lint": "eslint -c eslintrc.cjs src/**/*.js packages/*/lib/**/*.js", | ||
"test:lts": "mocha -u tdd test/test.js --timeout 30000", | ||
@@ -68,3 +68,6 @@ "test": "node --stack-trace-limit=100 --experimental-wasm-multi-memory node_modules/mocha/bin/mocha.js -u tdd test/test.js --timeout 30000", | ||
"src", | ||
"obj" | ||
"obj/*.core.wasm", | ||
"obj/*.js", | ||
"obj/*.ts", | ||
"obj/interfaces" | ||
], | ||
@@ -71,0 +74,0 @@ "workspaces": [ |
@@ -153,4 +153,2 @@ <div align="center"> | ||
> Additional engines might be supported in future via an `--engine` field or otherwise. | ||
## API | ||
@@ -157,0 +155,0 @@ |
@@ -41,3 +41,3 @@ /** | ||
export { optimizeComponent as opt } from "./cmd/opt.js"; | ||
export { transpileComponent as transpile } from "./cmd/transpile.js"; | ||
export { transpileComponent as transpile, typesComponent as types } from "./cmd/transpile.js"; | ||
//# sourceMappingURL=api.d.ts.map |
export { optimizeComponent as opt } from './cmd/opt.js'; | ||
export { transpileComponent as transpile } from './cmd/transpile.js'; | ||
export { transpileComponent as transpile, typesComponent as types } from './cmd/transpile.js'; | ||
import { $init, tools } from "../obj/wasm-tools.js"; | ||
@@ -4,0 +4,0 @@ const { print: printFn, parse: parseFn, componentWit: componentWitFn, componentNew: componentNewFn, componentEmbed: componentEmbedFn, metadataAdd: metadataAddFn, metadataShow: metadataShowFn } = tools; |
@@ -15,11 +15,11 @@ import { readFile, writeFile } from 'node:fs/promises'; | ||
const source = await readFile(jsSource, 'utf8'); | ||
const { component, imports } = await componentizeFn(source, { | ||
const { component } = await componentizeFn(source, { | ||
sourceName: basename(jsSource), | ||
witPath: resolve(opts.wit), | ||
worldName: opts.worldName, | ||
enableStdout: opts.enableStdout, | ||
disableFeatures: opts.disable, | ||
preview2Adapter: opts.preview2Adapter, | ||
}); | ||
await writeFile(opts.out, component); | ||
console.log(c`{green OK} Successfully written {bold ${opts.out}} with imports (${imports.join(', ')}).`); | ||
console.log(c`{green OK} Successfully written {bold ${opts.out}}.`); | ||
} |
@@ -95,3 +95,5 @@ import { getTmpDir } from '../common.js'; | ||
} | ||
catch {} | ||
catch { | ||
// empty | ||
} | ||
let len = preview2ShimPath.length; | ||
@@ -138,4 +140,6 @@ preview2ShimPath = resolve(preview2ShimPath, '..', '..', '..', 'node_modules', '@bytecodealliance', 'preview2-shim'); | ||
await rm(outDir, { recursive: true }); | ||
} catch {} | ||
} catch { | ||
// empty | ||
} | ||
} | ||
} |
@@ -0,1 +1,22 @@ | ||
export function types(witPath: any, opts: any): Promise<void>; | ||
/** | ||
* @param {string} witPath | ||
* @param {{ | ||
* name?: string, | ||
* worldName?: string, | ||
* instantiation?: 'async' | 'sync', | ||
* tlaCompat?: bool, | ||
* outDir?: string, | ||
* }} opts | ||
* @returns {Promise<{ [filename: string]: Uint8Array }>} | ||
*/ | ||
export function typesComponent(witPath: string, opts: { | ||
name?: string; | ||
worldName?: string; | ||
instantiation?: 'async' | 'sync'; | ||
tlaCompat?: bool; | ||
outDir?: string; | ||
}): Promise<{ | ||
[filename: string]: Uint8Array; | ||
}>; | ||
export function transpile(componentPath: any, opts: any, program: any): Promise<void>; | ||
@@ -8,2 +29,3 @@ /** | ||
* instantiation?: 'async' | 'sync', | ||
* importBindings?: 'js' | 'optimized', 'hybrid', 'direct-optimized', | ||
* map?: Record<string, string>, | ||
@@ -19,2 +41,4 @@ * validLiftingOptimization?: bool, | ||
* namespacedExports?: bool, | ||
* outDir?: string, | ||
* multiMemory?: bool, | ||
* optArgs?: string[], | ||
@@ -27,2 +51,5 @@ * }} opts | ||
instantiation?: 'async' | 'sync'; | ||
importBindings?: 'js' | 'optimized'; | ||
hybrid: any; | ||
'direct-optimized': any; | ||
map?: Record<string, string>; | ||
@@ -38,2 +65,4 @@ validLiftingOptimization?: bool; | ||
namespacedExports?: bool; | ||
outDir?: string; | ||
multiMemory?: bool; | ||
optArgs?: string[]; | ||
@@ -47,3 +76,3 @@ }): Promise<{ | ||
}>; | ||
import { minify } from "terser"; | ||
import { minify } from 'terser'; | ||
//# sourceMappingURL=transpile.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { $init, generate } from '../../obj/js-component-bindgen-component.js'; | ||
import { $init, generate, generateTypes } from '../../obj/js-component-bindgen-component.js'; | ||
import { writeFile } from 'node:fs/promises'; | ||
@@ -17,2 +17,54 @@ import { mkdir } from 'node:fs/promises'; | ||
export async function types (witPath, opts) { | ||
const files = await typesComponent(witPath, opts); | ||
await writeFiles(files, opts.quiet ? false : 'Generated Type Files'); | ||
} | ||
/** | ||
* @param {string} witPath | ||
* @param {{ | ||
* name?: string, | ||
* worldName?: string, | ||
* instantiation?: 'async' | 'sync', | ||
* tlaCompat?: bool, | ||
* outDir?: string, | ||
* }} opts | ||
* @returns {Promise<{ [filename: string]: Uint8Array }>} | ||
*/ | ||
export async function typesComponent (witPath, opts) { | ||
await $init; | ||
const name = opts.name || (opts.worldName | ||
? opts.worldName.split(':').pop().split('/').pop() | ||
: basename(witPath.slice(0, -extname(witPath).length || Infinity))); | ||
let instantiation; | ||
if (opts.instantiation) { | ||
instantiation = { tag: opts.instantiation }; | ||
} | ||
let outDir = (opts.outDir ?? '').replace(/\\/g, '/'); | ||
if (!outDir.endsWith('/') && outDir !== '') | ||
outDir += '/'; | ||
return Object.fromEntries(generateTypes(name, { | ||
wit: { tag: 'path', val: (isWindows ? '//?/' : '') + resolve(witPath) }, | ||
instantiation, | ||
tlaCompat: opts.tlaCompat ?? false, | ||
world: opts.worldName | ||
}).map(([name, file]) => [`${outDir}${name}`, file])); | ||
} | ||
async function writeFiles(files, summaryTitle) { | ||
await Promise.all(Object.entries(files).map(async ([name, file]) => { | ||
await mkdir(dirname(name), { recursive: true }); | ||
await writeFile(name, file); | ||
})); | ||
if (!summaryTitle) | ||
return; | ||
console.log(c` | ||
{bold ${summaryTitle}:} | ||
${table(Object.entries(files).map(([name, source]) => [ | ||
c` - {italic ${name}} `, | ||
c`{black.italic ${sizeStr(source.length)}}` | ||
]))}`); | ||
} | ||
export async function transpile (componentPath, opts, program) { | ||
@@ -41,16 +93,3 @@ const varIdx = program?.parent.rawArgs.indexOf('--'); | ||
const { files } = await transpileComponent(component, opts); | ||
await Promise.all(Object.entries(files).map(async ([name, file]) => { | ||
await mkdir(dirname(name), { recursive: true }); | ||
await writeFile(name, file); | ||
})); | ||
if (!opts.quiet) | ||
console.log(c` | ||
{bold Transpiled JS Component Files:} | ||
${table(Object.entries(files).map(([name, source]) => [ | ||
c` - {italic ${name}} `, | ||
c`{black.italic ${sizeStr(source.length)}}` | ||
]))}`); | ||
await writeFiles(files, opts.quiet ? false : 'Transpiled JS Component Files'); | ||
} | ||
@@ -96,2 +135,3 @@ | ||
* namespacedExports?: bool, | ||
* outDir?: string, | ||
* multiMemory?: bool, | ||
@@ -290,3 +330,3 @@ * optArgs?: string[], | ||
.map(([name]) => { | ||
if (name === asmMangle(name)) { | ||
if (name === asmMangle(name)){ | ||
return ` ${name},`; | ||
@@ -293,0 +333,0 @@ } else { |
#!/usr/bin/env node | ||
import { program, Option } from 'commander'; | ||
import { opt } from './cmd/opt.js'; | ||
import { transpile } from './cmd/transpile.js'; | ||
import { transpile, types } from './cmd/transpile.js'; | ||
import { run as runCmd, serve as serveCmd } from './cmd/run.js'; | ||
@@ -14,3 +14,3 @@ import { parse, print, componentNew, componentEmbed, metadataAdd, metadataShow, componentWit } from './cmd/wasm-tools.js'; | ||
.usage('<command> [options]') | ||
.version('1.1.1'); | ||
.version('1.2.0'); | ||
@@ -27,3 +27,3 @@ function myParseInt(value) { | ||
.option('-n, --world-name <name>', 'WIT world to build') | ||
.option('--enable-stdout', 'Allow console.log to output to stdout') | ||
.addOption(new Option('-d, --disable <feature...>', 'disable WASI features').choices(['stdio', 'random', 'clocks'])) | ||
.option('--preview2-adapter <adapter>', 'provide a custom preview2 adapter path') | ||
@@ -53,3 +53,3 @@ .requiredOption('-o, --out <out>', 'output component file') | ||
.addOption(new Option('-I, --instantiation [mode]', 'output for custom module instantiation').choices(['async', 'sync']).preset('async')) | ||
.option('-q, --quiet', 'disable logging') | ||
.option('-q, --quiet', 'disable output summary') | ||
.option('--no-namespaced-exports', 'disable namespaced exports for typescript compatibility') | ||
@@ -60,2 +60,14 @@ .option('--multi-memory', 'optimized output for Wasm multi-memory') | ||
program.command('types') | ||
.description('Generate types for the given WIT') | ||
.usage('<wit-path> -o <out-dir>') | ||
.argument('<wit-path>', 'path to a WIT file or directory') | ||
.option('--name <name>', 'custom output name') | ||
.option('-n, --world-name <world>', 'WIT world to generate types for') | ||
.requiredOption('-o, --out-dir <out-dir>', 'output directory') | ||
.option('--tla-compat', 'generates types for the TLA compat output with an async $init promise export') | ||
.addOption(new Option('-I, --instantiation [mode]', 'type output for custom module instantiation').choices(['async', 'sync']).preset('async')) | ||
.option('-q, --quiet', 'disable output summary') | ||
.action(asyncAction(types)); | ||
program.command('run') | ||
@@ -165,3 +177,3 @@ .description('Run a WASI Command component') | ||
.option('--string-encoding <utf8|utf16|compact-utf16>', 'set the component string encoding') | ||
.option('--world <world-name>', 'positional world path to embed') | ||
.option('-n, --world-name <world-name>', 'world name to embed') | ||
.option('-m, --metadata <metadata...>', 'field=name[@version] producer metadata to add with the embedding') | ||
@@ -168,0 +180,0 @@ .action(asyncAction(componentEmbed)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
9958
4574920
58
205