@modern-js/app-tools 3.2.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/cjs/builder/builder-rspack/index.js +9 -5
  2. package/dist/cjs/builder/generator/adapterCopy.js +9 -5
  3. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +9 -5
  4. package/dist/cjs/builder/generator/createCopyPattern.js +9 -5
  5. package/dist/cjs/builder/generator/getBuilderEnvironments.js +9 -5
  6. package/dist/cjs/builder/generator/index.js +9 -5
  7. package/dist/cjs/builder/index.js +9 -5
  8. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +9 -5
  9. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +10 -6
  10. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +37 -8
  11. package/dist/cjs/builder/shared/builderPlugins/builderHooks.js +12 -8
  12. package/dist/cjs/builder/shared/builderPlugins/index.js +9 -5
  13. package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +9 -5
  14. package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +12 -8
  15. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +9 -5
  16. package/dist/cjs/builder/shared/bundlerPlugins/index.js +9 -5
  17. package/dist/cjs/builder/shared/createCopyInfo.js +9 -5
  18. package/dist/cjs/builder/shared/index.js +9 -5
  19. package/dist/cjs/builder/shared/lazyCompilation.js +94 -0
  20. package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +12 -8
  21. package/dist/cjs/commands/build.js +9 -5
  22. package/dist/cjs/commands/deploy.js +9 -5
  23. package/dist/cjs/commands/dev.js +9 -5
  24. package/dist/cjs/commands/index.js +9 -5
  25. package/dist/cjs/commands/info.js +9 -5
  26. package/dist/cjs/commands/inspect.js +12 -8
  27. package/dist/cjs/commands/serve.js +9 -5
  28. package/dist/cjs/compat/hooks.js +9 -5
  29. package/dist/cjs/compat/index.js +9 -5
  30. package/dist/cjs/compat/utils.js +9 -5
  31. package/dist/cjs/config/default.js +27 -7
  32. package/dist/cjs/config/index.js +9 -5
  33. package/dist/cjs/config/initialize/index.js +9 -5
  34. package/dist/cjs/config/initialize/inits.js +9 -5
  35. package/dist/cjs/constants.js +13 -9
  36. package/dist/cjs/defineConfig.js +12 -8
  37. package/dist/cjs/esm/register-esm.js +9 -5
  38. package/dist/cjs/esm/ts-node-loader.js +9 -5
  39. package/dist/cjs/esm/ts-paths-loader.js +9 -5
  40. package/dist/cjs/index.js +21 -16
  41. package/dist/cjs/locale/en.js +12 -8
  42. package/dist/cjs/locale/index.js +9 -5
  43. package/dist/cjs/locale/zh.js +12 -8
  44. package/dist/cjs/plugins/analyze/constants.js +14 -10
  45. package/dist/cjs/plugins/analyze/getBundleEntry.js +9 -5
  46. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -5
  47. package/dist/cjs/plugins/analyze/getHtmlTemplate.js +9 -5
  48. package/dist/cjs/plugins/analyze/getServerRoutes.js +9 -5
  49. package/dist/cjs/plugins/analyze/index.js +12 -6
  50. package/dist/cjs/plugins/analyze/isDefaultExportFunction.js +9 -5
  51. package/dist/cjs/plugins/analyze/templates.js +12 -8
  52. package/dist/cjs/plugins/analyze/utils.js +9 -5
  53. package/dist/cjs/plugins/deploy/index.js +9 -5
  54. package/dist/cjs/plugins/deploy/platforms/gh-pages.js +9 -5
  55. package/dist/cjs/plugins/deploy/platforms/netlify.js +9 -5
  56. package/dist/cjs/plugins/deploy/platforms/node.js +9 -5
  57. package/dist/cjs/plugins/deploy/platforms/vercel.js +9 -5
  58. package/dist/cjs/plugins/deploy/utils/generator.js +9 -5
  59. package/dist/cjs/plugins/deploy/utils/index.js +9 -5
  60. package/dist/cjs/plugins/initialize/index.js +19 -6
  61. package/dist/cjs/plugins/serverBuild.js +9 -5
  62. package/dist/cjs/plugins/serverRuntime.js +12 -8
  63. package/dist/cjs/rsbuild.js +9 -5
  64. package/dist/cjs/run/index.js +9 -5
  65. package/dist/cjs/types/config/index.js +9 -5
  66. package/dist/cjs/types/index.js +9 -5
  67. package/dist/cjs/utils/config.js +9 -5
  68. package/dist/cjs/utils/createServer.js +14 -10
  69. package/dist/cjs/utils/env.js +9 -5
  70. package/dist/cjs/utils/generateWatchFiles.js +9 -5
  71. package/dist/cjs/utils/getConfigFile.js +9 -5
  72. package/dist/cjs/utils/getSelectedEntries.js +9 -5
  73. package/dist/cjs/utils/initAppContext.js +9 -5
  74. package/dist/cjs/utils/loadPlugins.js +9 -5
  75. package/dist/cjs/utils/printInstructions.js +9 -5
  76. package/dist/cjs/utils/register.js +9 -5
  77. package/dist/cjs/utils/restart.js +9 -5
  78. package/dist/cjs/utils/routes.js +9 -5
  79. package/dist/esm/builder/shared/builderPlugins/adapterHtml.mjs +1 -1
  80. package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +29 -4
  81. package/dist/esm/builder/shared/lazyCompilation.mjs +44 -0
  82. package/dist/esm/config/default.mjs +14 -1
  83. package/dist/esm/plugins/analyze/index.mjs +3 -1
  84. package/dist/esm/plugins/initialize/index.mjs +11 -2
  85. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.mjs +1 -1
  86. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +29 -4
  87. package/dist/esm-node/builder/shared/lazyCompilation.mjs +45 -0
  88. package/dist/esm-node/config/default.mjs +14 -1
  89. package/dist/esm-node/plugins/analyze/index.mjs +3 -1
  90. package/dist/esm-node/plugins/initialize/index.mjs +11 -2
  91. package/dist/types/builder/shared/lazyCompilation.d.ts +43 -0
  92. package/dist/types/builder/shared/types.d.ts +10 -0
  93. package/dist/types/config/default.d.ts +6 -0
  94. package/dist/types/types/plugin.d.ts +14 -0
  95. package/package.json +18 -18
