@xnoxs/flux-lang 4.0.8 → 4.0.9

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.
@@ -2,11 +2,10 @@
2
2
  // Flux Self-Hosted Config Reader
3
3
  // src/self/config.flux — written in Flux, compiled by stage-0
4
4
  //
5
- // Reads config from package.json ("flux" key) or flux.json fallback.
6
- // Config file resolution order:
7
- // 1. package.json → { "flux": { ... } } ← primary
8
- // 2. flux.json ← legacy fallback
9
- // 3. default config ← if none found
5
+ // Reads flux.json project config and merges with CLI flags.
6
+ // Config file locations (searched in order):
7
+ // ./flux.json
8
+ // ./flux.config.js
10
9
  // ============================================================
11
10
 
12
11
  import Fs from "fs"
@@ -25,7 +24,7 @@ export val DEFAULT_CONFIG = {
25
24
  watch: false,
26
25
  ignore: [],
27
26
  selfHosted: false,
28
- registry: "https://registry.npmjs.org",
27
+ registry: "https://registry.flux-lang.dev",
29
28
  pkg: {
30
29
  name: "",
31
30
  version: "1.0.0",
@@ -37,22 +36,11 @@ export val DEFAULT_CONFIG = {
37
36
  }
38
37
  }
39
38
 
40
- // ── Load config (package.json "flux" key first, flux.json fallback) ──
39
+ // ── Load flux.json ────────────────────────────────────────────
41
40
  export fn loadConfig(cwd_):
42
41
  val cwd = cwd_ ?? process.cwd()
43
42
 
44
- // 1. Try package.json → "flux" key (primary)
45
- val pkgJsonPath = Path.join(cwd, "package.json")
46
- if Fs.existsSync(pkgJsonPath):
47
- try:
48
- val raw = Fs.readFileSync(pkgJsonPath, "utf8")
49
- val parsed = JSON.parse(raw)
50
- if parsed.flux and typeof parsed.flux == "object":
51
- return mergeConfig(DEFAULT_CONFIG, parsed.flux)
52
- catch(e):
53
- throw new Error("Invalid package.json: " + e.message)
54
-
55
- // 2. Try flux.json (legacy fallback)
43
+ // Try flux.json first
56
44
  val jsonPath = Path.join(cwd, "flux.json")
57
45
  if Fs.existsSync(jsonPath):
58
46
  try:
@@ -62,7 +50,15 @@ export fn loadConfig(cwd_):
62
50
  catch(e):
63
51
  throw new Error("Invalid flux.json: " + e.message)
64
52
 
65
- // 3. Default config
53
+ // Try flux.config.js
54
+ val jsPath = Path.join(cwd, "flux.config.js")
55
+ if Fs.existsSync(jsPath):
56
+ try:
57
+ val loaded = require(jsPath)
58
+ return mergeConfig(DEFAULT_CONFIG, loaded)
59
+ catch(e2):
60
+ throw new Error("Invalid flux.config.js: " + e2.message)
61
+
66
62
  return { ...DEFAULT_CONFIG }
67
63
 
68
64
  // ── Deep merge config objects ─────────────────────────────────
@@ -75,16 +71,12 @@ export fn mergeConfig(base, overrides):
75
71
  result[key] = val_
76
72
  return result
77
73
 
78
- // ── Write flux key into package.json ─────────────────────────
74
+ // ── Write flux.json ───────────────────────────────────────────
79
75
  export fn writeConfig(config, cwd_):
80
- val cwd = cwd_ ?? process.cwd()
81
- val pkgPath = Path.join(cwd, "package.json")
82
- var pkg = {}
83
- if Fs.existsSync(pkgPath):
84
- try: pkg = JSON.parse(Fs.readFileSync(pkgPath, "utf8"))
85
- catch(e): pkg = {}
86
- pkg.flux = config
87
- Fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8")
76
+ val cwd = cwd_ ?? process.cwd()
77
+ val jsonPath = Path.join(cwd, "flux.json")
78
+ val content = JSON.stringify(config, null, 2) + "\n"
79
+ Fs.writeFileSync(jsonPath, content, "utf8")
88
80
 
89
81
  // ── Validate config ───────────────────────────────────────────
90
82
  export fn validateConfig(config):
@@ -101,20 +93,20 @@ export fn validateConfig(config):
101
93
  errors: errors,
102
94
  }
