@xnoxs/flux-lang 3.3.4 → 3.4.1

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/CHANGELOG.md CHANGED
@@ -7,6 +7,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ---
9
9
 
10
+ ## [3.4.0] — 2026-06-25
11
+
12
+ ### Added
13
+ - **`src/self/pkg.flux`** — complete package manager written in Flux
14
+ - `flux add <pkg>[@version] [--dev]` — add dependency to `flux.json`
15
+ - `flux remove <pkg>` — remove dependency
16
+ - `flux install [--global]` — install all deps from `flux.json`
17
+ - `flux search <query>` — search package registry
18
+ - `flux info <pkg>` — show package metadata
19
+ - `flux list` — list installed packages
20
+ - `flux publish` — publish to Flux package registry
21
+ - **`src/self/config.flux`** — `flux.json` project config reader + schema validator
22
+ - Reads and merges `flux.json` + `flux.local.json`
23
+ - Full schema validation with typed error messages
24
+ - Programmatic API: `loadConfig(dir)`, `initConfig(name, dir)`, `validateConfig(cfg)`
25
+ - **`src/self/cli.flux`** — entire CLI (~880 lines) written in Flux
26
+ - All compiler commands: `compile`, `run`, `check`, `fmt`, `lint`, `test`, `bundle`, `watch`, `repl`, `tokens`, `ast`, `init`
27
+ - All package commands: `add`, `remove`, `install`, `search`, `info`, `list`, `publish`
28
+ - `flux self-hosted` sub-system with `build`, `verify`, `on`, `off`, `status` sub-commands
29
+ - Config-aware: reads `flux.json` to resolve entry point, compiler flags, output paths
30
+ - **3-stage bootstrap** — `scripts/bootstrap.js` now verifies all 18 modules
31
+ - Stage 0: stage-0 JS compiler compiles all `src/self/*.flux` → `.js`
32
+ - Stage 1: self-hosted output verified bit-for-bit identical to stage-0 output
33
+ - Stage 2: self-hosted compiler compiles its own `lexer.flux` → `lexer.stage2.js`
34
+ - Output: "Bootstrap complete — Flux is self-hosting."
35
+ - **`/self-hosted` web page** — live documentation page on the ecosystem server
36
+ - Animated status badge, hero section, 3-stage cards (Complete / Verified / Self-Compile)
37
+ - Interactive compiler pipeline visualizer (8 steps with arrows)
38
+ - 18-module grid with file sizes
39
+ - Tabbed code samples from `lexer.flux`, `parser.flux`, `cli.flux`
40
+ - Bootstrap quickstart command block
41
+ - **Navigation updated** — "Self-Hosted" link added to all nav bars across all pages
42
+
43
+ ### Changed
44
+ - `scripts/bootstrap.js` SOURCES array extended: `config`, `pkg`, `cli` added (15 → 18 modules)
45
+ - README fully updated with new CLI tables (package manager + self-hosted commands) and expanded self-hosting section (18-module tables, 3-stage bootstrap, programmatic API examples)
46
+ - `package.json` version bumped to `3.4.0`
47
+
48
+ ---
49
+
10
50
  ## [3.2.2] — 2026-06-24
11
51
 
12
52
  ### Changed
package/README.md CHANGED
@@ -1,9 +1,12 @@
1
- # ⚡ Flux Lang v3.2.0
1
+ # ⚡ Flux Lang v3.4.0
2
2
 
3
3
  **Flux** is a modern programming language that transpiles to clean JavaScript — combining Python-style indentation, TypeScript-grade type safety, Rust-inspired pattern matching, and a rich standard library — all with **zero runtime overhead**.
4
4
 
5
+ > **v3.4.0 — Fully Self-Hosted:** Every component of the Flux compiler — lexer, parser, type checker, code generator, formatter, linter, bundler, package manager, and CLI — is now written entirely in Flux and compiled by itself. `node scripts/bootstrap.js` → "Bootstrap complete — Flux is self-hosting."
6
+
5
7
  ```
6
8
  source.flux → [CSS Pre → JSX Pre → Lexer → Parser → TypeChecker → CodeGen] → output.js
9
+ ↑ all stages written in Flux, compiled by Flux itself (self-hosted v3.4.0)
7
10
  ```
