@modern-js/app-tools 2.40.0 → 2.42.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 (112) hide show
  1. package/dist/cjs/analyze/getHtmlTemplate.js +5 -5
  2. package/dist/cjs/analyze/templates.js +7 -6
  3. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +3 -1
  4. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
  5. package/dist/cjs/config/default.js +2 -1
  6. package/dist/cjs/defineConfig.js +8 -6
  7. package/dist/esm/analyze/getHtmlTemplate.js +5 -5
  8. package/dist/esm/analyze/templates.js +6 -6
  9. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +6 -4
  10. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
  11. package/dist/esm/config/default.js +2 -1
  12. package/dist/esm/config/initialize/inits.js +19 -19
  13. package/dist/esm/defineConfig.js +1 -1
  14. package/dist/esm-node/analyze/getHtmlTemplate.js +5 -5
  15. package/dist/esm-node/analyze/templates.js +7 -6
  16. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +3 -1
  17. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
  18. package/dist/esm-node/config/default.js +2 -1
  19. package/dist/esm-node/defineConfig.js +8 -6
  20. package/dist/types/analyze/constants.d.ts +19 -19
  21. package/dist/types/analyze/generateCode.d.ts +9 -16
  22. package/dist/types/analyze/getBundleEntry.d.ts +1 -1
  23. package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +7 -13
  24. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +7 -13
  25. package/dist/types/analyze/getClientRoutes/index.d.ts +1 -1
  26. package/dist/types/analyze/getClientRoutes/utils.d.ts +1 -1
  27. package/dist/types/analyze/getFileSystemEntry.d.ts +1 -1
  28. package/dist/types/analyze/getHtmlTemplate.d.ts +4 -7
  29. package/dist/types/analyze/getServerRoutes.d.ts +4 -7
  30. package/dist/types/analyze/index.d.ts +3 -5
  31. package/dist/types/analyze/isDefaultExportFunction.d.ts +1 -1
  32. package/dist/types/analyze/makeLegalIdentifier.d.ts +1 -1
  33. package/dist/types/analyze/nestedRoutes.d.ts +3 -3
  34. package/dist/types/analyze/templates.d.ts +22 -40
  35. package/dist/types/analyze/utils.d.ts +10 -19
  36. package/dist/types/builder/builder-rspack/adapterCopy.d.ts +1 -1
  37. package/dist/types/builder/builder-rspack/index.d.ts +1 -1
  38. package/dist/types/builder/builder-webpack/adapterModern.d.ts +1 -1
  39. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +20 -20
  40. package/dist/types/builder/builder-webpack/index.d.ts +1 -1
  41. package/dist/types/builder/generator/createBuilderOptions.d.ts +1 -1
  42. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +1 -1
  43. package/dist/types/builder/generator/getBuilderTargets.d.ts +1 -1
  44. package/dist/types/builder/generator/index.d.ts +2 -2
  45. package/dist/types/builder/index.d.ts +1 -1
  46. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +1 -1
  47. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -1
  48. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -1
  49. package/dist/types/builder/shared/builderPlugins/index.d.ts +1 -1
  50. package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +5 -5
  51. package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +7 -7
  52. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +24 -31
  53. package/dist/types/builder/shared/bundlerPlugins/index.d.ts +1 -1
  54. package/dist/types/builder/shared/createCopyInfo.d.ts +4 -4
  55. package/dist/types/builder/shared/index.d.ts +1 -1
  56. package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +1 -1
  57. package/dist/types/builder/shared/types.d.ts +3 -3
  58. package/dist/types/commands/build.d.ts +1 -1
  59. package/dist/types/commands/deploy.d.ts +1 -1
  60. package/dist/types/commands/dev.d.ts +2 -2
  61. package/dist/types/commands/index.d.ts +1 -1
  62. package/dist/types/commands/inspect.d.ts +7 -7
  63. package/dist/types/commands/serve.d.ts +1 -1
  64. package/dist/types/config/default.d.ts +1 -1
  65. package/dist/types/config/index.d.ts +1 -1
  66. package/dist/types/config/initialize/index.d.ts +1 -1
  67. package/dist/types/config/initialize/inits.d.ts +1 -1
  68. package/dist/types/config/legacy/createHtmlConfig.d.ts +1 -1
  69. package/dist/types/config/legacy/createOutputConfig.d.ts +1 -1
  70. package/dist/types/config/legacy/createSourceConfig.d.ts +1 -1
  71. package/dist/types/config/legacy/createToolsConfig.d.ts +1 -1
  72. package/dist/types/config/legacy/index.d.ts +1 -1
  73. package/dist/types/defineConfig.d.ts +1 -1
  74. package/dist/types/exports/server.d.ts +1 -1
  75. package/dist/types/hooks.d.ts +1 -1
  76. package/dist/types/index.d.ts +6 -6
  77. package/dist/types/initialize/index.d.ts +3 -5
  78. package/dist/types/locale/en.d.ts +38 -38
  79. package/dist/types/locale/index.d.ts +75 -75
  80. package/dist/types/locale/zh.d.ts +38 -38
  81. package/dist/types/types/config/deploy.d.ts +21 -21
  82. package/dist/types/types/config/dev.d.ts +10 -10
  83. package/dist/types/types/config/experiments.d.ts +1 -1
  84. package/dist/types/types/config/html.d.ts +1 -1
  85. package/dist/types/types/config/index.d.ts +38 -38
  86. package/dist/types/types/config/output.d.ts +35 -28
  87. package/dist/types/types/config/performance.d.ts +1 -1
  88. package/dist/types/types/config/security.d.ts +1 -1
  89. package/dist/types/types/config/source.d.ts +52 -52
  90. package/dist/types/types/config/testing.d.ts +6 -6
  91. package/dist/types/types/config/tools.d.ts +26 -24
  92. package/dist/types/types/hooks.d.ts +75 -75
  93. package/dist/types/types/index.d.ts +17 -17
  94. package/dist/types/types/legacyConfig/deploy.d.ts +5 -5
  95. package/dist/types/types/legacyConfig/dev.d.ts +9 -9
  96. package/dist/types/types/legacyConfig/index.d.ts +16 -16
  97. package/dist/types/types/legacyConfig/output.d.ts +45 -45
  98. package/dist/types/types/legacyConfig/source.d.ts +22 -22
  99. package/dist/types/types/legacyConfig/testing.d.ts +6 -6
  100. package/dist/types/types/legacyConfig/tools.d.ts +10 -10
  101. package/dist/types/types/utils.d.ts +4 -4
  102. package/dist/types/utils/config.d.ts +7 -13
  103. package/dist/types/utils/createServer.d.ts +5 -5
  104. package/dist/types/utils/env.d.ts +1 -1
  105. package/dist/types/utils/generateWatchFiles.d.ts +1 -1
  106. package/dist/types/utils/getSelectedEntries.d.ts +1 -1
  107. package/dist/types/utils/getServerInternalPlugins.d.ts +1 -1
  108. package/dist/types/utils/printInstructions.d.ts +1 -1
  109. package/dist/types/utils/restart.d.ts +1 -1
  110. package/dist/types/utils/routes.d.ts +1 -1
  111. package/dist/types/utils/types.d.ts +13 -13
  112. package/package.json +26 -26
