@modern-js/plugin-router-v5 2.15.0 → 2.16.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/CHANGELOG.md +14 -0
- package/dist/cjs/cli/index.js +88 -116
- package/dist/cjs/cli/types.js +4 -0
- package/dist/cjs/index.js +26 -36
- package/dist/cjs/runtime/DefaultNotFound.js +23 -38
- package/dist/cjs/runtime/index.js +24 -28
- package/dist/cjs/runtime/plugin.js +103 -79
- package/dist/cjs/runtime/utils.js +54 -67
- package/dist/esm/cli/index.js +134 -134
- package/dist/esm/cli/types.js +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/runtime/DefaultNotFound.js +12 -13
- package/dist/esm/runtime/index.js +1 -2
- package/dist/esm/runtime/plugin.js +124 -125
- package/dist/esm/runtime/utils.js +130 -126
- package/dist/esm-node/cli/index.js +79 -99
- package/dist/esm-node/cli/types.js +1 -0
- package/dist/esm-node/index.js +1 -4
- package/dist/esm-node/runtime/DefaultNotFound.js +11 -17
- package/dist/esm-node/runtime/index.js +1 -4
- package/dist/esm-node/runtime/plugin.js +36 -40
- package/dist/esm-node/runtime/utils.js +35 -45
- package/package.json +14 -10
@@ -1,46 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
6
|
for (var name in all)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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 utils_exports = {};
|
19
|
-
__export(utils_exports, {
|
20
|
-
getLocation: () => getLocation,
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
21
13
|
renderRoutes: () => renderRoutes,
|
22
|
-
|
23
|
-
urlJoin: () => urlJoin
|
14
|
+
getLocation: () => getLocation,
|
15
|
+
urlJoin: () => urlJoin,
|
16
|
+
standardSlash: () => standardSlash
|
24
17
|
});
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
const _jsxruntime = require("react/jsx-runtime");
|
19
|
+
const _react = /* @__PURE__ */ _interop_require_default(require("react"));
|
20
|
+
const _reactrouterdom = require("react-router-dom");
|
21
|
+
const _DefaultNotFound = require("./DefaultNotFound");
|
22
|
+
function _interop_require_default(obj) {
|
23
|
+
return obj && obj.__esModule ? obj : {
|
24
|
+
default: obj
|
25
|
+
};
|
26
|
+
}
|
29
27
|
function renderRoutes(routesConfig, extraProps = {}) {
|
30
28
|
if (!routesConfig) {
|
31
29
|
return null;
|
32
30
|
}
|
33
31
|
const Layout = ({ Component, ...props }) => {
|
34
|
-
const GlobalLayout = routesConfig
|
32
|
+
const GlobalLayout = routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp;
|
35
33
|
if (!GlobalLayout) {
|
36
|
-
return /* @__PURE__ */ (0,
|
34
|
+
return /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {
|
35
|
+
...props
|
36
|
+
});
|
37
37
|
}
|
38
|
-
return /* @__PURE__ */ (0,
|
38
|
+
return /* @__PURE__ */ (0, _jsxruntime.jsx)(GlobalLayout, {
|
39
|
+
Component,
|
40
|
+
...props
|
41
|
+
});
|
39
42
|
};
|
40
43
|
const findMatchedRoute = (pathname) => {
|
41
|
-
var
|
42
|
-
return
|
43
|
-
const info = (0,
|
44
|
+
var _routesConfig_routes;
|
45
|
+
return routesConfig === null || routesConfig === void 0 ? void 0 : (_routesConfig_routes = routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find((route) => {
|
46
|
+
const info = (0, _reactrouterdom.matchPath)(pathname, {
|
44
47
|
path: route.path,
|
45
48
|
exact: route.exact,
|
46
49
|
sensitive: route.sensitive
|
@@ -48,39 +51,30 @@ function renderRoutes(routesConfig, extraProps = {}) {
|
|
48
51
|
return Boolean(info);
|
49
52
|
});
|
50
53
|
};
|
51
|
-
return /* @__PURE__ */ (0,
|
52
|
-
|
53
|
-
{
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
if (!matchedRoute) {
|
58
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DefaultNotFound.DefaultNotFound, {});
|
59
|
-
}
|
60
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
61
|
-
import_react_router_dom.Route,
|
62
|
-
{
|
63
|
-
path: matchedRoute.path,
|
64
|
-
exact: matchedRoute.exact,
|
65
|
-
sensitive: matchedRoute.sensitive,
|
66
|
-
render: (routeProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
67
|
-
Layout,
|
68
|
-
{
|
69
|
-
Component: matchedRoute.component,
|
70
|
-
...routeProps,
|
71
|
-
...extraProps
|
72
|
-
}
|
73
|
-
)
|
74
|
-
}
|
75
|
-
);
|
54
|
+
return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Route, {
|
55
|
+
path: "/",
|
56
|
+
render: (props) => {
|
57
|
+
const matchedRoute = findMatchedRoute(props.location.pathname);
|
58
|
+
if (!matchedRoute) {
|
59
|
+
return /* @__PURE__ */ (0, _jsxruntime.jsx)(_DefaultNotFound.DefaultNotFound, {});
|
76
60
|
}
|
61
|
+
return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Route, {
|
62
|
+
path: matchedRoute.path,
|
63
|
+
exact: matchedRoute.exact,
|
64
|
+
sensitive: matchedRoute.sensitive,
|
65
|
+
render: (routeProps) => /* @__PURE__ */ (0, _jsxruntime.jsx)(Layout, {
|
66
|
+
Component: matchedRoute.component,
|
67
|
+
...routeProps,
|
68
|
+
...extraProps
|
69
|
+
})
|
70
|
+
});
|
77
71
|
}
|
78
|
-
);
|
72
|
+
});
|
79
73
|
}
|
80
74
|
function getLocation(serverContext) {
|
81
|
-
var
|
82
|
-
const { pathname, url } = (serverContext
|
83
|
-
const cleanUrl = (
|
75
|
+
var _url_replace;
|
76
|
+
const { pathname, url } = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
|
77
|
+
const cleanUrl = (_url_replace = url === null || url === void 0 ? void 0 : url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
|
84
78
|
const index = (cleanUrl || "").indexOf(pathname);
|
85
79
|
if (index === -1) {
|
86
80
|
return pathname;
|
@@ -108,10 +102,3 @@ function standardSlash(str) {
|
|
108
102
|
}
|
109
103
|
return addr;
|
110
104
|
}
|
111
|
-
// Annotate the CommonJS export names for ESM import in node:
|
112
|
-
0 && (module.exports = {
|
113
|
-
getLocation,
|
114
|
-
renderRoutes,
|
115
|
-
standardSlash,
|
116
|
-
urlJoin
|
117
|
-
});
|
package/dist/esm/cli/index.js
CHANGED
@@ -1,147 +1,147 @@
|
|
1
|
-
function
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
function _define_property(obj, key, value) {
|
2
|
+
if (key in obj) {
|
3
|
+
Object.defineProperty(obj, key, {
|
4
|
+
value,
|
5
|
+
enumerable: true,
|
6
|
+
configurable: true,
|
7
|
+
writable: true
|
8
|
+
});
|
9
|
+
} else {
|
10
|
+
obj[key] = value;
|
11
|
+
}
|
12
|
+
return obj;
|
13
13
|
}
|
14
|
-
function
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
23
|
-
ownKeys.forEach(function(key) {
|
24
|
-
_defineProperty(target, key, source[key]);
|
25
|
-
});
|
14
|
+
function _object_spread(target) {
|
15
|
+
for (var i = 1; i < arguments.length; i++) {
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
17
|
+
var ownKeys2 = Object.keys(source);
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
19
|
+
ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
21
|
+
}));
|
26
22
|
}
|
27
|
-
|
23
|
+
ownKeys2.forEach(function(key) {
|
24
|
+
_define_property(target, key, source[key]);
|
25
|
+
});
|
26
|
+
}
|
27
|
+
return target;
|
28
28
|
}
|
29
29
|
function ownKeys(object, enumerableOnly) {
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
}
|
38
|
-
keys.push.apply(keys, symbols);
|
30
|
+
var keys = Object.keys(object);
|
31
|
+
if (Object.getOwnPropertySymbols) {
|
32
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
33
|
+
if (enumerableOnly) {
|
34
|
+
symbols = symbols.filter(function(sym) {
|
35
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
36
|
+
});
|
39
37
|
}
|
40
|
-
|
38
|
+
keys.push.apply(keys, symbols);
|
39
|
+
}
|
40
|
+
return keys;
|
41
41
|
}
|
42
|
-
function
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
42
|
+
function _object_spread_props(target, source) {
|
43
|
+
source = source != null ? source : {};
|
44
|
+
if (Object.getOwnPropertyDescriptors) {
|
45
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
46
|
+
} else {
|
47
|
+
ownKeys(Object(source)).forEach(function(key) {
|
48
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
49
|
+
});
|
50
|
+
}
|
51
|
+
return target;
|
52
52
|
}
|
53
53
|
import { getEntryOptions, createRuntimeExportsUtils, PLUGIN_SCHEMAS, isRouterV5 as isV5 } from "@modern-js/utils";
|
54
54
|
import "./types";
|
55
55
|
var PLUGIN_IDENTIFIER = "router";
|
56
56
|
var ROUTES_IDENTIFIER = "routes";
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
}
|
98
|
-
]
|
99
|
-
});
|
100
|
-
} else {
|
101
|
-
throw new Error("should enable runtime.router.mode for entry ".concat(entryName));
|
102
|
-
}
|
103
|
-
return {
|
104
|
-
entrypoint: entrypoint,
|
105
|
-
imports: imports
|
106
|
-
};
|
107
|
-
},
|
108
|
-
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(param) {
|
109
|
-
var entrypoint = param.entrypoint, plugins = param.plugins;
|
110
|
-
var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
111
|
-
var serverRoutes = api.useAppContext().serverRoutes;
|
112
|
-
var runtimeConfig = runtimeConfigMap.get(entryName);
|
113
|
-
var userConfig = api.useResolvedConfigContext();
|
114
|
-
if (isV5(userConfig)) {
|
115
|
-
var serverBase = serverRoutes.filter(function(route) {
|
116
|
-
return route.entryName === entryName;
|
117
|
-
}).map(function(route) {
|
118
|
-
return route.urlPath;
|
119
|
-
}).sort(function(a, b) {
|
120
|
-
return a.length - b.length > 0 ? -1 : 1;
|
121
|
-
});
|
122
|
-
plugins.push({
|
123
|
-
name: PLUGIN_IDENTIFIER,
|
124
|
-
options: JSON.stringify(_objectSpreadProps(_objectSpread({
|
125
|
-
serverBase: serverBase
|
126
|
-
}, runtimeConfig.router), {
|
127
|
-
routesConfig: fileSystemRoutes ? "{ ".concat(ROUTES_IDENTIFIER, ", globalApp: App }") : void 0
|
128
|
-
})).replace(/"routesConfig"\s*:\s*"((\S|\s)+)"/g, '"routesConfig": $1,')
|
129
|
-
});
|
130
|
-
}
|
131
|
-
return {
|
132
|
-
entrypoint: entrypoint,
|
133
|
-
plugins: plugins
|
134
|
-
};
|
135
|
-
},
|
136
|
-
addRuntimeExports: function addRuntimeExports() {
|
137
|
-
var userConfig = api.useResolvedConfigContext();
|
138
|
-
if (isV5(userConfig)) {
|
139
|
-
pluginsExportsUtils.addExport("export { default as router } from '@modern-js/plugin-router-v5/runtime'");
|
140
|
-
routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport("export * from '@modern-js/plugin-router-v5/runtime'");
|
141
|
-
}
|
57
|
+
export default function() {
|
58
|
+
return {
|
59
|
+
name: "@modern-js/plugin-router-v5",
|
60
|
+
required: [
|
61
|
+
"@modern-js/runtime"
|
62
|
+
],
|
63
|
+
setup: function(api) {
|
64
|
+
var runtimeConfigMap = /* @__PURE__ */ new Map();
|
65
|
+
var pluginsExportsUtils;
|
66
|
+
var routerExportsUtils;
|
67
|
+
return {
|
68
|
+
config: function config() {
|
69
|
+
var appContext = api.useAppContext();
|
70
|
+
pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "plugins");
|
71
|
+
routerExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "router");
|
72
|
+
return {
|
73
|
+
source: {
|
74
|
+
alias: {
|
75
|
+
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
|
76
|
+
"@modern-js/runtime/router-v5": routerExportsUtils.getPath()
|
77
|
+
}
|
78
|
+
}
|
79
|
+
};
|
80
|
+
},
|
81
|
+
validateSchema: function validateSchema() {
|
82
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-router"];
|
83
|
+
},
|
84
|
+
modifyEntryImports: function modifyEntryImports(param) {
|
85
|
+
var entrypoint = param.entrypoint, imports = param.imports;
|
86
|
+
var entryName = entrypoint.entryName;
|
87
|
+
var userConfig = api.useResolvedConfigContext();
|
88
|
+
var packageName = api.useAppContext().packageName;
|
89
|
+
var runtimeConfig = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
90
|
+
runtimeConfigMap.set(entryName, runtimeConfig);
|
91
|
+
if (isV5(userConfig)) {
|
92
|
+
imports.push({
|
93
|
+
value: "@modern-js/runtime/plugins",
|
94
|
+
specifiers: [
|
95
|
+
{
|
96
|
+
imported: PLUGIN_IDENTIFIER
|
142
97
|
}
|
143
|
-
|
98
|
+
]
|
99
|
+
});
|
100
|
+
} else {
|
101
|
+
throw new Error("should enable runtime.router.mode for entry ".concat(entryName));
|
102
|
+
}
|
103
|
+
return {
|
104
|
+
entrypoint,
|
105
|
+
imports
|
106
|
+
};
|
107
|
+
},
|
108
|
+
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(param) {
|
109
|
+
var entrypoint = param.entrypoint, plugins = param.plugins;
|
110
|
+
var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
111
|
+
var serverRoutes = api.useAppContext().serverRoutes;
|
112
|
+
var runtimeConfig = runtimeConfigMap.get(entryName);
|
113
|
+
var userConfig = api.useResolvedConfigContext();
|
114
|
+
if (isV5(userConfig)) {
|
115
|
+
var serverBase = serverRoutes.filter(function(route) {
|
116
|
+
return route.entryName === entryName;
|
117
|
+
}).map(function(route) {
|
118
|
+
return route.urlPath;
|
119
|
+
}).sort(function(a, b) {
|
120
|
+
return a.length - b.length > 0 ? -1 : 1;
|
121
|
+
});
|
122
|
+
plugins.push({
|
123
|
+
name: PLUGIN_IDENTIFIER,
|
124
|
+
options: JSON.stringify(_object_spread_props(_object_spread({
|
125
|
+
serverBase
|
126
|
+
}, runtimeConfig.router), {
|
127
|
+
routesConfig: fileSystemRoutes ? "{ ".concat(ROUTES_IDENTIFIER, ", globalApp: App }") : void 0
|
128
|
+
})).replace(/"routesConfig"\s*:\s*"((\S|\s)+)"/g, '"routesConfig": $1,')
|
129
|
+
});
|
130
|
+
}
|
131
|
+
return {
|
132
|
+
entrypoint,
|
133
|
+
plugins
|
134
|
+
};
|
135
|
+
},
|
136
|
+
addRuntimeExports: function addRuntimeExports() {
|
137
|
+
var userConfig = api.useResolvedConfigContext();
|
138
|
+
if (isV5(userConfig)) {
|
139
|
+
pluginsExportsUtils.addExport("export { default as router } from '@modern-js/plugin-router-v5/runtime'");
|
140
|
+
routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport("export * from '@modern-js/plugin-router-v5/runtime'");
|
141
|
+
}
|
144
142
|
}
|
145
|
-
|
146
|
-
}
|
147
|
-
|
143
|
+
};
|
144
|
+
}
|
145
|
+
};
|
146
|
+
}
|
147
|
+
;
|
package/dist/esm/cli/types.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
export {};
|
package/dist/esm/index.js
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
2
|
-
var DefaultNotFound = function() {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
export var DefaultNotFound = function() {
|
3
|
+
return /* @__PURE__ */ _jsx("div", {
|
4
|
+
style: {
|
5
|
+
margin: "150px auto",
|
6
|
+
textAlign: "center",
|
7
|
+
display: "flex",
|
8
|
+
alignItems: "center",
|
9
|
+
justifyContent: "center"
|
10
|
+
},
|
11
|
+
children: "404"
|
12
|
+
});
|
13
13
|
};
|
14
|
-
export { DefaultNotFound };
|