8
11
 
9
12
  Every Flux file compiles to plain `.js` — no virtual machine, no custom runtime. You get the full JavaScript ecosystem for free.
@@ -32,6 +35,8 @@ console.log(result.output);
32
35
 
33
36
  ## CLI Reference
34
37
 
38
+ ### Compiler Commands
39
+
35
40
  | Command | Description |
36
41
  |---|---|
37
42
  | `flux run file.flux` | Compile and immediately execute |
@@ -49,6 +54,30 @@ console.log(result.output);
49
54
  | `flux version` | Show version |
50
55
  | `flux init [name]` | Create new Flux project |
51
56
 
57
+ ### Package Manager Commands *(written in Flux — `src/self/pkg.flux`)*
58
+
59
+ | Command | Description |
60
+ |---|---|
61
+ | `flux add <package>` | Add a package to `flux.json` dependencies |
62
+ | `flux add <package>@<version>` | Add a specific version |
63
+ | `flux add <package> --dev` | Add as dev dependency |
64
+ | `flux remove <package>` | Remove a package |
65
+ | `flux install` | Install all dependencies from `flux.json` |
66
+ | `flux search <query>` | Search the Flux package registry |
67
+ | `flux info <package>` | Show package details |
68
+ | `flux list` | List installed packages |
69
+ | `flux publish` | Publish your package to the Flux registry |
70
+
71
+ ### Self-Hosted Commands *(introspect the self-hosting system)*
72
+
73
+ | Command | Description |
74
+ |---|---|
75
+ | `flux self-hosted` | Show self-hosting status — all 18 modules |
76
+ | `flux self-hosted build` | Recompile all `src/self/*.flux` → `.js` |
77
+ | `flux self-hosted verify` | Full 3-stage bootstrap verification |
78
+ | `flux self-hosted on` | Activate self-hosted compiler globally |
79
+ | `flux self-hosted off` | Revert to stage-0 compiler |
80
+
52
81
  ### Flags
53
82
 
54
83
  ```
@@ -56,6 +85,8 @@ console.log(result.output);
56
85
  --sourcemap, -m Generate source map (.js.map)
57
86
  --stdout Print output to terminal
58
87
  --no-color Disable color output
88
+ --dev Mark dependency as devDependency (flux add)
89
+ --global, -g Install package globally (flux install)
59
90
  ```
60
91
 
61
92
  ---
@@ -1284,24 +1315,79 @@ JavaScript (.js) Ready to run in Node.js / browser
1284
1315
 
1285
1316
  ## Self-Hosting
1286
1317
 
1287
- Flux v3 is **100% self-hosted** — the compiler is written in Flux itself. The canonical source lives in `src/self/`:
1318
+ Flux v3.4.0 is **100% self-hosted** — every compiler component, the package manager, and the CLI are written entirely in Flux and compiled by Flux itself. The canonical sources live in `src/self/` (18 modules total):
1288
1319
 
