@modern-js/runtime 3.11.3 → 3.12.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 (58) hide show
  1. package/dist/cjs/cli/ssr/index.js +2 -2
  2. package/dist/cjs/cli/ssr/mode.js +1 -1
  3. package/dist/cjs/cli/template.js +1 -1
  4. package/dist/cjs/core/context/monitors/default.js +2 -2
  5. package/dist/cjs/core/context/response/index.js +3 -3
  6. package/dist/cjs/core/context/serverPayload/index.js +1 -1
  7. package/dist/cjs/core/react/wrapper.js +1 -1
  8. package/dist/cjs/core/server/stream/createReadableStream.worker.js +1 -1
  9. package/dist/cjs/core/server/string/loadable.js +2 -2
  10. package/dist/cjs/router/cli/code/index.js +2 -1
  11. package/dist/cjs/router/cli/code/nestedRoutes.js +6 -0
  12. package/dist/cjs/router/cli/code/templates.js +19 -9
  13. package/dist/cjs/router/cli/code/utils.js +4 -0
  14. package/dist/cjs/router/cli/config-routes/converter.js +2 -2
  15. package/dist/cjs/router/cli/constants.js +4 -0
  16. package/dist/cjs/router/cli/index.js +1 -1
  17. package/dist/cjs/router/runtime/plugin.node.js +2 -2
  18. package/dist/esm/cli/ssr/index.mjs +2 -2
  19. package/dist/esm/cli/ssr/mode.mjs +1 -1
  20. package/dist/esm/cli/template.mjs +1 -1
  21. package/dist/esm/core/context/monitors/default.mjs +2 -2
  22. package/dist/esm/core/context/response/index.mjs +3 -3
  23. package/dist/esm/core/context/serverPayload/index.mjs +1 -1
  24. package/dist/esm/core/react/wrapper.mjs +1 -1
  25. package/dist/esm/core/server/stream/createReadableStream.worker.mjs +1 -1
  26. package/dist/esm/core/server/string/loadable.mjs +2 -2
  27. package/dist/esm/router/cli/code/index.mjs +3 -2
  28. package/dist/esm/router/cli/code/nestedRoutes.mjs +7 -1
  29. package/dist/esm/router/cli/code/templates.mjs +19 -9
  30. package/dist/esm/router/cli/code/utils.mjs +3 -2
  31. package/dist/esm/router/cli/config-routes/converter.mjs +2 -2
  32. package/dist/esm/router/cli/constants.mjs +2 -1
  33. package/dist/esm/router/cli/index.mjs +1 -1
  34. package/dist/esm/router/runtime/plugin.node.mjs +2 -2
  35. package/dist/esm-node/cli/ssr/index.mjs +2 -2
  36. package/dist/esm-node/cli/ssr/mode.mjs +1 -1
  37. package/dist/esm-node/cli/template.mjs +1 -1
  38. package/dist/esm-node/core/context/monitors/default.mjs +2 -2
  39. package/dist/esm-node/core/context/response/index.mjs +3 -3
  40. package/dist/esm-node/core/context/serverPayload/index.mjs +1 -1
  41. package/dist/esm-node/core/react/wrapper.mjs +1 -1
  42. package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +1 -1
  43. package/dist/esm-node/core/server/string/loadable.mjs +2 -2
  44. package/dist/esm-node/router/cli/code/index.mjs +3 -2
  45. package/dist/esm-node/router/cli/code/nestedRoutes.mjs +7 -1
  46. package/dist/esm-node/router/cli/code/templates.mjs +19 -9
  47. package/dist/esm-node/router/cli/code/utils.mjs +3 -2
  48. package/dist/esm-node/router/cli/config-routes/converter.mjs +2 -2
  49. package/dist/esm-node/router/cli/constants.mjs +2 -1
  50. package/dist/esm-node/router/cli/index.mjs +1 -1
  51. package/dist/esm-node/router/runtime/plugin.node.mjs +2 -2
  52. package/dist/types/cli/template.d.ts +1 -1
  53. package/dist/types/core/context/response/index.d.ts +3 -3
  54. package/dist/types/core/context/serverPayload/index.d.ts +1 -1
  55. package/dist/types/router/cli/code/templates.d.ts +2 -1
  56. package/dist/types/router/cli/code/utils.d.ts +1 -0
  57. package/dist/types/router/cli/constants.d.ts +1 -0
  58. package/package.json +10 -10
@@ -37,7 +37,7 @@ var __webpack_require__ = {};
37
37
  var __webpack_exports__ = {};
38
38
  __webpack_require__.r(__webpack_exports__);
39
39
  __webpack_require__.d(__webpack_exports__, {
40
- default: ()=>cli_ssr,
40
+ default: ()=>ssr,
41
41
  ssrPlugin: ()=>ssrPlugin
42
42
  });
43
43
  const external_path_namespaceObject = require("path");