@@ -0,0 +1,43 @@
1
+ import { type EagerRouteComponentFilesByEntry } from '@modern-js/utils';
2
+ export { type EagerRouteComponentFilesByEntry, type RouteComponentFileCollection, collectRouteComponentFiles, normalizeModulePath, } from '@modern-js/utils';
3
+ type ModuleLike = {
4
+ resource?: string;
5
+ };
6
+ type LazyCompilationTestFn = (m: ModuleLike) => boolean;
7
+ /** Matches Rspack's `LazyCompilationOptions['test']`. */
8
+ type LazyCompilationTest = RegExp | LazyCompilationTestFn | undefined;
9
+ export type EagerRouteComponentInfo = {
10
+ files: Set<string>;
11
+ /** Specifiers that could not be resolved, keyed by entry name. */
12
+ unresolvedByEntry: Map<string, string[]>;
13
+ };
14
+ /**
15
+ * Aggregate the per-entry route component data (collected by the router plugin
16
+ * during route generation and threaded in as
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.
20
+ */
21
+ export declare function aggregateEagerRouteComponentFiles(byEntry: EagerRouteComponentFilesByEntry | undefined): EagerRouteComponentInfo;
22
+ /**
23
+ * Build a `lazyCompilation.test` that forces route component modules to compile
24
+ * eagerly (so SSR first-screen chunk/CSS injection has the assets it needs at
25
+ * render time), while delegating all other modules to the user's `test`
26
+ * (defaulting to lazy when the user did not provide one).
27
+ */
28
+ export declare function buildSSRLazyCompilationTest(eagerRouteFiles: Set<string>, userTest?: LazyCompilationTest): LazyCompilationTestFn;
29
+ export type SSRLazyPlan = {
30
+ apply: false;
31
+ unresolvedByEntry?: Map<string, string[]>;
32
+ } | {
33
+ apply: true;
34
+ lazyCompilation: Record<string, unknown>;
35
+ };
36
+ /**
37
+ * Decide whether to apply the route-eager lazy compilation for an SSR project.
38
+ * Checks unresolved route components FIRST: if any exist we cannot guarantee
39
+ * they are eager, so we skip the optimization (and surface them so the caller
40
+ * can warn) rather than silently leaving a route lazy. `current` is the
41
+ * existing `dev.lazyCompilation` value (lazy must be enabled for this to apply).
42
+ */
43
+ export declare function planSSRLazyCompilation(current: unknown, info: EagerRouteComponentInfo): SSRLazyPlan;
@@ -1,6 +1,16 @@
1
+ import type { EagerRouteComponentFilesByEntry } from '@modern-js/utils';
1
2
  import type { AppNormalizedConfig } from '../../types';
2
3
  import type { AppToolsContext } from '../../types/plugin';
3
4
  export type BuilderOptions = {
4
5
  normalizedConfig: AppNormalizedConfig;
5
6
  appContext: AppToolsContext;
7
+ /**
8
+ * Route component files collected from the FINAL file-system routes (after
9
+ * all `modifyFileSystemRoutes` consumers ran), keyed by entry name. Populated
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.
14
+ */
15
+ eagerRouteComponentFilesByEntry?: EagerRouteComponentFilesByEntry;
6
16
  };
@@ -1,3 +1,9 @@
1
1
  import type { AppUserConfig } from '../types';
2
2
  import type { AppToolsContext } from '../types/plugin';
3
3
  export declare function createDefaultConfig(appContext: AppToolsContext): AppUserConfig;
