@gasm-compiler/cli 0.3.0 → 0.4.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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/dist/cli.js +22 -12
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -56,6 +56,7 @@ Compiles a WebAssembly binary or AssemblyScript source to WGSL.
56
56
  | `--verbose` | Show detailed compilation steps |
57
57
  | `--keep-wasm` | Keep intermediate `.wasm` file when compiling from AssemblyScript |
58
58
  | `--optimize` | Apply optimization passes |
59
+ | `--minify` | Optimize and emit compact, single-line WGSL |
59
60
 
60
61
  **Examples:**
61
62
 
package/dist/cli.js CHANGED
@@ -43,31 +43,31 @@ async function compileAssemblyScriptToWGSL(inputFile, options = {}) {
43
43
  watOutput: watOutputFile,
44
44
  verbose = false,
45
45
  keepWasm = false,
46
- optimize = false,
46
+ optimize,
47
+ minify = false,
47
48
  denyF64Demotion = false,
48
49
  allowI64Demotion = false,
49
50
  warningsAsErrors = false,
50
51
  sourceMapping
51
52
  } = options;
52
53
  try {
54
+ if (minify && optimize === false) {
55
+ throw new Error("--minify cannot be combined with --no-optimize");
56
+ }
53
57
  if (requestedSpecVersion !== void 0 && requestedSpecVersion !== "0.1" && requestedSpecVersion !== "0.2") {
54
58
  throw new Error(
55
59
  `Unsupported spec version "${requestedSpecVersion}"; expected 0.1 or 0.2`
56
60
  );
57
61
  }
58
62
  if (prepare !== void 0 && prepare !== "auto") {
59
- throw new Error(
60
- `Unsupported prepare mode "${prepare}"; expected "auto"`
61
- );
63
+ throw new Error(`Unsupported prepare mode "${prepare}"; expected "auto"`);
62
64
  }
63
65
  if (prepare && strict) {
64
66
  throw new Error("--prepare and --strict cannot be used together");
65
67
  }
66
68
  const specVersion = requestedSpecVersion ?? "0.2";
67
69
  if (metadataFile && specVersion !== "0.2") {
68
- throw new Error(
69
- "--metadata requires --spec-version 0.2"
70
- );
70
+ throw new Error("--metadata requires --spec-version 0.2");
71
71
  }
72
72
  if (verbose) console.log(`[1/4] Validating input file: ${inputFile}`);
73
73
  const resolvedInput = resolve(inputFile);
@@ -153,7 +153,8 @@ ${errorMsg}`);
153
153
  }
154
154
  }
155
155
  let compileOptions = {
156
- optimize,
156
+ optimize: minify ? true : optimize ?? false,
157
+ minify,
157
158
  demotionPolicy,
158
159
  warningsAsErrors,
159
160
  sourceMapping: sourceMappingLevel,
@@ -191,7 +192,9 @@ ${errorMsg}`);
191
192
  const schema = validateGasmMetadataSchema(result.metadata);
192
193
  if (!schema.valid) {
193
194
  throw new Error(
194
- `Generated metadata failed schema validation: ${schema.errors.join(", ")}`
195
+ `Generated metadata failed schema validation: ${schema.errors.join(
196
+ ", "
197
+ )}`
195
198
  );
196
199
  }
197
200
  const resolvedMetadata = resolve(metadataFile);
@@ -282,7 +285,7 @@ async function getAssemblyScriptPath() {
282
285
  }
283
286
 
284
287
  // src/cli.ts
285
- var VERSION = "0.3.0";
288
+ var VERSION = "0.4.0";
286
289
  async function main() {
287
290
  const args = parseArgs(Deno.args, {
288
291
  string: [
@@ -299,6 +302,8 @@ async function main() {
299
302
  "verbose",
300
303
  "keep-wasm",
301
304
  "optimize",
305
+ "no-optimize",
306
+ "minify",
302
307
  "strict",
303
308
  "deny-f64-demotion",
304
309
  "allow-i64-demotion",
@@ -307,7 +312,7 @@ async function main() {
307
312
  default: {
308
313
  verbose: false,
309
314
  "keep-wasm": false,
310
- optimize: false
315
+ minify: false
311
316
  }
312
317
  });
313
318
  if (args.version) {
@@ -338,7 +343,8 @@ async function main() {
338
343
  watOutput: args["wat-output"],
339
344
  verbose: args.verbose,
340
345
  keepWasm: args["keep-wasm"],
341
- optimize: args.optimize,
346
+ optimize: Deno.args.includes("--optimize") ? true : Deno.args.includes("--no-optimize") ? false : void 0,
347
+ minify: args.minify,
342
348
  denyF64Demotion: args["deny-f64-demotion"],
343
349
  allowI64Demotion: args["allow-i64-demotion"],
344
350
  warningsAsErrors: args["warnings-as-errors"],
@@ -385,6 +391,7 @@ OPTIONS:
385
391
  --verbose Show detailed compilation steps
386
392
  --keep-wasm Keep intermediate WASM files
387
393
  --optimize Apply optimization passes
394
+ --minify Emit compact, single-line WGSL (enables optimization)
388
395
  --deny-f64-demotion Fail if f64 would be demoted to f32
389
396
  --allow-i64-demotion Allow lossy i64\u2192i32 demotion (mod 2^32)
390
397
  --warnings-as-errors Treat compiler warnings as errors
@@ -405,6 +412,9 @@ EXAMPLES:
405
412
  # Compile with optimization
406
413
  deno run --allow-all src/cli.ts compile input.wasm --optimize --output output.wgsl
407
414
 
415
+ # Compile minified WGSL
416
+ deno run --allow-all src/cli.ts compile input.wasm --minify --output output.wgsl
417
+
408
418
  DOCUMENTATION:
409
419
  https://github.com/MartinEricsson/gasm-compiler
410
420
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gasm-compiler/cli",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "CLI for compiling WebAssembly/AssemblyScript to WGSL using Gasm Compiler",
5
5
  "type": "module",
6
6
  "main": "./dist/cli.js",
@@ -33,7 +33,7 @@
33
33
  "cli"
34
34
  ],
35
35
  "dependencies": {
36
- "@gasm-compiler/core": "0.5.0"
36
+ "@gasm-compiler/core": "0.7.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "assemblyscript": "v0.28.9",