From c4e64409453253040b860f82b580d7c2ab37b6e4 Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Thu, 30 Jan 2025 18:08:22 -0600 Subject: [PATCH] fixes from code review --- .../js-component-bindgen/src/transpile_bindgen.rs | 15 ++++++--------- src/cmd/transpile.js | 8 ++++---- src/jco.js | 8 ++++---- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/crates/js-component-bindgen/src/transpile_bindgen.rs b/crates/js-component-bindgen/src/transpile_bindgen.rs index 63aff83a0..642630b85 100644 --- a/crates/js-component-bindgen/src/transpile_bindgen.rs +++ b/crates/js-component-bindgen/src/transpile_bindgen.rs @@ -267,15 +267,6 @@ impl JsBindgen<'_> { } } - // adds a default implementation of `getCoreModule` - if matches!(self.opts.instantiation, Some(InstantiationMode::Async)) { - uwriteln!( - compilation_promises, - "if (!getCoreModule) getCoreModule = (name) => {}(new URL(`./${{name}}`, import.meta.url));", - self.intrinsic(Intrinsic::FetchCompile) - ); - } - // Setup the compilation data and compilation promises let mut removed = BTreeSet::new(); for i in 0..self.core_module_cnt { @@ -318,6 +309,12 @@ impl JsBindgen<'_> { self.opts.instantiation.is_some(), ); + uwriteln!( + js_intrinsics, + "if (!getCoreModule) getCoreModule = (name) => {}(new URL(`./${{name}}`, import.meta.url));", + self.intrinsic(Intrinsic::FetchCompile) + ); + if let Some(instantiation) = &self.opts.instantiation { uwrite!( output, diff --git a/src/cmd/transpile.js b/src/cmd/transpile.js index 5dc295f18..865439075 100644 --- a/src/cmd/transpile.js +++ b/src/cmd/transpile.js @@ -76,9 +76,9 @@ export async function typesComponent (witPath, opts) { features = { tag: 'list', val: opts.feature }; } - if (opts.defaultAsyncImports) + if (opts.asyncWasiImports) opts.asyncImports = DEFAULT_ASYNC_IMPORTS.concat(opts.asyncImports || []); - if (opts.defaultAsyncExports) + if (opts.asyncWasiExports) opts.asyncExports = DEFAULT_ASYNC_EXPORTS.concat(opts.asyncExports || []); const asyncMode = !opts.asyncMode || opts.asyncMode === 'sync' ? @@ -141,9 +141,9 @@ export async function transpile (componentPath, opts, program) { if (opts.map) opts.map = Object.fromEntries(opts.map.map(mapping => mapping.split('='))); - if (opts.defaultAsyncImports) + if (opts.asyncWasiImports) opts.asyncImports = DEFAULT_ASYNC_IMPORTS.concat(opts.asyncImports || []); - if (opts.defaultAsyncExports) + if (opts.asyncWasiExports) opts.asyncExports = DEFAULT_ASYNC_EXPORTS.concat(opts.asyncExports || []); const { files } = await transpileComponent(component, opts); diff --git a/src/jco.js b/src/jco.js index 9ea13cf5d..251c10a5a 100755 --- a/src/jco.js +++ b/src/jco.js @@ -53,8 +53,8 @@ program.command('transpile') .option('--valid-lifting-optimization', 'optimize component binary validations assuming all lifted values are valid') .addOption(new Option('--import-bindings [mode]', 'bindings mode for imports').choices(['js', 'optimized', 'hybrid', 'direct-optimized']).preset('js')) .addOption(new Option('--async-mode [mode]', 'EXPERIMENTAL: use async imports and exports').choices(['sync', 'jspi']).preset('sync')) - .option('--default-async-imports', 'EXPERIMENTAL: default async component imports from WASI interfaces') - .option('--default-async-exports', 'EXPERIMENTAL: default async component exports from WASI interfaces') + .option('--async-wasi-imports', 'EXPERIMENTAL: async component imports from WASI interfaces') + .option('--async-wasi-exports', 'EXPERIMENTAL: async component exports from WASI interfaces') .option('--async-imports ', 'EXPERIMENTAL: async component imports (examples: "wasi:io/poll@0.2.0#poll", "wasi:io/poll#[method]pollable.block")') .option('--async-exports ', 'EXPERIMENTAL: async component exports (examples: "wasi:cli/run@#run", "handle")') .option('--tracing', 'emit `tracing` calls on function entry/exit') @@ -82,8 +82,8 @@ program.command('types') .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')) .addOption(new Option('--async-mode [mode]', 'EXPERIMENTAL: use async imports and exports').choices(['sync', 'jspi']).preset('sync')) - .option('--default-async-imports', 'EXPERIMENTAL: default async component imports from WASI interfaces') - .option('--default-async-exports', 'EXPERIMENTAL: default async component exports from WASI interfaces') + .option('--async-wasi-imports', 'EXPERIMENTAL: async component imports from WASI interfaces') + .option('--async-wasi-exports', 'EXPERIMENTAL: async component exports from WASI interfaces') .option('--async-imports ', 'EXPERIMENTAL: async component imports (examples: "wasi:io/poll@0.2.0#poll", "wasi:io/poll#[method]pollable.block")') .option('--async-exports ', 'EXPERIMENTAL: async component exports (examples: "wasi:cli/run@#run", "handle")') .option('-q, --quiet', 'disable output summary')