@modern-js/app-tools 2.7.0 → 2.8.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 (76) hide show
  1. package/CHANGELOG.md +53 -2
  2. package/README.md +2 -2
  3. package/dist/cjs/analyze/generateCode.js +16 -2
  4. package/dist/cjs/analyze/index.js +0 -32
  5. package/dist/cjs/analyze/templates.js +26 -2
  6. package/dist/cjs/analyze/utils.js +5 -0
  7. package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
  8. package/dist/cjs/builder/generator/index.js +10 -2
  9. package/dist/cjs/builder/index.js +1 -1
  10. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +101 -0
  11. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +91 -0
  12. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +164 -0
  13. package/dist/cjs/builder/{builder-webpack/webpackPlugins → shared/builderPlugins}/index.js +5 -3
  14. package/dist/cjs/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
  15. package/dist/cjs/builder/shared/bundlerPlugins/index.js +19 -0
  16. package/dist/cjs/builder/shared/index.js +1 -1
  17. package/dist/cjs/index.js +1 -1
  18. package/dist/cjs/locale/en.js +1 -0
  19. package/dist/cjs/locale/zh.js +1 -0
  20. package/dist/esm/analyze/generateCode.js +34 -19
  21. package/dist/esm/analyze/index.js +2 -25
  22. package/dist/esm/analyze/templates.js +16 -2
  23. package/dist/esm/analyze/utils.js +4 -1
  24. package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +0 -11
  25. package/dist/esm/builder/generator/index.js +6 -4
  26. package/dist/esm/builder/index.js +1 -1
  27. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +101 -0
  28. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +120 -0
  29. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +350 -0
  30. package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
  31. package/dist/esm/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +10 -6
  32. package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
  33. package/dist/esm/builder/shared/index.js +1 -1
  34. package/dist/esm/index.js +1 -1
  35. package/dist/esm/locale/en.js +1 -0
  36. package/dist/esm/locale/zh.js +1 -0
  37. package/dist/esm-node/analyze/generateCode.js +29 -4
  38. package/dist/esm-node/analyze/index.js +1 -39
  39. package/dist/esm-node/analyze/templates.js +25 -2
  40. package/dist/esm-node/analyze/utils.js +4 -0
  41. package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
  42. package/dist/esm-node/builder/generator/index.js +10 -2
  43. package/dist/esm-node/builder/index.js +1 -1
  44. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +67 -0
  45. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +67 -0
  46. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +143 -0
  47. package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
  48. package/dist/esm-node/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
  49. package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
  50. package/dist/esm-node/builder/shared/index.js +1 -1
  51. package/dist/esm-node/index.js +1 -1
  52. package/dist/esm-node/locale/en.js +1 -0
  53. package/dist/esm-node/locale/zh.js +1 -0
  54. package/dist/types/analyze/templates.d.ts +3 -2
  55. package/dist/types/analyze/utils.d.ts +2 -1
  56. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +7 -0
  57. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +5 -0
  58. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +4 -0
  59. package/dist/types/builder/shared/builderPlugins/index.d.ts +3 -0
  60. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +5 -0
  61. package/dist/types/builder/shared/bundlerPlugins/index.d.ts +3 -0
  62. package/dist/types/builder/shared/index.d.ts +1 -1
  63. package/dist/types/builder/shared/types.d.ts +7 -4
  64. package/dist/types/locale/en.d.ts +1 -0
  65. package/dist/types/locale/index.d.ts +2 -0
  66. package/dist/types/locale/zh.d.ts +1 -0
  67. package/dist/types/types/config/output.d.ts +2 -15
  68. package/package.json +26 -26
  69. package/dist/cjs/builder/shared/builderPlugins/adapterModern.js +0 -234
  70. package/dist/esm/builder/builder-webpack/webpackPlugins/index.js +0 -1
  71. package/dist/esm/builder/shared/builderPlugins/adapterModern.js +0 -300
  72. package/dist/esm-node/builder/builder-webpack/webpackPlugins/index.js +0 -1
  73. package/dist/esm-node/builder/shared/builderPlugins/adapterModern.js +0 -202
  74. package/dist/types/builder/builder-webpack/webpackPlugins/RouterPlugin.d.ts +0 -4
  75. package/dist/types/builder/builder-webpack/webpackPlugins/index.d.ts +0 -1
  76. package/dist/types/builder/shared/builderPlugins/adapterModern.d.ts +0 -13
