@modern-js/runtime 2.63.3 → 2.63.5

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 (38) 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/document/cli/index.js +32 -34
  5. package/dist/cjs/router/cli/code/index.js +5 -5
  6. package/dist/cjs/router/cli/handler.js +6 -6
  7. package/dist/cjs/router/cli/index.js +76 -78
  8. package/dist/cjs/router/runtime/plugin.js +1 -4
  9. package/dist/cjs/state/cli/index.js +22 -24
  10. package/dist/esm/cli/code.js +3 -3
  11. package/dist/esm/cli/index.js +120 -130
  12. package/dist/esm/cli/ssr/index.js +50 -53
  13. package/dist/esm/document/cli/index.js +28 -30
  14. package/dist/esm/router/cli/code/index.js +8 -8
  15. package/dist/esm/router/cli/handler.js +6 -6
  16. package/dist/esm/router/cli/index.js +161 -157
  17. package/dist/esm/router/runtime/plugin.js +1 -4
  18. package/dist/esm/state/cli/index.js +23 -25
  19. package/dist/esm-node/cli/code.js +2 -2
  20. package/dist/esm-node/cli/index.js +102 -108
  21. package/dist/esm-node/cli/ssr/index.js +49 -52
  22. package/dist/esm-node/document/cli/index.js +32 -34
  23. package/dist/esm-node/router/cli/code/index.js +5 -5
  24. package/dist/esm-node/router/cli/handler.js +6 -6
  25. package/dist/esm-node/router/cli/index.js +76 -78
  26. package/dist/esm-node/router/runtime/plugin.js +1 -4
  27. package/dist/esm-node/state/cli/index.js +22 -24
  28. package/dist/types/cli/code.d.ts +2 -9
  29. package/dist/types/cli/index.d.ts +3 -3
  30. package/dist/types/cli/ssr/index.d.ts +2 -2
  31. package/dist/types/document/cli/index.d.ts +2 -2
  32. package/dist/types/router/cli/code/index.d.ts +3 -3
  33. package/dist/types/router/cli/code/templates.d.ts +2 -2
  34. package/dist/types/router/cli/handler.d.ts +4 -4
  35. package/dist/types/router/cli/index.d.ts +2 -2
  36. package/dist/types/router/runtime/types.d.ts +0 -10
  37. package/dist/types/state/cli/index.d.ts +2 -2
  38. package/package.json +11 -11
@@ -3,7 +3,6 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
3
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
4
4
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
5
5
  import { merge } from "@modern-js/runtime-utils/merge";
6
- import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
7
6
  import { RouterProvider, createBrowserRouter, createHashRouter, createRoutesFromElements, useHref, useLocation, useMatches } from "@modern-js/runtime-utils/router";
8
7
  import { useContext, useMemo } from "react";
9
8
  import { RuntimeReactContext } from "../../core";
@@ -32,7 +31,6 @@ var routerPlugin = function() {
32
31
  },
