@ecopages/react 0.2.1 → 0.3.0

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.
Files changed (173) hide show
  1. package/README.md +178 -35
  2. package/package.json +80 -32
  3. package/src/app/client-only.js +10 -0
  4. package/src/app/dynamic.js +9 -0
  5. package/src/app/dynamic.test.browser.d.ts +1 -0
  6. package/src/app/dynamic.test.browser.js +38 -0
  7. package/src/bundling/bootstrap-package-paths.d.ts +5 -0
  8. package/src/bundling/bootstrap-package-paths.js +5 -0
  9. package/src/bundling/bundle.d.ts +78 -0
  10. package/src/bundling/bundle.js +130 -0
  11. package/src/bundling/runtime-alias-map.d.ts +12 -0
  12. package/src/bundling/runtime-alias-map.js +110 -0
  13. package/src/bundling/runtime-bundle.d.ts +70 -0
  14. package/src/bundling/runtime-bundle.js +233 -0
  15. package/src/{utils/react-dom-runtime-interop-plugin.d.ts → bundling/runtime-interop-plugin.d.ts} +1 -1
  16. package/src/bundling/runtime-interop-plugin.js +32 -0
  17. package/src/bundling/runtime-mode.d.ts +1 -0
  18. package/src/bundling/runtime-mode.js +10 -0
  19. package/src/bundling/runtime-modules.d.ts +21 -0
  20. package/src/bundling/runtime-modules.js +28 -0
  21. package/src/client-graph/ast-transform-eco-page.d.ts +10 -0
  22. package/src/client-graph/ast-transform-eco-page.js +71 -0
  23. package/src/client-graph/ast-transform-import-edits.d.ts +13 -0
  24. package/src/client-graph/ast-transform-import-edits.js +75 -0
  25. package/src/client-graph/ast-transform-walk-imports.d.ts +20 -0
  26. package/src/client-graph/ast-transform-walk-imports.js +105 -0
  27. package/src/client-graph/ast-transform.d.ts +12 -0
  28. package/src/client-graph/ast-transform.js +91 -0
  29. package/src/client-graph/ast-walk.d.ts +10 -0
  30. package/src/client-graph/ast-walk.js +26 -0
  31. package/src/client-graph/boundary-plugin-read-file-inline.d.ts +7 -0
  32. package/src/client-graph/boundary-plugin-read-file-inline.js +43 -0
  33. package/src/client-graph/boundary-plugin-transform.d.ts +16 -0
  34. package/src/client-graph/boundary-plugin-transform.js +31 -0
  35. package/src/client-graph/boundary-plugin.d.ts +23 -0
  36. package/src/client-graph/boundary-plugin.js +177 -0
  37. package/src/client-graph/component-config-traversal.d.ts +36 -0
  38. package/src/client-graph/component-config-traversal.js +77 -0
  39. package/src/{utils → client-graph}/declared-modules.d.ts +1 -1
  40. package/src/client-graph/declared-modules.js +69 -0
  41. package/src/client-graph/module-classification.d.ts +3 -0
  42. package/src/client-graph/module-classification.js +43 -0
  43. package/src/client-graph/reachability-analyzer.d.ts +26 -0
  44. package/src/client-graph/reachability-analyzer.js +55 -0
  45. package/src/client-graph/reachability-client-roots.d.ts +8 -0
  46. package/src/client-graph/reachability-client-roots.js +59 -0
  47. package/src/client-graph/reachability-export-names.d.ts +5 -0
  48. package/src/client-graph/reachability-export-names.js +34 -0
  49. package/src/client-graph/reachability-fallback-roots.d.ts +3 -0
  50. package/src/client-graph/reachability-fallback-roots.js +71 -0
  51. package/src/client-graph/reachability-preload.d.ts +10 -0
  52. package/src/client-graph/reachability-preload.js +30 -0
  53. package/src/client-graph/reachability-top-level-index.d.ts +14 -0
  54. package/src/client-graph/reachability-top-level-index.js +93 -0
  55. package/src/client-graph/reachability-traverse.d.ts +7 -0
  56. package/src/client-graph/reachability-traverse.js +201 -0
  57. package/src/client-graph/specifier-classification.d.ts +74 -0
  58. package/src/client-graph/specifier-classification.js +191 -0
  59. package/src/content/collection-component-cache.d.ts +25 -0
  60. package/src/content/collection-component-cache.js +62 -0
  61. package/src/{router-adapter.d.ts → contracts/router-adapter.d.ts} +7 -14
  62. package/src/contracts/router-adapter.js +6 -0
  63. package/src/dev-transform/react-dev-transform-contributor.d.ts +17 -0
  64. package/src/dev-transform/react-dev-transform-contributor.js +22 -0
  65. package/src/hmr/hmr-strategy-process.d.ts +34 -0
  66. package/src/hmr/hmr-strategy-process.js +83 -0
  67. package/src/hmr/hmr-strategy.d.ts +67 -0
  68. package/src/hmr/hmr-strategy.js +306 -0
  69. package/src/{services/react-hmr-page-metadata-cache.d.ts → hmr/page-metadata-cache.d.ts} +6 -2
  70. package/src/hmr/page-metadata-cache.js +44 -0
  71. package/src/hmr/react-hmr-dev-transform-plugins.d.ts +22 -0
  72. package/src/hmr/react-hmr-dev-transform-plugins.js +19 -0
  73. package/src/hydration/assert-no-bare-ecopages-imports.d.ts +4 -0
  74. package/src/hydration/assert-no-bare-ecopages-imports.js +7 -0
  75. package/src/hydration/bootstrap-imports.d.ts +25 -0
  76. package/src/hydration/bootstrap-imports.js +33 -0
  77. package/src/hydration/browser/island-hydration.d.ts +82 -0
  78. package/src/hydration/browser/island-hydration.js +251 -0
  79. package/src/hydration/browser/page-hydration-hmr.d.ts +11 -0
  80. package/src/hydration/browser/page-hydration-hmr.js +56 -0
  81. package/src/hydration/browser/page-hydration-module.d.ts +8 -0
  82. package/src/hydration/browser/page-hydration-module.js +17 -0
  83. package/src/hydration/browser/page-hydration.d.ts +54 -0
  84. package/src/hydration/browser/page-hydration.js +177 -0
  85. package/src/hydration/compiled-page-hydration-options.d.ts +20 -0
  86. package/src/hydration/compiled-page-hydration-options.js +1 -0
  87. package/src/hydration/hydration-asset.d.ts +127 -0
  88. package/src/hydration/hydration-asset.js +379 -0
  89. package/src/hydration/hydration-lifecycle.test.browser.d.ts +1 -0
  90. package/src/hydration/hydration-lifecycle.test.browser.js +461 -0
  91. package/src/hydration/hydration-page-entry-source.d.ts +5 -0
  92. package/src/hydration/hydration-page-entry-source.js +87 -0
  93. package/src/hydration/hydration-script-compiler.d.ts +48 -0
  94. package/src/hydration/hydration-script-compiler.js +213 -0
  95. package/src/hydration/page-data-manifest.d.ts +58 -0
  96. package/src/hydration/page-data-manifest.js +97 -0
  97. package/src/hydration/page-data-reader.d.ts +17 -0
  98. package/src/hydration/page-data-reader.js +31 -0
  99. package/src/hydration/page-payload.d.ts +68 -0
  100. package/src/hydration/page-payload.js +106 -0
  101. package/src/hydration/serialize-page-data-script.d.ts +27 -0
  102. package/src/hydration/serialize-page-data-script.js +30 -0
  103. package/src/mdx/mdx-config-dependency.d.ts +37 -0
  104. package/src/mdx/mdx-config-dependency.js +107 -0
  105. package/src/mdx/mdx-loader-plugin.d.ts +8 -0
  106. package/src/mdx/mdx-loader-plugin.js +11 -0
  107. package/src/page/page-module.d.ts +46 -0
  108. package/src/page/page-module.js +74 -0
  109. package/src/plugin/react.constants.d.ts +1 -0
  110. package/src/plugin/react.constants.js +1 -0
  111. package/src/plugin/react.plugin.d.ts +71 -0
  112. package/src/plugin/react.plugin.js +210 -0
  113. package/src/plugin/react.types.d.ts +106 -0
  114. package/src/plugin/react.types.js +1 -0
  115. package/src/render/component-ownership.d.ts +49 -0
  116. package/src/render/component-ownership.js +47 -0
  117. package/src/render/component-ssr.d.ts +59 -0
  118. package/src/render/component-ssr.js +76 -0
  119. package/src/render/eco-embed.d.ts +11 -0
  120. package/src/render/eco-embed.js +9 -0
  121. package/src/render/errors.d.ts +16 -0
  122. package/src/render/errors.js +23 -0
  123. package/src/render/html-boundary.js +59 -0
  124. package/src/render/layout-compose.d.ts +66 -0
  125. package/src/render/layout-compose.js +134 -0
  126. package/src/render/react-renderer.d.ts +114 -0
  127. package/src/render/react-renderer.js +490 -0
  128. package/src/render/react-runtime.d.ts +13 -0
  129. package/src/render/react-runtime.js +26 -0
  130. package/src/render/unified-layout-composition.d.ts +22 -0
  131. package/src/render/unified-layout-composition.js +31 -0
  132. package/src/runtime/use-sync-external-store-with-selector.d.ts +3 -0
  133. package/src/runtime/use-sync-external-store-with-selector.js +54 -0
  134. package/CHANGELOG.md +0 -29
  135. package/src/react-hmr-strategy.d.ts +0 -148
  136. package/src/react-hmr-strategy.js +0 -313
  137. package/src/react-renderer.d.ts +0 -213
  138. package/src/react-renderer.js +0 -654
  139. package/src/react.plugin.d.ts +0 -147
  140. package/src/react.plugin.js +0 -146
  141. package/src/router-adapter.js +0 -0
  142. package/src/services/react-bundle.service.d.ts +0 -47
  143. package/src/services/react-bundle.service.js +0 -93
  144. package/src/services/react-hmr-page-metadata-cache.js +0 -35
  145. package/src/services/react-hydration-asset.service.d.ts +0 -76
  146. package/src/services/react-hydration-asset.service.js +0 -210
  147. package/src/services/react-page-module.service.d.ts +0 -83
  148. package/src/services/react-page-module.service.js +0 -162
  149. package/src/services/react-runtime-bundle.service.d.ts +0 -40
  150. package/src/services/react-runtime-bundle.service.js +0 -130
  151. package/src/utils/client-graph-boundary-plugin.d.ts +0 -43
  152. package/src/utils/client-graph-boundary-plugin.js +0 -494
  153. package/src/utils/client-only.js +0 -19
  154. package/src/utils/declared-modules.js +0 -59
  155. package/src/utils/dynamic.js +0 -12
  156. package/src/utils/hmr-scripts.d.ts +0 -18
  157. package/src/utils/hmr-scripts.js +0 -31
  158. package/src/utils/html-boundary.js +0 -55
  159. package/src/utils/hydration-scripts.d.ts +0 -86
  160. package/src/utils/hydration-scripts.js +0 -285
  161. package/src/utils/reachability-analyzer.d.ts +0 -66
  162. package/src/utils/reachability-analyzer.js +0 -339
  163. package/src/utils/react-dom-runtime-interop-plugin.js +0 -29
  164. package/src/utils/react-mdx-loader-plugin.d.ts +0 -3
  165. package/src/utils/react-mdx-loader-plugin.js +0 -45
  166. package/src/utils/react-runtime-specifier-map.d.ts +0 -6
  167. package/src/utils/react-runtime-specifier-map.js +0 -37
  168. package/src/utils/use-sync-external-store-shim-plugin.d.ts +0 -5
  169. package/src/utils/use-sync-external-store-shim-plugin.js +0 -41
  170. /package/src/{utils → app}/client-only.d.ts +0 -0
  171. /package/src/{utils → app}/dynamic.d.ts +0 -0
  172. /package/src/{declarations.d.ts → contracts/declarations.d.ts} +0 -0
  173. /package/src/{utils → render}/html-boundary.d.ts +0 -0
