@modern-js/runtime 2.65.5 → 2.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/index.js +2 -7
- package/dist/cjs/router/cli/code/index.js +3 -4
- package/dist/cjs/router/cli/code/templates.js +3 -0
- package/dist/cjs/router/cli/entry.js +2 -2
- package/dist/cjs/router/cli/handler.js +6 -7
- package/dist/cjs/router/cli/index.js +12 -10
- package/dist/esm/cli/index.js +1 -5
- package/dist/esm/router/cli/code/index.js +6 -7
- package/dist/esm/router/cli/code/templates.js +13 -6
- package/dist/esm/router/cli/entry.js +3 -4
- package/dist/esm/router/cli/handler.js +9 -11
- package/dist/esm/router/cli/index.js +13 -11
- package/dist/esm-node/cli/index.js +1 -5
- package/dist/esm-node/router/cli/code/index.js +4 -5
- package/dist/esm-node/router/cli/code/templates.js +3 -0
- package/dist/esm-node/router/cli/entry.js +3 -3
- package/dist/esm-node/router/cli/handler.js +6 -7
- package/dist/esm-node/router/cli/index.js +13 -11
- package/dist/types/cli/code.d.ts +1 -1
- package/dist/types/cli/index.d.ts +3 -4
- package/dist/types/cli/ssr/index.d.ts +1 -1
- package/dist/types/cli/template.d.ts +8 -8
- package/dist/types/common.d.ts +2 -8
- package/dist/types/config.d.ts +0 -2
- package/dist/types/core/compat/requestContext.d.ts +4 -7
- package/dist/types/core/context/index.d.ts +0 -1
- package/dist/types/core/context/monitors/index.server.d.ts +1 -1
- package/dist/types/core/context/runtime.d.ts +0 -4
- package/dist/types/core/loader/useLoader.d.ts +2 -2
- package/dist/types/core/plugin/base.d.ts +0 -1
- package/dist/types/core/server/shared.d.ts +0 -1
- package/dist/types/core/server/utils.d.ts +9 -1
- package/dist/types/document/Script.d.ts +0 -1
- package/dist/types/document/Title.d.ts +0 -1
- package/dist/types/document/cli/index.d.ts +1 -1
- package/dist/types/index.d.ts +1 -2
- package/dist/types/router/cli/code/index.d.ts +1 -1
- package/dist/types/router/cli/code/templates.d.ts +5 -5
- package/dist/types/router/cli/code/utils.d.ts +1 -1
- package/dist/types/router/cli/entry.d.ts +1 -1
- package/dist/types/router/cli/handler.d.ts +3 -3
- package/dist/types/router/cli/index.d.ts +1 -1
- package/dist/types/router/runtime/DeferredDataScripts.node.d.ts +0 -1
- package/dist/types/router/runtime/hooks.d.ts +2 -2
- package/dist/types/router/runtime/routeModule.d.ts +0 -1
- package/dist/types/router/runtime/types.d.ts +0 -1
- package/dist/types/router/runtime/withRouter.d.ts +1 -1
- package/package.json +12 -27
- package/types/index.d.ts +1 -13
- package/types/router.d.ts +0 -1
- package/dist/cjs/state/cli/index.js +0 -62
- package/dist/cjs/state/index.js +0 -43
- package/dist/cjs/state/plugins.js +0 -50
- package/dist/cjs/state/runtime/index.js +0 -42
- package/dist/cjs/state/runtime/plugin.js +0 -95
- package/dist/esm/state/cli/index.js +0 -41
- package/dist/esm/state/index.js +0 -7
- package/dist/esm/state/plugins.js +0 -19
- package/dist/esm/state/runtime/index.js +0 -6
- package/dist/esm/state/runtime/plugin.js +0 -93
- package/dist/esm-node/state/cli/index.js +0 -38
- package/dist/esm-node/state/index.js +0 -7
- package/dist/esm-node/state/plugins.js +0 -13
- package/dist/esm-node/state/runtime/index.js +0 -6
- package/dist/esm-node/state/runtime/plugin.js +0 -69
- package/dist/types/state/cli/index.d.ts +0 -3
- package/dist/types/state/index.d.ts +0 -3
- package/dist/types/state/plugins.d.ts +0 -4
- package/dist/types/state/runtime/index.d.ts +0 -3
- package/dist/types/state/runtime/plugin.d.ts +0 -11
- package/types/model.d.ts +0 -7
package/dist/cjs/cli/index.js
CHANGED
|
@@ -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
|
});
|
|
@@ -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
|
|
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 (!
|
|
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,
|
|
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 (
|
|
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(
|
|
43
|
-
|
|
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 {
|
|
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 (
|
|
62
|
+
if ((nestedRoutesEntry || pageRoutesEntry) && !isRouterV5) {
|
|
60
63
|
plugins.push({
|
|
61
64
|
name: "router",
|
|
62
|
-
path: `@${
|
|
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)(
|
|
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
|
|
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 (!
|
|
110
|
-
pluginsExportsUtils.addExport(`export { default as router } from '@${
|
|
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;
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -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
|
};
|
|
@@ -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,
|
|
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,
|
|
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 (!(!
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
501
|
+
4
|
|
504
502
|
];
|
|
505
|
-
case
|
|
503
|
+
case 3:
|
|
506
504
|
imports.push("let appConfig;");
|
|
507
505
|
imports.push("let appInit;");
|
|
508
|
-
_state.label =
|
|
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
|
|
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
|
|
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(
|
|
9
|
+
function handleModifyEntrypoints(isRouterV5, entrypoints) {
|
|
10
10
|
return _handleModifyEntrypoints.apply(this, arguments);
|
|
11
11
|
}
|
|
12
12
|
function _handleModifyEntrypoints() {
|
|
13
|
-
_handleModifyEntrypoints = _async_to_generator(function(
|
|
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,
|
|
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
|
|
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
|
|
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 (
|
|
37
|
+
if ((nestedRoutesEntry || pageRoutesEntry) && !isRouterV5) {
|
|
35
38
|
plugins.push({
|
|
36
39
|
name: "router",
|
|
37
|
-
path: "@".concat(
|
|
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(
|
|
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
|
|
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 (!
|
|
125
|
-
pluginsExportsUtils.addExport("export { default as router } from '@".concat(
|
|
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
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { fs, getEntryOptions,
|
|
2
|
+
import { fs, getEntryOptions, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
|
|
3
3
|
import { filterRoutesForServer, filterRoutesLoader, markRoutes } from "@modern-js/utils";
|
|
4
4
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
5
5
|
import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME } from "../../../cli/constants";
|
|
@@ -8,11 +8,10 @@ import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
|
8
8
|
import { walk } from "./nestedRoutes";
|
|
9
9
|
import * as templates from "./templates";
|
|
10
10
|
import { getServerCombinedModueFile, getServerLoadersFile } from "./utils";
|
|
11
|
-
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
11
|
+
const generateCode = async (appContext, config, entrypoints, api, isRouterV5) => {
|
|
12
12
|
const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
|
13
13
|
const hooks = api.getHooks();
|
|
14
|
-
const
|
|
15
|
-
const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
14
|
+
const getRoutes = isRouterV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
16
15
|
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
16
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
18
17
|
async function generateEntryCode(entrypoint) {
|
|
@@ -32,7 +31,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
32
31
|
internalDirAlias
|
|
33
32
|
});
|
|
34
33
|
}
|
|
35
|
-
if (!
|
|
34
|
+
if (!isRouterV5 && entrypoint.nestedRoutesEntry) {
|
|
36
35
|
nestedRoutes = await walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
|
|
37
36
|
name: internalSrcAlias,
|
|
38
37
|
basename: srcDirectory
|
|
@@ -394,6 +394,9 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
|
|
|
394
394
|
} else {
|
|
395
395
|
imports.push(`let appInit;`);
|
|
396
396
|
}
|
|
397
|
+
} else {
|
|
398
|
+
imports.push(`let appConfig;`);
|
|
399
|
+
imports.push(`let appInit;`);
|
|
397
400
|
}
|
|
398
401
|
} else {
|
|
399
402
|
imports.push(`let appConfig;`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { fs, JS_EXTENSIONS, findExists
|
|
2
|
+
import { fs, JS_EXTENSIONS, findExists } from "@modern-js/utils";
|
|
3
3
|
import { hasApp } from "../../cli/entry";
|
|
4
4
|
import { FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, NESTED_ROUTES_DIR, PAGES_DIR_NAME } from "./constants";
|
|
5
5
|
const hasPages = (dir) => fs.existsSync(path.join(dir, PAGES_DIR_NAME));
|
|
@@ -13,14 +13,14 @@ const isRouteEntry = (dir) => {
|
|
|
13
13
|
}
|
|
14
14
|
return false;
|
|
15
15
|
};
|
|
16
|
-
const modifyEntrypoints = (entrypoints,
|
|
16
|
+
const modifyEntrypoints = (entrypoints, isRouterV5) => {
|
|
17
17
|
return entrypoints.map((entrypoint) => {
|
|
18
18
|
if (!entrypoint.isAutoMount) {
|
|
19
19
|
return entrypoint;
|
|
20
20
|
}
|
|
21
21
|
if (entrypoint === null || entrypoint === void 0 ? void 0 : entrypoint.isCustomSourceEntry) {
|
|
22
22
|
if (entrypoint.fileSystemRoutes) {
|
|
23
|
-
if (isRouterV5
|
|
23
|
+
if (isRouterV5) {
|
|
24
24
|
throw Error("Custom entries with conventional routing not support use react router v5!");
|
|
25
25
|
}
|
|
26
26
|
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
@@ -4,17 +4,16 @@ import * as templates from "./code/templates";
|
|
|
4
4
|
import { isPageComponentFile } from "./code/utils";
|
|
5
5
|
import { modifyEntrypoints } from "./entry";
|
|
6
6
|
let originEntrypoints = [];
|
|
7
|
-
async function handleModifyEntrypoints(
|
|
8
|
-
|
|
9
|
-
return modifyEntrypoints(entrypoints, config);
|
|
7
|
+
async function handleModifyEntrypoints(isRouterV5, entrypoints) {
|
|
8
|
+
return modifyEntrypoints(entrypoints, isRouterV5);
|
|
10
9
|
}
|
|
11
|
-
async function handleGeneratorEntryCode(api, entrypoints) {
|
|
10
|
+
async function handleGeneratorEntryCode(api, entrypoints, isRouterV5) {
|
|
12
11
|
const appContext = api.getAppContext();
|
|
13
12
|
const { internalDirectory } = appContext;
|
|
14
13
|
const resolvedConfig = api.getNormalizedConfig();
|
|
15
14
|
const { generatorRegisterCode, generateCode } = await import("./code");
|
|
16
15
|
originEntrypoints = cloneDeep(entrypoints);
|
|
17
|
-
await generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
16
|
+
await generateCode(appContext, resolvedConfig, entrypoints, api, isRouterV5);
|
|
18
17
|
await Promise.all(entrypoints.map(async (entrypoint) => {
|
|
19
18
|
if (entrypoint.nestedRoutesEntry || entrypoint.pageRoutesEntry) {
|
|
20
19
|
var _entrypoint_fileSystemRoutes;
|
|
@@ -30,7 +29,7 @@ async function handleGeneratorEntryCode(api, entrypoints) {
|
|
|
30
29
|
}));
|
|
31
30
|
return entrypoints;
|
|
32
31
|
}
|
|
33
|
-
async function handleFileChange(api, e) {
|
|
32
|
+
async function handleFileChange(api, isRouterV5, e) {
|
|
34
33
|
const appContext = api.getAppContext();
|
|
35
34
|
const { appDirectory, entrypoints } = appContext;
|
|
36
35
|
const { filename, eventType } = e;
|
|
@@ -43,7 +42,7 @@ async function handleFileChange(api, e) {
|
|
|
43
42
|
const resolvedConfig = api.getNormalizedConfig();
|
|
44
43
|
const { generateCode } = await import("./code");
|
|
45
44
|
const entrypoints2 = cloneDeep(originEntrypoints);
|
|
46
|
-
await generateCode(appContext, resolvedConfig, entrypoints2, api);
|
|
45
|
+
await generateCode(appContext, resolvedConfig, entrypoints2, api, isRouterV5);
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
export {
|