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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wat4wasm",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/central-network/wat4wasm#readme",
6
6
  "bugs": {
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
- const compiled = await compileCallback(rawCode);
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) {