4
+ /**
5
+ * Default-enable lazy compilation for pure CSR and stream SSR. Stream SSR keeps
6
+ * first-screen route assets correct via the route-eager lazyCompilation.test
7
+ * injected by the SSR builder plugin. String SSR, RSC and SSG stay disabled.
8
+ */
9
+ export declare function isLazyCompilationSafeByDefault(userConfig: Pick<AppUserConfig, 'server' | 'output'>): boolean;
@@ -1,6 +1,7 @@
1
1
  import type { AppContext, AsyncHook, InternalContext, PluginHook, PluginHookTap, TransformFunction } from '@modern-js/plugin';
2
2
  import type { Hooks } from '@modern-js/plugin/cli';
3
3
  import type { Entrypoint, HtmlPartials, HtmlTemplates, NestedRouteForCli, PageRoute, RouteLegacy, ServerPlugin, ServerRoute } from '@modern-js/types';
4
+ import type { EagerRouteComponentFilesByEntry } from '@modern-js/utils';
4
5
  import type { AppTools } from '.';
5
6
  import type { getHookRunners } from '../compat/hooks';
6
7
  import type { AppToolsNormalizedConfig, AppToolsUserConfig } from './config';
@@ -109,6 +110,19 @@ export interface AppToolsExtendContext {
109
110
  * @private
110
111
  */
111
112
  bffRuntimeFramework?: string;
113
+ /**
114
+ * Route component files collected from the FINAL file-system routes (after all
115
+ * `modifyFileSystemRoutes` consumers ran), keyed by entry name. Populated by
116
+ * the router plugin during route generation and consumed (currently by stream
117
+ * SSR lazy compilation) to force route component chunks eager.
118
+ *
119
+ * Published via the app context (`api.updateAppContext`) by the router plugin,
120
+ * then read fresh when assembling the builder options and threaded into
121
+ * `BuilderOptions.eagerRouteComponentFilesByEntry`; the SSR builder plugin
122
+ * reads it from those options (not from the context directly).
123
+ * @private
124
+ */
125
+ eagerRouteComponentFilesByEntry?: EagerRouteComponentFilesByEntry;
112
126
  }
113
127
  export type AppToolsContext = AppContext<AppTools> & AppToolsExtendContext;
114
128
  export type AppToolsHooks = Hooks<AppToolsUserConfig, AppToolsNormalizedConfig, {}, {}> & AppToolsExtendHooks;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.2.1",
18
+ "version": "3.3.0",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "exports": {
@@ -80,32 +80,32 @@
80
80
  "modern-app": "./bin/modern.js"
81
81
  },
82
82
  "dependencies": {
83
- "@babel/parser": "^7.29.3",
84
- "@babel/traverse": "^7.29.0",
85
- "@babel/types": "^7.29.0",
86
- "@rsbuild/core": "2.0.0",
87
- "@swc/core": "1.15.33",
83
+ "@babel/parser": "^7.29.7",
84
+ "@babel/traverse": "^7.29.7",
85
+ "@babel/types": "^7.29.7",
86
+ "@rsbuild/core": "2.0.10",
87
+ "@swc/core": "1.15.40",
88
88
  "@swc/helpers": "^0.5.17",
89
89
  "es-module-lexer": "^1.7.0",
90
- "import-meta-resolve": "^4.2.0",
91
90
  "flatted": "^3.4.2",
91
+ "import-meta-resolve": "^4.2.0",
92
92
  "mlly": "^1.8.2",
93
93
  "ndepe": "^0.1.13",
94
94
  "pkg-types": "^1.3.1",
95
95
  "std-env": "^3.10.0",
96
- "@modern-js/builder": "3.2.1",
97
- "@modern-js/plugin": "3.2.1",
98
- "@modern-js/i18n-utils": "3.2.1",
99
- "@modern-js/plugin-data-loader": "3.2.1",
100
- "@modern-js/prod-server": "3.2.1",
101
- "@modern-js/server": "3.2.1",
102
- "@modern-js/server-core": "3.2.1",
103
- "@modern-js/server-utils": "3.2.1",
104
- "@modern-js/types": "3.2.1",
105
- "@modern-js/utils": "3.2.1"
96
+ "@modern-js/i18n-utils": "3.3.0",
97
+ "@modern-js/plugin": "3.3.0",
98
+ "@modern-js/builder": "3.3.0",
99
+ "@modern-js/plugin-data-loader": "3.3.0",
100
+ "@modern-js/prod-server": "3.3.0",
101
+ "@modern-js/server": "3.3.0",
102
+ "@modern-js/server-core": "3.3.0",
103
+ "@modern-js/server-utils": "3.3.0",
104
+ "@modern-js/types": "3.3.0",
105
+ "@modern-js/utils": "3.3.0"
106
106
  },
107
107
  "devDependencies": {
108
- "@rslib/core": "0.21.5",
108
+ "@rslib/core": "0.22.0",
109
109
  "@types/babel__traverse": "7.28.0",
110
110
  "@types/node": "^20",
111
111
  "ts-node": "^10.9.2",