@modern-js/runtime 2.66.0 → 2.67.1

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 (53) hide show
  1. package/dist/cjs/cli/index.js +2 -7
  2. package/dist/cjs/cli/template.server.js +4 -10
  3. package/dist/cjs/router/cli/code/index.js +3 -4
  4. package/dist/cjs/router/cli/code/templates.js +3 -0
  5. package/dist/cjs/router/cli/entry.js +2 -2
  6. package/dist/cjs/router/cli/handler.js +6 -7
  7. package/dist/cjs/router/cli/index.js +12 -10
  8. package/dist/esm/cli/index.js +1 -5
  9. package/dist/esm/cli/template.server.js +4 -4
  10. package/dist/esm/router/cli/code/index.js +6 -7
  11. package/dist/esm/router/cli/code/templates.js +13 -6
  12. package/dist/esm/router/cli/entry.js +3 -4
  13. package/dist/esm/router/cli/handler.js +9 -11
  14. package/dist/esm/router/cli/index.js +13 -11
  15. package/dist/esm-node/cli/index.js +1 -5
  16. package/dist/esm-node/cli/template.server.js +4 -10
  17. package/dist/esm-node/router/cli/code/index.js +4 -5
  18. package/dist/esm-node/router/cli/code/templates.js +3 -0
  19. package/dist/esm-node/router/cli/entry.js +3 -3
  20. package/dist/esm-node/router/cli/handler.js +6 -7
  21. package/dist/esm-node/router/cli/index.js +13 -11
  22. package/dist/types/cli/index.d.ts +1 -2
  23. package/dist/types/common.d.ts +0 -6
  24. package/dist/types/config.d.ts +0 -2
  25. package/dist/types/core/context/runtime.d.ts +0 -3
  26. package/dist/types/index.d.ts +1 -2
  27. package/dist/types/router/cli/code/index.d.ts +1 -1
  28. package/dist/types/router/cli/entry.d.ts +1 -1
  29. package/dist/types/router/cli/handler.d.ts +3 -3
  30. package/package.json +12 -27
  31. package/types/index.d.ts +1 -13
  32. package/types/router.d.ts +0 -1
  33. package/dist/cjs/state/cli/index.js +0 -62
  34. package/dist/cjs/state/index.js +0 -43
  35. package/dist/cjs/state/plugins.js +0 -50
  36. package/dist/cjs/state/runtime/index.js +0 -42
  37. package/dist/cjs/state/runtime/plugin.js +0 -95
  38. package/dist/esm/state/cli/index.js +0 -41
  39. package/dist/esm/state/index.js +0 -7
  40. package/dist/esm/state/plugins.js +0 -19
  41. package/dist/esm/state/runtime/index.js +0 -6
  42. package/dist/esm/state/runtime/plugin.js +0 -93
  43. package/dist/esm-node/state/cli/index.js +0 -38
  44. package/dist/esm-node/state/index.js +0 -7
  45. package/dist/esm-node/state/plugins.js +0 -13
  46. package/dist/esm-node/state/runtime/index.js +0 -6
  47. package/dist/esm-node/state/runtime/plugin.js +0 -69
  48. package/dist/types/state/cli/index.d.ts +0 -3
  49. package/dist/types/state/index.d.ts +0 -3
  50. package/dist/types/state/plugins.d.ts +0 -4
  51. package/dist/types/state/runtime/index.d.ts +0 -3
  52. package/dist/types/state/runtime/plugin.d.ts +0 -11
  53. package/types/model.d.ts +0 -7
@@ -33,15 +33,13 @@ __export(cli_exports, {
33
33
  isRuntimeEntry: () => import_entry2.isRuntimeEntry,
34
34
  routerPlugin: () => import_cli2.routerPlugin,
35
35
  runtimePlugin: () => runtimePlugin,
36
- ssrPlugin: () => import_ssr.ssrPlugin,
37
- statePlugin: () => import_cli3.statePlugin
36
+ ssrPlugin: () => import_ssr.ssrPlugin
38
37
  });
39
38
  module.exports = __toCommonJS(cli_exports);
40
39
  var import_path = __toESM(require("path"));
41
40
  var import_utils = require("@modern-js/utils");
42
41
  var import_cli = require("../document/cli");
43
42
  var import_cli2 = require("../router/cli");
44
- var import_cli3 = require("../state/cli");
45
43
  var import_alias = require("./alias");
46
44
  var import_code = require("./code");
47
45
  var import_constants = require("./constants");
