@modern-js/runtime 2.63.2 → 2.63.4

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 (42) hide show
  1. package/dist/cjs/cli/code.js +2 -2
  2. package/dist/cjs/cli/index.js +102 -108
  3. package/dist/cjs/cli/ssr/index.js +49 -52
  4. package/dist/cjs/core/server/string/loadable.js +13 -3
  5. package/dist/cjs/document/cli/index.js +32 -34
  6. package/dist/cjs/router/cli/code/index.js +5 -5
  7. package/dist/cjs/router/cli/handler.js +6 -6
  8. package/dist/cjs/router/cli/index.js +76 -78
  9. package/dist/cjs/router/runtime/plugin.js +1 -4
  10. package/dist/cjs/state/cli/index.js +22 -24
  11. package/dist/esm/cli/code.js +3 -3
  12. package/dist/esm/cli/index.js +120 -130
  13. package/dist/esm/cli/ssr/index.js +50 -53
  14. package/dist/esm/core/server/string/loadable.js +17 -5
  15. package/dist/esm/document/cli/index.js +28 -30
  16. package/dist/esm/router/cli/code/index.js +8 -8
  17. package/dist/esm/router/cli/handler.js +6 -6
  18. package/dist/esm/router/cli/index.js +161 -157
  19. package/dist/esm/router/runtime/plugin.js +1 -4
  20. package/dist/esm/state/cli/index.js +23 -25
  21. package/dist/esm-node/cli/code.js +2 -2
  22. package/dist/esm-node/cli/index.js +102 -108
  23. package/dist/esm-node/cli/ssr/index.js +49 -52
  24. package/dist/esm-node/core/server/string/loadable.js +13 -3
  25. package/dist/esm-node/document/cli/index.js +32 -34
  26. package/dist/esm-node/router/cli/code/index.js +5 -5
  27. package/dist/esm-node/router/cli/handler.js +6 -6
  28. package/dist/esm-node/router/cli/index.js +76 -78
  29. package/dist/esm-node/router/runtime/plugin.js +1 -4
  30. package/dist/esm-node/state/cli/index.js +22 -24
  31. package/dist/types/cli/code.d.ts +2 -9
  32. package/dist/types/cli/index.d.ts +3 -3
  33. package/dist/types/cli/ssr/index.d.ts +2 -2
  34. package/dist/types/core/server/string/loadable.d.ts +3 -2
  35. package/dist/types/document/cli/index.d.ts +2 -2
  36. package/dist/types/router/cli/code/index.d.ts +3 -3
  37. package/dist/types/router/cli/code/templates.d.ts +2 -2
  38. package/dist/types/router/cli/handler.d.ts +4 -4
  39. package/dist/types/router/cli/index.d.ts +2 -2
  40. package/dist/types/router/runtime/types.d.ts +0 -10
  41. package/dist/types/state/cli/index.d.ts +2 -2
  42. package/package.json +11 -11
