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

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 (33) hide show
  1. package/dist/cjs/builder/generator/getBuilderEnvironments.js +37 -0
  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/rsbuild.js +7 -3
  9. package/dist/cjs/utils/initAppContext.js +12 -1
  10. package/dist/esm/builder/generator/getBuilderEnvironments.mjs +37 -0
  11. package/dist/esm/builder/generator/index.mjs +2 -1
  12. package/dist/esm/builder/shared/builderPlugins/adapterLazyCompilation.mjs +36 -0
  13. package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +4 -29
  14. package/dist/esm/builder/shared/builderPlugins/index.mjs +1 -0
  15. package/dist/esm/builder/shared/lazyCompilation.mjs +6 -4
  16. package/dist/esm/plugins/deploy/index.mjs +9 -1
  17. package/dist/esm/rsbuild.mjs +7 -3
  18. package/dist/esm/utils/initAppContext.mjs +12 -1
  19. package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +37 -0
  20. package/dist/esm-node/builder/generator/index.mjs +2 -1
  21. package/dist/esm-node/builder/shared/builderPlugins/adapterLazyCompilation.mjs +37 -0
  22. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +4 -29
  23. package/dist/esm-node/builder/shared/builderPlugins/index.mjs +1 -0
  24. package/dist/esm-node/builder/shared/lazyCompilation.mjs +6 -4
  25. package/dist/esm-node/plugins/deploy/index.mjs +9 -1
  26. package/dist/esm-node/rsbuild.mjs +7 -3
  27. package/dist/esm-node/utils/initAppContext.mjs +12 -1
  28. package/dist/types/builder/shared/builderPlugins/adapterLazyCompilation.d.ts +3 -0
  29. package/dist/types/builder/shared/builderPlugins/index.d.ts +1 -0
  30. package/dist/types/builder/shared/lazyCompilation.d.ts +7 -5
  31. package/dist/types/builder/shared/types.d.ts +3 -3
  32. package/dist/types/rsbuild.d.ts +1 -0
  33. package/package.json +19 -27
@@ -143,7 +143,44 @@ function getEffectBffEntry(normalizedConfig, appContext) {
143
143
  function isCloudflareWorkerDeploy(normalizedConfig) {
144
144
  return normalizedConfig.deploy?.target === 'cloudflare' || 'cloudflare' === process.env.MODERNJS_DEPLOY;
145
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
+ }
146
182
  function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig) {
183
+ applySourceBuildReactRuntimeAliases(normalizedConfig, appContext, tempBuilderConfig);
147
184
  const entries = {};
148
185
  const { entrypoints = [], checkedEntries } = appContext;
149
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', {
@@ -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);
@@ -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: [],
@@ -100,7 +100,44 @@ function getEffectBffEntry(normalizedConfig, appContext) {
100
100
  function isCloudflareWorkerDeploy(normalizedConfig) {
101
101
  return normalizedConfig.deploy?.target === 'cloudflare' || 'cloudflare' === process.env.MODERNJS_DEPLOY;
102
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
+ }
103
139
  function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig) {
140
+ applySourceBuildReactRuntimeAliases(normalizedConfig, appContext, tempBuilderConfig);
104
141
  const entries = {};
105
142
  const { entrypoints = [], checkedEntries } = appContext;
106
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 };
@@ -1,30 +1,21 @@
1
1
  import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/builder";
2
- import { fs, isUseRsc, isUseSSRBundle, logger } from "@modern-js/utils";
2
+ import { fs, isUseRsc, isUseSSRBundle } from "@modern-js/utils";
3
3
  import { mergeRsbuildConfig } from "@rsbuild/core";
4
4
  import { getServerCombinedModuleFile } from "../../../plugins/analyze/utils.mjs";
5
5
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins/index.mjs";
6
- import { aggregateEagerRouteComponentFiles, planSSRLazyCompilation } from "../lazyCompilation.mjs";
7
6
  import * as __rspack_external_path from "path";
