Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap merge args, rename config.entries --> config.include #1

Merged
merged 5 commits into from
Jul 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched it back, because targets should be respected over default "options".

}
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