@fluixi/compiler 1.0.0-alpha.100
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/LICENSE +21 -0
- package/README.md +131 -0
- package/dist/analyze/expr-shape.cjs +62 -0
- package/dist/analyze/expr-shape.d.cts +14 -0
- package/dist/analyze/expr-shape.d.ts +15 -0
- package/dist/analyze/expr-shape.d.ts.map +1 -0
- package/dist/analyze/expr-shape.js +37 -0
- package/dist/analyze/expr-shape.mjs +41 -0
- package/dist/analyze/intrinsics.cjs +112 -0
- package/dist/analyze/intrinsics.d.cts +80 -0
- package/dist/analyze/intrinsics.d.ts +81 -0
- package/dist/analyze/intrinsics.d.ts.map +1 -0
- package/dist/analyze/intrinsics.js +126 -0
- package/dist/analyze/intrinsics.mjs +91 -0
- package/dist/analyze/paren.cjs +134 -0
- package/dist/analyze/paren.d.cts +23 -0
- package/dist/analyze/paren.d.ts +24 -0
- package/dist/analyze/paren.d.ts.map +1 -0
- package/dist/analyze/paren.js +168 -0
- package/dist/analyze/paren.mjs +113 -0
- package/dist/analyze/props-destructure.cjs +226 -0
- package/dist/analyze/props-destructure.d.cts +83 -0
- package/dist/analyze/props-destructure.d.ts +84 -0
- package/dist/analyze/props-destructure.d.ts.map +1 -0
- package/dist/analyze/props-destructure.js +272 -0
- package/dist/analyze/props-destructure.mjs +205 -0
- package/dist/analyze/reactive-bindings.cjs +210 -0
- package/dist/analyze/reactive-bindings.d.cts +42 -0
- package/dist/analyze/reactive-bindings.d.ts +43 -0
- package/dist/analyze/reactive-bindings.d.ts.map +1 -0
- package/dist/analyze/reactive-bindings.js +191 -0
- package/dist/analyze/reactive-bindings.mjs +187 -0
- package/dist/analyze/reactive-expr.cjs +38 -0
- package/dist/analyze/reactive-expr.d.cts +38 -0
- package/dist/analyze/reactive-expr.d.ts +39 -0
- package/dist/analyze/reactive-expr.d.ts.map +1 -0
- package/dist/analyze/reactive-expr.js +31 -0
- package/dist/analyze/reactive-expr.mjs +17 -0
- package/dist/analyze/static-graph.cjs +831 -0
- package/dist/analyze/static-graph.d.cts +102 -0
- package/dist/analyze/static-graph.d.ts +103 -0
- package/dist/analyze/static-graph.d.ts.map +1 -0
- package/dist/analyze/static-graph.js +871 -0
- package/dist/analyze/static-graph.mjs +813 -0
- package/dist/babel-I6BUWUCU.mjs +636 -0
- package/dist/chunk-3AICWNF7.mjs +92 -0
- package/dist/chunk-6CWJWGE2.mjs +2170 -0
- package/dist/chunk-C3XPDB4Y.mjs +16 -0
- package/dist/chunk-GX5XV6Z7.mjs +190 -0
- package/dist/chunk-HXEXPWJ2.mjs +999 -0
- package/dist/chunk-NU3W67UZ.mjs +584 -0
- package/dist/chunk-SKAVY75W.mjs +11 -0
- package/dist/codegen/backend.cjs +18 -0
- package/dist/codegen/backend.d.cts +35 -0
- package/dist/codegen/backend.d.ts +36 -0
- package/dist/codegen/backend.d.ts.map +1 -0
- package/dist/codegen/backend.js +1 -0
- package/dist/codegen/backend.mjs +0 -0
- package/dist/codegen/backends/imperative.cjs +577 -0
- package/dist/codegen/backends/imperative.d.cts +11 -0
- package/dist/codegen/backends/imperative.d.ts +12 -0
- package/dist/codegen/backends/imperative.d.ts.map +1 -0
- package/dist/codegen/backends/imperative.js +362 -0
- package/dist/codegen/backends/imperative.mjs +554 -0
- package/dist/codegen/contract.cjs +52 -0
- package/dist/codegen/contract.d.cts +24 -0
- package/dist/codegen/contract.d.ts +25 -0
- package/dist/codegen/contract.d.ts.map +1 -0
- package/dist/codegen/contract.js +30 -0
- package/dist/codegen/contract.mjs +31 -0
- package/dist/codegen/partial-template.cjs +176 -0
- package/dist/codegen/partial-template.d.cts +61 -0
- package/dist/codegen/partial-template.d.ts +62 -0
- package/dist/codegen/partial-template.d.ts.map +1 -0
- package/dist/codegen/partial-template.js +0 -0
- package/dist/codegen/partial-template.mjs +153 -0
- package/dist/codegen/serialize-static.cjs +125 -0
- package/dist/codegen/serialize-static.d.cts +38 -0
- package/dist/codegen/serialize-static.d.ts +39 -0
- package/dist/codegen/serialize-static.d.ts.map +1 -0
- package/dist/codegen/serialize-static.js +165 -0
- package/dist/codegen/serialize-static.mjs +104 -0
- package/dist/frontend/babel/build-ir-lit.cjs +1933 -0
- package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
- package/dist/frontend/babel/build-ir-lit.d.ts +27 -0
- package/dist/frontend/babel/build-ir-lit.d.ts.map +1 -0
- package/dist/frontend/babel/build-ir-lit.js +13 -0
- package/dist/frontend/babel/build-ir-lit.mjs +1902 -0
- package/dist/frontend/babel/build-ir.cjs +1948 -0
- package/dist/frontend/babel/build-ir.d.cts +35 -0
- package/dist/frontend/babel/build-ir.d.ts +36 -0
- package/dist/frontend/babel/build-ir.d.ts.map +1 -0
- package/dist/frontend/babel/build-ir.js +124 -0
- package/dist/frontend/babel/build-ir.mjs +1919 -0
- package/dist/frontend/babel/index.cjs +2610 -0
- package/dist/frontend/babel/index.d.cts +33 -0
- package/dist/frontend/babel/index.d.ts +34 -0
- package/dist/frontend/babel/index.d.ts.map +1 -0
- package/dist/frontend/babel/index.js +65 -0
- package/dist/frontend/babel/index.mjs +2580 -0
- package/dist/frontend/babel/lower-template.cjs +1931 -0
- package/dist/frontend/babel/lower-template.d.cts +23 -0
- package/dist/frontend/babel/lower-template.d.ts +24 -0
- package/dist/frontend/babel/lower-template.d.ts.map +1 -0
- package/dist/frontend/babel/lower-template.js +64 -0
- package/dist/frontend/babel/lower-template.mjs +1902 -0
- package/dist/frontend/babel/plugin.cjs +2556 -0
- package/dist/frontend/babel/plugin.d.cts +95 -0
- package/dist/frontend/babel/plugin.d.ts +96 -0
- package/dist/frontend/babel/plugin.d.ts.map +1 -0
- package/dist/frontend/babel/plugin.js +523 -0
- package/dist/frontend/babel/plugin.mjs +2527 -0
- package/dist/frontend/babel/server-functions.cjs +110 -0
- package/dist/frontend/babel/server-functions.d.cts +10 -0
- package/dist/frontend/babel/server-functions.d.ts +11 -0
- package/dist/frontend/babel/server-functions.d.ts.map +1 -0
- package/dist/frontend/babel/server-functions.js +81 -0
- package/dist/frontend/babel/server-functions.mjs +89 -0
- package/dist/frontend/babel/types.cjs +18 -0
- package/dist/frontend/babel/types.d.cts +33 -0
- package/dist/frontend/babel/types.d.ts +34 -0
- package/dist/frontend/babel/types.d.ts.map +1 -0
- package/dist/frontend/babel/types.js +1 -0
- package/dist/frontend/babel/types.mjs +0 -0
- package/dist/frontend/types.cjs +18 -0
- package/dist/frontend/types.d.cts +25 -0
- package/dist/frontend/types.d.ts +26 -0
- package/dist/frontend/types.d.ts.map +1 -0
- package/dist/frontend/types.js +1 -0
- package/dist/frontend/types.mjs +0 -0
- package/dist/frontend/vocabulary.cjs +98 -0
- package/dist/frontend/vocabulary.d.cts +79 -0
- package/dist/frontend/vocabulary.d.ts +80 -0
- package/dist/frontend/vocabulary.d.ts.map +1 -0
- package/dist/frontend/vocabulary.js +124 -0
- package/dist/frontend/vocabulary.mjs +77 -0
- package/dist/index.cjs +1957 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.mjs +1949 -0
- package/dist/integrations.cjs +5705 -0
- package/dist/integrations.d.cts +215 -0
- package/dist/integrations.d.ts +216 -0
- package/dist/integrations.d.ts.map +1 -0
- package/dist/integrations.js +566 -0
- package/dist/integrations.mjs +810 -0
- package/dist/ir/nodes.cjs +18 -0
- package/dist/ir/nodes.d.cts +168 -0
- package/dist/ir/nodes.d.ts +169 -0
- package/dist/ir/nodes.d.ts.map +1 -0
- package/dist/ir/nodes.js +1 -0
- package/dist/ir/nodes.mjs +0 -0
- package/dist/lower/compile-template.cjs +1670 -0
- package/dist/lower/compile-template.d.cts +82 -0
- package/dist/lower/compile-template.d.ts +83 -0
- package/dist/lower/compile-template.d.ts.map +1 -0
- package/dist/lower/compile-template.js +79 -0
- package/dist/lower/compile-template.mjs +1662 -0
- package/dist/lower/entities.cjs +288 -0
- package/dist/lower/entities.d.cts +1 -0
- package/dist/lower/entities.d.ts +2 -0
- package/dist/lower/entities.d.ts.map +1 -0
- package/dist/lower/entities.js +54 -0
- package/dist/lower/entities.mjs +267 -0
- package/dist/lower/jsx.cjs +1101 -0
- package/dist/lower/jsx.d.cts +33 -0
- package/dist/lower/jsx.d.ts +34 -0
- package/dist/lower/jsx.d.ts.map +1 -0
- package/dist/lower/jsx.js +414 -0
- package/dist/lower/jsx.mjs +1078 -0
- package/dist/lower/template.cjs +1354 -0
- package/dist/lower/template.d.cts +53 -0
- package/dist/lower/template.d.ts +54 -0
- package/dist/lower/template.d.ts.map +1 -0
- package/dist/lower/template.js +542 -0
- package/dist/lower/template.mjs +1335 -0
- package/dist/lower/text.cjs +42 -0
- package/dist/lower/text.d.cts +10 -0
- package/dist/lower/text.d.ts +11 -0
- package/dist/lower/text.d.ts.map +1 -0
- package/dist/lower/text.js +31 -0
- package/dist/lower/text.mjs +21 -0
- package/dist/optimize/analyze-static.cjs +112 -0
- package/dist/optimize/analyze-static.d.cts +39 -0
- package/dist/optimize/analyze-static.d.ts +40 -0
- package/dist/optimize/analyze-static.d.ts.map +1 -0
- package/dist/optimize/analyze-static.js +131 -0
- package/dist/optimize/analyze-static.mjs +91 -0
- package/dist/optimize/collapse-strategies.cjs +90 -0
- package/dist/optimize/collapse-strategies.d.cts +30 -0
- package/dist/optimize/collapse-strategies.d.ts +31 -0
- package/dist/optimize/collapse-strategies.d.ts.map +1 -0
- package/dist/optimize/collapse-strategies.js +33 -0
- package/dist/optimize/collapse-strategies.mjs +67 -0
- package/dist/options.cjs +33 -0
- package/dist/options.d.cts +39 -0
- package/dist/options.d.ts +40 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +8 -0
- package/dist/options.mjs +12 -0
- package/dist/resolve/builtins.cjs +73 -0
- package/dist/resolve/builtins.d.cts +68 -0
- package/dist/resolve/builtins.d.ts +69 -0
- package/dist/resolve/builtins.d.ts.map +1 -0
- package/dist/resolve/builtins.js +64 -0
- package/dist/resolve/builtins.mjs +53 -0
- package/dist/resolve/component-globals.cjs +272 -0
- package/dist/resolve/component-globals.d.cts +88 -0
- package/dist/resolve/component-globals.d.ts +89 -0
- package/dist/resolve/component-globals.d.ts.map +1 -0
- package/dist/resolve/component-globals.js +160 -0
- package/dist/resolve/component-globals.mjs +249 -0
- package/dist/resolve/component-resolver.cjs +80 -0
- package/dist/resolve/component-resolver.d.cts +68 -0
- package/dist/resolve/component-resolver.d.ts +69 -0
- package/dist/resolve/component-resolver.d.ts.map +1 -0
- package/dist/resolve/component-resolver.js +95 -0
- package/dist/resolve/component-resolver.mjs +59 -0
- package/dist/resolve/load-directive.cjs +93 -0
- package/dist/resolve/load-directive.d.cts +53 -0
- package/dist/resolve/load-directive.d.ts +54 -0
- package/dist/resolve/load-directive.d.ts.map +1 -0
- package/dist/resolve/load-directive.js +93 -0
- package/dist/resolve/load-directive.mjs +72 -0
- package/dist/resolve/resolve-ir.cjs +108 -0
- package/dist/resolve/resolve-ir.d.cts +53 -0
- package/dist/resolve/resolve-ir.d.ts +54 -0
- package/dist/resolve/resolve-ir.d.ts.map +1 -0
- package/dist/resolve/resolve-ir.js +58 -0
- package/dist/resolve/resolve-ir.mjs +85 -0
- package/dist/resolve/write-globals.cjs +383 -0
- package/dist/resolve/write-globals.d.cts +36 -0
- package/dist/resolve/write-globals.d.ts +37 -0
- package/dist/resolve/write-globals.d.ts.map +1 -0
- package/dist/resolve/write-globals.js +169 -0
- package/dist/resolve/write-globals.mjs +362 -0
- package/dist/server-fns-VZLHMQTC.mjs +79 -0
- package/dist/server-functions-UAZKOLZW.mjs +82 -0
- package/dist/transform/bindings.cjs +71 -0
- package/dist/transform/bindings.d.cts +16 -0
- package/dist/transform/bindings.d.ts +17 -0
- package/dist/transform/bindings.d.ts.map +1 -0
- package/dist/transform/bindings.js +69 -0
- package/dist/transform/bindings.mjs +50 -0
- package/dist/transform/index.cjs +3837 -0
- package/dist/transform/index.d.cts +15 -0
- package/dist/transform/index.d.ts +16 -0
- package/dist/transform/index.d.ts.map +1 -0
- package/dist/transform/index.js +12 -0
- package/dist/transform/index.mjs +4882 -0
- package/dist/transform/intrinsics.cjs +261 -0
- package/dist/transform/intrinsics.d.cts +33 -0
- package/dist/transform/intrinsics.d.ts +34 -0
- package/dist/transform/intrinsics.d.ts.map +1 -0
- package/dist/transform/intrinsics.js +120 -0
- package/dist/transform/intrinsics.mjs +238 -0
- package/dist/transform/props.cjs +441 -0
- package/dist/transform/props.d.cts +45 -0
- package/dist/transform/props.d.ts +46 -0
- package/dist/transform/props.d.ts.map +1 -0
- package/dist/transform/props.js +221 -0
- package/dist/transform/props.mjs +1487 -0
- package/dist/transform/server-fn-id.cjs +35 -0
- package/dist/transform/server-fn-id.d.cts +9 -0
- package/dist/transform/server-fn-id.d.ts +10 -0
- package/dist/transform/server-fn-id.d.ts.map +1 -0
- package/dist/transform/server-fn-id.js +18 -0
- package/dist/transform/server-fn-id.mjs +14 -0
- package/dist/transform/server-fns.cjs +114 -0
- package/dist/transform/server-fns.d.cts +12 -0
- package/dist/transform/server-fns.d.ts +13 -0
- package/dist/transform/server-fns.d.ts.map +1 -0
- package/dist/transform/server-fns.js +94 -0
- package/dist/transform/server-fns.mjs +1160 -0
- package/dist/transform/source-locations.cjs +393 -0
- package/dist/transform/source-locations.d.cts +48 -0
- package/dist/transform/source-locations.d.ts +49 -0
- package/dist/transform/source-locations.d.ts.map +1 -0
- package/dist/transform/source-locations.js +303 -0
- package/dist/transform/source-locations.mjs +370 -0
- package/dist/transform/styles.cjs +606 -0
- package/dist/transform/styles.d.cts +237 -0
- package/dist/transform/styles.d.ts +238 -0
- package/dist/transform/styles.d.ts.map +1 -0
- package/dist/transform/styles.js +743 -0
- package/dist/transform/styles.mjs +671 -0
- package/dist/transform/templates.cjs +3806 -0
- package/dist/transform/templates.d.cts +82 -0
- package/dist/transform/templates.d.ts +83 -0
- package/dist/transform/templates.d.ts.map +1 -0
- package/dist/transform/templates.js +613 -0
- package/dist/transform/templates.mjs +4852 -0
- package/dist/transform-3W45L3EA.mjs +951 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/dist/vite-styles.cjs +223 -0
- package/dist/vite-styles.d.cts +68 -0
- package/dist/vite-styles.d.ts +69 -0
- package/dist/vite-styles.d.ts.map +1 -0
- package/dist/vite-styles.js +241 -0
- package/dist/vite-styles.mjs +214 -0
- package/package.json +141 -0
|
@@ -0,0 +1,810 @@
|
|
|
1
|
+
/*! @fluixi/compiler v1.0.0-alpha.100 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
import {
|
|
3
|
+
styleIds
|
|
4
|
+
} from "./chunk-NU3W67UZ.mjs";
|
|
5
|
+
import {
|
|
6
|
+
INTRINSICS,
|
|
7
|
+
TAG_INTRINSICS,
|
|
8
|
+
builtinComponentMap,
|
|
9
|
+
createComponentResolver
|
|
10
|
+
} from "./chunk-GX5XV6Z7.mjs";
|
|
11
|
+
import "./chunk-3AICWNF7.mjs";
|
|
12
|
+
import {
|
|
13
|
+
__require
|
|
14
|
+
} from "./chunk-SKAVY75W.mjs";
|
|
15
|
+
|
|
16
|
+
// src/resolve/write-globals.ts
|
|
17
|
+
import { mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { basename, dirname, relative, sep, resolve as resolvePath } from "node:path";
|
|
19
|
+
|
|
20
|
+
// src/resolve/component-globals.ts
|
|
21
|
+
var DOM_GLOBALS = /* @__PURE__ */ new Set([
|
|
22
|
+
"Text",
|
|
23
|
+
"Image",
|
|
24
|
+
"Option",
|
|
25
|
+
"Audio",
|
|
26
|
+
"Comment",
|
|
27
|
+
"Range",
|
|
28
|
+
"Selection",
|
|
29
|
+
"Notification",
|
|
30
|
+
"Event",
|
|
31
|
+
"Document",
|
|
32
|
+
"Element",
|
|
33
|
+
"Node",
|
|
34
|
+
"Screen",
|
|
35
|
+
"Window",
|
|
36
|
+
"Location",
|
|
37
|
+
"History",
|
|
38
|
+
"Storage",
|
|
39
|
+
"Response",
|
|
40
|
+
"Request",
|
|
41
|
+
"Headers"
|
|
42
|
+
]);
|
|
43
|
+
function packageOf(specifier) {
|
|
44
|
+
if (specifier.startsWith(".") || specifier.startsWith("/")) return void 0;
|
|
45
|
+
if (/^[~@]\//.test(specifier)) return void 0;
|
|
46
|
+
const parts = specifier.split("/");
|
|
47
|
+
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
48
|
+
}
|
|
49
|
+
function namespaceAlias(module) {
|
|
50
|
+
return `_${module.replace(/[^A-Za-z0-9]/g, "_")}`;
|
|
51
|
+
}
|
|
52
|
+
function componentGlobals(rules, options = {}) {
|
|
53
|
+
const {
|
|
54
|
+
available: availableList,
|
|
55
|
+
builtins = true,
|
|
56
|
+
intrinsics = true,
|
|
57
|
+
generator = "@fluixi/compiler",
|
|
58
|
+
specifier = (module) => module,
|
|
59
|
+
candidates = []
|
|
60
|
+
} = options;
|
|
61
|
+
const all = [...rules];
|
|
62
|
+
if (builtins) {
|
|
63
|
+
all.push({ components: builtinComponentMap() });
|
|
64
|
+
}
|
|
65
|
+
const resolver = createComponentResolver(all);
|
|
66
|
+
const available = availableList ? new Set(availableList) : void 0;
|
|
67
|
+
const declared = [];
|
|
68
|
+
const shadowedByDom = [];
|
|
69
|
+
const unavailable = [];
|
|
70
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
71
|
+
const names = /* @__PURE__ */ new Set([...resolver.names(), ...[...candidates].filter((n) => /^[A-Za-z_$][\w$]*$/.test(n))]);
|
|
72
|
+
for (const name of [...names].sort()) {
|
|
73
|
+
const target = resolver.resolve(name);
|
|
74
|
+
if (!target) continue;
|
|
75
|
+
const pkg = packageOf(target.module);
|
|
76
|
+
if (DOM_GLOBALS.has(name)) shadowedByDom.push(name);
|
|
77
|
+
else if (available && pkg && !available.has(pkg)) unavailable.push(name);
|
|
78
|
+
else {
|
|
79
|
+
declared.push(name);
|
|
80
|
+
resolved.set(name, target);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const usableIntrinsics = intrinsics ? Object.entries({ ...INTRINSICS, ...TAG_INTRINSICS }).filter(([, i]) => {
|
|
84
|
+
const pkg = packageOf(i.module);
|
|
85
|
+
return !available || !pkg || available.has(pkg);
|
|
86
|
+
}) : [];
|
|
87
|
+
const intrinsicModules = [...new Set(usableIntrinsics.map(([, i]) => i.module))];
|
|
88
|
+
const modules = [
|
|
89
|
+
.../* @__PURE__ */ new Set([...declared.map((name) => resolved.get(name).module), ...intrinsicModules])
|
|
90
|
+
].sort();
|
|
91
|
+
const imports = modules.map(
|
|
92
|
+
(m) => `import * as ${namespaceAlias(m)} from '${specifier(m)}';`
|
|
93
|
+
);
|
|
94
|
+
const lines = declared.map((name) => {
|
|
95
|
+
const target = resolved.get(name);
|
|
96
|
+
const ns = namespaceAlias(target.module);
|
|
97
|
+
return target.export === "default" ? ` const ${name}: typeof ${ns}.default;` : ` export import ${name} = ${ns}.${target.export};`;
|
|
98
|
+
});
|
|
99
|
+
const note = shadowedByDom.length > 0 ? `//
|
|
100
|
+
// Import these explicitly: lib.dom already declares the name, so an ambient
|
|
101
|
+
// declaration cannot win:
|
|
102
|
+
` + shadowedByDom.map((n) => {
|
|
103
|
+
const module = resolver.resolve(n)?.module;
|
|
104
|
+
return `// import { ${n} } from '${module ? specifier(module) : ""}';
|
|
105
|
+
`;
|
|
106
|
+
}).join("") : "";
|
|
107
|
+
const intrinsicLines = usableIntrinsics.map(
|
|
108
|
+
([name, intrinsic]) => ` const ${name}: typeof ${namespaceAlias(intrinsic.module)}.${intrinsic.export};`
|
|
109
|
+
);
|
|
110
|
+
const patternRules = rules.filter((rule) => "match" in rule).length;
|
|
111
|
+
const patternNote = patternRules === 0 ? "" : options.candidates ? `//
|
|
112
|
+
// ${patternRules} pattern rule${patternRules === 1 ? "" : "s"}: declared for the files the module path
|
|
113
|
+
// points at. A name with no such file still resolves at build time; declare it by hand.
|
|
114
|
+
` : `//
|
|
115
|
+
// ${patternRules} pattern rule${patternRules === 1 ? "" : "s"} cannot be declared:
|
|
116
|
+
// a pattern matches unboundedly many names, so there is no list to emit. Those
|
|
117
|
+
// tags still resolve at build time; declare them by hand if the editor needs them.
|
|
118
|
+
`;
|
|
119
|
+
const source = `// GENERATED by ${generator}, do not edit.
|
|
120
|
+
//
|
|
121
|
+
// The components \`resolve\` supplies without an import. This describes what the
|
|
122
|
+
// compiler already does; it does not enable it.
|
|
123
|
+
` + note + patternNote + (imports.length > 0 ? `
|
|
124
|
+
${imports.join("\n")}
|
|
125
|
+
` : "\n") + `
|
|
126
|
+
declare global {
|
|
127
|
+
${[...lines, ...intrinsicLines].join("\n")}
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
return { source, declared, shadowedByDom, unavailable, patternRules };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/resolve/write-globals.ts
|
|
134
|
+
var GENERATED_MARKER = "GENERATED by @fluixi/compiler";
|
|
135
|
+
var DEFAULT_GLOBALS_PATH = "fluixi.d.ts";
|
|
136
|
+
function coveredByInclude(root, target) {
|
|
137
|
+
let config;
|
|
138
|
+
try {
|
|
139
|
+
const raw = readFileSync(resolvePath(root, "tsconfig.json"), "utf8");
|
|
140
|
+
config = JSON.parse(raw.replace(/^\s*\/\/.*$/gm, ""));
|
|
141
|
+
} catch {
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
if (config.extends !== void 0) return void 0;
|
|
145
|
+
if (!Array.isArray(config.include)) return true;
|
|
146
|
+
const relative3 = relativePosix(root, target);
|
|
147
|
+
return config.include.some((entry) => {
|
|
148
|
+
if (typeof entry !== "string") return false;
|
|
149
|
+
const pattern = entry.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, "(?:.*/)?").replace(/\*/g, "[^/]*");
|
|
150
|
+
return new RegExp(`^${pattern}(?:/.*)?$`).test(relative3);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function relativePosix(from, to) {
|
|
154
|
+
return relative(from, to).split(sep).join("/");
|
|
155
|
+
}
|
|
156
|
+
function forTypeScript(module, outDir, root) {
|
|
157
|
+
if (!module.startsWith("/")) return module;
|
|
158
|
+
const absolute = resolvePath(root, module.slice(1));
|
|
159
|
+
let rel = relative(outDir, absolute).split(sep).join("/");
|
|
160
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
161
|
+
return rel.replace(/\.(tsx|ts|jsx|mts|cts)$/, ".js");
|
|
162
|
+
}
|
|
163
|
+
function projectDependencies(root) {
|
|
164
|
+
try {
|
|
165
|
+
const manifest = JSON.parse(readFileSync(resolvePath(root, "package.json"), "utf8"));
|
|
166
|
+
return [
|
|
167
|
+
...Object.keys(manifest.dependencies ?? {}),
|
|
168
|
+
...Object.keys(manifest.devDependencies ?? {}),
|
|
169
|
+
...Object.keys(manifest.peerDependencies ?? {})
|
|
170
|
+
];
|
|
171
|
+
} catch {
|
|
172
|
+
return void 0;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function patternCandidates(rules, root) {
|
|
176
|
+
const out = [];
|
|
177
|
+
for (const rule of rules) {
|
|
178
|
+
if (!("match" in rule) || !rule.module.startsWith("/")) continue;
|
|
179
|
+
const dir = dirname(rule.module);
|
|
180
|
+
const file = basename(rule.module);
|
|
181
|
+
const group = file.match(/\$\d+/);
|
|
182
|
+
if (dir.includes("$") || !group || file.indexOf("$", group.index + 1) !== -1) continue;
|
|
183
|
+
const before = file.slice(0, group.index);
|
|
184
|
+
const after = file.slice(group.index + group[0].length);
|
|
185
|
+
let entries;
|
|
186
|
+
try {
|
|
187
|
+
entries = readdirSync(resolvePath(root, dir.slice(1)));
|
|
188
|
+
} catch {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
for (const entry of entries) {
|
|
192
|
+
if (entry.length > before.length + after.length && entry.startsWith(before) && entry.endsWith(after)) {
|
|
193
|
+
out.push(entry.slice(before.length, entry.length - after.length));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
function writeComponentGlobals(options, root) {
|
|
200
|
+
if (options.globals === false) return { status: "skipped", reason: "disabled" };
|
|
201
|
+
const rules = options.resolve ?? [];
|
|
202
|
+
const target = resolvePath(root, options.globals ?? DEFAULT_GLOBALS_PATH);
|
|
203
|
+
let existing;
|
|
204
|
+
try {
|
|
205
|
+
existing = readFileSync(target, "utf8");
|
|
206
|
+
} catch {
|
|
207
|
+
existing = void 0;
|
|
208
|
+
}
|
|
209
|
+
if (existing !== void 0 && !existing.includes(GENERATED_MARKER)) {
|
|
210
|
+
return { status: "skipped", reason: "foreign-file", path: target };
|
|
211
|
+
}
|
|
212
|
+
const { source, declared } = componentGlobals(rules, {
|
|
213
|
+
available: projectDependencies(root),
|
|
214
|
+
candidates: patternCandidates(rules, root),
|
|
215
|
+
specifier: (module) => forTypeScript(module, dirname(target), root)
|
|
216
|
+
});
|
|
217
|
+
if (existing === source) {
|
|
218
|
+
return {
|
|
219
|
+
status: "unchanged",
|
|
220
|
+
path: target,
|
|
221
|
+
declared: declared.length,
|
|
222
|
+
warning: warnIfUnreachable(root, target)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
226
|
+
writeFileSync(target, source);
|
|
227
|
+
return {
|
|
228
|
+
status: "written",
|
|
229
|
+
path: target,
|
|
230
|
+
declared: declared.length,
|
|
231
|
+
warning: warnIfUnreachable(root, target)
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function warnIfUnreachable(root, target) {
|
|
235
|
+
if (coveredByInclude(root, target) !== false) return void 0;
|
|
236
|
+
const relative3 = relativePosix(root, target);
|
|
237
|
+
return `[fluixi] ${relative3} is not covered by "include" in tsconfig.json, so TypeScript will ignore it and every resolved component stays "Cannot find name". Add "${relative3}" to "include".`;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/vite-styles.ts
|
|
241
|
+
import { existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
242
|
+
import { basename as basename2, dirname as dirname2, extname, join, relative as relative2 } from "node:path";
|
|
243
|
+
var STYLE_ID = /\.fx-(\d+)\.css(?:\?inline)?$/;
|
|
244
|
+
var LITERAL_ID = /\.fx-literal-([\w$]+)\.css\?inline$/;
|
|
245
|
+
var SUFFIX = /\.fx-(?:\d+|literal-[\w$]+)\.css(?:\?inline)?$/;
|
|
246
|
+
var styleId = styleIds.block;
|
|
247
|
+
function firstLoc(nodes) {
|
|
248
|
+
for (const node of nodes) {
|
|
249
|
+
if (node.loc) return node.loc.source;
|
|
250
|
+
if ((node.kind === "rule" || node.kind === "at-rule") && node.nodes.length) {
|
|
251
|
+
const inner = firstLoc(node.nodes);
|
|
252
|
+
if (inner) return inner;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return void 0;
|
|
256
|
+
}
|
|
257
|
+
var ownerOf = (id) => id.slice(0, id.search(SUFFIX));
|
|
258
|
+
var loader = (name) => `const href = new URL(${JSON.stringify(`./${name}`)}, import.meta.url).href;
|
|
259
|
+
if (typeof document !== 'undefined' && !document.querySelector(\`link[data-fx-css="\${href}"]\`)) {
|
|
260
|
+
const link = document.createElement('link');
|
|
261
|
+
link.rel = 'stylesheet';
|
|
262
|
+
link.href = href;
|
|
263
|
+
link.dataset.fxCss = href;
|
|
264
|
+
document.head.appendChild(link);
|
|
265
|
+
}
|
|
266
|
+
`;
|
|
267
|
+
function createComponentStyles(compile) {
|
|
268
|
+
let api;
|
|
269
|
+
let server;
|
|
270
|
+
let root = process.cwd();
|
|
271
|
+
let library;
|
|
272
|
+
const emitted = /* @__PURE__ */ new Map();
|
|
273
|
+
const fileOf = (id) => existsSync(id) ? id : join(root, id);
|
|
274
|
+
const cache = /* @__PURE__ */ new Map();
|
|
275
|
+
const resolveReference = async (ref, importer, ctx, seen, modules) => {
|
|
276
|
+
const resolved = await ctx.resolve?.(ref.source, importer);
|
|
277
|
+
if (!resolved) return null;
|
|
278
|
+
const file = resolved.id.split("?")[0];
|
|
279
|
+
if (seen.has(file)) return null;
|
|
280
|
+
let code;
|
|
281
|
+
try {
|
|
282
|
+
code = readFileSync2(fileOf(file), "utf8");
|
|
283
|
+
} catch {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
const styles = api.styles(file);
|
|
287
|
+
let result = compile(code, file, styles);
|
|
288
|
+
if (result?.styleReferences?.length) {
|
|
289
|
+
const imported = await resolveAll(result.styleReferences, file, ctx, /* @__PURE__ */ new Set([...seen, file]), modules);
|
|
290
|
+
result = compile(code, file, { ...styles, imported, importedModules: modules });
|
|
291
|
+
}
|
|
292
|
+
const literal = result?.styleLiterals?.find((l) => l.name === ref.name);
|
|
293
|
+
if (!literal) return null;
|
|
294
|
+
const nodes = literal.nodes ?? styles.process(literal.css, file);
|
|
295
|
+
const named = firstLoc(nodes);
|
|
296
|
+
if (named) modules.set(named, { id: file, code });
|
|
297
|
+
return nodes;
|
|
298
|
+
};
|
|
299
|
+
const resolveAll = async (refs, importer, ctx, seen, modules) => {
|
|
300
|
+
const imported = /* @__PURE__ */ new Map();
|
|
301
|
+
for (const ref of refs) {
|
|
302
|
+
const nodes = await resolveReference(ref, importer, ctx, seen, modules);
|
|
303
|
+
if (nodes) imported.set(`${ref.source}#${ref.name}`, nodes);
|
|
304
|
+
}
|
|
305
|
+
return imported;
|
|
306
|
+
};
|
|
307
|
+
const run = async (code, id, ctx) => {
|
|
308
|
+
const file = fileOf(id);
|
|
309
|
+
const styles = api.styles(file);
|
|
310
|
+
let result = compile(code, file, styles);
|
|
311
|
+
if (result?.styleReferences?.length) {
|
|
312
|
+
const modules = /* @__PURE__ */ new Map();
|
|
313
|
+
const imported = await resolveAll(result.styleReferences, id, ctx, /* @__PURE__ */ new Set([file]), modules);
|
|
314
|
+
result = compile(code, file, { ...styles, imported, importedModules: modules });
|
|
315
|
+
}
|
|
316
|
+
const css = (result?.styles ?? []).map((s) => s.css);
|
|
317
|
+
const maps = (result?.styles ?? []).map((s) => s.map ?? null);
|
|
318
|
+
const literals = new Map((result?.styleLiterals ?? []).map((l) => [l.name, l.css]));
|
|
319
|
+
const before = cache.get(file);
|
|
320
|
+
cache.set(file, { source: code, css, maps, literals });
|
|
321
|
+
if (server && before) {
|
|
322
|
+
for (let i = 0; i < css.length; i++) {
|
|
323
|
+
if (before.css[i] === css[i]) continue;
|
|
324
|
+
const mod = server.moduleGraph.getModuleById(styleId(file, i));
|
|
325
|
+
if (mod) void server.reloadModule(mod);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const page = (result?.styles ?? []).flatMap((s, i) => s.shadow ? [] : [i]);
|
|
329
|
+
if (!result || page.length === 0) return result;
|
|
330
|
+
if (library) {
|
|
331
|
+
const name = `${basename2(file, extname(file))}.css`;
|
|
332
|
+
if (existsSync(join(dirname2(file), name))) {
|
|
333
|
+
throw new Error(`[fluixi] ${file} has <style> blocks, and ${name} next to it would be overwritten by their CSS. Rename one of them.`);
|
|
334
|
+
}
|
|
335
|
+
const out = join(relative2(library, dirname2(file)), name);
|
|
336
|
+
emitted.set(out, page.map((i) => css[i]).join("\n"));
|
|
337
|
+
emitted.set(`${out}.js`, loader(name));
|
|
338
|
+
return { ...result, code: `${result.code}
|
|
339
|
+
import ${JSON.stringify(`./${name}`)};` };
|
|
340
|
+
}
|
|
341
|
+
const imports = page.map((i) => `
|
|
342
|
+
import ${JSON.stringify(styleId(file, i))};`).join("");
|
|
343
|
+
return { ...result, code: result.code + imports };
|
|
344
|
+
};
|
|
345
|
+
return {
|
|
346
|
+
/** Looks for @fluixi-css/vite among the plugins; without it component styles stay off. */
|
|
347
|
+
connect(plugins, projectRoot) {
|
|
348
|
+
if (projectRoot) root = projectRoot;
|
|
349
|
+
api = (plugins ?? []).map((p) => p?.api?.fluixiCss).find((a) => Boolean(a));
|
|
350
|
+
api?.useComponentStyles();
|
|
351
|
+
},
|
|
352
|
+
/** Turns on library output, from the directory of a `build.lib` entry. */
|
|
353
|
+
setLibrary(entryDir) {
|
|
354
|
+
library = entryDir;
|
|
355
|
+
},
|
|
356
|
+
/** A library build's style import: left for the package's consumer to bundle. */
|
|
357
|
+
isLibraryImport(id, importer) {
|
|
358
|
+
if (library === void 0 || !importer || !id.startsWith("./") || !id.endsWith(".css")) return false;
|
|
359
|
+
return emitted.has(join(relative2(library, dirname2(fileOf(importer))), id));
|
|
360
|
+
},
|
|
361
|
+
/** The style files a library build writes, by path under the output directory. */
|
|
362
|
+
libraryFiles() {
|
|
363
|
+
return emitted;
|
|
364
|
+
},
|
|
365
|
+
get active() {
|
|
366
|
+
return api !== void 0;
|
|
367
|
+
},
|
|
368
|
+
setServer(dev) {
|
|
369
|
+
server = dev;
|
|
370
|
+
},
|
|
371
|
+
isStyle(id) {
|
|
372
|
+
return STYLE_ID.test(id) || LITERAL_ID.test(id);
|
|
373
|
+
},
|
|
374
|
+
/**
|
|
375
|
+
* A style request as the module id Vite keeps: its owner's absolute path, then the suffix.
|
|
376
|
+
* One id per block however it was asked for (`/src/card.tsx.fx-0.css` from a page, the
|
|
377
|
+
* absolute path from the component), or the reload after an edit misses the copy in use.
|
|
378
|
+
* A css`` value imported from another module names that module relatively, as written.
|
|
379
|
+
*/
|
|
380
|
+
async resolveId(id, importer, ctx) {
|
|
381
|
+
const at = id.search(SUFFIX);
|
|
382
|
+
const owner = id.slice(0, at);
|
|
383
|
+
if (!owner.startsWith(".")) return fileOf(owner) + id.slice(at);
|
|
384
|
+
const resolved = importer ? await ctx.resolve?.(owner, importer) : null;
|
|
385
|
+
return resolved ? resolved.id.split("?")[0] + id.slice(at) : null;
|
|
386
|
+
},
|
|
387
|
+
/**
|
|
388
|
+
* The style modules of a changed file, for the update Vite sends. Their ids do not name the
|
|
389
|
+
* file (they end in `.css`), so Vite would not find them itself.
|
|
390
|
+
*/
|
|
391
|
+
hotModules(file, graph) {
|
|
392
|
+
const entry = cache.get(file);
|
|
393
|
+
if (!entry) return [];
|
|
394
|
+
const paths = [
|
|
395
|
+
...entry.css.map((_, i) => styleId(file, i)),
|
|
396
|
+
...[...entry.literals.keys()].map((name) => styleIds.literal(file, name).replace(/\?inline$/, ""))
|
|
397
|
+
];
|
|
398
|
+
return paths.flatMap((path) => [...graph.getModulesByFile(path) ?? []]);
|
|
399
|
+
},
|
|
400
|
+
compile: run,
|
|
401
|
+
/**
|
|
402
|
+
* A block's CSS and its map back to the module, compiling the module again when the cache
|
|
403
|
+
* does not match the file.
|
|
404
|
+
*/
|
|
405
|
+
async load(id, ctx) {
|
|
406
|
+
const match = STYLE_ID.exec(id);
|
|
407
|
+
const literal = LITERAL_ID.exec(id);
|
|
408
|
+
if (!match && !literal || !api) return null;
|
|
409
|
+
const file = ownerOf(id);
|
|
410
|
+
let source;
|
|
411
|
+
try {
|
|
412
|
+
source = readFileSync2(fileOf(file), "utf8");
|
|
413
|
+
} catch {
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
if (cache.get(fileOf(file))?.source !== source) await run(source, file, ctx);
|
|
417
|
+
const entry = cache.get(fileOf(file));
|
|
418
|
+
if (literal) {
|
|
419
|
+
const css = entry?.literals.get(literal[1]);
|
|
420
|
+
if (css === void 0) throw new Error(`[fluixi] ${literal[1]} in ${file} is not a css\`\` value, so it cannot be a shadow root's styles.`);
|
|
421
|
+
return { code: css, map: null, moduleType: "css" };
|
|
422
|
+
}
|
|
423
|
+
const index = Number(match[1]);
|
|
424
|
+
return { code: entry?.css[index] ?? "", map: entry?.maps[index] ?? null, moduleType: "css" };
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// src/integrations.ts
|
|
430
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync3 } from "node:fs";
|
|
431
|
+
import { dirname as dirname3, join as _join, resolve as resolvePath2 } from "node:path";
|
|
432
|
+
async function createBabelPlugin(options = {}) {
|
|
433
|
+
let pluginModule = null;
|
|
434
|
+
try {
|
|
435
|
+
pluginModule = await import("./babel-I6BUWUCU.mjs");
|
|
436
|
+
} catch (e) {
|
|
437
|
+
console.warn("Could not load the babel front-end:", e);
|
|
438
|
+
}
|
|
439
|
+
return {
|
|
440
|
+
name: "babel-fluixi-jsx",
|
|
441
|
+
plugin: pluginModule ? pluginModule.default || pluginModule : null,
|
|
442
|
+
// Provide options mapping
|
|
443
|
+
getOptions() {
|
|
444
|
+
return {
|
|
445
|
+
importSource: options.importSource || "@fluixi/jsx",
|
|
446
|
+
development: options.development || false,
|
|
447
|
+
delegateEvents: options.delegateEvents !== false,
|
|
448
|
+
...options.format ? { format: options.format } : {},
|
|
449
|
+
// Forwarded explicitly: getOptions() is an allowlist, so an option missing
|
|
450
|
+
// here is silently dropped rather than rejected.
|
|
451
|
+
...options.resolve ? { resolve: options.resolve } : {},
|
|
452
|
+
...options.templateClone !== void 0 ? { templateClone: options.templateClone } : {},
|
|
453
|
+
...options.partialTemplates !== void 0 ? { partialTemplates: options.partialTemplates } : {},
|
|
454
|
+
...options.litTag ? { litTag: options.litTag } : {},
|
|
455
|
+
...options.signalModule ? { signalModule: options.signalModule } : {},
|
|
456
|
+
...options.controlFlowModule ? { controlFlowModule: options.controlFlowModule } : {},
|
|
457
|
+
...options.routerModule ? { routerModule: options.routerModule } : {},
|
|
458
|
+
...options.reactiveModule ? { reactiveModule: options.reactiveModule } : {}
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function createTypeScriptTransformer(options = {}) {
|
|
464
|
+
const ts = tryRequire("typescript");
|
|
465
|
+
if (!ts) {
|
|
466
|
+
console.warn("TypeScript not found, transformer unavailable");
|
|
467
|
+
return (context) => (sourceFile) => sourceFile;
|
|
468
|
+
}
|
|
469
|
+
return (context) => {
|
|
470
|
+
const visitor = (node) => {
|
|
471
|
+
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
472
|
+
return transformTSJSXNode(node, options, ts);
|
|
473
|
+
}
|
|
474
|
+
return ts.visitEachChild(node, visitor, context);
|
|
475
|
+
};
|
|
476
|
+
return (sourceFile) => {
|
|
477
|
+
return ts.visitNode(sourceFile, visitor);
|
|
478
|
+
};
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
function transformTSJSXNode(node, options, ts) {
|
|
482
|
+
return node;
|
|
483
|
+
}
|
|
484
|
+
function tryRequire(moduleName) {
|
|
485
|
+
try {
|
|
486
|
+
return __require(moduleName);
|
|
487
|
+
} catch (e) {
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
var RETIRED_SUBPATHS = {
|
|
492
|
+
"@fluixi/core/router-next": "is now @fluixi/core/router",
|
|
493
|
+
"@fluixi/core/rx": "is gone — import signals and effects from @fluixi/reactive, or the server primitives it resolved to under node from @fluixi/core/server"
|
|
494
|
+
};
|
|
495
|
+
function createVitePlugin(options = {}) {
|
|
496
|
+
let transformTemplates;
|
|
497
|
+
let projectRoot = process.cwd();
|
|
498
|
+
const componentStyles = createComponentStyles((code, id, styles) => {
|
|
499
|
+
return transformTemplates(code, id, { ...transformOptions(options, id), sourceRoot: projectRoot, styles });
|
|
500
|
+
});
|
|
501
|
+
return {
|
|
502
|
+
name: "vite-fluixi-jsx",
|
|
503
|
+
enforce: "pre",
|
|
504
|
+
// JSX the compiler leaves alone goes to Vite's own transform: Oxc in Vite 8 (Rolldown),
|
|
505
|
+
// esbuild before, which Vite 8 warns about.
|
|
506
|
+
// In dev, CSS maps are on unless the app says otherwise, so devtools show the line a
|
|
507
|
+
// component's rule was written on. Vite leaves them off by default; a build never has them.
|
|
508
|
+
config(user) {
|
|
509
|
+
const importSource = options.importSource || "@fluixi/jsx";
|
|
510
|
+
const jsx = this && this.meta?.rolldownVersion ? { oxc: { jsx: { runtime: "automatic", importSource } } } : { esbuild: { jsx: "automatic", jsxImportSource: importSource } };
|
|
511
|
+
return user?.css?.devSourcemap === void 0 ? { ...jsx, css: { devSourcemap: true } } : jsx;
|
|
512
|
+
},
|
|
513
|
+
// Written once per build, and on dev-server start, rather than per transform: the
|
|
514
|
+
// set of resolvable names comes from config, so nothing a file does can change it.
|
|
515
|
+
async configResolved(config) {
|
|
516
|
+
const outcome = writeComponentGlobals(options, config?.root ?? process.cwd());
|
|
517
|
+
if (outcome.warning) console.warn(outcome.warning);
|
|
518
|
+
if (options.babel) return;
|
|
519
|
+
projectRoot = config?.root ?? projectRoot;
|
|
520
|
+
componentStyles.connect(config?.plugins, config?.root);
|
|
521
|
+
const entry = config?.command === "build" && config.build?.lib ? config.build.lib.entry : void 0;
|
|
522
|
+
const first = typeof entry === "string" ? entry : Array.isArray(entry) ? entry[0] : entry && typeof entry === "object" ? Object.values(entry)[0] : void 0;
|
|
523
|
+
if (typeof first === "string") componentStyles.setLibrary(dirname3(resolvePath2(config.root ?? process.cwd(), first)));
|
|
524
|
+
if (componentStyles.active) ({ transformTemplates } = await import("./transform-3W45L3EA.mjs"));
|
|
525
|
+
},
|
|
526
|
+
generateBundle() {
|
|
527
|
+
for (const [fileName, source] of componentStyles.libraryFiles()) this.emitFile({ type: "asset", fileName, source });
|
|
528
|
+
},
|
|
529
|
+
// An edited component's style modules go out with its update: their ids end in `.css`, so
|
|
530
|
+
// Vite does not connect them to the file.
|
|
531
|
+
handleHotUpdate(ctx) {
|
|
532
|
+
if (!componentStyles.active) return void 0;
|
|
533
|
+
const styles = componentStyles.hotModules(ctx.file, ctx.server.moduleGraph);
|
|
534
|
+
return styles.length ? [...ctx.modules, ...styles] : void 0;
|
|
535
|
+
},
|
|
536
|
+
configureServer(server) {
|
|
537
|
+
componentStyles.setServer(server);
|
|
538
|
+
},
|
|
539
|
+
load(id) {
|
|
540
|
+
return componentStyles.isStyle(id) ? componentStyles.load(id, this) : null;
|
|
541
|
+
},
|
|
542
|
+
// A subpath we retired resolves to nothing, and the bundler reports that as
|
|
543
|
+
// `Missing "./x" specifier`, which names neither the replacement nor the file
|
|
544
|
+
// that asked. Answer it here, where the rename is known.
|
|
545
|
+
resolveId(id, importer) {
|
|
546
|
+
if (componentStyles.isStyle(id)) return componentStyles.resolveId(id, importer, this);
|
|
547
|
+
if (componentStyles.isLibraryImport(id, importer)) return { id, external: true };
|
|
548
|
+
const moved = RETIRED_SUBPATHS[id];
|
|
549
|
+
if (!moved) return null;
|
|
550
|
+
throw new Error(
|
|
551
|
+
`[fluixi] ${id} ${moved}` + (importer ? `
|
|
552
|
+
imported by ${importer}` : "")
|
|
553
|
+
);
|
|
554
|
+
},
|
|
555
|
+
async transform(code, id) {
|
|
556
|
+
if (!/\.(jsx|tsx|ts)$/i.test(id)) {
|
|
557
|
+
return null;
|
|
558
|
+
}
|
|
559
|
+
if (!options.babel && componentStyles.active) {
|
|
560
|
+
const result = await componentStyles.compile(code, id, this);
|
|
561
|
+
reportDiagnostics(result, id);
|
|
562
|
+
return result;
|
|
563
|
+
}
|
|
564
|
+
if (!options.babel) return compileModule(code, id, options);
|
|
565
|
+
const babelPlugin = await createBabelPlugin(options);
|
|
566
|
+
try {
|
|
567
|
+
const babel = await import("@babel/core").catch(() => null);
|
|
568
|
+
if (!babel) {
|
|
569
|
+
throw new Error(
|
|
570
|
+
`[fluixi] @babel/core is required to compile ${id} but could not be loaded. Install it alongside @fluixi/compiler.`
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
const isTSX = /\.tsx$/.test(id);
|
|
574
|
+
const isTS = /\.ts$/.test(id);
|
|
575
|
+
const presets = [];
|
|
576
|
+
const plugins = [];
|
|
577
|
+
if (isTSX || isTS) {
|
|
578
|
+
const tsPreset = await import("@babel/preset-typescript").then((m) => m.default || m).catch(() => null);
|
|
579
|
+
if (tsPreset) {
|
|
580
|
+
presets.push([
|
|
581
|
+
tsPreset,
|
|
582
|
+
{
|
|
583
|
+
isTSX,
|
|
584
|
+
allExtensions: true,
|
|
585
|
+
// Important: preserve JSX so our plugin can transform it
|
|
586
|
+
jsxPragma: "jsx",
|
|
587
|
+
jsxPragmaFrag: "Fragment",
|
|
588
|
+
onlyRemoveTypeImports: true
|
|
589
|
+
}
|
|
590
|
+
]);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (babelPlugin && babelPlugin.plugin) {
|
|
594
|
+
plugins.push([babelPlugin.plugin, babelPlugin.getOptions()]);
|
|
595
|
+
} else {
|
|
596
|
+
console.warn("[createVitePlugin] custom babel plugin not found");
|
|
597
|
+
}
|
|
598
|
+
const result = await babel.transformAsync(code, {
|
|
599
|
+
filename: id,
|
|
600
|
+
configFile: false,
|
|
601
|
+
babelrc: false,
|
|
602
|
+
presets,
|
|
603
|
+
plugins,
|
|
604
|
+
sourceMaps: options.sourceMaps !== false
|
|
605
|
+
});
|
|
606
|
+
return {
|
|
607
|
+
code: result?.code || code,
|
|
608
|
+
map: result?.map
|
|
609
|
+
};
|
|
610
|
+
} catch (e) {
|
|
611
|
+
throw e;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
function marks(options, id) {
|
|
617
|
+
if (options.sourceLocations !== true) return false;
|
|
618
|
+
if (options.sourceLocationsExternal) return true;
|
|
619
|
+
if (!id || id.includes("/node_modules/")) return false;
|
|
620
|
+
const root = options.sourceRoot;
|
|
621
|
+
if (!root) return true;
|
|
622
|
+
const base = root.endsWith("/") ? root : `${root}/`;
|
|
623
|
+
return id.startsWith(base);
|
|
624
|
+
}
|
|
625
|
+
function transformOptions(options, id) {
|
|
626
|
+
return {
|
|
627
|
+
resolve: options.resolve,
|
|
628
|
+
litTag: options.litTag,
|
|
629
|
+
sourceLocations: marks(options, id),
|
|
630
|
+
sourceRoot: options.sourceRoot,
|
|
631
|
+
templateClone: options.templateClone,
|
|
632
|
+
partialTemplates: options.partialTemplates,
|
|
633
|
+
runtimeModule: options.signalModule,
|
|
634
|
+
controlFlowModule: options.controlFlowModule,
|
|
635
|
+
routerModule: options.routerModule,
|
|
636
|
+
reactiveModule: options.reactiveModule,
|
|
637
|
+
propsDestructure: options.propsDestructure
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
async function rewriteProps(code, id, options) {
|
|
641
|
+
if (options.propsDestructure === false) return code;
|
|
642
|
+
const { transformProps } = await import("./transform-3W45L3EA.mjs");
|
|
643
|
+
const result = transformProps(code, id);
|
|
644
|
+
reportDiagnostics({ propsDiagnostics: result.diagnostics }, id);
|
|
645
|
+
return result.rewritten > 0 ? result.code : code;
|
|
646
|
+
}
|
|
647
|
+
var reported = /* @__PURE__ */ new Set();
|
|
648
|
+
function reportDiagnostics(result, id) {
|
|
649
|
+
const r = result;
|
|
650
|
+
const say = (message) => {
|
|
651
|
+
const key = `${id}\0${message}`;
|
|
652
|
+
if (reported.has(key)) return;
|
|
653
|
+
reported.add(key);
|
|
654
|
+
console.warn(`[fluixi] ${id}: ${message}`);
|
|
655
|
+
};
|
|
656
|
+
for (const d of r?.unresolvedDiagnostics ?? []) say(d.message);
|
|
657
|
+
for (const d of r?.loadDiagnostics ?? []) say(d.message);
|
|
658
|
+
for (const d of r?.intrinsicDiagnostics ?? []) say(d.message);
|
|
659
|
+
for (const d of r?.styleDiagnostics ?? []) say(`${d.line}:${d.column + 1} ${d.message}`);
|
|
660
|
+
for (const d of r?.propsDiagnostics ?? []) {
|
|
661
|
+
say(`\`${d.name}\` was left destructured: ${d.message}. It reads once instead of tracking.`);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
async function compileModule(code, id, options) {
|
|
665
|
+
if (!options.babel) {
|
|
666
|
+
const { transformTemplates } = await import("./transform-3W45L3EA.mjs");
|
|
667
|
+
const result2 = transformTemplates(code, id, transformOptions(options, id));
|
|
668
|
+
reportDiagnostics(result2, id);
|
|
669
|
+
return result2;
|
|
670
|
+
}
|
|
671
|
+
const source = await rewriteProps(code, id, options);
|
|
672
|
+
const babel = await import("@babel/core").catch(() => null);
|
|
673
|
+
const plugin = await createBabelPlugin(options);
|
|
674
|
+
if (!babel || !plugin.plugin) {
|
|
675
|
+
throw new Error(
|
|
676
|
+
`[fluixi] babel: true needs @babel/core, which could not be loaded for ${id}. Install it, or drop the option to use the built-in compiler.`
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
const result = await babel.transformAsync(source, {
|
|
680
|
+
filename: id,
|
|
681
|
+
configFile: false,
|
|
682
|
+
babelrc: false,
|
|
683
|
+
plugins: [[plugin.plugin, plugin.getOptions()]],
|
|
684
|
+
sourceMaps: options.sourceMaps !== false
|
|
685
|
+
});
|
|
686
|
+
return result?.code ? { code: result.code, map: result.map } : null;
|
|
687
|
+
}
|
|
688
|
+
function createWebpackLoader(options = {}) {
|
|
689
|
+
return async function(source) {
|
|
690
|
+
const callback = this.async();
|
|
691
|
+
compileModule(source, this.resourcePath, options).then((result) => {
|
|
692
|
+
callback(null, result?.code, result?.map);
|
|
693
|
+
}).catch((err) => {
|
|
694
|
+
callback(err);
|
|
695
|
+
});
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
function createRollupPlugin(options = {}) {
|
|
699
|
+
return {
|
|
700
|
+
name: "rollup-fluixi-jsx",
|
|
701
|
+
async transform(code, id) {
|
|
702
|
+
if (!/\.[jt]sx?$/.test(id)) return null;
|
|
703
|
+
return compileModule(code, id, options);
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
function createESBuildPlugin(options = {}) {
|
|
708
|
+
return {
|
|
709
|
+
name: "esbuild-fluixi-jsx",
|
|
710
|
+
setup(build) {
|
|
711
|
+
build.onLoad({ filter: /\.[jt]sx?$/ }, async (args) => {
|
|
712
|
+
const { readFileSync: readFileSync4 } = await import("node:fs");
|
|
713
|
+
const source = readFileSync4(args.path, "utf8");
|
|
714
|
+
try {
|
|
715
|
+
const result = await compileModule(source, args.path, options);
|
|
716
|
+
return {
|
|
717
|
+
contents: result?.code ?? source,
|
|
718
|
+
loader: args.path.endsWith("x") ? "tsx" : "ts"
|
|
719
|
+
};
|
|
720
|
+
} catch (e) {
|
|
721
|
+
return {
|
|
722
|
+
errors: [
|
|
723
|
+
{
|
|
724
|
+
text: `Transform error: ${e}`
|
|
725
|
+
}
|
|
726
|
+
]
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
var SERVER_FNS_VMOD = "virtual:fluixi-server-fns";
|
|
734
|
+
function hasServerDirective(source) {
|
|
735
|
+
const withoutComments = source.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/(^|[^:])\/\/[^\n]*/g, "$1");
|
|
736
|
+
return /(^|[\s;{(,])['"]use server['"]/.test(withoutComments);
|
|
737
|
+
}
|
|
738
|
+
function findServerFnModules(dir, out = []) {
|
|
739
|
+
let entries;
|
|
740
|
+
try {
|
|
741
|
+
entries = readdirSync2(dir, { withFileTypes: true });
|
|
742
|
+
} catch {
|
|
743
|
+
return out;
|
|
744
|
+
}
|
|
745
|
+
for (const e of entries) {
|
|
746
|
+
if (e.name === "node_modules" || e.name === "dist" || e.name.startsWith(".")) continue;
|
|
747
|
+
const full = _join(dir, e.name);
|
|
748
|
+
if (e.isDirectory()) findServerFnModules(full, out);
|
|
749
|
+
else if (/\.[jt]sx?$/.test(e.name)) {
|
|
750
|
+
try {
|
|
751
|
+
if (hasServerDirective(readFileSync3(full, "utf8"))) out.push(full);
|
|
752
|
+
} catch {
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return out;
|
|
757
|
+
}
|
|
758
|
+
function serverFunctionsVitePlugin(options = {}) {
|
|
759
|
+
let root = process.cwd();
|
|
760
|
+
return {
|
|
761
|
+
name: "fluixi-server-functions",
|
|
762
|
+
enforce: "pre",
|
|
763
|
+
configResolved(config) {
|
|
764
|
+
root = config.root || root;
|
|
765
|
+
},
|
|
766
|
+
resolveId(id) {
|
|
767
|
+
return id === SERVER_FNS_VMOD || id === "@fluixi/start/server-fns" ? "\0" + SERVER_FNS_VMOD : null;
|
|
768
|
+
},
|
|
769
|
+
load(id) {
|
|
770
|
+
if (id !== "\0" + SERVER_FNS_VMOD) return null;
|
|
771
|
+
const mods = findServerFnModules(_join(root, "src"));
|
|
772
|
+
const setup = `import '@fluixi/start/server-fn-setup';
|
|
773
|
+
`;
|
|
774
|
+
const imports = mods.map((m) => `import ${JSON.stringify(m)};`).join("\n");
|
|
775
|
+
const dispatcher = `
|
|
776
|
+
export { isServerFnRequest, handleServerFn } from '@fluixi/start/server-fn';
|
|
777
|
+
`;
|
|
778
|
+
return setup + imports + dispatcher;
|
|
779
|
+
},
|
|
780
|
+
async transform(code, id, opts) {
|
|
781
|
+
if (!/\.[jt]sx?$/.test(id)) return null;
|
|
782
|
+
if (!code.includes("use server")) return null;
|
|
783
|
+
const args = { ssr: !!opts?.ssr, filename: id, root };
|
|
784
|
+
if (options.babel) {
|
|
785
|
+
const { transformServerFunctions } = await import("./server-functions-UAZKOLZW.mjs");
|
|
786
|
+
return transformServerFunctions(code, args);
|
|
787
|
+
}
|
|
788
|
+
const { transformServerFns } = await import("./server-fns-VZLHMQTC.mjs");
|
|
789
|
+
return transformServerFns(code, args);
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
var integrations_default = {
|
|
794
|
+
createBabelPlugin,
|
|
795
|
+
createTypeScriptTransformer,
|
|
796
|
+
createVitePlugin,
|
|
797
|
+
createWebpackLoader,
|
|
798
|
+
createRollupPlugin,
|
|
799
|
+
createESBuildPlugin
|
|
800
|
+
};
|
|
801
|
+
export {
|
|
802
|
+
createBabelPlugin,
|
|
803
|
+
createESBuildPlugin,
|
|
804
|
+
createRollupPlugin,
|
|
805
|
+
createTypeScriptTransformer,
|
|
806
|
+
createVitePlugin,
|
|
807
|
+
createWebpackLoader,
|
|
808
|
+
integrations_default as default,
|
|
809
|
+
serverFunctionsVitePlugin
|
|
810
|
+
};
|