8
7
  const builderPluginAdapterSSR = (options)=>({
9
8
  name: 'builder-plugin-adapter-modern-ssr',
10
9
  setup (api) {
11
- const { normalizedConfig, appContext, eagerRouteComponentFilesByEntry } = options;
12
- api.modifyRsbuildConfig((config)=>{
13
- const merged = mergeRsbuildConfig(config, {
10
+ const { normalizedConfig, appContext } = options;
11
+ api.modifyRsbuildConfig((config)=>mergeRsbuildConfig(config, {
14
12
  html: {
15
13
  inject: isStreamingSSR(normalizedConfig) ? 'head' : void 0
16
14
  },
17
15
  server: {
18
16
  compress: isStreamingSSR(normalizedConfig) || isUseRsc(normalizedConfig) ? false : void 0
19
17
  }
20
- });
21
- const lazyCompilation = getSSRLazyCompilation(merged.dev?.lazyCompilation, normalizedConfig, appContext, eagerRouteComponentFilesByEntry);
22
- if (void 0 !== lazyCompilation) merged.dev = {
23
- ...merged.dev,
24
- lazyCompilation
25
- };
26
- return merged;
27
- });
18
+ }));
28
19
  api.modifyBundlerChain(async (chain, { target, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer, environment })=>{
29
20
  const builderConfig = environment.config;
30
21
  const { normalizedConfig } = options;
@@ -60,22 +51,6 @@ const isStreamingSSR = (userConfig)=>{
60
51
  }
61
52
  return false;
62
53
  };
63
- function getSSRLazyCompilation(current, normalizedConfig, appContext, eagerRouteComponentFilesByEntry) {
64
- if (!current || isUseRsc(normalizedConfig) || !isStreamingSSR(normalizedConfig)) return;
65
- const plan = planSSRLazyCompilation(current, aggregateEagerRouteComponentFiles(eagerRouteComponentFilesByEntry));
66
- if (!plan.apply) {
67
- if (plan.unresolvedByEntry) warnUnresolvedRouteComponents(appContext.appDirectory, plan.unresolvedByEntry);
68
- return;
69
- }
70
- return plan.lazyCompilation;
71
- }
72
- const warnedLazyApps = new Set();
73
- function warnUnresolvedRouteComponents(appDirectory, unresolvedByEntry) {
74
- if (warnedLazyApps.has(appDirectory)) return;
75
- warnedLazyApps.add(appDirectory);
76
- const detail = Array.from(unresolvedByEntry).map(([entry, comps])=>`${entry}: ${comps.join(', ')}`).join('; ');
77
- 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.`);
78
- }
79
54
  function applyAsyncChunkHtmlPlugin({ chain, modernConfig, HtmlBundlerPlugin }) {
80
55
  if (isStreamingSSR(modernConfig) || isUseRsc(modernConfig)) chain.plugin('html-async-chunk').use(HtmlAsyncChunkPlugin, [
81
56
  HtmlBundlerPlugin
@@ -1,5 +1,6 @@
1
1
  export * from "./adapterBasic.mjs";
2
2
  export * from "./adapterHtml.mjs";
3
+ export * from "./adapterLazyCompilation.mjs";
3
4
  export * from "./adapterPrecompress.mjs";
4
5
  export * from "./adapterSSR.mjs";
5
6
  export * from "./builderHooks.mjs";
@@ -11,7 +11,7 @@ function aggregateEagerRouteComponentFiles(byEntry) {
11
11
  unresolvedByEntry
12
12
  };
13
13
  }
14
- function buildSSRLazyCompilationTest(eagerRouteFiles, userTest) {
14
+ function buildRouteEagerLazyCompilationTest(eagerRouteFiles, userTest) {
15
15
  const userTestFn = 'function' == typeof userTest ? userTest : userTest instanceof RegExp ? (m)=>userTest.test(m.resource || '') : ()=>true;
16
16
  return (m)=>{
17
17
  const resource = m.resource;
@@ -20,7 +20,8 @@ function buildSSRLazyCompilationTest(eagerRouteFiles, userTest) {
20
20
  return userTestFn(m);
21
21
  };
22
22
  }
23
- function planSSRLazyCompilation(current, info) {
23
+ const buildSSRLazyCompilationTest = buildRouteEagerLazyCompilationTest;
24
+ function planRouteEagerLazyCompilation(current, info) {
24
25
  if (!current) return {
25
26
  apply: false
26
27
  };
@@ -37,8 +38,9 @@ function planSSRLazyCompilation(current, info) {
37
38
  apply: true,
38
39
  lazyCompilation: {
39
40
  ...base,
40
- test: buildSSRLazyCompilationTest(info.files, userTest)
41
+ test: buildRouteEagerLazyCompilationTest(info.files, userTest)
41
42
  }
42
43
  };
43
44
  }
44
- export { aggregateEagerRouteComponentFiles, buildSSRLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planSSRLazyCompilation };
45
+ const planSSRLazyCompilation = planRouteEagerLazyCompilation;
46
+ export { aggregateEagerRouteComponentFiles, buildRouteEagerLazyCompilationTest, buildSSRLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planRouteEagerLazyCompilation, planSSRLazyCompilation };
@@ -14,7 +14,15 @@ const deployPresets = {
14
14
  };
15
15
  const getSupportedDeployTargets = ()=>Object.keys(deployPresets);
16
16
  const isDeployTarget = (target)=>Object.prototype.hasOwnProperty.call(deployPresets, target);
17
- const resolveDeployTarget = (modernConfig, envDeployTarget = process.env.MODERNJS_DEPLOY, detectedProvider = provider)=>modernConfig.deploy?.target || envDeployTarget || detectedProvider || 'node';
17
+ const providerDeployTargets = {
18
+ vercel: 'vercel',
19
+ netlify: 'netlify',
20
+ cloudflare: 'cloudflare',
21
+ cloudflare_pages: 'cloudflare',
22
+ cloudflare_workers: 'cloudflare'
23
+ };
24
+ const normalizeDetectedProvider = (value)=>value ? providerDeployTargets[value] : void 0;
25
+ const resolveDeployTarget = (modernConfig, envDeployTarget = process.env.MODERNJS_DEPLOY, detectedProvider = provider)=>modernConfig.deploy?.target || envDeployTarget || normalizeDetectedProvider(detectedProvider) || 'node';
18
26
  async function getDeployPreset(appContext, modernConfig, deployTarget, api) {
19
27
  const { appDirectory, distDirectory, metaName } = appContext;
20
28
  const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory, metaName);
@@ -23,9 +23,13 @@ async function resolveModernRsbuildConfig(options) {
23
23
  plugins: modernConfig.builderPlugins
24
24
  };
25
25
  const appContext = getAppContext();
26
- const { rsbuildConfig, rsbuildPlugins } = await parseRspackConfig(nonStandardConfig, {
27
- cwd
28
- });
26
+ const builderOptions = {
27
+ cwd,
28
+ ...void 0 === options.disableReactCompiler ? {} : {
29
+ disableReactCompiler: options.disableReactCompiler
30
+ }
31
+ };
32
+ const { rsbuildConfig, rsbuildPlugins } = await parseRspackConfig(nonStandardConfig, builderOptions);
29
33
  const adapterParams = {
30
34
  appContext,
31
35
  normalizedConfig: modernConfig
@@ -1,5 +1,16 @@
1
1
  import { address, fs } from "@modern-js/utils";
2
2
  import path from "path";
3
+ function isSymlinkedNodeModules(appDirectory) {
4
+ try {
5
+ return fs.lstatSync(path.resolve(appDirectory, 'node_modules')).isSymbolicLink();
6
+ } catch {
7
+ return false;
8
+ }
9
+ }
10
+ function getDefaultInternalDirectory(appDirectory, metaName) {
11
+ if (isSymlinkedNodeModules(appDirectory)) return path.resolve(appDirectory, `.${metaName}`);
12
+ return path.resolve(appDirectory, `./node_modules/.${metaName}`);
13
+ }
3
14
  const initAppContext = ({ metaName, appDirectory, runtimeConfigFile, options, tempDir })=>{
4
15
  const { apiDir = 'api', sharedDir = 'shared', bffRuntimeFramework = 'hono' } = options || {};
5
16
  const pkgPath = path.resolve(appDirectory, './package.json');
@@ -13,7 +24,7 @@ const initAppContext = ({ metaName, appDirectory, runtimeConfigFile, options, te
13
24
  lambdaDirectory: path.resolve(appDirectory, apiDir, 'lambda'),
14
25
  sharedDirectory: path.resolve(appDirectory, sharedDir),
15
26
  serverPlugins: [],
16
- internalDirectory: path.resolve(appDirectory, tempDir || `./node_modules/.${metaName}`),
27
+ internalDirectory: tempDir ? path.resolve(appDirectory, tempDir) : getDefaultInternalDirectory(appDirectory, metaName),
17
28
  htmlTemplates: {},
18
29
  serverRoutes: [],
19
30
  entrypoints: [],
@@ -105,7 +105,44 @@ function getEffectBffEntry(normalizedConfig, appContext) {
105
105
  function isCloudflareWorkerDeploy(normalizedConfig) {
106
106
  return normalizedConfig.deploy?.target === 'cloudflare' || 'cloudflare' === process.env.MODERNJS_DEPLOY;
107
107
  }
108
+ function getConsumingReactRuntimeAliases(appContext) {
109
+ const resolvePaths = [
110
+ appContext.appDirectory,
111
+ process.cwd()
112
+ ];
113
+ return {
114
+ react$: resolvePackageFile('react', 'index.js', resolvePaths),
115
+ 'react/jsx-runtime$': resolvePackageFile('react', 'jsx-runtime.js', resolvePaths),
116
+ 'react/jsx-dev-runtime$': resolvePackageFile('react', 'jsx-dev-runtime.js', resolvePaths),
117
+ 'react/compiler-runtime$': resolvePackageFile('react', 'compiler-runtime.js', resolvePaths)
118
+ };
119
+ }
120
+ function setResolvedAliases(alias, aliases) {
121
+ for (const [name, value] of Object.entries(aliases))setAliasIfPresent(alias, name, value);
122
+ }
123
+ function appendBundlerChain(config, handler) {
124
+ const bundlerChain = config.tools?.bundlerChain;
125
+ config.tools = {
126
+ ...config.tools,
127
+ bundlerChain: bundlerChain ? Array.isArray(bundlerChain) ? [
128
+ ...bundlerChain,
129
+ handler
130
+ ] : [
131
+ bundlerChain,
132
+ handler
133
+ ] : handler
134
+ };
135
+ }
136
+ function applySourceBuildReactRuntimeAliases(normalizedConfig, appContext, tempBuilderConfig) {
137
+ if (!normalizedConfig.experiments?.sourceBuild) return;
138
+ const aliases = getConsumingReactRuntimeAliases(appContext);
139
+ if (!Object.values(aliases).some(Boolean)) return;
140
+ appendBundlerChain(tempBuilderConfig, (chain)=>{
141
+ setResolvedAliases(chain.resolve.alias, aliases);
142
+ });
143
+ }
108
144
  function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig) {
145
+ applySourceBuildReactRuntimeAliases(normalizedConfig, appContext, tempBuilderConfig);
109
146
  const entries = {};
110
147
  const { entrypoints = [], checkedEntries } = appContext;
111
148
  for (const { entryName, internalEntry, entry } of entrypoints){
@@ -1,7 +1,7 @@
1
1
  import "node:module";
2
2
  import { createBuilder } from "@modern-js/builder";
3
3
  import { mergeRsbuildConfig } from "@rsbuild/core";
4
- import { builderPluginAdapterBasic, builderPluginAdapterHooks, builderPluginAdapterHtml, builderPluginAdapterPrecompress, builderPluginAdapterSSR } from "../shared/builderPlugins/index.mjs";
4
+ import { builderPluginAdapterBasic, builderPluginAdapterHooks, builderPluginAdapterHtml, builderPluginAdapterLazyCompilation, builderPluginAdapterPrecompress, builderPluginAdapterSSR } from "../shared/builderPlugins/index.mjs";
5
5
  import { builderPluginAdapterCopy } from "./adapterCopy.mjs";
6
6
  import { createBuilderProviderConfig } from "./createBuilderProviderConfig.mjs";
7
7
  import { getBuilderEnvironments } from "./getBuilderEnvironments.mjs";
@@ -39,6 +39,7 @@ async function generateBuilder(options, bundlerType) {
39
39
  async function applyBuilderPlugins(builder, options) {
40
40
  builder.addPlugins([
41
41
  builderPluginAdapterBasic(options),
42
+ builderPluginAdapterLazyCompilation(options),
42
43
  builderPluginAdapterSSR(options),
43
44
  builderPluginAdapterHtml(options),
44
45
  builderPluginAdapterPrecompress(options),
@@ -0,0 +1,37 @@
1
+ import "node:module";
2
+ import { isUseRsc, logger } from "@modern-js/utils";
3
+ import { aggregateEagerRouteComponentFiles, planRouteEagerLazyCompilation } from "../lazyCompilation.mjs";
4
+ const builderPluginAdapterLazyCompilation = (options)=>({
5
+ name: 'builder-plugin-adapter-modern-lazy-compilation',
6
+ setup (api) {
7
+ api.modifyRsbuildConfig((config)=>{
8
+ const lazyCompilation = getRouteEagerLazyCompilation(options, config);
9
+ if (void 0 === lazyCompilation) return config;
10
+ return {
11
+ ...config,
12
+ dev: {
13
+ ...config.dev,
14
+ lazyCompilation
15
+ }
16
+ };
17
+ });
18
+ }
19
+ });
20
+ function getRouteEagerLazyCompilation(options, config) {
21
+ const current = config.dev?.lazyCompilation;
22
+ if (!current || isUseRsc(options.normalizedConfig)) return;
23
+ const plan = planRouteEagerLazyCompilation(current, aggregateEagerRouteComponentFiles(options.eagerRouteComponentFilesByEntry));
24
+ if (!plan.apply) {
25
+ if (plan.unresolvedByEntry) warnUnresolvedRouteComponents(options.appContext.appDirectory, plan.unresolvedByEntry);
26
+ return;
27
+ }
28
+ return plan.lazyCompilation;
29
+ }
30
+ const warnedLazyApps = new Set();
31
+ function warnUnresolvedRouteComponents(appDirectory, unresolvedByEntry) {
32
+ if (warnedLazyApps.has(appDirectory)) return;
33
+ warnedLazyApps.add(appDirectory);
34
+ const detail = Array.from(unresolvedByEntry).map(([entry, components])=>`${entry}: ${components.join(', ')}`).join('; ');
35
+ 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.`);
36
+ }
37
+ export { builderPluginAdapterLazyCompilation };
@@ -1,32 +1,23 @@
1
1
  import __rslib_shim_module__ from "node:module";
2
2
  const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
3
  import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/builder";
4
- import { fs, isUseRsc, isUseSSRBundle, logger } from "@modern-js/utils";
4
+ import { fs, isUseRsc, isUseSSRBundle } from "@modern-js/utils";
5
5
  import { mergeRsbuildConfig } from "@rsbuild/core";
6
6
  import { getServerCombinedModuleFile } from "../../../plugins/analyze/utils.mjs";
7
7
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins/index.mjs";
8
- import { aggregateEagerRouteComponentFiles, planSSRLazyCompilation } from "../lazyCompilation.mjs";
9
8
  import * as __rspack_external_path from "path";
10
9
  const builderPluginAdapterSSR = (options)=>({
11
10
  name: 'builder-plugin-adapter-modern-ssr',
12
11
  setup (api) {
13
- const { normalizedConfig, appContext, eagerRouteComponentFilesByEntry } = options;
14
- api.modifyRsbuildConfig((config)=>{
15
- const merged = mergeRsbuildConfig(config, {
12
+ const { normalizedConfig, appContext } = options;
13
+ api.modifyRsbuildConfig((config)=>mergeRsbuildConfig(config, {
16
14
  html: {
17
15
  inject: isStreamingSSR(normalizedConfig) ? 'head' : void 0
18
16
  },
19
17
  server: {
20
18
  compress: isStreamingSSR(normalizedConfig) || isUseRsc(normalizedConfig) ? false : void 0
21
19
  }
22
- });
23
- const lazyCompilation = getSSRLazyCompilation(merged.dev?.lazyCompilation, normalizedConfig, appContext, eagerRouteComponentFilesByEntry);
24
- if (void 0 !== lazyCompilation) merged.dev = {
25
- ...merged.dev,
26
- lazyCompilation
27
- };
28
- return merged;
29
- });
20
+ }));
30
21
  api.modifyBundlerChain(async (chain, { target, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer, environment })=>{
31
22
  const builderConfig = environment.config;
32
23
  const { normalizedConfig } = options;
@@ -62,22 +53,6 @@ const isStreamingSSR = (userConfig)=>{
62
53
  }
63
54
  return false;
64
55
  };
65
- function getSSRLazyCompilation(current, normalizedConfig, appContext, eagerRouteComponentFilesByEntry) {
66
- if (!current || isUseRsc(normalizedConfig) || !isStreamingSSR(normalizedConfig)) return;
67
- const plan = planSSRLazyCompilation(current, aggregateEagerRouteComponentFiles(eagerRouteComponentFilesByEntry));
68
- if (!plan.apply) {
69
- if (plan.unresolvedByEntry) warnUnresolvedRouteComponents(appContext.appDirectory, plan.unresolvedByEntry);
70
- return;
71
- }
72
- return plan.lazyCompilation;
73
- }
74
- const warnedLazyApps = new Set();
75
- function warnUnresolvedRouteComponents(appDirectory, unresolvedByEntry) {
76
- if (warnedLazyApps.has(appDirectory)) return;
77
- warnedLazyApps.add(appDirectory);
78
- const detail = Array.from(unresolvedByEntry).map(([entry, comps])=>`${entry}: ${comps.join(', ')}`).join('; ');
79
- 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.`);
80
- }
81
56
  function applyAsyncChunkHtmlPlugin({ chain, modernConfig, HtmlBundlerPlugin }) {
82
57
  if (isStreamingSSR(modernConfig) || isUseRsc(modernConfig)) chain.plugin('html-async-chunk').use(HtmlAsyncChunkPlugin, [
83
58
  HtmlBundlerPlugin
@@ -1,6 +1,7 @@
1
1
  import "node:module";
2
2
  export * from "./adapterBasic.mjs";
3
3
  export * from "./adapterHtml.mjs";
4
+ export * from "./adapterLazyCompilation.mjs";
4
5
  export * from "./adapterPrecompress.mjs";
5
6
  export * from "./adapterSSR.mjs";
6
7
  export * from "./builderHooks.mjs";
@@ -12,7 +12,7 @@ function aggregateEagerRouteComponentFiles(byEntry) {
12
12
  unresolvedByEntry
13
13
  };
14
14
  }
15
- function buildSSRLazyCompilationTest(eagerRouteFiles, userTest) {
15
+ function buildRouteEagerLazyCompilationTest(eagerRouteFiles, userTest) {
16
16
  const userTestFn = 'function' == typeof userTest ? userTest : userTest instanceof RegExp ? (m)=>userTest.test(m.resource || '') : ()=>true;
17
17
  return (m)=>{
18
18
  const resource = m.resource;
@@ -21,7 +21,8 @@ function buildSSRLazyCompilationTest(eagerRouteFiles, userTest) {
21
21
  return userTestFn(m);
22
22
  };
23
23
  }
24
- function planSSRLazyCompilation(current, info) {
24
+ const buildSSRLazyCompilationTest = buildRouteEagerLazyCompilationTest;
25
+ function planRouteEagerLazyCompilation(current, info) {
25
26
  if (!current) return {
26
27
  apply: false
27
28
  };
@@ -38,8 +39,9 @@ function planSSRLazyCompilation(current, info) {
38
39
  apply: true,
39
40
  lazyCompilation: {
40
41
  ...base,
41
- test: buildSSRLazyCompilationTest(info.files, userTest)
42
+ test: buildRouteEagerLazyCompilationTest(info.files, userTest)
42
43
  }
43
44
  };
44
45
  }
45
- export { aggregateEagerRouteComponentFiles, buildSSRLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planSSRLazyCompilation };
46
+ const planSSRLazyCompilation = planRouteEagerLazyCompilation;
47
+ export { aggregateEagerRouteComponentFiles, buildRouteEagerLazyCompilationTest, buildSSRLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planRouteEagerLazyCompilation, planSSRLazyCompilation };
@@ -15,7 +15,15 @@ const deployPresets = {
15
15
  };
16
16
  const getSupportedDeployTargets = ()=>Object.keys(deployPresets);
17
17
  const isDeployTarget = (target)=>Object.prototype.hasOwnProperty.call(deployPresets, target);
18
- const resolveDeployTarget = (modernConfig, envDeployTarget = process.env.MODERNJS_DEPLOY, detectedProvider = provider)=>modernConfig.deploy?.target || envDeployTarget || detectedProvider || 'node';
18
+ const providerDeployTargets = {
19
+ vercel: 'vercel',
20
+ netlify: 'netlify',
21
+ cloudflare: 'cloudflare',
22
+ cloudflare_pages: 'cloudflare',
23
+ cloudflare_workers: 'cloudflare'
24
+ };
25
+ const normalizeDetectedProvider = (value)=>value ? providerDeployTargets[value] : void 0;
26
+ const resolveDeployTarget = (modernConfig, envDeployTarget = process.env.MODERNJS_DEPLOY, detectedProvider = provider)=>modernConfig.deploy?.target || envDeployTarget || normalizeDetectedProvider(detectedProvider) || 'node';
19
27
  async function getDeployPreset(appContext, modernConfig, deployTarget, api) {
20
28
  const { appDirectory, distDirectory, metaName } = appContext;
21
29
  const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory, metaName);
@@ -24,9 +24,13 @@ async function resolveModernRsbuildConfig(options) {
24
24
  plugins: modernConfig.builderPlugins
25
25
  };
26
26
  const appContext = getAppContext();
27
- const { rsbuildConfig, rsbuildPlugins } = await parseRspackConfig(nonStandardConfig, {
28
- cwd
29
- });
27
+ const builderOptions = {
28
+ cwd,
29
+ ...void 0 === options.disableReactCompiler ? {} : {
30
+ disableReactCompiler: options.disableReactCompiler
31
+ }
32
+ };
33
+ const { rsbuildConfig, rsbuildPlugins } = await parseRspackConfig(nonStandardConfig, builderOptions);
30
34
  const adapterParams = {
31
35
  appContext,
32
36
  normalizedConfig: modernConfig
@@ -1,6 +1,17 @@
1
1
  import "node:module";
2
2
  import { address, fs } from "@modern-js/utils";
3
3
  import path from "path";
4
+ function isSymlinkedNodeModules(appDirectory) {
5
+ try {
6
+ return fs.lstatSync(path.resolve(appDirectory, 'node_modules')).isSymbolicLink();
7
+ } catch {
8
+ return false;
9
+ }
10
+ }
11
+ function getDefaultInternalDirectory(appDirectory, metaName) {
12
+ if (isSymlinkedNodeModules(appDirectory)) return path.resolve(appDirectory, `.${metaName}`);
13
+ return path.resolve(appDirectory, `./node_modules/.${metaName}`);
14
+ }
4
15
  const initAppContext = ({ metaName, appDirectory, runtimeConfigFile, options, tempDir })=>{
5
16
  const { apiDir = 'api', sharedDir = 'shared', bffRuntimeFramework = 'hono' } = options || {};
6
17
  const pkgPath = path.resolve(appDirectory, './package.json');
@@ -14,7 +25,7 @@ const initAppContext = ({ metaName, appDirectory, runtimeConfigFile, options, te
14
25
  lambdaDirectory: path.resolve(appDirectory, apiDir, 'lambda'),
15
26
  sharedDirectory: path.resolve(appDirectory, sharedDir),
16
27
  serverPlugins: [],
17
- internalDirectory: path.resolve(appDirectory, tempDir || `./node_modules/.${metaName}`),
28
+ internalDirectory: tempDir ? path.resolve(appDirectory, tempDir) : getDefaultInternalDirectory(appDirectory, metaName),
18
29
  htmlTemplates: {},
19
30
  serverRoutes: [],
20
31
  entrypoints: [],
@@ -0,0 +1,3 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ import type { BuilderOptions } from '../types';
3
+ export declare const builderPluginAdapterLazyCompilation: (options: BuilderOptions) => RsbuildPlugin;
@@ -1,5 +1,6 @@
1
1
  export * from './adapterBasic';
2
2
  export * from './adapterHtml';
3
+ export * from './adapterLazyCompilation';
3
4
  export * from './adapterPrecompress';
4
5
  export * from './adapterSSR';
5
6
  export * from './builderHooks';
@@ -15,8 +15,8 @@ export type EagerRouteComponentInfo = {
15
15
  * Aggregate the per-entry route component data (collected by the router plugin
16
16
  * during route generation and threaded in as
17
17
  * `BuilderOptions.eagerRouteComponentFilesByEntry`) into the flat shape
18
- * {@link planSSRLazyCompilation} expects: one Set of all route files plus the
19
- * unresolved specifiers keyed by entry.
18
+ * {@link planRouteEagerLazyCompilation} expects: one Set of all route files
19
+ * plus the unresolved specifiers keyed by entry.
20
20
  */
21
21
  export declare function aggregateEagerRouteComponentFiles(byEntry: EagerRouteComponentFilesByEntry | undefined): EagerRouteComponentInfo;
22
22
  /**
@@ -25,7 +25,8 @@ export declare function aggregateEagerRouteComponentFiles(byEntry: EagerRouteCom
25
25
  * render time), while delegating all other modules to the user's `test`
26
26
  * (defaulting to lazy when the user did not provide one).
27
27
  */
28
- export declare function buildSSRLazyCompilationTest(eagerRouteFiles: Set<string>, userTest?: LazyCompilationTest): LazyCompilationTestFn;
28
+ export declare function buildRouteEagerLazyCompilationTest(eagerRouteFiles: Set<string>, userTest?: LazyCompilationTest): LazyCompilationTestFn;
29
+ export declare const buildSSRLazyCompilationTest: typeof buildRouteEagerLazyCompilationTest;
29
30
  export type SSRLazyPlan = {
30
31
  apply: false;
31
32
  unresolvedByEntry?: Map<string, string[]>;
@@ -34,10 +35,11 @@ export type SSRLazyPlan = {
34
35
  lazyCompilation: Record<string, unknown>;
35
36
  };
36
37
  /**
37
- * Decide whether to apply the route-eager lazy compilation for an SSR project.
38
+ * Decide whether to apply route-eager lazy compilation for a project.
38
39
  * Checks unresolved route components FIRST: if any exist we cannot guarantee
39
40
  * they are eager, so we skip the optimization (and surface them so the caller
40
41
  * can warn) rather than silently leaving a route lazy. `current` is the
41
42
  * existing `dev.lazyCompilation` value (lazy must be enabled for this to apply).
42
43
  */
43
- export declare function planSSRLazyCompilation(current: unknown, info: EagerRouteComponentInfo): SSRLazyPlan;
44
+ export declare function planRouteEagerLazyCompilation(current: unknown, info: EagerRouteComponentInfo): SSRLazyPlan;
45
+ export declare const planSSRLazyCompilation: typeof planRouteEagerLazyCompilation;
@@ -8,9 +8,9 @@ export type BuilderOptions = {
8
8
  * Route component files collected from the FINAL file-system routes (after
9
9
  * all `modifyFileSystemRoutes` consumers ran), keyed by entry name. Populated
10
10
  * by the router plugin during route generation and threaded in here (read
11
- * FRESH from the app context AFTER `generateEntryCode` runs) so the SSR
12
- * builder plugin can force route component chunks eager under lazy
13
- * compilation. Explicit param instead of a direct `_internalContext` read.
11
+ * FRESH from the app context AFTER `generateEntryCode` runs) so builder
12
+ * plugins can force route component chunks eager under lazy compilation.
13
+ * Explicit param instead of a direct `_internalContext` read.
14
14
  */
15
15
  eagerRouteComponentFilesByEntry?: EagerRouteComponentFilesByEntry;
16
16
  };
@@ -3,6 +3,7 @@ type ResolveModernRsbuildConfigOptions = {
3
3
  command: string;
4
4
  configPath?: string;
5
5
  cwd?: string;
6
+ disableReactCompiler?: boolean;
6
7
  metaName?: string;
7
8
  modifyModernConfig?: (config: AppUserConfig) => AppUserConfig | Promise<AppUserConfig>;
8
9
  };
package/package.json CHANGED
@@ -17,40 +17,32 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.4.0-ultramodern.2",
20
+ "version": "3.4.0-ultramodern.3",
21
21
  "types": "./dist/types/index.d.ts",
22
22
  "main": "./dist/cjs/index.js",
23
23
  "exports": {
24
24
  ".": {
25
25
  "types": "./dist/types/index.d.ts",
26
- "node": {
27
- "import": "./dist/esm-node/index.mjs",
28
- "require": "./dist/cjs/index.js"
29
- },
26
+ "import": "./dist/esm-node/index.mjs",
27
+ "require": "./dist/cjs/index.js",
30
28
  "default": "./dist/cjs/index.js"
31
29
  },
32
30
  "./builder": {
33
31
  "types": "./dist/types/builder/index.d.ts",
34
- "node": {
35
- "import": "./dist/esm-node/builder/index.mjs",
36
- "require": "./dist/cjs/builder/index.js"
37
- },
32
+ "import": "./dist/esm-node/builder/index.mjs",
33
+ "require": "./dist/cjs/builder/index.js",
38
34
  "default": "./dist/cjs/builder/index.js"
39
35
  },
40
36
  "./cli": {
41
37
  "types": "./dist/types/index.d.ts",
42
- "node": {
43
- "import": "./dist/esm-node/index.mjs",
44
- "require": "./dist/cjs/index.js"
45
- },
38
+ "import": "./dist/esm-node/index.mjs",
39
+ "require": "./dist/cjs/index.js",
46
40
  "default": "./dist/cjs/index.js"
47
41
  },
48
42
  "./cli/run": {
49
43
  "types": "./dist/types/run/index.d.ts",
50
- "node": {
51
- "import": "./dist/esm-node/run/index.mjs",
52
- "require": "./dist/cjs/run/index.js"
53
- },
44
+ "import": "./dist/esm-node/run/index.mjs",
45
+ "require": "./dist/cjs/run/index.js",
54
46
  "default": "./dist/cjs/run/index.js"
55
47
  },
56
48
  "./types": {
@@ -98,16 +90,16 @@
98
90
  "ndepe": "^0.1.13",
99
91
  "pkg-types": "^2.3.1",
100
92
  "std-env": "4.1.0",
101
- "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.4.0-ultramodern.2",
102
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.4.0-ultramodern.2",
103
- "@modern-js/i18n-utils": "npm:@bleedingdev/modern-js-i18n-utils@3.4.0-ultramodern.2",
104
- "@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.4.0-ultramodern.2",
105
- "@modern-js/server": "npm:@bleedingdev/modern-js-server@3.4.0-ultramodern.2",
106
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.4.0-ultramodern.2",
107
- "@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.4.0-ultramodern.2",
108
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.4.0-ultramodern.2",
109
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.4.0-ultramodern.2",
110
- "@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.4.0-ultramodern.2"
93
+ "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.4.0-ultramodern.3",
94
+ "@modern-js/i18n-utils": "npm:@bleedingdev/modern-js-i18n-utils@3.4.0-ultramodern.3",
95
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.4.0-ultramodern.3",
96
+ "@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.4.0-ultramodern.3",
97
+ "@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.4.0-ultramodern.3",
98
+ "@modern-js/server": "npm:@bleedingdev/modern-js-server@3.4.0-ultramodern.3",
99
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.4.0-ultramodern.3",
100
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.4.0-ultramodern.3",
101
+ "@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.4.0-ultramodern.3",
102
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.4.0-ultramodern.3"
111
103
  },
112
104
  "devDependencies": {
113
105
  "@rslib/core": "0.23.0",