diff --git a/cli/asc.js b/cli/asc.js index 204f9c308d..54a5ac7046 100644 --- a/cli/asc.js +++ b/cli/asc.js @@ -283,10 +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, 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 @@ -321,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/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" + } +} 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); 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": {}