@xnoxs/flux-lang 3.2.2 → 3.3.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/index.js CHANGED
@@ -13,6 +13,7 @@ const { buildStdlib, detectUsedSymbols, STDLIB_SYMBOLS } = require('./src/stdlib
13
13
  const { Lexer } = require('./src/lexer');
14
14
  const { Parser } = require('./src/parser');
15
15
  const { bundle } = require('./src/bundler');
16
+ const { loadConfig, mergeConfig, defineConfig } = require('./src/config');
16
17
 
17
18
  module.exports = {
18
19
  transpile,
@@ -23,4 +24,7 @@ module.exports = {
23
24
  Lexer,
24
25
  Parser,
25
26
  bundle,
27
+ loadConfig,
28
+ mergeConfig,
29
+ defineConfig,
26
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xnoxs/flux-lang",
3
- "version": "3.2.2",
3
+ "version": "3.3.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",
@@ -9,33 +9,35 @@
9
9
  "flux": "./bin/flux.js"
10
10
  },
11
11
  "scripts": {
12
- "build": "node scripts/build.js",
13
- "prepublishOnly": "npm test && npm run build",
14
- "test": "node src/cli.js test tests/",
15
- "test:file": "node src/cli.js test",
16
- "check": "node src/cli.js check tests/01_basics.test.flux",
17
- "bench": "node benchmarks/bench.js",
18
- "start": "node src/cli.js run app/server.flux",
19
- "repl": "node src/cli.js repl",
20
- "version": "node src/cli.js version"
12
+ "build": "node scripts/build.js",
13
+ "prepublishOnly": "npm test && npm run build",
14
+ "test": "node src/cli.js test tests/",
15
+ "test:file": "node src/cli.js test",
16
+ "check": "node src/cli.js check tests/01_basics.test.flux",
17
+ "bench": "node benchmarks/bench.js",
18
+ "start": "node src/cli.js run app/server.flux",
19
+ "repl": "node src/cli.js repl",
20
+ "version": "node src/cli.js version"
21
21
  },
22
22
  "exports": {
23
23
  ".": {
24
- "import": "./dist/flux.esm.js",
24
+ "import": "./dist/flux.esm.js",
25
25
  "require": "./dist/flux.cjs.js",
26
26
  "default": "./dist/flux.cjs.js"
27
27
  },
28
+ "./config": "./src/config.js",
28
29
  "./dist/cjs": "./dist/flux.cjs.js",
29
30
  "./dist/esm": "./dist/flux.esm.js",
30
31
  "./dist/min": "./dist/flux.min.js",
31
- "./stdlib": "./src/stdlib.js",
32
- "./formatter":"./src/formatter.js"
32
+ "./stdlib": "./src/stdlib.js",
33
+ "./formatter": "./src/formatter.js"
33
34
  },
34
35
  "files": [
35
36
  "bin/",
36
37
  "dist/",
37
38
  "src/stdlib.js",
38
39
  "src/formatter.js",
40
+ "src/config.js",
39
41
  "src/self/",
40
42
  "scripts/build.js",
41
43
  "index.js",
package/src/config.js ADDED
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Flux Lang — Project Config Loader
5
+ *
6
+ * Looks for flux.config.js (or .fluxrc.js) in the current working directory.
7
+ * Returns a plain object with config values; returns {} if no config found.
8
+ *
9
+ * Config schema:
10
+ * module.exports = {
11
+ * jsxTarget : 'browser' | 'server' | 'react', // default: 'browser'
12
+ * outDir : './dist', // output dir for compiled files
13
+ * sourcemap : false, // generate .js.map files
14
+ * mangle : true, // obfuscate variable/function names
15
+ * ignore : [], // glob patterns to skip in `flux test`
16
+ * entry : 'src/main.flux', // default bundle entry
17
+ * }
18
+ *
19
+ * CLI flags always take precedence over config values.
20
+ */
21
+
22
+ const fs = require('fs');
23
+ const path = require('path');
24
+
25
+ const CONFIG_NAMES = [
26
+ 'flux.config.js',
27
+ 'flux.config.cjs',
28
+ '.fluxrc.js',
29
+ ];
30
+
31
+ /**
32
+ * Load project config from CWD (or a given directory).
33
+ * @param {string} [cwd] - directory to search (default: process.cwd())
34
+ * @returns {object} raw config object (or {} if none found)
35
+ */
36
+ function loadConfig(cwd) {
37
+ const dir = cwd || process.cwd();
38
+
39
+ for (const name of CONFIG_NAMES) {
40
+ const configPath = path.join(dir, name);
41
+ if (!fs.existsSync(configPath)) continue;
42
+
43
+ // Bust require cache so tests can reload different configs
44
+ delete require.cache[require.resolve(configPath)];
45
+
46
+ try {
47
+ const raw = require(configPath);
48
+ const cfg = raw && raw.default ? raw.default : raw;
49
+
50
+ if (typeof cfg !== 'object' || cfg === null) {
51
+ process.stderr.write(
52
+ `[flux] warning: ${name} must export a plain object — ignoring\n`
53
+ );
54
+ return {};
55
+ }
56
+
57
+ return cfg;
58
+ } catch (e) {
59
+ process.stderr.write(
60
+ `[flux] error loading ${name}: ${e.message}\n`
61
+ );
62
+ return {};
63
+ }
64
+ }
65
+
66
+ return {};
67
+ }
68
+
69
+ /**
70
+ * Merge file config with CLI opts (CLI flags win).
71
+ * @param {object} fileConfig - from loadConfig()
72
+ * @param {object} cliOpts - parsed CLI flags
73
+ * @returns {object} merged options safe to pass to transpile()
74
+ */
75
+ function mergeConfig(fileConfig, cliOpts) {
76
+ const cfg = fileConfig || {};
77
+ const cli = cliOpts || {};
78
+
79
+ return {
80
+ jsxTarget : cli.jsxTarget !== undefined ? cli.jsxTarget : (cfg.jsxTarget || 'browser'),
81
+ outDir : cli.outDir !== undefined ? cli.outDir : (cfg.outDir || null),
82
+ sourcemap : cli.sourcemap !== undefined ? cli.sourcemap : (cfg.sourcemap || false),
83
+ mangle : cli.mangle !== undefined ? cli.mangle : (cfg.mangle !== undefined ? cfg.mangle : true),
84
+ ignore : cli.ignore !== undefined ? cli.ignore : (cfg.ignore || []),
85
+ entry : cli.entry !== undefined ? cli.entry : (cfg.entry || null),
86
+ };
87
+ }
88
+
89
+ /**
90
+ * Identity helper for IDE type-checking / autocompletion.
91
+ * Usage in flux.config.js: const { defineConfig } = require('@xnoxs/flux-lang/config');
92
+ * @param {object} config
93
+ * @returns {object}
94
+ */
95
+ function defineConfig(config) {
96
+ return config;
97
+ }
98
+
99
+ module.exports = { loadConfig, mergeConfig, defineConfig };