1289
- ```
1290
- src/self/lexer.flux → compiled → src/lexer.js
1291
- src/self/parser.flux → compiled src/parser.js
1292
- src/self/codegen.flux → compiled → src/codegen.js
1293
- src/self/type-checker.flux compiled src/type-checker.js
1294
- src/self/transpiler.flux compiled src/transpiler.js
1295
- ...
1296
- ```
1320
+ ### Core Compiler (8 modules)
1321
+
1322
+ | Source | Output | Description |
1323
+ |---|---|---|
1324
+ | `src/self/lexer.flux` | `src/self/lexer.js` | Tokenizer — 60+ token types, indentation tracking |
1325
+ | `src/self/parser.flux` | `src/self/parser.js` | Recursive descent parser → AST |
1326
+ | `src/self/codegen.flux` | `src/self/codegen.js` | AST → JavaScript code generator |
1327
+ | `src/self/type-checker.flux` | `src/self/type-checker.js` | Static type inference + checking |
1328
+ | `src/self/checker.flux` | `src/self/checker.js` | Semantic analysis, scope resolution |
1329
+ | `src/self/transpiler.flux` | `src/self/transpiler.js` | Full pipeline coordinator |
1330
+ | `src/self/jsx.flux` | `src/self/jsx.js` | JSX transform (server + browser targets) |
1331
+ | `src/self/css-preprocessor.flux` | `src/self/css-preprocessor.js` | CSS variable substitution + nesting |
1332
+
1333
+ ### Extended Toolchain (7 modules)
1334
+
1335
+ | Source | Output | Description |
1336
+ |---|---|---|
1337
+ | `src/self/formatter.flux` | `src/self/formatter.js` | `flux fmt` — canonical code formatter |
1338
+ | `src/self/sourcemap.flux` | `src/self/sourcemap.js` | Source map generation (V3 spec) |
1339
+ | `src/self/stdlib.flux` | `src/self/stdlib.js` | 80+ standard library functions |
1340
+ | `src/self/mangler.flux` | `src/self/mangler.js` | Identifier mangling for minification |
1341
+ | `src/self/linter.flux` | `src/self/linter.js` | `flux lint` — unused vars, shadowing, unreachable |
1342
+ | `src/self/bundler.flux` | `src/self/bundler.js` | `flux bundle` — single-file output |
1343
+ | `src/self/test-runner.flux` | `src/self/test-runner.js` | `flux test` — discovers and runs `.test.flux` files |
1344
+
1345
+ ### Ecosystem Tooling (3 modules — new in v3.4.0)
1346
+
1347
+ | Source | Output | Description |
1348
+ |---|---|---|
1349
+ | `src/self/config.flux` | `src/self/config.js` | `flux.json` project config reader + validator |
1350
+ | `src/self/pkg.flux` | `src/self/pkg.js` | Package manager (add/remove/install/search/publish) |
1351
+ | `src/self/cli.flux` | `src/self/cli.js` | Complete CLI — all commands, flags, REPL, self-hosted sub-system |
1297
1352
 
1298
- Bootstrap the self-hosted compiler:
1353
+ ### 3-Stage Bootstrap
1299
1354
 
1300
1355
  ```bash
1356
+ # Stage 0 — stage-0 JS compiler compiles all 18 .flux → .js
1357
+ # Stage 1 — self-hosted output verified identical to stage-0 output
1358
+ # Stage 2 — self-hosted compiler compiles its own lexer.flux
1301
1359
  node scripts/bootstrap.js
1360
+ # ✓ Bootstrap complete — Flux is self-hosting.
1302
1361
  ```
1303
1362
 
1304
- This compiles all `.flux` source files into their `.js` counterparts using the existing JS stage of the compiler.
1363
+ The bootstrap script produces `src/self/lexer.stage2.js` as cryptographic proof of self-compile.
1364
+
1365
+ ### Using the Self-Hosted Compiler
1366
+
1367
+ ```bash
1368
+ # Check status of all 18 modules
1369
+ flux self-hosted
1370
+
1371
+ # Rebuild after editing any src/self/*.flux file
1372
+ flux self-hosted build
1373
+
1374
+ # Run full 3-stage verification
1375
+ flux self-hosted verify
1376
+
1377
+ # Activate self-hosted compiler as default
1378
+ flux self-hosted on
1379
+ ```
1380
+
1381
+ ### Programmatic API (self-hosted transpiler)
1382
+
1383
+ ```js
1384
+ const { transpile } = require('@xnoxs/flux-lang/src/self/transpiler');
1385
+ // or the stage-0 compiler:
1386
+ const { transpile } = require('@xnoxs/flux-lang');
1387
+
1388
+ const result = transpile('val x = 42\nprint(x)', {});
1389
+ console.log(result.output);
1390
+ ```
1305
1391
 
1306
1392
  ---
1307
1393
 
