Skip to content

Commit 3e0303d

Browse files
authored
Merge pull request AssemblyScript#1 from willemneal/asconfig
Swap merge args, rename config.entries --> config.include
2 parents acd8725 + 7827a93 commit 3e0303d

File tree

18 files changed

+88
-2
lines changed

18 files changed

+88
-2
lines changed

cli/asc.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,22 @@ exports.main = function main(argv, options, callback) {
283283
while (asconfig) {
284284
// merge target first, then merge options, then merge extended asconfigs
285285
if (asconfig.targets && asconfig.targets[target]) {
286-
args = optionsUtil.merge(exports.options, args, asconfig.targets[target]);
286+
args = optionsUtil.merge(exports.options, asconfig.targets[target], args);
287287
}
288288
if (asconfig.options) {
289-
args = optionsUtil.merge(exports.options, args, asconfig.options);
289+
if (asconfig.options.transform) {
290+
// ensure that a transform's path is relative to the current config
291+
asconfig.options.transform = asconfig.options.transform.map(p => {
292+
if (!path.isAbsolute(p)) {
293+
if (p.startsWith(".")) {
294+
return path.join(asconfigDir, p);
295+
}
296+
return require.resolve(p);
297+
}
298+
return p;
299+
});
300+
}
301+
args = optionsUtil.merge(exports.options, asconfig.options, args);
290302
}
291303

292304
// entries are added to the compilation
@@ -321,6 +333,9 @@ exports.main = function main(argv, options, callback) {
321333
}
322334
}
323335

336+
exports.args = args;
337+
exports.argv = argv;
338+
324339
// This method resolves a path relative to the baseDir instead of process.cwd()
325340
function resolve(arg) {
326341
if (path.isAbsolute(arg)) return arg;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"entries": ["assembly/globals.ts"]
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
@global
4+
const answerToLife = 42;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
assert(answerToLife == 42);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../asconfig.json"
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
assert(answerToLife == 42);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"test": "node ../../index.js"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"test": "node ../index.js && cd nested && npm run test"
5+
}
6+
}

tests/asconfig/flags/asconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"target": {
3+
"release": {},
4+
"debug": {
5+
"debug": true
6+
}
7+
}
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../asconfig.json"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"debug": true
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"test": "node ../../index.js"
5+
}
6+
}

tests/asconfig/flags/options.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"debug": true
3+
}

tests/asconfig/flags/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"test": "node ../index.js && cd nested && npm run test"
5+
}
6+
}

tests/asconfig/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const asc = require("../../cli/asc");
22
const loader = require("../../lib/loader");
33
const args = process.argv.slice(2);
4+
const fs = require("fs");
5+
const path = require("path");
46

57
/** @type {Uint8Array} */
68
let binary;
@@ -20,6 +22,15 @@ asc.main(["assembly/index.ts", "--outFile", "output.wasm", "--explicitStart", ..
2022
console.error("No binary was generated for the asconfig test in " + process.cwd());
2123
process.exit(1);
2224
}
25+
const optionsPath = path.join(process.cwd(), "options.json")
26+
if (fs.existsSync(optionsPath)) {
27+
const options = require(optionsPath);
28+
for (let option of Object.getOwnPropertyNames(options) ){
29+
if (options[option] != asc.args[option]) {
30+
throw new Error(`Test ${path.basename(process.cwd())}: ${options[option]} != ${asc.args[option]}`);
31+
}
32+
}
33+
}
2334

2435
const theResult = loader.instantiateSync(binary);
2536

tests/asconfig/target/asconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"optimizeLevel": 3,
55
"shrinkLevel": 1,
66
"enable": ["simd"]
7+
},
8+
"dev": {
9+
"debug": true
710
}
811
},
912
"options": {}

0 commit comments

Comments
 (0)