@@ -61,7 +59,6 @@ const runtimePlugin = (params) => ({
61
59
  usePlugins: (params === null || params === void 0 ? void 0 : params.plugins) || [
62
60
  (0, import_ssr.ssrPlugin)(),
63
61
  (0, import_cli2.routerPlugin)(),
64
- (0, import_cli3.statePlugin)(),
65
62
  (0, import_cli.documentPlugin)()
66
63
  ],
67
64
  setup: (api) => {
@@ -167,7 +164,6 @@ const runtimePlugin = (params) => ({
167
164
  });
168
165
  api.onBeforeRestart(() => {
169
166
  (0, import_utils.cleanRequireCache)([
170
- require.resolve("../state/cli"),
171
167
  require.resolve("../router/cli"),
172
168
  require.resolve("./ssr")
173
169
  ]);
@@ -181,6 +177,5 @@ var cli_default = runtimePlugin;
181
177
  isRuntimeEntry,
182
178
  routerPlugin,
183
179
  runtimePlugin,
184
- ssrPlugin,
185
- statePlugin
180
+ ssrPlugin
186
181
  });
@@ -35,8 +35,7 @@ const handleRequest = async (request, ServerRoot, options) => {
35
35
 
36
36
  return new Response(body, {
37
37
  headers: {
38
- 'content-type': 'text/html; charset=utf-8',
39
- #headers
38
+ 'content-type': 'text/html; charset=utf-8'
40
39
  },
41
40
  })
42
41
  };
@@ -65,8 +64,7 @@ const handleRequest = async (request, ServerRoot, options) => {
65
64
 
66
65
  return new Response(body, {
67
66
  headers: {
68
- 'content-type': 'text/html; charset=utf-8',
69
- #headers
67
+ 'content-type': 'text/html; charset=utf-8'
70
68
  },
71
69
  })
72
70
  };
@@ -97,11 +95,7 @@ const entryForCSRWithRSC = ({ metaName }) => {
97
95
  clientManifest,
98
96
  })
99
97
 
100
- const response = new Response(stream, {
101
- headers: {
102
- 'Transfer-Encoding': 'chunked',
103
- },
104
- });
98
+ const response = new Response(stream);
105
99
  return response
106
100
  }
107
101
  `;
@@ -123,7 +117,7 @@ function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, inter
123
117
  }
124
118
  function transformServerEntry(source, options) {
125
119
  const { metaName = "modern-js", mode } = options;
126
- const output = source.replace(/#metaName/g, metaName).replace(/#render/g, mode === "string" ? "renderString" : "renderStreaming").replace(/#headers/g, mode === "string" ? "" : `'transfer-encoding': 'chunked',`);
120
+ const output = source.replace(/#metaName/g, metaName).replace(/#render/g, mode === "string" ? "renderString" : "renderStreaming");
127
121
  return output;
128
122
  }
129
123
  // Annotate the CommonJS export names for ESM import in node:
@@ -42,11 +42,10 @@ var import_getClientRoutes = require("./getClientRoutes");
42
42
  var import_nestedRoutes = require("./nestedRoutes");
43
43
  var templates = __toESM(require("./templates"));
44
44
  var import_utils3 = require("./utils");
45
- const generateCode = async (appContext, config, entrypoints, api) => {
45
+ const generateCode = async (appContext, config, entrypoints, api, isRouterV5) => {
46
46
  const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
47
47
  const hooks = api.getHooks();
48
- const isV5 = (0, import_utils.isRouterV5)(config);
49
- const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
48
+ const getRoutes = isRouterV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
50
49
  const oldVersion = typeof (config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
51
50
  await Promise.all(entrypoints.map(generateEntryCode));
52
51
  async function generateEntryCode(entrypoint) {
@@ -66,7 +65,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
66
65
  internalDirAlias
67
66
  });
68
67
  }
69
- if (!isV5 && entrypoint.nestedRoutesEntry) {
68
+ if (!isRouterV5 && entrypoint.nestedRoutesEntry) {
70
69
  nestedRoutes = await (0, import_nestedRoutes.walk)(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
71
70
  name: internalSrcAlias,
72
71
  basename: srcDirectory
@@ -430,6 +430,9 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
430
430
  } else {
431
431
  imports.push(`let appInit;`);
432
432
  }
433
+ } else {
434
+ imports.push(`let appConfig;`);
435
+ imports.push(`let appInit;`);
433
436
  }
434
437
  } else {
435
438
  imports.push(`let appConfig;`);
@@ -49,14 +49,14 @@ const isRouteEntry = (dir) => {
49
49
  }
50
50
  return false;
51
51
  };
52
- const modifyEntrypoints = (entrypoints, config = {}) => {
52
+ const modifyEntrypoints = (entrypoints, isRouterV5) => {
53
53
  return entrypoints.map((entrypoint) => {
54
54
  if (!entrypoint.isAutoMount) {
55
55
  return entrypoint;
56
56
  }
57
57
  if (entrypoint === null || entrypoint === void 0 ? void 0 : entrypoint.isCustomSourceEntry) {
58
58
  if (entrypoint.fileSystemRoutes) {
59
- if ((0, import_utils.isRouterV5)(config)) {
59
+ if (isRouterV5) {
60
60
  throw Error("Custom entries with conventional routing not support use react router v5!");
61
61
  }
62
62
  entrypoint.nestedRoutesEntry = entrypoint.entry;
@@ -39,17 +39,16 @@ var templates = __toESM(require("./code/templates"));
39
39
  var import_utils = require("./code/utils");
40
40
  var import_entry = require("./entry");
41
41
  let originEntrypoints = [];
42
- async function handleModifyEntrypoints(api, entrypoints) {
43
- const config = api.getNormalizedConfig();
44
- return (0, import_entry.modifyEntrypoints)(entrypoints, config);
42
+ async function handleModifyEntrypoints(isRouterV5, entrypoints) {
43
+ return (0, import_entry.modifyEntrypoints)(entrypoints, isRouterV5);
45
44
  }
46
- async function handleGeneratorEntryCode(api, entrypoints) {
45
+ async function handleGeneratorEntryCode(api, entrypoints, isRouterV5) {
47
46
  const appContext = api.getAppContext();
48
47
  const { internalDirectory } = appContext;
49
48
  const resolvedConfig = api.getNormalizedConfig();
50
49
  const { generatorRegisterCode, generateCode } = await Promise.resolve().then(() => __toESM(require("./code")));
51
50
  originEntrypoints = (0, import_lodash.cloneDeep)(entrypoints);
52
- await generateCode(appContext, resolvedConfig, entrypoints, api);
51
+ await generateCode(appContext, resolvedConfig, entrypoints, api, isRouterV5);
53
52
  await Promise.all(entrypoints.map(async (entrypoint) => {
54
53
  if (entrypoint.nestedRoutesEntry || entrypoint.pageRoutesEntry) {
55
54
  var _entrypoint_fileSystemRoutes;
@@ -65,7 +64,7 @@ async function handleGeneratorEntryCode(api, entrypoints) {
65
64
  }));
66
65
  return entrypoints;
67
66
  }
68
- async function handleFileChange(api, e) {
67
+ async function handleFileChange(api, isRouterV5, e) {
69
68
  const appContext = api.getAppContext();
70
69
  const { appDirectory, entrypoints } = appContext;
71
70
  const { filename, eventType } = e;
@@ -78,7 +77,7 @@ async function handleFileChange(api, e) {
78
77
  const resolvedConfig = api.getNormalizedConfig();
79
78
  const { generateCode } = await Promise.resolve().then(() => __toESM(require("./code")));
80
79
  const entrypoints2 = (0, import_lodash.cloneDeep)(originEntrypoints);
81
- await generateCode(appContext, resolvedConfig, entrypoints2, api);
80
+ await generateCode(appContext, resolvedConfig, entrypoints2, api, isRouterV5);
82
81
  }
83
82
  }
84
83
  // Annotate the CommonJS export names for ESM import in node:
@@ -50,16 +50,19 @@ const routerPlugin = () => ({
50
50
  setup: (api) => {
51
51
  const nestedRoutes = {};
52
52
  const nestedRoutesForServer = {};
53
+ const { metaName } = api.getAppContext();
54
+ const isRouterV5 = api.isPluginExists(`@${metaName}/plugin-router-v5`);
53
55
  api._internalRuntimePlugins(({ entrypoint, plugins }) => {
54
56
  var _getEntryOptions;
55
- const { packageName, serverRoutes, metaName } = api.getAppContext();
57
+ const { nestedRoutesEntry, pageRoutesEntry } = entrypoint;
58
+ const { packageName, serverRoutes, metaName: metaName2 } = api.getAppContext();
56
59
  const serverBase = serverRoutes.filter((route) => route.entryName === entrypoint.entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
57
60
  const userConfig = api.getNormalizedConfig();
58
61
  const routerConfig = (_getEntryOptions = (0, import_utils.getEntryOptions)(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
59
- if (routerConfig && !(0, import_utils.isRouterV5)(userConfig)) {
62
+ if ((nestedRoutesEntry || pageRoutesEntry) && !isRouterV5) {
60
63
  plugins.push({
61
64
  name: "router",
62
- path: `@${metaName}/runtime/router`,
65
+ path: `@${metaName2}/runtime/router`,
63
66
  config: typeof routerConfig === "boolean" ? {
64
67
  serverBase
65
68
  } : {
@@ -94,24 +97,23 @@ const routerPlugin = () => ({
94
97
  };
95
98
  });
96
99
  api.modifyEntrypoints(async ({ entrypoints }) => {
97
- const newEntryPoints = await (0, import_handler.handleModifyEntrypoints)(api, entrypoints);
100
+ const newEntryPoints = await (0, import_handler.handleModifyEntrypoints)(isRouterV5, entrypoints);
98
101
  return {
99
102
  entrypoints: newEntryPoints
100
103
  };
101
104
  });
102
105
  api.generateEntryCode(async ({ entrypoints }) => {
103
- await (0, import_handler.handleGeneratorEntryCode)(api, entrypoints);
106
+ await (0, import_handler.handleGeneratorEntryCode)(api, entrypoints, isRouterV5);
104
107
  });
105
108
  api.addRuntimeExports(() => {
106
- const userConfig = api.useResolvedConfigContext();
107
- const { internalDirectory, metaName } = api.useAppContext();
109
+ const { internalDirectory, metaName: metaName2 } = api.useAppContext();
108
110
  const pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "plugins");
109
- if (!(0, import_utils.isRouterV5)(userConfig)) {
110
- pluginsExportsUtils.addExport(`export { default as router } from '@${metaName}/runtime/router'`);
111
+ if (!isRouterV5) {
112
+ pluginsExportsUtils.addExport(`export { default as router } from '@${metaName2}/runtime/router'`);
111
113
  }
112
114
  });
113
115
  api.onFileChanged(async (e) => {
114
- await (0, import_handler.handleFileChange)(api, e);
116
+ await (0, import_handler.handleFileChange)(api, isRouterV5, e);
115
117
  });
116
118
  api.modifyFileSystemRoutes(({ entrypoint, routes }) => {
117
119
  nestedRoutes[entrypoint.entryName] = routes;
@@ -5,7 +5,6 @@ import path from "path";
5
5
  import { isReact18 as checkIsReact18, cleanRequireCache, createRuntimeExportsUtils } from "@modern-js/utils";
6
6
  import { documentPlugin } from "../document/cli";
7
7
  import { routerPlugin } from "../router/cli";
8
- import { statePlugin } from "../state/cli";
9
8
  import { builderPluginAlias } from "./alias";
10
9
  import { generateCode } from "./code";
11
10
  import { ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME } from "./constants";
@@ -26,7 +25,6 @@ var runtimePlugin = function(params) {
26
25
  usePlugins: (params === null || params === void 0 ? void 0 : params.plugins) || [
27
26
  ssrPlugin(),
28
27
  routerPlugin(),
29
- statePlugin(),
30
28
  documentPlugin()
31
29
  ],
32
30
  setup: function(api) {
@@ -152,7 +150,6 @@ var runtimePlugin = function(params) {
152
150
  });
153
151
  api.onBeforeRestart(function() {
154
152
  cleanRequireCache([
155
- require.resolve("../state/cli"),
156
153
  require.resolve("../router/cli"),
157
154
  require.resolve("./ssr")
158
155
  ]);
@@ -167,6 +164,5 @@ export {
167
164
  isRuntimeEntry2 as isRuntimeEntry,
168
165
  routerPlugin,
169
166
  runtimePlugin,
170
- ssrPlugin,
171
- statePlugin
167
+ ssrPlugin
172
168
  };
@@ -1,13 +1,13 @@
1
1
  import { formatImportPath } from "@modern-js/utils";
2
- var SERVER_ENTRY = "\nimport {\n #render,\n createRequestHandler,\n} from '@#metaName/runtime/ssr/server';\n\nconst handleRequest = async (request, ServerRoot, options) => {\n\n const body = await #render(request, <ServerRoot />, options);\n\n return new Response(body, {\n headers: {\n 'content-type': 'text/html; charset=utf-8',\n #headers\n },\n })\n};\n\nexport const requestHandler = createRequestHandler(handleRequest);\n";
3
- var SERVER_ENTRY_RSC = "\nimport {\n renderStreaming,\n createRequestHandler,\n} from '@#metaName/runtime/ssr/server';\nimport { RSCServerSlot } from '@#metaName/runtime/rsc/client';\nexport { handleAction } from '@#metaName/runtime/rsc/server';\n\nconst handleRequest = async (request, ServerRoot, options) => {\n\n const body = await renderStreaming(request,\n <ServerRoot>\n <RSCServerSlot />\n </ServerRoot>,\n {\n ...options,\n rscRoot: <options.RSCRoot />,\n },\n );\n\n return new Response(body, {\n headers: {\n 'content-type': 'text/html; charset=utf-8',\n #headers\n },\n })\n};\n\nexport const requestHandler = createRequestHandler(handleRequest, {\n enableRsc: true,\n});\n";
2
+ var SERVER_ENTRY = "\nimport {\n #render,\n createRequestHandler,\n} from '@#metaName/runtime/ssr/server';\n\nconst handleRequest = async (request, ServerRoot, options) => {\n\n const body = await #render(request, <ServerRoot />, options);\n\n return new Response(body, {\n headers: {\n 'content-type': 'text/html; charset=utf-8'\n },\n })\n};\n\nexport const requestHandler = createRequestHandler(handleRequest);\n";
3
+ var SERVER_ENTRY_RSC = "\nimport {\n renderStreaming,\n createRequestHandler,\n} from '@#metaName/runtime/ssr/server';\nimport { RSCServerSlot } from '@#metaName/runtime/rsc/client';\nexport { handleAction } from '@#metaName/runtime/rsc/server';\n\nconst handleRequest = async (request, ServerRoot, options) => {\n\n const body = await renderStreaming(request,\n <ServerRoot>\n <RSCServerSlot />\n </ServerRoot>,\n {\n ...options,\n rscRoot: <options.RSCRoot />,\n },\n );\n\n return new Response(body, {\n headers: {\n 'content-type': 'text/html; charset=utf-8'\n },\n })\n};\n\nexport const requestHandler = createRequestHandler(handleRequest, {\n enableRsc: true,\n});\n";
4
4
  var serverIndex = function(options) {
5
5
  var _options_metaName = options.metaName, metaName = _options_metaName === void 0 ? "modern-js" : _options_metaName, entryName = options.entryName;
6
6
  return "\n import '@".concat(metaName, "/runtime/registry/").concat(entryName, "';\n ").concat(genHandlerCode(options), "\n ");
7
7
  };
8
8
  var entryForCSRWithRSC = function(param) {
9
9
  var metaName = param.metaName;
10
- return "\n import App from './AppProxy';\n import { renderRsc } from '@".concat(metaName, "/runtime/rsc/server'\n export { handleAction } from '@").concat(metaName, "/runtime/rsc/server';\n\n\n export const rscRequestHandler = ({\n clientManifest\n }) => {\n const stream = renderRsc({\n element: <App/>,\n clientManifest,\n })\n\n const response = new Response(stream, {\n headers: {\n 'Transfer-Encoding': 'chunked',\n },\n });\n return response\n }\n");
10
+ return "\n import App from './AppProxy';\n import { renderRsc } from '@".concat(metaName, "/runtime/rsc/server'\n export { handleAction } from '@").concat(metaName, "/runtime/rsc/server';\n\n\n export const rscRequestHandler = ({\n clientManifest\n }) => {\n const stream = renderRsc({\n element: <App/>,\n clientManifest,\n })\n\n const response = new Response(stream);\n return response\n }\n");
11
11
  };
12
12
  function genHandlerCode(param) {
13
13
  var mode = param.mode, metaName = param.metaName, customServerEntry = param.customServerEntry, srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, enableRsc = param.enableRsc;
@@ -25,7 +25,7 @@ function genHandlerCode(param) {
25
25
  }
26
26
  function transformServerEntry(source, options) {
27
27
  var _options_metaName = options.metaName, metaName = _options_metaName === void 0 ? "modern-js" : _options_metaName, mode = options.mode;
28
- var output = source.replace(/#metaName/g, metaName).replace(/#render/g, mode === "string" ? "renderString" : "renderStreaming").replace(/#headers/g, mode === "string" ? "" : "'transfer-encoding': 'chunked',");
28
+ var output = source.replace(/#metaName/g, metaName).replace(/#render/g, mode === "string" ? "renderString" : "renderStreaming");
29
29
  return output;
30
30
  }
31
31
  export {
@@ -2,7 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _type_of } from "@swc/helpers/_/_type_of";
3
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  import path from "path";
5
- import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
5
+ import { fs, getEntryOptions, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
6
6
  import { filterRoutesForServer, filterRoutesLoader, markRoutes } from "@modern-js/utils";
7
7
  import { cloneDeep } from "@modern-js/utils/lodash";
8
8
  import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME } from "../../../cli/constants";
@@ -12,8 +12,8 @@ import { walk } from "./nestedRoutes";
12
12
  import * as templates from "./templates";
13
13
  import { getServerCombinedModueFile, getServerLoadersFile } from "./utils";
14
14
  var generateCode = function() {
15
- var _ref = _async_to_generator(function(appContext, config, entrypoints, api) {
16
- var internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hooks, isV5, getRoutes, oldVersion;
15
+ var _ref = _async_to_generator(function(appContext, config, entrypoints, api, isRouterV5) {
16
+ var internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hooks, getRoutes, oldVersion;
17
17
  function generateEntryCode(entrypoint) {
18
18
  return _generateEntryCode.apply(this, arguments);
19
19
  }
@@ -46,7 +46,7 @@ var generateCode = function() {
46
46
  internalDirAlias
47
47
  });
48
48
  }
49
- if (!(!isV5 && entrypoint.nestedRoutesEntry))
49
+ if (!(!isRouterV5 && entrypoint.nestedRoutesEntry))
50
50
  return [
51
51
  3,
52
52
  2
@@ -222,8 +222,7 @@ var generateCode = function() {
222
222
  case 0:
223
223
  internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
224
224
  hooks = api.getHooks();
225
- isV5 = isRouterV5(config);
226
- getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
225
+ getRoutes = isRouterV5 ? getClientRoutesLegacy : getClientRoutes;
227
226
  oldVersion = _type_of(config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
228
227
  return [
229
228
  4,
@@ -237,7 +236,7 @@ var generateCode = function() {
237
236
  }
238
237
  });
239
238
  });
240
- return function generateCode2(appContext, config, entrypoints, api) {
239
+ return function generateCode2(appContext, config, entrypoints, api, isRouterV5) {
241
240
  return _ref.apply(this, arguments);
242
241
  };
243
242
  }();
@@ -444,7 +444,7 @@ var runtimeGlobalContext = function() {
444
444
  if (!nestedRoutesEntry)
445
445
  return [
446
446
  3,
447
- 4
447
+ 5
448
448
  ];
449
449
  rootLayoutPath = path.join(nestedRoutesEntry, "layout");
450
450
  rootLayoutFile = findExists([
@@ -496,17 +496,24 @@ var runtimeGlobalContext = function() {
496
496
  } else {
497
497
  imports.push("let appInit;");
498
498
  }
499
- _state.label = 3;
500
- case 3:
501
499
  return [
502
500
  3,
503
- 5
501
+ 4
504
502
  ];
505
- case 4:
503
+ case 3:
506
504
  imports.push("let appConfig;");
507
505
  imports.push("let appInit;");
508
- _state.label = 5;
506
+ _state.label = 4;
507
+ case 4:
508
+ return [
509
+ 3,
510
+ 6
511
+ ];
509
512
  case 5:
513
+ imports.push("let appConfig;");
514
+ imports.push("let appInit;");
515
+ _state.label = 6;
516
+ case 6:
510
517
  if (globalApp) {
511
518
  imports.push("import layoutApp from '".concat(formatImportPath(globalApp.replace(srcDirectory, internalSrcAlias)), "';"));
512
519
  } else {
@@ -1,7 +1,7 @@
1
1
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
2
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
3
  import path from "path";
4
- import { fs, JS_EXTENSIONS, findExists, isRouterV5 } from "@modern-js/utils";
4
+ import { fs, JS_EXTENSIONS, findExists } from "@modern-js/utils";
5
5
  import { hasApp } from "../../cli/entry";
6
6
  import { FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, NESTED_ROUTES_DIR, PAGES_DIR_NAME } from "./constants";
7
7
  var hasPages = function(dir) {
@@ -19,15 +19,14 @@ var isRouteEntry = function(dir) {
19
19
  }
20
20
  return false;
21
21
  };
22
- var modifyEntrypoints = function(entrypoints) {
23
- var config = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
22
+ var modifyEntrypoints = function(entrypoints, isRouterV5) {
24
23
  return entrypoints.map(function(entrypoint) {
25
24
  if (!entrypoint.isAutoMount) {
26
25
  return entrypoint;
27
26
  }
28
27
  if (entrypoint === null || entrypoint === void 0 ? void 0 : entrypoint.isCustomSourceEntry) {
29
28
  if (entrypoint.fileSystemRoutes) {
30
- if (isRouterV5(config)) {
29
+ if (isRouterV5) {
31
30
  throw Error("Custom entries with conventional routing not support use react router v5!");
32
31
  }
33
32
  entrypoint.nestedRoutesEntry = entrypoint.entry;
@@ -6,27 +6,25 @@ import * as templates from "./code/templates";
6
6
  import { isPageComponentFile } from "./code/utils";
7
7
  import { modifyEntrypoints } from "./entry";
8
8
  var originEntrypoints = [];
9
- function handleModifyEntrypoints(api, entrypoints) {
9
+ function handleModifyEntrypoints(isRouterV5, entrypoints) {
10
10
  return _handleModifyEntrypoints.apply(this, arguments);
11
11
  }
12
12
  function _handleModifyEntrypoints() {
13
- _handleModifyEntrypoints = _async_to_generator(function(api, entrypoints) {
14
- var config;
13
+ _handleModifyEntrypoints = _async_to_generator(function(isRouterV5, entrypoints) {
15
14
  return _ts_generator(this, function(_state) {
16
- config = api.getNormalizedConfig();
17
15
  return [
18
16
  2,
19
- modifyEntrypoints(entrypoints, config)
17
+ modifyEntrypoints(entrypoints, isRouterV5)
20
18
  ];
21
19
  });
22
20
  });
23
21
  return _handleModifyEntrypoints.apply(this, arguments);
24
22
  }
25
- function handleGeneratorEntryCode(api, entrypoints) {
23
+ function handleGeneratorEntryCode(api, entrypoints, isRouterV5) {
26
24
  return _handleGeneratorEntryCode.apply(this, arguments);
27
25
  }
28
26
  function _handleGeneratorEntryCode() {
29
- _handleGeneratorEntryCode = _async_to_generator(function(api, entrypoints) {
27
+ _handleGeneratorEntryCode = _async_to_generator(function(api, entrypoints, isRouterV5) {
30
28
  var appContext, internalDirectory, resolvedConfig, _ref, generatorRegisterCode, generateCode;
31
29
  return _ts_generator(this, function(_state) {
32
30
  switch (_state.label) {
@@ -43,7 +41,7 @@ function _handleGeneratorEntryCode() {
43
41
  originEntrypoints = cloneDeep(entrypoints);
44
42
  return [
45
43
  4,
46
- generateCode(appContext, resolvedConfig, entrypoints, api)
44
+ generateCode(appContext, resolvedConfig, entrypoints, api, isRouterV5)
47
45
  ];
48
46
  case 2:
49
47
  _state.sent();
@@ -103,11 +101,11 @@ function _handleGeneratorEntryCode() {
103
101
  });
104
102
  return _handleGeneratorEntryCode.apply(this, arguments);
105
103
  }
106
- function handleFileChange(api, e) {
104
+ function handleFileChange(api, isRouterV5, e) {
107
105
  return _handleFileChange.apply(this, arguments);
108
106
  }
109
107
  function _handleFileChange() {
110
- _handleFileChange = _async_to_generator(function(api, e) {
108
+ _handleFileChange = _async_to_generator(function(api, isRouterV5, e) {
111
109
  var appContext, appDirectory, entrypoints, filename, eventType, nestedRouteEntries, pagesDir, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, generateCode, entrypoints1;
112
110
  return _ts_generator(this, function(_state) {
113
111
  switch (_state.label) {
@@ -145,7 +143,7 @@ function _handleFileChange() {
145
143
  entrypoints1 = cloneDeep(originEntrypoints);
146
144
  return [
147
145
  4,
148
- generateCode(appContext, resolvedConfig, entrypoints1, api)
146
+ generateCode(appContext, resolvedConfig, entrypoints1, api, isRouterV5)
149
147
  ];
150
148
  case 2:
151
149
  _state.sent();
@@ -3,7 +3,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
3
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import path from "node:path";
6
- import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, getEntryOptions, isRouterV5 as isV5 } from "@modern-js/utils";
6
+ import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, getEntryOptions } from "@modern-js/utils";
7
7
  import { filterRoutesForServer } from "@modern-js/utils";
8
8
  import { isRouteEntry } from "./entry";
9
9
  import { handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints } from "./handler";
@@ -18,10 +18,13 @@ var routerPlugin = function() {
18
18
  setup: function(api) {
19
19
  var nestedRoutes = {};
20
20
  var nestedRoutesForServer = {};
21
+ var metaName = api.getAppContext().metaName;
22
+ var isRouterV5 = api.isPluginExists("@".concat(metaName, "/plugin-router-v5"));
21
23
  api._internalRuntimePlugins(function(param) {
22
24
  var entrypoint = param.entrypoint, plugins = param.plugins;
23
25
  var _getEntryOptions;
24
- var _api_getAppContext = api.getAppContext(), packageName = _api_getAppContext.packageName, serverRoutes = _api_getAppContext.serverRoutes, metaName = _api_getAppContext.metaName;
26
+ var nestedRoutesEntry = entrypoint.nestedRoutesEntry, pageRoutesEntry = entrypoint.pageRoutesEntry;
27
+ var _api_getAppContext = api.getAppContext(), packageName = _api_getAppContext.packageName, serverRoutes = _api_getAppContext.serverRoutes, metaName2 = _api_getAppContext.metaName;
25
28
  var serverBase = serverRoutes.filter(function(route) {
26
29
  return route.entryName === entrypoint.entryName;
27
30
  }).map(function(route) {
@@ -31,10 +34,10 @@ var routerPlugin = function() {
31
34
  });
32
35
  var userConfig = api.getNormalizedConfig();
33
36
  var routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
34
- if (routerConfig && !isV5(userConfig)) {
37
+ if ((nestedRoutesEntry || pageRoutesEntry) && !isRouterV5) {
35
38
  plugins.push({
36
39
  name: "router",
37
- path: "@".concat(metaName, "/runtime/router"),
40
+ path: "@".concat(metaName2, "/runtime/router"),
38
41
  config: typeof routerConfig === "boolean" ? {
39
42
  serverBase
40
43
  } : _object_spread_props(_object_spread({}, routerConfig), {
@@ -77,7 +80,7 @@ var routerPlugin = function() {
77
80
  entrypoints = param.entrypoints;
78
81
  return [
79
82
  4,
80
- handleModifyEntrypoints(api, entrypoints)
83
+ handleModifyEntrypoints(isRouterV5, entrypoints)
81
84
  ];
82
85
  case 1:
83
86
  newEntryPoints = _state.sent();
@@ -103,7 +106,7 @@ var routerPlugin = function() {
103
106
  entrypoints = param.entrypoints;
104
107
  return [
105
108
  4,
106
- handleGeneratorEntryCode(api, entrypoints)
109
+ handleGeneratorEntryCode(api, entrypoints, isRouterV5)
107
110
  ];
108
111
  case 1:
109
112
  _state.sent();
@@ -118,11 +121,10 @@ var routerPlugin = function() {
118
121
  };
119
122
  }());
120
123
  api.addRuntimeExports(function() {
121
- var userConfig = api.useResolvedConfigContext();
122
- var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
124
+ var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName2 = _api_useAppContext.metaName;
123
125
  var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
124
- if (!isV5(userConfig)) {
125
- pluginsExportsUtils.addExport("export { default as router } from '@".concat(metaName, "/runtime/router'"));
126
+ if (!isRouterV5) {
127
+ pluginsExportsUtils.addExport("export { default as router } from '@".concat(metaName2, "/runtime/router'"));
126
128
  }
127
129
  });
128
130
  api.onFileChanged(function() {
@@ -132,7 +134,7 @@ var routerPlugin = function() {
132
134
  case 0:
133
135
  return [
134
136
  4,
135
- handleFileChange(api, e)
137
+ handleFileChange(api, isRouterV5, e)
136
138
  ];
137
139
  case 1:
138
140
  _state.sent();
@@ -2,7 +2,6 @@ import path from "path";
2
2
  import { isReact18 as checkIsReact18, cleanRequireCache, createRuntimeExportsUtils } from "@modern-js/utils";
3
3
  import { documentPlugin } from "../document/cli";
4
4
  import { routerPlugin } from "../router/cli";
5
- import { statePlugin } from "../state/cli";
6
5
  import { builderPluginAlias } from "./alias";
7
6
  import { generateCode } from "./code";
8
7
  import { ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME } from "./constants";
@@ -22,7 +21,6 @@ const runtimePlugin = (params) => ({
22
21
  usePlugins: (params === null || params === void 0 ? void 0 : params.plugins) || [
23
22
  ssrPlugin(),
24
23
  routerPlugin(),
25
- statePlugin(),
26
24
  documentPlugin()
27
25
  ],
28
26
  setup: (api) => {
@@ -128,7 +126,6 @@ const runtimePlugin = (params) => ({
128
126
  });
129
127
  api.onBeforeRestart(() => {
130
128
  cleanRequireCache([
131
- require.resolve("../state/cli"),
132
129
  require.resolve("../router/cli"),
133
130
  require.resolve("./ssr")
134
131
  ]);
@@ -142,6 +139,5 @@ export {
142
139
  isRuntimeEntry2 as isRuntimeEntry,
143
140
  routerPlugin,
144
141
  runtimePlugin,
145
- ssrPlugin,
146
- statePlugin
142
+ ssrPlugin
147
143
  };
@@ -11,8 +11,7 @@ const handleRequest = async (request, ServerRoot, options) => {
11
11
 
12
12
  return new Response(body, {
13
13
  headers: {
14
- 'content-type': 'text/html; charset=utf-8',
15
- #headers
14
+ 'content-type': 'text/html; charset=utf-8'
16
15
  },
17
16
  })
18
17
  };
@@ -41,8 +40,7 @@ const handleRequest = async (request, ServerRoot, options) => {
41
40
 
42
41
  return new Response(body, {
43
42
  headers: {
44
- 'content-type': 'text/html; charset=utf-8',
45
- #headers
43
+ 'content-type': 'text/html; charset=utf-8'
46
44
  },
47
45
  })
48
46
  };
@@ -73,11 +71,7 @@ const entryForCSRWithRSC = ({ metaName }) => {
73
71
  clientManifest,
74
72
  })
75
73
 
76
- const response = new Response(stream, {
77
- headers: {
78
- 'Transfer-Encoding': 'chunked',
79
- },
80
- });
74
+ const response = new Response(stream);
81
75
  return response
82
76
  }
83
77
  `;
@@ -99,7 +93,7 @@ function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, inter
99
93
  }
100
94
  function transformServerEntry(source, options) {
101
95
  const { metaName = "modern-js", mode } = options;
102
- const output = source.replace(/#metaName/g, metaName).replace(/#render/g, mode === "string" ? "renderString" : "renderStreaming").replace(/#headers/g, mode === "string" ? "" : `'transfer-encoding': 'chunked',`);
96
+ const output = source.replace(/#metaName/g, metaName).replace(/#render/g, mode === "string" ? "renderString" : "renderStreaming");
103
97
  return output;
104
98
  }
105
99
  export {