Skip to content

Commit d3a65a3

Browse files
committed
support nodejs and bun
1 parent 55ed3b8 commit d3a65a3

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

as-test.config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
},
1010
"buildOptions": {
1111
"args": [],
12-
"wasi": true,
12+
"wasi": false,
1313
"parallel": true,
1414
"verbose": true
1515
},
1616
"runOptions": {
1717
"runtime": {
18-
"name": "wasmtime",
19-
"run": "wasmtime <file>"
18+
"name": "node",
19+
"run": "node ./test.js"
2020
}
2121
}
2222
}

asconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
}
2727
},
2828
"options": {
29-
"transform": [],
30-
"disableWarning": [226]
31-
},
32-
"extends": "./node_modules/@assemblyscript/wasi-shim/asconfig.json"
29+
"bindings": "esm"
30+
}
3331
}

bin/run.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export async function run() {
1919
if (!existsSync(bin))
2020
continue;
2121
for (const file of readdirSync(bin)) {
22-
if (file == config.runOptions.runtime.name ||
23-
file == config.runOptions.runtime.name + ".exe") {
22+
if (file == config.runOptions.runtime.run.split(" ")[0] ||
23+
file == config.runOptions.runtime.run.split(" ")[0] + ".exe") {
2424
execPath = bin + "/" + file;
2525
}
2626
}
@@ -29,20 +29,27 @@ export async function run() {
2929
console.log(chalk.bgRed(" ERROR ") +
3030
chalk.dim(":") +
3131
" could not locate " +
32-
config.runOptions.runtime.name +
32+
config.runOptions.runtime.run.split(" ")[0] +
3333
" in your PATH variable. Either set it, or install it" +
34-
(config.runOptions.runtime.name
34+
(config.runOptions.runtime.run.split(" ")[0]
3535
? "using " +
36-
chalk.dim(installScripts.get(config.runOptions.runtime.name))
36+
chalk.dim(installScripts.get(config.runOptions.runtime.run.split(" ")[0]))
3737
: "."));
3838
}
3939
for (const file of inputFiles) {
4040
const outFile = config.outDir +
4141
"/" +
4242
file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm");
43-
exec(config.runOptions.runtime.run
43+
let cmd = config.runOptions.runtime.run
4444
.replace(config.runOptions.runtime.name, execPath)
45-
.replace("<file>", outFile), (err, stdout, stderr) => {
45+
.replace("<file>", outFile);
46+
if (config.runOptions.runtime.run.startsWith("bun") || config.runOptions.runtime.run.startsWith("node") || config.runOptions.runtime.run.startsWith("deno")) {
47+
cmd = config.runOptions.runtime.run
48+
.replace(config.runOptions.runtime.name, execPath)
49+
.replace("<file>", outFile.replace(".wasm", ".js"));
50+
}
51+
console.log("running: " + cmd);
52+
exec(cmd, (err, stdout, stderr) => {
4653
process.stdout.write(stdout);
4754
process.stderr.write(stderr);
4855
if (err) {

cli/run.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export async function run() {
2626
if (!existsSync(bin)) continue;
2727
for (const file of readdirSync(bin)) {
2828
if (
29-
file == config.runOptions.runtime.name ||
30-
file == config.runOptions.runtime.name + ".exe"
29+
file == config.runOptions.runtime.run.split(" ")[0] ||
30+
file == config.runOptions.runtime.run.split(" ")[0] + ".exe"
3131
) {
3232
execPath = bin + "/" + file;
3333
}
@@ -37,25 +37,32 @@ export async function run() {
3737
if (!execPath) {
3838
console.log(
3939
chalk.bgRed(" ERROR ") +
40-
chalk.dim(":") +
41-
" could not locate " +
42-
config.runOptions.runtime.name +
43-
" in your PATH variable. Either set it, or install it" +
44-
(config.runOptions.runtime.name
45-
? "using " +
46-
chalk.dim(installScripts.get(config.runOptions.runtime.name))
47-
: "."),
40+
chalk.dim(":") +
41+
" could not locate " +
42+
config.runOptions.runtime.run.split(" ")[0] +
43+
" in your PATH variable. Either set it, or install it" +
44+
(config.runOptions.runtime.run.split(" ")[0]
45+
? "using " +
46+
chalk.dim(installScripts.get(config.runOptions.runtime.run.split(" ")[0]))
47+
: "."),
4848
);
4949
}
50+
5051
for (const file of inputFiles) {
5152
const outFile =
5253
config.outDir +
5354
"/" +
5455
file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm");
55-
exec(
56-
config.runOptions.runtime.run
56+
57+
let cmd = config.runOptions.runtime.run
58+
.replace(config.runOptions.runtime.name, execPath)
59+
.replace("<file>", outFile);
60+
if (config.runOptions.runtime.run.startsWith("bun") || config.runOptions.runtime.run.startsWith("node") || config.runOptions.runtime.run.startsWith("deno")) {
61+
cmd = config.runOptions.runtime.run
5762
.replace(config.runOptions.runtime.name, execPath)
58-
.replace("<file>", outFile),
63+
.replace("<file>", outFile.replace(".wasm", ".js"))
64+
}
65+
exec(cmd,
5966
(err, stdout, stderr) => {
6067
process.stdout.write(stdout);
6168
process.stderr.write(stderr);

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
},
1717
"devDependencies": {
1818
"@assemblyscript/wasi-shim": "^0.1.0",
19-
"@types/node": "^20.14.9",
19+
"@types/node": "^20.14.10",
2020
"as-test": "./",
21-
"assemblyscript": "^0.27.28",
21+
"assemblyscript": "^0.27.29",
2222
"assemblyscript-prettier": "^3.0.1",
2323
"typescript": "^5.5.3",
2424
"visitor-as": "^0.11.4"
@@ -28,7 +28,7 @@
2828
"as-rainbow": "^0.1.0",
2929
"as-variant": "^0.4.1",
3030
"chalk": "^5.3.0",
31-
"glob": "^10.4.2",
31+
"glob": "^11.0.0",
3232
"jest": "^29.7.0"
3333
},
3434
"overrides": {

0 commit comments

Comments
 (0)