From 7bee6a8c194c84ece8404c6cbdb121dcf24ffd99 Mon Sep 17 00:00:00 2001 From: Pauan Date: Wed, 29 Apr 2020 20:59:49 +0200 Subject: [PATCH] Fixing require to be ignored by Webpack (#2115) * Fixing require to be ignored by Webpack * Making the module.require even more dynamic, to trick Webpack --- crates/cli-support/src/js/mod.rs | 2 +- crates/cli/tests/reference/anyref-import-catch.js | 2 +- crates/cli/tests/reference/string-arg.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index ed305ff9..afd5dfe9 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -1251,7 +1251,7 @@ impl<'a> Context<'a> { self.global(&format!( " const l{0} = typeof {0} === 'undefined' ? \ - require('util').{0} : {0};\ + (0, module.require)('util').{0} : {0};\ ", s )); diff --git a/crates/cli/tests/reference/anyref-import-catch.js b/crates/cli/tests/reference/anyref-import-catch.js index 0ad9ccc5..6a059a65 100644 --- a/crates/cli/tests/reference/anyref-import-catch.js +++ b/crates/cli/tests/reference/anyref-import-catch.js @@ -1,6 +1,6 @@ import * as wasm from './reference_test_bg.wasm'; -const lTextDecoder = typeof TextDecoder === 'undefined' ? require('util').TextDecoder : TextDecoder; +const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); diff --git a/crates/cli/tests/reference/string-arg.js b/crates/cli/tests/reference/string-arg.js index c830c61c..dad77bfa 100644 --- a/crates/cli/tests/reference/string-arg.js +++ b/crates/cli/tests/reference/string-arg.js @@ -1,6 +1,6 @@ import * as wasm from './reference_test_bg.wasm'; -const lTextDecoder = typeof TextDecoder === 'undefined' ? require('util').TextDecoder : TextDecoder; +const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); @@ -20,7 +20,7 @@ function getStringFromWasm0(ptr, len) { let WASM_VECTOR_LEN = 0; -const lTextEncoder = typeof TextEncoder === 'undefined' ? require('util').TextEncoder : TextEncoder; +const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; let cachedTextEncoder = new lTextEncoder('utf-8');