@bytecodealliance/jco 1.0.2 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/jco",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "JavaScript tooling for working with WebAssembly Components",
5
5
  "author": "Guy Bedford",
6
6
  "bin": {
@@ -18,16 +18,16 @@
18
18
  },
19
19
  "type": "module",
20
20
  "dependencies": {
21
- "@bytecodealliance/preview2-shim": "0.15.1",
22
- "binaryen": "^111.0.0",
23
- "chalk-template": "^0.4.0",
24
- "commander": "^9.4.1",
25
- "mkdirp": "^1.0.4",
26
- "ora": "^6.1.2",
27
- "terser": "^5.16.1"
21
+ "@bytecodealliance/preview2-shim": "0.16.0",
22
+ "binaryen": "^116.0.0",
23
+ "chalk-template": "^1",
24
+ "commander": "^12",
25
+ "mkdirp": "^3",
26
+ "ora": "^8",
27
+ "terser": "^5"
28
28
  },
29
29
  "devDependencies": {
30
- "@bytecodealliance/componentize-js": "^0.7.0",
30
+ "@bytecodealliance/componentize-js": "^0.8.0",
31
31
  "@types/node": "^18.11.17",
32
32
  "@typescript-eslint/eslint-plugin": "^5.41.0",
33
33
  "@typescript-eslint/parser": "^5.41.0",
@@ -56,7 +56,7 @@
56
56
  "build:types:preview2-shim": "cargo xtask generate wasi-types",
57
57
  "lint": "eslint -c eslintrc.cjs lib/**/*.js packages/*/lib/**/*.js",
58
58
  "test:lts": "mocha -u tdd test/test.js --timeout 30000",
59
- "test": "node --experimental-wasm-multi-memory node_modules/mocha/bin/mocha.js -u tdd test/test.js --timeout 30000",
59
+ "test": "node --stack-trace-limit=100 --experimental-wasm-multi-memory node_modules/mocha/bin/mocha.js -u tdd test/test.js --timeout 30000",
60
60
  "prepublishOnly": "cargo xtask build release && npm run test"
61
61
  },
