@farm.js/react 0.1.0-beta.4 → 0.1.0-beta.40
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/README.md +825 -15
- package/dist/client.d.mts +1 -0
- package/dist/client.d.ts +1 -0
- package/dist/compiled-root.cjs +17 -0
- package/dist/compiled-root.cjs.map +1 -0
- package/dist/compiled-root.d.mts +12 -0
- package/dist/compiled-root.d.ts +12 -0
- package/dist/compiled-root.mjs +14 -0
- package/dist/compiled-root.mjs.map +1 -0
- package/dist/compiler-runtime.cjs +7150 -1170
- package/dist/compiler-runtime.cjs.map +1 -1
- package/dist/compiler-runtime.d.mts +267 -5
- package/dist/compiler-runtime.d.ts +267 -5
- package/dist/compiler-runtime.mjs +7029 -1171
- package/dist/compiler-runtime.mjs.map +1 -1
- package/dist/index.cjs +45 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.mjs +45 -5
- package/dist/index.mjs.map +1 -1
- package/dist/list.cjs +6 -0
- package/dist/list.cjs.map +1 -1
- package/dist/list.mjs +6 -0
- package/dist/list.mjs.map +1 -1
- package/dist/server.d.mts +0 -1
- package/dist/server.d.ts +0 -1
- package/dist/vite.cjs +5181 -422
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.mts +10 -1
- package/dist/vite.d.ts +10 -1
- package/dist/vite.mjs +5183 -425
- package/dist/vite.mjs.map +1 -1
- package/package.json +18 -10
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/compiler-options.ts
|
|
4
|
+
var warnedExperimentalCompiler = false;
|
|
5
|
+
function resolveCompilerOption(options = {}, warnDeprecated = false) {
|
|
6
|
+
const experimental = options.experimental;
|
|
7
|
+
const legacy = experimental && typeof experimental === "object" ? experimental.compiler : void 0;
|
|
8
|
+
if (legacy !== void 0 && options.compiler !== void 0) {
|
|
9
|
+
throw new TypeError(
|
|
10
|
+
"Configure the React compiler with `compiler` only; remove `experimental.compiler`."
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
const compiler = legacy === void 0 ? options.compiler : legacy;
|
|
14
|
+
if (compiler !== void 0 && typeof compiler !== "boolean" && (compiler === null || typeof compiler !== "object" || Array.isArray(compiler))) {
|
|
15
|
+
throw new TypeError("React compiler must be a boolean or compiler options object.");
|
|
16
|
+
}
|
|
17
|
+
if (legacy !== void 0 && warnDeprecated && !warnedExperimentalCompiler) {
|
|
18
|
+
warnedExperimentalCompiler = true;
|
|
19
|
+
console.warn(
|
|
20
|
+
"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`."
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return compiler;
|
|
24
|
+
}
|
|
25
|
+
|
|
3
26
|
// src/index.ts
|
|
4
27
|
var DEFAULT_COMPILER_DIRECTIVE = "use compiler";
|
|
5
28
|
var DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
|
|
@@ -42,7 +65,11 @@ function normalizeReactCompilerOptions(value) {
|
|
|
42
65
|
}
|
|
43
66
|
const reportFile = normalizeCompilerReportFile(options.reportFile);
|
|
44
67
|
const report = options.report === true || options.reportFile !== void 0;
|
|
45
|
-
|
|
68
|
+
if (options.compiledRoot !== void 0 && typeof options.compiledRoot !== "boolean") {
|
|
69
|
+
throw new TypeError("The React compiler compiledRoot option must be a boolean.");
|
|
70
|
+
}
|
|
71
|
+
const compiledRoot = options.compiledRoot !== false;
|
|
72
|
+
return { mode, directive, onUnsupported, reactivity, report, reportFile, compiledRoot };
|
|
46
73
|
}
|
|
47
74
|
var REACT_RENDERER = Object.freeze({
|
|
48
75
|
name: "react",
|
|
@@ -60,21 +87,34 @@ var REACT_RENDERER = Object.freeze({
|
|
|
60
87
|
"@farm.js/react/compiler-runtime"
|
|
61
88
|
],
|
|
62
89
|
capabilities: {
|
|
63
|
-
|
|
90
|
+
reconcilesRerenders: true,
|
|
91
|
+
streaming: {
|
|
92
|
+
node: true,
|
|
93
|
+
web: false,
|
|
94
|
+
runtimes: { edge: { node: false, web: true } }
|
|
95
|
+
},
|
|
96
|
+
functionComponents: true
|
|
64
97
|
}
|
|
65
98
|
});
|
|
66
99
|
function react(options = {}) {
|
|
67
|
-
const compiler = options
|
|
100
|
+
const compiler = resolveCompilerOption(options, true);
|
|
68
101
|
const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;
|
|
69
102
|
return {
|
|
70
103
|
...REACT_RENDERER,
|
|
71
104
|
dedupe: [...REACT_RENDERER.dedupe || []],
|
|
72
105
|
optimizeDeps: [...REACT_RENDERER.optimizeDeps || []],
|
|
73
106
|
capabilities: {
|
|
74
|
-
|
|
107
|
+
reconcilesRerenders: true,
|
|
108
|
+
streaming: {
|
|
109
|
+
...REACT_RENDERER.capabilities?.streaming,
|
|
110
|
+
runtimes: {
|
|
111
|
+
edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge }
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
functionComponents: true
|
|
75
115
|
},
|
|
76
116
|
options: {
|
|
77
|
-
|
|
117
|
+
compiler: normalizedCompiler
|
|
78
118
|
}
|
|
79
119
|
};
|
|
80
120
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAwCO,IAAM,0BAAA,GAA6B;AACnC,IAAM,4BAAA,GAA+B;AAE5C,SAAS,4BAA4B,KAAA,EAAwB;AAC3D,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,4BAAA;AAChC,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,KAAA,CAAM,MAAK,EAAG;AAC9C,IAAA,MAAM,IAAI,UAAU,mEAAmE,CAAA;AAAA,EACzF;AACA,EAAA,MAAM,aAAa,KAAA,CAAM,IAAA,EAAK,CAAE,OAAA,C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ACtE,EAAA,MAAM,QAAA,GAAW,QAAQ,YAAA,EAAc,QAAA;AACvC,EAAA,MAAM,kBAAA,GAAqB,QAAA,GAAW,6BAAA,CAA8B,QAAQ,CAAA,GAAI,KAAA;AAEhF,EAAA,OAAO;AAAA,IACL,GAAG,cAAA;AAAA,IACH,QAAQ,CAAC,GAAI,cAAA,CAAe,MAAA,IAAU,EAAG,CAAA;AAAA,IACzC,cAAc,CAAC,GAAI,cAAA,CAAe,YAAA,IAAgB,EAAG,CAAA;AAAA,IACrD,YAAA,EAAc;AAAA,MACZ,SAAA,EAAW,EAAE,GAAG,cAAA,CAAe,cAAc,SAAA;AAAU,KACzD;AAAA,IACA,OAAA,EAAS;AAAA,MACP,YAAA,EAAc,EAAE,QAAA,EAAU,kBAAA;AAAmB;AAC/C,GACF;AACF","file":"index.cjs","sourcesContent":["import type { FarmRenderer } from \"@farm.js/core/renderer\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type ReactCompilerReactivity = \"static\" | \"hybrid\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /**\n * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven\n * dependencies and narrows short-circuited reads at runtime.\n */\n reactivity?: ReactCompilerReactivity;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n}\n\nexport interface ReactRendererOptions {\n experimental?: {\n /** `true` enables automatic inference; an object customizes selection. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n reactivity: ReactCompilerReactivity;\n report: boolean;\n reportFile: string;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n const reactivity = options.reactivity || \"hybrid\";\n if (reactivity !== \"static\" && reactivity !== \"hybrid\") {\n throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n\n return { mode, directive, onUnsupported, reactivity, report, reportFile };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n streaming: { node: true, web: false },\n },\n});\n\n/** Select React and optionally enable Farm's experimental AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = options.experimental?.compiler;\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n streaming: { ...REACT_RENDERER.capabilities?.streaming },\n },\n options: {\n experimental: { compiler: normalizedCompiler },\n },\n };\n}\n\nexport { REACT_RENDERER };\nexport type { FarmRenderer } from \"@farm.js/core/renderer\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/compiler-options.ts","../src/index.ts"],"names":[],"mappings":";;;AAEA,IAAI,0BAAA,GAA6B,KAAA;AAG1B,SAAS,qBAAA,CACd,OAAA,GAA0D,EAAC,EAC3D,iBAAiB,KAAA,EAC2B;AAC5C,EAAA,MAAM,eAAe,OAAA,CAAQ,YAAA;AAC7B,EAAA,MAAM,SACJ,YAAA,IAAgB,OAAO,YAAA,KAAiB,QAAA,GACnC,aAAwC,QAAA,GACzC,MAAA;AACN,EAAA,IAAI,MAAA,KAAW,MAAA,IAAa,OAAA,CAAQ,QAAA,KAAa,MAAA,EAAW;AAC1D,IAAA,MAAM,IAAI,SAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,MAAM,QAAA,GAAW,M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BAAA,CAAsB,OAAA,EAAS,IAAI,CAAA;AACpD,EAAA,MAAM,kBAAA,GAAqB,QAAA,GAAW,6BAAA,CAA8B,QAAQ,CAAA,GAAI,KAAA;AAEhF,EAAA,OAAO;AAAA,IACL,GAAG,cAAA;AAAA,IACH,QAAQ,CAAC,GAAI,cAAA,CAAe,MAAA,IAAU,EAAG,CAAA;AAAA,IACzC,cAAc,CAAC,GAAI,cAAA,CAAe,YAAA,IAAgB,EAAG,CAAA;AAAA,IACrD,YAAA,EAAc;AAAA,MACZ,mBAAA,EAAqB,IAAA;AAAA,MACrB,SAAA,EAAW;AAAA,QACT,GAAG,eAAe,YAAA,EAAc,SAAA;AAAA,QAChC,QAAA,EAAU;AAAA,UACR,MAAM,EAAE,GAAG,eAAe,YAAA,EAAc,SAAA,EAAW,UAAU,IAAA;AAAK;AACpE,OACF;AAAA,MACA,kBAAA,EAAoB;AAAA,KACtB;AAAA,IACA,OAAA,EAAS;AAAA,MACP,QAAA,EAAU;AAAA;AACZ,GACF;AACF","file":"index.cjs","sourcesContent":["import type { ReactCompilerOptions } from \"./index\";\n\nlet warnedExperimentalCompiler = false;\n\n// Shared by react() and the Vite adapter, including descriptors from older renderers.\nexport function resolveCompilerOption(\n options: { compiler?: unknown; experimental?: unknown } = {},\n warnDeprecated = false,\n): boolean | ReactCompilerOptions | undefined {\n const experimental = options.experimental;\n const legacy =\n experimental && typeof experimental === \"object\"\n ? (experimental as { compiler?: unknown }).compiler\n : undefined;\n if (legacy !== undefined && options.compiler !== undefined) {\n throw new TypeError(\n \"Configure the React compiler with `compiler` only; remove `experimental.compiler`.\",\n );\n }\n const compiler = legacy === undefined ? options.compiler : legacy;\n if (\n compiler !== undefined &&\n typeof compiler !== \"boolean\" &&\n (compiler === null || typeof compiler !== \"object\" || Array.isArray(compiler))\n ) {\n throw new TypeError(\"React compiler must be a boolean or compiler options object.\");\n }\n if (legacy !== undefined && warnDeprecated && !warnedExperimentalCompiler) {\n warnedExperimentalCompiler = true;\n console.warn(\n \"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`.\",\n );\n }\n return compiler as boolean | ReactCompilerOptions | undefined;\n}\n","import type { FarmRenderer } from \"@farm.js/core/renderer\";\nimport { resolveCompilerOption } from \"./compiler-options\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type ReactCompilerReactivity = \"static\" | \"hybrid\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /**\n * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven\n * dependencies and narrows short-circuited reads at runtime.\n */\n reactivity?: ReactCompilerReactivity;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n /**\n * Mount the app's own `createRoot` roots without React DOM when their tree is fully compiled.\n * The build points `import { createRoot } from \"react-dom/client\"` in app modules at\n * `@farm.js/react/compiled-root`, which loads React DOM on demand for anything else.\n * While on, `onChange` rows beside conditional content or in a list between static siblings\n * compile to blocks such roots run themselves and React DOM renders through React; `false`\n * keeps them on the smaller React-owned list. Defaults to `true`.\n */\n compiledRoot?: boolean;\n}\n\nexport interface ReactRendererOptions {\n /**\n * Farm's AOT compiler. `true` enables automatic inference; an object\n * customizes selection. Unsupported components always stay on React.\n */\n compiler?: boolean | ReactCompilerOptions;\n experimental?: {\n /** @deprecated Use the top-level `compiler` option. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n reactivity: ReactCompilerReactivity;\n report: boolean;\n reportFile: string;\n compiledRoot: boolean;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n const reactivity = options.reactivity || \"hybrid\";\n if (reactivity !== \"static\" && reactivity !== \"hybrid\") {\n throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n if (options.compiledRoot !== undefined && typeof options.compiledRoot !== \"boolean\") {\n throw new TypeError(\"The React compiler compiledRoot option must be a boolean.\");\n }\n const compiledRoot = options.compiledRoot !== false;\n\n return { mode, directive, onUnsupported, reactivity, report, reportFile, compiledRoot };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n node: true,\n web: false,\n runtimes: { edge: { node: false, web: true } },\n },\n functionComponents: true,\n },\n});\n\n/** Select React and optionally enable Farm's AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = resolveCompilerOption(options, true);\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n ...REACT_RENDERER.capabilities?.streaming,\n runtimes: {\n edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge },\n },\n },\n functionComponents: true,\n },\n options: {\n compiler: normalizedCompiler,\n },\n };\n}\n\nexport { REACT_RENDERER };\nexport type { FarmRenderer } from \"@farm.js/core/renderer\";\n"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -20,10 +20,24 @@ interface ReactCompilerOptions {
|
|
|
20
20
|
report?: boolean;
|
|
21
21
|
/** Project-relative report location. Providing it also enables reporting. */
|
|
22
22
|
reportFile?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Mount the app's own `createRoot` roots without React DOM when their tree is fully compiled.
|
|
25
|
+
* The build points `import { createRoot } from "react-dom/client"` in app modules at
|
|
26
|
+
* `@farm.js/react/compiled-root`, which loads React DOM on demand for anything else.
|
|
27
|
+
* While on, `onChange` rows beside conditional content or in a list between static siblings
|
|
28
|
+
* compile to blocks such roots run themselves and React DOM renders through React; `false`
|
|
29
|
+
* keeps them on the smaller React-owned list. Defaults to `true`.
|
|
30
|
+
*/
|
|
31
|
+
compiledRoot?: boolean;
|
|
23
32
|
}
|
|
24
33
|
interface ReactRendererOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Farm's AOT compiler. `true` enables automatic inference; an object
|
|
36
|
+
* customizes selection. Unsupported components always stay on React.
|
|
37
|
+
*/
|
|
38
|
+
compiler?: boolean | ReactCompilerOptions;
|
|
25
39
|
experimental?: {
|
|
26
|
-
/**
|
|
40
|
+
/** @deprecated Use the top-level `compiler` option. */
|
|
27
41
|
compiler?: boolean | ReactCompilerOptions;
|
|
28
42
|
};
|
|
29
43
|
}
|
|
@@ -34,12 +48,13 @@ interface NormalizedReactCompilerOptions {
|
|
|
34
48
|
reactivity: ReactCompilerReactivity;
|
|
35
49
|
report: boolean;
|
|
36
50
|
reportFile: string;
|
|
51
|
+
compiledRoot: boolean;
|
|
37
52
|
}
|
|
38
53
|
declare const DEFAULT_COMPILER_DIRECTIVE = "use compiler";
|
|
39
54
|
declare const DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
|
|
40
55
|
declare function normalizeReactCompilerOptions(value: true | ReactCompilerOptions): NormalizedReactCompilerOptions;
|
|
41
56
|
declare const REACT_RENDERER: Readonly<FarmRenderer>;
|
|
42
|
-
/** Select React and optionally enable Farm's
|
|
57
|
+
/** Select React and optionally enable Farm's AOT compiler. */
|
|
43
58
|
declare function react(options?: ReactRendererOptions): FarmRenderer;
|
|
44
59
|
|
|
45
60
|
export { DEFAULT_COMPILER_DIRECTIVE, DEFAULT_COMPILER_REPORT_FILE, type NormalizedReactCompilerOptions, REACT_RENDERER, type ReactCompilerMode, type ReactCompilerOptions, type ReactCompilerReactivity, type ReactRendererOptions, type UnsupportedCompilerBehavior, normalizeReactCompilerOptions, react };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,10 +20,24 @@ interface ReactCompilerOptions {
|
|
|
20
20
|
report?: boolean;
|
|
21
21
|
/** Project-relative report location. Providing it also enables reporting. */
|
|
22
22
|
reportFile?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Mount the app's own `createRoot` roots without React DOM when their tree is fully compiled.
|
|
25
|
+
* The build points `import { createRoot } from "react-dom/client"` in app modules at
|
|
26
|
+
* `@farm.js/react/compiled-root`, which loads React DOM on demand for anything else.
|
|
27
|
+
* While on, `onChange` rows beside conditional content or in a list between static siblings
|
|
28
|
+
* compile to blocks such roots run themselves and React DOM renders through React; `false`
|
|
29
|
+
* keeps them on the smaller React-owned list. Defaults to `true`.
|
|
30
|
+
*/
|
|
31
|
+
compiledRoot?: boolean;
|
|
23
32
|
}
|
|
24
33
|
interface ReactRendererOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Farm's AOT compiler. `true` enables automatic inference; an object
|
|
36
|
+
* customizes selection. Unsupported components always stay on React.
|
|
37
|
+
*/
|
|
38
|
+
compiler?: boolean | ReactCompilerOptions;
|
|
25
39
|
experimental?: {
|
|
26
|
-
/**
|
|
40
|
+
/** @deprecated Use the top-level `compiler` option. */
|
|
27
41
|
compiler?: boolean | ReactCompilerOptions;
|
|
28
42
|
};
|
|
29
43
|
}
|
|
@@ -34,12 +48,13 @@ interface NormalizedReactCompilerOptions {
|
|
|
34
48
|
reactivity: ReactCompilerReactivity;
|
|
35
49
|
report: boolean;
|
|
36
50
|
reportFile: string;
|
|
51
|
+
compiledRoot: boolean;
|
|
37
52
|
}
|
|
38
53
|
declare const DEFAULT_COMPILER_DIRECTIVE = "use compiler";
|
|
39
54
|
declare const DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
|
|
40
55
|
declare function normalizeReactCompilerOptions(value: true | ReactCompilerOptions): NormalizedReactCompilerOptions;
|
|
41
56
|
declare const REACT_RENDERER: Readonly<FarmRenderer>;
|
|
42
|
-
/** Select React and optionally enable Farm's
|
|
57
|
+
/** Select React and optionally enable Farm's AOT compiler. */
|
|
43
58
|
declare function react(options?: ReactRendererOptions): FarmRenderer;
|
|
44
59
|
|
|
45
60
|
export { DEFAULT_COMPILER_DIRECTIVE, DEFAULT_COMPILER_REPORT_FILE, type NormalizedReactCompilerOptions, REACT_RENDERER, type ReactCompilerMode, type ReactCompilerOptions, type ReactCompilerReactivity, type ReactRendererOptions, type UnsupportedCompilerBehavior, normalizeReactCompilerOptions, react };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
// src/compiler-options.ts
|
|
2
|
+
var warnedExperimentalCompiler = false;
|
|
3
|
+
function resolveCompilerOption(options = {}, warnDeprecated = false) {
|
|
4
|
+
const experimental = options.experimental;
|
|
5
|
+
const legacy = experimental && typeof experimental === "object" ? experimental.compiler : void 0;
|
|
6
|
+
if (legacy !== void 0 && options.compiler !== void 0) {
|
|
7
|
+
throw new TypeError(
|
|
8
|
+
"Configure the React compiler with `compiler` only; remove `experimental.compiler`."
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
const compiler = legacy === void 0 ? options.compiler : legacy;
|
|
12
|
+
if (compiler !== void 0 && typeof compiler !== "boolean" && (compiler === null || typeof compiler !== "object" || Array.isArray(compiler))) {
|
|
13
|
+
throw new TypeError("React compiler must be a boolean or compiler options object.");
|
|
14
|
+
}
|
|
15
|
+
if (legacy !== void 0 && warnDeprecated && !warnedExperimentalCompiler) {
|
|
16
|
+
warnedExperimentalCompiler = true;
|
|
17
|
+
console.warn(
|
|
18
|
+
"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`."
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return compiler;
|
|
22
|
+
}
|
|
23
|
+
|
|
1
24
|
// src/index.ts
|
|
2
25
|
var DEFAULT_COMPILER_DIRECTIVE = "use compiler";
|
|
3
26
|
var DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
|
|
@@ -40,7 +63,11 @@ function normalizeReactCompilerOptions(value) {
|
|
|
40
63
|
}
|
|
41
64
|
const reportFile = normalizeCompilerReportFile(options.reportFile);
|
|
42
65
|
const report = options.report === true || options.reportFile !== void 0;
|
|
43
|
-
|
|
66
|
+
if (options.compiledRoot !== void 0 && typeof options.compiledRoot !== "boolean") {
|
|
67
|
+
throw new TypeError("The React compiler compiledRoot option must be a boolean.");
|
|
68
|
+
}
|
|
69
|
+
const compiledRoot = options.compiledRoot !== false;
|
|
70
|
+
return { mode, directive, onUnsupported, reactivity, report, reportFile, compiledRoot };
|
|
44
71
|
}
|
|
45
72
|
var REACT_RENDERER = Object.freeze({
|
|
46
73
|
name: "react",
|
|
@@ -58,21 +85,34 @@ var REACT_RENDERER = Object.freeze({
|
|
|
58
85
|
"@farm.js/react/compiler-runtime"
|
|
59
86
|
],
|
|
60
87
|
capabilities: {
|
|
61
|
-
|
|
88
|
+
reconcilesRerenders: true,
|
|
89
|
+
streaming: {
|
|
90
|
+
node: true,
|
|
91
|
+
web: false,
|
|
92
|
+
runtimes: { edge: { node: false, web: true } }
|
|
93
|
+
},
|
|
94
|
+
functionComponents: true
|
|
62
95
|
}
|
|
63
96
|
});
|
|
64
97
|
function react(options = {}) {
|
|
65
|
-
const compiler = options
|
|
98
|
+
const compiler = resolveCompilerOption(options, true);
|
|
66
99
|
const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;
|
|
67
100
|
return {
|
|
68
101
|
...REACT_RENDERER,
|
|
69
102
|
dedupe: [...REACT_RENDERER.dedupe || []],
|
|
70
103
|
optimizeDeps: [...REACT_RENDERER.optimizeDeps || []],
|
|
71
104
|
capabilities: {
|
|
72
|
-
|
|
105
|
+
reconcilesRerenders: true,
|
|
106
|
+
streaming: {
|
|
107
|
+
...REACT_RENDERER.capabilities?.streaming,
|
|
108
|
+
runtimes: {
|
|
109
|
+
edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge }
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
functionComponents: true
|
|
73
113
|
},
|
|
74
114
|
options: {
|
|
75
|
-
|
|
115
|
+
compiler: normalizedCompiler
|
|
76
116
|
}
|
|
77
117
|
};
|
|
78
118
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAwCO,IAAM,0BAAA,GAA6B;AACnC,IAAM,4BAAA,GAA+B;AAE5C,SAAS,4BAA4B,KAAA,EAAwB;AAC3D,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,4BAAA;AAChC,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,KAAA,CAAM,MAAK,EAAG;AAC9C,IAAA,MAAM,IAAI,UAAU,mEAAmE,CAAA;AAAA,EACzF;AACA,EAAA,MAAM,aAAa,KAAA,CAAM,IAAA,EAAK,CAAE,OAAA,CAAQ,OAAO,GAAG,CAAA;AAClD,EAAA,IACE,UAAA,CAAW,UAAA,CAAW,GAAG,CAAA,IACzB,eAAe,IAAA,CAAK,UAAU,CAAA,IAC9B,UAAA,CAAW,KAAA,CAAM,GAAG,CAAA,CAAE,QAAA,CAAS,IAAI,CAAA,EACnC;AACA,IAAA,MAAM,IAAI,UAAU,mEAAmE,CAAA;AAAA,EACzF;AACA,EAAA,OAAO,UAAA;AACT;AAEO,SAAS,8BACd,KAAA,EACgC;AAChC,EAAA,MAAM,OAAA,GAAU,KAAA,KAAU,IAAA,GAAO,EAAC,GAAI,KAAA;AACtC,EAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,IAAQ,OAAA;AAE7B,EAAA,IAAI,IAAA,KAAS,OAAA,IAAW,IAAA,KAAS,YAAA,EAAc;AAC7C,IAAA,MAAM,IAAI,SAAA,CAAU,CAAA,6BAAA,EAAgC,MAAA,CAAO,IAAI,CAAC,CAAA,CAAE,CAAA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AAA,EAAW,aAAA,EAAe,UAAA,EAAY,QAAQ,UAAA,EAAW;AAC1E;AAEA,IAAM,cAAA,GAAyC,OAAO,MAAA,CAAO;AAAA,EAC3D,IAAA,EAAM,OAAA;AAAA,EACN,IAAA,EAAM,qBAAA;AAAA,EACN,MAAA,EAAQ,uBAAA;AAAA,EACR,MAAA,EAAQ,uBAAA;AAAA,EACR,eAAA,EAAiB,OAAA;AAAA,EACjB,MAAA,EAAQ,CAAC,OAAA,EAAS,WAAA,EAAa,qBAAqB,uBAAuB,CAAA;AAAA,EAC3E,YAAA,EAAc;AAAA,IACZ,OAAA;AAAA,IACA,WAAA;AAAA,IACA,kBAAA;AAAA,IACA,mBAAA;AAAA,IACA,uBAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA,YAAA,EAAc;AAAA,IACZ,SAAA,EAAW,EAAE,IAAA,EAAM,IAAA,EAAM,KAAK,KAAA;AAAM;AAExC,CAAC;AAGM,SAAS,KAAA,CAAM,OAAA,GAAgC,EAAC,EAAiB;AACtE,EAAA,MAAM,QAAA,GAAW,QAAQ,YAAA,EAAc,QAAA;AACvC,EAAA,MAAM,kBAAA,GAAqB,QAAA,GAAW,6BAAA,CAA8B,QAAQ,CAAA,GAAI,KAAA;AAEhF,EAAA,OAAO;AAAA,IACL,GAAG,cAAA;AAAA,IACH,QAAQ,CAAC,GAAI,cAAA,CAAe,MAAA,IAAU,EAAG,CAAA;AAAA,IACzC,cAAc,CAAC,GAAI,cAAA,CAAe,YAAA,IAAgB,EAAG,CAAA;AAAA,IACrD,YAAA,EAAc;AAAA,MACZ,SAAA,EAAW,EAAE,GAAG,cAAA,CAAe,cAAc,SAAA;AAAU,KACzD;AAAA,IACA,OAAA,EAAS;AAAA,MACP,YAAA,EAAc,EAAE,QAAA,EAAU,kBAAA;AAAmB;AAC/C,GACF;AACF","file":"index.mjs","sourcesContent":["import type { FarmRenderer } from \"@farm.js/core/renderer\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type ReactCompilerReactivity = \"static\" | \"hybrid\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /**\n * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven\n * dependencies and narrows short-circuited reads at runtime.\n */\n reactivity?: ReactCompilerReactivity;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n}\n\nexport interface ReactRendererOptions {\n experimental?: {\n /** `true` enables automatic inference; an object customizes selection. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n reactivity: ReactCompilerReactivity;\n report: boolean;\n reportFile: string;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n const reactivity = options.reactivity || \"hybrid\";\n if (reactivity !== \"static\" && reactivity !== \"hybrid\") {\n throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n\n return { mode, directive, onUnsupported, reactivity, report, reportFile };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n streaming: { node: true, web: false },\n },\n});\n\n/** Select React and optionally enable Farm's experimental AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = options.experimental?.compiler;\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n streaming: { ...REACT_RENDERER.capabilities?.streaming },\n },\n options: {\n experimental: { compiler: normalizedCompiler },\n },\n };\n}\n\nexport { REACT_RENDERER };\nexport type { FarmRenderer } from \"@farm.js/core/renderer\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/compiler-options.ts","../src/index.ts"],"names":[],"mappings":";AAEA,IAAI,0BAAA,GAA6B,KAAA;AAG1B,SAAS,qBAAA,CACd,OAAA,GAA0D,EAAC,EAC3D,iBAAiB,KAAA,EAC2B;AAC5C,EAAA,MAAM,eAAe,OAAA,CAAQ,YAAA;AAC7B,EAAA,MAAM,SACJ,YAAA,IAAgB,OAAO,YAAA,KAAiB,QAAA,GACnC,aAAwC,QAAA,GACzC,MAAA;AACN,EAAA,IAAI,MAAA,KAAW,MAAA,IAAa,OAAA,CAAQ,QAAA,KAAa,MAAA,EAAW;AAC1D,IAAA,MAAM,IAAI,SAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,MAAM,QAAA,GAAW,MAAA,KAAW,MAAA,GAAY,OAAA,CAAQ,QAAA,GAAW,MAAA;AAC3D,EAAA,IACE,QAAA,KAAa,MAAA,IACb,OAAO,QAAA,KAAa,SAAA,KACnB,QAAA,KAAa,IAAA,IAAQ,OAAO,QAAA,KAAa,QAAA,IAAY,KAAA,CAAM,OAAA,CAAQ,QAAQ,CAAA,CAAA,EAC5E;AACA,IAAA,MAAM,IAAI,UAAU,8DAA8D,CAAA;AAAA,EACpF;AACA,EAAA,IAAI,MAAA,KAAW,MAAA,IAAa,cAAA,IAAkB,CAAC,0BAAA,EAA4B;AACzE,IAAA,0BAAA,GAA6B,IAAA;AAC7B,IAAA,OAAA,CAAQ,IAAA;AAAA,MACN;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,QAAA;AACT;;;ACsBO,IAAM,0BAAA,GAA6B;AACnC,IAAM,4BAAA,GAA+B;AAE5C,SAAS,4BAA4B,KAAA,EAAwB;AAC3D,EAAA,IAAI,KAAA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AAA,EAAU;AAAA;AACZ,GACF;AACF","file":"index.mjs","sourcesContent":["import type { ReactCompilerOptions } from \"./index\";\n\nlet warnedExperimentalCompiler = false;\n\n// Shared by react() and the Vite adapter, including descriptors from older renderers.\nexport function resolveCompilerOption(\n options: { compiler?: unknown; experimental?: unknown } = {},\n warnDeprecated = false,\n): boolean | ReactCompilerOptions | undefined {\n const experimental = options.experimental;\n const legacy =\n experimental && typeof experimental === \"object\"\n ? (experimental as { compiler?: unknown }).compiler\n : undefined;\n if (legacy !== undefined && options.compiler !== undefined) {\n throw new TypeError(\n \"Configure the React compiler with `compiler` only; remove `experimental.compiler`.\",\n );\n }\n const compiler = legacy === undefined ? options.compiler : legacy;\n if (\n compiler !== undefined &&\n typeof compiler !== \"boolean\" &&\n (compiler === null || typeof compiler !== \"object\" || Array.isArray(compiler))\n ) {\n throw new TypeError(\"React compiler must be a boolean or compiler options object.\");\n }\n if (legacy !== undefined && warnDeprecated && !warnedExperimentalCompiler) {\n warnedExperimentalCompiler = true;\n console.warn(\n \"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`.\",\n );\n }\n return compiler as boolean | ReactCompilerOptions | undefined;\n}\n","import type { FarmRenderer } from \"@farm.js/core/renderer\";\nimport { resolveCompilerOption } from \"./compiler-options\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type ReactCompilerReactivity = \"static\" | \"hybrid\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /**\n * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven\n * dependencies and narrows short-circuited reads at runtime.\n */\n reactivity?: ReactCompilerReactivity;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n /**\n * Mount the app's own `createRoot` roots without React DOM when their tree is fully compiled.\n * The build points `import { createRoot } from \"react-dom/client\"` in app modules at\n * `@farm.js/react/compiled-root`, which loads React DOM on demand for anything else.\n * While on, `onChange` rows beside conditional content or in a list between static siblings\n * compile to blocks such roots run themselves and React DOM renders through React; `false`\n * keeps them on the smaller React-owned list. Defaults to `true`.\n */\n compiledRoot?: boolean;\n}\n\nexport interface ReactRendererOptions {\n /**\n * Farm's AOT compiler. `true` enables automatic inference; an object\n * customizes selection. Unsupported components always stay on React.\n */\n compiler?: boolean | ReactCompilerOptions;\n experimental?: {\n /** @deprecated Use the top-level `compiler` option. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n reactivity: ReactCompilerReactivity;\n report: boolean;\n reportFile: string;\n compiledRoot: boolean;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n const reactivity = options.reactivity || \"hybrid\";\n if (reactivity !== \"static\" && reactivity !== \"hybrid\") {\n throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n if (options.compiledRoot !== undefined && typeof options.compiledRoot !== \"boolean\") {\n throw new TypeError(\"The React compiler compiledRoot option must be a boolean.\");\n }\n const compiledRoot = options.compiledRoot !== false;\n\n return { mode, directive, onUnsupported, reactivity, report, reportFile, compiledRoot };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n node: true,\n web: false,\n runtimes: { edge: { node: false, web: true } },\n },\n functionComponents: true,\n },\n});\n\n/** Select React and optionally enable Farm's AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = resolveCompilerOption(options, true);\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n ...REACT_RENDERER.capabilities?.streaming,\n runtimes: {\n edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge },\n },\n },\n functionComponents: true,\n },\n options: {\n compiler: normalizedCompiler,\n },\n };\n}\n\nexport { REACT_RENDERER };\nexport type { FarmRenderer } from \"@farm.js/core/renderer\";\n"]}
|
package/dist/list.cjs
CHANGED
|
@@ -10,8 +10,14 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
10
10
|
|
|
11
11
|
// src/iterable.ts
|
|
12
12
|
var oneShotSnapshots = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
var arrayIterator = /* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();
|
|
13
14
|
function materializeIterable(source) {
|
|
14
15
|
if (source == null) return [];
|
|
16
|
+
if (Array.isArray(source) && Object.getPrototypeOf(source) === Array.prototype && source[Symbol.iterator] === arrayIterator) {
|
|
17
|
+
const items2 = [];
|
|
18
|
+
for (let index = 0; index < source.length; index += 1) items2.push(source[index]);
|
|
19
|
+
return items2;
|
|
20
|
+
}
|
|
15
21
|
const iterator = source[Symbol.iterator]();
|
|
16
22
|
const oneShot = iterator === source && (typeof source === "object" || typeof source === "function");
|
|
17
23
|
if (oneShot) {
|
package/dist/list.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":["React"],"mappings":";;;;;;;;;;;AAAA,IAAM,gBAAA,uBAAuB,OAAA,EAAoC;
|
|
1
|
+
{"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":["items","React"],"mappings":";;;;;;;;;;;AAAA,IAAM,gBAAA,uBAAuB,OAAA,EAAoC;AAEjE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O,oBAAoB,IAAI,CAAA;AACrC,EAAA,OAAOC,sBAAA,CAAM,aAAA;AAAA,IACXA,sBAAA,CAAM,QAAA;AAAA,IACN,IAAA;AAAA,IACA,GAAG,IAAA,CAAK,GAAA,CAAI,CAAC,MAAM,KAAA,KAAU;AAC3B,MAAA,MAAM,GAAA,GAAM,QAAA,CAAS,IAAA,EAAM,KAAK,CAAA;AAChC,MAAA,IAAI,CAACA,sBAAA,CAAM,cAAA,CAAe,GAAG,CAAA,EAAG;AAC9B,QAAA,MAAM,IAAI,UAAU,6DAA6D,CAAA;AAAA,MACnF;AACA,MAAA,OAAOA,sBAAA,CAAM,aAAa,GAAA,EAAK,EAAE,KAAK,EAAA,CAAG,IAAA,EAAM,KAAK,CAAA,EAAuB,CAAA;AAAA,IAC7E,CAAC;AAAA,GACH;AACF","file":"list.cjs","sourcesContent":["const oneShotSnapshots = new WeakMap<object, readonly unknown[]>();\n\nconst arrayIterator = /* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();\n\n/** Materialize an iterable without consuming a one-shot iterator more than once. */\nexport function materializeIterable<Item>(source: Iterable<Item> | null | undefined): Item[] {\n if (source == null) return [];\n // A plain array iterates by index, so copy it without the iterator protocol.\n if (\n Array.isArray(source) &&\n Object.getPrototypeOf(source) === Array.prototype &&\n source[Symbol.iterator] === arrayIterator\n ) {\n const items: Item[] = [];\n for (let index = 0; index < source.length; index += 1) items.push(source[index]);\n return items;\n }\n\n const iterator = source[Symbol.iterator]();\n const oneShot =\n iterator === (source as unknown) &&\n (typeof source === \"object\" || typeof source === \"function\");\n if (oneShot) {\n const cached = oneShotSnapshots.get(source as object);\n if (cached) return cached as Item[];\n }\n\n const items = Array.from({ [Symbol.iterator]: () => iterator });\n if (oneShot) oneShotSnapshots.set(source as object, items);\n return items;\n}\n","import React from \"react\";\nimport { materializeIterable } from \"./iterable\";\n\nexport interface ListProps<Item> {\n /** Items to render. Nullish collections are treated as empty. */\n each: Iterable<Item> | null | undefined;\n /** Returns the stable React key for one item. */\n by(item: Item, index: number): React.Key;\n /** Renders one keyed row. */\n children(item: Item, index: number): React.ReactElement;\n}\n\n/**\n * An explicit keyed collection boundary for advanced list expressions.\n *\n * It behaves like ordinary React when the compiler is disabled. With the\n * experimental compiler enabled, eligible usages are isolated so local list\n * updates do not execute the surrounding user component.\n */\nexport function List<Item>({ each, by, children }: ListProps<Item>): React.ReactElement {\n const rows = materializeIterable(each);\n return React.createElement(\n React.Fragment,\n null,\n ...rows.map((item, index) => {\n const row = children(item, index);\n if (!React.isValidElement(row)) {\n throw new TypeError(\"@farm.js/react List children must return one React element.\");\n }\n return React.cloneElement(row, { key: by(item, index) } as React.Attributes);\n }),\n );\n}\n"]}
|
package/dist/list.mjs
CHANGED
|
@@ -4,8 +4,14 @@ import React from 'react';
|
|
|
4
4
|
|
|
5
5
|
// src/iterable.ts
|
|
6
6
|
var oneShotSnapshots = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
var arrayIterator = /* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();
|
|
7
8
|
function materializeIterable(source) {
|
|
8
9
|
if (source == null) return [];
|
|
10
|
+
if (Array.isArray(source) && Object.getPrototypeOf(source) === Array.prototype && source[Symbol.iterator] === arrayIterator) {
|
|
11
|
+
const items2 = [];
|
|
12
|
+
for (let index = 0; index < source.length; index += 1) items2.push(source[index]);
|
|
13
|
+
return items2;
|
|
14
|
+
}
|
|
9
15
|
const iterator = source[Symbol.iterator]();
|
|
10
16
|
const oneShot = iterator === source && (typeof source === "object" || typeof source === "function");
|
|
11
17
|
if (oneShot) {
|
package/dist/list.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":[],"mappings":";;;;;AAAA,IAAM,gBAAA,uBAAuB,OAAA,EAAoC;
|
|
1
|
+
{"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":["items"],"mappings":";;;;;AAAA,IAAM,gBAAA,uBAAuB,OAAA,EA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,IAAA,GAAO,oBAAoB,IAAI,CAAA;AACrC,EAAA,OAAO,KAAA,CAAM,aAAA;AAAA,IACX,KAAA,CAAM,QAAA;AAAA,IACN,IAAA;AAAA,IACA,GAAG,IAAA,CAAK,GAAA,CAAI,CAAC,MAAM,KAAA,KAAU;AAC3B,MAAA,MAAM,GAAA,GAAM,QAAA,CAAS,IAAA,EAAM,KAAK,CAAA;AAChC,MAAA,IAAI,CAAC,KAAA,CAAM,cAAA,CAAe,GAAG,CAAA,EAAG;AAC9B,QAAA,MAAM,IAAI,UAAU,6DAA6D,CAAA;AAAA,MACnF;AACA,MAAA,OAAO,KAAA,CAAM,aAAa,GAAA,EAAK,EAAE,KAAK,EAAA,CAAG,IAAA,EAAM,KAAK,CAAA,EAAuB,CAAA;AAAA,IAC7E,CAAC;AAAA,GACH;AACF","file":"list.mjs","sourcesContent":["const oneShotSnapshots = new WeakMap<object, readonly unknown[]>();\n\nconst arrayIterator = /* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();\n\n/** Materialize an iterable without consuming a one-shot iterator more than once. */\nexport function materializeIterable<Item>(source: Iterable<Item> | null | undefined): Item[] {\n if (source == null) return [];\n // A plain array iterates by index, so copy it without the iterator protocol.\n if (\n Array.isArray(source) &&\n Object.getPrototypeOf(source) === Array.prototype &&\n source[Symbol.iterator] === arrayIterator\n ) {\n const items: Item[] = [];\n for (let index = 0; index < source.length; index += 1) items.push(source[index]);\n return items;\n }\n\n const iterator = source[Symbol.iterator]();\n const oneShot =\n iterator === (source as unknown) &&\n (typeof source === \"object\" || typeof source === \"function\");\n if (oneShot) {\n const cached = oneShotSnapshots.get(source as object);\n if (cached) return cached as Item[];\n }\n\n const items = Array.from({ [Symbol.iterator]: () => iterator });\n if (oneShot) oneShotSnapshots.set(source as object, items);\n return items;\n}\n","import React from \"react\";\nimport { materializeIterable } from \"./iterable\";\n\nexport interface ListProps<Item> {\n /** Items to render. Nullish collections are treated as empty. */\n each: Iterable<Item> | null | undefined;\n /** Returns the stable React key for one item. */\n by(item: Item, index: number): React.Key;\n /** Renders one keyed row. */\n children(item: Item, index: number): React.ReactElement;\n}\n\n/**\n * An explicit keyed collection boundary for advanced list expressions.\n *\n * It behaves like ordinary React when the compiler is disabled. With the\n * experimental compiler enabled, eligible usages are isolated so local list\n * updates do not execute the surrounding user component.\n */\nexport function List<Item>({ each, by, children }: ListProps<Item>): React.ReactElement {\n const rows = materializeIterable(each);\n return React.createElement(\n React.Fragment,\n null,\n ...rows.map((item, index) => {\n const row = children(item, index);\n if (!React.isValidElement(row)) {\n throw new TypeError(\"@farm.js/react List children must return one React element.\");\n }\n return React.cloneElement(row, { key: by(item, index) } as React.Attributes);\n }),\n );\n}\n"]}
|
package/dist/server.d.mts
CHANGED
package/dist/server.d.ts
CHANGED