@@ -155,7 +155,7 @@ const ssrPlugin = ()=>({
155
155
  }));
156
156
  }
157
157
  });
158
- const cli_ssr = ssrPlugin;
158
+ const ssr = ssrPlugin;
159
159
  exports["default"] = __webpack_exports__["default"];
160
160
  exports.ssrPlugin = __webpack_exports__.ssrPlugin;
161
161
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -28,7 +28,7 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  function resolveSSRMode(params) {
31
- const { entry, config, appDirectory, nestedRoutesEntry } = params;
31
+ const { entry, config, nestedRoutesEntry } = params;
32
32
  const isSsgEnabled = config.output?.ssg || config.output?.ssgByEntries && (entry ? !!config.output.ssgByEntries[entry] : Object.keys(config.output.ssgByEntries).length > 0);
33
33
  if (isSsgEnabled) if (nestedRoutesEntry) return 'stream';
34
34
  else return 'string';
@@ -80,7 +80,7 @@ ${genRenderStatement({
80
80
  isNestedRouter
81
81
  })}`;
82
82
  };
83
- const entryForCSRWithRSC = ({ metaName, entryName, urlPath = '/', mountId = 'root', isNestedRouter })=>`
83
+ const entryForCSRWithRSC = ({ metaName, entryName, mountId = 'root', isNestedRouter })=>`
84
84
  import '@${metaName}/runtime/registry/${entryName}';
85
85
  import { render } from '@${metaName}/runtime/browser';
86
86
  import { createRoot } from '@${metaName}/runtime/react';
@@ -28,13 +28,13 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  const defaultMonitors = {
31
- counter (name) {},
31
+ counter () {},
32
32
  info: console.info,
33
33
  debug: console.debug,
34
34
  trace: console.trace,
35
35
  warn: console.warn,
36
36
  error: console.error,
37
- timing (name, dur) {}
37
+ timing () {}
38
38
  };
39
39
  __webpack_require__.d(__webpack_exports__, {}, {
40
40
  defaultMonitors: defaultMonitors
@@ -28,9 +28,9 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  const getResponseProxy = ()=>null;
31
- const setHeaders = (headers)=>{};
32
- const setStatus = (status)=>{};
33
- const redirect = (url, init)=>{
31
+ const setHeaders = (_headers)=>{};
32
+ const setStatus = (_status)=>{};
33
+ const redirect = (_url, _init)=>{
34
34
  console.warn("You should not use this API in the browser, please use the router's redirect or useNavigate method.");
35
35
  };
36
36
  __webpack_require__.d(__webpack_exports__, {}, {
@@ -28,7 +28,7 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  const getServerPayload = ()=>{};
31
- const setServerPayload = (payload)=>{};
31
+ const setServerPayload = (_payload)=>{};
32
32
  __webpack_require__.d(__webpack_exports__, {}, {
33
33
  getServerPayload: getServerPayload,
34
34
  setServerPayload: setServerPayload
@@ -33,7 +33,7 @@ __webpack_require__.d(__webpack_exports__, {
33
33
  const jsx_runtime_namespaceObject = require("react/jsx-runtime");
34
34
  const index_js_namespaceObject = require("../context/index.js");
35
35
  function wrapRuntimeContextProvider(App, contextValue) {
36
- const { isBrowser, initialData, routes, context, routeManifest, routerContext, unstable_getBlockNavState, ssrContext, _internalContext, _internalRouterBaseName, ...rest } = contextValue;
36
+ const { isBrowser, initialData, routes, context, routeManifest: _routeManifest, routerContext: _routerContext, unstable_getBlockNavState: _unstable_getBlockNavState, ssrContext: _ssrContext, _internalContext, _internalRouterBaseName, ...rest } = contextValue;
37
37
  const runtimeContextValue = {
38
38
  isBrowser,
39
39
  initialData,
@@ -153,7 +153,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
153
153
  }
154
154
  });
155
155
  return stream;
156
- } catch (e) {
156
+ } catch {
157
157
  const fallbackHtml = `${shellBefore}${shellAfter}`;
158
158
  const stream = (0, external_shared_js_namespaceObject.getReadableStreamFromString)(fallbackHtml);
159
159
  return stream;
@@ -72,7 +72,7 @@ class LoadableCollector {
72
72
  asyncChunks.push(...extractor.getChunkAssets([
73
73
  `async-${entryName}`
74
74
  ]));
75
- } catch (e) {}
75
+ } catch {}
76
76
  const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
77
77
  const scriptChunks = generateChunks(chunks, 'js');
78
78
  const styleChunks = generateChunks(chunks, 'css');
@@ -112,7 +112,7 @@ class LoadableCollector {
112
112
  chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
113
113
  }
114
114
  async emitStyleAssets(chunks) {
115
- const { template, chunkSet, config, entryName } = this.options;
115
+ const { template, chunkSet, config } = this.options;
116
116
  const { inlineStyles } = config;
117
117
  const atrributes = (0, external_utils_js_namespaceObject.attributesToString)(this.generateAttributes());
118
118
  const css = await Promise.all(chunks.filter((chunk)=>!(0, external_utils_js_namespaceObject.hasStylesheetLink)(template, chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
@@ -150,7 +150,8 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
150
150
  const filtedRoutesForServer = (0, utils_namespaceObject.filterRoutesForServer)(routes);
151
151
  const routesForServerLoaderMatches = (0, utils_namespaceObject.filterRoutesLoader)(routes);
152
152
  const code = external_templates_js_namespaceObject.routesForServer({
153
- routesForServerLoaderMatches
153
+ routesForServerLoaderMatches,
154
+ ssg: (0, utils_namespaceObject.isSSGEntry)(config, entryName, entrypoints)
154
155
  });
155
156
  await utils_namespaceObject.fs.ensureFile(routesServerFile);
156
157
  await utils_namespaceObject.fs.writeFile(routesServerFile, code);
@@ -118,12 +118,14 @@ const walk = async (options)=>{
118
118
  let pageClientData = '';
119
119
  let pageData = '';
120
120
  let pageAction = '';
121
+ let pageSsgParams = '';
121
122
  let splatLoaderFile = '';
122
123
  let splatRoute = null;
123
124
  let splatConfigFile = '';
124
125
  let splatClientData = '';
125
126
  let splatData = '';
126
127
  let splatAction = '';
128
+ let splatSsgParams = '';
127
129
  const items = await utils_namespaceObject.fs.readdir(dirname);
128
130
  for (const item of items){
129
131
  const itemPath = external_path_namespaceObject.join(dirname, item);
@@ -159,6 +161,7 @@ const walk = async (options)=>{
159
161
  if (itemWithoutExt === external_constants_js_namespaceObject.NESTED_ROUTE.PAGE_DATA_FILE) {
160
162
  pageData = itemPathWithAlias;
161
163
  if (await (0, external_utils_js_namespaceObject.hasAction)(itemPath)) pageAction = itemPathWithAlias;
164
+ if (await (0, external_utils_js_namespaceObject.hasSsgParams)(itemPath)) pageSsgParams = itemPathWithAlias;
162
165
  }
163
166
  if (itemWithoutExt === external_constants_js_namespaceObject.NESTED_ROUTE.PAGE_CONFIG_FILE) pageConfigFile = itemPathWithAlias;
164
167
  if (itemWithoutExt === external_constants_js_namespaceObject.NESTED_ROUTE.PAGE_FILE) {
@@ -170,6 +173,7 @@ const walk = async (options)=>{
170
173
  if (pageData) pageRoute.data = pageData;
171
174
  if (pageClientData) pageRoute.clientData = pageClientData;
172
175
  if (pageAction) pageRoute.action = pageAction;
176
+ if (pageSsgParams) pageRoute.ssgParams = pageSsgParams;
173
177
  route.children?.unshift(pageRoute);
174
178
  }
175
179
  if (itemWithoutExt === external_constants_js_namespaceObject.NESTED_ROUTE.SPLATE_LOADER_FILE) splatLoaderFile = itemPathWithAlias;
@@ -180,6 +184,7 @@ const walk = async (options)=>{
180
184
  if (itemWithoutExt === external_constants_js_namespaceObject.NESTED_ROUTE.SPLATE_DATA_FILE) {
181
185
  splatData = itemPathWithAlias;
182
186
  if (await (0, external_utils_js_namespaceObject.hasAction)(itemPath)) splatAction = itemPathWithAlias;
187
+ if (await (0, external_utils_js_namespaceObject.hasSsgParams)(itemPath)) splatSsgParams = itemPathWithAlias;
183
188
  }
184
189
  if (itemWithoutExt === external_constants_js_namespaceObject.NESTED_ROUTE.SPLATE_FILE) {
185
190
  splatRoute = createRoute({
@@ -192,6 +197,7 @@ const walk = async (options)=>{
192
197
  if (splatData) splatRoute.data = splatData;
193
198
  if (splatConfigFile) splatRoute.config = splatConfigFile;
194
199
  if (splatAction) splatRoute.action = splatAction;
200
+ if (splatSsgParams) splatRoute.ssgParams = splatSsgParams;
195
201
  route.children?.push(splatRoute);
196
202
  }
197
203
  if (itemWithoutExt === external_constants_js_namespaceObject.NESTED_ROUTE.LOADING_FILE) route.loading = itemPathWithAlias;
@@ -49,9 +49,11 @@ const utils_namespaceObject = require("@modern-js/utils");
49
49
  const constants_namespaceObject = require("@modern-js/utils/universal/constants");
50
50
  const external_constants_js_namespaceObject = require("../constants.js");
51
51
  const external_utils_js_namespaceObject = require("./utils.js");
52
- const routesForServer = ({ routesForServerLoaderMatches })=>{
52
+ const routesForServer = ({ routesForServerLoaderMatches, ssg = false })=>{
53
53
  const loaders = [];
54
54
  const actions = [];
55
+ const ssgParamsImports = [];
56
+ const ssgParamsEntries = [];
55
57
  const loadersMap = {};
56
58
  const traverseRouteTree = (route)=>{
57
59
  let children;
@@ -59,6 +61,11 @@ const routesForServer = ({ routesForServerLoaderMatches })=>{
59
61
  let loader;
60
62
  let action;
61
63
  if ('nested' === route.type) {
64
+ if (ssg && route.ssgParams && route.id && !route.inValidSSRRoute) {
65
+ const name = `ssgParams_${ssgParamsImports.length}`;
66
+ ssgParamsImports.push(`import { ssgParams as ${name} } from ${JSON.stringify((0, utils_namespaceObject.slash)(route.ssgParams))};`);
67
+ ssgParamsEntries.push(`${JSON.stringify(route.id)}: ${name}`);
68
+ }
62
69
  if (route.loader || route.data) {
63
70
  loaders.push(route.loader);
64
71
  const loaderId = loaders.length - 1;
@@ -84,6 +91,7 @@ const routesForServer = ({ routesForServerLoaderMatches })=>{
84
91
  action,
85
92
  children
86
93
  };
94
+ if ('ssgParams' in finalRoute) delete finalRoute.ssgParams;
87
95
  return finalRoute;
88
96
  };
89
97
  let routesCode = `
@@ -110,10 +118,11 @@ const routesForServer = ({ routesForServerLoaderMatches })=>{
110
118
  if (route.action) importLoadersCode += `import { loader as ${key}, action as action_${loaderInfo.loaderId} } from "${(0, utils_namespaceObject.slash)(loaderInfo.filePath)}";\n`;
111
119
  else importLoadersCode += `import { loader as ${key} } from "${(0, utils_namespaceObject.slash)(loaderInfo.filePath)}";\n`;
112
120
  } else importLoadersCode += `import ${key} from "${(0, utils_namespaceObject.slash)(loaderInfo.filePath)}";\n`;
113
- return `
121
+ const code = `
114
122
  ${importLoadersCode}
115
123
  ${routesCode}
116
124
  `;
125
+ return ssg ? `${code}\n${ssgParamsImports.join('\n')}\nexport const ssgParams = {${ssgParamsEntries.join(',')}};\n` : code;
117
126
  };
118
127
  const createMatchReg = (keyword)=>new RegExp(`("${keyword}":\\s)"([^\n]+)"`, 'g');
119
128
  async function hasUseClientDirective(componentPath, srcDirectory, internalSrcAlias) {
@@ -157,7 +166,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
157
166
  };
158
167
  const createLazyImport = ({ componentPath, routeId, webpackChunkName, eager })=>{
159
168
  const importOptions = webpackChunkName ? `/* webpackChunkName: "${routeId}" */ ` : eager ? '/* webpackMode: "eager" */ ' : '';
160
- return `() => import(${importOptions}'${componentPath}').then(routeModule => handleRouteModule(routeModule, "${routeId}"))`;
169
+ return `() => import(${importOptions}'${(0, utils_namespaceObject.formatImportPath)(componentPath)}').then(routeModule => handleRouteModule(routeModule, "${routeId}"))`;
161
170
  };
162
171
  const traverseRouteTree = async (route, isRscClientBundle)=>{
163
172
  let children;
@@ -206,7 +215,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
206
215
  componentPath: route._component,
207
216
  routeId: route.id
208
217
  });
209
- rootLayoutCode = `import RootLayout from '${route._component}'`;
218
+ rootLayoutCode = `import RootLayout from '${(0, utils_namespaceObject.formatImportPath)(route._component)}'`;
210
219
  component = 'RootLayout';
211
220
  } else if (splitRouteChunks) {
212
221
  lazyImport = createLazyImport({
@@ -227,7 +236,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
227
236
  component = `lazy(${lazyImport})`;
228
237
  }
229
238
  } else if (route._component) if (splitRouteChunks) {
230
- lazyImport = `() => import('${route._component}')`;
239
+ lazyImport = `() => import('${(0, utils_namespaceObject.formatImportPath)(route._component)}')`;
231
240
  component = `loadable(${lazyImport})`;
232
241
  } else {
233
242
  components.push(route._component);
@@ -253,6 +262,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
253
262
  component
254
263
  }
255
264
  };
265
+ delete finalRoute.ssgParams;
256
266
  if ('nested' === route.type && route._component && (route.loader || route.data)) finalRoute.shouldRevalidate = `createShouldRevalidate("${route.id}")`;
257
267
  return finalRoute;
258
268
  };
@@ -276,7 +286,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
276
286
  const newRouteStr = regs.reduce((acc, reg)=>acc.replace(reg, '$1$2'), routeStr).replace(/"(RootLayout)"/g, '$1').replace(/\\"/g, '"');
277
287
  routeComponentsCode += `${newRouteStr},`;
278
288
  } else {
279
- const component = `loadable(() => import('${route._component}'))`;
289
+ const component = `loadable(() => import('${(0, utils_namespaceObject.formatImportPath)(route._component)}'))`;
280
290
  const finalRoute = {
281
291
  ...route,
282
292
  component
@@ -291,9 +301,9 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
291
301
  routeComponentsCode += `${newRouteStr},`;
292
302
  }
293
303
  routeComponentsCode += `\n];`;
294
- const importLoadingCode = loadings.map((loading, index)=>`import loading_${index} from '${loading}';\n`).join('');
295
- const importComponentsCode = components.map((component, index)=>`import component_${index} from '${component}';\n`).join('');
296
- const importErrorComponentsCode = errors.map((error, index)=>`import error_${index} from '${error}';\n`).join('');
304
+ const importLoadingCode = loadings.map((loading, index)=>`import loading_${index} from '${(0, utils_namespaceObject.formatImportPath)(loading)}';\n`).join('');
305
+ const importComponentsCode = components.map((component, index)=>`import component_${index} from '${(0, utils_namespaceObject.formatImportPath)(component)}';\n`).join('');
306
+ const importErrorComponentsCode = errors.map((error, index)=>`import error_${index} from '${(0, utils_namespaceObject.formatImportPath)(error)}';\n`).join('');
297
307
  let importLoadersCode = '';
298
308
  for (const [key, loaderInfo] of Object.entries(loadersMap))if (loaderInfo.inline) {
299
309
  const { route } = loaderInfo;
@@ -42,6 +42,7 @@ __webpack_require__.d(__webpack_exports__, {
42
42
  getServerLoadersFile: ()=>getServerLoadersFile,
43
43
  hasAction: ()=>hasAction,
44
44
  hasLoader: ()=>hasLoader,
45
+ hasSsgParams: ()=>hasSsgParams,
45
46
  isPageComponentFile: ()=>isPageComponentFile,
46
47
  parseModule: ()=>parseModule,
47
48
  replaceWithAlias: ()=>replaceWithAlias,
@@ -127,6 +128,7 @@ const hasExport = async (filename, exportName, source)=>{
127
128
  };
128
129
  const hasLoader = (filename, source)=>hasExport(filename, external_constants_js_namespaceObject.LOADER_EXPORT_NAME, source);
129
130
  const hasAction = (filename, source)=>hasExport(filename, external_constants_js_namespaceObject.ACTION_EXPORT_NAME, source);
131
+ const hasSsgParams = (filename, source)=>hasExport(filename, external_constants_js_namespaceObject.SSG_PARAMS_EXPORT_NAME, source);
130
132
  const getServerLoadersFile = (internalDirectory, entryName)=>external_path_default().join(internalDirectory, entryName, 'route-server-loaders.js');
131
133
  const getServerCombinedModuleFile = (internalDirectory, entryName)=>external_path_default().join(internalDirectory, entryName, 'server-loader-combined.js');
132
134
  const getPathWithoutExt = (filename)=>{
@@ -138,6 +140,7 @@ exports.getServerCombinedModuleFile = __webpack_exports__.getServerCombinedModul
138
140
  exports.getServerLoadersFile = __webpack_exports__.getServerLoadersFile;
139
141
  exports.hasAction = __webpack_exports__.hasAction;
140
142
  exports.hasLoader = __webpack_exports__.hasLoader;
143
+ exports.hasSsgParams = __webpack_exports__.hasSsgParams;
141
144
  exports.isPageComponentFile = __webpack_exports__.isPageComponentFile;
142
145
  exports.parseModule = __webpack_exports__.parseModule;
143
146
  exports.replaceWithAlias = __webpack_exports__.replaceWithAlias;
@@ -148,6 +151,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
148
151
  "getServerLoadersFile",
149
152
  "hasAction",
150
153
  "hasLoader",
154
+ "hasSsgParams",
151
155
  "isPageComponentFile",
152
156
  "parseModule",
153
157
  "replaceWithAlias",
@@ -106,14 +106,14 @@ async function discoverRelatedFiles(nestedRoute, componentPath, alias) {
106
106
  const aliasedPath = alias ? (0, utils_js_namespaceObject.replaceWithAlias)(alias.basename, filePath, alias.name) : filePath;
107
107
  nestedRoute[key] = (0, utils_namespaceObject.normalizeToPosixPath)(aliasedPath);
108
108
  }
109
- } catch (e) {}
109
+ } catch {}
110
110
  }));
111
111
  }
112
112
  function normalizeRoutes(generatedRoutes) {
113
113
  return generatedRoutes.map((route)=>normalizeRoute(route));
114
114
  }
115
115
  function normalizeRoute(route) {
116
- const { component, ...rest } = route;
116
+ const { component: _component, ...rest } = route;
117
117
  const processedRoute = {
118
118
  ...rest,
119
119
  ...route.children && route.children.length > 0 ? {
@@ -31,6 +31,7 @@ const NESTED_ROUTES_DIR = 'routes';
31
31
  const FILE_SYSTEM_ROUTES_FILE_NAME = 'routes.js';
32
32
  const LOADER_EXPORT_NAME = 'loader';
33
33
  const ACTION_EXPORT_NAME = 'action';
34
+ const SSG_PARAMS_EXPORT_NAME = 'ssgParams';
34
35
  const TEMP_LOADERS_DIR = '__loaders__';
35
36
  const FILE_SYSTEM_ROUTES_INDEX = 'index';
36
37
  const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
@@ -70,6 +71,7 @@ __webpack_require__.d(__webpack_exports__, {}, {
70
71
  LOADER_EXPORT_NAME: LOADER_EXPORT_NAME,
71
72
  NESTED_ROUTE: NESTED_ROUTE,
72
73
  NESTED_ROUTES_DIR: NESTED_ROUTES_DIR,
74
+ SSG_PARAMS_EXPORT_NAME: SSG_PARAMS_EXPORT_NAME,
73
75
  TEMP_LOADERS_DIR: TEMP_LOADERS_DIR
74
76
  });
75
77
  exports.ACTION_EXPORT_NAME = __webpack_exports__.ACTION_EXPORT_NAME;
@@ -83,6 +85,7 @@ exports.FILE_SYSTEM_ROUTES_INDEX = __webpack_exports__.FILE_SYSTEM_ROUTES_INDEX;
83
85
  exports.LOADER_EXPORT_NAME = __webpack_exports__.LOADER_EXPORT_NAME;
84
86
  exports.NESTED_ROUTE = __webpack_exports__.NESTED_ROUTE;
85
87
  exports.NESTED_ROUTES_DIR = __webpack_exports__.NESTED_ROUTES_DIR;
88
+ exports.SSG_PARAMS_EXPORT_NAME = __webpack_exports__.SSG_PARAMS_EXPORT_NAME;
86
89
  exports.TEMP_LOADERS_DIR = __webpack_exports__.TEMP_LOADERS_DIR;
87
90
  for(var __rspack_i in __webpack_exports__)if (-1 === [
88
91
  "ACTION_EXPORT_NAME",
@@ -96,6 +99,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
96
99
  "LOADER_EXPORT_NAME",
97
100
  "NESTED_ROUTE",
98
101
  "NESTED_ROUTES_DIR",
102
+ "SSG_PARAMS_EXPORT_NAME",
99
103
  "TEMP_LOADERS_DIR"
100
104
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
101
105
  Object.defineProperty(exports, '__esModule', {
@@ -56,7 +56,7 @@ const routerPlugin = ()=>({
56
56
  setup: (api)=>{
57
57
  const nestedRoutes = {};
58
58
  const nestedRoutesForServer = {};
59
- const { metaName } = api.getAppContext();
59
+ api.getAppContext();
60
60
  api.addCommand(({ program })=>{
61
61
  program.command('routes').description('generate routes inspect report').action(async ()=>{
62
62
  const { generateRoutesInspectReport } = await import("./code/inspect.js");
@@ -82,7 +82,7 @@ const routerPlugin = (userConfig = {})=>({
82
82
  if (!finalRouteConfig.routes && !createRoutes) return;
83
83
  const enableRsc = (0, index_js_namespaceObject.getGlobalEnableRsc)();
84
84
  if (enableRsc) await (0, external_rsc_router_js_namespaceObject.prepareRSCRoutes)(finalRouteConfig.routes);
85
- const { request, mode: ssrMode, nonce, loaderFailureMode = 'errorBoundary', baseUrl } = context.ssrContext;
85
+ const { mode: ssrMode, nonce, loaderFailureMode = 'errorBoundary', baseUrl } = context.ssrContext;
86
86
  const _basename = '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, basename) : baseUrl;
87
87
  const requestContext = (0, node_namespaceObject.createRequestContext)(context.ssrContext?.loaderContext);
88
88
  const hooks = api.getHooks();
@@ -136,7 +136,7 @@ const routerPlugin = (userConfig = {})=>({
136
136
  if (!finalRouteConfig) return App;
137
137
  const getRouteApp = ()=>{
138
138
  const enableRsc = (0, index_js_namespaceObject.getGlobalEnableRsc)();
139
- return (props)=>{
139
+ return ()=>{
140
140
  const context = (0, external_react_namespaceObject.useContext)(index_js_namespaceObject.InternalRuntimeContext);
141
141
  const { routerContext, ssrContext, routes } = context;
142
142
  const { nonce, mode, useJsonScript } = ssrContext;
@@ -111,6 +111,6 @@ const ssrPlugin = ()=>({
111
111
  }));
112
112
  }
113
113
  });
114
- const cli_ssr = ssrPlugin;
115
- export default cli_ssr;
114
+ const ssr = ssrPlugin;
115
+ export default ssr;
116
116
  export { ssrPlugin };
@@ -1,5 +1,5 @@
1
1
  function resolveSSRMode(params) {
2
- const { entry, config, appDirectory, nestedRoutesEntry } = params;
2
+ const { entry, config, nestedRoutesEntry } = params;
3
3
  const isSsgEnabled = config.output?.ssg || config.output?.ssgByEntries && (entry ? !!config.output.ssgByEntries[entry] : Object.keys(config.output.ssgByEntries).length > 0);
4
4
  if (isSsgEnabled) if (nestedRoutesEntry) return 'stream';
5
5
  else return 'string';
@@ -31,7 +31,7 @@ ${genRenderStatement({
31
31
  isNestedRouter
32
32
  })}`;
