mirror of
https://github.com/remko/waforth
synced 2024-12-27 09:59:29 +01:00
build: Pipe wat2wasm directly to esbuild
This commit is contained in:
parent
0cf61783c8
commit
f48dd6b86d
1 changed files with 12 additions and 24 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
const { promisify } = require("util");
|
const { promisify } = require("util");
|
||||||
const exec = promisify(require("child_process").exec);
|
const exec = promisify(require("child_process").exec);
|
||||||
const fs = require("fs");
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
function wasmTextPlugin({ debug } = {}) {
|
function wasmTextPlugin({ debug } = {}) {
|
||||||
|
@ -23,30 +22,19 @@ function wasmTextPlugin({ debug } = {}) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
build.onLoad({ filter: /.*/, namespace: "wasm-text" }, async (args) => {
|
build.onLoad({ filter: /.*/, namespace: "wasm-text" }, async (args) => {
|
||||||
// Would be handy if we could get output from stdout without going through file
|
let flags = [];
|
||||||
const out = `wat2wasm.${Math.floor(
|
if (debug) {
|
||||||
Math.random() * 1000000000
|
flags.push("--debug-names");
|
||||||
)}.tmp.wasm`;
|
|
||||||
try {
|
|
||||||
let flags = [];
|
|
||||||
if (debug) {
|
|
||||||
flags.push("--debug-names");
|
|
||||||
}
|
|
||||||
// console.log("wat: compiling %s", args.path);
|
|
||||||
await exec(
|
|
||||||
`wat2wasm ${flags.join(" ")} --output=${out} ${args.path}`
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
contents: await fs.promises.readFile(out),
|
|
||||||
loader: "binary",
|
|
||||||
};
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
await fs.promises.unlink(out);
|
|
||||||
} catch (e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// console.log("wat: compiling %s", args.path);
|
||||||
|
const r = await exec(
|
||||||
|
`wat2wasm ${flags.join(" ")} --output=- ${args.path}`,
|
||||||
|
{ encoding: "buffer" }
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
contents: r.stdout,
|
||||||
|
loader: "binary",
|
||||||
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue