@bleedingdev/modern-js-app-tools 3.4.0-ultramodern.0 → 3.4.0-ultramodern.10

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 +49 -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/esm/register-esm.js +14 -1
  8. package/dist/cjs/esm/register-esm.mjs +14 -1
  9. package/dist/cjs/plugins/deploy/index.js +9 -1
  10. package/dist/cjs/plugins/deploy/platforms/cloudflare.js +13 -4
  11. package/dist/cjs/rsbuild.js +7 -3
  12. package/dist/cjs/utils/initAppContext.js +12 -1
  13. package/dist/esm/builder/generator/getBuilderEnvironments.mjs +49 -5
  14. package/dist/esm/builder/generator/index.mjs +2 -1
  15. package/dist/esm/builder/shared/builderPlugins/adapterLazyCompilation.mjs +36 -0
  16. package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +4 -29
  17. package/dist/esm/builder/shared/builderPlugins/index.mjs +1 -0
  18. package/dist/esm/builder/shared/lazyCompilation.mjs +6 -4
  19. package/dist/esm/esm/register-esm.mjs +14 -1
  20. package/dist/esm/plugins/deploy/index.mjs +9 -1
  21. package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +13 -4
  22. package/dist/esm/rsbuild.mjs +7 -3
  23. package/dist/esm/utils/initAppContext.mjs +12 -1
  24. package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +49 -5
  25. package/dist/esm-node/builder/generator/index.mjs +2 -1
  26. package/dist/esm-node/builder/shared/builderPlugins/adapterLazyCompilation.mjs +37 -0
  27. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +4 -29
  28. package/dist/esm-node/builder/shared/builderPlugins/index.mjs +1 -0
  29. package/dist/esm-node/builder/shared/lazyCompilation.mjs +6 -4
  30. package/dist/esm-node/esm/register-esm.mjs +14 -1
  31. package/dist/esm-node/plugins/deploy/index.mjs +9 -1
  32. package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +13 -4
  33. package/dist/esm-node/rsbuild.mjs +7 -3
  34. package/dist/esm-node/utils/initAppContext.mjs +12 -1
  35. package/dist/types/builder/shared/builderPlugins/adapterLazyCompilation.d.ts +3 -0
  36. package/dist/types/builder/shared/builderPlugins/index.d.ts +1 -0
  37. package/dist/types/builder/shared/lazyCompilation.d.ts +7 -5
  38. package/dist/types/builder/shared/types.d.ts +3 -3
  39. package/dist/types/esm/register-esm.d.mts +1 -1
  40. package/dist/types/rsbuild.d.ts +1 -0
  41. package/package.json +21 -29
@@ -48,12 +48,14 @@ const utils_namespaceObject = require("@modern-js/utils");
48
48
  const BFF_EFFECT_WORKER_ENTRY_NAME = '__modern_bff_effect';
49
49
  const BFF_EFFECT_WORKER_RUNTIME_QUERY = 'modern-bff-runtime';
50
50
  const JS_OR_TS_EXTS = [
51
- '.ts',
52
- '.tsx',
53
51
  '.js',
54
52
  '.jsx',
53
+ '.ts',
54
+ '.tsx',
55
55
  '.mjs',
56
- '.cjs'
56
+ '.mts',
57
+ '.cjs',
58
+ '.cts'
57
59
  ];
