Skip to content

Commit 5cf4063

Browse files
author
Willem Wyndham
authored
fix: hasTarget and check target for output in the target (#12)
1 parent 09a333d commit 5cf4063

7 files changed

Lines changed: 56 additions & 7 deletions

File tree

dist/cli.js

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function safeRequire(path: string): any {
110110
}
111111

112112
function hasTarget(config: any, target: string): boolean {
113-
return config.target && config.target[target][target];
113+
return config.targets && config.targets[target];
114114
}
115115

116116
function compileProject(
@@ -189,7 +189,7 @@ function compileProject(
189189
}
190190
if (
191191
args.outDir ||
192-
!(hasOutput(ascArgv, ".wasm") || config.options?.binaryFile)
192+
!containsOutput(config, target, ascArgv)
193193
) {
194194
ascArgv.push("--binaryFile", wasmFile);
195195
}
@@ -203,3 +203,11 @@ function compileProject(
203203
function hasOutput(ascArgv: string[], suffix: string): boolean {
204204
return ascArgv.some((s) => s.endsWith(suffix));
205205
}
206+
207+
208+
function containsOutput(config: any, target: string, ascArgv: string[]): boolean {
209+
if (hasOutput(ascArgv, ".wasm")) return true;
210+
if (config.options?.binaryFile) return true;
211+
if (config.targets && config.targets[target]?.binaryFile) return true;
212+
return false;
213+
}

test/targets/asconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"targets": {
3+
"debug": {
4+
"debug": false,
5+
"noAssert": true,
6+
"binaryFile": "out/main.wasm",
7+
"optimize": true
8+
}
9+
}
10+
}

test/targets/assembly/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (!ASC_NO_ASSERT) {
2+
assert(false, "noAssert should be true");
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "assemblyscript/std/assembly.json",
3+
"include": [
4+
"./**/*.ts"
5+
]
6+
}

test/targets/expected.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"debug": false,
3+
"optimize": true,
4+
"binaryFile": "out/main.wasm"
5+
}

test/targets/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "main",
3+
"license": "MIT",
4+
"scripts": {
5+
"test": "ts-node .. --target debug -- --showConfig"
6+
}
7+
}

0 commit comments

Comments
 (0)