103
95
 
104
- // ── Read package info (package.json first, flux.json fallback) ────
96
+ // ── Read flux.json package info ───────────────────────────────
105
97
  export fn readPackage(cwd_):
106
- val cwd = cwd_ ?? process.cwd()
107
- val pkgJson = Path.join(cwd, "package.json")
98
+ val cwd = cwd_ ?? process.cwd()
108
99
  val fluxJson = Path.join(cwd, "flux.json")
100
+ val pkgJson = Path.join(cwd, "package.json")
109
101
 
110
- if Fs.existsSync(pkgJson):
102
+ if Fs.existsSync(fluxJson):
111
103
  try:
112
- return JSON.parse(Fs.readFileSync(pkgJson, "utf8"))
104
+ return JSON.parse(Fs.readFileSync(fluxJson, "utf8"))
113
105
  catch(e): return null
114
106
 
115
- if Fs.existsSync(fluxJson):
107
+ if Fs.existsSync(pkgJson):
116
108
  try:
117
- return JSON.parse(Fs.readFileSync(fluxJson, "utf8"))
109
+ return JSON.parse(Fs.readFileSync(pkgJson, "utf8"))
118
110
  catch(e2): return null
119
111
 
120
112
  return null
@@ -1,27 +1,25 @@
1
- /* compiled from src/self/config.flux */
1
+ /* compiled from src/self/config.flux by Flux Lang */
2
2
  'use strict';
3
- // Generated by Flux Transpiler v3.5.3 (self-hosted)
3
+ // ── Flux stdlib ──
4
+
5
+ function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
6
+
7
+ function includes(arr, val) { return arr.includes(val); }
8
+
9
+ function keys(obj) { return Object.keys(obj); }
10
+
11
+ function endsWith(s, suffix) { return String(s).endsWith(suffix); }
12
+ // ── end stdlib ──
13
+
14
+ // Generated by Flux Transpiler v3.2.0
4
15
  "use strict";
5
16
 
6
17
  const Fs = require("fs");
7
18
  const Path = require("path");
8
- const DEFAULT_CONFIG = { entry: "src/main.flux", outDir: "dist", sourcemap: false, mangle: false, jsx: false, jsxTarget: "browser", typecheck: true, strict: false, watch: false, ignore: [], selfHosted: false, registry: "https://registry.npmjs.org", pkg: { name: "", version: "1.0.0", description: "", author: "", license: "MIT", deps: { }, devDeps: { } } };
19
+ const DEFAULT_CONFIG = { entry: "src/main.flux", outDir: "dist", sourcemap: false, mangle: false, jsx: false, jsxTarget: "browser", typecheck: true, strict: false, watch: false, ignore: [], selfHosted: false, registry: "https://registry.flux-lang.dev", pkg: { name: "", version: "1.0.0", description: "", author: "", license: "MIT", deps: { }, devDeps: { } } };
9
20
  module.exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