33
32
  setup: function(api) {
34
33
  var routes = [];
35
- window._SERVER_DATA = parsedJSONFromElement("__MODERN_SERVER_DATA__");
36
34
  return {
37
35
  beforeRender: function beforeRender(context) {
38
36
  context.router = {
@@ -63,9 +61,8 @@ var routerPlugin = function() {
63
61
  }
64
62
  var getRouteApp = function() {
65
63
  var useCreateRouter = function(props) {
66
- var _window__SERVER_DATA;
67
64
  var runtimeContext = useContext(RuntimeReactContext);
68
- var baseUrl = (((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
65
+ var baseUrl = select(location.pathname).replace(/^\/*/, "/");
69
66
  var _basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename) : baseUrl;
70
67
  var hydrationData = window._ROUTER_DATA;
71
68
  var getBlockNavState = runtimeContext.unstable_getBlockNavState;
@@ -7,32 +7,30 @@ var statePlugin = function() {
7
7
  "@modern-js/runtime"
8
8
  ],
9
9
  setup: function(api) {
10
- return {
11
- _internalRuntimePlugins: function _internalRuntimePlugins(param) {
12
- var entrypoint = param.entrypoint, plugins = param.plugins;
13
- var _getEntryOptions;
14
- var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
15
- var userConfig = api.useResolvedConfigContext();
16
- var _api_useAppContext = api.useAppContext(), packageName = _api_useAppContext.packageName, metaName = _api_useAppContext.metaName;
17
- var stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
18
- if (stateConfig) {
19
- plugins.push({
20
- name: PLUGIN_IDENTIFIER,
21
- path: "@".concat(metaName, "/runtime/model"),
22
- config: typeof stateConfig === "boolean" ? {} : stateConfig
23
- });
24
- }
25
- return {
26
- entrypoint,
27
- plugins
28
- };
29
- },
30
- addRuntimeExports: function addRuntimeExports() {
31
- var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
32
- var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
33
- pluginsExportsUtils.addExport("export { default as state } from '@".concat(metaName, "/runtime/model'"));
10
+ api._internalRuntimePlugins(function(param) {
11
+ var entrypoint = param.entrypoint, plugins = param.plugins;
12
+ var _getEntryOptions;
13
+ var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
14
+ var userConfig = api.useResolvedConfigContext();
15
+ var _api_useAppContext = api.useAppContext(), packageName = _api_useAppContext.packageName, metaName = _api_useAppContext.metaName;
16
+ var stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
17
+ if (stateConfig) {
18
+ plugins.push({
19
+ name: PLUGIN_IDENTIFIER,
20
+ path: "@".concat(metaName, "/runtime/model"),
21
+ config: typeof stateConfig === "boolean" ? {} : stateConfig
22
+ });
34
23
  }
35
- };
24
+ return {
25
+ entrypoint,
26
+ plugins
27
+ };
28
+ });
29
+ api.addRuntimeExports(function() {
30
+ var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
31
+ var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
32
+ pluginsExportsUtils.addExport("export { default as state } from '@".concat(metaName, "/runtime/model'"));
33
+ });
36
34
  }
37
35
  };
38
36
  };
@@ -19,13 +19,13 @@ function getSSRMode(entry, config) {
19
19
  return ssr2.mode === "stream" ? "stream" : "string";
20
20
  }
21
21
  }
22
- const generateCode = async (entrypoints, appContext, config, onCollectRuntimePlugins) => {
22
+ const generateCode = async (entrypoints, appContext, config, hooks) => {
23
23
  const { mountId } = config.html;
24
24
  const { enableAsyncEntry } = config.source;
25
25
  const { runtimeConfigFile, internalDirectory, internalSrcAlias, metaName, srcDirectory } = appContext;
26
26
  await Promise.all(entrypoints.map(async (entrypoint) => {
27
27
  const { entryName, isAutoMount, entry, customEntry, customBootstrap, customServerEntry } = entrypoint;
28
- const { plugins: runtimePlugins } = await onCollectRuntimePlugins({
28
+ const { plugins: runtimePlugins } = await hooks._internalRuntimePlugins.call({
29
29
  entrypoint,
30
30
  plugins: []
31
31
  });
@@ -26,119 +26,113 @@ const runtimePlugin = (params) => ({
26
26
  documentPlugin()
27
27
  ],
28
28
  setup: (api) => {
29
- return {
30
- checkEntryPoint({ path: path2, entry }) {
31
- return {
32
- path: path2,
33
- entry: entry || isRuntimeEntry(path2)
34
- };
35
- },
36
- modifyEntrypoints({ entrypoints }) {
37
- const { internalDirectory } = api.useAppContext();
38
- const { source: { enableAsyncEntry } } = api.useResolvedConfigContext();
39
- const newEntryPoints = entrypoints.map((entrypoint) => {
40
- if (entrypoint.isAutoMount) {
41
- entrypoint.internalEntry = path.resolve(internalDirectory, `./${entrypoint.entryName}/${enableAsyncEntry ? ENTRY_BOOTSTRAP_FILE_NAME : ENTRY_POINT_FILE_NAME}`);
29
+ api.checkEntryPoint(({ path: path2, entry }) => {
30
+ return {
31
+ path: path2,
32
+ entry: entry || isRuntimeEntry(path2)
33
+ };
34
+ });
35
+ api.modifyEntrypoints(({ entrypoints }) => {
36
+ const { internalDirectory } = api.getAppContext();
37
+ const { source: { enableAsyncEntry } } = api.getNormalizedConfig();
38
+ const newEntryPoints = entrypoints.map((entrypoint) => {
39
+ if (entrypoint.isAutoMount) {
40
+ entrypoint.internalEntry = path.resolve(internalDirectory, `./${entrypoint.entryName}/${enableAsyncEntry ? ENTRY_BOOTSTRAP_FILE_NAME : ENTRY_POINT_FILE_NAME}`);
41
+ }
42
+ return entrypoint;
43
+ });
44
+ return {
45
+ entrypoints: newEntryPoints
46
+ };
47
+ });
48
+ api.generateEntryCode(async ({ entrypoints }) => {
49
+ const appContext = api.getAppContext();
50
+ const resolvedConfig = api.getNormalizedConfig();
51
+ const hooks = api.getHooks();
52
+ await generateCode(entrypoints, appContext, resolvedConfig, hooks);
53
+ });
54
+ api.onPrepare(() => {
55
+ const { builder, entrypoints, internalDirectory, metaName } = api.getAppContext();
56
+ builder === null || builder === void 0 ? void 0 : builder.addPlugins([
57
+ builderPluginAlias({
58
+ entrypoints,
59
+ internalDirectory,
60
+ metaName
61
+ })
62
+ ]);
63
+ });
64
+ api.config(() => {
65
+ const { appDirectory, metaName, internalDirectory } = api.getAppContext();
66
+ const isReact18 = checkIsReact18(appDirectory);
67
+ process.env.IS_REACT18 = isReact18.toString();
68
+ const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
69
+ return {
70
+ runtime: {},
71
+ runtimeByEntries: {},
72
+ source: {
73
+ alias: {
74
+ /**
75
+ * twin.macro inserts styled-components into the code during the compilation process
76
+ * But it will not be installed under the user project.
77
+ * So need to add alias
78
+ */
79
+ "styled-components": require.resolve("styled-components"),
80
+ /**
81
+ * Compatible with the reference path of the old version of the plugin.
82
+ */
83
+ [`@${metaName}/runtime/plugins`]: pluginsExportsUtils.getPath(),
84
+ "@meta/runtime/browser$": require.resolve("@modern-js/runtime/browser"),
85
+ "@meta/runtime/react$": require.resolve("@modern-js/runtime/react"),
86
+ "@meta/runtime/context$": require.resolve("@modern-js/runtime/context"),
87
+ "@meta/runtime$": require.resolve("@modern-js/runtime")
88
+ },
89
+ globalVars: {
90
+ "process.env.IS_REACT18": process.env.IS_REACT18
42
91
  }
43
- return entrypoint;
44
- });
45
- return {
46
- entrypoints: newEntryPoints
47
- };
48
- },
49
- async generateEntryCode({ entrypoints }) {
50
- const appContext = api.useAppContext();
51
- const resolvedConfig = api.useResolvedConfigContext();
52
- const runners = api.useHookRunners();
53
- await generateCode(entrypoints, appContext, resolvedConfig, runners._internalRuntimePlugins);
54
- },
55
- /* Note that the execution time of the config hook is before prepare.
56
- /* This means that the entry information cannot be obtained in the config hook.
57
- /* Therefore, aliases cannot be set directly in the config.
58
- */
59
- prepare() {
60
- const { builder, entrypoints, internalDirectory, metaName } = api.useAppContext();
61
- builder === null || builder === void 0 ? void 0 : builder.addPlugins([
62
- builderPluginAlias({
63
- entrypoints,
64
- internalDirectory,
65
- metaName
66
- })
67
- ]);
68
- },
69
- config() {
70
- const { appDirectory, metaName, internalDirectory } = api.useAppContext();
71
- const isReact18 = checkIsReact18(appDirectory);
72
- process.env.IS_REACT18 = isReact18.toString();
73
- const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
74
- return {
75
- runtime: {},
76
- runtimeByEntries: {},
77
- source: {
78
- alias: {
79
- /**
80
- * twin.macro inserts styled-components into the code during the compilation process
81
- * But it will not be installed under the user project.
82
- * So need to add alias
83
- */
84
- "styled-components": require.resolve("styled-components"),
85
- /**
86
- * Compatible with the reference path of the old version of the plugin.
87
- */
88
- [`@${metaName}/runtime/plugins`]: pluginsExportsUtils.getPath(),
89
- "@meta/runtime/browser$": require.resolve("@modern-js/runtime/browser"),
90
- "@meta/runtime/react$": require.resolve("@modern-js/runtime/react"),
91
- "@meta/runtime/context$": require.resolve("@modern-js/runtime/context"),
92
- "@meta/runtime$": require.resolve("@modern-js/runtime")
93
- },
94
- globalVars: {
95
- "process.env.IS_REACT18": process.env.IS_REACT18
92
+ },
93
+ tools: {
94
+ styledComponents: {
95
+ // https://github.com/styled-components/babel-plugin-styled-components/issues/287
96
+ topLevelImportPaths: [
97
+ "@modern-js/runtime/styled"
98
+ ]
99
+ },
100
+ bundlerChain: (chain) => {
101
+ chain.module.rule("modern-entry").test(/\.jsx?$/).include.add(path.resolve(appDirectory, "node_modules", `.${metaName}`)).end().sideEffects(true);
102
+ },
103
+ /**
104
+ * Add IgnorePlugin to fix react-dom/client import error when use react17
105
+ */
106
+ webpackChain: (chain, { webpack }) => {
107
+ if (!isReact18) {
108
+ chain.plugin("ignore-plugin").use(webpack.IgnorePlugin, [
109
+ {
110
+ resourceRegExp: /^react-dom\/client$/,
111
+ contextRegExp: /./
112
+ }
113
+ ]);
96
114
  }
97
115
  },
98
- tools: {
99
- styledComponents: {
100
- // https://github.com/styled-components/babel-plugin-styled-components/issues/287
101
- topLevelImportPaths: [
102
- "@modern-js/runtime/styled"
103
- ]
104
- },
105
- bundlerChain: (chain) => {
106
- chain.module.rule("modern-entry").test(/\.jsx?$/).include.add(path.resolve(appDirectory, "node_modules", `.${metaName}`)).end().sideEffects(true);
107
- },
108
- /**
109
- * Add IgnorePlugin to fix react-dom/client import error when use react17
110
- */
111
- webpackChain: (chain, { webpack }) => {
112
- if (!isReact18) {
113
- chain.plugin("ignore-plugin").use(webpack.IgnorePlugin, [
114
- {
115
- resourceRegExp: /^react-dom\/client$/,
116
- contextRegExp: /./
117
- }
118
- ]);
119
- }
120
- },
121
- rspack: (_config, { appendPlugins, rspack }) => {
122
- if (!isReact18) {
123
- appendPlugins([
124
- new rspack.IgnorePlugin({
125
- resourceRegExp: /^react-dom\/client$/,
126
- contextRegExp: /./
127
- })
128
- ]);
129
- }
116
+ rspack: (_config, { appendPlugins, rspack }) => {
117
+ if (!isReact18) {
118
+ appendPlugins([
119
+ new rspack.IgnorePlugin({
120
+ resourceRegExp: /^react-dom\/client$/,
121
+ contextRegExp: /./
122
+ })
123
+ ]);
130
124
  }
131
125
  }
132
- };
133
- },
134
- async beforeRestart() {
135
- cleanRequireCache([
136
- require.resolve("../state/cli"),
137
- require.resolve("../router/cli"),
138
- require.resolve("./ssr")
139
- ]);
140
- }
141
- };
126
+ }
127
+ };
128
+ });
129
+ api.onBeforeRestart(() => {
130
+ cleanRequireCache([
131
+ require.resolve("../state/cli"),
132
+ require.resolve("../router/cli"),
133
+ require.resolve("./ssr")
134
+ ]);
135
+ });
142
136
  }
143
137
  });
144
138
  var cli_default = runtimePlugin;
@@ -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;
@@ -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);