File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -377,9 +377,14 @@ function ensurePackageJson() {
377
377
function ensureIndexJs ( ) {
378
378
console . log ( "- Making sure that 'index.js' exists..." ) ;
379
379
if ( ! fs . existsSync ( indexFile ) ) {
380
+ // since node.js v13.2.0 or v12.17.0 we can use ESM without flags
381
+ const ver = process . versions . node . split ( '.' ) ;
382
+ const maj = parseInt ( ver [ 0 ] ) ;
383
+ const min = parseInt ( ver [ 1 ] ) ;
384
+ const supportESM = maj >= 14 || ( maj == 13 && min >= 2 ) || ( maj == 12 && min >= 17 ) ;
380
385
fs . writeFileSync ( indexFile , [
381
386
"const fs = require(\"fs\");" ,
382
- "const loader = require(\"@assemblyscript/loader\");" ,
387
+ "const loader = require(\"@assemblyscript/loader" + ( supportESM ? "" : "/umd" ) + " \");",
383
388
"const imports = { /* imports go here */ };" ,
384
389
"const wasmModule = loader.instantiateSync(fs.readFileSync(__dirname + \"/build/optimized.wasm\"), imports);" ,
385
390
"module.exports = wasmModule.exports;"
You can’t perform that action at this time.
0 commit comments