@xnoxs/flux-lang 4.0.4 → 4.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xnoxs/flux-lang",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
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",
@@ -3,6 +3,8 @@
3
3
  // src/self/bundler.flux — written in Flux, compiled by stage-0
4
4
  //
5
5
  // Bundles multiple Flux modules into a single JS file.
6
+ // Resolves all inter-file .flux imports recursively.
7
+ // npm packages (non-relative imports) remain as require() calls.
6
8
  // ============================================================
7
9
 
8
10
  import Fs from "fs"
@@ -16,17 +18,25 @@ fn toModuleId(absPath):
16
18
  return '_flux_' + base.replace(/[^a-zA-Z0-9]/g, '_')
17
19
 
18
20
  fn extractModuleInfo(ast, fromFile):
19
- val imports = []
20
- val exports = []
21
- val body = []
22
- val dir = Path.dirname(fromFile)
21
+ val imports = []
22
+ val npmImports = []
23
+ val exports = []
24
+ val body = []
25
+ val dir = Path.dirname(fromFile)
23
26
 
24
27
  for node in ast.body:
25
28
  if node.type == 'ImportDecl':
26
- var src = node.source
27
- if not src.endsWith('.flux'): src = src + '.flux'
28
- val absPath = Path.resolve(dir, src)
29
- imports.push({ names: node.names, source: node.source, absPath })
29
+ val src = node.source
30
+ // Relative import resolve as .flux file
31
+ if src.startsWith('./') or src.startsWith('../'):
32
+ var resolved = src
33
+ if not resolved.endsWith('.flux'): resolved = resolved + '.flux'
34
+ val absPath = Path.resolve(dir, resolved)
35
+ imports.push({ names: node.names, source: node.source, absPath })
36
+ else:
37
+ // npm package import — keep as-is (require in output)
38
+ npmImports.push({ names: node.names, source: src })
39
+ body.push(node)
30
40
 
31
41
  else if node.type == 'ExportDecl':
32
42
  val inner = node.decl
@@ -38,7 +48,7 @@ fn extractModuleInfo(ast, fromFile):
38
48
  else:
39
49
  body.push(node)
40
50
 
41
- return { cleanAst: { type: 'Program', body }, imports, exports }
51
+ return { cleanAst: { type: 'Program', body }, imports, npmImports, exports }
42
52
 
43
53
  fn codegenModule(ast):
44
54
  val cg = makeCodeGen({ indent: ' ' })
@@ -80,6 +90,7 @@ export class Bundler:
80
90
  val info = extractModuleInfo(ast, absPath)
81
91
  self.modules.set(absPath, { cleanAst: info.cleanAst, imports: info.imports, exports: info.exports, source, absPath })
82
92
 
93
+ // Recursively collect all .flux imports
83
94
  for imp in info.imports:
84
95
  self.collect(imp.absPath)
85
96
 
@@ -98,12 +109,6 @@ export class Bundler:
98
109
  lines.push('"use strict";')
99
110
  lines.push('')
100
111
 
101
- // flux_modules resolver: patches Module._resolveFilename so require() looks in
102
- // flux_modules/node_modules/ first (packages installed via `flux install`).
103
- lines.push('// flux_modules resolver')
104
- lines.push("(function(){var _p=require('path'),_fs=require('fs'),_M=require('module'),_d=_p.join(process.cwd(),'flux_modules','node_modules');if(_fs.existsSync(_d)){var _o=_M._resolveFilename.bind(_M);_M._resolveFilename=function(r,p,m,op){if(!r.startsWith('.')&&!r.startsWith('/')&&!r.startsWith('node:')){var _fp=_p.join(_d,r.split('/')[0]);if(_fs.existsSync(_fp)){try{return _o(_p.join(_d,r),p,m,op);}catch(_e){}}}return _o(r,p,m,op);};}})();")
105
- lines.push('')
106
-
107
112
  lines.push('(function() {')
108
113
  lines.push('')
109
114
 
@@ -125,7 +130,7 @@ export class Bundler:
125
130
  for imp in mod.imports:
126
131
  val srcId = toModuleId(imp.absPath)
127
132
  for name in imp.names:
128
- val localName = name.alias ?? name.name
133
+ val localName = name.alias ?? name.name
129
134
  val importedName = name.name
130
135
  lines.push(' var ' + localName + ' = ' + srcId + '._exports ? ' + srcId + '._exports.' + importedName + ' : ' + srcId + '.' + importedName + ';')
131
136
 
@@ -1,23 +1,6 @@
1
- /* compiled from src/self/bundler.flux by Flux Lang */
1
+ /* compiled from src/self/bundler.flux */
2
2
  'use strict';
3
- // ── Flux stdlib ──
4
-
5
- function findIndex(arr, fn) { return arr.findIndex(fn); }
6
-
7
- function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
8
-
9
- function includes(arr, val) { return arr.includes(val); }
10
-
11
- function trim(s) { return String(s).trim(); }
12
-
13
- function startsWith(s, prefix) { return String(s).startsWith(prefix); }
14
-
15
- function endsWith(s, suffix) { return String(s).endsWith(suffix); }
16
-
17
- function repeat(s, n) { return String(s).repeat(n); }
18
- // ── end stdlib ──
19
-
20
- // Generated by Flux Transpiler v3.2.0
3
+ // Generated by Flux Transpiler v3.5.3 (self-hosted)
21
4
  "use strict";
22
5
 
23
6
  const Fs = require("fs");