package/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 2.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ab1e8065cb: feat: support router-plugin in Rspack bundler.
8
+ feat: 在 Rspack bundler 里支持 router-plugin
9
+
10
+ ### Patch Changes
11
+
12
+ - a12b5b4ec8: fix: the adapterSSR builder plugin modifyChain Hooks is not async function
13
+ fix: adapterSSR builder 插件的 adapterSSR Hooks 不是异步函数
14
+ - 1104a9f18b: feat: support start web service only
15
+ feat: 支持只启动 web 服务
16
+ - 1f6ca2c7fb: fix: nested routes in ssg
17
+ fix: 修复嵌套路由在 SSG 中的问题
18
+ - 2b6b1a014c: refactor: app-tools builder
19
+ refactor: 重构 app-tools builder
20
+ - 250f794c40: fix: move the analyze webpackChain config to app-tools builder shared
21
+ fix: 将 anylyze 的 `webpackChain` 配置项移植进 app-tools builder shared
22
+ - Updated dependencies [ea7bb41e30]
23
+ - Updated dependencies [65c56f43b9]
24
+ - Updated dependencies [0cf8540ffe]
25
+ - Updated dependencies [bd369a89a4]
26
+ - Updated dependencies [bc943c9b04]
27
+ - Updated dependencies [40f5039b17]
28
+ - Updated dependencies [1104a9f18b]
29
+ - Updated dependencies [70d82e1408]
30
+ - Updated dependencies [2c1151271d]
31
+ - Updated dependencies [481461a61d]
32
+ - Updated dependencies [1242f5d8d6]
33
+ - Updated dependencies [1f6ca2c7fb]
34
+ - Updated dependencies [457ee832b9]
35
+ - @modern-js/server@2.8.0
36
+ - @modern-js/builder-webpack-provider@2.8.0
37
+ - @modern-js/plugin-data-loader@2.8.0
38
+ - @modern-js/builder@2.8.0
39
+ - @modern-js/builder-shared@2.8.0
40
+ - @modern-js/builder-rspack-provider@2.8.0
41
+ - @modern-js/prod-server@2.8.0
42
+ - @modern-js/utils@2.8.0
43
+ - @modern-js/types@2.8.0
44
+ - @modern-js/builder-plugin-esbuild@2.8.0
45
+ - @modern-js/builder-plugin-node-polyfill@2.8.0
46
+ - @modern-js/core@2.8.0
47
+ - @modern-js/plugin-i18n@2.8.0
48
+ - @modern-js/plugin-lint@2.8.0
49
+ - @modern-js/new-action@2.8.0
50
+ - @modern-js/node-bundle-require@2.8.0
51
+ - @modern-js/upgrade@2.8.0
52
+ - @modern-js/plugin@2.8.0
53
+
3
54
  ## 2.7.0
4
55
 
5
56
  ### Minor Changes
@@ -167,8 +218,8 @@
167
218
 
168
219
  - e84d16b: feat: support catch-all routing
169
220
  feat: 支持通配路由
170
- - a914be8: feat: modern-js support rspack bundler
171
- feat: modern-js 支持 rspack 构建工具
221
+ - a914be8: feat: modern-js support Rspack bundler
222
+ feat: modern-js 支持 Rspack 构建工具
172
223
 
173
224
  ### Patch Changes
174
225
 
package/README.md CHANGED
@@ -19,8 +19,8 @@ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-sta
19
19
 
20
20
  ## Contributing
21
21
 
22
- Please read the [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md).
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
23
23
 
24
24
  ## License
25
25
 
26
- Modern.js is [MIT licensed](https://github.com/modern-js-dev/modern.js/blob/main/LICENSE).
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
@@ -138,6 +138,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
138
138
  config2.server.ssrByEntries,
139
139
  packageName
140
140
  );
141
+ const useSSG = (0, import_utils.isSSGEntry)(config2, entryName, entrypoints);
141
142
  let mode;
142
143
  if (ssr) {
143
144
  mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
@@ -157,13 +158,13 @@ const generateCode = async (appContext, config, entrypoints, api) => {
157
158
  entrypoint,
158
159
  code: await templates.fileSystemRoutes({
159
160
  routes,
160
- ssrMode: mode,
161
+ ssrMode: useSSG ? "string" : mode,
161
162
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
162
163
  entryName: entrypoint.entryName,
163
164
  internalDirectory
164
165
  })
165
166
  });