@@ -1378,6 +1464,20 @@ app.listen(3000, fn():
1378
1464
 
1379
1465
  ## Changelog
1380
1466
 
1467
+ ### v3.4.0 — June 25, 2026
1468
+ - **Complete self-hosting ecosystem** — 18 Flux modules total (was 15)
1469
+ - **`src/self/pkg.flux`** — full package manager written in Flux: `flux add/remove/install/search/info/publish`
1470
+ - **`src/self/config.flux`** — `flux.json` project config reader + schema validator in Flux
1471
+ - **`src/self/cli.flux`** — entire CLI (~880 lines) written in Flux: all commands, REPL, init, watch, self-hosted sub-system
1472
+ - **3-stage bootstrap verified** — Stage-0 compile → Stage-1 parity check → Stage-2 self-compile of `lexer.flux`
1473
+ - **`flux self-hosted` sub-command** — introspect status of all 18 modules, rebuild, verify, activate
1474
+ - **`/self-hosted` web page** — live documentation page with pipeline visualizer and code samples
1475
+ - Nav updated: Home · Playground · Docs · Examples · **Self-Hosted** · Demo
1476
+
1477
+ ### v3.3.4 — June 2026
1478
+ - Build pipeline hardened — `dist/flux-cli.js` (347 kB), `dist/flux.cjs.js` (263 kB)
1479
+ - `src/self/` included in npm package `files` array
1480
+
1381
1481
  ### v3.2.0 — June 2026
1382
1482
  - **Decorators** — `@name` and `@name(args)` on `fn` and `class`
1383
1483
  - **Private fields** — `private var x` → JS `#x` syntax
package/dist/flux-cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /*!
3
- * flux-lang v3.3.4
3
+ * flux-lang v3.4.1
4
4
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
5
5
  * (c) 2026 Flux Lang Contributors
6
6
  * Released under the MIT License
@@ -7203,7 +7203,7 @@ var require_package = __commonJS({
7203
7203
  "package.json"(exports2, module2) {
7204
7204
  module2.exports = {
7205
7205
  name: "@xnoxs/flux-lang",
7206
- version: "3.3.4",
7206
+ version: "3.4.1",
7207
7207
  description: "Flux \u2014 A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.",
7208
7208
  main: "dist/flux.cjs.js",
7209
7209
  module: "dist/flux.esm.js",
@@ -8643,136 +8643,258 @@ function cmdInit(name) {
8643
8643
  const projectName = name || "my-flux-app";
8644
8644
  const dir = path.resolve(projectName);
8645
8645
  if (fs.existsSync(dir)) {
8646
- console.error(clr(C.red, `[Error] Directory already exists: ${projectName}`));
8646
+ console.error(clr(C.red, `\u2717 Directory already exists: ${projectName}`));
8647
8647
  process.exit(1);
8648
8648
  }
8649
8649
  fs.mkdirSync(dir, { recursive: true });
8650
8650
  fs.mkdirSync(path.join(dir, "src"), { recursive: true });
8651
- fs.writeFileSync(path.join(dir, "src", "main.flux"), [
8652
- "// Welcome to Flux Lang v2.0!",
8653
- "",
8654
- "// --- Basic ---",
8655
- 'val greeting = "Hello, Flux!"',
8656
- "print(greeting)",
8657
- "",
8658
- "// --- Async / Await ---",
8659
- "async fn fetchData(url):",
8660
- " try:",
8661
- " val res = await fetch(url)",
8662
- " val data = await res.json()",
8663
- " return data",
8664
- " catch(e):",
8665
- ' print("Fetch error:", e.message)',
8666
- " return null",
8667
- "",
8668
- "// --- Destructuring ---",
8669
- 'val person = { name: "Budi", age: 25, city: "Jakarta" }',
8670
- "val { name, age } = person",
8671
- 'print("Name: {name}, Age: {age}")',
8672
- "",
8673
- "// --- Optional chaining & nullish coalescing ---",
8674
- "val user = null",
8675
- 'val displayName = user?.name ?? "Anonymous"',
8676
- 'print("User:", displayName)',
8677
- "",
8678
- "// --- Spread ---",
8679
- "val nums = [1, 2, 3]",
8680
- "val more = [...nums, 4, 5, 6]",
8681
- 'print("Numbers:", more)',
8682
- "",
8683
- "// --- Rest params ---",
8684
- "fn sum(...args):",
8685
- " return args.reduce((acc, x) -> acc + x, 0)",
8686
- "",
8687
- 'print("Sum:", sum(1, 2, 3, 4, 5))',
8688
- "",
8689
- "// --- Default params ---",
8690
- 'fn greet(name = "World") -> "Hello, {name}!"',
8691
- "print(greet())",
8692
- 'print(greet("Flux"))',
8693
- "",
8694
- "// --- Error handling ---",
8695
- "fn divide(a, b):",
8696
- " if b == 0:",
8697
- ' throw new Error("Division by zero")',
8698
- " return a / b",
8699
- "",
8700
- "try:",
8701
- " print(divide(10, 2))",
8702
- " print(divide(10, 0))",
8703
- "catch(e):",
8704
- ' print("Error:", e.message)',
8705
- "finally:",
8706
- ' print("Done.")',
8707
- ""
8708
- ].join("\n"), "utf8");
8709
- fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify({
8651
+ fs.mkdirSync(path.join(dir, "tests"), { recursive: true });
8652
+ fs.writeFileSync(path.join(dir, "src", "main.flux"), `// ${projectName} \u2014 built with Flux Lang v${VERSION}
8653
+ // Run: flux run src/main.flux
8654
+
8655
+ // \u2500\u2500 Algebraic Data Types + Pattern Matching \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8656
+ type Shape = Circle(radius) | Rect(width, height) | Triangle(base, height)
8657
+
8658
+ fn area(shape):
8659
+ match shape:
8660
+ when Circle(r): return Math.PI * r * r
8661
+ when Rect(w, h): return w * h
8662
+ when Triangle(b, h): return 0.5 * b * h
8663
+
8664
+ fn describe(shape):
8665
+ match shape:
8666
+ when Circle(r): return "Circle(r={r:.2f})"
8667
+ when Rect(w, h): return "Rect({w:.1f}x{h:.1f})"
8668
+ when Triangle(b, h): return "Triangle(b={b:.1f}, h={h:.1f})"
8669
+
8670
+ // \u2500\u2500 Result type \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8671
+ type Result = Ok(value) | Err(message)
8672
+
8673
+ fn safeDivide(a, b):
8674
+ if b == 0: return Err("division by zero")
8675
+ return Ok(a / b)
8676
+
8677
+ // \u2500\u2500 Utility functions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8678
+ fn greet(name): return "Hello from Flux, {name}!"
8679
+
8680
+ fn formatList(items):
8681
+ if items.length == 0: return "(empty)"
8682
+ return "[" + items.join(", ") + "]"
8683
+
8684
+ fn clamp(value, lo, hi):
8685
+ if value < lo: return lo
8686
+ if value > hi: return hi
8687
+ return value
8688
+
8689
+ // \u2500\u2500 Pipe operator + stdlib \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8690
+ val numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
8691
+ val processed = numbers
8692
+ |> filter(n -> n > 3)
8693
+ |> map(n -> n * n)
8694
+ |> sort
8695
+
8696
+ // \u2500\u2500 Main \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8697
+ print(greet("${projectName}"))
8698
+ print("Squares > 3: {formatList(processed)}")
8699
+ print("clamp(12, 0, 10) = {clamp(12, 0, 10)}")
8700
+
8701
+ val shapes = [Circle(5.0), Rect(8.0, 3.0), Triangle(6.0, 4.0)]
8702
+ for shape in shapes:
8703
+ val a = area(shape)
8704
+ print("{describe(shape)} area={a:.2f}")
8705
+
8706
+ match safeDivide(10.0, 3.0):
8707
+ when Ok(v): print("10 / 3 = {v:.4f}")
8708
+ when Err(e): print("Error: {e}")
8709
+ `, "utf8");
8710
+ fs.writeFileSync(path.join(dir, "src", "utils.flux"), `// Utility functions for ${projectName}
8711
+ // Use with: flux bundle src/main.flux (bundles imports automatically)
8712
+
8713
+ export fn greet(name):
8714
+ return "\u26A1 Hello from Flux, {name}!"
8715
+
8716
+ export fn formatList(items):
8717
+ if items.length == 0: return "(empty)"
8718
+ return "[" + items.join(", ") + "]"
8719
+
8720
+ export fn clamp(value, lo, hi):
8721
+ if value < lo: return lo
8722
+ if value > hi: return hi
8723
+ return value
8724
+
8725
+ export fn sum(nums):
8726
+ return nums.reduce((acc, x) -> acc + x, 0)
8727
+
8728
+ export fn average(nums):
8729
+ if nums.length == 0: return 0
8730
+ return sum(nums) / nums.length
8731
+ `, "utf8");
8732
+ fs.writeFileSync(path.join(dir, "tests", "main.test.flux"), `// Tests for ${projectName}
8733
+ // Run: flux test tests/
8734
+
8735
+ // \u2500\u2500 Functions under test \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8736
+ fn add(a, b):
8737
+ return a + b
8738
+
8739
+ fn mul(a, b):
8740
+ return a * b
8741
+
8742
+ fn clamp(value, lo, hi):
8743
+ if value < lo: return lo
8744
+ if value > hi: return hi
8745
+ return value
8746
+
8747
+ fn average(nums):
8748
+ if nums.length == 0: return 0
8749
+ return nums.reduce((s, x) -> s + x, 0) / nums.length
8750
+
8751
+ type Result = Ok(value) | Err(message)
8752
+
8753
+ fn safeDivide(a, b):
8754
+ if b == 0: return Err("div by zero")
8755
+ return Ok(a / b)
8756
+
8757
+ // \u2500\u2500 Test functions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
8758
+ fn test_add():
8759
+ assert(add(1, 2) == 3, "1+2=3")
8760
+ assert(add(0, 0) == 0, "0+0=0")
8761
+ assert(add(-1, 1) == 0, "-1+1=0")
8762
+
8763
+ fn test_mul():
8764
+ assert(mul(3, 4) == 12, "3*4=12")
8765
+ assert(mul(0, 5) == 0, "0*5=0")
8766
+
8767
+ fn test_clamp():
8768
+ assert(clamp(5, 0, 10) == 5, "within range")
8769
+ assert(clamp(-1, 0, 10) == 0, "below min")
8770
+ assert(clamp(15, 0, 10) == 10, "above max")
8771
+
8772
+ fn test_average():
8773
+ assert(average([2, 4, 6]) == 4, "average of 2,4,6")
8774
+ assert(average([]) == 0, "empty list")
8775
+
8776
+ fn test_safe_divide():
8777
+ val ok = safeDivide(10, 2)
8778
+ match ok:
8779
+ when Ok(v): assert(v == 5, "10/2=5")
8780
+ when Err(e): assert(false, "unexpected error")
8781
+ val err = safeDivide(10, 0)
8782
+ match err:
8783
+ when Ok(v): assert(false, "expected error")
8784
+ when Err(e): assert(e == "div by zero", "error message")
8785
+
8786
+ fn test_pipe_operator():
8787
+ val result = [1, 2, 3, 4, 5] |> filter(n -> n > 2) |> map(n -> n * 2)
8788
+ assert(result.length == 3, "filter length")
8789
+ assert(result[0] == 6, "first element")
8790
+ assert(result[2] == 10, "last element")
8791
+ `, "utf8");
8792
+ const fluxJson = {
8710
8793
  name: projectName,
8711
8794
  version: "1.0.0",
8712
- description: `A Flux Lang project`,
8795
+ description: `A Flux Lang v${VERSION} project`,
8796
+ author: "",
8797
+ license: "MIT",
8798
+ entry: "src/main.flux",
8799
+ outDir: "dist",
8800
+ sourcemap: false,
8801
+ typecheck: true,
8713
8802
  scripts: {
8714
- start: `flux run src/main.flux`,
8715
- build: `flux bundle src/main.flux -o dist/bundle.js`,
8716
- dev: `flux watch src/main.flux`,
8717
- check: `flux check src/main.flux`
8803
+ start: "flux run src/main.flux",
8804
+ build: "flux bundle src/main.flux -o dist/bundle.js",
8805
+ dev: "flux watch src/main.flux",
8806
+ check: "flux check src/main.flux",
8807
+ test: "flux test tests/",
8808
+ fmt: "flux fmt src/",
8809
+ lint: "flux lint src/"
8718
8810
  },
8719
8811
  dependencies: {},
8720
- devDependencies: { "flux-lang": `^${VERSION}` }
8721
- }, null, 2), "utf8");
8722
- fs.writeFileSync(path.join(dir, "flux.config.js"), [
8723
- "// Flux Lang project configuration",
8724
- "// All options are optional \u2014 CLI flags always override these values.",
8725
- "module.exports = {",
8726
- " // jsxTarget : 'browser', // 'browser' | 'server' | 'react'",
8727
- " // outDir : './dist', // output directory for compiled files",
8728
- " // sourcemap : false, // generate .js.map files",
8729
- " // mangle : true, // obfuscate names in output",
8730
- " // ignore : [], // glob patterns to skip in `flux test`",
8731
- " // entry : 'src/main.flux', // default entry for `flux bundle`",
8732
- "};"
8733
- ].join("\n"), "utf8");
8812
+ devDependencies: { "@xnoxs/flux-lang": `^${VERSION}` }
8813
+ };
8814
+ fs.writeFileSync(path.join(dir, "flux.json"), JSON.stringify(fluxJson, null, 2) + "\n", "utf8");
8734
8815
  fs.writeFileSync(path.join(dir, ".gitignore"), [
8735
8816
  "node_modules/",
8736
8817
  "dist/",
8818
+ "flux_modules/",
8737
8819
  "*.js.map",
8738
- ".DS_Store"
8739
- ].join("\n"), "utf8");
8740
- fs.writeFileSync(path.join(dir, "README.md"), [
8741
- `# ${projectName}`,
8742
- "",
8743
- "A project built with [Flux Lang](https://github.com/flux-lang/flux-lang) v2.",
8744
- "",
8745
- "## Getting Started",
8746
- "",
8747
- "```bash",
8748
- "npm install",
8749
- "flux run src/main.flux",
8750
- "```",
8751
- "",
8752
- "## Commands",
8753
- "",
8754
- "| Command | Description |",
8755
- "|---|---|",
8756
- "| `npm start` | Run main.flux |",
8757
- "| `npm run build` | Bundle to dist/ |",
8758
- "| `npm run dev` | Watch mode |",
8759
- "| `npm run check` | Check syntax |",
8820
+ ".DS_Store",
8760
8821
  ""
8761
8822
  ].join("\n"), "utf8");
8823
+ fs.writeFileSync(path.join(dir, "README.md"), `# ${projectName}
8824
+
8825
+ A project built with [Flux Lang](https://flux-lang.dev) v${VERSION} \u2014 the self-hosted compiler written in Flux itself.
8826
+
8827
+ ## Quick Start
8828
+
8829
+ \`\`\`bash
8830
+ flux run src/main.flux
8831
+ \`\`\`
8832
+
8833
+ ## Project Structure
8834
+
8835
+ \`\`\`
8836
+ ${projectName}/
8837
+ \u251C\u2500\u2500 src/
8838
+ \u2502 \u251C\u2500\u2500 main.flux # Entry point
8839
+ \u2502 \u2514\u2500\u2500 utils.flux # Utility functions
8840
+ \u251C\u2500\u2500 tests/
8841
+ \u2502 \u2514\u2500\u2500 main.test.flux # Test suite
8842
+ \u251C\u2500\u2500 flux.json # Project config
8843
+ \u2514\u2500\u2500 README.md
8844
+ \`\`\`
8845
+
8846
+ ## Commands
8847
+
8848
+ | Command | Description |
8849
+ |---|---|
8850
+ | \`flux run src/main.flux\` | Run the project |
8851
+ | \`flux bundle src/main.flux -o dist/bundle.js\` | Bundle to single file |
8852
+ | \`flux watch src/main.flux\` | Watch mode \u2014 auto-recompile |
8853
+ | \`flux check src/main.flux\` | Type check + static analysis |
8854
+ | \`flux test tests/\` | Run all tests |
8855
+ | \`flux fmt src/\` | Format source code |
8856
+ | \`flux lint src/\` | Lint for issues |
8857
+ | \`flux add <package>\` | Add a dependency |
8858
+
8859
+ ## flux.json Reference
8860
+
8861
+ \`\`\`json
8862
+ {
8863
+ "entry": "src/main.flux", // default entry for flux bundle
8864
+ "outDir": "dist", // output directory
8865
+ "sourcemap": false, // generate .js.map files
8866
+ "typecheck": true, // run type checker on compile
8867
+ "scripts": { ... } // runnable with: flux run <name>
8868
+ }
8869
+ \`\`\`
8870
+
8871
+ ## Learn More
8872
+
8873
+ - [Flux Docs](https://flux-lang.dev/docs)
8874
+ - [Playground](https://flux-lang.dev/playground)
8875
+ - [Self-Hosted Compiler](https://flux-lang.dev/self-hosted)
8876
+ - [npm package](https://www.npmjs.com/package/@xnoxs/flux-lang)
8877
+ `, "utf8");
8878
+ const files = [
8879
+ `${projectName}/src/main.flux`,
8880
+ `${projectName}/src/utils.flux`,
8881
+ `${projectName}/tests/main.test.flux`,
8882
+ `${projectName}/flux.json`,
8883
+ `${projectName}/.gitignore`,
8884
+ `${projectName}/README.md`
8885
+ ];
8762
8886
  console.log();
8763
- console.log(clr(C.green, `\u2713 Project created: ${projectName}/`));
8887
+ console.log(clr(C.green, `\u2713 Created: `) + clr(C.bold, `${projectName}/`));
8764
8888
  console.log();
8765
- console.log(clr(C.gray, " Files created:"));
8766
- console.log(" " + clr(C.cyan, `${projectName}/src/main.flux`));
8767
- console.log(" " + clr(C.cyan, `${projectName}/flux.config.js`));
8768
- console.log(" " + clr(C.cyan, `${projectName}/package.json`));
8769
- console.log(" " + clr(C.cyan, `${projectName}/.gitignore`));
8770
- console.log(" " + clr(C.cyan, `${projectName}/README.md`));
8889
+ console.log(clr(C.gray, " Files:"));
8890
+ for (const f of files) console.log(" " + clr(C.cyan, f));
8771
8891
  console.log();
8772
8892
  console.log(clr(C.bold, " Next steps:"));
8773
8893
  console.log(` ${clr(C.yellow, `cd ${projectName}`)}`);
8774
- console.log(` ${clr(C.yellow, "npm install")}`);
8775
- console.log(` ${clr(C.yellow, "flux run src/main.flux")}`);
8894
+ console.log(` ${clr(C.yellow, `flux run src/main.flux`)}`);
8895
+ console.log();
8896
+ console.log(clr(C.gray, ` Or run the test suite:`));
8897
+ console.log(` ${clr(C.yellow, `flux test tests/`)}`);
8776
8898
  console.log();
8777
8899
  }
8778
8900
  function cmdCompile(filePath, opts) {
package/dist/flux.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * flux-lang v3.3.4
2
+ * flux-lang v3.4.1
3
3
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
4
4
  * (c) 2026 Flux Lang Contributors
5
5
  * Released under the MIT License
package/dist/flux.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * flux-lang v3.3.4
2
+ * flux-lang v3.4.1
3
3
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
4
4
  * (c) 2026 Flux Lang Contributors
5
5
  * Released under the MIT License
package/dist/flux.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * flux-lang v3.3.4
2
+ * flux-lang v3.4.1
3
3
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
4
4
  * (c) 2026 Flux Lang Contributors
5
5
  * Released under the MIT License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xnoxs/flux-lang",
3
- "version": "3.3.4",
3
+ "version": "3.4.1",
4
4
  "description": "Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.",
5
5
  "main": "dist/flux.cjs.js",
6
6
  "module": "dist/flux.esm.js",
@@ -5,9 +5,15 @@ function findIndex(arr, fn) { return arr.findIndex(fn); }
5
5
  function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
6
6
 
7
7
  function includes(arr, val) { return arr.includes(val); }
8
+
9
+ function trim(s) { return String(s).trim(); }
10
+
11
+ function endsWith(s, suffix) { return String(s).endsWith(suffix); }
12
+
13
+ function repeat(s, n) { return String(s).repeat(n); }
8
14
  // ── end stdlib ──
9
15
 
10
- // Generated by Flux Transpiler v3.1.0
16
+ // Generated by Flux Transpiler v3.2.0
11
17
  "use strict";
12
18
 
13
19
  const Fs = require("fs");