10
21
  function loadConfig(cwd_) {
11
22
  const cwd = (cwd_ ?? process.cwd());
12
- const pkgJsonPath = Path.join(cwd, "package.json");
13
- if (Fs.existsSync(pkgJsonPath)) {
14
- try {
15
- const raw = Fs.readFileSync(pkgJsonPath, "utf8");
16
- const parsed = JSON.parse(raw);
17
- if ((parsed.flux && (typeof parsed.flux == "object"))) {
18
- return mergeConfig(DEFAULT_CONFIG, parsed.flux);
19
- }
20
- }
21
- catch (e) {
22
- throw new Error(("Invalid package.json: " + e.message));
23
- }
24
- }
25
23
  const jsonPath = Path.join(cwd, "flux.json");
26
24
  if (Fs.existsSync(jsonPath)) {
27
25
  try {
@@ -33,6 +31,16 @@ function loadConfig(cwd_) {
33
31
  throw new Error(("Invalid flux.json: " + e.message));
34
32
  }
35
33
  }
34
+ const jsPath = Path.join(cwd, "flux.config.js");
35
+ if (Fs.existsSync(jsPath)) {
36
+ try {
37
+ const loaded = require(jsPath);
38
+ return mergeConfig(DEFAULT_CONFIG, loaded);
39
+ }
40
+ catch (e2) {
41
+ throw new Error(("Invalid flux.config.js: " + e2.message));
42
+ }
43
+ }
36
44
  return { ...DEFAULT_CONFIG };
37
45
  }
38
46
  module.exports.loadConfig = loadConfig;
@@ -52,18 +60,9 @@ function mergeConfig(base, overrides) {
52
60
  module.exports.mergeConfig = mergeConfig;
53
61
  function writeConfig(config, cwd_) {
54
62
  const cwd = (cwd_ ?? process.cwd());
55
- const pkgPath = Path.join(cwd, "package.json");
56
- let pkg = { };
57
- if (Fs.existsSync(pkgPath)) {
58
- try {
59
- pkg = JSON.parse(Fs.readFileSync(pkgPath, "utf8"));
60
- }
61
- catch (e) {
62
- pkg = { };
63
- }
64
- }
65
- pkg.flux = config;
66
- Fs.writeFileSync(pkgPath, (JSON.stringify(pkg, null, 2) + "\n"), "utf8");
63
+ const jsonPath = Path.join(cwd, "flux.json");
64
+ const content = (JSON.stringify(config, null, 2) + "\n");
65
+ Fs.writeFileSync(jsonPath, content, "utf8");
67
66
  }
68
67
  module.exports.writeConfig = writeConfig;
69
68
  function validateConfig(config) {
@@ -79,19 +78,19 @@ function validateConfig(config) {
79
78
  module.exports.validateConfig = validateConfig;
80
79
  function readPackage(cwd_) {
81
80
  const cwd = (cwd_ ?? process.cwd());
82
- const pkgJson = Path.join(cwd, "package.json");
83
81
  const fluxJson = Path.join(cwd, "flux.json");
84
- if (Fs.existsSync(pkgJson)) {
82
+ const pkgJson = Path.join(cwd, "package.json");
83
+ if (Fs.existsSync(fluxJson)) {
85
84
  try {
86
- return JSON.parse(Fs.readFileSync(pkgJson, "utf8"));
85
+ return JSON.parse(Fs.readFileSync(fluxJson, "utf8"));
87
86
  }
88
87
  catch (e) {
89
88
  return null;
90
89
  }
91
90
  }
92
- if (Fs.existsSync(fluxJson)) {
91
+ if (Fs.existsSync(pkgJson)) {
93
92
  try {
94
- return JSON.parse(Fs.readFileSync(fluxJson, "utf8"));
93
+ return JSON.parse(Fs.readFileSync(pkgJson, "utf8"));
95
94
  }
96
95
  catch (e2) {
97
96
  return null;
@@ -1,3 +1,5 @@
1
+ /* compiled from src/self/css-preprocessor.flux by Flux Lang */
2
+ 'use strict';
1
3
  // ── Flux stdlib ──
2
4
 
3
5
  function includes(arr, val) { return arr.includes(val); }
@@ -298,7 +300,7 @@ class CssPreprocessor {
298
300
  const charAfter = (this.src[(this.pos + 3)] ?? "");
299
301
  if ((!/[a-zA-Z0-9_]/.test(charBefore) && !/[a-zA-Z0-9_]/.test(charAfter))) {
300
302
  let j = (this.pos + 3);
301
- while (((j < this.src.length) && ((((this.src[j] == " ") || (this.src[j] == "\t")) || (this.src[j] == "\n")) || (this.src[j] == "\r")))) {
303
+ while (((j < this.src.length) && ((((this.src[j] == " ") || (this.src[j] == " ")) || (this.src[j] == "\n")) || (this.src[j] == "\r")))) {
302
304
  j = (j + 1);
303
305
  }
304
306
  if ((this.src[j] == "{")) {
@@ -1,3 +1,5 @@
1
+ /* compiled from src/self/formatter.flux by Flux Lang */
2
+ 'use strict';
1
3
  // ── Flux stdlib ──
2
4
 
3
5
  function map(arr, fn) { return arr.map(fn); }
@@ -0,0 +1,87 @@
1
+ // ============================================================
2
+ // Flux Lang — Compiler Entry Point v4.0.3
3
+ // src/self/index.flux
4
+ //
5
+ // Di-kompilasi menjadi src/self/index.js, lalu di-bundle
6
+ // oleh esbuild → dist/flux-compiler.js (satu file).
7
+ //
8
+ // Catatan: bundler.flux dan mangler.flux mengandung template
9
+ // literal yang menghasilkan kode JS yang tidak bisa di-parse
10
+ // oleh esbuild, sehingga tidak di-bundle di sini.
11
+ // Gunakan @xnoxs/flux-lang untuk akses ke bundler dan mangler.
12
+ // ============================================================
13
+
14
+ // ── Core pipeline (koordinator utama) ────────────────────────
15
+ import { transpile as _transpile, transpileFile as _transpileFile, FLUX_VERSION as _VERSION, FLUX_STAGE as _STAGE } from './transpiler'
16
+
17
+ export val transpile = _transpile
18
+ export val transpileFile = _transpileFile
19
+ export val FLUX_VERSION = _VERSION
20
+ export val FLUX_STAGE = _STAGE
21
+
22
+ // ── Lexer ─────────────────────────────────────────────────────
23
+ import { Lexer as _Lexer, lexerize as _lexerize, T as _T, TokenType as _TT } from './lexer'
24
+
25
+ export val Lexer = _Lexer
26
+ export val lexerize = _lexerize
27
+ export val T = _T
28
+ export val TokenType = _TT
29
+
30
+ // ── Parser ────────────────────────────────────────────────────
31
+ import { Parser as _Parser, makeParser as _makeParser } from './parser'
32
+
33
+ export val Parser = _Parser
34
+ export val makeParser = _makeParser
35
+
36
+ // ── Code Generator ────────────────────────────────────────────
37
+ import { CodeGenerator as _CG, makeCodeGen as _makeCG } from './codegen'
38
+
39
+ export val CodeGenerator = _CG
40
+ export val makeCodeGen = _makeCG
41
+
42
+ // ── Type System ───────────────────────────────────────────────
43
+ import { FluxTypeChecker as _FTC } from './type-checker'
44
+ import { Checker as _Checker } from './checker'
45
+
46
+ export val FluxTypeChecker = _FTC
47
+ export val Checker = _Checker
48
+
49
+ // ── Preprocessors ─────────────────────────────────────────────
50
+ import { transformCss as _transformCss } from './css-preprocessor'
51
+ import { transformJsx as _transformJsx, FLUX_H_BROWSER as _FHB, FLUX_H_SERVER as _FHS } from './jsx'
52
+
53
+ export val transformCss = _transformCss
54
+ export val transformJsx = _transformJsx
55
+ export val FLUX_H_BROWSER = _FHB
56
+ export val FLUX_H_SERVER = _FHS
57
+
58
+ // ── Toolchain ─────────────────────────────────────────────────
59
+ import { format as _format, diff as _diff } from './formatter'
60
+ import { lint as _lint, Linter as _Linter } from './linter'
61
+ import { SourceMapBuilder as _SMB } from './sourcemap'
62
+
63
+ export val format = _format
64
+ export val diff = _diff
65
+ export val lint = _lint
66
+ export val Linter = _Linter
67
+ export val SourceMapBuilder = _SMB
68
+
69
+ // ── Standard Library ──────────────────────────────────────────
70
+ import { buildStdlib as _bStdlib, detectUsedSymbols as _det, STDLIB_SYMBOLS as _SS } from './stdlib'
71
+
72
+ export val buildStdlib = _bStdlib
73
+ export val detectUsedSymbols = _det
74
+ export val STDLIB_SYMBOLS = _SS
75
+
76
+ // ── Project Config & Test Runner ──────────────────────────────
77
+ import { loadConfig as _lc, mergeConfig as _mc, writeConfig as _wc, validateConfig as _vc, DEFAULT_CONFIG as _DC } from './config'
78
+ import { discoverTestFiles as _dtf, runTestFile as _rtf, runTests as _rt } from './test-runner'
79
+
80
+ export val loadConfig = _lc
81
+ export val mergeConfig = _mc
82
+ export val writeConfig = _wc
83
+ export val validateConfig = _vc
84
+ export val DEFAULT_CONFIG = _DC
85
+ export val discoverTestFiles = _dtf
86
+ export val runTestFile = _rtf
87
+ export val runTests = _rt
package/src/self/jsx.js CHANGED
@@ -1,3 +1,5 @@
1
+ /* compiled from src/self/jsx.flux by Flux Lang */
2
+ 'use strict';
1
3
  // Flux JSX Runtime
2
4
  "use strict";
3
5
 
@@ -108,7 +110,7 @@ class JsxPreprocessor {
108
110
  return false;
109
111
  }
110
112
  let i = (this.pos - 1);
111
- while (((i >= 0) && ((this.src[i] == " ") || (this.src[i] == "\t")))) {
113
+ while (((i >= 0) && ((this.src[i] == " ") || (this.src[i] == " ")))) {
112
114
  i = (i - 1);
113
115
  }
114
116
  if ((i < 0)) {
@@ -382,7 +384,7 @@ class JsxPreprocessor {
382
384
  }
383
385
 
384
386
  skipWs() {
385
- while (((this.pos < this.src.length) && ((this.src[this.pos] == " ") || (this.src[this.pos] == "\t")))) {
387
+ while (((this.pos < this.src.length) && ((this.src[this.pos] == " ") || (this.src[this.pos] == " ")))) {
386
388
  this.pos = (this.pos + 1);
387
389
  }
388
390
  }
package/src/self/lexer.js CHANGED
@@ -1,3 +1,5 @@
1
+ /* compiled from src/self/lexer.flux by Flux Lang */
2
+ 'use strict';
1
3
  // ── Flux stdlib ──
2
4
 
3
5
  function map(arr, fn) { return arr.map(fn); }
@@ -89,7 +91,7 @@ class Lexer {
89
91
  s += "\n";
90
92
  }
91
93
  else if ((e == "t")) {
92
- s += "\t";
94
+ s += " ";
93
95
  }
94
96
  else if ((e == "`")) {
95
97
  s += "`";
@@ -146,7 +148,7 @@ class Lexer {
146
148
  text += "\n";
147
149
  }
148
150
  else if ((e == "t")) {
149
- text += "\t";
151
+ text += " ";
150
152
  }
151
153
  else if ((e == "\"")) {
152
154
  text += "\"";
@@ -276,8 +278,8 @@ class Lexer {
276
278
  if (bol) {
277
279
  bol = false;
278
280
  let indent = 0;
279
- while (((this.ch() == " ") || (this.ch() == "\t"))) {
280
- if ((this.ch() == "\t")) {
281
+ while (((this.ch() == " ") || (this.ch() == " "))) {
282
+ if ((this.ch() == " ")) {
281
283
  indent = (indent + 4);
282
284
  }
283
285
  else {
@@ -331,7 +333,7 @@ class Lexer {
331
333
  }
332
334
  continue;
333
335
  }
334
- if (((cur == " ") || (cur == "\t"))) {
336
+ if (((cur == " ") || (cur == " "))) {
335
337
  this.adv();
336
338
  continue;
337
339
  }
@@ -419,7 +421,7 @@ class Lexer {
419
421
  sq += "\n";
420
422
  }
421
423
  else if ((e == "t")) {
422
- sq += "\t";
424
+ sq += " ";
423
425
  }
424
426
  else if ((e == "r")) {
425
427
  sq += "\r";
@@ -1,3 +1,5 @@
1
+ /* compiled from src/self/linter.flux by Flux Lang */
2
+ 'use strict';
1
3
  // ── Flux stdlib ──
2
4
 
3
5
  function sort(arr, fn) { return arr.slice().sort(fn); }
@@ -1,3 +1,5 @@
1
+ /* compiled from src/self/mangler.flux by Flux Lang */
2
+ 'use strict';
1
3
  // Flux JSX Runtime
2
4
  "use strict";
3
5
 
@@ -1,3 +1,5 @@
1
+ /* compiled from src/self/parser.flux by Flux Lang */
2
+ 'use strict';
1
3
  // ── Flux stdlib ──
2
4
 
3
5
  function map(arr, fn) { return arr.map(fn); }