166
- if (entrypoint.nestedRoutesEntry && mode) {
167
+ if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
167
168
  const routesServerFile = (0, import_utils2.getServerLoadersFile)(
168
169
  internalDirectory,
169
170
  entryName
@@ -174,6 +175,19 @@ const generateCode = async (appContext, config, entrypoints, api) => {
174
175
  await import_utils.fs.ensureFile(routesServerFile);
175
176
  await import_utils.fs.writeFile(routesServerFile, code3);
176
177
  }
178
+ const serverLoaderCombined = templates.ssrLoaderCombinedModule(
179
+ entrypoints,
180
+ entrypoint,
181
+ config2,
182
+ appContext
183
+ );
184
+ if (serverLoaderCombined) {
185
+ const serverLoaderFile = (0, import_utils2.getServerCombinedModueFile)(
186
+ internalDirectory,
187
+ entryName
188
+ );
189
+ await import_utils.fs.outputFile(serverLoaderFile, serverLoaderCombined);
190
+ }
177
191
  import_utils.fs.outputFileSync(
178
192
  import_path.default.resolve(
179
193
  internalDirectory,
@@ -33,7 +33,6 @@ module.exports = __toCommonJS(analyze_exports);
33
33
  var path = __toESM(require("path"));
34
34
  var import_utils = require("@modern-js/utils");
35
35
  var import_lodash = require("@modern-js/utils/lodash");
36
- var import_builder_shared = require("@modern-js/builder-shared");
37
36
  var import_printInstructions = require("../utils/printInstructions");
38
37
  var import_routes = require("../utils/routes");
39
38
  var import_config = require("../utils/config");
@@ -190,37 +189,6 @@ var analyze_default = ({
190
189
  watchFiles() {
191
190
  return pagesDir;
192
191
  },
193
- config() {
194
- return {
195
- tools: {
196
- webpackChain: (chain, { name }) => {
197
- const appContext = api.useAppContext();
198
- const resolvedConfig = api.useResolvedConfigContext();
199
- const { entrypoints, internalDirectory, packageName } = appContext;
200
- entrypoints.forEach((entrypoint) => {
201
- const { entryName } = entrypoint;
202
- const ssr = (0, import_utils.getEntryOptions)(
203
- entryName,
204
- resolvedConfig.server.ssr,
205
- resolvedConfig.server.ssrByEntries,
206
- packageName
207
- );
208
- if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
209
- const serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
210
- const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(
211
- internalDirectory,
212
- entryName
213
- );
214
- const combinedModule = (0, import_builder_shared.createVirtualModule)(
215
- `export * from "${serverLoaderRuntime}"; export * from "${serverLoadersFile}"`
216
- );
217
- chain.entry(`${entryName}-server-loaders`).add(combinedModule);
218
- }
219
- });
220
- }
221
- }
222
- };
223
- },
224
192
  resolvedConfig({ resolved }) {
225
193
  const appContext = api.useAppContext();
226
194
  const config = (0, import_config2.initialNormalizedConfig)(resolved, appContext, bundler);
@@ -31,12 +31,14 @@ __export(templates_exports, {
31
31
  html: () => html,
32
32
  index: () => index,
33
33
  renderFunction: () => renderFunction,
34
- routesForServer: () => routesForServer
34
+ routesForServer: () => routesForServer,
35
+ ssrLoaderCombinedModule: () => ssrLoaderCombinedModule
35
36
  });
36
37
  module.exports = __toCommonJS(templates_exports);
37
38
  var import_path = __toESM(require("path"));
38
39
  var import_utils = require("@modern-js/utils");
39
40
  var import_constants = require("./constants");
41
+ var import_utils2 = require("./utils");
40
42
  const index = ({
41
43
  mountId,
42
44
  imports,
@@ -319,11 +321,33 @@ const fileSystemRoutes = async ({
319
321
  ${routeComponentsCode}
320
322
  `;
321
323
  };
324
+ function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
325
+ const { entryName } = entrypoint;
326
+ const { packageName, internalDirectory } = appContext;
327
+ const ssr = (0, import_utils.getEntryOptions)(
328
+ entryName,
329
+ config.server.ssr,
330
+ config.server.ssrByEntries,
331
+ packageName
332
+ );
333
+ const ssg = (0, import_utils.isSSGEntry)(config, entryName, entrypoints);
334
+ if (entrypoint.nestedRoutesEntry && (ssr || ssg)) {
335
+ const serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
336
+ const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(
337
+ internalDirectory,
338
+ entryName
339
+ );
340
+ const combinedModule = `export * from "${serverLoaderRuntime}"; export * from "${serverLoadersFile}"`;
341
+ return combinedModule;
342
+ }
343
+ return null;
344
+ }
322
345
  // Annotate the CommonJS export names for ESM import in node:
323
346
  0 && (module.exports = {
324
347
  fileSystemRoutes,
325
348
  html,
326
349
  index,
327
350
  renderFunction,
328
- routesForServer
351
+ routesForServer,
352
+ ssrLoaderCombinedModule
329
353
  });
@@ -28,6 +28,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
28
28
  var utils_exports = {};
29
29
  __export(utils_exports, {
30
30
  getDefaultImports: () => getDefaultImports,
31
+ getServerCombinedModueFile: () => getServerCombinedModueFile,
31
32
  getServerLoadersFile: () => getServerLoadersFile,
32
33
  hasLoader: () => hasLoader,
33
34
  isPageComponentFile: () => isPageComponentFile,
@@ -144,9 +145,13 @@ const hasLoader = async (filename) => {
144
145
  const getServerLoadersFile = (internalDirectory, entryName) => {
145
146
  return import_path.default.join(internalDirectory, entryName, "route-server-loaders.js");
146
147
  };
148
+ const getServerCombinedModueFile = (internalDirectory, entryName) => {
149
+ return import_path.default.join(internalDirectory, entryName, "server-loader-combined.js");
150
+ };
147
151
  // Annotate the CommonJS export names for ESM import in node:
148
152
  0 && (module.exports = {
149
153
  getDefaultImports,
154
+ getServerCombinedModueFile,
150
155
  getServerLoadersFile,
151
156
  hasLoader,
152
157
  isPageComponentFile,
@@ -22,13 +22,11 @@ __export(compatModern_exports, {
22
22
  module.exports = __toCommonJS(compatModern_exports);
23
23
  var import_path = require("path");
24
24
  var import_shared = require("../../shared");
25
- var import_webpackPlugins = require("../webpackPlugins");
26
25
  const builderPluginCompatModern = (options) => ({
27
26
  name: "builder-plugin-compat-modern",
28
27
  setup(api) {
29
28
  const { normalizedConfig: modernConfig, appContext } = options;
30
29
  api.modifyWebpackChain((chain, { CHAIN_ID }) => {
31
- var _a;
32
30
  chain.resolve.modules.add("node_modules").add((0, import_path.join)(api.context.rootPath, "node_modules"));
33
31
  if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
34
32
  const defaultCopyPattern = (0, import_shared.createCopyPattern)(
@@ -38,23 +36,14 @@ const builderPluginCompatModern = (options) => ({
38
36
  chain
39
37
  );
40
38
  chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
41
- var _a2;
39
+ var _a;
42
40
  return [
43
41
  {
44
- patterns: [...((_a2 = args[0]) == null ? void 0 : _a2.patterns) || [], defaultCopyPattern]
42
+ patterns: [...((_a = args[0]) == null ? void 0 : _a.patterns) || [], defaultCopyPattern]
45
43
  }
46
44
  ];
47
45
  });
48
46
  }
49
- const { entrypoints } = appContext;
50
- const existNestedRoutes = entrypoints.some(
51
- (entrypoint) => entrypoint.nestedRoutesEntry
52
- );
53
- const routerConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router;
54
- const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
55
- if (existNestedRoutes || routerManifest) {
56
- chain.plugin("route-plugin").use(import_webpackPlugins.RouterPlugin);
57
- }
58
47
  });
59
48
  }
60
49
  });
@@ -53,8 +53,16 @@ async function generateBuilder(options, generateProvider, utils) {
53
53
  return builder;
54
54
  }
55
55
  async function applyBuilderPlugins(builder, options) {
56
- const { builderPluginAdapterModern } = await Promise.resolve().then(() => __toESM(require("../shared/builderPlugins/adapterModern")));
57
- builder.addPlugins([builderPluginAdapterModern(options)]);
56
+ const {
57
+ builderPluginAdapterBasic,
58
+ builderPluginAdapterHtml,
59
+ builderPluginAdapterSSR
60
+ } = await Promise.resolve().then(() => __toESM(require("../shared/builderPlugins")));
61
+ builder.addPlugins([
62
+ builderPluginAdapterBasic(options),
63
+ builderPluginAdapterSSR(options),
64
+ builderPluginAdapterHtml(options)
65
+ ]);
58
66
  }
59
67
  // Annotate the CommonJS export names for ESM import in node:
60
68
  0 && (module.exports = {
@@ -37,7 +37,7 @@ async function createBuilderGenerator(bundler) {
37
37
  return createRspackBuilderForModern;
38
38
  } catch (_) {
39
39
  throw new Error(
40
- "Failed to use rspack, please check if you have `@modern-js/builder-rspack-provider` installed"
40
+ "Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed"
41
41
  );
42
42
  }
43
43
  }
@@ -0,0 +1,101 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var adapterBasic_exports = {};
29
+ __export(adapterBasic_exports, {
30
+ applyCallbacks: () => applyCallbacks,
31
+ builderPluginAdapterBasic: () => builderPluginAdapterBasic
32
+ });
33
+ module.exports = __toCommonJS(adapterBasic_exports);
34
+ const builderPluginAdapterBasic = (options) => ({
35
+ name: "builder-plugin-adapter-modern-basic",
36
+ setup(api) {
37
+ api.modifyBundlerChain((chain, { target, CHAIN_ID }) => {
38
+ if (target === "node") {
39
+ chain.name("server");
40
+ } else if (target === "service-worker") {
41
+ chain.name("service-worker");
42
+ } else if (target === "web-worker") {
43
+ chain.name("worker");
44
+ } else if (target === "modern-web") {
45
+ chain.name("modern");
46
+ } else {
47
+ chain.name("client");
48
+ }
49
+ if (target === "node" || target === "service-worker") {
50
+ applyNodeCompat(target, chain);
51
+ }
52
+ if (target === "web" || target === "modern-web") {
53
+ const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
54
+ chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
55
+ chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
56
+ }
57
+ });
58
+ applyCallbacks(api, options);
59
+ }
60
+ });
61
+ function applyCallbacks(api, options) {
62
+ options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
63
+ options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
64
+ options.onAfterStartDevServer && api.onAfterStartDevServer(options.onAfterStartDevServer);
65
+ options.onBeforeBuild && api.onBeforeBuild(options.onBeforeBuild);
66
+ options.onBeforeCreateCompiler && api.onBeforeCreateCompiler(options.onBeforeCreateCompiler);
67
+ options.onBeforeStartDevServer && api.onBeforeStartDevServer(options.onBeforeStartDevServer);
68
+ options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
69
+ options.onExit && api.onExit(options.onExit);
70
+ }
71
+ function applyNodeCompat(target, chain) {
72
+ const nodeExts = [
73
+ ".node.js",
74
+ ".node.jsx",
75
+ ".node.ts",
76
+ ".node.tsx",
77
+ ".server.js",
78
+ ".server.ts",
79
+ ".server.ts",
80
+ ".server.tsx"
81
+ ];
82
+ const webWorkerExts = [
83
+ ".worker.js",
84
+ ".worker.jsx",
85
+ ".worker.ts",
86
+ ".worker.tsx"
87
+ ];
88
+ for (const ext of nodeExts) {
89
+ chain.resolve.extensions.prepend(ext);
90
+ }
91
+ if (target === "service-worker") {
92
+ for (const ext of webWorkerExts) {
93
+ chain.resolve.extensions.prepend(ext);
94
+ }
95
+ }
96
+ }
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ applyCallbacks,
100
+ builderPluginAdapterBasic
101
+ });
@@ -0,0 +1,91 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var adapterHtml_exports = {};
19
+ __export(adapterHtml_exports, {
20
+ builderPluginAdapterHtml: () => builderPluginAdapterHtml,
21
+ isHtmlEnabled: () => isHtmlEnabled
22
+ });
23
+ module.exports = __toCommonJS(adapterHtml_exports);
24
+ var import_utils = require("@modern-js/utils");
25
+ var import_lodash = require("@modern-js/utils/lodash");
26
+ var import_bundlerPlugins = require("../bundlerPlugins");
27
+ function isHtmlEnabled(config, target) {
28
+ var _a;
29
+ return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
30
+ }
31
+ const builderPluginAdapterHtml = (options) => ({
32
+ name: "builder-plugin-adpater-modern-html",
33
+ setup(api) {
34
+ api.modifyBundlerChain(
35
+ (chain, { CHAIN_ID, target, HtmlPlugin: HtmlBundlerPlugin }) => {
36
+ const builderConfig = api.getNormalizedConfig();
37
+ if (isHtmlEnabled(builderConfig, target)) {
38
+ applyBottomHtmlPlugin({
39
+ api,
40
+ options,
41
+ chain,
42
+ CHAIN_ID,
43
+ HtmlBundlerPlugin
44
+ });
45
+ }
46
+ }
47
+ );
48
+ }
49
+ });
50
+ function applyBottomHtmlPlugin({
51
+ api,
52
+ chain,
53
+ options,
54
+ CHAIN_ID,
55
+ HtmlBundlerPlugin
56
+ }) {
57
+ const { normalizedConfig: modernConfig, appContext } = options;
58
+ for (const entryName of Object.keys(api.context.entry)) {
59
+ const baseTemplateParams = {
60
+ entryName,
61
+ title: (0, import_utils.getEntryOptions)(
62
+ entryName,
63
+ modernConfig.html.title,
64
+ modernConfig.html.titleByEntries,
65
+ appContext.packageName
66
+ ),
67
+ mountId: modernConfig.html.mountId,
68
+ ...(0, import_utils.getEntryOptions)(
69
+ entryName,
70
+ modernConfig.html.templateParameters,
71
+ modernConfig.html.templateParametersByEntries,
72
+ appContext.packageName
73
+ )
74
+ };
75
+ chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
76
+ {
77
+ ...args[0] || {},
78
+ __internal__: true,
79
+ bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && (0, import_lodash.template)(appContext.htmlTemplates[`__${entryName}-bottom__`])(
80
+ baseTemplateParams
81
+ )
82
+ }
83
+ ]);
84
+ }
85
+ chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(import_bundlerPlugins.BottomTemplatePlugin, [HtmlBundlerPlugin]);
86
+ }
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ builderPluginAdapterHtml,
90
+ isHtmlEnabled
91
+ });
@@ -0,0 +1,164 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var adapterSSR_exports = {};
19
+ __export(adapterSSR_exports, {
20
+ builderPluginAdapterSSR: () => builderPluginAdapterSSR
21
+ });
22
+ module.exports = __toCommonJS(adapterSSR_exports);
23
+ var import_builder_shared = require("@modern-js/builder-shared");
24
+ var import_utils = require("@modern-js/utils");
25
+ var import_bundlerPlugins = require("../bundlerPlugins");
26
+ var import_utils2 = require("../../../analyze/utils");
27
+ var import_adapterHtml = require("./adapterHtml");
28
+ const builderPluginAdapterSSR = (options) => ({
29
+ name: "builder-plugin-adapter-modern-ssr",
30
+ setup(api) {
31
+ const { normalizedConfig } = options;
32
+ api.modifyBuilderConfig((config) => {
33
+ if (isStreamingSSR(normalizedConfig)) {
34
+ return (0, import_builder_shared.mergeBuilderConfig)(config, {
35
+ html: {
36
+ inject: "body"
37
+ }
38
+ });
39
+ }
40
+ return config;
41
+ });
42
+ api.modifyBundlerChain(
43
+ async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
44
+ const builderConfig = api.getNormalizedConfig();
45
+ applyRouterPlugin(chain, options);
46
+ await applySSRLoaderEntry(chain, options, isServer);
47
+ if (["node", "service-worker"].includes(target)) {
48
+ applyFilterEntriesBySSRConfig({
49
+ isProd,
50
+ chain,
51
+ appNormalizedConfig: options.normalizedConfig
52
+ });
53
+ }
54
+ if ((0, import_adapterHtml.isHtmlEnabled)(builderConfig, target)) {
55
+ applyAsyncChunkHtmlPlugin({
56
+ chain,
57
+ modernConfig: options.normalizedConfig,
58
+ CHAIN_ID,
59
+ HtmlBundlerPlugin
60
+ });
61
+ }
62
+ }
63
+ );
64
+ }
65
+ });
66
+ const isStreamingSSR = (userConfig) => {
67
+ const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
68
+ const { server } = userConfig;
69
+ if (isStreaming(server.ssr)) {
70
+ return true;
71
+ }
72
+ if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
73
+ for (const name of Object.keys(server.ssrByEntries)) {
74
+ if (isStreaming(server.ssrByEntries[name])) {
75
+ return true;
76
+ }
77
+ }
78
+ }
79
+ return false;
80
+ };
81
+ function applyAsyncChunkHtmlPlugin({
82
+ chain,
83
+ modernConfig,
84
+ CHAIN_ID,
85
+ HtmlBundlerPlugin
86
+ }) {
87
+ if (isStreamingSSR(modernConfig)) {
88
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(import_bundlerPlugins.HtmlAsyncChunkPlugin, [HtmlBundlerPlugin]);
89
+ }
90
+ }
91
+ function applyRouterPlugin(chain, options) {
92
+ var _a;
93
+ const { appContext, normalizedConfig } = options;
94
+ const { entrypoints } = appContext;
95
+ const existNestedRoutes = entrypoints.some(
96
+ (entrypoint) => entrypoint.nestedRoutesEntry
97
+ );
98
+ const routerConfig = (_a = normalizedConfig == null ? void 0 : normalizedConfig.runtime) == null ? void 0 : _a.router;
99
+ const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
100
+ if (existNestedRoutes || routerManifest) {
101
+ chain.plugin("route-plugin").use(import_bundlerPlugins.RouterPlugin);
102
+ }
103
+ }
104
+ function applyFilterEntriesBySSRConfig({
105
+ isProd,
106
+ chain,
107
+ appNormalizedConfig
108
+ }) {
109
+ var _a;
110
+ const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
111
+ const entries = chain.entryPoints.entries();
112
+ if (isProd && ((outputConfig == null ? void 0 : outputConfig.ssg) === true || typeof ((_a = outputConfig == null ? void 0 : outputConfig.ssg) == null ? void 0 : _a[0]) === "function")) {
113
+ return;
114
+ }
115
+ if (typeof entries === "undefined") {
116
+ throw new Error(
117
+ "No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required"
118
+ );
119
+ }
120
+ const entryNames = Object.keys(entries);
121
+ if (isProd && entryNames.length === 1 && (outputConfig == null ? void 0 : outputConfig.ssg)) {
122
+ return;
123
+ }
124
+ const ssgEntries = [];
125
+ if (isProd && (outputConfig == null ? void 0 : outputConfig.ssg)) {
126
+ const { ssg } = outputConfig;
127
+ entryNames.forEach((name) => {
128
+ if (ssg[name]) {
129
+ ssgEntries.push(name);
130
+ }
131
+ });
132
+ }
133
+ const { ssr, ssrByEntries } = serverConfig || {};
134
+ entryNames.forEach((name) => {
135
+ if (!ssgEntries.includes(name) && (ssr && (ssrByEntries == null ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries == null ? void 0 : ssrByEntries[name]))) {
136
+ chain.entryPoints.delete(name);
137
+ }
138
+ });
139
+ }
140
+ async function applySSRLoaderEntry(chain, optinos, isServer) {
141
+ const { appContext } = optinos;
142
+ const { internalDirectory } = appContext;
143
+ const { entrypoints } = appContext;
144
+ await Promise.all(
145
+ entrypoints.map(async (entrypoint) => {
146
+ const { entryName } = entrypoint;
147
+ const serverLoadersFile = (0, import_utils2.getServerCombinedModueFile)(
148
+ internalDirectory,
149
+ entryName
150
+ );
151
+ if (isServer) {
152
+ try {
153
+ await import_utils.fs.access(serverLoadersFile, import_utils.fs.constants.F_OK);
154
+ chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
155
+ } catch (err) {
156
+ }
157
+ }
158
+ })
159
+ );
160
+ }
161
+ // Annotate the CommonJS export names for ESM import in node:
162
+ 0 && (module.exports = {
163
+ builderPluginAdapterSSR
164
+ });