@@ -24,7 +24,7 @@ const ssrBuilderPlugin = (modernAPI) => ({
24
24
  setup(api) {
25
25
  api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig }) => {
26
26
  const isServerEnvironment = config.output.target === "node" || name === "workerSSR";
27
- const userConfig = modernAPI.useResolvedConfigContext();
27
+ const userConfig = modernAPI.getNormalizedConfig();
28
28
  const useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig);
29
29
  return mergeEnvironmentConfig(config, {
30
30
  source: {
@@ -52,61 +52,58 @@ const ssrPlugin = () => ({
52
52
  "@modern-js/runtime"
53
53
  ],
54
54
  setup: (api) => {
55
- const appContext = api.useAppContext();
56
- return {
57
- // for bundle
58
- config() {
59
- const { bundlerType = "webpack" } = api.useAppContext();
60
- const babelHandler = (() => {
61
- if (bundlerType === "webpack") {
62
- return (config) => {
63
- var _config_plugins;
64
- const userConfig = api.useResolvedConfigContext();
55
+ const appContext = api.getAppContext();
56
+ api.config(() => {
57
+ const { bundlerType = "webpack" } = api.getAppContext();
58
+ const babelHandler = (() => {
59
+ if (bundlerType === "webpack") {
60
+ return (config) => {
61
+ var _config_plugins;
62
+ const userConfig = api.getNormalizedConfig();
63
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
64
+ if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
65
+ var _config_plugins1;
66
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
67
+ }
68
+ };
69
+ } else if (bundlerType === "rspack") {
70
+ return (config) => {
71
+ const userConfig = api.useResolvedConfigContext();
72
+ if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
73
+ var _config_plugins, _config_plugins1;
65
74
  (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
66
- if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
67
- var _config_plugins1;
68
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
69
- }
70
- };
71
- } else if (bundlerType === "rspack") {
72
- return (config) => {
73
- const userConfig = api.useResolvedConfigContext();
74
- if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
75
- var _config_plugins, _config_plugins1;
76
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
77
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
78
- }
79
- };
80
- }
81
- })();
82
- return {
83
- builderPlugins: [
84
- ssrBuilderPlugin(api)
85
- ],
86
- source: {
87
- alias: {
88
- // ensure that all packages use the same storage in @modern-js/runtime-utils/node
89
- "@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node")
75
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
90
76
  }
91
- },
92
- tools: {
93
- babel: babelHandler,
94
- bundlerChain: (chain, { isServer }) => {
95
- if (isServer && appContext.moduleType === "module") {
96
- chain.output.libraryTarget("module").set("chunkFormat", "module");
97
- chain.output.library({
98
- type: "module"
99
- });
100
- chain.experiments({
101
- ...chain.get("experiments"),
102
- outputModule: true
103
- });
104
- }
77
+ };
78
+ }
79
+ })();
80
+ return {
81
+ builderPlugins: [
82
+ ssrBuilderPlugin(api)
83
+ ],
84
+ source: {
85
+ alias: {
86
+ // ensure that all packages use the same storage in @modern-js/runtime-utils/node
87
+ "@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node")
88
+ }
89
+ },
90
+ tools: {
91
+ babel: babelHandler,
92
+ bundlerChain: (chain, { isServer }) => {
93
+ if (isServer && appContext.moduleType === "module") {
94
+ chain.output.libraryTarget("module").set("chunkFormat", "module");
95
+ chain.output.library({
96
+ type: "module"
97
+ });
98
+ chain.experiments({
99
+ ...chain.get("experiments"),
100
+ outputModule: true
101
+ });
105
102
  }
106
103
  }
107
- };
108
- }
109
- };
104
+ }
105
+ };
106
+ });
110
107
  }
111
108
  });
112
109
  var ssr_default = ssrPlugin;
@@ -47,8 +47,18 @@ class LoadableCollector {
47
47
  if (!this.extractor) {
48
48
  return;
49
49
  }
50
- const { extractor } = this;
51
- const chunks = extractor.getChunkAssets(extractor.chunks);
50
+ const { extractor, options } = this;
51
+ const { entryName, config } = options;
52
+ const asyncChunks = [];
53
+ if (config.enableAsyncEntry) {
54
+ try {
55
+ asyncChunks.push(...extractor.getChunkAssets([
56
+ `async-${entryName}`
57
+ ]));
58
+ } catch (e) {
59
+ }
60
+ }
61
+ const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
52
62
  const scriptChunks = generateChunks(chunks, "js");
53
63
  const styleChunks = generateChunks(chunks, "css");
54
64
  this.emitLoadableScripts(extractor);
@@ -99,7 +109,7 @@ class LoadableCollector {
99
109
  chunkSet.jsChunk += scripts.filter((script) => Boolean(script)).join("");
100
110
  }
101
111
  async emitStyleAssets(chunks) {
102
- const { template, chunkSet, config } = this.options;
112
+ const { template, chunkSet, config, entryName } = this.options;
103
113
  const { enableInlineStyles } = config;
104
114
  const atrributes = attributesToString(this.generateAttributes());
105
115
  const linkRegExp = /<link .*?href="([^"]+)".*?>/g;
@@ -39,13 +39,13 @@ const documentPlugin = () => ({
39
39
  };
40
40
  }
41
41
  const documentEntry = (entryName, templateParameters) => {
42
- const { entrypoints, internalDirectory, appDirectory } = api.useAppContext();
42
+ const { entrypoints, internalDirectory, appDirectory } = api.getAppContext();
43
43
  const documentFilePath = getDocumenByEntryName(entrypoints, entryName, appDirectory);
44
44
  if (!documentFilePath) {
45
45
  return null;
46
46
  }
47
47
  return async ({ htmlWebpackPlugin }) => {
48
- const config = api.useResolvedConfigContext();
48
+ const config = api.getNormalizedConfig();
49
49
  const documentParams = getDocParams({
50
50
  config,
51
51
  entryName,
@@ -109,7 +109,7 @@ const documentPlugin = () => ({
109
109
  }, React.createElement(Document, null));
110
110
  let html = ReactDomServer.renderToStaticMarkup(HTMLElement);
111
111
  debug("entry %s's document jsx rendered html: %o", entryName, html);
112
- const { partialsByEntrypoint } = api.useAppContext();
112
+ const { partialsByEntrypoint } = api.getAppContext();
113
113
  const scripts = [
114
114
  htmlWebpackPlugin.tags.headTags.filter((item) => item.tagName === "script").join(""),
115
115
  htmlWebpackPlugin.tags.bodyTags.toString()
@@ -148,38 +148,36 @@ const documentPlugin = () => ({
148
148
  return finalHtml;
149
149
  };
150
150
  };
151
- return {
152
- config: () => {
153
- var _userConfig_tools;
154
- const userConfig = api.useConfigContext();
155
- if (((_userConfig_tools = userConfig.tools) === null || _userConfig_tools === void 0 ? void 0 : _userConfig_tools.htmlPlugin) === false) {
156
- return {};
157
- }
158
- return {
159
- tools: {
160
- htmlPlugin: (options, entry) => {
161
- const hackParameters = typeof (options === null || options === void 0 ? void 0 : options.templateParameters) === "function" ? options === null || options === void 0 ? void 0 : options.templateParameters({}, {}, {}, {}) : {
162
- ...options === null || options === void 0 ? void 0 : options.templateParameters
163
- };
164
- const templateContent = documentEntry(
165
- entry.entryName,
166
- // options,
167
- hackParameters
168
- );
169
- const documentHtmlOptions = templateContent ? {
170
- templateContent,
171
- // Note: the behavior of inject/modify tags in afterTemplateExecution hook will not take effect
172
- inject: false
173
- } : {};
174
- return {
175
- ...options,
176
- ...documentHtmlOptions
177
- };
178
- }
179
- }
180
- };
151
+ api.config(() => {
152
+ var _userConfig_tools;
153
+ const userConfig = api.getConfig();
154
+ if (((_userConfig_tools = userConfig.tools) === null || _userConfig_tools === void 0 ? void 0 : _userConfig_tools.htmlPlugin) === false) {
155
+ return {};
181
156
  }
182
- };
157
+ return {
158
+ tools: {
159
+ htmlPlugin: (options, entry) => {
160
+ const hackParameters = typeof (options === null || options === void 0 ? void 0 : options.templateParameters) === "function" ? options === null || options === void 0 ? void 0 : options.templateParameters({}, {}, {}, {}) : {
161
+ ...options === null || options === void 0 ? void 0 : options.templateParameters
162
+ };
163
+ const templateContent = documentEntry(
164
+ entry.entryName,
165
+ // options,
166
+ hackParameters
167
+ );
168
+ const documentHtmlOptions = templateContent ? {
169
+ templateContent,
170
+ // Note: the behavior of inject/modify tags in afterTemplateExecution hook will not take effect
171
+ inject: false
172
+ } : {};
173
+ return {
174
+ ...options,
175
+ ...documentHtmlOptions
176
+ };
177
+ }
178
+ }
179
+ };
180
+ });
183
181
  }
184
182
  });
185
183
  var cli_default = documentPlugin;
@@ -10,14 +10,14 @@ import * as templates from "./templates";
10
10
  import { getServerCombinedModueFile, getServerLoadersFile } from "./utils";
11
11
  const generateCode = async (appContext, config, entrypoints, api) => {
12
12
  const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
13
- const hookRunners = api.useHookRunners();
13
+ const hooks = api.getHooks();
14
14
  const isV5 = isRouterV5(config);
15
15
  const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
16
16
  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;
17
17
  await Promise.all(entrypoints.map(generateEntryCode));
18
18
  async function generateEntryCode(entrypoint) {
19
19
  const { entryName, isMainEntry, isAutoMount, pageRoutesEntry, nestedRoutesEntry } = entrypoint;
20
- const { metaName } = api.useAppContext();
20
+ const { metaName } = api.getAppContext();
21
21
  if (isAutoMount) {
22
22
  if (pageRoutesEntry || nestedRoutesEntry) {
23
23
  var _config_output;
@@ -48,11 +48,11 @@ const generateCode = async (appContext, config, entrypoints, api) => {
48
48
  }
49
49
  }
50
50
  }
51
- const config2 = api.useResolvedConfigContext();
51
+ const config2 = api.getNormalizedConfig();
52
52
  const ssrByRouteIds = config2.server.ssrByRouteIds || [];
53
53
  const clonedRoutes = cloneDeep(initialRoutes);
54
54
  const markedRoutes = ssrByRouteIds.length > 0 ? markRoutes(clonedRoutes, ssrByRouteIds) : initialRoutes;
55
- const { routes } = await hookRunners.modifyFileSystemRoutes({
55
+ const { routes } = await hooks.modifyFileSystemRoutes.call({
56
56
  entrypoint,
57
57
  routes: markedRoutes
58
58
  });
@@ -69,7 +69,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
69
69
  process.exit(1);
70
70
  }
71
71
  }
72
- const { code } = await hookRunners.beforeGenerateRoutes({
72
+ const { code } = await hooks.onBeforeGenerateRoutes.call({
73
73
  entrypoint,
74
74
  code: await templates.fileSystemRoutes({
75
75
  metaName,
@@ -5,13 +5,13 @@ import { isPageComponentFile } from "./code/utils";
5
5
  import { modifyEntrypoints } from "./entry";
6
6
  let originEntrypoints = [];
7
7
  async function handleModifyEntrypoints(api, entrypoints) {
8
- const config = api.useResolvedConfigContext();
8
+ const config = api.getNormalizedConfig();
9
9
  return modifyEntrypoints(entrypoints, config);
10
10
  }
11
11
  async function handleGeneratorEntryCode(api, entrypoints) {
12
- const appContext = api.useAppContext();
13
- const { internalDirectory } = api.useAppContext();
14
- const resolvedConfig = api.useResolvedConfigContext();
12
+ const appContext = api.getAppContext();
13
+ const { internalDirectory } = appContext;
14
+ const resolvedConfig = api.getNormalizedConfig();
15
15
  const { generatorRegisterCode, generateCode } = await import("./code");
16
16
  originEntrypoints = cloneDeep(entrypoints);
17
17
  await generateCode(appContext, resolvedConfig, entrypoints, api);
@@ -30,7 +30,7 @@ async function handleGeneratorEntryCode(api, entrypoints) {
30
30
  return entrypoints;
31
31
  }
32
32
  async function handleFileChange(api, e) {
33
- const appContext = api.useAppContext();
33
+ const appContext = api.getAppContext();
34
34
  const { appDirectory, entrypoints } = appContext;
35
35
  const { filename, eventType } = e;
36
36
  const nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
@@ -39,7 +39,7 @@ async function handleFileChange(api, e) {
39
39
  const absoluteFilePath = path.resolve(appDirectory, filename);
40
40
  const isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
41
41
  if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
42
- const resolvedConfig = api.useResolvedConfigContext();
42
+ const resolvedConfig = api.getNormalizedConfig();
43
43
  const { generateCode } = await import("./code");
44
44
  const entrypoints2 = cloneDeep(originEntrypoints);
45
45
  await generateCode(appContext, resolvedConfig, entrypoints2, api);
@@ -13,87 +13,85 @@ const routerPlugin = () => ({
13
13
  setup: (api) => {
14
14
  const nestedRoutes = {};
15
15
  const nestedRoutesForServer = {};
16
- return {
17
- _internalRuntimePlugins({ entrypoint, plugins }) {
18
- var _getEntryOptions;
19
- const { packageName, serverRoutes, metaName } = api.useAppContext();
20
- const serverBase = serverRoutes.filter((route) => route.entryName === entrypoint.entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
21
- const userConfig = api.useResolvedConfigContext();
22
- const routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
23
- if (routerConfig && !isV5(userConfig)) {
24
- plugins.push({
25
- name: "router",
26
- path: `@${metaName}/runtime/router`,
27
- config: typeof routerConfig === "boolean" ? {
28
- serverBase
29
- } : {
30
- ...routerConfig,
31
- serverBase
32
- }
33
- });
34
- }
35
- return {
36
- entrypoint,
37
- plugins
38
- };
39
- },
40
- checkEntryPoint({ path: path2, entry }) {
41
- return {
42
- path: path2,
43
- entry: entry || isRouteEntry(path2)
44
- };
45
- },
46
- config() {
47
- return {
48
- source: {
49
- include: [
50
- // react-router v6 is no longer support ie 11
51
- // so we need to compile these packages to ensure the compatibility
52
- // https://github.com/remix-run/react-router/commit/f6df0697e1b2064a2b3a12e8b39577326fdd945b
53
- /node_modules\/react-router/,
54
- /node_modules\/react-router-dom/,
55
- /node_modules\/@remix-run\/router/
56
- ]
16
+ api._internalRuntimePlugins(({ entrypoint, plugins }) => {
17
+ var _getEntryOptions;
18
+ const { packageName, serverRoutes, metaName } = api.getAppContext();
19
+ const serverBase = serverRoutes.filter((route) => route.entryName === entrypoint.entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
20
+ const userConfig = api.getNormalizedConfig();
21
+ const routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
22
+ if (routerConfig && !isV5(userConfig)) {
23
+ plugins.push({
24
+ name: "router",
25
+ path: `@${metaName}/runtime/router`,
26
+ config: typeof routerConfig === "boolean" ? {
27
+ serverBase
28
+ } : {
29
+ ...routerConfig,
30
+ serverBase
57
31
  }
58
- };
59
- },
60
- async modifyEntrypoints({ entrypoints }) {
61
- const newEntryPoints = await handleModifyEntrypoints(api, entrypoints);
62
- return {
63
- entrypoints: newEntryPoints
64
- };
65
- },
66
- async generateEntryCode({ entrypoints }) {
67
- await handleGeneratorEntryCode(api, entrypoints);
68
- },
69
- addRuntimeExports() {
70
- const userConfig = api.useResolvedConfigContext();
71
- const { internalDirectory, metaName } = api.useAppContext();
72
- const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
73
- if (!isV5(userConfig)) {
74
- pluginsExportsUtils.addExport(`export { default as router } from '@${metaName}/runtime/router'`);
32
+ });
33
+ }
34
+ return {
35
+ entrypoint,
36
+ plugins
37
+ };
38
+ });
39
+ api.checkEntryPoint(({ path: path2, entry }) => {
40
+ return {
41
+ path: path2,
42
+ entry: entry || isRouteEntry(path2)
43
+ };
44
+ });
45
+ api.config(() => {
46
+ return {
47
+ source: {
48
+ include: [
49
+ // react-router v6 is no longer support ie 11
50
+ // so we need to compile these packages to ensure the compatibility
51
+ // https://github.com/remix-run/react-router/commit/f6df0697e1b2064a2b3a12e8b39577326fdd945b
52
+ /node_modules\/react-router/,
53
+ /node_modules\/react-router-dom/,
54
+ /node_modules\/@remix-run\/router/
55
+ ]
75
56
  }
76
- },
77
- async fileChange(e) {
78
- await handleFileChange(api, e);
79
- },
80
- async modifyFileSystemRoutes({ entrypoint, routes }) {
81
- nestedRoutes[entrypoint.entryName] = routes;
82
- nestedRoutesForServer[entrypoint.entryName] = filterRoutesForServer(routes);
83
- return {
84
- entrypoint,
85
- routes
86
- };
87
- },
88
- async beforeGenerateRoutes({ entrypoint, code }) {
89
- const { distDirectory } = api.useAppContext();
90
- await fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutesForServer);
91
- return {
92
- entrypoint,
93
- code
94
- };
57
+ };
58
+ });
59
+ api.modifyEntrypoints(async ({ entrypoints }) => {
60
+ const newEntryPoints = await handleModifyEntrypoints(api, entrypoints);
61
+ return {
62
+ entrypoints: newEntryPoints
63
+ };
64
+ });
65
+ api.generateEntryCode(async ({ entrypoints }) => {
66
+ await handleGeneratorEntryCode(api, entrypoints);
67
+ });
68
+ api.addRuntimeExports(() => {
69
+ const userConfig = api.useResolvedConfigContext();
70
+ const { internalDirectory, metaName } = api.useAppContext();
71
+ const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
72
+ if (!isV5(userConfig)) {
73
+ pluginsExportsUtils.addExport(`export { default as router } from '@${metaName}/runtime/router'`);
95
74
  }
96
- };
75
+ });
76
+ api.onFileChanged(async (e) => {
77
+ await handleFileChange(api, e);
78
+ });
79
+ api.modifyFileSystemRoutes(({ entrypoint, routes }) => {
80
+ nestedRoutes[entrypoint.entryName] = routes;
81
+ nestedRoutesForServer[entrypoint.entryName] = filterRoutesForServer(routes);
82
+ return {
83
+ entrypoint,
84
+ routes
85
+ };
86
+ });
87
+ api.onBeforeGenerateRoutes(async ({ entrypoint, code }) => {
88
+ const { distDirectory } = api.getAppContext();
89
+ await fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutesForServer);
90
+ return {
91
+ entrypoint,
92
+ code
93
+ };
94
+ });
97
95
  }
98
96
  });
99
97
  var cli_default = routerPlugin;
@@ -1,6 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { merge } from "@modern-js/runtime-utils/merge";
3
- import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
4
3
  import { RouterProvider, createBrowserRouter, createHashRouter, createRoutesFromElements, useHref, useLocation, useMatches } from "@modern-js/runtime-utils/router";
5
4
  import { useContext, useMemo } from "react";
6
5
  import { RuntimeReactContext } from "../../core";
@@ -28,7 +27,6 @@ const routerPlugin = (userConfig = {}) => {
28
27
  },
29
28
  setup: (api) => {
30
29
  let routes = [];
31
- window._SERVER_DATA = parsedJSONFromElement("__MODERN_SERVER_DATA__");
32
30
  return {
33
31
  beforeRender(context) {
34
32
  context.router = {
@@ -56,9 +54,8 @@ const routerPlugin = (userConfig = {}) => {
56
54
  }
57
55
  const getRouteApp = () => {
58
56
  const useCreateRouter = (props) => {
59
- var _window__SERVER_DATA;
60
57
  const runtimeContext = useContext(RuntimeReactContext);
61
- const baseUrl = (((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
58
+ const baseUrl = select(location.pathname).replace(/^\/*/, "/");
62
59
  const _basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename) : baseUrl;
63
60
  let hydrationData = window._ROUTER_DATA;
64
61
  const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
@@ -6,31 +6,29 @@ const statePlugin = () => ({
6
6
  "@modern-js/runtime"
7
7
  ],
8
8
  setup: (api) => {
9
- return {
10
- _internalRuntimePlugins({ entrypoint, plugins }) {
11
- var _getEntryOptions;
12
- const { entryName, isMainEntry } = entrypoint;
13
- const userConfig = api.useResolvedConfigContext();
14
- const { packageName, metaName } = api.useAppContext();
15
- const stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
16
- if (stateConfig) {
17
- plugins.push({
18
- name: PLUGIN_IDENTIFIER,
19
- path: `@${metaName}/runtime/model`,
20
- config: typeof stateConfig === "boolean" ? {} : stateConfig
21
- });
22
- }
23
- return {
24
- entrypoint,
25
- plugins
26
- };
27
- },
28
- addRuntimeExports() {
29
- const { internalDirectory, metaName } = api.useAppContext();
30
- const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
31
- pluginsExportsUtils.addExport(`export { default as state } from '@${metaName}/runtime/model'`);
9
+ api._internalRuntimePlugins(({ entrypoint, plugins }) => {
10
+ var _getEntryOptions;
11
+ const { entryName, isMainEntry } = entrypoint;
12
+ const userConfig = api.useResolvedConfigContext();
13
+ const { packageName, metaName } = api.useAppContext();
14
+ const stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
15
+ if (stateConfig) {
16
+ plugins.push({
17
+ name: PLUGIN_IDENTIFIER,
18
+ path: `@${metaName}/runtime/model`,
19
+ config: typeof stateConfig === "boolean" ? {} : stateConfig
20
+ });
32
21
  }
33
- };
22
+ return {
23
+ entrypoint,
24
+ plugins
25
+ };
26
+ });
27
+ api.addRuntimeExports(() => {
28
+ const { internalDirectory, metaName } = api.useAppContext();
29
+ const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
30
+ pluginsExportsUtils.addExport(`export { default as state } from '@${metaName}/runtime/model'`);
31
+ });
34
32
  }
35
33
  });
36
34
  var cli_default = statePlugin;
@@ -1,10 +1,3 @@
1
- import type { AppTools, IAppContext, NormalizedConfig, RuntimePlugin } from '@modern-js/app-tools';
2
- import type { MaybeAsync } from '@modern-js/plugin';
1
+ import type { AppToolsContext, AppToolsFeatureHooks, AppToolsNormalizedConfig } from '@modern-js/app-tools';
3
2
  import type { Entrypoint } from '@modern-js/types';
4
- export declare const generateCode: (entrypoints: Entrypoint[], appContext: IAppContext, config: NormalizedConfig<AppTools>, onCollectRuntimePlugins: (params: {
5
- entrypoint: Entrypoint;
6
- plugins: RuntimePlugin[];
7
- }) => MaybeAsync<{
8
- entrypoint: Entrypoint;
9
- plugins: RuntimePlugin[];
10
- }>) => Promise<void>;
3
+ export declare const generateCode: (entrypoints: Entrypoint[], appContext: AppToolsContext<'shared'>, config: AppToolsNormalizedConfig, hooks: AppToolsFeatureHooks<'shared'>) => Promise<void>;
@@ -1,4 +1,4 @@
1
- import type { AppTools, CliPlugin } from '@modern-js/app-tools';
1
+ import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
2
2
  import { documentPlugin } from '../document/cli';
3
3
  import { routerPlugin } from '../router/cli';
4
4
  import { statePlugin } from '../state/cli';
@@ -6,6 +6,6 @@ import { ssrPlugin } from './ssr';
6
6
  export { isRuntimeEntry } from './entry';
7
7
  export { statePlugin, ssrPlugin, routerPlugin, documentPlugin };
8
8
  export declare const runtimePlugin: (params?: {
9
- plugins?: CliPlugin<AppTools>[];
10
- }) => CliPlugin<AppTools>;
9
+ plugins?: CliPluginFuture<AppTools<'shared'>>[];
10
+ }) => CliPluginFuture<AppTools<'shared'>>;
11
11
  export default runtimePlugin;
@@ -1,3 +1,3 @@
1
- import type { AppTools, CliPlugin } from '@modern-js/app-tools';
2
- export declare const ssrPlugin: () => CliPlugin<AppTools>;
1
+ import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
2
+ export declare const ssrPlugin: () => CliPluginFuture<AppTools<'shared'>>;
3
3
  export default ssrPlugin;
@@ -2,8 +2,8 @@ import type { ReactElement } from 'react';
2
2
  import type { ChunkSet, Collector } from './types';
3
3
  declare module '@loadable/server' {
4
4
  interface ChunkExtractor {
5
- chunks: Chunk;
6
- getChunkAssets: (chunks: Chunk) => Chunk[];
5
+ chunks: string[];
6
+ getChunkAssets: (chunks: string[]) => Chunk[];
7
7
  }
8
8
  }
9
9
  export interface LoadableCollectorOptions {
@@ -20,6 +20,7 @@ export interface LoadableCollectorConfig {
20
20
  enableInlineStyles?: boolean | RegExp;
21
21
  enableInlineScripts?: boolean | RegExp;
22
22
  crossorigin?: boolean | 'anonymous' | 'use-credentials';
23
+ enableAsyncEntry?: boolean;
23
24
  }
24
25
  export declare class LoadableCollector implements Collector {
25
26
  private options;
@@ -1,5 +1,5 @@
1
- import type { AppTools, CliPlugin } from '@modern-js/app-tools';
1
+ import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
2
2
  import type { Entrypoint } from '@modern-js/types/cli';
3
3
  export declare const getDocumenByEntryName: (entrypoints: Entrypoint[], entryName: string, fallbackDir?: string) => string | undefined;
4
- export declare const documentPlugin: () => CliPlugin<AppTools>;
4
+ export declare const documentPlugin: () => CliPluginFuture<AppTools<'shared'>>;
5
5
  export default documentPlugin;
@@ -1,5 +1,5 @@
1
- import type { AppNormalizedConfig, AppTools } from '@modern-js/app-tools';
2
- import type { IAppContext, PluginAPI } from '@modern-js/core';
1
+ import type { AppNormalizedConfig, AppTools, AppToolsContext } from '@modern-js/app-tools';
2
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
3
3
  import type { Entrypoint } from '@modern-js/types';
4
- export declare const generateCode: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>, entrypoints: Entrypoint[], api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
4
+ export declare const generateCode: (appContext: AppToolsContext<'shared'>, config: AppNormalizedConfig<'shared'>, entrypoints: Entrypoint[], api: CLIPluginAPI<AppTools<'shared'>>) => Promise<void>;
5
5
  export declare function generatorRegisterCode(internalDirectory: string, entryName: string, code: string): void;