@modern-js/plugin-router-v5 0.0.0-next-45d726979 → 0.0.0-next-0bf5ec13d2
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/CHANGELOG.md +3 -3
- package/dist/js/modern/cli/index.js +128 -0
- package/dist/js/modern/cli/types.js +0 -0
- package/dist/js/modern/index.js +5 -0
- package/dist/js/modern/runtime/DefaultNotFound.js +14 -0
- package/dist/js/modern/runtime/index.js +7 -0
- package/dist/js/modern/runtime/plugin.js +111 -0
- package/dist/js/modern/runtime/utils.js +111 -0
- package/dist/js/node/cli/index.js +143 -0
- package/dist/js/node/cli/types.js +0 -0
- package/dist/js/node/index.js +33 -0
- package/dist/js/node/runtime/DefaultNotFound.js +37 -0
- package/dist/js/node/runtime/index.js +29 -0
- package/dist/js/node/runtime/plugin.js +130 -0
- package/dist/js/node/runtime/utils.js +135 -0
- package/dist/js/treeshaking/cli/index.js +151 -0
- package/dist/js/treeshaking/cli/types.js +1 -0
- package/dist/js/treeshaking/index.js +3 -0
- package/dist/js/treeshaking/runtime/DefaultNotFound.js +14 -0
- package/dist/js/treeshaking/runtime/index.js +5 -0
- package/dist/js/treeshaking/runtime/plugin.js +138 -0
- package/dist/js/treeshaking/runtime/utils.js +141 -0
- package/dist/types/runtime/DefaultNotFound.d.ts +1 -0
- package/dist/types/runtime/utils.d.ts +1 -0
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @modern-js/plugin-router-v5
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-0bf5ec13d2
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- @modern-js/types@0.0.0-next-
|
|
8
|
-
- @modern-js/utils@0.0.0-next-
|
|
7
|
+
- @modern-js/types@0.0.0-next-0bf5ec13d2
|
|
8
|
+
- @modern-js/utils@0.0.0-next-0bf5ec13d2
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import {
|
|
21
|
+
getEntryOptions,
|
|
22
|
+
createRuntimeExportsUtils,
|
|
23
|
+
PLUGIN_SCHEMAS
|
|
24
|
+
} from "@modern-js/utils";
|
|
25
|
+
import "./types";
|
|
26
|
+
const PLUGIN_IDENTIFIER = "router";
|
|
27
|
+
const ROUTES_IDENTIFIER = "routes";
|
|
28
|
+
const isV5 = (config) => {
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
return typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
|
|
31
|
+
};
|
|
32
|
+
var cli_default = () => ({
|
|
33
|
+
name: "@modern-js/plugin-router-v5",
|
|
34
|
+
required: ["@modern-js/runtime"],
|
|
35
|
+
setup: (api) => {
|
|
36
|
+
const runtimeConfigMap = /* @__PURE__ */ new Map();
|
|
37
|
+
let pluginsExportsUtils;
|
|
38
|
+
let routerExportsUtils;
|
|
39
|
+
return {
|
|
40
|
+
config() {
|
|
41
|
+
const appContext = api.useAppContext();
|
|
42
|
+
pluginsExportsUtils = createRuntimeExportsUtils(
|
|
43
|
+
appContext.internalDirectory,
|
|
44
|
+
"plugins"
|
|
45
|
+
);
|
|
46
|
+
routerExportsUtils = createRuntimeExportsUtils(
|
|
47
|
+
appContext.internalDirectory,
|
|
48
|
+
"router"
|
|
49
|
+
);
|
|
50
|
+
return {
|
|
51
|
+
source: {
|
|
52
|
+
alias: {
|
|
53
|
+
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
|
|
54
|
+
"@modern-js/runtime/router-v5": routerExportsUtils.getPath()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
validateSchema() {
|
|
60
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-router"];
|
|
61
|
+
},
|
|
62
|
+
modifyEntryImports({ entrypoint, imports }) {
|
|
63
|
+
const { entryName } = entrypoint;
|
|
64
|
+
const userConfig = api.useResolvedConfigContext();
|
|
65
|
+
const { packageName } = api.useAppContext();
|
|
66
|
+
const runtimeConfig = getEntryOptions(
|
|
67
|
+
entryName,
|
|
68
|
+
userConfig.runtime,
|
|
69
|
+
userConfig.runtimeByEntries,
|
|
70
|
+
packageName
|
|
71
|
+
);
|
|
72
|
+
runtimeConfigMap.set(entryName, runtimeConfig);
|
|
73
|
+
if (isV5(userConfig)) {
|
|
74
|
+
imports.push({
|
|
75
|
+
value: "@modern-js/runtime/plugins",
|
|
76
|
+
specifiers: [{ imported: PLUGIN_IDENTIFIER }]
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`should enable runtime.router.mode for entry ${entryName}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
entrypoint,
|
|
85
|
+
imports
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
|
89
|
+
const { entryName, fileSystemRoutes } = entrypoint;
|
|
90
|
+
const { serverRoutes } = api.useAppContext();
|
|
91
|
+
const runtimeConfig = runtimeConfigMap.get(entryName);
|
|
92
|
+
const userConfig = api.useResolvedConfigContext();
|
|
93
|
+
if (isV5(userConfig)) {
|
|
94
|
+
const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
|
|
95
|
+
plugins.push({
|
|
96
|
+
name: PLUGIN_IDENTIFIER,
|
|
97
|
+
options: JSON.stringify(__spreadProps(__spreadValues({
|
|
98
|
+
serverBase
|
|
99
|
+
}, runtimeConfig.router), {
|
|
100
|
+
routesConfig: fileSystemRoutes ? `{ ${ROUTES_IDENTIFIER}, globalApp: App }` : void 0
|
|
101
|
+
})).replace(
|
|
102
|
+
/"routesConfig"\s*:\s*"((\S|\s)+)"/g,
|
|
103
|
+
'"routesConfig": $1,'
|
|
104
|
+
)
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
entrypoint,
|
|
109
|
+
plugins
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
addRuntimeExports() {
|
|
113
|
+
const userConfig = api.useResolvedConfigContext();
|
|
114
|
+
if (isV5(userConfig)) {
|
|
115
|
+
pluginsExportsUtils.addExport(
|
|
116
|
+
`export { default as router } from '@modern-js/plugin-router-v5/runtime'`
|
|
117
|
+
);
|
|
118
|
+
routerExportsUtils == null ? void 0 : routerExportsUtils.addExport(
|
|
119
|
+
`export * from '@modern-js/plugin-router-v5/runtime'`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
export {
|
|
127
|
+
cli_default as default
|
|
128
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
const DefaultNotFound = () => /* @__PURE__ */ jsx("div", {
|
|
3
|
+
style: {
|
|
4
|
+
margin: "150px auto",
|
|
5
|
+
textAlign: "center",
|
|
6
|
+
display: "flex",
|
|
7
|
+
alignItems: "center",
|
|
8
|
+
justifyContent: "center"
|
|
9
|
+
},
|
|
10
|
+
children: "404"
|
|
11
|
+
});
|
|
12
|
+
export {
|
|
13
|
+
DefaultNotFound
|
|
14
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { jsx } from "react/jsx-runtime";
|
|
21
|
+
import { useContext } from "react";
|
|
22
|
+
import {
|
|
23
|
+
createBrowserHistory,
|
|
24
|
+
createHashHistory
|
|
25
|
+
} from "history";
|
|
26
|
+
import {
|
|
27
|
+
Router,
|
|
28
|
+
StaticRouter,
|
|
29
|
+
useRouteMatch,
|
|
30
|
+
useLocation
|
|
31
|
+
} from "react-router-dom";
|
|
32
|
+
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
33
|
+
import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
|
|
34
|
+
import { renderRoutes, getLocation, urlJoin } from "./utils";
|
|
35
|
+
const routerPlugin = ({
|
|
36
|
+
serverBase = [],
|
|
37
|
+
history: customHistory,
|
|
38
|
+
supportHtml5History = true,
|
|
39
|
+
routesConfig,
|
|
40
|
+
createRoutes,
|
|
41
|
+
historyOptions = {}
|
|
42
|
+
}) => {
|
|
43
|
+
const isBrow = isBrowser();
|
|
44
|
+
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
|
45
|
+
return {
|
|
46
|
+
name: "@modern-js/plugin-router",
|
|
47
|
+
setup: () => {
|
|
48
|
+
return {
|
|
49
|
+
init({ context }, next) {
|
|
50
|
+
context.router = {
|
|
51
|
+
useRouteMatch,
|
|
52
|
+
useLocation
|
|
53
|
+
};
|
|
54
|
+
return next({ context });
|
|
55
|
+
},
|
|
56
|
+
hoc: ({ App }, next) => {
|
|
57
|
+
const getRouteApp = () => {
|
|
58
|
+
var _a;
|
|
59
|
+
if (isBrow) {
|
|
60
|
+
const baseUrl = ((_a = window._SERVER_DATA) == null ? void 0 : _a.router.baseUrl) || select(location.pathname);
|
|
61
|
+
historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
|
|
62
|
+
const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
|
|
63
|
+
return (props) => /* @__PURE__ */ jsx(Router, {
|
|
64
|
+
history,
|
|
65
|
+
children: createRoutes ? /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
|
|
66
|
+
Component: createRoutes()
|
|
67
|
+
})) : /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
|
|
68
|
+
children: renderRoutes(routesConfig, props)
|
|
69
|
+
}))
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return (props) => {
|
|
73
|
+
const runtimeContext = useContext(RuntimeReactContext);
|
|
74
|
+
const { ssrContext } = runtimeContext;
|
|
75
|
+
const location2 = getLocation(ssrContext);
|
|
76
|
+
const routerContext = (ssrContext == null ? void 0 : ssrContext.redirection) || {};
|
|
77
|
+
const request = ssrContext == null ? void 0 : ssrContext.request;
|
|
78
|
+
const baseUrl = request == null ? void 0 : request.baseUrl;
|
|
79
|
+
const basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
|
|
80
|
+
return /* @__PURE__ */ jsx(StaticRouter, {
|
|
81
|
+
basename: basename === "/" ? "" : basename,
|
|
82
|
+
location: location2,
|
|
83
|
+
context: routerContext,
|
|
84
|
+
children: createRoutes ? /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
|
|
85
|
+
Component: createRoutes()
|
|
86
|
+
})) : /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
|
|
87
|
+
children: renderRoutes(routesConfig, props)
|
|
88
|
+
}))
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
let RouteApp = getRouteApp();
|
|
93
|
+
if (App) {
|
|
94
|
+
RouteApp = hoistNonReactStatics(RouteApp, App);
|
|
95
|
+
}
|
|
96
|
+
if (routesConfig == null ? void 0 : routesConfig.globalApp) {
|
|
97
|
+
return next({
|
|
98
|
+
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return next({
|
|
102
|
+
App: RouteApp
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
export {
|
|
110
|
+
routerPlugin
|
|
111
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __objRest = (source, exclude) => {
|
|
18
|
+
var target = {};
|
|
19
|
+
for (var prop in source)
|
|
20
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
+
target[prop] = source[prop];
|
|
22
|
+
if (source != null && __getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
import { jsx } from "react/jsx-runtime";
|
|
30
|
+
import { Route, matchPath } from "react-router-dom";
|
|
31
|
+
import { DefaultNotFound } from "./DefaultNotFound";
|
|
32
|
+
function renderRoutes(routesConfig, extraProps = {}) {
|
|
33
|
+
if (!routesConfig) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const Layout = (_a) => {
|
|
37
|
+
var _b = _a, { Component } = _b, props = __objRest(_b, ["Component"]);
|
|
38
|
+
const GlobalLayout = routesConfig == null ? void 0 : routesConfig.globalApp;
|
|
39
|
+
if (!GlobalLayout) {
|
|
40
|
+
return /* @__PURE__ */ jsx(Component, __spreadValues({}, props));
|
|
41
|
+
}
|
|
42
|
+
return /* @__PURE__ */ jsx(GlobalLayout, __spreadValues({
|
|
43
|
+
Component
|
|
44
|
+
}, props));
|
|
45
|
+
};
|
|
46
|
+
const findMatchedRoute = (pathname) => {
|
|
47
|
+
var _a;
|
|
48
|
+
return (_a = routesConfig == null ? void 0 : routesConfig.routes) == null ? void 0 : _a.find((route) => {
|
|
49
|
+
const info = matchPath(pathname, {
|
|
50
|
+
path: route.path,
|
|
51
|
+
exact: route.exact,
|
|
52
|
+
sensitive: route.sensitive
|
|
53
|
+
});
|
|
54
|
+
return Boolean(info);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
return /* @__PURE__ */ jsx(Route, {
|
|
58
|
+
path: "/",
|
|
59
|
+
render: (props) => {
|
|
60
|
+
const matchedRoute = findMatchedRoute(props.location.pathname);
|
|
61
|
+
if (!matchedRoute) {
|
|
62
|
+
return /* @__PURE__ */ jsx(DefaultNotFound, {});
|
|
63
|
+
}
|
|
64
|
+
return /* @__PURE__ */ jsx(Route, {
|
|
65
|
+
path: matchedRoute.path,
|
|
66
|
+
exact: matchedRoute.exact,
|
|
67
|
+
sensitive: matchedRoute.sensitive,
|
|
68
|
+
render: (routeProps) => /* @__PURE__ */ jsx(Layout, __spreadValues(__spreadValues({
|
|
69
|
+
Component: matchedRoute.component
|
|
70
|
+
}, routeProps), extraProps))
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function getLocation(serverContext) {
|
|
76
|
+
var _a;
|
|
77
|
+
const { pathname, url } = (serverContext == null ? void 0 : serverContext.request) || {};
|
|
78
|
+
const cleanUrl = (_a = url == null ? void 0 : url.replace("http://", "")) == null ? void 0 : _a.replace("https://", "");
|
|
79
|
+
const index = (cleanUrl || "").indexOf(pathname);
|
|
80
|
+
if (index === -1) {
|
|
81
|
+
return pathname;
|
|
82
|
+
}
|
|
83
|
+
return cleanUrl.substring(index);
|
|
84
|
+
}
|
|
85
|
+
const urlJoin = (...parts) => {
|
|
86
|
+
const separator = "/";
|
|
87
|
+
const replace = new RegExp(`${separator}{1,}`, "g");
|
|
88
|
+
return standardSlash(parts.join(separator).replace(replace, separator));
|
|
89
|
+
};
|
|
90
|
+
function standardSlash(str) {
|
|
91
|
+
let addr = str;
|
|
92
|
+
if (!addr || typeof addr !== "string") {
|
|
93
|
+
return addr;
|
|
94
|
+
}
|
|
95
|
+
if (addr.startsWith(".")) {
|
|
96
|
+
addr = addr.slice(1);
|
|
97
|
+
}
|
|
98
|
+
if (!addr.startsWith("/")) {
|
|
99
|
+
addr = `/${addr}`;
|
|
100
|
+
}
|
|
101
|
+
if (addr.endsWith("/") && addr !== "/") {
|
|
102
|
+
addr = addr.slice(0, addr.length - 1);
|
|
103
|
+
}
|
|
104
|
+
return addr;
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
getLocation,
|
|
108
|
+
renderRoutes,
|
|
109
|
+
standardSlash,
|
|
110
|
+
urlJoin
|
|
111
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
var cli_exports = {};
|
|
36
|
+
__export(cli_exports, {
|
|
37
|
+
default: () => cli_default
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(cli_exports);
|
|
40
|
+
var import_utils = require("@modern-js/utils");
|
|
41
|
+
var import_types2 = require("./types");
|
|
42
|
+
const PLUGIN_IDENTIFIER = "router";
|
|
43
|
+
const ROUTES_IDENTIFIER = "routes";
|
|
44
|
+
const isV5 = (config) => {
|
|
45
|
+
var _a, _b, _c;
|
|
46
|
+
return typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
|
|
47
|
+
};
|
|
48
|
+
var cli_default = () => ({
|
|
49
|
+
name: "@modern-js/plugin-router-v5",
|
|
50
|
+
required: ["@modern-js/runtime"],
|
|
51
|
+
setup: (api) => {
|
|
52
|
+
const runtimeConfigMap = /* @__PURE__ */ new Map();
|
|
53
|
+
let pluginsExportsUtils;
|
|
54
|
+
let routerExportsUtils;
|
|
55
|
+
return {
|
|
56
|
+
config() {
|
|
57
|
+
const appContext = api.useAppContext();
|
|
58
|
+
pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(
|
|
59
|
+
appContext.internalDirectory,
|
|
60
|
+
"plugins"
|
|
61
|
+
);
|
|
62
|
+
routerExportsUtils = (0, import_utils.createRuntimeExportsUtils)(
|
|
63
|
+
appContext.internalDirectory,
|
|
64
|
+
"router"
|
|
65
|
+
);
|
|
66
|
+
return {
|
|
67
|
+
source: {
|
|
68
|
+
alias: {
|
|
69
|
+
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
|
|
70
|
+
"@modern-js/runtime/router-v5": routerExportsUtils.getPath()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
validateSchema() {
|
|
76
|
+
return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-router"];
|
|
77
|
+
},
|
|
78
|
+
modifyEntryImports({ entrypoint, imports }) {
|
|
79
|
+
const { entryName } = entrypoint;
|
|
80
|
+
const userConfig = api.useResolvedConfigContext();
|
|
81
|
+
const { packageName } = api.useAppContext();
|
|
82
|
+
const runtimeConfig = (0, import_utils.getEntryOptions)(
|
|
83
|
+
entryName,
|
|
84
|
+
userConfig.runtime,
|
|
85
|
+
userConfig.runtimeByEntries,
|
|
86
|
+
packageName
|
|
87
|
+
);
|
|
88
|
+
runtimeConfigMap.set(entryName, runtimeConfig);
|
|
89
|
+
if (isV5(userConfig)) {
|
|
90
|
+
imports.push({
|
|
91
|
+
value: "@modern-js/runtime/plugins",
|
|
92
|
+
specifiers: [{ imported: PLUGIN_IDENTIFIER }]
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`should enable runtime.router.mode for entry ${entryName}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
entrypoint,
|
|
101
|
+
imports
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
|
105
|
+
const { entryName, fileSystemRoutes } = entrypoint;
|
|
106
|
+
const { serverRoutes } = api.useAppContext();
|
|
107
|
+
const runtimeConfig = runtimeConfigMap.get(entryName);
|
|
108
|
+
const userConfig = api.useResolvedConfigContext();
|
|
109
|
+
if (isV5(userConfig)) {
|
|
110
|
+
const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
|
|
111
|
+
plugins.push({
|
|
112
|
+
name: PLUGIN_IDENTIFIER,
|
|
113
|
+
options: JSON.stringify(__spreadProps(__spreadValues({
|
|
114
|
+
serverBase
|
|
115
|
+
}, runtimeConfig.router), {
|
|
116
|
+
routesConfig: fileSystemRoutes ? `{ ${ROUTES_IDENTIFIER}, globalApp: App }` : void 0
|
|
117
|
+
})).replace(
|
|
118
|
+
/"routesConfig"\s*:\s*"((\S|\s)+)"/g,
|
|
119
|
+
'"routesConfig": $1,'
|
|
120
|
+
)
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
entrypoint,
|
|
125
|
+
plugins
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
addRuntimeExports() {
|
|
129
|
+
const userConfig = api.useResolvedConfigContext();
|
|
130
|
+
if (isV5(userConfig)) {
|
|
131
|
+
pluginsExportsUtils.addExport(
|
|
132
|
+
`export { default as router } from '@modern-js/plugin-router-v5/runtime'`
|
|
133
|
+
);
|
|
134
|
+
routerExportsUtils == null ? void 0 : routerExportsUtils.addExport(
|
|
135
|
+
`export * from '@modern-js/plugin-router-v5/runtime'`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
+
0 && (module.exports = {});
|
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var src_exports = {};
|
|
26
|
+
__export(src_exports, {
|
|
27
|
+
default: () => import_runtime.default
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(src_exports);
|
|
30
|
+
var import_runtime = __toESM(require("./runtime"));
|
|
31
|
+
__reExport(src_exports, require("./runtime"), module.exports);
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var DefaultNotFound_exports = {};
|
|
19
|
+
__export(DefaultNotFound_exports, {
|
|
20
|
+
DefaultNotFound: () => DefaultNotFound
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(DefaultNotFound_exports);
|
|
23
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
+
const DefaultNotFound = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
25
|
+
style: {
|
|
26
|
+
margin: "150px auto",
|
|
27
|
+
textAlign: "center",
|
|
28
|
+
display: "flex",
|
|
29
|
+
alignItems: "center",
|
|
30
|
+
justifyContent: "center"
|
|
31
|
+
},
|
|
32
|
+
children: "404"
|
|
33
|
+
});
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
DefaultNotFound
|
|
37
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var runtime_exports = {};
|
|
20
|
+
__export(runtime_exports, {
|
|
21
|
+
default: () => runtime_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
24
|
+
var import_plugin = require("./plugin");
|
|
25
|
+
__reExport(runtime_exports, require("react-router-dom"), module.exports);
|
|
26
|
+
__reExport(runtime_exports, require("history"), module.exports);
|
|
27
|
+
var runtime_default = import_plugin.routerPlugin;
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {});
|