@bleedingdev/modern-js-app-tools 3.4.0-ultramodern.2 → 3.4.0-ultramodern.20

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 (41) hide show
  1. package/dist/cjs/builder/generator/getBuilderEnvironments.js +45 -5
  2. package/dist/cjs/builder/generator/index.js +1 -0
  3. package/dist/cjs/builder/shared/builderPlugins/adapterLazyCompilation.js +74 -0
  4. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +3 -28
  5. package/dist/cjs/builder/shared/builderPlugins/index.js +13 -6
  6. package/dist/cjs/builder/shared/lazyCompilation.js +11 -3
  7. package/dist/cjs/plugins/deploy/index.js +9 -1
  8. package/dist/cjs/plugins/deploy/platforms/cloudflare.js +112 -27
  9. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +14 -1
  10. package/dist/cjs/rsbuild.js +7 -3
  11. package/dist/cjs/utils/initAppContext.js +12 -1
  12. package/dist/esm/builder/generator/getBuilderEnvironments.mjs +45 -5
  13. package/dist/esm/builder/generator/index.mjs +2 -1
  14. package/dist/esm/builder/shared/builderPlugins/adapterLazyCompilation.mjs +36 -0
  15. package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +4 -29
  16. package/dist/esm/builder/shared/builderPlugins/index.mjs +1 -0
  17. package/dist/esm/builder/shared/lazyCompilation.mjs +6 -4
  18. package/dist/esm/plugins/deploy/index.mjs +9 -1
  19. package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +112 -27
  20. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +14 -1
  21. package/dist/esm/rsbuild.mjs +7 -3
  22. package/dist/esm/utils/initAppContext.mjs +12 -1
  23. package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +45 -5
  24. package/dist/esm-node/builder/generator/index.mjs +2 -1
  25. package/dist/esm-node/builder/shared/builderPlugins/adapterLazyCompilation.mjs +37 -0
  26. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +4 -29
  27. package/dist/esm-node/builder/shared/builderPlugins/index.mjs +1 -0
  28. package/dist/esm-node/builder/shared/lazyCompilation.mjs +6 -4
  29. package/dist/esm-node/plugins/deploy/index.mjs +9 -1
  30. package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +112 -27
  31. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +14 -1
  32. package/dist/esm-node/rsbuild.mjs +7 -3
  33. package/dist/esm-node/utils/initAppContext.mjs +12 -1
  34. package/dist/types/builder/shared/builderPlugins/adapterLazyCompilation.d.ts +3 -0
  35. package/dist/types/builder/shared/builderPlugins/index.d.ts +1 -0
  36. package/dist/types/builder/shared/lazyCompilation.d.ts +7 -5
  37. package/dist/types/builder/shared/types.d.ts +3 -3
  38. package/dist/types/rsbuild.d.ts +1 -0
  39. package/dist/types/types/config/cloudflareDeploy.d.ts +14 -0
  40. package/dist/types/types/config/deploy.d.ts +21 -2
  41. package/package.json +19 -27