@@ -63,7 +63,7 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
63
63
  for (const entrypoint of entrypoints) {
64
64
  const { entryName, isMainEntry } = entrypoint;
65
65
  const name = entrypoints.length === 1 && isMainEntry ? "" : entryName;
66
- const customIndexTemplate = findPartials(htmlDir, name, PartialPosition.INDEX);
66
+ const customIndexTemplate = findPartials(htmlDir, name, "index");
67
67
  if (customIndexTemplate) {
68
68
  htmlTemplates[entryName] = customIndexTemplate.file;
69
69
  } else {
@@ -71,9 +71,9 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
71
71
  const { partials } = await hookRunners.htmlPartials({
72
72
  entrypoint,
73
73
  partials: [
74
- PartialPosition.TOP,
75
- PartialPosition.HEAD,
76
- PartialPosition.BODY
74
+ "top",
75
+ "head",
76
+ "body"
77
77
  ].reduce((previous, position) => {
78
78
  const found = findPartials(htmlDir, name, position);
79
79
  previous[position] = found ? [
@@ -90,7 +90,7 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
90
90
  import_utils.fs.outputFileSync(templatePath, templates.html(partials), "utf8");
91
91
  htmlTemplates[entryName] = templatePath;
92
92
  partialsByEntrypoint[entryName] = partials;
93
- const bottomTemplate = findPartials(htmlDir, name, PartialPosition.BOTTOM);
93
+ const bottomTemplate = findPartials(htmlDir, name, "bottom");
94
94
  if (bottomTemplate) {
95
95
  htmlTemplates[`__${entryName}-bottom__`] = bottomTemplate.content;
96
96
  }
@@ -190,7 +190,8 @@ const routesForServer = ({ routes }) => {
190
190
  ${routesCode}
191
191
  `;
192
192
  };
193
- const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([^,]+)"`, "g");
193
+ const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([^
194
+ ]+)"`, "g");
194
195
  const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, splitRouteChunks = true }) => {
195
196
  const components = [];
196
197
  const loadings = [];
@@ -264,18 +265,18 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
264
265
  if (route._component) {
265
266
  if (splitRouteChunks) {
266
267
  if (route.isRoot) {
267
- lazyImport = `() => import('${route._component}').then(routeModule => {if(typeof document !== "undefined") window.${import_constants.ROUTE_MODULES}["${route.id}"] = routeModule; return routeModule; }) `;
268
+ lazyImport = `() => import('${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
268
269
  rootLayoutCode = `import RootLayout from '${route._component}'`;
269
270
  component = `RootLayout`;
270
271
  } else if (ssrMode === "string") {
271
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => {if(typeof document !== "undefined") window.${import_constants.ROUTE_MODULES}["${route.id}"] = routeModule; return routeModule; }) `;
272
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
272
273
  component = `loadable(${lazyImport})`;
273
274
  } else {
274
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => {if(typeof document !== "undefined") window.${import_constants.ROUTE_MODULES}["${route.id}"] = routeModule; return routeModule; }) `;
275
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
275
276
  component = `lazy(${lazyImport})`;
276
277
  }
277
278
  } else {
278
- lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule => {if(typeof document !== "undefined") window.${import_constants.ROUTE_MODULES}["${route.id}"] = routeModule; return routeModule; }) `;
279
+ lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
279
280
  if (ssrMode === "string") {
280
281
  component = `loadable(${lazyImport})`;
281
282
  } else {
@@ -402,7 +403,7 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
402
403
  await import_utils.fs.ensureFile(loadersMapFile);
403
404
  await import_utils.fs.writeJSON(loadersMapFile, loadersMap);
404
405
  const importRuntimeRouterCode = `
405
- import { createShouldRevalidate } from '@modern-js/runtime/router';
406
+ import { createShouldRevalidate, handleRouteModule, handleRouteModuleError} from '@modern-js/runtime/router';
406
407
  `;
407
408
  const routeModulesCode = `
408
409
  if(typeof document !== 'undefined'){
@@ -109,12 +109,14 @@ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
109
109
  const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
110
110
  const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
111
111
  const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
112
+ const { enableInlineRouteManifests, disableInlineRouteManifests } = normalizedConfig.output;
113
+ const inlineRouteManifests = disableInlineRouteManifests ? !disableInlineRouteManifests : enableInlineRouteManifests;
112
114
  if (existNestedRoutes || routerManifest || workerSSR) {
113
115
  var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
114
116
  chain.plugin(pluginName).use(import_bundlerPlugins.RouterPlugin, [
115
117
  {
116
118
  HtmlBundlerPlugin,
117
- enableInlineRouteManifests: normalizedConfig.output.enableInlineRouteManifests,
119
+ enableInlineRouteManifests: inlineRouteManifests,
118
120
  staticJsDir: (_normalizedConfig_output = normalizedConfig.output) === null || _normalizedConfig_output === void 0 ? void 0 : (_normalizedConfig_output_distPath = _normalizedConfig_output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.js,
119
121
  disableFilenameHash: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : _normalizedConfig_output1.disableFilenameHash,
120
122
  scriptLoading: (_normalizedConfig_html = normalizedConfig.html) === null || _normalizedConfig_html === void 0 ? void 0 : _normalizedConfig_html.scriptLoading,
@@ -62,7 +62,7 @@ class RouterPlugin {
62
62
  return;
63
63
  }
64
64
  const { webpack } = compiler;
65
- const isRspack = webpack.rspackVersion;
65
+ const isRspack = "rspackVersion" in webpack;
66
66
  const { Compilation, sources } = webpack;
67
67
  const { RawSource } = sources;
68
68
  const normalizePath = (path) => {
@@ -36,7 +36,8 @@ function createDefaultConfig(appContext, bundler) {
36
36
  const output = {
37
37
  ...defaultBuilderConfig.output,
38
38
  disableNodePolyfill: true,
39
- enableInlineRouteManifests: true
39
+ enableInlineRouteManifests: true,
40
+ disableInlineRouteManifests: false
40
41
  };
41
42
  const source = {
42
43
  ...defaultBuilderConfig.source,
@@ -23,12 +23,14 @@ __export(defineConfig_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(defineConfig_exports);
25
25
  const defineConfig = (config) => config;
26
- var _config_autoLoadPlugins;
27
- const defineLegacyConfig = (config) => ({
28
- ...config,
29
- legacy: true,
30
- autoLoadPlugins: (_config_autoLoadPlugins = config.autoLoadPlugins) !== null && _config_autoLoadPlugins !== void 0 ? _config_autoLoadPlugins : true
31
- });
26
+ const defineLegacyConfig = (config) => {
27
+ var _config_autoLoadPlugins;
28
+ return {
29
+ ...config,
30
+ legacy: true,
31
+ autoLoadPlugins: (_config_autoLoadPlugins = config.autoLoadPlugins) !== null && _config_autoLoadPlugins !== void 0 ? _config_autoLoadPlugins : true
32
+ };
33
+ };
32
34
  // Annotate the CommonJS export names for ESM import in node:
33
35
  0 && (module.exports = {
34
36
  defineConfig,
@@ -59,7 +59,7 @@ var getHtmlTemplate = function() {
59
59
  entrypoint = _step.value;
60
60
  entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
61
61
  name = entrypoints.length === 1 && isMainEntry ? "" : entryName;
62
- customIndexTemplate = findPartials(htmlDir, name, PartialPosition.INDEX);
62
+ customIndexTemplate = findPartials(htmlDir, name, "index");
63
63
  if (!customIndexTemplate)
64
64
  return [
65
65
  3,
@@ -77,9 +77,9 @@ var getHtmlTemplate = function() {
77
77
  hookRunners.htmlPartials({
78
78
  entrypoint,
79
79
  partials: [
80
- PartialPosition.TOP,
81
- PartialPosition.HEAD,
82
- PartialPosition.BODY
80
+ "top",
81
+ "head",
82
+ "body"
83
83
  ].reduce(function(previous, position) {
84
84
  var found = findPartials(htmlDir, name, position);
85
85
  previous[position] = found ? [
@@ -99,7 +99,7 @@ var getHtmlTemplate = function() {
99
99
  fs.outputFileSync(templatePath, templates.html(partials), "utf8");
100
100
  htmlTemplates[entryName] = templatePath;
101
101
  partialsByEntrypoint[entryName] = partials;
102
- bottomTemplate = findPartials(htmlDir, name, PartialPosition.BOTTOM);
102
+ bottomTemplate = findPartials(htmlDir, name, "bottom");
103
103
  if (bottomTemplate) {
104
104
  htmlTemplates["__".concat(entryName, "-bottom__")] = bottomTemplate.content;
105
105
  }
@@ -131,7 +131,7 @@ var routesForServer = function(param) {
131
131
  return "\n ".concat(importLoadersCode, "\n ").concat(routesCode, "\n ");
132
132
  };
133
133
  var createMatchReg = function(keyword) {
134
- return new RegExp('("'.concat(keyword, '":\\s)"([^,]+)"'), "g");
134
+ return new RegExp('("'.concat(keyword, '":\\s)"([^\n]+)"'), "g");
135
135
  };
136
136
  var fileSystemRoutes = function() {
137
137
  var _ref = _async_to_generator(function(param) {
@@ -210,18 +210,18 @@ var fileSystemRoutes = function() {
210
210
  if (route2._component) {
211
211
  if (splitRouteChunks) {
212
212
  if (route2.isRoot) {
213
- lazyImport = "() => import('".concat(route2._component, `').then(routeModule => {if(typeof document !== "undefined") window.`).concat(ROUTE_MODULES, '["').concat(route2.id, '"] = routeModule; return routeModule; }) ');
213
+ lazyImport = "() => import('".concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
214
214
  rootLayoutCode = "import RootLayout from '".concat(route2._component, "'");
215
215
  component2 = "RootLayout";
216
216
  } else if (ssrMode === "string") {
217
- lazyImport = '() => import(/* webpackChunkName: "'.concat(route2.id, `" */ '`).concat(route2._component, `').then(routeModule => {if(typeof document !== "undefined") window.`).concat(ROUTE_MODULES, '["').concat(route2.id, '"] = routeModule; return routeModule; }) ');
217
+ lazyImport = '() => import(/* webpackChunkName: "'.concat(route2.id, `" */ '`).concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
218
218
  component2 = "loadable(".concat(lazyImport, ")");
219
219
  } else {
220
- lazyImport = '() => import(/* webpackChunkName: "'.concat(route2.id, `" */ '`).concat(route2._component, `').then(routeModule => {if(typeof document !== "undefined") window.`).concat(ROUTE_MODULES, '["').concat(route2.id, '"] = routeModule; return routeModule; }) ');
220
+ lazyImport = '() => import(/* webpackChunkName: "'.concat(route2.id, `" */ '`).concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
221
221
  component2 = "lazy(".concat(lazyImport, ")");
222
222
  }
223
223
  } else {
224
- lazyImport = `() => import(/* webpackMode: "eager" */ '`.concat(route2._component, `').then(routeModule => {if(typeof document !== "undefined") window.`).concat(ROUTE_MODULES, '["').concat(route2.id, '"] = routeModule; return routeModule; }) ');
224
+ lazyImport = `() => import(/* webpackMode: "eager" */ '`.concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
225
225
  if (ssrMode === "string") {
226
226
  component2 = "loadable(".concat(lazyImport, ")");
227
227
  } else {
@@ -400,7 +400,7 @@ var fileSystemRoutes = function() {
400
400
  ];
401
401
  case 2:
402
402
  _state.sent();
403
- importRuntimeRouterCode = "\n import { createShouldRevalidate } from '@modern-js/runtime/router';\n ";
403
+ importRuntimeRouterCode = "\n import { createShouldRevalidate, handleRouteModule, handleRouteModuleError} from '@modern-js/runtime/router';\n ";
404
404
  routeModulesCode = "\n if(typeof document !== 'undefined'){\n window.".concat(ROUTE_MODULES, " = {}\n }\n ");
405
405
  return [
406
406
  2,
@@ -127,14 +127,16 @@ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
127
127
  var routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
128
128
  var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
129
129
  var workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
130
+ var _normalizedConfig_output = normalizedConfig.output, enableInlineRouteManifests = _normalizedConfig_output.enableInlineRouteManifests, disableInlineRouteManifests = _normalizedConfig_output.disableInlineRouteManifests;
131
+ var inlineRouteManifests = disableInlineRouteManifests ? !disableInlineRouteManifests : enableInlineRouteManifests;
130
132
  if (existNestedRoutes || routerManifest || workerSSR) {
131
- var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
133
+ var _normalizedConfig_output_distPath, _normalizedConfig_output1, _normalizedConfig_output2, _normalizedConfig_html, _normalizedConfig_security;
132
134
  chain.plugin(pluginName).use(RouterPlugin, [
133
135
  {
134
136
  HtmlBundlerPlugin,
135
- enableInlineRouteManifests: normalizedConfig.output.enableInlineRouteManifests,
136
- staticJsDir: (_normalizedConfig_output = normalizedConfig.output) === null || _normalizedConfig_output === void 0 ? void 0 : (_normalizedConfig_output_distPath = _normalizedConfig_output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.js,
137
- disableFilenameHash: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : _normalizedConfig_output1.disableFilenameHash,
137
+ enableInlineRouteManifests: inlineRouteManifests,
138
+ staticJsDir: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : (_normalizedConfig_output_distPath = _normalizedConfig_output1.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.js,
139
+ disableFilenameHash: (_normalizedConfig_output2 = normalizedConfig.output) === null || _normalizedConfig_output2 === void 0 ? void 0 : _normalizedConfig_output2.disableFilenameHash,
138
140
  scriptLoading: (_normalizedConfig_html = normalizedConfig.html) === null || _normalizedConfig_html === void 0 ? void 0 : _normalizedConfig_html.scriptLoading,
139
141
  nonce: (_normalizedConfig_security = normalizedConfig.security) === null || _normalizedConfig_security === void 0 ? void 0 : _normalizedConfig_security.nonce
140
142
  }
@@ -80,7 +80,7 @@ var RouterPlugin = /* @__PURE__ */ function() {
80
80
  return;
81
81
  }
82
82
  var webpack = compiler.webpack;
83
- var isRspack = webpack.rspackVersion;
83
+ var isRspack = "rspackVersion" in webpack;
84
84
  var Compilation = webpack.Compilation, sources = webpack.sources;
85
85
  var RawSource = sources.RawSource;
86
86
  var normalizePath = function(path) {
@@ -13,7 +13,8 @@ function createDefaultConfig(appContext, bundler) {
13
13
  });
14
14
  var output = _object_spread_props(_object_spread({}, defaultBuilderConfig.output), {
15
15
  disableNodePolyfill: true,
16
- enableInlineRouteManifests: true
16
+ enableInlineRouteManifests: true,
17
+ disableInlineRouteManifests: false
17
18
  });
18
19
  var _obj;
19
20
  var source = _object_spread_props(_object_spread({}, defaultBuilderConfig.source), {
@@ -1,31 +1,31 @@
1
1
  import path, { isAbsolute } from "path";
2
2
  import { findExists } from "@modern-js/utils";
3
3
  function initHtmlConfig(config, appContext) {
4
- var createBuilderAppIcon = function createBuilderAppIcon2(config2, appContext2) {
4
+ var ICON_EXTENSIONS = [
5
+ "png",
6
+ "jpg",
7
+ "jpeg",
8
+ "svg",
9
+ "ico"
10
+ ];
11
+ config.html.appIcon = createBuilderAppIcon(config, appContext);
12
+ config.html.favicon = createBuilderFavicon(config, appContext);
13
+ return config.html;
14
+ function createBuilderAppIcon(config2, appContext2) {
5
15
  var configDir = config2.source.configDir;
6
16
  var appIcon = findExists(ICON_EXTENSIONS.map(function(ext) {
7
17
  return path.resolve(appContext2.appDirectory, configDir || "./config", "icon.".concat(ext));
8
18
  }));
9
19
  return typeof appIcon === "string" ? appIcon : void 0;
10
- };
11
- var createBuilderFavicon = function createBuilderFavicon2(config2, appContext2) {
20
+ }
21
+ function createBuilderFavicon(config2, appContext2) {
12
22
  var configDir = config2.source.configDir;
13
23
  var favicon = config2.html.favicon;
14
24
  var defaultFavicon = findExists(ICON_EXTENSIONS.map(function(ext) {
15
25
  return path.resolve(appContext2.appDirectory, configDir || "./config", "favicon.".concat(ext));
16
26
  }));
17
27
  return favicon || defaultFavicon || void 0;
18
- };
19
- var ICON_EXTENSIONS = [
20
- "png",
21
- "jpg",
22
- "jpeg",
23
- "svg",
24
- "ico"
25
- ];
26
- config.html.appIcon = createBuilderAppIcon(config, appContext);
27
- config.html.favicon = createBuilderFavicon(config, appContext);
28
- return config.html;
28
+ }
29
29
  }
30
30
  function initSourceConfig(config, appContext, bundler) {
31
31
  config.source.include = createBuilderInclude(config, appContext);
@@ -50,11 +50,6 @@ function createBuilderInclude(config, appContext) {
50
50
  return transformInclude;
51
51
  }
52
52
  function createBuilderModuleScope(config) {
53
- var isPrimitiveScope = function isPrimitiveScope2(items) {
54
- return items.every(function(item) {
55
- return typeof item === "string" || Object.prototype.toString.call(item) === "[object RegExp]";
56
- });
57
- };
58
53
  var moduleScopes = config.source.moduleScopes;
59
54
  if (moduleScopes) {
60
55
  var DEFAULT_SCOPES = [
@@ -67,6 +62,11 @@ function createBuilderModuleScope(config) {
67
62
  } else {
68
63
  return void 0;
69
64
  }
65
+ function isPrimitiveScope(items) {
66
+ return items.every(function(item) {
67
+ return typeof item === "string" || Object.prototype.toString.call(item) === "[object RegExp]";
68
+ });
69
+ }
70
70
  function applyScopeOptions(defaults, options) {
71
71
  if (Array.isArray(options)) {
72
72
  if (isPrimitiveScope(options)) {
@@ -3,8 +3,8 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
3
  var defineConfig = function(config) {
4
4
  return config;
5
5
  };
6
- var _config_autoLoadPlugins;
7
6
  var defineLegacyConfig = function(config) {
7
+ var _config_autoLoadPlugins;
8
8
  return _object_spread_props(_object_spread({}, config), {
9
9
  legacy: true,
10
10
  autoLoadPlugins: (_config_autoLoadPlugins = config.autoLoadPlugins) !== null && _config_autoLoadPlugins !== void 0 ? _config_autoLoadPlugins : true
@@ -30,7 +30,7 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
30
30
  for (const entrypoint of entrypoints) {
31
31
  const { entryName, isMainEntry } = entrypoint;
32
32
  const name = entrypoints.length === 1 && isMainEntry ? "" : entryName;
33
- const customIndexTemplate = findPartials(htmlDir, name, PartialPosition.INDEX);
33
+ const customIndexTemplate = findPartials(htmlDir, name, "index");
34
34
  if (customIndexTemplate) {
35
35
  htmlTemplates[entryName] = customIndexTemplate.file;
36
36
  } else {
@@ -38,9 +38,9 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
38
38
  const { partials } = await hookRunners.htmlPartials({
39
39
  entrypoint,
40
40
  partials: [
41
- PartialPosition.TOP,
42
- PartialPosition.HEAD,
43
- PartialPosition.BODY
41
+ "top",
42
+ "head",
43
+ "body"
44
44
  ].reduce((previous, position) => {
45
45
  const found = findPartials(htmlDir, name, position);
46
46
  previous[position] = found ? [
@@ -57,7 +57,7 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
57
57
  fs.outputFileSync(templatePath, templates.html(partials), "utf8");
58
58
  htmlTemplates[entryName] = templatePath;
59
59
  partialsByEntrypoint[entryName] = partials;
60
- const bottomTemplate = findPartials(htmlDir, name, PartialPosition.BOTTOM);
60
+ const bottomTemplate = findPartials(htmlDir, name, "bottom");
61
61
  if (bottomTemplate) {
62
62
  htmlTemplates[`__${entryName}-bottom__`] = bottomTemplate.content;
63
63
  }
@@ -152,7 +152,8 @@ const routesForServer = ({ routes }) => {
152
152
  ${routesCode}
153
153
  `;
154
154
  };
155
- const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([^,]+)"`, "g");
155
+ const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([^
156
+ ]+)"`, "g");
156
157
  const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, splitRouteChunks = true }) => {
157
158
  const components = [];
158
159
  const loadings = [];
@@ -226,18 +227,18 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
226
227
  if (route._component) {
227
228
  if (splitRouteChunks) {
228
229
  if (route.isRoot) {
229
- lazyImport = `() => import('${route._component}').then(routeModule => {if(typeof document !== "undefined") window.${ROUTE_MODULES}["${route.id}"] = routeModule; return routeModule; }) `;
230
+ lazyImport = `() => import('${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
230
231
  rootLayoutCode = `import RootLayout from '${route._component}'`;
231
232
  component = `RootLayout`;
232
233
  } else if (ssrMode === "string") {
233
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => {if(typeof document !== "undefined") window.${ROUTE_MODULES}["${route.id}"] = routeModule; return routeModule; }) `;
234
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
234
235
  component = `loadable(${lazyImport})`;
235
236
  } else {
236
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => {if(typeof document !== "undefined") window.${ROUTE_MODULES}["${route.id}"] = routeModule; return routeModule; }) `;
237
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
237
238
  component = `lazy(${lazyImport})`;
238
239
  }
239
240
  } else {
240
- lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule => {if(typeof document !== "undefined") window.${ROUTE_MODULES}["${route.id}"] = routeModule; return routeModule; }) `;
241
+ lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
241
242
  if (ssrMode === "string") {
242
243
  component = `loadable(${lazyImport})`;
243
244
  } else {
@@ -364,7 +365,7 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
364
365
  await fs.ensureFile(loadersMapFile);
365
366
  await fs.writeJSON(loadersMapFile, loadersMap);
366
367
  const importRuntimeRouterCode = `
367
- import { createShouldRevalidate } from '@modern-js/runtime/router';
368
+ import { createShouldRevalidate, handleRouteModule, handleRouteModuleError} from '@modern-js/runtime/router';
368
369
  `;
369
370
  const routeModulesCode = `
370
371
  if(typeof document !== 'undefined'){
@@ -76,12 +76,14 @@ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
76
76
  const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
77
77
  const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
78
78
  const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
79
+ const { enableInlineRouteManifests, disableInlineRouteManifests } = normalizedConfig.output;
80
+ const inlineRouteManifests = disableInlineRouteManifests ? !disableInlineRouteManifests : enableInlineRouteManifests;
79
81
  if (existNestedRoutes || routerManifest || workerSSR) {
80
82
  var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
81
83
  chain.plugin(pluginName).use(RouterPlugin, [
82
84
  {
83
85
  HtmlBundlerPlugin,
84
- enableInlineRouteManifests: normalizedConfig.output.enableInlineRouteManifests,
86
+ enableInlineRouteManifests: inlineRouteManifests,
85
87
  staticJsDir: (_normalizedConfig_output = normalizedConfig.output) === null || _normalizedConfig_output === void 0 ? void 0 : (_normalizedConfig_output_distPath = _normalizedConfig_output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.js,
86
88
  disableFilenameHash: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : _normalizedConfig_output1.disableFilenameHash,
87
89
  scriptLoading: (_normalizedConfig_html = normalizedConfig.html) === null || _normalizedConfig_html === void 0 ? void 0 : _normalizedConfig_html.scriptLoading,
@@ -39,7 +39,7 @@ class RouterPlugin {
39
39
  return;
40
40
  }
41
41
  const { webpack } = compiler;
42
- const isRspack = webpack.rspackVersion;
42
+ const isRspack = "rspackVersion" in webpack;
43
43
  const { Compilation, sources } = webpack;
44
44
  const { RawSource } = sources;
45
45
  const normalizePath = (path) => {
@@ -12,7 +12,8 @@ function createDefaultConfig(appContext, bundler) {
12
12
  const output = {
13
13
  ...defaultBuilderConfig.output,
14
14
  disableNodePolyfill: true,
15
- enableInlineRouteManifests: true
15
+ enableInlineRouteManifests: true,
16
+ disableInlineRouteManifests: false
16
17
  };
17
18
  const source = {
18
19
  ...defaultBuilderConfig.source,
@@ -1,10 +1,12 @@
1
1
  const defineConfig = (config) => config;
2
- var _config_autoLoadPlugins;
3
- const defineLegacyConfig = (config) => ({
4
- ...config,
5
- legacy: true,
6
- autoLoadPlugins: (_config_autoLoadPlugins = config.autoLoadPlugins) !== null && _config_autoLoadPlugins !== void 0 ? _config_autoLoadPlugins : true
7
- });
2
+ const defineLegacyConfig = (config) => {
3
+ var _config_autoLoadPlugins;
4
+ return {
5
+ ...config,
6
+ legacy: true,
7
+ autoLoadPlugins: (_config_autoLoadPlugins = config.autoLoadPlugins) !== null && _config_autoLoadPlugins !== void 0 ? _config_autoLoadPlugins : true
8
+ };
9
+ };
8
10
  export {
9
11
  defineConfig,
10
12
  defineLegacyConfig
@@ -18,25 +18,25 @@ export declare const HTML_PARTIALS_FOLDER = "html";
18
18
  export declare const HTML_PARTIALS_EXTENSIONS: string[];
19
19
  export declare const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
20
20
  export declare const NESTED_ROUTE: {
21
- LAYOUT_FILE: string;
22
- LAYOUT_CONFIG_FILE: string;
23
- LAYOUT_LOADER_FILE: string;
24
- LAYOUT_DATA_FILE: string;
25
- LAYOUT_CLIENT_LOADER: string;
26
- PAGE_FILE: string;
27
- PAGE_CONFIG_FILE: string;
28
- PAGE_LOADER_FILE: string;
29
- PAGE_DATA_FILE: string;
30
- PAGE_CLIENT_LOADER: string;
31
- SPLATE_FILE: string;
32
- SPLATE_CONFIG_FILE: string;
33
- SPLATE_LOADER_FILE: string;
34
- SPLATE_DATA_FILE: string;
35
- SPLATE_CLIENT_DATA: string;
36
- LOADING_FILE: string;
37
- ERROR_FILE: string;
38
- LOADER_FILE: string;
21
+ LAYOUT_FILE: string;
22
+ LAYOUT_CONFIG_FILE: string;
23
+ LAYOUT_LOADER_FILE: string;
24
+ LAYOUT_DATA_FILE: string;
25
+ LAYOUT_CLIENT_LOADER: string;
26
+ PAGE_FILE: string;
27
+ PAGE_CONFIG_FILE: string;
28
+ PAGE_LOADER_FILE: string;
29
+ PAGE_DATA_FILE: string;
30
+ PAGE_CLIENT_LOADER: string;
31
+ SPLATE_FILE: string;
32
+ SPLATE_CONFIG_FILE: string;
33
+ SPLATE_LOADER_FILE: string;
34
+ SPLATE_DATA_FILE: string;
35
+ SPLATE_CLIENT_DATA: string;
36
+ LOADING_FILE: string;
37
+ ERROR_FILE: string;
38
+ LOADER_FILE: string;
39
39
  };
40
40
  export declare const APP_CONFIG_NAME = "config";
41
41
  export declare const APP_INIT_EXPORTED = "init";
42
- export declare const APP_INIT_IMPORTED = "appInit";
42
+ export declare const APP_INIT_IMPORTED = "appInit";
@@ -4,20 +4,13 @@ import { BundlerConfig } from '@modern-js/builder-shared';
4
4
  import { AppNormalizedConfig, AppTools, ImportStatement } from '../types';
5
5
  export declare const createImportStatements: (statements: ImportStatement[]) => string;
6
6
  export declare const generateCode: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>, entrypoints: Entrypoint[], api: PluginAPI<AppTools<'shared'>>) => Promise<{
7
- importsStatemets: Map<string, ImportStatement[]>;
7
+ importsStatemets: Map<string, ImportStatement[]>;
8
8
  }>;
9
- export declare const generateIndexCode: ({
10
- appContext,
11
- api,
12
- entrypoints,
13
- config,
14
- importsStatemets,
15
- bundlerConfigs
16
- }: {
17
- appContext: IAppContext;
18
- api: PluginAPI<AppTools<'shared'>>;
19
- entrypoints: Entrypoint[];
20
- config: AppNormalizedConfig<'shared'>;
21
- importsStatemets: Map<string, ImportStatement[]>;
22
- bundlerConfigs?: BundlerConfig[] | undefined;
23
- }) => Promise<void>;
9
+ export declare const generateIndexCode: ({ appContext, api, entrypoints, config, importsStatemets, bundlerConfigs, }: {
10
+ appContext: IAppContext;
11
+ api: PluginAPI<AppTools<'shared'>>;
12
+ entrypoints: Entrypoint[];
13
+ config: AppNormalizedConfig<'shared'>;
14
+ importsStatemets: Map<string, ImportStatement[]>;
15
+ bundlerConfigs?: BundlerConfig[] | undefined;
16
+ }) => Promise<void>;
@@ -1,3 +1,3 @@
1
1
  import type { Entrypoint } from '@modern-js/types';
2
2
  import type { AppNormalizedConfig, IAppContext } from '../types';
3
- export declare const getBundleEntry: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Entrypoint[];
3
+ export declare const getBundleEntry: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Entrypoint[];
@@ -1,14 +1,8 @@
1
1
  import type { Entrypoint, NestedRouteForCli, PageRoute } from '@modern-js/types';
2
- export declare const getClientRoutes: ({
3
- entrypoint,
4
- srcDirectory,
5
- srcAlias,
6
- internalDirectory,
7
- internalDirAlias
8
- }: {
9
- entrypoint: Entrypoint;
10
- srcDirectory: string;
11
- srcAlias: string;
12
- internalDirectory: string;
13
- internalDirAlias: string;
14
- }) => (NestedRouteForCli | PageRoute)[];
2
+ export declare const getClientRoutes: ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias, }: {
3
+ entrypoint: Entrypoint;
4
+ srcDirectory: string;
5
+ srcAlias: string;
6
+ internalDirectory: string;
7
+ internalDirAlias: string;
8
+ }) => (NestedRouteForCli | PageRoute)[];
@@ -1,15 +1,9 @@
1
1
  import type { Entrypoint, RouteLegacy } from '@modern-js/types';
2
2
  export type { RouteLegacy as Route };
3
- export declare const getClientRoutes: ({
4
- entrypoint,
5
- srcDirectory,
6
- srcAlias,
7
- internalDirectory,
8
- internalDirAlias
9
- }: {
10
- entrypoint: Entrypoint;
11
- srcDirectory: string;
12
- srcAlias: string;
13
- internalDirectory: string;
14
- internalDirAlias: string;
15
- }) => RouteLegacy[];
3
+ export declare const getClientRoutes: ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias, }: {
4
+ entrypoint: Entrypoint;
5
+ srcDirectory: string;
6
+ srcAlias: string;
7
+ internalDirectory: string;
8
+ internalDirAlias: string;
9
+ }) => RouteLegacy[];
@@ -1,2 +1,2 @@
1
1
  export { getClientRoutes } from './getRoutes';
2
- export { getClientRoutes as getClientRoutesLegacy } from './getRoutesLegacy';
2
+ export { getClientRoutes as getClientRoutesLegacy } from './getRoutesLegacy';
@@ -2,4 +2,4 @@ declare const debug: import("@modern-js/utils/compiled/debug").Debugger;
2
2
  export { debug };
3
3
  export declare const findLayout: (dir: string) => string | false;
4
4
  export declare const getRouteWeight: (route: string) => number;
5
- export declare const shouldSkip: (file: string) => boolean;
5
+ export declare const shouldSkip: (file: string) => boolean;
@@ -1,4 +1,4 @@
1
1
  import type { Entrypoint } from '@modern-js/types';
2
2
  import type { AppNormalizedConfig, IAppContext } from '../types';
3
3
  export type { Entrypoint };
4
- export declare const getFileSystemEntry: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Entrypoint[];
4
+ export declare const getFileSystemEntry: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Entrypoint[];