|
1 | 1 | var Module = (() => { |
2 | | - var _scriptName = import.meta.url; |
3 | | - |
| 2 | + var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined; |
| 3 | + if (typeof __filename != 'undefined') _scriptName = _scriptName || __filename; |
4 | 4 | return ( |
5 | 5 | async function(moduleArg = {}) { |
6 | 6 | var moduleRtn; |
@@ -40,11 +40,6 @@ var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions |
40 | 40 | var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; |
41 | 41 |
|
42 | 42 | if (ENVIRONMENT_IS_NODE) { |
43 | | - // When building an ES module `require` is not normally available. |
44 | | - // We need to use `createRequire()` to construct the require()` function. |
45 | | - const { createRequire } = await import('module'); |
46 | | - /** @suppress{duplicate} */ |
47 | | - var require = createRequire(import.meta.url); |
48 | 43 |
|
49 | 44 | } |
50 | 45 |
|
@@ -93,12 +88,7 @@ if (ENVIRONMENT_IS_NODE) { |
93 | 88 | var fs = require('fs'); |
94 | 89 | var nodePath = require('path'); |
95 | 90 |
|
96 | | - // EXPORT_ES6 + ENVIRONMENT_IS_NODE always requires use of import.meta.url, |
97 | | - // since there's no way getting the current absolute path of the module when |
98 | | - // support for that is not available. |
99 | | - if (!import.meta.url.startsWith('data:')) { |
100 | | - scriptDirectory = nodePath.dirname(require('url').fileURLToPath(import.meta.url)) + '/'; |
101 | | - } |
| 91 | + scriptDirectory = __dirname + '/'; |
102 | 92 |
|
103 | 93 | // include: node_shell_read.js |
104 | 94 | readBinary = (filename) => { |
@@ -445,15 +435,13 @@ function isExportedByForceFilesystem(name) { |
445 | 435 | * their build, or no symbols that no longer exist. |
446 | 436 | */ |
447 | 437 | function hookGlobalSymbolAccess(sym, func) { |
448 | | - if (typeof globalThis != 'undefined' && !Object.getOwnPropertyDescriptor(globalThis, sym)) { |
449 | | - Object.defineProperty(globalThis, sym, { |
450 | | - configurable: true, |
451 | | - get() { |
452 | | - func(); |
453 | | - return undefined; |
454 | | - } |
455 | | - }); |
456 | | - } |
| 438 | + // In MODULARIZE mode the generated code runs inside a function scope and not |
| 439 | + // the global scope, and JavaScript does not provide access to function scopes |
| 440 | + // so we cannot dynamically modify the scrope using `defineProperty` in this |
| 441 | + // case. |
| 442 | + // |
| 443 | + // In this mode we simply ignore requests for `hookGlobalSymbolAccess`. Since |
| 444 | + // this is a debug-only feature, skipping it is not major issue. |
457 | 445 | } |
458 | 446 |
|
459 | 447 | function missingGlobal(sym, msg) { |
@@ -721,11 +709,7 @@ function createExportWrapper(name, nargs) { |
721 | 709 |
|
722 | 710 | var wasmBinaryFile; |
723 | 711 | function findWasmBinary() { |
724 | | - if (Module['locateFile']) { |
725 | 712 | return locateFile('libecs.wasm'); |
726 | | - } |
727 | | - // Use bundler-friendly `new URL(..., import.meta.url)` pattern; works in browsers too. |
728 | | - return new URL('libecs.wasm', import.meta.url).href; |
729 | 713 | } |
730 | 714 |
|
731 | 715 | function getBinarySync(file) { |
@@ -3826,4 +3810,10 @@ for (const prop of Object.keys(Module)) { |
3826 | 3810 | return real_Module(arg); |
3827 | 3811 | } |
3828 | 3812 | })(); |
3829 | | -export default Module; |
| 3813 | +if (typeof exports === 'object' && typeof module === 'object') { |
| 3814 | + module.exports = Module; |
| 3815 | + // This default export looks redundant, but it allows TS to import this |
| 3816 | + // commonjs style module. |
| 3817 | + module.exports.default = Module; |
| 3818 | +} else if (typeof define === 'function' && define['amd']) |
| 3819 | + define([], () => Module); |
0 commit comments