wat4wasm 1.0.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/examples/01-text/module-output.wat +3 -35
- package/examples/02-include/module-output.wat +2 -2
- package/examples/03-ref.extern/module-output.wat +31 -549
- package/examples/04-ref.func/module-output.wat +3 -4
- package/examples/05-global.get/module-output.wat +19 -269
- package/examples/06-async/module-output.wat +5 -215
- package/examples/07-data/module-output.wasm +0 -0
- package/examples/08-reflectors/module-output.wat +50 -264
- package/examples/09-replaceAll/module-output.wat +3 -1
- package/examples/99-complex/apply_1.js +5 -0
- package/examples/99-complex/output.html +1 -1
- package/examples/shell-usages.sh +10 -23
- package/lib/cli.js +29 -2
- package/package.json +1 -1
- package/wat4wasm +25 -1
package/package.json
CHANGED
package/wat4wasm
CHANGED
|
@@ -1785,6 +1785,7 @@ async function processCLI(compileCallback, PROCESS = process) {
|
|
|
1785
1785
|
faviconLinkHref: "data:null",
|
|
1786
1786
|
printOnly: false,
|
|
1787
1787
|
passthroughArgs: [],
|
|
1788
|
+
applyScripts: [],
|
|
1788
1789
|
};
|
|
1789
1790
|
for (let i = 0; i < args.length; i++) {
|
|
1790
1791
|
const arg = args[i];
|
|
@@ -1792,6 +1793,8 @@ async function processCLI(compileCallback, PROCESS = process) {
|
|
|
1792
1793
|
config.outputFile = arg.split("=")[1];
|
|
1793
1794
|
} else if (arg.startsWith("--input=")) {
|
|
1794
1795
|
config.inputFile = arg.split("=")[1];
|
|
1796
|
+
} else if (arg.startsWith("--apply=")) {
|
|
1797
|
+
config.applyScripts.push(arg.split("=")[1]);
|
|
1795
1798
|
} else if (arg.startsWith("--wat2wasm=")) {
|
|
1796
1799
|
config.wat2wasmPath = arg.split("=")[1];
|
|
1797
1800
|
} else if (arg.startsWith("--tag=")) {
|
|
@@ -1837,6 +1840,18 @@ async function processCLI(compileCallback, PROCESS = process) {
|
|
|
1837
1840
|
console.error("Error: Input file required! Usage: wat4wasm <input.wat> [options]");
|
|
1838
1841
|
PROCESS.exit(1);
|
|
1839
1842
|
}
|
|
1843
|
+
config.inputDirectory = process
|
|
1844
|
+
.cwd()
|
|
1845
|
+
.replaceAll("file://", "")
|
|
1846
|
+
.concat(config
|
|
1847
|
+
.inputFile
|
|
1848
|
+
.split("/")
|
|
1849
|
+
.reverse().slice(1)
|
|
1850
|
+
.reverse()
|
|
1851
|
+
.join("/")
|
|
1852
|
+
)
|
|
1853
|
+
.concat("/")
|
|
1854
|
+
.replaceAll("//", "/");
|
|
1840
1855
|
const isJSTarget = config.outputFile?.endsWith(".js");
|
|
1841
1856
|
const isHTMLTarget = config.outputFile?.endsWith(".html");
|
|
1842
1857
|
if (isHTMLTarget || isJSTarget) {
|
|
@@ -1855,7 +1870,16 @@ async function processCLI(compileCallback, PROCESS = process) {
|
|
|
1855
1870
|
}
|
|
1856
1871
|
const rawCode = fs.readFileSync(config.inputFile, "utf8");
|
|
1857
1872
|
// 2. Call the provided compile function
|
|
1858
|
-
|
|
1873
|
+
let compiled = await compileCallback(rawCode);
|
|
1874
|
+
let applyScript, applyCount = config.applyScripts.length;
|
|
1875
|
+
while (applyScript = config.applyScripts[--applyCount]) {
|
|
1876
|
+
const baseName = applyScript.split("/").pop().split(".").reverse().slice(1).reverse().join(".");
|
|
1877
|
+
console.log(`\x1b[0m\x1b[34m🎸 apply call[\x1b[35m${applyCount}\x1b[0m] \x1b[32m-->\x1b[0m \x1b[35m${baseName}\x1b[0m(wat)\x1b[0m`);
|
|
1878
|
+
const { default: applyFunction } = await import(
|
|
1879
|
+
config.inputDirectory.concat(applyScript)
|
|
1880
|
+
);
|
|
1881
|
+
compiled = await applyFunction(compiled);
|
|
1882
|
+
}
|
|
1859
1883
|
console.log("\x1b[0m")
|
|
1860
1884
|
// 3. Handle Output
|
|
1861
1885
|
if (config.printOnly) {
|