Skip to content

Commit b66df4d

Browse files
author
Guy Bedford
authored
gen-host-js: --nodejs-compat default / --no-nodejs-compat (#427)
1 parent 6d48630 commit b66df4d

4 files changed

Lines changed: 10 additions & 13 deletions

File tree

crates/gen-host-js/src/lib.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub struct Opts {
6161
long,
6262
short = 'I',
6363
conflicts_with = "compatibility",
64+
conflicts_with = "no-compatibility",
6465
conflicts_with = "compat"
6566
)
6667
)]
@@ -72,15 +73,12 @@ pub struct Opts {
7273
/// component import specifiers to JS import specifiers.
7374
#[cfg_attr(feature = "clap", arg(long), clap(value_parser = maps_str_to_map))]
7475
pub map: Option<HashMap<String, String>>,
75-
/// Enables all compat flags: --nodejs-compat, --tla-compat.
76+
/// Enables all compat flags: --tla-compat.
7677
#[cfg_attr(feature = "clap", arg(long, short = 'c'))]
7778
pub compat: bool,
78-
/// Enables compatibility in Node.js without a fetch global.
79-
#[cfg_attr(
80-
feature = "clap",
81-
arg(long, group = "compatibility", conflicts_with = "compat")
82-
)]
83-
pub nodejs_compat: bool,
79+
/// Disables compatibility in Node.js without a fetch global.
80+
#[cfg_attr(feature = "clap", arg(long, group = "no-compatibility"))]
81+
pub no_nodejs_compat: bool,
8482
/// Enables compatibility for JS environments without top-level await support
8583
/// via an async $init promise export to wait for instead.
8684
#[cfg_attr(feature = "clap", arg(long, group = "compatibility"))]
@@ -108,7 +106,6 @@ impl Opts {
108106
let mut gen = Js::default();
109107
gen.opts = self;
110108
if gen.opts.compat {
111-
gen.opts.nodejs_compat = true;
112109
gen.opts.tla_compat = true;
113110
}
114111
Ok(Box::new(gen))
@@ -569,7 +566,7 @@ impl Js {
569566
"),
570567

571568
Intrinsic::LoadWasm => match self.opts.load {
572-
Load::Fetch => if self.opts.nodejs_compat {
569+
Load::Fetch => if !self.opts.no_nodejs_compat {
573570
self.src.js_intrinsics("
574571
const isNode = typeof process !== 'undefined' && process.versions && process.versions.node;
575572
let _fs;
@@ -586,7 +583,7 @@ impl Js {
586583
const loadWasm = url => fetch(url).then(WebAssembly.compileStreaming);
587584
")
588585
},
589-
Load::Base64 => if self.opts.nodejs_compat {
586+
Load::Base64 => if !self.opts.no_nodejs_compat {
590587
self.src.js_intrinsics("
591588
const loadWasm = str => WebAssembly.compile(typeof Buffer !== 'undefined' ? Buffer.from(str, 'base64') : Uint8Array.from(atob(str), b => b.charCodeAt(0)));
592589
")

tests/runtime/exports_only/host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --nodejs-compat --valid-lifting-optimization
1+
// Flags: --valid-lifting-optimization
22
// @ts-ignore
33
import { ok, strictEqual } from 'assert';
44
// @ts-ignore

tests/runtime/flavorful/host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --nodejs-compat --map testwasi=./helpers.js,imports=./host.js
1+
// Flags: --map testwasi=./helpers.js,imports=./host.js
22

33
// @ts-ignore
44
import * as assert from 'assert';

tests/runtime/smoke/host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --load=base64 --compat --map testwasi=./helpers.js,imports=./host.js
1+
// Flags: --no-nodejs-compat --load=base64 --compat --map testwasi=./helpers.js,imports=./host.js
22
function assert(x: boolean, msg: string) {
33
if (!x)
44
throw new Error(msg);

0 commit comments

Comments
 (0)