wat4wasm 1.0.7 → 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.
@@ -16,6 +16,7 @@ export default function (wat) {
16
16
  .replaceAll("(console $", "(call $self.console.")
17
17
  .replaceAll("(reflect $", "(call $self.Reflect.")
18
18
  .replaceAll("(bigint $", "(call $self.BigInt.")
19
+ .replaceAll("(promise $", "(call $self.Promise.")
19
20
  .replaceAll("(number $", "(call $self.Number.")
20
21
  .replaceAll("(math $", "(call $self.Math.")
21
22
  .replaceAll("(string $", "(call $self.String.")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wat4wasm",
3
- "version": "1.0.7",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/central-network/wat4wasm#readme",
6
6
  "bugs": {
package/wat4wasm CHANGED
@@ -1235,6 +1235,7 @@ function REPLACE_ALL (wat) {
1235
1235
  .replaceAll("(console $", "(call $self.console.")
1236
1236
  .replaceAll("(reflect $", "(call $self.Reflect.")
1237
1237
  .replaceAll("(bigint $", "(call $self.BigInt.")
1238
+ .replaceAll("(promise $", "(call $self.Promise.")
1238
1239
  .replaceAll("(number $", "(call $self.Number.")
1239
1240
  .replaceAll("(math $", "(call $self.Math.")
1240
1241
  .replaceAll("(string $", "(call $self.String.")
@@ -1784,6 +1785,7 @@ async function processCLI(compileCallback, PROCESS = process) {
1784
1785
  faviconLinkHref: "data:null",
1785
1786
  printOnly: false,
1786
1787
  passthroughArgs: [],
1788
+ applyScripts: [],
1787
1789
  };
1788
1790
  for (let i = 0; i < args.length; i++) {
1789
1791
  const arg = args[i];
@@ -1791,6 +1793,8 @@ async function processCLI(compileCallback, PROCESS = process) {
1791
1793
  config.outputFile = arg.split("=")[1];
1792
1794
  } else if (arg.startsWith("--input=")) {
1793
1795
  config.inputFile = arg.split("=")[1];
1796
+ } else if (arg.startsWith("--apply=")) {
1797
+ config.applyScripts.push(arg.split("=")[1]);
1794
1798
  } else if (arg.startsWith("--wat2wasm=")) {
1795
1799
  config.wat2wasmPath = arg.split("=")[1];
1796
1800
  } else if (arg.startsWith("--tag=")) {
@@ -1836,6 +1840,18 @@ async function processCLI(compileCallback, PROCESS = process) {
1836
1840
  console.error("Error: Input file required! Usage: wat4wasm <input.wat> [options]");
1837
1841
  PROCESS.exit(1);
1838
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("//", "/");
1839
1855
  const isJSTarget = config.outputFile?.endsWith(".js");
1840
1856
  const isHTMLTarget = config.outputFile?.endsWith(".html");
1841
1857
  if (isHTMLTarget || isJSTarget) {
@@ -1854,7 +1870,16 @@ async function processCLI(compileCallback, PROCESS = process) {
1854
1870
  }
1855
1871
  const rawCode = fs.readFileSync(config.inputFile, "utf8");
1856
1872
  // 2. Call the provided compile function
1857
- 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
+ }
1858
1883
  console.log("\x1b[0m")
1859
1884
  // 3. Handle Output
1860
1885
  if (config.printOnly) {