33
33
  };
34
- const entryForCSRWithRSC = ({ metaName, entryName, urlPath = '/', mountId = 'root', isNestedRouter })=>`
34
+ const entryForCSRWithRSC = ({ metaName, entryName, mountId = 'root', isNestedRouter })=>`
35
35
  import '@${metaName}/runtime/registry/${entryName}';
36
36
  import { render } from '@${metaName}/runtime/browser';
37
37
  import { createRoot } from '@${metaName}/runtime/react';
@@ -1,10 +1,10 @@
1
1
  const defaultMonitors = {
2
- counter (name) {},
2
+ counter () {},
3
3
  info: console.info,
4
4
  debug: console.debug,
5
5
  trace: console.trace,
6
6
  warn: console.warn,
7
7
  error: console.error,
8
- timing (name, dur) {}
8
+ timing () {}
9
9
  };
10
10
  export { defaultMonitors };
@@ -1,7 +1,7 @@
1
1
  const getResponseProxy = ()=>null;
2
- const setHeaders = (headers)=>{};
3
- const setStatus = (status)=>{};
4
- const redirect = (url, init)=>{
2
+ const setHeaders = (_headers)=>{};
3
+ const setStatus = (_status)=>{};
4
+ const redirect = (_url, _init)=>{
5
5
  console.warn("You should not use this API in the browser, please use the router's redirect or useNavigate method.");
6
6
  };
7
7
  export { getResponseProxy, redirect, setHeaders, setStatus };
@@ -1,3 +1,3 @@
1
1
  const getServerPayload = ()=>{};
2
- const setServerPayload = (payload)=>{};
2
+ const setServerPayload = (_payload)=>{};
3
3
  export { getServerPayload, setServerPayload };
@@ -1,7 +1,7 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { InternalRuntimeContext, RuntimeContext } from "../context/index.mjs";
3
3
  function wrapRuntimeContextProvider(App, contextValue) {
4
- const { isBrowser, initialData, routes, context, routeManifest, routerContext, unstable_getBlockNavState, ssrContext, _internalContext, _internalRouterBaseName, ...rest } = contextValue;
4
+ const { isBrowser, initialData, routes, context, routeManifest: _routeManifest, routerContext: _routerContext, unstable_getBlockNavState: _unstable_getBlockNavState, ssrContext: _ssrContext, _internalContext, _internalRouterBaseName, ...rest } = contextValue;
5
5
  const runtimeContextValue = {
6
6
  isBrowser,
7
7
  initialData,
@@ -121,7 +121,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
121
121
  }
122
122
  });
