From 8195764142344164d1d3c22b21b9e01846f1d6e3 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 8 Jul 2020 18:11:13 -0400 Subject: [PATCH 1/5] Swap merge args, rename config.entries --> config.include Also make transforms relative or use require --- cli/asc.js | 20 ++++++++++++++++---- tests/asconfig/target/asconfig.json | 3 +++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cli/asc.js b/cli/asc.js index 204f9c308d..c0cf4bf50f 100644 --- a/cli/asc.js +++ b/cli/asc.js @@ -283,15 +283,27 @@ exports.main = function main(argv, options, callback) { while (asconfig) { // merge target first, then merge options, then merge extended asconfigs if (asconfig.targets && asconfig.targets[target]) { - args = optionsUtil.merge(exports.options, args, asconfig.targets[target]); + args = optionsUtil.merge(exports.options, asconfig.targets[target], args); } if (asconfig.options) { - args = optionsUtil.merge(exports.options, args, asconfig.options); + if (asconfig.options.transform) { + // ensure that a transform's path is relative to the current config + asconfig.options.transform = asconfig.options.transform.map(p => { + if (!path.isAbsolute(p)) { + if (p.startsWith(".")) { + return path.join(asconfigDir, p); + } + return require.resolve(p) + } + return p; + }) + } + args = optionsUtil.merge(exports.options, asconfig.options, args); } // entries are added to the compilation - if (asconfig.entries) { - for (const entry of asconfig.entries) { + if (asconfig.include) { + for (const entry of asconfig.include) { argv.push( path.isAbsolute(entry) ? entry diff --git a/tests/asconfig/target/asconfig.json b/tests/asconfig/target/asconfig.json index 5e9a441e1e..aaadbf8119 100644 --- a/tests/asconfig/target/asconfig.json +++ b/tests/asconfig/target/asconfig.json @@ -4,6 +4,9 @@ "optimizeLevel": 3, "shrinkLevel": 1, "enable": ["simd"] + }, + "dev": { + "debug": true } }, "options": {} From f30d456316e1291d3e65b05422392241fd8b6699 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 8 Jul 2020 22:32:08 -0400 Subject: [PATCH 2/5] Rename include back to entries Also fixed missing ;'s --- cli/asc.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cli/asc.js b/cli/asc.js index c0cf4bf50f..aca2e61bc7 100644 --- a/cli/asc.js +++ b/cli/asc.js @@ -290,20 +290,17 @@ exports.main = function main(argv, options, callback) { // ensure that a transform's path is relative to the current config asconfig.options.transform = asconfig.options.transform.map(p => { if (!path.isAbsolute(p)) { - if (p.startsWith(".")) { - return path.join(asconfigDir, p); - } - return require.resolve(p) + return require.resolve(p); } return p; - }) + }); } args = optionsUtil.merge(exports.options, asconfig.options, args); } // entries are added to the compilation - if (asconfig.include) { - for (const entry of asconfig.include) { + if (asconfig.entries) { + for (const entry of asconfig.entries) { argv.push( path.isAbsolute(entry) ? entry From 7e268384bd18bf357e314dfb741dc85a4f2ce84e Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 10 Jul 2020 14:17:13 -0400 Subject: [PATCH 3/5] Added entry-points test --- tests/asconfig/entry-points/asconfig.json | 3 +++ tests/asconfig/entry-points/assembly/globals.ts | 4 ++++ tests/asconfig/entry-points/assembly/index.ts | 2 ++ tests/asconfig/entry-points/nested/asconfig.json | 3 +++ tests/asconfig/entry-points/nested/assembly/index.ts | 2 ++ tests/asconfig/entry-points/nested/package.json | 6 ++++++ tests/asconfig/entry-points/package.json | 6 ++++++ 7 files changed, 26 insertions(+) create mode 100644 tests/asconfig/entry-points/asconfig.json create mode 100644 tests/asconfig/entry-points/assembly/globals.ts create mode 100644 tests/asconfig/entry-points/assembly/index.ts create mode 100644 tests/asconfig/entry-points/nested/asconfig.json create mode 100644 tests/asconfig/entry-points/nested/assembly/index.ts create mode 100644 tests/asconfig/entry-points/nested/package.json create mode 100644 tests/asconfig/entry-points/package.json diff --git a/tests/asconfig/entry-points/asconfig.json b/tests/asconfig/entry-points/asconfig.json new file mode 100644 index 0000000000..52f569718c --- /dev/null +++ b/tests/asconfig/entry-points/asconfig.json @@ -0,0 +1,3 @@ +{ + "entries": ["assembly/globals.ts"] +} diff --git a/tests/asconfig/entry-points/assembly/globals.ts b/tests/asconfig/entry-points/assembly/globals.ts new file mode 100644 index 0000000000..15cd47228a --- /dev/null +++ b/tests/asconfig/entry-points/assembly/globals.ts @@ -0,0 +1,4 @@ + + +@global +const answerToLife = 42; \ No newline at end of file diff --git a/tests/asconfig/entry-points/assembly/index.ts b/tests/asconfig/entry-points/assembly/index.ts new file mode 100644 index 0000000000..8d57706af7 --- /dev/null +++ b/tests/asconfig/entry-points/assembly/index.ts @@ -0,0 +1,2 @@ + +assert(answerToLife == 42); diff --git a/tests/asconfig/entry-points/nested/asconfig.json b/tests/asconfig/entry-points/nested/asconfig.json new file mode 100644 index 0000000000..92d84fcc96 --- /dev/null +++ b/tests/asconfig/entry-points/nested/asconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../asconfig.json" +} diff --git a/tests/asconfig/entry-points/nested/assembly/index.ts b/tests/asconfig/entry-points/nested/assembly/index.ts new file mode 100644 index 0000000000..8d57706af7 --- /dev/null +++ b/tests/asconfig/entry-points/nested/assembly/index.ts @@ -0,0 +1,2 @@ + +assert(answerToLife == 42); diff --git a/tests/asconfig/entry-points/nested/package.json b/tests/asconfig/entry-points/nested/package.json new file mode 100644 index 0000000000..7603e9ad4d --- /dev/null +++ b/tests/asconfig/entry-points/nested/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "scripts": { + "test": "node ../../index.js" + } +} diff --git a/tests/asconfig/entry-points/package.json b/tests/asconfig/entry-points/package.json new file mode 100644 index 0000000000..e835996ed6 --- /dev/null +++ b/tests/asconfig/entry-points/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "scripts": { + "test": "node ../index.js && cd nested && npm run test" + } +} From d8bd07b2c57a0cdd3033a7c336b119996f5a70b3 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 10 Jul 2020 14:42:05 -0400 Subject: [PATCH 4/5] Swap back and fix transform --- cli/asc.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/asc.js b/cli/asc.js index aca2e61bc7..adf11595f6 100644 --- a/cli/asc.js +++ b/cli/asc.js @@ -283,19 +283,22 @@ exports.main = function main(argv, options, callback) { while (asconfig) { // merge target first, then merge options, then merge extended asconfigs if (asconfig.targets && asconfig.targets[target]) { - args = optionsUtil.merge(exports.options, asconfig.targets[target], args); + args = optionsUtil.merge(exports.options, args, asconfig.targets[target]); } if (asconfig.options) { if (asconfig.options.transform) { // ensure that a transform's path is relative to the current config asconfig.options.transform = asconfig.options.transform.map(p => { if (!path.isAbsolute(p)) { + if (p.startsWith(".")) { + return path.join(asconfigDir, p); + } return require.resolve(p); } return p; }); } - args = optionsUtil.merge(exports.options, asconfig.options, args); + args = optionsUtil.merge(exports.options, args, asconfig.options); } // entries are added to the compilation From 7827a9340b600a9a81b3654958e8d9a53782a56a Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 10 Jul 2020 16:58:50 -0400 Subject: [PATCH 5/5] Added more tests Also exported args and argv from asc And swapped back order of args to merge --- cli/asc.js | 7 +++++-- tests/asconfig/flags/asconfig.json | 8 ++++++++ tests/asconfig/flags/assembly/index.ts | 1 + tests/asconfig/flags/nested/asconfig.json | 3 +++ tests/asconfig/flags/nested/assembly/index.ts | 1 + tests/asconfig/flags/nested/options.json | 3 +++ tests/asconfig/flags/nested/package.json | 6 ++++++ tests/asconfig/flags/options.json | 3 +++ tests/asconfig/flags/package.json | 6 ++++++ tests/asconfig/index.js | 11 +++++++++++ 10 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 tests/asconfig/flags/asconfig.json create mode 100644 tests/asconfig/flags/assembly/index.ts create mode 100644 tests/asconfig/flags/nested/asconfig.json create mode 100644 tests/asconfig/flags/nested/assembly/index.ts create mode 100644 tests/asconfig/flags/nested/options.json create mode 100644 tests/asconfig/flags/nested/package.json create mode 100644 tests/asconfig/flags/options.json create mode 100644 tests/asconfig/flags/package.json diff --git a/cli/asc.js b/cli/asc.js index adf11595f6..54a5ac7046 100644 --- a/cli/asc.js +++ b/cli/asc.js @@ -283,7 +283,7 @@ exports.main = function main(argv, options, callback) { while (asconfig) { // merge target first, then merge options, then merge extended asconfigs if (asconfig.targets && asconfig.targets[target]) { - args = optionsUtil.merge(exports.options, args, asconfig.targets[target]); + args = optionsUtil.merge(exports.options, asconfig.targets[target], args); } if (asconfig.options) { if (asconfig.options.transform) { @@ -298,7 +298,7 @@ exports.main = function main(argv, options, callback) { return p; }); } - args = optionsUtil.merge(exports.options, args, asconfig.options); + args = optionsUtil.merge(exports.options, asconfig.options, args); } // entries are added to the compilation @@ -333,6 +333,9 @@ exports.main = function main(argv, options, callback) { } } + exports.args = args; + exports.argv = argv; + // This method resolves a path relative to the baseDir instead of process.cwd() function resolve(arg) { if (path.isAbsolute(arg)) return arg; diff --git a/tests/asconfig/flags/asconfig.json b/tests/asconfig/flags/asconfig.json new file mode 100644 index 0000000000..c83915e042 --- /dev/null +++ b/tests/asconfig/flags/asconfig.json @@ -0,0 +1,8 @@ +{ + "target": { + "release": {}, + "debug": { + "debug": true + } + } +} diff --git a/tests/asconfig/flags/assembly/index.ts b/tests/asconfig/flags/assembly/index.ts new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/tests/asconfig/flags/assembly/index.ts @@ -0,0 +1 @@ + diff --git a/tests/asconfig/flags/nested/asconfig.json b/tests/asconfig/flags/nested/asconfig.json new file mode 100644 index 0000000000..92d84fcc96 --- /dev/null +++ b/tests/asconfig/flags/nested/asconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../asconfig.json" +} diff --git a/tests/asconfig/flags/nested/assembly/index.ts b/tests/asconfig/flags/nested/assembly/index.ts new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/tests/asconfig/flags/nested/assembly/index.ts @@ -0,0 +1 @@ + diff --git a/tests/asconfig/flags/nested/options.json b/tests/asconfig/flags/nested/options.json new file mode 100644 index 0000000000..32c639edd1 --- /dev/null +++ b/tests/asconfig/flags/nested/options.json @@ -0,0 +1,3 @@ +{ + "debug": true +} \ No newline at end of file diff --git a/tests/asconfig/flags/nested/package.json b/tests/asconfig/flags/nested/package.json new file mode 100644 index 0000000000..7603e9ad4d --- /dev/null +++ b/tests/asconfig/flags/nested/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "scripts": { + "test": "node ../../index.js" + } +} diff --git a/tests/asconfig/flags/options.json b/tests/asconfig/flags/options.json new file mode 100644 index 0000000000..32c639edd1 --- /dev/null +++ b/tests/asconfig/flags/options.json @@ -0,0 +1,3 @@ +{ + "debug": true +} \ No newline at end of file diff --git a/tests/asconfig/flags/package.json b/tests/asconfig/flags/package.json new file mode 100644 index 0000000000..e835996ed6 --- /dev/null +++ b/tests/asconfig/flags/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "scripts": { + "test": "node ../index.js && cd nested && npm run test" + } +} diff --git a/tests/asconfig/index.js b/tests/asconfig/index.js index 2a7e3cc0fb..ae3b110041 100644 --- a/tests/asconfig/index.js +++ b/tests/asconfig/index.js @@ -1,6 +1,8 @@ const asc = require("../../cli/asc"); const loader = require("../../lib/loader"); const args = process.argv.slice(2); +const fs = require("fs"); +const path = require("path"); /** @type {Uint8Array} */ let binary; @@ -20,6 +22,15 @@ asc.main(["assembly/index.ts", "--outFile", "output.wasm", "--explicitStart", .. console.error("No binary was generated for the asconfig test in " + process.cwd()); process.exit(1); } + const optionsPath = path.join(process.cwd(), "options.json") + if (fs.existsSync(optionsPath)) { + const options = require(optionsPath); + for (let option of Object.getOwnPropertyNames(options) ){ + if (options[option] != asc.args[option]) { + throw new Error(`Test ${path.basename(process.cwd())}: ${options[option]} != ${asc.args[option]}`); + } + } + } const theResult = loader.instantiateSync(binary);