62
62
  "files": [
@@ -1,7 +1,6 @@
1
1
  import { readFile, writeFile } from 'node:fs/promises';
2
- import { resolve } from 'node:path';
2
+ import { resolve, basename } from 'node:path';
3
3
  import c from 'chalk-template';
4
- import { isWindows } from '../common.js';
5
4
 
6
5
  export async function componentize (jsSource, opts) {
7
6
  let componentizeFn;
@@ -14,6 +13,7 @@ export async function componentize (jsSource, opts) {
14
13
  }
15
14
  const source = await readFile(jsSource, 'utf8');
16
15
  const { component, imports } = await componentizeFn(source, {
16
+ sourceName: basename(jsSource),
17
17
  witPath: resolve(opts.wit),
18
18
  worldName: opts.worldName,
19
19
  enableStdout: opts.enableStdout,
package/src/cmd/run.js CHANGED
@@ -2,7 +2,7 @@ import { getTmpDir } from '../common.js';
2
2
  import { transpile } from './transpile.js';
3
3
  import { rm, stat, mkdir, writeFile, symlink } from 'node:fs/promises';
4
4
  import { basename, resolve, extname } from 'node:path';
5
- import { fork } from 'node:child_process';
5
+ import { spawn } from 'node:child_process';
6
6
  import process from 'node:process';
7
7
  import { fileURLToPath, pathToFileURL } from 'node:url';
8
8
  import c from 'chalk-template';
@@ -75,7 +75,8 @@ async function runComponent (componentPath, args, opts, executor) {
75
75
  wasiShim: true,
76
76
  outDir,
77
77
  tracing: opts.jcoTrace,
78
- map: opts.jcoMap
78
+ map: opts.jcoMap,
79
+ importBindings: opts.jcoImportBindings,
79
80
  });
80
81
  }
81
82
  catch (e) {
@@ -112,6 +113,7 @@ async function runComponent (componentPath, args, opts, executor) {
112
113
  const runPath = resolve(outDir, '_run.js');
113
114
  await writeFile(runPath, `
114
115
  ${jcoImport ? `import ${JSON.stringify(pathToFileURL(jcoImport))}` : ''}
116
+ import process from 'node:process';
115
117
  try {
116
118
  process.argv[1] = "${name}";
117
119
  } catch {}
@@ -119,8 +121,10 @@ async function runComponent (componentPath, args, opts, executor) {
119
121
  ${executor}
120
122
  `);
121
123
 
124
+ const nodePath = process.env.JCO_RUN_PATH || process.argv[0];
125
+
122
126
  process.exitCode = await new Promise((resolve, reject) => {
123
- const cp = fork(runPath, args, { stdio: 'inherit' });
127
+ const cp = spawn(nodePath, [...process.env.JCO_RUN_ARGS ? process.env.JCO_RUN_ARGS.split(' ') : [], runPath, ...args], { stdio: 'inherit' });
124
128
 
125
129
  cp.on('error', reject);
126
130
  cp.on('exit', resolve);
@@ -80,6 +80,7 @@ async function wasm2Js (source) {
80
80
  * @param {{
81
81
  * name: string,
82
82
  * instantiation?: 'async' | 'sync',
83
+ * importBindings?: 'js' | 'optimized', 'hybrid', 'direct-optimized',
83
84
  * map?: Record<string, string>,
84
85
  * validLiftingOptimization?: bool,
85
86
  * tracing?: bool,
@@ -133,6 +134,7 @@ export async function transpileComponent (component, opts = {}) {
133
134
  name: opts.name ?? 'component',
134
135
  map: Object.entries(opts.map ?? {}),
135
136
  instantiation,
137
+ importBindings: opts.importBindings ? { tag: opts.importBindings } : null,
136
138
  validLiftingOptimization: opts.validLiftingOptimization ?? false,
137
139
  tracing: opts.tracing ?? false,
138
140
  noNodejsCompat: opts.nodejsCompat === false,
package/src/jco.js CHANGED
@@ -11,7 +11,7 @@ program
11
11
  .name('jco')
12
12
  .description(c`{bold jco - WebAssembly JS Component Tools}\n JS Component Transpilation Bindgen & Wasm Tools for JS`)
13
13
  .usage('<command> [options]')
14
- .version('1.0.2');
14
+ .version('1.1.0');
15
15
 
16
16
  function myParseInt(value) {
17
17
  return parseInt(value, 10);
@@ -38,6 +38,7 @@ program.command('transpile')
38
38
  .option('-O, --optimize', 'optimize the component first')
39
39
  .option('--no-typescript', 'do not output TypeScript .d.ts types')
40
40
  .option('--valid-lifting-optimization', 'optimize component binary validations assuming all lifted values are valid')
41
+ .addOption(new Option('--import-bindings [mode]', 'bindings mode for imports').choices(['js', 'optimized', 'hybrid', 'direct-optimized']).preset('js'))
41
42
  .option('--tracing', 'emit `tracing` calls on function entry/exit')
42
43
  .option('-b, --base64-cutoff <bytes>', 'set the byte size under which core Wasm binaries will be inlined as base64', myParseInt)
43
44
  .option('--tla-compat', 'enables compatibility for JS environments without top-level await support via an async $init promise export')
@@ -64,6 +65,7 @@ program.command('run')
64
65
  .option('--jco-trace', 'Enable call tracing')
65
66
  .option('--jco-import <module>', 'Custom module to import before the run executes to support custom environment setup')
66
67
  .option('--jco-map <mappings...>', 'specifier=./output custom mappings for the component imports')
68
+ .addOption(new Option('--jco-import-bindings [mode]', 'bindings mode for imports').choices(['js', 'optimized', 'hybrid', 'direct-optimized']).preset('js'))
67
69
  .argument('[args...]', 'Any CLI arguments for the component')
68
70
  .action(asyncAction(async function run (cmd, args, opts, command) {
69
71
  // specially only allow help option in first position
@@ -86,6 +88,7 @@ program.command('serve')
86
88
  .option('--jco-dir <dir>', 'Instead of using a temporary dir, set the output directory for the transpiled code')
87
89
  .option('--jco-trace', 'Enable call tracing')
88
90
  .option('--jco-import <module>', 'Custom module to import before the server executes to support custom environment setup')
91
+ .addOption(new Option('--jco-import-bindings [mode]', 'bindings mode for imports').choices(['js', 'optimized', 'hybrid', 'direct-optimized']).preset('js'))
89
92
  .option('--jco-map <mappings...>', 'specifier=./output custom mappings for the component imports')
90
93
  .argument('[args...]', 'Any CLI arguments for the component')
91
94
  .action(asyncAction(async function serve (cmd, args, opts, command) {