Skip to content

Commit

Permalink
Merge pull request #1 from willemneal/asconfig
Browse files Browse the repository at this point in the history
Swap merge args, rename config.entries --> config.include
  • Loading branch information
jtenner authored Jul 11, 2020
2 parents acd8725 + 7827a93 commit 3e0303d
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions tests/asconfig/entry-points/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"entries": ["assembly/globals.ts"]
}
4 changes: 4 additions & 0 deletions tests/asconfig/entry-points/assembly/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


@global
const answerToLife = 42;
2 changes: 2 additions & 0 deletions tests/asconfig/entry-points/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

assert(answerToLife == 42);
3 changes: 3 additions & 0 deletions tests/asconfig/entry-points/nested/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../asconfig.json"
}
2 changes: 2 additions & 0 deletions tests/asconfig/entry-points/nested/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

assert(answerToLife == 42);
6 changes: 6 additions & 0 deletions tests/asconfig/entry-points/nested/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"scripts": {
"test": "node ../../index.js"
}
}
6 changes: 6 additions & 0 deletions tests/asconfig/entry-points/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"scripts": {
"test": "node ../index.js && cd nested && npm run test"
}
}
8 changes: 8 additions & 0 deletions tests/asconfig/flags/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"target": {
"release": {},
"debug": {
"debug": true
}
}
}
1 change: 1 addition & 0 deletions tests/asconfig/flags/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions tests/asconfig/flags/nested/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../asconfig.json"
}
1 change: 1 addition & 0 deletions tests/asconfig/flags/nested/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions tests/asconfig/flags/nested/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"debug": true
}
6 changes: 6 additions & 0 deletions tests/asconfig/flags/nested/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"scripts": {
"test": "node ../../index.js"
}
}
3 changes: 3 additions & 0 deletions tests/asconfig/flags/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"debug": true
}
6 changes: 6 additions & 0 deletions tests/asconfig/flags/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"scripts": {
"test": "node ../index.js && cd nested && npm run test"
}
}
11 changes: 11 additions & 0 deletions tests/asconfig/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions tests/asconfig/target/asconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"optimizeLevel": 3,
"shrinkLevel": 1,
"enable": ["simd"]
},
"dev": {
"debug": true
}
},
"options": {}
Expand Down

0 comments on commit 3e0303d

Please sign in to comment.