@@ -1,339 +0,0 @@
1
- import { parseSync } from "oxc-parser";
2
- import { extname } from "node:path";
3
- function parserLanguageForFile(filename) {
4
- const extension = extname(filename).toLowerCase();
5
- if (extension === ".tsx") return "tsx";
6
- if (extension === ".ts") return "ts";
7
- if (extension === ".jsx") return "jsx";
8
- return "js";
9
- }
10
- function analyzeReachability(source, filename, program, explicitlyRequestedExports) {
11
- let resolvedProgram;
12
- if (program) {
13
- resolvedProgram = program;
14
- } else {
15
- let result;
16
- try {
17
- result = parseSync(filename, source, {
18
- sourceType: "module",
19
- lang: parserLanguageForFile(filename)
20
- });
21
- } catch {
22
- return {
23
- reachableImports: /* @__PURE__ */ new Map(),
24
- reachableDeclarations: /* @__PURE__ */ new Set(),
25
- unreachableSideEffectImports: [],
26
- isFallbackRoots: true,
27
- analyzed: false
28
- };
29
- }
30
- resolvedProgram = result.program;
31
- }
32
- const topLevelImports = [];
33
- const topLevelDeclarations = /* @__PURE__ */ new Map();
34
- const potentialClientRoots = [];
35
- for (const statement of resolvedProgram.body) {
36
- if (statement.type === "ImportDeclaration") {
37
- const specifier = statement.source.value;
38
- const bindings = /* @__PURE__ */ new Map();
39
- if (!statement.specifiers || statement.specifiers.length === 0) {
40
- topLevelImports.push({ node: statement, specifier, bindings, isSideEffect: true });
41
- } else {
42
- for (const spec of statement.specifiers) {
43
- if (spec.type === "ImportDefaultSpecifier") {
44
- bindings.set(spec.local.name, "default");
45
- } else if (spec.type === "ImportNamespaceSpecifier") {
46
- bindings.set(spec.local.name, "*");
47
- } else if (spec.type === "ImportSpecifier") {
48
- const importedName = spec.imported.type === "Identifier" ? spec.imported.name : spec.imported.value;
49
- bindings.set(spec.local.name, importedName);
50
- }
51
- }
52
- topLevelImports.push({ node: statement, specifier, bindings, isSideEffect: false });
53
- }
54
- } else if (statement.type === "VariableDeclaration") {
55
- for (const decl of statement.declarations) {
56
- if (decl.id.type === "Identifier") {
57
- topLevelDeclarations.set(decl.id.name, statement);
58
- checkPotentialClientRoot(decl.init);
59
- }
60
- }
61
- } else if (statement.type === "FunctionDeclaration" || statement.type === "ClassDeclaration") {
62
- if (statement.id && statement.id.type === "Identifier") {
63
- topLevelDeclarations.set(statement.id.name, statement);
64
- }
65
- } else if (statement.type === "ExportNamedDeclaration") {
66
- if (statement.declaration) {
67
- const decl = statement.declaration;
68
- if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
69
- if (decl.id && decl.id.type === "Identifier") {
70
- topLevelDeclarations.set(decl.id.name, statement);
71
- }
72
- } else if (decl.type === "VariableDeclaration") {
73
- for (const v of decl.declarations) {
74
- if (v.id.type === "Identifier") {
75
- topLevelDeclarations.set(v.id.name, statement);
76
- checkPotentialClientRoot(v.init);
77
- }
78
- }
79
- }
80
- }
81
- } else if (statement.type === "ExportDefaultDeclaration") {
82
- checkPotentialClientRoot(statement.declaration);
83
- } else if (statement.type === "ExpressionStatement") {
84
- checkPotentialClientRoot(statement.expression);
85
- } else if (statement.type === "ExportAllDeclaration" && statement.source) {
86
- potentialClientRoots.push(statement);
87
- }
88
- }
89
- function checkPotentialClientRoot(node) {
90
- if (!node || typeof node !== "object") return;
91
- if (node.type === "CallExpression" && node.callee.type === "MemberExpression") {
92
- const obj = node.callee.object;
93
- const prop = node.callee.property;
94
- if (obj.type === "Identifier" && obj.name === "eco" && prop.type === "Identifier" && (prop.name === "page" || prop.name === "component")) {
95
- potentialClientRoots.push(node.callee);
96
- const arg = node.arguments[0];
97
- if (arg && arg.type === "ObjectExpression") {
98
- for (const prop2 of arg.properties) {
99
- if (prop2.type === "Property" && prop2.key.type === "Identifier") {
100
- if ([
101
- "render",
102
- "errorBoundary",
103
- "loadingFallback",
104
- "clientScripts",
105
- "dependencies"
106
- ].includes(prop2.key.name)) {
107
- potentialClientRoots.push(prop2.value);
108
- }
109
- }
110
- }
111
- }
112
- }
113
- } else if (node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "dynamic") {
114
- potentialClientRoots.push(node);
115
- }
116
- }
117
- function getExportedName(specifier) {
118
- if (specifier?.exported?.type === "Identifier") return specifier.exported.name;
119
- if (typeof specifier?.exported?.value === "string") return specifier.exported.value;
120
- if (specifier?.local?.type === "Identifier") return specifier.local.name;
121
- if (typeof specifier?.local?.value === "string") return specifier.local.value;
122
- return void 0;
123
- }
124
- function getReexportedImportName(specifier) {
125
- if (specifier?.local?.type === "Identifier") return specifier.local.name;
126
- if (typeof specifier?.local?.value === "string") return specifier.local.value;
127
- if (specifier?.imported?.type === "Identifier") return specifier.imported.name;
128
- if (typeof specifier?.imported?.value === "string") return specifier.imported.value;
129
- return getExportedName(specifier);
130
- }
131
- function getLocalExportName(specifier) {
132
- if (specifier?.local?.type === "Identifier") return specifier.local.name;
133
- if (typeof specifier?.local?.value === "string") return specifier.local.value;
134
- return void 0;
135
- }
136
- function isExplicitlyRequestedExport(name) {
137
- if (explicitlyRequestedExports === "*") return true;
138
- return explicitlyRequestedExports?.has(name) ?? false;
139
- }
140
- let isFallbackRoots = false;
141
- if (potentialClientRoots.length === 0) {
142
- if (explicitlyRequestedExports) {
143
- for (const node of resolvedProgram.body) {
144
- if (node.type === "ExportNamedDeclaration") {
145
- const exportNode = node;
146
- if (exportNode.source && exportNode.specifiers?.length) {
147
- const hasRequestedReexport = exportNode.specifiers.some((specifier) => {
148
- const exportedName = getExportedName(specifier);
149
- return exportedName ? isExplicitlyRequestedExport(exportedName) : false;
150
- });
151
- if (hasRequestedReexport) {
152
- potentialClientRoots.push(node);
153
- }
154
- continue;
155
- }
156
- if (exportNode.declaration?.type === "FunctionDeclaration" || exportNode.declaration?.type === "ClassDeclaration") {
157
- const declarationName = exportNode.declaration.id?.name;
158
- if (declarationName && isExplicitlyRequestedExport(declarationName)) {
159
- potentialClientRoots.push(node);
160
- }
161
- continue;
162
- }
163
- if (exportNode.declaration?.type === "VariableDeclaration") {
164
- const hasRequestedDeclaration = exportNode.declaration.declarations.some(
165
- (declaration) => declaration.id?.type === "Identifier" && isExplicitlyRequestedExport(declaration.id.name)
166
- );
167
- if (hasRequestedDeclaration) {
168
- potentialClientRoots.push(node);
169
- }
170
- continue;
171
- }
172
- if (exportNode.specifiers?.length) {
173
- const hasRequestedSpecifier = exportNode.specifiers.some((specifier) => {
174
- const exportedName = getExportedName(specifier);
175
- return exportedName ? isExplicitlyRequestedExport(exportedName) : false;
176
- });
177
- if (hasRequestedSpecifier) {
178
- potentialClientRoots.push(node);
179
- }
180
- }
181
- } else if (node.type === "ExportDefaultDeclaration") {
182
- if (isExplicitlyRequestedExport("default")) {
183
- potentialClientRoots.push(node);
184
- }
185
- } else if (node.type === "ExportAllDeclaration") {
186
- if (explicitlyRequestedExports === "*") {
187
- potentialClientRoots.push(node);
188
- }
189
- }
190
- }
191
- } else {
192
- isFallbackRoots = true;
193
- for (const node of resolvedProgram.body) {
194
- if (node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportAllDeclaration") {
195
- potentialClientRoots.push(node);
196
- }
197
- }
198
- }
199
- }
200
- const reachableImports = /* @__PURE__ */ new Map();
201
- const reachableDeclarations = /* @__PURE__ */ new Set();
202
- const queue = [...potentialClientRoots];
203
- const visitedNodes = /* @__PURE__ */ new Set();
204
- function markImportReachable(specifier, importedName) {
205
- let current = reachableImports.get(specifier);
206
- if (current === "*") return;
207
- if (importedName === "*") {
208
- reachableImports.set(specifier, "*");
209
- } else {
210
- if (!current) {
211
- current = /* @__PURE__ */ new Set();
212
- reachableImports.set(specifier, current);
213
- }
214
- current.add(importedName);
215
- }
216
- }
217
- function checkIdentifier(name) {
218
- if (topLevelDeclarations.has(name)) {
219
- const declNode = topLevelDeclarations.get(name);
220
- if (!reachableDeclarations.has(declNode)) {
221
- reachableDeclarations.add(declNode);
222
- queue.push(declNode);
223
- }
224
- }
225
- for (const imp of topLevelImports) {
226
- if (imp.bindings.has(name)) {
227
- markImportReachable(imp.specifier, imp.bindings.get(name));
228
- }
229
- }
230
- }
231
- function traverse(node, localScope) {
232
- if (!node || typeof node !== "object") return;
233
- if (visitedNodes.has(node)) return;
234
- visitedNodes.add(node);
235
- if (Array.isArray(node)) {
236
- for (const child of node) traverse(child, localScope);
237
- return;
238
- }
239
- const currentScope = localScope;
240
- if (node.type === "ExportAllDeclaration" && typeof node.source?.value === "string") {
241
- markImportReachable(node.source.value, "*");
242
- return;
243
- }
244
- if (node.type === "ExportNamedDeclaration" && typeof node.source?.value === "string") {
245
- for (const specifier of node.specifiers ?? []) {
246
- const importedName = getReexportedImportName(specifier);
247
- if (importedName) {
248
- markImportReachable(node.source.value, importedName);
249
- }
250
- }
251
- return;
252
- }
253
- if (node.type === "ExportNamedDeclaration" && !node.source && explicitlyRequestedExports && node.specifiers?.length) {
254
- for (const specifier of node.specifiers) {
255
- const exportedName = getExportedName(specifier);
256
- if (!exportedName || !isExplicitlyRequestedExport(exportedName)) {
257
- continue;
258
- }
259
- const localName = getLocalExportName(specifier);
260
- if (localName && !currentScope.has(localName)) {
261
- checkIdentifier(localName);
262
- }
263
- }
264
- return;
265
- }
266
- if (node.type === "Identifier" || node.type === "JSXIdentifier" && /^[A-Z]/.test(node.name)) {
267
- if (!currentScope.has(node.name)) {
268
- checkIdentifier(node.name);
269
- }
270
- } else if (node.type === "MemberExpression") {
271
- traverse(node.object, currentScope);
272
- if (node.computed) {
273
- traverse(node.property, currentScope);
274
- }
275
- return;
276
- } else if (node.type === "Property") {
277
- if (node.computed) traverse(node.key, currentScope);
278
- traverse(node.value, currentScope);
279
- return;
280
- } else if (node.type === "JSXOpeningElement" || node.type === "JSXClosingElement") {
281
- traverse(node.name, currentScope);
282
- if (node.attributes) {
283
- for (const attr of node.attributes) traverse(attr, currentScope);
284
- }
285
- return;
286
- } else if (node.type === "JSXIdentifier") {
287
- if (/^[A-Z]/.test(node.name) && !currentScope.has(node.name)) {
288
- checkIdentifier(node.name);
289
- }
290
- } else if (node.type === "JSXMemberExpression") {
291
- traverse(node.object, currentScope);
292
- return;
293
- } else if (node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "dynamic") {
294
- const arg = node.arguments[0];
295
- if (arg && (arg.type === "ArrowFunctionExpression" || arg.type === "FunctionExpression")) {
296
- const body = arg.body;
297
- if (body.type === "ImportExpression" && body.source.type === "Literal") {
298
- markImportReachable(body.source.value, "*");
299
- }
300
- }
301
- } else if (node.type === "ImportExpression" && node.source.type === "Literal") {
302
- markImportReachable(node.source.value, "*");
303
- }
304
- if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration") {
305
- const newScope = new Set(currentScope);
306
- if (node.id && node.id.type === "Identifier") newScope.add(node.id.name);
307
- if (node.params && node.params.items) {
308
- for (const p of node.params.items) {
309
- if (p.pattern && p.pattern.type === "Identifier") {
310
- newScope.add(p.pattern.name);
311
- }
312
- }
313
- }
314
- traverse(node.body, newScope);
315
- return;
316
- }
317
- for (const key in node) {
318
- if (key !== "type" && key !== "start" && key !== "end") {
319
- traverse(node[key], currentScope);
320
- }
321
- }
322
- }
323
- while (queue.length > 0) {
324
- const root = queue.shift();
325
- traverse(root, /* @__PURE__ */ new Set());
326
- }
327
- const unreachableSideEffectImports = topLevelImports.filter((imp) => imp.isSideEffect && !reachableImports.has(imp.specifier)).map((imp) => imp.node);
328
- return {
329
- reachableImports,
330
- reachableDeclarations,
331
- unreachableSideEffectImports,
332
- isFallbackRoots,
333
- analyzed: true
334
- };
335
- }
336
- export {
337
- analyzeReachability,
338
- parserLanguageForFile
339
- };
@@ -1,29 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- function createReactDomRuntimeInteropPlugin(options) {
4
- const reactDomFileFilter = /[\\/]react-dom[\\/].*\.js$/;
5
- const reactRequirePattern = /\brequire\((['"])react\1\)/g;
6
- const reactSpecifier = options?.reactSpecifier ?? "react";
7
- return {
8
- name: options?.name ?? "react-dom-runtime-interop",
9
- setup(build) {
10
- build.onLoad({ filter: reactDomFileFilter }, (args) => {
11
- const content = fs.readFileSync(args.path, "utf-8");
12
- if (!reactRequirePattern.test(content)) {
13
- return void 0;
14
- }
15
- reactRequirePattern.lastIndex = 0;
16
- const rewritten = content.replace(reactRequirePattern, "__ecopages_react_runtime");
17
- return {
18
- contents: `import * as __ecopages_react_runtime from '${reactSpecifier}';
19
- ${rewritten}`,
20
- loader: "js",
21
- resolveDir: path.dirname(args.path)
22
- };
23
- });
24
- }
25
- };
26
- }
27
- export {
28
- createReactDomRuntimeInteropPlugin
29
- };
@@ -1,3 +0,0 @@
1
- import type { EcoBuildPlugin } from '@ecopages/core/build/build-types';
2
- import { type CompileOptions } from '@mdx-js/mdx';
3
- export declare function createReactMdxLoaderPlugin(compilerOptions?: CompileOptions): EcoBuildPlugin;
@@ -1,45 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import path from "node:path";
3
- import { compile } from "@mdx-js/mdx";
4
- import sourceMap from "source-map";
5
- import { VFile } from "vfile";
6
- function resolveCompileFormat(filePath, compilerOptions) {
7
- const configuredFormat = compilerOptions?.format;
8
- if (configuredFormat && configuredFormat !== "detect") {
9
- return configuredFormat;
10
- }
11
- return path.extname(filePath).toLowerCase() === ".md" ? "mdx" : configuredFormat;
12
- }
13
- function createReactMdxLoaderPlugin(compilerOptions) {
14
- const mdxExtensions = compilerOptions?.mdxExtensions ?? [".mdx"];
15
- const mdExtensions = compilerOptions?.mdExtensions ?? [];
16
- const allExtensions = [...mdxExtensions, ...mdExtensions];
17
- const escapedExts = allExtensions.map((ext) => ext.replace(".", "\\."));
18
- const filter = new RegExp(`(${escapedExts.join("|")})(\\?.*)?$`);
19
- return {
20
- name: "react-mdx-loader",
21
- setup(build) {
22
- build.onLoad({ filter }, async (args) => {
23
- const filePath = args.path.includes("?") ? args.path.split("?")[0] : args.path;
24
- const source = readFileSync(filePath, "utf-8");
25
- const file = new VFile({ path: filePath, value: source });
26
- const compiled = await compile(file, {
27
- ...compilerOptions,
28
- format: resolveCompileFormat(filePath, compilerOptions),
29
- SourceMapGenerator: sourceMap.SourceMapGenerator
30
- });
31
- const inlineSourceMap = compiled.map ? `
32
- //# sourceMappingURL=data:application/json;base64,${Buffer.from(JSON.stringify(compiled.map)).toString("base64")}
33
- ` : "";
34
- return {
35
- contents: `${String(compiled.value)}${inlineSourceMap}`,
36
- loader: compilerOptions?.jsx ? "jsx" : "js",
37
- resolveDir: path.dirname(args.path)
38
- };
39
- });
40
- }
41
- };
42
- }
43
- export {
44
- createReactMdxLoaderPlugin
45
- };
@@ -1,6 +0,0 @@
1
- import type { ReactRouterAdapter } from '../router-adapter.js';
2
- import type { ReactRuntimeImports } from '../services/react-runtime-bundle.service.js';
3
- export declare const REACT_RUNTIME_SPECIFIERS: readonly ["react", "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime", "react-dom/client"];
4
- export declare function buildReactRuntimeSpecifierMap(runtimeImports: ReactRuntimeImports, routerAdapter?: ReactRouterAdapter): Record<string, string>;
5
- export declare function getReactRuntimeExternalSpecifiers(): string[];
6
- export declare function getReactClientGraphAllowSpecifiers(runtimeSpecifiers: Iterable<string>, routerAdapter?: ReactRouterAdapter): string[];
@@ -1,37 +0,0 @@
1
- const REACT_RUNTIME_SPECIFIERS = [
2
- "react",
3
- "react-dom",
4
- "react/jsx-runtime",
5
- "react/jsx-dev-runtime",
6
- "react-dom/client"
7
- ];
8
- function buildReactRuntimeSpecifierMap(runtimeImports, routerAdapter) {
9
- const map = {
10
- react: runtimeImports.react,
11
- "react/jsx-runtime": runtimeImports.reactJsxRuntime,
12
- "react/jsx-dev-runtime": runtimeImports.reactJsxDevRuntime,
13
- "react-dom": runtimeImports.reactDom,
14
- "react-dom/client": runtimeImports.reactDomClient
15
- };
16
- if (routerAdapter && runtimeImports.router) {
17
- map[routerAdapter.importMapKey] = runtimeImports.router;
18
- }
19
- return map;
20
- }
21
- function getReactRuntimeExternalSpecifiers() {
22
- return [...REACT_RUNTIME_SPECIFIERS];
23
- }
24
- function getReactClientGraphAllowSpecifiers(runtimeSpecifiers, routerAdapter) {
25
- return [
26
- "@ecopages/core",
27
- ...REACT_RUNTIME_SPECIFIERS,
28
- ...routerAdapter ? [routerAdapter.importMapKey] : [],
29
- ...Array.from(runtimeSpecifiers)
30
- ];
31
- }
32
- export {
33
- REACT_RUNTIME_SPECIFIERS,
34
- buildReactRuntimeSpecifierMap,
35
- getReactClientGraphAllowSpecifiers,
36
- getReactRuntimeExternalSpecifiers
37
- };
@@ -1,5 +0,0 @@
1
- import type { EcoBuildPlugin } from '@ecopages/core/build/build-types';
2
- export declare function createUseSyncExternalStoreShimPlugin(options?: {
3
- name?: string;
4
- namespace?: string;
5
- }): EcoBuildPlugin;
@@ -1,41 +0,0 @@
1
- function createUseSyncExternalStoreShimPlugin(options) {
2
- const namespace = options?.namespace ?? "ecopages-react-use-sync-external-store-shim";
3
- return {
4
- name: options?.name ?? "react-use-sync-external-store-shim",
5
- setup(build) {
6
- build.onResolve({ filter: /^use-sync-external-store\/shim(?:\/index\.js)?$/ }, () => ({
7
- path: "use-sync-external-store/shim",
8
- namespace
9
- }));
10
- build.onLoad({ filter: /^use-sync-external-store\/shim$/, namespace }, () => ({
11
- contents: "export { useSyncExternalStore } from 'react';",
12
- loader: "js"
13
- }));
14
- build.onLoad({ filter: /[\\/]use-sync-external-store[\\/]shim[\\/]index\.js$/ }, () => ({
15
- contents: "export { useSyncExternalStore } from 'react';",
16
- loader: "js"
17
- }));
18
- build.onLoad(
19
- {
20
- filter: /[\\/]use-sync-external-store[\\/]cjs[\\/]use-sync-external-store-shim\.development\.js$/
21
- },
22
- () => ({
23
- contents: "export { useSyncExternalStore } from 'react';",
24
- loader: "js"
25
- })
26
- );
27
- build.onLoad(
28
- {
29
- filter: /[\\/]use-sync-external-store[\\/]cjs[\\/]use-sync-external-store-shim\.production\.js$/
30
- },
31
- () => ({
32
- contents: "export { useSyncExternalStore } from 'react';",
33
- loader: "js"
34
- })
35
- );
36
- }
37
- };
38
- }
39
- export {
40
- createUseSyncExternalStoreShimPlugin
41
- };
File without changes
File without changes
File without changes