From b43236ab419ddb7ff4a26a3429c173f9100a549e Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Feb 2021 16:45:13 +0200 Subject: [PATCH 1/7] auto detect ESM support during asinit --- bin/asinit | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/asinit b/bin/asinit index 57bc75d9f0..0d31389969 100755 --- a/bin/asinit +++ b/bin/asinit @@ -377,9 +377,12 @@ function ensurePackageJson() { function ensureIndexJs() { console.log("- Making sure that 'index.js' exists..."); if (!fs.existsSync(indexFile)) { + // since nide.js v13.2.0 or v12.17.0 we can use ESM without flags + const nodeVersion = parseFloat(process.versions.node); + const supportESM = nodeVersion >= 12.17 && nodeVersion < 13 || nodeVersion >= 13.2; fs.writeFileSync(indexFile, [ "const fs = require(\"fs\");", - "const loader = require(\"@assemblyscript/loader\");", + "const loader = require(\"@assemblyscript/loader" + (supportESM ? "" : "/umd") + "\");", "const imports = { /* imports go here */ };", "const wasmModule = loader.instantiateSync(fs.readFileSync(__dirname + \"/build/optimized.wasm\"), imports);", "module.exports = wasmModule.exports;" From a7229eddffb6d69457bd1ecedeef5d0b2e39b6f2 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Feb 2021 16:56:11 +0200 Subject: [PATCH 2/7] typo --- bin/asinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/asinit b/bin/asinit index 0d31389969..8302fefcdd 100755 --- a/bin/asinit +++ b/bin/asinit @@ -377,7 +377,7 @@ function ensurePackageJson() { function ensureIndexJs() { console.log("- Making sure that 'index.js' exists..."); if (!fs.existsSync(indexFile)) { - // since nide.js v13.2.0 or v12.17.0 we can use ESM without flags + // since node.js v13.2.0 or v12.17.0 we can use ESM without flags const nodeVersion = parseFloat(process.versions.node); const supportESM = nodeVersion >= 12.17 && nodeVersion < 13 || nodeVersion >= 13.2; fs.writeFileSync(indexFile, [ From f073ea2fdd7f9087e130de124fce17d5ae47a178 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Feb 2021 17:26:13 +0200 Subject: [PATCH 3/7] better --- bin/asinit | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/asinit b/bin/asinit index 8302fefcdd..5fed537244 100755 --- a/bin/asinit +++ b/bin/asinit @@ -378,8 +378,10 @@ function ensureIndexJs() { console.log("- Making sure that 'index.js' exists..."); if (!fs.existsSync(indexFile)) { // since node.js v13.2.0 or v12.17.0 we can use ESM without flags - const nodeVersion = parseFloat(process.versions.node); - const supportESM = nodeVersion >= 12.17 && nodeVersion < 13 || nodeVersion >= 13.2; + const ver = process.versions.node.split('.'); + const maj = parseInt(ver[0]); + const min = parseInt(ver[1]); + const supportESM = (maj >= 12 && min >= 7 && maj < 13) || (maj >= 13 && min >= 2); fs.writeFileSync(indexFile, [ "const fs = require(\"fs\");", "const loader = require(\"@assemblyscript/loader" + (supportESM ? "" : "/umd") + "\");", From a39afa08074c6ede2f27ace21aabf95f4ed43bdb Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 15 Feb 2021 22:58:52 +0200 Subject: [PATCH 4/7] fix minor low bound --- bin/asinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/asinit b/bin/asinit index 5fed537244..d2479d0992 100755 --- a/bin/asinit +++ b/bin/asinit @@ -381,7 +381,7 @@ function ensureIndexJs() { const ver = process.versions.node.split('.'); const maj = parseInt(ver[0]); const min = parseInt(ver[1]); - const supportESM = (maj >= 12 && min >= 7 && maj < 13) || (maj >= 13 && min >= 2); + const supportESM = (maj >= 12 && min >= 17 && maj < 13) || (maj >= 13 && min >= 2); fs.writeFileSync(indexFile, [ "const fs = require(\"fs\");", "const loader = require(\"@assemblyscript/loader" + (supportESM ? "" : "/umd") + "\");", From 148c6cd2a9730adce24cf4a0d073de60e6ad21c8 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 6 Mar 2021 01:05:06 +0200 Subject: [PATCH 5/7] fix for >= 14 --- bin/asinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/asinit b/bin/asinit index d2479d0992..774b34e8f2 100755 --- a/bin/asinit +++ b/bin/asinit @@ -381,7 +381,7 @@ function ensureIndexJs() { const ver = process.versions.node.split('.'); const maj = parseInt(ver[0]); const min = parseInt(ver[1]); - const supportESM = (maj >= 12 && min >= 17 && maj < 13) || (maj >= 13 && min >= 2); + const supportESM = (maj >= 12 && min >= 17 && maj < 13) || (maj >= 13 && min >= 2) || maj >= 14; fs.writeFileSync(indexFile, [ "const fs = require(\"fs\");", "const loader = require(\"@assemblyscript/loader" + (supportESM ? "" : "/umd") + "\");", From 6fe2273662a6bdfbbefa4f713b37ac217bae2170 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 6 Mar 2021 01:18:24 +0200 Subject: [PATCH 6/7] reorder --- bin/asinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/asinit b/bin/asinit index 774b34e8f2..3795f93ad7 100755 --- a/bin/asinit +++ b/bin/asinit @@ -381,7 +381,7 @@ function ensureIndexJs() { const ver = process.versions.node.split('.'); const maj = parseInt(ver[0]); const min = parseInt(ver[1]); - const supportESM = (maj >= 12 && min >= 17 && maj < 13) || (maj >= 13 && min >= 2) || maj >= 14; + const supportESM = maj >= 14 || (maj >= 13 && min >= 2) || (maj >= 12 && min >= 17 && maj < 13); fs.writeFileSync(indexFile, [ "const fs = require(\"fs\");", "const loader = require(\"@assemblyscript/loader" + (supportESM ? "" : "/umd") + "\");", From a63f4e0ade445e3a4c5f787abee7882658d17b56 Mon Sep 17 00:00:00 2001 From: Max Graey Date: Mon, 8 Mar 2021 19:32:40 +0200 Subject: [PATCH 7/7] Update bin/asinit Co-authored-by: Daniel Wirtz --- bin/asinit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/asinit b/bin/asinit index 3795f93ad7..d1a18cf235 100755 --- a/bin/asinit +++ b/bin/asinit @@ -381,7 +381,7 @@ function ensureIndexJs() { const ver = process.versions.node.split('.'); const maj = parseInt(ver[0]); const min = parseInt(ver[1]); - const supportESM = maj >= 14 || (maj >= 13 && min >= 2) || (maj >= 12 && min >= 17 && maj < 13); + const supportESM = maj >= 14 || (maj == 13 && min >= 2) || (maj == 12 && min >= 17); fs.writeFileSync(indexFile, [ "const fs = require(\"fs\");", "const loader = require(\"@assemblyscript/loader" + (supportESM ? "" : "/umd") + "\");",