58
60
  const CLOUDFLARE_WORKER_NODE_BUILTINS = [
59
61
  'async_hooks',
@@ -73,6 +75,11 @@ const CLOUDFLARE_WORKER_COMPAT_TEMPLATE_DIR = external_node_path_default().resol
73
75
  function findExistingFile(candidates) {
74
76
  return candidates.find((candidate)=>external_node_fs_default().existsSync(candidate));
75
77
  }
78
+ function resolveJsOrTsEntry(entryWithoutOrWithExt) {
79
+ const extension = external_node_path_default().extname(entryWithoutOrWithExt);
80
+ if (JS_OR_TS_EXTS.includes(extension)) return external_node_fs_default().existsSync(entryWithoutOrWithExt) ? entryWithoutOrWithExt : void 0;
81
+ return findExistingFile(JS_OR_TS_EXTS.map((extension)=>`${entryWithoutOrWithExt}${extension}`));
82
+ }
76
83
  function resolvePackageEntry(packageName, paths) {
77
84
  try {
78
85
  return external_node_fs_default().realpathSync(require.resolve(packageName, {
@@ -130,13 +137,50 @@ function getCloudflareWorkerNodeExternals() {
130
137
  function getEffectBffEntry(normalizedConfig, appContext) {
131
138
  if (!normalizedConfig.bff || 'hono' === normalizedConfig.bff.runtimeFramework) return;
132
139
  const configuredEntry = normalizedConfig.bff.effect?.entry;
133
- const entryWithoutExtension = 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');
134
- return findExistingFile(JS_OR_TS_EXTS.map((extension)=>`${entryWithoutExtension}${extension}`));
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);
135
142
  }
136
143
  function isCloudflareWorkerDeploy(normalizedConfig) {
137
144
  return normalizedConfig.deploy?.target === 'cloudflare' || 'cloudflare' === process.env.MODERNJS_DEPLOY;
138
145
  }
146
+ function getConsumingReactRuntimeAliases(appContext) {
147
+ const resolvePaths = [
148
+ appContext.appDirectory,
149
+ process.cwd()
150
+ ];
151
+ return {
152
+ react$: resolvePackageFile('react', 'index.js', resolvePaths),
153
+ 'react/jsx-runtime$': resolvePackageFile('react', 'jsx-runtime.js', resolvePaths),
154
+ 'react/jsx-dev-runtime$': resolvePackageFile('react', 'jsx-dev-runtime.js', resolvePaths),
155
+ 'react/compiler-runtime$': resolvePackageFile('react', 'compiler-runtime.js', resolvePaths)
156
+ };
157
+ }
158
+ function setResolvedAliases(alias, aliases) {
159
+ for (const [name, value] of Object.entries(aliases))setAliasIfPresent(alias, name, value);
160
+ }
161
+ function appendBundlerChain(config, handler) {
162
+ const bundlerChain = config.tools?.bundlerChain;
163
+ config.tools = {
164
+ ...config.tools,
165
+ bundlerChain: bundlerChain ? Array.isArray(bundlerChain) ? [
166
+ ...bundlerChain,
167
+ handler
168
+ ] : [
169
+ bundlerChain,
170
+ handler
171
+ ] : handler
172
+ };
173
+ }
174
+ function applySourceBuildReactRuntimeAliases(normalizedConfig, appContext, tempBuilderConfig) {
175
+ if (!normalizedConfig.experiments?.sourceBuild) return;
176
+ const aliases = getConsumingReactRuntimeAliases(appContext);
177
+ if (!Object.values(aliases).some(Boolean)) return;
178
+ appendBundlerChain(tempBuilderConfig, (chain)=>{
179
+ setResolvedAliases(chain.resolve.alias, aliases);
180
+ });
181
+ }
139
182
  function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig) {
183
+ applySourceBuildReactRuntimeAliases(normalizedConfig, appContext, tempBuilderConfig);
140
184
  const entries = {};
141
185
  const { entrypoints = [], checkedEntries } = appContext;
142
186
  for (const { entryName, internalEntry, entry } of entrypoints){
@@ -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', {
@@ -30,8 +30,21 @@ var __webpack_require__ = {};
30
30
  })();
31
31
  var __webpack_exports__ = {};
32
32
  __webpack_require__.r(__webpack_exports__);
33
+ let registeredPathHooks;
33
34
  const registerPathsLoader = async ({ appDir, baseUrl, paths })=>{
34
- const { register } = await import("node:module");
35
+ const { register, registerHooks } = await import("node:module");
36
+ if ('function' == typeof registerHooks) {
37
+ const loader = await import("./ts-paths-loader.js");
38
+ await loader.initialize({
39
+ appDir,
40
+ baseUrl,
41
+ paths
42
+ });
43
+ registeredPathHooks ??= registerHooks({
44
+ resolve: loader.resolve
45
+ });
46
+ return registeredPathHooks;
47
+ }
35
48
  register('./ts-paths-loader.mjs', __rslib_import_meta_url__, {
36
49
  data: {
37
50
  appDir,
@@ -1,5 +1,18 @@
1
+ let registeredPathHooks;
1
2
  export const registerPathsLoader = async ({ appDir, baseUrl, paths })=>{
2
- const { register } = await import('node:module');
3
+ const { register, registerHooks } = await import('node:module');
4
+ if ('function' == typeof registerHooks) {
5
+ const loader = await import('./ts-paths-loader.mjs');
6
+ await loader.initialize({
7
+ appDir,
8
+ baseUrl,
9
+ paths
10
+ });
11
+ registeredPathHooks ??= registerHooks({
12
+ resolve: loader.resolve
13
+ });
14
+ return registeredPathHooks;
15
+ }
3
16
  register('./ts-paths-loader.mjs', import.meta.url, {
4
17
  data: {
5
18
  appDir,
@@ -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);
@@ -54,6 +54,7 @@ const PUBLIC_ASSETS_DIRECTORY = 'public';
54
54
  const WORKER_BUNDLE_DIRECTORY = 'worker';
55
55
  const SERVER_BUNDLE_DIRECTORY = 'bundles';
56
56
  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.';
57
58
  const DEFAULT_COMPATIBILITY_DATE = '2026-06-02';
58
59
  const COMPATIBILITY_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
59
60
  const DEFAULT_SECURITY_HEADERS = {
@@ -247,6 +248,7 @@ const readRouteSpec = async (outputDirectory)=>{
247
248
  routes: Array.isArray(routeSpec.routes) ? routeSpec.routes : []
248
249
  };
249
250
  };
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}`);
250
252
  const createWorkerManifest = async (outputDirectory, modernConfig)=>{
251
253
  const routeSpec = await readRouteSpec(outputDirectory);
252
254
  const routes = await Promise.all(routeSpec.routes.map(async (route)=>{
@@ -264,6 +266,7 @@ const createWorkerManifest = async (outputDirectory, modernConfig)=>{
264
266
  const primaryBffPrefix = Array.isArray(bffPrefix) ? bffPrefix[0] : bffPrefix;
265
267
  const isEffectBff = Boolean(modernConfig.bff) && modernConfig.bff?.runtimeFramework !== 'hono';
266
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);
267
270
  return {
268
271
  version: 1,
269
272
  runtime: {
@@ -357,9 +360,15 @@ const createCloudflarePreset = ({ appContext, modernConfig })=>{
357
360
  const routeSpecSourcePath = external_node_path_default().join(distDirectory, ROUTE_SPEC_FILE);
358
361
  if (await utils_namespaceObject.fs.pathExists(routeSpecSourcePath)) await utils_namespaceObject.fs.copy(routeSpecSourcePath, routeSpecOutputPath);
359
362
  const workerBundleSourceDirectory = external_node_path_default().join(distDirectory, WORKER_BUNDLE_DIRECTORY);
360
- if (await utils_namespaceObject.fs.pathExists(workerBundleSourceDirectory)) await utils_namespaceObject.fs.copy(workerBundleSourceDirectory, external_node_path_default().join(outputDirectory, WORKER_BUNDLE_DIRECTORY), {
361
- filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
362
- });
363
+ const workerBundleOutputDirectory = external_node_path_default().join(outputDirectory, WORKER_BUNDLE_DIRECTORY);
364
+ if (await utils_namespaceObject.fs.pathExists(workerBundleSourceDirectory)) {
365
+ await utils_namespaceObject.fs.copy(workerBundleSourceDirectory, workerBundleOutputDirectory, {
366
+ filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
367
+ });
368
+ await utils_namespaceObject.fs.writeJSON(external_node_path_default().join(workerBundleOutputDirectory, 'package.json'), {
369
+ type: 'commonjs'
370
+ });
371
+ }
363
372
  await utils_namespaceObject.fs.writeJSON(wranglerConfigPath, {
364
373
  $schema: 'node_modules/wrangler/config-schema.json',
365
374
  name: workerName,
@@ -381,7 +390,7 @@ const createCloudflarePreset = ({ appContext, modernConfig })=>{
381
390
  spaces: 2
382
391
  });
383
392
  await utils_namespaceObject.fs.writeJSON(external_node_path_default().join(outputDirectory, 'package.json'), {
384
- type: 'commonjs'
393
+ type: 'module'
385
394
  });
386
395
  },
387
396
  async genEntry () {
@@ -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: [],
@@ -5,12 +5,14 @@ import { isProd, isSSR, isServiceWorker, isUseRsc, isUseSSRBundle } from "@moder
5
5
  const BFF_EFFECT_WORKER_ENTRY_NAME = '__modern_bff_effect';
6
6
  const BFF_EFFECT_WORKER_RUNTIME_QUERY = 'modern-bff-runtime';
7
7
  const JS_OR_TS_EXTS = [
8
- '.ts',
9
- '.tsx',
10
8
  '.js',
11
9
  '.jsx',
10
+ '.ts',
11
+ '.tsx',
12
12
  '.mjs',
13
- '.cjs'
13
+ '.mts',
14
+ '.cjs',
15
+ '.cts'
14
16
  ];
15
17
  const CLOUDFLARE_WORKER_NODE_BUILTINS = [
16
18
  'async_hooks',
@@ -30,6 +32,11 @@ const CLOUDFLARE_WORKER_COMPAT_TEMPLATE_DIR = node_path.resolve(__dirname, '../.
30
32
  function findExistingFile(candidates) {
31
33
  return candidates.find((candidate)=>node_fs.existsSync(candidate));
32
34
  }
35
+ function resolveJsOrTsEntry(entryWithoutOrWithExt) {
36
+ const extension = node_path.extname(entryWithoutOrWithExt);
37
+ if (JS_OR_TS_EXTS.includes(extension)) return node_fs.existsSync(entryWithoutOrWithExt) ? entryWithoutOrWithExt : void 0;
38
+ return findExistingFile(JS_OR_TS_EXTS.map((extension)=>`${entryWithoutOrWithExt}${extension}`));
39
+ }
33
40
  function resolvePackageEntry(packageName, paths) {
34
41
  try {
35
42
  return node_fs.realpathSync(require.resolve(packageName, {
@@ -87,13 +94,50 @@ function getCloudflareWorkerNodeExternals() {
87
94
  function getEffectBffEntry(normalizedConfig, appContext) {
88
95
  if (!normalizedConfig.bff || 'hono' === normalizedConfig.bff.runtimeFramework) return;
89
96
  const configuredEntry = normalizedConfig.bff.effect?.entry;
90
- const entryWithoutExtension = configuredEntry ? node_path.isAbsolute(configuredEntry) ? configuredEntry : node_path.resolve(appContext.appDirectory, configuredEntry) : node_path.resolve(appContext.apiDirectory, 'effect', 'index');
91
- return findExistingFile(JS_OR_TS_EXTS.map((extension)=>`${entryWithoutExtension}${extension}`));
97
+ const entryWithoutOrWithExtension = configuredEntry ? node_path.isAbsolute(configuredEntry) ? configuredEntry : node_path.resolve(appContext.appDirectory, configuredEntry) : node_path.resolve(appContext.apiDirectory, 'effect', 'index');
98
+ return resolveJsOrTsEntry(entryWithoutOrWithExtension);
92
99
  }
93
100
  function isCloudflareWorkerDeploy(normalizedConfig) {
94
101
  return normalizedConfig.deploy?.target === 'cloudflare' || 'cloudflare' === process.env.MODERNJS_DEPLOY;
95
102
  }
103
+ function getConsumingReactRuntimeAliases(appContext) {
104
+ const resolvePaths = [
105
+ appContext.appDirectory,
106
+ process.cwd()
107
+ ];
108
+ return {
109
+ react$: resolvePackageFile('react', 'index.js', resolvePaths),
110
+ 'react/jsx-runtime$': resolvePackageFile('react', 'jsx-runtime.js', resolvePaths),
111
+ 'react/jsx-dev-runtime$': resolvePackageFile('react', 'jsx-dev-runtime.js', resolvePaths),
112
+ 'react/compiler-runtime$': resolvePackageFile('react', 'compiler-runtime.js', resolvePaths)
113
+ };
114
+ }
115
+ function setResolvedAliases(alias, aliases) {
116
+ for (const [name, value] of Object.entries(aliases))setAliasIfPresent(alias, name, value);
117
+ }
118
+ function appendBundlerChain(config, handler) {
119
+ const bundlerChain = config.tools?.bundlerChain;
120
+ config.tools = {
121
+ ...config.tools,
122
+ bundlerChain: bundlerChain ? Array.isArray(bundlerChain) ? [
123
+ ...bundlerChain,
124
+ handler
125
+ ] : [
126
+ bundlerChain,
127
+ handler
128
+ ] : handler
129
+ };
130
+ }
131
+ function applySourceBuildReactRuntimeAliases(normalizedConfig, appContext, tempBuilderConfig) {
132
+ if (!normalizedConfig.experiments?.sourceBuild) return;
133
+ const aliases = getConsumingReactRuntimeAliases(appContext);
134
+ if (!Object.values(aliases).some(Boolean)) return;
135
+ appendBundlerChain(tempBuilderConfig, (chain)=>{
136
+ setResolvedAliases(chain.resolve.alias, aliases);
137
+ });
138
+ }
96
139
  function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig) {
140
+ applySourceBuildReactRuntimeAliases(normalizedConfig, appContext, tempBuilderConfig);
97
141
  const entries = {};
98
142
  const { entrypoints = [], checkedEntries } = appContext;
99
143
  for (const { entryName, internalEntry, entry } of entrypoints){
@@ -1,6 +1,6 @@
1
1
  import { createBuilder } from "@modern-js/builder";
2
2
  import { mergeRsbuildConfig } from "@rsbuild/core";
3
- import { builderPluginAdapterBasic, builderPluginAdapterHooks, builderPluginAdapterHtml, builderPluginAdapterPrecompress, builderPluginAdapterSSR } from "../shared/builderPlugins/index.mjs";
3
+ import { builderPluginAdapterBasic, builderPluginAdapterHooks, builderPluginAdapterHtml, builderPluginAdapterLazyCompilation, builderPluginAdapterPrecompress, builderPluginAdapterSSR } from "../shared/builderPlugins/index.mjs";
4
4
  import { builderPluginAdapterCopy } from "./adapterCopy.mjs";
5
5
  import { createBuilderProviderConfig } from "./createBuilderProviderConfig.mjs";
6
6
  import { getBuilderEnvironments } from "./getBuilderEnvironments.mjs";
@@ -38,6 +38,7 @@ async function generateBuilder(options, bundlerType) {
38
38
  async function applyBuilderPlugins(builder, options) {
39
39
  builder.addPlugins([
40
40
  builderPluginAdapterBasic(options),
41
+ builderPluginAdapterLazyCompilation(options),
41
42
  builderPluginAdapterSSR(options),
42
43
  builderPluginAdapterHtml(options),
43
44
  builderPluginAdapterPrecompress(options),
@@ -0,0 +1,36 @@
1
+ import { isUseRsc, logger } from "@modern-js/utils";
2
+ import { aggregateEagerRouteComponentFiles, planRouteEagerLazyCompilation } from "../lazyCompilation.mjs";
3
+ const builderPluginAdapterLazyCompilation = (options)=>({
4
+ name: 'builder-plugin-adapter-modern-lazy-compilation',
5
+ setup (api) {
6
+ api.modifyRsbuildConfig((config)=>{
7
+ const lazyCompilation = getRouteEagerLazyCompilation(options, config);
8
+ if (void 0 === lazyCompilation) return config;
9
+ return {
10
+ ...config,
11
+ dev: {
12
+ ...config.dev,
13
+ lazyCompilation
14
+ }
15
+ };
16
+ });
17
+ }
18
+ });
19
+ function getRouteEagerLazyCompilation(options, config) {
20
+ const current = config.dev?.lazyCompilation;
21
+ if (!current || isUseRsc(options.normalizedConfig)) return;
22
+ const plan = planRouteEagerLazyCompilation(current, aggregateEagerRouteComponentFiles(options.eagerRouteComponentFilesByEntry));
23
+ if (!plan.apply) {
24
+ if (plan.unresolvedByEntry) warnUnresolvedRouteComponents(options.appContext.appDirectory, plan.unresolvedByEntry);
25
+ return;
26
+ }
27
+ return plan.lazyCompilation;
28
+ }
29
+ const warnedLazyApps = new Set();
30
+ function warnUnresolvedRouteComponents(appDirectory, unresolvedByEntry) {
31
+ if (warnedLazyApps.has(appDirectory)) return;
32
+ warnedLazyApps.add(appDirectory);
33
+ const detail = Array.from(unresolvedByEntry).map(([entry, components])=>`${entry}: ${components.join(', ')}`).join('; ');
34
+ 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.`);
35
+ }
36
+ export { builderPluginAdapterLazyCompilation };