@@ -137,13 +137,53 @@ function getCloudflareWorkerNodeExternals() {
137
137
  function getEffectBffEntry(normalizedConfig, appContext) {
138
138
  if (!normalizedConfig.bff || 'hono' === normalizedConfig.bff.runtimeFramework) return;
139
139
  const configuredEntry = normalizedConfig.bff.effect?.entry;
140
- const entryWithoutOrWithExtension = configuredEntry ? external_node_path_default().isAbsolute(configuredEntry) ? configuredEntry : external_node_path_default().resolve(appContext.appDirectory, configuredEntry) : external_node_path_default().resolve(appContext.apiDirectory, 'effect', 'index');
141
- return resolveJsOrTsEntry(entryWithoutOrWithExtension);
140
+ if (configuredEntry) {
141
+ const entryWithoutOrWithExtension = external_node_path_default().isAbsolute(configuredEntry) ? configuredEntry : external_node_path_default().resolve(appContext.appDirectory, configuredEntry);
142
+ return resolveJsOrTsEntry(entryWithoutOrWithExtension);
143
+ }
144
+ return resolveJsOrTsEntry(external_node_path_default().resolve(appContext.apiDirectory, 'index'));
142
145
  }
143
146
  function isCloudflareWorkerDeploy(normalizedConfig) {
144
147
  return normalizedConfig.deploy?.target === 'cloudflare' || 'cloudflare' === process.env.MODERNJS_DEPLOY;
145
148
  }
149
+ function getConsumingReactRuntimeAliases(appContext) {
150
+ const resolvePaths = [
151
+ appContext.appDirectory,
152
+ process.cwd()
153
+ ];
154
+ return {
155
+ react$: resolvePackageFile('react', 'index.js', resolvePaths),
156
+ 'react/jsx-runtime$': resolvePackageFile('react', 'jsx-runtime.js', resolvePaths),
157
+ 'react/jsx-dev-runtime$': resolvePackageFile('react', 'jsx-dev-runtime.js', resolvePaths),
158
+ 'react/compiler-runtime$': resolvePackageFile('react', 'compiler-runtime.js', resolvePaths)
159
+ };
160
+ }
161
+ function setResolvedAliases(alias, aliases) {
162
+ for (const [name, value] of Object.entries(aliases))setAliasIfPresent(alias, name, value);
163
+ }
164
+ function appendBundlerChain(config, handler) {
165
+ const bundlerChain = config.tools?.bundlerChain;
166
+ config.tools = {
167
+ ...config.tools,
168
+ bundlerChain: bundlerChain ? Array.isArray(bundlerChain) ? [
169
+ ...bundlerChain,
170
+ handler
171
+ ] : [
172
+ bundlerChain,
173
+ handler
174
+ ] : handler
175
+ };
176
+ }
177
+ function applySourceBuildReactRuntimeAliases(normalizedConfig, appContext, tempBuilderConfig) {
178
+ if (!normalizedConfig.experiments?.sourceBuild) return;
179
+ const aliases = getConsumingReactRuntimeAliases(appContext);
180
+ if (!Object.values(aliases).some(Boolean)) return;
181
+ appendBundlerChain(tempBuilderConfig, (chain)=>{
182
+ setResolvedAliases(chain.resolve.alias, aliases);
183
+ });
184
+ }
146
185
  function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig) {
186
+ applySourceBuildReactRuntimeAliases(normalizedConfig, appContext, tempBuilderConfig);
147
187
  const entries = {};
148
188
  const { entrypoints = [], checkedEntries } = appContext;
149
189
  for (const { entryName, internalEntry, entry } of entrypoints){
@@ -190,7 +230,7 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
190
230
  const useWorkerTarget = (0, utils_namespaceObject.isServiceWorker)(normalizedConfig);
191
231
  if (useWorkerTarget) {
192
232
  const useCloudflareModuleWorker = isCloudflareWorkerDeploy(normalizedConfig);
193
- const effectBffEntry = useCloudflareModuleWorker ? getEffectBffEntry(normalizedConfig, appContext) : void 0;
233
+ const effectApiEntry = useCloudflareModuleWorker ? getEffectBffEntry(normalizedConfig, appContext) : void 0;
194
234
  const tanstackRouterSsrServerFile = useCloudflareModuleWorker ? resolvePackageFile('@tanstack/router-core', 'dist/esm/ssr/ssr-server.js', [
195
235
  appContext.appDirectory,
196
236
  process.cwd()
@@ -232,10 +272,10 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
232
272
  const fsPromisesWorkerFile = useCloudflareModuleWorker ? getCloudflareWorkerCompatFile('cloudflare-worker-fs-promises.mjs') : void 0;
233
273
  const pathWorkerFile = useCloudflareModuleWorker ? getCloudflareWorkerCompatFile('cloudflare-worker-path.mjs') : void 0;
234
274
  const baseWorkerEntries = useCloudflareModuleWorker ? cloudflareWorkerServerEntries : serverEntries;
235
- const workerEntries = effectBffEntry ? {
275
+ const workerEntries = effectApiEntry ? {
236
276
  ...baseWorkerEntries,
237
277
  [BFF_EFFECT_WORKER_ENTRY_NAME]: [
238
- `${effectBffEntry}?${BFF_EFFECT_WORKER_RUNTIME_QUERY}`
278
+ `${effectApiEntry}?${BFF_EFFECT_WORKER_RUNTIME_QUERY}`
239
279
  ]
240
280
  } : baseWorkerEntries;
241
281
  environments[builder_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME] = {
@@ -70,6 +70,7 @@ async function generateBuilder(options, bundlerType) {
70
70
  async function applyBuilderPlugins(builder, options) {
71
71
  builder.addPlugins([
72
72
  (0, index_js_namespaceObject.builderPluginAdapterBasic)(options),
73
+ (0, index_js_namespaceObject.builderPluginAdapterLazyCompilation)(options),
73
74
  (0, index_js_namespaceObject.builderPluginAdapterSSR)(options),
74
75
  (0, index_js_namespaceObject.builderPluginAdapterHtml)(options),
75
76
  (0, index_js_namespaceObject.builderPluginAdapterPrecompress)(options),
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ builderPluginAdapterLazyCompilation: ()=>builderPluginAdapterLazyCompilation
32
+ });
33
+ const utils_namespaceObject = require("@modern-js/utils");
34
+ const external_lazyCompilation_js_namespaceObject = require("../lazyCompilation.js");
35
+ const builderPluginAdapterLazyCompilation = (options)=>({
36
+ name: 'builder-plugin-adapter-modern-lazy-compilation',
37
+ setup (api) {
38
+ api.modifyRsbuildConfig((config)=>{
39
+ const lazyCompilation = getRouteEagerLazyCompilation(options, config);
40
+ if (void 0 === lazyCompilation) return config;
41
+ return {
42
+ ...config,
43
+ dev: {
44
+ ...config.dev,
45
+ lazyCompilation
46
+ }
47
+ };
48
+ });
49
+ }
50
+ });
51
+ function getRouteEagerLazyCompilation(options, config) {
52
+ const current = config.dev?.lazyCompilation;
53
+ if (!current || (0, utils_namespaceObject.isUseRsc)(options.normalizedConfig)) return;
54
+ const plan = (0, external_lazyCompilation_js_namespaceObject.planRouteEagerLazyCompilation)(current, (0, external_lazyCompilation_js_namespaceObject.aggregateEagerRouteComponentFiles)(options.eagerRouteComponentFilesByEntry));
55
+ if (!plan.apply) {
56
+ if (plan.unresolvedByEntry) warnUnresolvedRouteComponents(options.appContext.appDirectory, plan.unresolvedByEntry);
57
+ return;
58
+ }
59
+ return plan.lazyCompilation;
60
+ }
61
+ const warnedLazyApps = new Set();
62
+ function warnUnresolvedRouteComponents(appDirectory, unresolvedByEntry) {
63
+ if (warnedLazyApps.has(appDirectory)) return;
64
+ warnedLazyApps.add(appDirectory);
65
+ const detail = Array.from(unresolvedByEntry).map(([entry, components])=>`${entry}: ${components.join(', ')}`).join('; ');
66
+ utils_namespaceObject.logger.warn(`[lazyCompilation] Skipped route-eager optimization because some route components could not be resolved to a file (${detail}). Lazy compilation may delay route rendering for these routes.`);
67
+ }
68
+ exports.builderPluginAdapterLazyCompilation = __webpack_exports__.builderPluginAdapterLazyCompilation;
69
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
70
+ "builderPluginAdapterLazyCompilation"
71
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
72
+ Object.defineProperty(exports, '__esModule', {
73
+ value: true
74
+ });
@@ -36,27 +36,18 @@ const core_namespaceObject = require("@rsbuild/core");
36
36
  const external_path_namespaceObject = require("path");
37
37
  const utils_js_namespaceObject = require("../../../plugins/analyze/utils.js");
38
38
  const index_js_namespaceObject = require("../bundlerPlugins/index.js");
39
- const external_lazyCompilation_js_namespaceObject = require("../lazyCompilation.js");
40
39
  const builderPluginAdapterSSR = (options)=>({
41
40
  name: 'builder-plugin-adapter-modern-ssr',
42
41
  setup (api) {
43
- const { normalizedConfig, appContext, eagerRouteComponentFilesByEntry } = options;
44
- api.modifyRsbuildConfig((config)=>{
45
- const merged = (0, core_namespaceObject.mergeRsbuildConfig)(config, {
42
+ const { normalizedConfig, appContext } = options;
43
+ api.modifyRsbuildConfig((config)=>(0, core_namespaceObject.mergeRsbuildConfig)(config, {
46
44
  html: {
47
45
  inject: isStreamingSSR(normalizedConfig) ? 'head' : void 0
48
46
  },
49
47
  server: {
50
48
  compress: isStreamingSSR(normalizedConfig) || (0, utils_namespaceObject.isUseRsc)(normalizedConfig) ? false : void 0
51
49
  }
52
- });
53
- const lazyCompilation = getSSRLazyCompilation(merged.dev?.lazyCompilation, normalizedConfig, appContext, eagerRouteComponentFilesByEntry);
54
- if (void 0 !== lazyCompilation) merged.dev = {
55
- ...merged.dev,
56
- lazyCompilation
57
- };
58
- return merged;
59
- });
50
+ }));
60
51
  api.modifyBundlerChain(async (chain, { target, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer, environment })=>{
61
52
  const builderConfig = environment.config;
62
53
  const { normalizedConfig } = options;
@@ -92,22 +83,6 @@ const isStreamingSSR = (userConfig)=>{
92
83
  }
93
84
  return false;
94
85
  };
95
- function getSSRLazyCompilation(current, normalizedConfig, appContext, eagerRouteComponentFilesByEntry) {
96
- if (!current || (0, utils_namespaceObject.isUseRsc)(normalizedConfig) || !isStreamingSSR(normalizedConfig)) return;
97
- const plan = (0, external_lazyCompilation_js_namespaceObject.planSSRLazyCompilation)(current, (0, external_lazyCompilation_js_namespaceObject.aggregateEagerRouteComponentFiles)(eagerRouteComponentFilesByEntry));
98
- if (!plan.apply) {
99
- if (plan.unresolvedByEntry) warnUnresolvedRouteComponents(appContext.appDirectory, plan.unresolvedByEntry);
100
- return;
101
- }
102
- return plan.lazyCompilation;
103
- }
104
- const warnedLazyApps = new Set();
105
- function warnUnresolvedRouteComponents(appDirectory, unresolvedByEntry) {
106
- if (warnedLazyApps.has(appDirectory)) return;
107
- warnedLazyApps.add(appDirectory);
108
- const detail = Array.from(unresolvedByEntry).map(([entry, comps])=>`${entry}: ${comps.join(', ')}`).join('; ');
109
- utils_namespaceObject.logger.warn(`[lazyCompilation] Skipped stream SSR route-eager optimization because some route components could not be resolved to a file (${detail}). Lazy compilation may break first-screen CSS/JS for these routes.`);
110
- }
111
86
  function applyAsyncChunkHtmlPlugin({ chain, modernConfig, HtmlBundlerPlugin }) {
112
87
  if (isStreamingSSR(modernConfig) || (0, utils_namespaceObject.isUseRsc)(modernConfig)) chain.plugin('html-async-chunk').use(index_js_namespaceObject.HtmlAsyncChunkPlugin, [
113
88
  HtmlBundlerPlugin
@@ -6,6 +6,9 @@ var __webpack_modules__ = {
6
6
  "./adapterHtml" (module) {
7
7
  module.exports = require("./adapterHtml.js");
8
8
  },
9
+ "./adapterLazyCompilation" (module) {
10
+ module.exports = require("./adapterLazyCompilation.js");
11
+ },
9
12
  "./adapterPrecompress" (module) {
10
13
  module.exports = require("./adapterPrecompress.js");
11
14
  },
@@ -71,17 +74,21 @@ var __webpack_exports__ = {};
71
74
  var __rspack_reexport = {};
72
75
  for(const __rspack_import_key in _adapterHtml__rspack_import_1)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_adapterHtml__rspack_import_1[__rspack_import_key];
73
76
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
74
- var _adapterPrecompress__rspack_import_2 = __webpack_require__("./adapterPrecompress");
77
+ var _adapterLazyCompilation__rspack_import_2 = __webpack_require__("./adapterLazyCompilation");
78
+ var __rspack_reexport = {};
79
+ for(const __rspack_import_key in _adapterLazyCompilation__rspack_import_2)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_adapterLazyCompilation__rspack_import_2[__rspack_import_key];
80
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
81
+ var _adapterPrecompress__rspack_import_3 = __webpack_require__("./adapterPrecompress");
75
82
  var __rspack_reexport = {};
76
- for(const __rspack_import_key in _adapterPrecompress__rspack_import_2)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_adapterPrecompress__rspack_import_2[__rspack_import_key];
83
+ for(const __rspack_import_key in _adapterPrecompress__rspack_import_3)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_adapterPrecompress__rspack_import_3[__rspack_import_key];
77
84
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
78
- var _adapterSSR__rspack_import_3 = __webpack_require__("./adapterSSR");
85
+ var _adapterSSR__rspack_import_4 = __webpack_require__("./adapterSSR");
79
86
  var __rspack_reexport = {};
80
- for(const __rspack_import_key in _adapterSSR__rspack_import_3)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_adapterSSR__rspack_import_3[__rspack_import_key];
87
+ for(const __rspack_import_key in _adapterSSR__rspack_import_4)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_adapterSSR__rspack_import_4[__rspack_import_key];
81
88
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
82
- var _builderHooks__rspack_import_4 = __webpack_require__("./builderHooks");
89
+ var _builderHooks__rspack_import_5 = __webpack_require__("./builderHooks");
83
90
  var __rspack_reexport = {};
84
- for(const __rspack_import_key in _builderHooks__rspack_import_4)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_builderHooks__rspack_import_4[__rspack_import_key];
91
+ for(const __rspack_import_key in _builderHooks__rspack_import_5)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_builderHooks__rspack_import_5[__rspack_import_key];
85
92
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
86
93
  })();
87
94
  for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -29,9 +29,11 @@ var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  aggregateEagerRouteComponentFiles: ()=>aggregateEagerRouteComponentFiles,
32
+ buildRouteEagerLazyCompilationTest: ()=>buildRouteEagerLazyCompilationTest,
32
33
  buildSSRLazyCompilationTest: ()=>buildSSRLazyCompilationTest,
33
34
  collectRouteComponentFiles: ()=>utils_namespaceObject.collectRouteComponentFiles,
34
35
  normalizeModulePath: ()=>utils_namespaceObject.normalizeModulePath,
36
+ planRouteEagerLazyCompilation: ()=>planRouteEagerLazyCompilation,
35
37
  planSSRLazyCompilation: ()=>planSSRLazyCompilation
36
38
  });
37
39
  const utils_namespaceObject = require("@modern-js/utils");
@@ -47,7 +49,7 @@ function aggregateEagerRouteComponentFiles(byEntry) {
47
49
  unresolvedByEntry
48
50
  };
49
51
  }
50
- function buildSSRLazyCompilationTest(eagerRouteFiles, userTest) {
52
+ function buildRouteEagerLazyCompilationTest(eagerRouteFiles, userTest) {
51
53
  const userTestFn = 'function' == typeof userTest ? userTest : userTest instanceof RegExp ? (m)=>userTest.test(m.resource || '') : ()=>true;
52
54
  return (m)=>{
53
55
  const resource = m.resource;
@@ -56,7 +58,8 @@ function buildSSRLazyCompilationTest(eagerRouteFiles, userTest) {
56
58
  return userTestFn(m);
57
59
  };
58
60
  }
59
- function planSSRLazyCompilation(current, info) {
61
+ const buildSSRLazyCompilationTest = buildRouteEagerLazyCompilationTest;
62
+ function planRouteEagerLazyCompilation(current, info) {
60
63
  if (!current) return {
61
64
  apply: false
62
65
  };
@@ -73,20 +76,25 @@ function planSSRLazyCompilation(current, info) {
73
76
  apply: true,
74
77
  lazyCompilation: {
75
78
  ...base,
76
- test: buildSSRLazyCompilationTest(info.files, userTest)
79
+ test: buildRouteEagerLazyCompilationTest(info.files, userTest)
77
80
  }
78
81
  };
79
82
  }
83
+ const planSSRLazyCompilation = planRouteEagerLazyCompilation;
80
84
  exports.aggregateEagerRouteComponentFiles = __webpack_exports__.aggregateEagerRouteComponentFiles;
85
+ exports.buildRouteEagerLazyCompilationTest = __webpack_exports__.buildRouteEagerLazyCompilationTest;
81
86
  exports.buildSSRLazyCompilationTest = __webpack_exports__.buildSSRLazyCompilationTest;
82
87
  exports.collectRouteComponentFiles = __webpack_exports__.collectRouteComponentFiles;
83
88
  exports.normalizeModulePath = __webpack_exports__.normalizeModulePath;
89
+ exports.planRouteEagerLazyCompilation = __webpack_exports__.planRouteEagerLazyCompilation;
84
90
  exports.planSSRLazyCompilation = __webpack_exports__.planSSRLazyCompilation;
85
91
  for(var __rspack_i in __webpack_exports__)if (-1 === [
86
92
  "aggregateEagerRouteComponentFiles",
93
+ "buildRouteEagerLazyCompilationTest",
87
94
  "buildSSRLazyCompilationTest",
88
95
  "collectRouteComponentFiles",
89
96
  "normalizeModulePath",
97
+ "planRouteEagerLazyCompilation",
90
98
  "planSSRLazyCompilation"
91
99
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
92
100
  Object.defineProperty(exports, '__esModule', {
@@ -48,7 +48,15 @@ const deployPresets = {
48
48
  };
49
49
  const getSupportedDeployTargets = ()=>Object.keys(deployPresets);
50
50
  const isDeployTarget = (target)=>Object.prototype.hasOwnProperty.call(deployPresets, target);
51
- const resolveDeployTarget = (modernConfig, envDeployTarget = process.env.MODERNJS_DEPLOY, detectedProvider = external_std_env_namespaceObject.provider)=>modernConfig.deploy?.target || envDeployTarget || detectedProvider || 'node';
51
+ const providerDeployTargets = {
52
+ vercel: 'vercel',
53
+ netlify: 'netlify',
54
+ cloudflare: 'cloudflare',
55
+ cloudflare_pages: 'cloudflare',
56
+ cloudflare_workers: 'cloudflare'
57
+ };
58
+ const normalizeDetectedProvider = (value)=>value ? providerDeployTargets[value] : void 0;
59
+ const resolveDeployTarget = (modernConfig, envDeployTarget = process.env.MODERNJS_DEPLOY, detectedProvider = external_std_env_namespaceObject.provider)=>modernConfig.deploy?.target || envDeployTarget || normalizeDetectedProvider(detectedProvider) || 'node';
52
60
  async function getDeployPreset(appContext, modernConfig, deployTarget, api) {
53
61
  const { appDirectory, distDirectory, metaName } = appContext;
54
62
  const { useSSR, useAPI, useWebServer } = (0, index_js_namespaceObject.getProjectUsage)(appDirectory, distDirectory, metaName);
@@ -45,6 +45,8 @@ const utils_namespaceObject = require("@modern-js/utils");
45
45
  const index_js_namespaceObject = require("../utils/index.js");
46
46
  const WORKER_ENTRY = 'server/index.mjs';
47
47
  const WORKER_MANIFEST = 'server/modern-worker-manifest.json';
48
+ const WRANGLER_CONFIG_FILE = 'wrangler.json';
49
+ const OUTPUT_PACKAGE_FILE = 'package.json';
48
50
  const ASSETS_BINDING = 'ASSETS';
49
51
  const ROUTE_SPEC_FILE = 'route.json';
50
52
  const ROUTE_SPEC_OUTPUT = `server/${ROUTE_SPEC_FILE}`;
@@ -53,10 +55,28 @@ const ROUTE_MANIFEST_FILE = 'routes-manifest.json';
53
55
  const PUBLIC_ASSETS_DIRECTORY = 'public';
54
56
  const WORKER_BUNDLE_DIRECTORY = 'worker';
55
57
  const SERVER_BUNDLE_DIRECTORY = 'bundles';
58
+ const SERVER_OUTPUT_DIRECTORY = 'server';
59
+ const DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES = [
60
+ 'api',
61
+ 'shared'
62
+ ];
56
63
  const BFF_EFFECT_WORKER_ENTRY = `${WORKER_BUNDLE_DIRECTORY}/__modern_bff_effect.js`;
57
- const EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE = 'Ensure the Effect BFF entry exists at api/effect/index.ts or bff.effect.entry, and import Cloudflare edge handlers from @modern-js/plugin-bff/effect-edge instead of lambda/Hono server helpers.';
64
+ const EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE = 'Ensure the Effect API entry exists at api/index.ts or bff.effect.entry, and import Cloudflare edge handlers from @modern-js/plugin-bff/effect-edge instead of lambda/Hono server helpers.';
58
65
  const DEFAULT_COMPATIBILITY_DATE = '2026-06-02';
59
66
  const COMPATIBILITY_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
67
+ const REQUIRED_COMPATIBILITY_FLAGS = [
68
+ 'nodejs_compat',
69
+ 'global_fetch_strictly_public'
70
+ ];
71
+ const RESERVED_ARTIFACT_DESTINATION_FILES = new Set([
72
+ WRANGLER_CONFIG_FILE,
73
+ OUTPUT_PACKAGE_FILE
74
+ ]);
75
+ const RESERVED_ARTIFACT_DESTINATION_DIRECTORIES = new Set([
76
+ PUBLIC_ASSETS_DIRECTORY,
77
+ SERVER_OUTPUT_DIRECTORY,
78
+ WORKER_BUNDLE_DIRECTORY
79
+ ]);
60
80
  const DEFAULT_SECURITY_HEADERS = {
61
81
  referrerPolicy: 'strict-origin-when-cross-origin',
62
82
  contentTypeOptions: 'nosniff',
@@ -145,6 +165,13 @@ const getConfiguredWorkerName = (appDirectory, modernConfig)=>{
145
165
  const configuredName = modernConfig.deploy?.worker?.name?.trim();
146
166
  return configuredName || getWorkerName(appDirectory);
147
167
  };
168
+ const normalizeRelativePath = (value, label, scope = 'app output')=>{
169
+ if ('string' != typeof value) throw new Error(`${label} must be a relative path inside the ${scope}.`);
170
+ const normalized = value.trim().replace(/\\/g, '/').replace(/^\.\/+/u, '').replace(/\/+$/u, '');
171
+ const segments = normalized.split('/');
172
+ if (!normalized || external_node_path_default().isAbsolute(normalized) || '.' === normalized || segments.includes('..')) throw new Error(`${label} must be a relative path inside the ${scope}.`);
173
+ return normalized;
174
+ };
148
175
  const normalizeDirectiveValues = (value)=>{
149
176
  const values = Array.isArray(value) ? value : [
150
177
  value
@@ -237,6 +264,66 @@ const createCloudflareWorkerSecurityPolicy = (modernConfig)=>{
237
264
  reason: security?.reason
238
265
  };
239
266
  };
267
+ const isJsonRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
268
+ const getConfiguredWrangler = (modernConfig)=>{
269
+ const wrangler = modernConfig.deploy?.worker?.wrangler;
270
+ if (void 0 === wrangler) return {};
271
+ if (!isJsonRecord(wrangler)) throw new Error('deploy.worker.wrangler must be a JSON object.');
272
+ return wrangler;
273
+ };
274
+ const createWranglerCompatibilityFlags = (configuredFlags)=>{
275
+ if (void 0 === configuredFlags) return [
276
+ ...REQUIRED_COMPATIBILITY_FLAGS
277
+ ];
278
+ if (!Array.isArray(configuredFlags) || configuredFlags.some((flag)=>'string' != typeof flag)) throw new Error('deploy.worker.wrangler.compatibility_flags must be an array of strings.');
279
+ return [
280
+ ...new Set([
281
+ ...configuredFlags,
282
+ ...REQUIRED_COMPATIBILITY_FLAGS
283
+ ])
284
+ ];
285
+ };
286
+ const createWranglerAssetsConfig = (configuredAssets)=>{
287
+ if (void 0 !== configuredAssets && !isJsonRecord(configuredAssets)) throw new Error('deploy.worker.wrangler.assets must be an object.');
288
+ return {
289
+ ...isJsonRecord(configuredAssets) ? configuredAssets : {},
290
+ directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
291
+ binding: ASSETS_BINDING,
292
+ run_worker_first: true
293
+ };
294
+ };
295
+ const createWranglerConfig = (appDirectory, modernConfig)=>{
296
+ const wrangler = getConfiguredWrangler(modernConfig);
297
+ return {
298
+ $schema: 'node_modules/wrangler/config-schema.json',
299
+ name: getConfiguredWorkerName(appDirectory, modernConfig),
300
+ compatibility_date: getCompatibilityDate(modernConfig),
301
+ ...wrangler,
302
+ main: WORKER_ENTRY,
303
+ compatibility_flags: createWranglerCompatibilityFlags(wrangler.compatibility_flags),
304
+ assets: createWranglerAssetsConfig(wrangler.assets)
305
+ };
306
+ };
307
+ const normalizeCloudflareArtifact = (artifact, index)=>{
308
+ const from = normalizeRelativePath(artifact.from, `deploy.worker.artifacts[${index}].from`, 'app root');
309
+ const to = normalizeRelativePath(artifact.to, `deploy.worker.artifacts[${index}].to`, 'Cloudflare output');
310
+ const [topLevelDestination] = to.split('/');
311
+ const reservedDestination = RESERVED_ARTIFACT_DESTINATION_FILES.has(to) ? to : topLevelDestination;
312
+ if (RESERVED_ARTIFACT_DESTINATION_FILES.has(to) || RESERVED_ARTIFACT_DESTINATION_DIRECTORIES.has(topLevelDestination)) throw new Error(`deploy.worker.artifacts[${index}].to must not target generated Cloudflare output path ${JSON.stringify(reservedDestination)}.`);
313
+ return {
314
+ from,
315
+ to,
316
+ index
317
+ };
318
+ };
319
+ const getCloudflareArtifacts = (modernConfig)=>(modernConfig.deploy?.worker?.artifacts ?? []).map(normalizeCloudflareArtifact);
320
+ const copyCloudflareArtifacts = async (appDirectory, outputDirectory, artifacts)=>{
321
+ for (const artifact of artifacts){
322
+ const sourcePath = external_node_path_default().join(appDirectory, artifact.from);
323
+ if (!await utils_namespaceObject.fs.pathExists(sourcePath)) throw new Error(`deploy.worker.artifacts[${artifact.index}].from does not exist: ${artifact.from}`);
324
+ await utils_namespaceObject.fs.copy(sourcePath, external_node_path_default().join(outputDirectory, artifact.to));
325
+ }
326
+ };
240
327
  const readRouteSpec = async (outputDirectory)=>{
241
328
  const routeSpecPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
242
329
  if (!await utils_namespaceObject.fs.pathExists(routeSpecPath)) return {
@@ -248,7 +335,7 @@ const readRouteSpec = async (outputDirectory)=>{
248
335
  routes: Array.isArray(routeSpec.routes) ? routeSpec.routes : []
249
336
  };
250
337
  };
251
- const createMissingEffectBffWorkerError = (outputDirectory, worker)=>new Error(`Cloudflare Effect BFF is configured, but the BFF worker bundle is missing: ${external_node_path_default().join(outputDirectory, worker)}. ${EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE}`);
338
+ const createMissingEffectBffWorkerError = (outputDirectory, worker)=>new Error(`Cloudflare Effect API runtime is configured, but the BFF worker bundle is missing: ${external_node_path_default().join(outputDirectory, worker)}. ${EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE}`);
252
339
  const createWorkerManifest = async (outputDirectory, modernConfig)=>{
253
340
  const routeSpec = await readRouteSpec(outputDirectory);
254
341
  const routes = await Promise.all(routeSpec.routes.map(async (route)=>{
@@ -264,9 +351,9 @@ const createWorkerManifest = async (outputDirectory, modernConfig)=>{
264
351
  }));
265
352
  const bffPrefix = modernConfig.bff?.prefix;
266
353
  const primaryBffPrefix = Array.isArray(bffPrefix) ? bffPrefix[0] : bffPrefix;
267
- const isEffectBff = Boolean(modernConfig.bff) && modernConfig.bff?.runtimeFramework !== 'hono';
268
- const effectBffWorkerExists = await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, BFF_EFFECT_WORKER_ENTRY));
269
- if (isEffectBff && primaryBffPrefix && !effectBffWorkerExists) throw createMissingEffectBffWorkerError(outputDirectory, BFF_EFFECT_WORKER_ENTRY);
354
+ const isEffectApi = Boolean(modernConfig.bff) && modernConfig.bff?.runtimeFramework !== 'hono';
355
+ const effectApiWorkerExists = await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, BFF_EFFECT_WORKER_ENTRY));
356
+ if (isEffectApi && primaryBffPrefix && !effectApiWorkerExists) throw createMissingEffectBffWorkerError(outputDirectory, BFF_EFFECT_WORKER_ENTRY);
270
357
  return {
271
358
  version: 1,
272
359
  runtime: {
@@ -295,7 +382,7 @@ const createWorkerManifest = async (outputDirectory, modernConfig)=>{
295
382
  routeManifest: ROUTE_MANIFEST_FILE
296
383
  },
297
384
  security: createCloudflareWorkerSecurityPolicy(modernConfig),
298
- bff: isEffectBff && primaryBffPrefix && effectBffWorkerExists ? {
385
+ bff: isEffectApi && primaryBffPrefix && effectApiWorkerExists ? {
299
386
  runtimeFramework: 'effect',
300
387
  prefix: primaryBffPrefix,
301
388
  worker: BFF_EFFECT_WORKER_ENTRY
@@ -318,12 +405,22 @@ const createWorkerModuleLoaders = (manifest)=>{
318
405
  ].map(([worker, loader])=>`${JSON.stringify(worker)}: ${loader}`);
319
406
  return `{\n${loaders.join(',\n')}\n}`;
320
407
  };
321
- const shouldCopyToPublicAssets = (src, distDirectory)=>{
408
+ const getPublicAssetExcludes = (appDirectory, modernConfig)=>[
409
+ ...DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES.filter((directory)=>{
410
+ try {
411
+ return utils_namespaceObject.fs.statSync(external_node_path_default().join(appDirectory, directory)).isDirectory();
412
+ } catch {
413
+ return false;
414
+ }
415
+ }),
416
+ ...modernConfig.deploy?.worker?.publicAssetExcludes ?? []
417
+ ].map((entry)=>normalizeRelativePath(entry, 'deploy.worker.publicAssetExcludes'));
418
+ const shouldCopyToPublicAssets = (src, distDirectory, publicAssetExcludes)=>{
322
419
  const relativePath = external_node_path_default().relative(distDirectory, src);
323
420
  if (!relativePath) return true;
324
421
  const normalizedRelativePath = relativePath.replace(/\\/g, '/');
325
422
  const [topLevelDirectory] = normalizedRelativePath.split('/');
326
- return normalizedRelativePath !== ROUTE_SPEC_FILE && topLevelDirectory !== WORKER_BUNDLE_DIRECTORY && topLevelDirectory !== SERVER_BUNDLE_DIRECTORY;
423
+ return normalizedRelativePath !== ROUTE_SPEC_FILE && topLevelDirectory !== WORKER_BUNDLE_DIRECTORY && topLevelDirectory !== SERVER_BUNDLE_DIRECTORY && !publicAssetExcludes.some((exclude)=>normalizedRelativePath === exclude || normalizedRelativePath.startsWith(`${exclude}/`));
327
424
  };
328
425
  const shouldCopyToWorkerBundle = (src, workerBundleDirectory)=>{
329
426
  const relativePath = external_node_path_default().relative(workerBundleDirectory, src);
@@ -345,15 +442,16 @@ const createCloudflarePreset = ({ appContext, modernConfig })=>{
345
442
  const workerEntryPath = external_node_path_default().join(outputDirectory, WORKER_ENTRY);
346
443
  const workerManifestPath = external_node_path_default().join(outputDirectory, WORKER_MANIFEST);
347
444
  const routeSpecOutputPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
348
- const wranglerConfigPath = external_node_path_default().join(outputDirectory, 'wrangler.json');
349
- const workerName = getConfiguredWorkerName(appDirectory, modernConfig);
445
+ const wranglerConfigPath = external_node_path_default().join(outputDirectory, WRANGLER_CONFIG_FILE);
446
+ const cloudflareArtifacts = getCloudflareArtifacts(modernConfig);
447
+ const publicAssetExcludes = getPublicAssetExcludes(appDirectory, modernConfig);
350
448
  return {
351
449
  async prepare () {
352
450
  await utils_namespaceObject.fs.remove(outputDirectory);
353
451
  },
354
452
  async writeOutput () {
355
453
  await utils_namespaceObject.fs.copy(distDirectory, publicDirectory, {
356
- filter: (src)=>shouldCopyToPublicAssets(src, distDirectory)
454
+ filter: (src)=>shouldCopyToPublicAssets(src, distDirectory, publicAssetExcludes)
357
455
  });
358
456
  await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerEntryPath));
359
457
  await utils_namespaceObject.fs.ensureDir(external_node_path_default().dirname(workerManifestPath));
@@ -369,27 +467,14 @@ const createCloudflarePreset = ({ appContext, modernConfig })=>{
369
467
  type: 'commonjs'
370
468
  });
371
469
  }
372
- await utils_namespaceObject.fs.writeJSON(wranglerConfigPath, {
373
- $schema: 'node_modules/wrangler/config-schema.json',
374
- name: workerName,
375
- main: WORKER_ENTRY,
376
- compatibility_date: getCompatibilityDate(modernConfig),
377
- compatibility_flags: [
378
- 'nodejs_compat',
379
- 'global_fetch_strictly_public'
380
- ],
381
- assets: {
382
- directory: `./${PUBLIC_ASSETS_DIRECTORY}`,
383
- binding: ASSETS_BINDING,
384
- run_worker_first: true
385
- }
386
- }, {
470
+ await copyCloudflareArtifacts(appDirectory, outputDirectory, cloudflareArtifacts);
471
+ await utils_namespaceObject.fs.writeJSON(wranglerConfigPath, createWranglerConfig(appDirectory, modernConfig), {
387
472
  spaces: 2
388
473
  });
389
474
  await utils_namespaceObject.fs.writeJSON(workerManifestPath, await createWorkerManifest(outputDirectory, modernConfig), {
390
475
  spaces: 2
391
476
  });
392
- await utils_namespaceObject.fs.writeJSON(external_node_path_default().join(outputDirectory, 'package.json'), {
477
+ await utils_namespaceObject.fs.writeJSON(external_node_path_default().join(outputDirectory, OUTPUT_PACKAGE_FILE), {
393
478
  type: 'module'
394
479
  });
395
480
  },
@@ -312,6 +312,19 @@ function getRemoteManifestUrl(remote, request) {
312
312
  if ('string' != typeof entry || 0 === entry.length) return;
313
313
  return new URL(entry, request.url).toString();
314
314
  }
315
+ function ensureTrailingSlash(value) {
316
+ return value.endsWith('/') ? value : `${value}/`;
317
+ }
318
+ function getRemoteAssetBase(remoteManifest, manifestUrl) {
319
+ const publicPath = 'string' == typeof remoteManifest?.metaData?.publicPath ? remoteManifest.metaData.publicPath : void 0;
320
+ const fallbackBase = new URL('.', manifestUrl).toString();
321
+ if (!publicPath || 'auto' === publicPath) return fallbackBase;
322
+ try {
323
+ return new URL(ensureTrailingSlash(publicPath), manifestUrl).toString();
324
+ } catch {
325
+ return fallbackBase;
326
+ }
327
+ }
315
328
  async function fetchRemoteJson(jsonUrl) {
316
329
  if (!remoteJsonPromises.has(jsonUrl)) remoteJsonPromises.set(jsonUrl, fetch(jsonUrl).then((response)=>{
317
330
  if (!response.ok) {
@@ -374,7 +387,7 @@ async function collectRenderedRemoteCssHrefs(html, request, env) {
374
387
  if (!manifestUrl) return;
375
388
  const remoteManifest = await fetchRemoteJson(manifestUrl);
376
389
  const remoteExpose = findRemoteExpose(remoteManifest, expose);
377
- const publicPath = 'string' == typeof remoteManifest?.metaData?.publicPath ? remoteManifest.metaData.publicPath : manifestUrl;
390
+ const publicPath = getRemoteAssetBase(remoteManifest, manifestUrl);
378
391
  const remoteRouteManifest = await fetchRemoteJson(new URL('routes-manifest.json', publicPath).toString());
379
392
  for (const asset of collectCssAssetEntries(remoteExpose?.assets))hrefs.add(new URL(asset, publicPath).toString());
380
393
  for (const asset of collectRouteManifestCssAssets(remoteRouteManifest))hrefs.add(new URL(asset, publicPath).toString());
@@ -55,9 +55,13 @@ async function resolveModernRsbuildConfig(options) {
55
55
  plugins: modernConfig.builderPlugins
56
56
  };
57
57
  const appContext = getAppContext();
58
- const { rsbuildConfig, rsbuildPlugins } = await (0, builder_namespaceObject.parseRspackConfig)(nonStandardConfig, {
59
- cwd
60
- });
58
+ const builderOptions = {
59
+ cwd,
60
+ ...void 0 === options.disableReactCompiler ? {} : {
61
+ disableReactCompiler: options.disableReactCompiler
62
+ }
63
+ };
64
+ const { rsbuildConfig, rsbuildPlugins } = await (0, builder_namespaceObject.parseRspackConfig)(nonStandardConfig, builderOptions);
61
65
  const adapterParams = {
62
66
  appContext,
63
67
  normalizedConfig: modernConfig
@@ -42,6 +42,17 @@ __webpack_require__.d(__webpack_exports__, {
42
42
  const utils_namespaceObject = require("@modern-js/utils");
43
43
  const external_path_namespaceObject = require("path");
44
44
  var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
45
+ function isSymlinkedNodeModules(appDirectory) {
46
+ try {
47
+ return utils_namespaceObject.fs.lstatSync(external_path_default().resolve(appDirectory, 'node_modules')).isSymbolicLink();
48
+ } catch {
49
+ return false;
50
+ }
51
+ }
52
+ function getDefaultInternalDirectory(appDirectory, metaName) {
53
+ if (isSymlinkedNodeModules(appDirectory)) return external_path_default().resolve(appDirectory, `.${metaName}`);
54
+ return external_path_default().resolve(appDirectory, `./node_modules/.${metaName}`);
55
+ }
45
56
  const initAppContext = ({ metaName, appDirectory, runtimeConfigFile, options, tempDir })=>{
46
57
  const { apiDir = 'api', sharedDir = 'shared', bffRuntimeFramework = 'hono' } = options || {};
47
58
  const pkgPath = external_path_default().resolve(appDirectory, './package.json');
@@ -55,7 +66,7 @@ const initAppContext = ({ metaName, appDirectory, runtimeConfigFile, options, te
55
66
  lambdaDirectory: external_path_default().resolve(appDirectory, apiDir, 'lambda'),
56
67
  sharedDirectory: external_path_default().resolve(appDirectory, sharedDir),
57
68
  serverPlugins: [],
58
- internalDirectory: external_path_default().resolve(appDirectory, tempDir || `./node_modules/.${metaName}`),
69
+ internalDirectory: tempDir ? external_path_default().resolve(appDirectory, tempDir) : getDefaultInternalDirectory(appDirectory, metaName),
59
70
  htmlTemplates: {},
60
71
  serverRoutes: [],
61
72
  entrypoints: [],