123
123
  return stream;
124
- } catch (e) {
124
+ } catch {
125
125
  const fallbackHtml = `${shellBefore}${shellAfter}`;
126
126
  const stream = getReadableStreamFromString(fallbackHtml);
127
127
  return stream;
@@ -40,7 +40,7 @@ class LoadableCollector {
40
40
  asyncChunks.push(...extractor.getChunkAssets([
41
41
  `async-${entryName}`
42
42
  ]));
43
- } catch (e) {}
43
+ } catch {}
44
44
  const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
45
45
  const scriptChunks = generateChunks(chunks, 'js');
46
46
  const styleChunks = generateChunks(chunks, 'css');
@@ -80,7 +80,7 @@ class LoadableCollector {
80
80
  chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
81
81
  }
82
82
  async emitStyleAssets(chunks) {
83
- const { template, chunkSet, config, entryName } = this.options;
83
+ const { template, chunkSet, config } = this.options;
84
84
  const { inlineStyles } = config;
85
85
  const atrributes = attributesToString(this.generateAttributes());
86
86
  const css = await Promise.all(chunks.filter((chunk)=>!hasStylesheetLink(template, chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { collectRouteComponentFiles, filterRoutesForServer, filterRoutesLoader, fs, getEntryOptions, isUseRsc, isUseSSRBundle, logger, markRoutes } from "@modern-js/utils";
2
+ import { collectRouteComponentFiles, filterRoutesForServer, filterRoutesLoader, fs, getEntryOptions, isSSGEntry, isUseRsc, isUseSSRBundle, logger, markRoutes } from "@modern-js/utils";
3
3
  import { cloneDeep } from "@modern-js/utils/lodash";
4
4
  import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME } from "../../../cli/constants.mjs";
5
5
  import { resolveSSRMode } from "../../../cli/ssr/mode.mjs";
@@ -105,7 +105,8 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
105
105
  const filtedRoutesForServer = filterRoutesForServer(routes);
106
106
  const routesForServerLoaderMatches = filterRoutesLoader(routes);
107
107
  const code = __rspack_external__templates_mjs_ab577925.routesForServer({
108
- routesForServerLoaderMatches
108
+ routesForServerLoaderMatches,
109
+ ssg: isSSGEntry(config, entryName, entrypoints)
109
110
  });
110
111
  await fs.ensureFile(routesServerFile);
111
112
  await fs.writeFile(routesServerFile, code);
@@ -1,6 +1,6 @@
1
1
  import { JS_EXTENSIONS, fs, normalizeToPosixPath } from "@modern-js/utils";
2
2
  import { NESTED_ROUTE } from "../constants.mjs";
3
- import { getPathWithoutExt, hasAction, replaceWithAlias } from "./utils.mjs";
3
+ import { getPathWithoutExt, hasAction, hasSsgParams, replaceWithAlias } from "./utils.mjs";
4
4
  import * as __rspack_external_path from "path";
5
5
  const conventionNames = Object.values(NESTED_ROUTE);
6
6
  const replaceDynamicPath = (routePath)=>routePath.replace(/\[(.*?)\]/g, ':$1');
@@ -84,12 +84,14 @@ const walk = async (options)=>{
84
84
  let pageClientData = '';
85
85
  let pageData = '';
86
86
  let pageAction = '';
87
+ let pageSsgParams = '';
87
88
  let splatLoaderFile = '';
88
89
  let splatRoute = null;
89
90
  let splatConfigFile = '';
90
91
  let splatClientData = '';
91
92
  let splatData = '';
92
93
  let splatAction = '';
94
+ let splatSsgParams = '';
93
95
  const items = await fs.readdir(dirname);
94
96
  for (const item of items){
95
97
  const itemPath = __rspack_external_path.join(dirname, item);
@@ -125,6 +127,7 @@ const walk = async (options)=>{
125
127
  if (itemWithoutExt === NESTED_ROUTE.PAGE_DATA_FILE) {
126
128
  pageData = itemPathWithAlias;
127
129
  if (await hasAction(itemPath)) pageAction = itemPathWithAlias;
130
+ if (await hasSsgParams(itemPath)) pageSsgParams = itemPathWithAlias;
128
131
  }
129
132
  if (itemWithoutExt === NESTED_ROUTE.PAGE_CONFIG_FILE) pageConfigFile = itemPathWithAlias;
130
133
  if (itemWithoutExt === NESTED_ROUTE.PAGE_FILE) {
@@ -136,6 +139,7 @@ const walk = async (options)=>{
136
139
  if (pageData) pageRoute.data = pageData;
137
140
  if (pageClientData) pageRoute.clientData = pageClientData;
138
141
  if (pageAction) pageRoute.action = pageAction;
142
+ if (pageSsgParams) pageRoute.ssgParams = pageSsgParams;
139
143
  route.children?.unshift(pageRoute);
140
144
  }
141
145
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) splatLoaderFile = itemPathWithAlias;
@@ -146,6 +150,7 @@ const walk = async (options)=>{
146
150
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_DATA_FILE) {
147
151
  splatData = itemPathWithAlias;
148
152
  if (await hasAction(itemPath)) splatAction = itemPathWithAlias;
153
+ if (await hasSsgParams(itemPath)) splatSsgParams = itemPathWithAlias;
149
154
  }
150
155
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_FILE) {
151
156
  splatRoute = createRoute({
@@ -158,6 +163,7 @@ const walk = async (options)=>{
158
163
  if (splatData) splatRoute.data = splatData;
159
164
  if (splatConfigFile) splatRoute.config = splatConfigFile;
160
165
  if (splatAction) splatRoute.action = splatAction;
166
+ if (splatSsgParams) splatRoute.ssgParams = splatSsgParams;
161
167
  route.children?.push(splatRoute);
162
168
  }
163
169
  if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) route.loading = itemPathWithAlias;