@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.
- package/dist/cjs/cli/code.js +2 -2
- package/dist/cjs/cli/index.js +102 -108
- package/dist/cjs/cli/ssr/index.js +49 -52
- package/dist/cjs/document/cli/index.js +32 -34
- package/dist/cjs/router/cli/code/index.js +5 -5
- package/dist/cjs/router/cli/handler.js +6 -6
- package/dist/cjs/router/cli/index.js +76 -78
- package/dist/cjs/router/runtime/plugin.js +1 -4
- package/dist/cjs/state/cli/index.js +22 -24
- package/dist/esm/cli/code.js +3 -3
- package/dist/esm/cli/index.js +120 -130
- package/dist/esm/cli/ssr/index.js +50 -53
- package/dist/esm/document/cli/index.js +28 -30
- package/dist/esm/router/cli/code/index.js +8 -8
- package/dist/esm/router/cli/handler.js +6 -6
- package/dist/esm/router/cli/index.js +161 -157
- package/dist/esm/router/runtime/plugin.js +1 -4
- package/dist/esm/state/cli/index.js +23 -25
- package/dist/esm-node/cli/code.js +2 -2
- package/dist/esm-node/cli/index.js +102 -108
- package/dist/esm-node/cli/ssr/index.js +49 -52
- package/dist/esm-node/document/cli/index.js +32 -34
- package/dist/esm-node/router/cli/code/index.js +5 -5
- package/dist/esm-node/router/cli/handler.js +6 -6
- package/dist/esm-node/router/cli/index.js +76 -78
- package/dist/esm-node/router/runtime/plugin.js +1 -4
- package/dist/esm-node/state/cli/index.js +22 -24
- package/dist/types/cli/code.d.ts +2 -9
- package/dist/types/cli/index.d.ts +3 -3
- package/dist/types/cli/ssr/index.d.ts +2 -2
- package/dist/types/document/cli/index.d.ts +2 -2
- package/dist/types/router/cli/code/index.d.ts +3 -3
- package/dist/types/router/cli/code/templates.d.ts +2 -2
- package/dist/types/router/cli/handler.d.ts +4 -4
- package/dist/types/router/cli/index.d.ts +2 -2
- package/dist/types/router/runtime/types.d.ts +0 -10
- package/dist/types/state/cli/index.d.ts +2 -2
- package/package.json +11 -11
package/dist/cjs/cli/code.js
CHANGED
|
@@ -52,13 +52,13 @@ function getSSRMode(entry, config) {
|
|
|
52
52
|
return ssr2.mode === "stream" ? "stream" : "string";
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
const generateCode = async (entrypoints, appContext, config,
|
|
55
|
+
const generateCode = async (entrypoints, appContext, config, hooks) => {
|
|
56
56
|
const { mountId } = config.html;
|
|
57
57
|
const { enableAsyncEntry } = config.source;
|
|
58
58
|
const { runtimeConfigFile, internalDirectory, internalSrcAlias, metaName, srcDirectory } = appContext;
|
|
59
59
|
await Promise.all(entrypoints.map(async (entrypoint) => {
|
|
60
60
|
const { entryName, isAutoMount, entry, customEntry, customBootstrap, customServerEntry } = entrypoint;
|
|
61
|
-
const { plugins: runtimePlugins } = await
|
|
61
|
+
const { plugins: runtimePlugins } = await hooks._internalRuntimePlugins.call({
|
|
62
62
|
entrypoint,
|
|
63
63
|
plugins: []
|
|
64
64
|
});
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -65,119 +65,113 @@ const runtimePlugin = (params) => ({
|
|
|
65
65
|
(0, import_cli.documentPlugin)()
|
|
66
66
|
],
|
|
67
67
|
setup: (api) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
api.checkEntryPoint(({ path: path2, entry }) => {
|
|
69
|
+
return {
|
|
70
|
+
path: path2,
|
|
71
|
+
entry: entry || (0, import_entry.isRuntimeEntry)(path2)
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
api.modifyEntrypoints(({ entrypoints }) => {
|
|
75
|
+
const { internalDirectory } = api.getAppContext();
|
|
76
|
+
const { source: { enableAsyncEntry } } = api.getNormalizedConfig();
|
|
77
|
+
const newEntryPoints = entrypoints.map((entrypoint) => {
|
|
78
|
+
if (entrypoint.isAutoMount) {
|
|
79
|
+
entrypoint.internalEntry = import_path.default.resolve(internalDirectory, `./${entrypoint.entryName}/${enableAsyncEntry ? import_constants.ENTRY_BOOTSTRAP_FILE_NAME : import_constants.ENTRY_POINT_FILE_NAME}`);
|
|
80
|
+
}
|
|
81
|
+
return entrypoint;
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
entrypoints: newEntryPoints
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
api.generateEntryCode(async ({ entrypoints }) => {
|
|
88
|
+
const appContext = api.getAppContext();
|
|
89
|
+
const resolvedConfig = api.getNormalizedConfig();
|
|
90
|
+
const hooks = api.getHooks();
|
|
91
|
+
await (0, import_code.generateCode)(entrypoints, appContext, resolvedConfig, hooks);
|
|
92
|
+
});
|
|
93
|
+
api.onPrepare(() => {
|
|
94
|
+
const { builder, entrypoints, internalDirectory, metaName } = api.getAppContext();
|
|
95
|
+
builder === null || builder === void 0 ? void 0 : builder.addPlugins([
|
|
96
|
+
(0, import_alias.builderPluginAlias)({
|
|
97
|
+
entrypoints,
|
|
98
|
+
internalDirectory,
|
|
99
|
+
metaName
|
|
100
|
+
})
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
api.config(() => {
|
|
104
|
+
const { appDirectory, metaName, internalDirectory } = api.getAppContext();
|
|
105
|
+
const isReact18 = (0, import_utils.isReact18)(appDirectory);
|
|
106
|
+
process.env.IS_REACT18 = isReact18.toString();
|
|
107
|
+
const pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "plugins");
|
|
108
|
+
return {
|
|
109
|
+
runtime: {},
|
|
110
|
+
runtimeByEntries: {},
|
|
111
|
+
source: {
|
|
112
|
+
alias: {
|
|
113
|
+
/**
|
|
114
|
+
* twin.macro inserts styled-components into the code during the compilation process
|
|
115
|
+
* But it will not be installed under the user project.
|
|
116
|
+
* So need to add alias
|
|
117
|
+
*/
|
|
118
|
+
"styled-components": require.resolve("styled-components"),
|
|
119
|
+
/**
|
|
120
|
+
* Compatible with the reference path of the old version of the plugin.
|
|
121
|
+
*/
|
|
122
|
+
[`@${metaName}/runtime/plugins`]: pluginsExportsUtils.getPath(),
|
|
123
|
+
"@meta/runtime/browser$": require.resolve("@modern-js/runtime/browser"),
|
|
124
|
+
"@meta/runtime/react$": require.resolve("@modern-js/runtime/react"),
|
|
125
|
+
"@meta/runtime/context$": require.resolve("@modern-js/runtime/context"),
|
|
126
|
+
"@meta/runtime$": require.resolve("@modern-js/runtime")
|
|
127
|
+
},
|
|
128
|
+
globalVars: {
|
|
129
|
+
"process.env.IS_REACT18": process.env.IS_REACT18
|
|
81
130
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
metaName
|
|
105
|
-
})
|
|
106
|
-
]);
|
|
107
|
-
},
|
|
108
|
-
config() {
|
|
109
|
-
const { appDirectory, metaName, internalDirectory } = api.useAppContext();
|
|
110
|
-
const isReact18 = (0, import_utils.isReact18)(appDirectory);
|
|
111
|
-
process.env.IS_REACT18 = isReact18.toString();
|
|
112
|
-
const pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "plugins");
|
|
113
|
-
return {
|
|
114
|
-
runtime: {},
|
|
115
|
-
runtimeByEntries: {},
|
|
116
|
-
source: {
|
|
117
|
-
alias: {
|
|
118
|
-
/**
|
|
119
|
-
* twin.macro inserts styled-components into the code during the compilation process
|
|
120
|
-
* But it will not be installed under the user project.
|
|
121
|
-
* So need to add alias
|
|
122
|
-
*/
|
|
123
|
-
"styled-components": require.resolve("styled-components"),
|
|
124
|
-
/**
|
|
125
|
-
* Compatible with the reference path of the old version of the plugin.
|
|
126
|
-
*/
|
|
127
|
-
[`@${metaName}/runtime/plugins`]: pluginsExportsUtils.getPath(),
|
|
128
|
-
"@meta/runtime/browser$": require.resolve("@modern-js/runtime/browser"),
|
|
129
|
-
"@meta/runtime/react$": require.resolve("@modern-js/runtime/react"),
|
|
130
|
-
"@meta/runtime/context$": require.resolve("@modern-js/runtime/context"),
|
|
131
|
-
"@meta/runtime$": require.resolve("@modern-js/runtime")
|
|
132
|
-
},
|
|
133
|
-
globalVars: {
|
|
134
|
-
"process.env.IS_REACT18": process.env.IS_REACT18
|
|
131
|
+
},
|
|
132
|
+
tools: {
|
|
133
|
+
styledComponents: {
|
|
134
|
+
// https://github.com/styled-components/babel-plugin-styled-components/issues/287
|
|
135
|
+
topLevelImportPaths: [
|
|
136
|
+
"@modern-js/runtime/styled"
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
bundlerChain: (chain) => {
|
|
140
|
+
chain.module.rule("modern-entry").test(/\.jsx?$/).include.add(import_path.default.resolve(appDirectory, "node_modules", `.${metaName}`)).end().sideEffects(true);
|
|
141
|
+
},
|
|
142
|
+
/**
|
|
143
|
+
* Add IgnorePlugin to fix react-dom/client import error when use react17
|
|
144
|
+
*/
|
|
145
|
+
webpackChain: (chain, { webpack }) => {
|
|
146
|
+
if (!isReact18) {
|
|
147
|
+
chain.plugin("ignore-plugin").use(webpack.IgnorePlugin, [
|
|
148
|
+
{
|
|
149
|
+
resourceRegExp: /^react-dom\/client$/,
|
|
150
|
+
contextRegExp: /./
|
|
151
|
+
}
|
|
152
|
+
]);
|
|
135
153
|
}
|
|
136
154
|
},
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
chain.module.rule("modern-entry").test(/\.jsx?$/).include.add(import_path.default.resolve(appDirectory, "node_modules", `.${metaName}`)).end().sideEffects(true);
|
|
146
|
-
},
|
|
147
|
-
/**
|
|
148
|
-
* Add IgnorePlugin to fix react-dom/client import error when use react17
|
|
149
|
-
*/
|
|
150
|
-
webpackChain: (chain, { webpack }) => {
|
|
151
|
-
if (!isReact18) {
|
|
152
|
-
chain.plugin("ignore-plugin").use(webpack.IgnorePlugin, [
|
|
153
|
-
{
|
|
154
|
-
resourceRegExp: /^react-dom\/client$/,
|
|
155
|
-
contextRegExp: /./
|
|
156
|
-
}
|
|
157
|
-
]);
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
rspack: (_config, { appendPlugins, rspack }) => {
|
|
161
|
-
if (!isReact18) {
|
|
162
|
-
appendPlugins([
|
|
163
|
-
new rspack.IgnorePlugin({
|
|
164
|
-
resourceRegExp: /^react-dom\/client$/,
|
|
165
|
-
contextRegExp: /./
|
|
166
|
-
})
|
|
167
|
-
]);
|
|
168
|
-
}
|
|
155
|
+
rspack: (_config, { appendPlugins, rspack }) => {
|
|
156
|
+
if (!isReact18) {
|
|
157
|
+
appendPlugins([
|
|
158
|
+
new rspack.IgnorePlugin({
|
|
159
|
+
resourceRegExp: /^react-dom\/client$/,
|
|
160
|
+
contextRegExp: /./
|
|
161
|
+
})
|
|
162
|
+
]);
|
|
169
163
|
}
|
|
170
164
|
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
};
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
api.onBeforeRestart(() => {
|
|
169
|
+
(0, import_utils.cleanRequireCache)([
|
|
170
|
+
require.resolve("../state/cli"),
|
|
171
|
+
require.resolve("../router/cli"),
|
|
172
|
+
require.resolve("./ssr")
|
|
173
|
+
]);
|
|
174
|
+
});
|
|
181
175
|
}
|
|
182
176
|
});
|
|
183
177
|
var cli_default = runtimePlugin;
|
|
@@ -58,7 +58,7 @@ const ssrBuilderPlugin = (modernAPI) => ({
|
|
|
58
58
|
setup(api) {
|
|
59
59
|
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig }) => {
|
|
60
60
|
const isServerEnvironment = config.output.target === "node" || name === "workerSSR";
|
|
61
|
-
const userConfig = modernAPI.
|
|
61
|
+
const userConfig = modernAPI.getNormalizedConfig();
|
|
62
62
|
const useLoadablePlugin = (0, import_utils.isUseSSRBundle)(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig);
|
|
63
63
|
return mergeEnvironmentConfig(config, {
|
|
64
64
|
source: {
|
|
@@ -86,61 +86,58 @@ const ssrPlugin = () => ({
|
|
|
86
86
|
"@modern-js/runtime"
|
|
87
87
|
],
|
|
88
88
|
setup: (api) => {
|
|
89
|
-
const appContext = api.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
const appContext = api.getAppContext();
|
|
90
|
+
api.config(() => {
|
|
91
|
+
const { bundlerType = "webpack" } = api.getAppContext();
|
|
92
|
+
const babelHandler = (() => {
|
|
93
|
+
if (bundlerType === "webpack") {
|
|
94
|
+
return (config) => {
|
|
95
|
+
var _config_plugins;
|
|
96
|
+
const userConfig = api.getNormalizedConfig();
|
|
97
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(import_path.default.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
98
|
+
if ((0, import_utils.isUseSSRBundle)(userConfig) && checkUseStringSSR(userConfig)) {
|
|
99
|
+
var _config_plugins1;
|
|
100
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
} else if (bundlerType === "rspack") {
|
|
104
|
+
return (config) => {
|
|
105
|
+
const userConfig = api.useResolvedConfigContext();
|
|
106
|
+
if ((0, import_utils.isUseSSRBundle)(userConfig) && checkUseStringSSR(userConfig)) {
|
|
107
|
+
var _config_plugins, _config_plugins1;
|
|
99
108
|
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(import_path.default.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
100
|
-
|
|
101
|
-
var _config_plugins1;
|
|
102
|
-
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
} else if (bundlerType === "rspack") {
|
|
106
|
-
return (config) => {
|
|
107
|
-
const userConfig = api.useResolvedConfigContext();
|
|
108
|
-
if ((0, import_utils.isUseSSRBundle)(userConfig) && checkUseStringSSR(userConfig)) {
|
|
109
|
-
var _config_plugins, _config_plugins1;
|
|
110
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(import_path.default.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
111
|
-
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
})();
|
|
116
|
-
return {
|
|
117
|
-
builderPlugins: [
|
|
118
|
-
ssrBuilderPlugin(api)
|
|
119
|
-
],
|
|
120
|
-
source: {
|
|
121
|
-
alias: {
|
|
122
|
-
// ensure that all packages use the same storage in @modern-js/runtime-utils/node
|
|
123
|
-
"@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node")
|
|
109
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
124
110
|
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
})();
|
|
114
|
+
return {
|
|
115
|
+
builderPlugins: [
|
|
116
|
+
ssrBuilderPlugin(api)
|
|
117
|
+
],
|
|
118
|
+
source: {
|
|
119
|
+
alias: {
|
|
120
|
+
// ensure that all packages use the same storage in @modern-js/runtime-utils/node
|
|
121
|
+
"@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node")
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
tools: {
|
|
125
|
+
babel: babelHandler,
|
|
126
|
+
bundlerChain: (chain, { isServer }) => {
|
|
127
|
+
if (isServer && appContext.moduleType === "module") {
|
|
128
|
+
chain.output.libraryTarget("module").set("chunkFormat", "module");
|
|
129
|
+
chain.output.library({
|
|
130
|
+
type: "module"
|
|
131
|
+
});
|
|
132
|
+
chain.experiments({
|
|
133
|
+
...chain.get("experiments"),
|
|
134
|
+
outputModule: true
|
|
135
|
+
});
|
|
139
136
|
}
|
|
140
137
|
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
});
|
|
144
141
|
}
|
|
145
142
|
});
|
|
146
143
|
var ssr_default = ssrPlugin;
|
|
@@ -74,13 +74,13 @@ const documentPlugin = () => ({
|
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
const documentEntry = (entryName, templateParameters) => {
|
|
77
|
-
const { entrypoints, internalDirectory, appDirectory } = api.
|
|
77
|
+
const { entrypoints, internalDirectory, appDirectory } = api.getAppContext();
|
|
78
78
|
const documentFilePath = getDocumenByEntryName(entrypoints, entryName, appDirectory);
|
|
79
79
|
if (!documentFilePath) {
|
|
80
80
|
return null;
|
|
81
81
|
}
|
|
82
82
|
return async ({ htmlWebpackPlugin }) => {
|
|
83
|
-
const config = api.
|
|
83
|
+
const config = api.getNormalizedConfig();
|
|
84
84
|
const documentParams = getDocParams({
|
|
85
85
|
config,
|
|
86
86
|
entryName,
|
|
@@ -144,7 +144,7 @@ const documentPlugin = () => ({
|
|
|
144
144
|
}, import_react.default.createElement(Document, null));
|
|
145
145
|
let html = import_server.default.renderToStaticMarkup(HTMLElement);
|
|
146
146
|
debug("entry %s's document jsx rendered html: %o", entryName, html);
|
|
147
|
-
const { partialsByEntrypoint } = api.
|
|
147
|
+
const { partialsByEntrypoint } = api.getAppContext();
|
|
148
148
|
const scripts = [
|
|
149
149
|
htmlWebpackPlugin.tags.headTags.filter((item) => item.tagName === "script").join(""),
|
|
150
150
|
htmlWebpackPlugin.tags.bodyTags.toString()
|
|
@@ -183,38 +183,36 @@ const documentPlugin = () => ({
|
|
|
183
183
|
return finalHtml;
|
|
184
184
|
};
|
|
185
185
|
};
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return {};
|
|
192
|
-
}
|
|
193
|
-
return {
|
|
194
|
-
tools: {
|
|
195
|
-
htmlPlugin: (options, entry) => {
|
|
196
|
-
const hackParameters = typeof (options === null || options === void 0 ? void 0 : options.templateParameters) === "function" ? options === null || options === void 0 ? void 0 : options.templateParameters({}, {}, {}, {}) : {
|
|
197
|
-
...options === null || options === void 0 ? void 0 : options.templateParameters
|
|
198
|
-
};
|
|
199
|
-
const templateContent = documentEntry(
|
|
200
|
-
entry.entryName,
|
|
201
|
-
// options,
|
|
202
|
-
hackParameters
|
|
203
|
-
);
|
|
204
|
-
const documentHtmlOptions = templateContent ? {
|
|
205
|
-
templateContent,
|
|
206
|
-
// Note: the behavior of inject/modify tags in afterTemplateExecution hook will not take effect
|
|
207
|
-
inject: false
|
|
208
|
-
} : {};
|
|
209
|
-
return {
|
|
210
|
-
...options,
|
|
211
|
-
...documentHtmlOptions
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
};
|
|
186
|
+
api.config(() => {
|
|
187
|
+
var _userConfig_tools;
|
|
188
|
+
const userConfig = api.getConfig();
|
|
189
|
+
if (((_userConfig_tools = userConfig.tools) === null || _userConfig_tools === void 0 ? void 0 : _userConfig_tools.htmlPlugin) === false) {
|
|
190
|
+
return {};
|
|
216
191
|
}
|
|
217
|
-
|
|
192
|
+
return {
|
|
193
|
+
tools: {
|
|
194
|
+
htmlPlugin: (options, entry) => {
|
|
195
|
+
const hackParameters = typeof (options === null || options === void 0 ? void 0 : options.templateParameters) === "function" ? options === null || options === void 0 ? void 0 : options.templateParameters({}, {}, {}, {}) : {
|
|
196
|
+
...options === null || options === void 0 ? void 0 : options.templateParameters
|
|
197
|
+
};
|
|
198
|
+
const templateContent = documentEntry(
|
|
199
|
+
entry.entryName,
|
|
200
|
+
// options,
|
|
201
|
+
hackParameters
|
|
202
|
+
);
|
|
203
|
+
const documentHtmlOptions = templateContent ? {
|
|
204
|
+
templateContent,
|
|
205
|
+
// Note: the behavior of inject/modify tags in afterTemplateExecution hook will not take effect
|
|
206
|
+
inject: false
|
|
207
|
+
} : {};
|
|
208
|
+
return {
|
|
209
|
+
...options,
|
|
210
|
+
...documentHtmlOptions
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
});
|
|
218
216
|
}
|
|
219
217
|
});
|
|
220
218
|
var cli_default = documentPlugin;
|
|
@@ -44,14 +44,14 @@ var templates = __toESM(require("./templates"));
|
|
|
44
44
|
var import_utils3 = require("./utils");
|
|
45
45
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
46
46
|
const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
|
47
|
-
const
|
|
47
|
+
const hooks = api.getHooks();
|
|
48
48
|
const isV5 = (0, import_utils.isRouterV5)(config);
|
|
49
49
|
const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
|
|
50
50
|
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
51
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
52
52
|
async function generateEntryCode(entrypoint) {
|
|
53
53
|
const { entryName, isMainEntry, isAutoMount, pageRoutesEntry, nestedRoutesEntry } = entrypoint;
|
|
54
|
-
const { metaName } = api.
|
|
54
|
+
const { metaName } = api.getAppContext();
|
|
55
55
|
if (isAutoMount) {
|
|
56
56
|
if (pageRoutesEntry || nestedRoutesEntry) {
|
|
57
57
|
var _config_output;
|
|
@@ -82,11 +82,11 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
const config2 = api.
|
|
85
|
+
const config2 = api.getNormalizedConfig();
|
|
86
86
|
const ssrByRouteIds = config2.server.ssrByRouteIds || [];
|
|
87
87
|
const clonedRoutes = (0, import_lodash.cloneDeep)(initialRoutes);
|
|
88
88
|
const markedRoutes = ssrByRouteIds.length > 0 ? (0, import_utils2.markRoutes)(clonedRoutes, ssrByRouteIds) : initialRoutes;
|
|
89
|
-
const { routes } = await
|
|
89
|
+
const { routes } = await hooks.modifyFileSystemRoutes.call({
|
|
90
90
|
entrypoint,
|
|
91
91
|
routes: markedRoutes
|
|
92
92
|
});
|
|
@@ -103,7 +103,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
103
103
|
process.exit(1);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
const { code } = await
|
|
106
|
+
const { code } = await hooks.onBeforeGenerateRoutes.call({
|
|
107
107
|
entrypoint,
|
|
108
108
|
code: await templates.fileSystemRoutes({
|
|
109
109
|
metaName,
|
|
@@ -40,13 +40,13 @@ var import_utils = require("./code/utils");
|
|
|
40
40
|
var import_entry = require("./entry");
|
|
41
41
|
let originEntrypoints = [];
|
|
42
42
|
async function handleModifyEntrypoints(api, entrypoints) {
|
|
43
|
-
const config = api.
|
|
43
|
+
const config = api.getNormalizedConfig();
|
|
44
44
|
return (0, import_entry.modifyEntrypoints)(entrypoints, config);
|
|
45
45
|
}
|
|
46
46
|
async function handleGeneratorEntryCode(api, entrypoints) {
|
|
47
|
-
const appContext = api.
|
|
48
|
-
const { internalDirectory } =
|
|
49
|
-
const resolvedConfig = api.
|
|
47
|
+
const appContext = api.getAppContext();
|
|
48
|
+
const { internalDirectory } = appContext;
|
|
49
|
+
const resolvedConfig = api.getNormalizedConfig();
|
|
50
50
|
const { generatorRegisterCode, generateCode } = await Promise.resolve().then(() => __toESM(require("./code")));
|
|
51
51
|
originEntrypoints = (0, import_lodash.cloneDeep)(entrypoints);
|
|
52
52
|
await generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
@@ -65,7 +65,7 @@ async function handleGeneratorEntryCode(api, entrypoints) {
|
|
|
65
65
|
return entrypoints;
|
|
66
66
|
}
|
|
67
67
|
async function handleFileChange(api, e) {
|
|
68
|
-
const appContext = api.
|
|
68
|
+
const appContext = api.getAppContext();
|
|
69
69
|
const { appDirectory, entrypoints } = appContext;
|
|
70
70
|
const { filename, eventType } = e;
|
|
71
71
|
const nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
|
@@ -74,7 +74,7 @@ async function handleFileChange(api, e) {
|
|
|
74
74
|
const absoluteFilePath = import_path.default.resolve(appDirectory, filename);
|
|
75
75
|
const isRouteComponent = isPageFile(absoluteFilePath) && (0, import_utils.isPageComponentFile)(absoluteFilePath);
|
|
76
76
|
if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
|
|
77
|
-
const resolvedConfig = api.
|
|
77
|
+
const resolvedConfig = api.getNormalizedConfig();
|
|
78
78
|
const { generateCode } = await Promise.resolve().then(() => __toESM(require("./code")));
|
|
79
79
|
const entrypoints2 = (0, import_lodash.cloneDeep)(originEntrypoints);
|
|
80
80
|
await generateCode(appContext, resolvedConfig, entrypoints2, api);
|