@modern-js/plugin-router-v5 2.18.2-alpha.0 → 2.19.1
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 +17 -0
- package/dist/cjs/runtime/plugin.js +3 -4
- package/dist/esm/runtime/plugin.js +3 -4
- package/dist/esm-node/runtime/plugin.js +3 -4
- package/dist/types/runtime/plugin.d.ts +1 -1
- package/package.json +10 -10
- package/dist/js/modern/cli/index.js +0 -128
- package/dist/js/modern/cli/types.js +0 -0
- package/dist/js/modern/index.js +0 -5
- package/dist/js/modern/runtime/DefaultNotFound.js +0 -14
- package/dist/js/modern/runtime/index.js +0 -7
- package/dist/js/modern/runtime/plugin.js +0 -106
- package/dist/js/modern/runtime/utils.js +0 -108
- package/dist/js/node/cli/index.js +0 -143
- package/dist/js/node/cli/types.js +0 -0
- package/dist/js/node/index.js +0 -33
- package/dist/js/node/runtime/DefaultNotFound.js +0 -37
- package/dist/js/node/runtime/index.js +0 -29
- package/dist/js/node/runtime/plugin.js +0 -125
- package/dist/js/node/runtime/utils.js +0 -132
- package/dist/js/treeshaking/cli/index.js +0 -151
- package/dist/js/treeshaking/cli/types.js +0 -1
- package/dist/js/treeshaking/index.js +0 -3
- package/dist/js/treeshaking/runtime/DefaultNotFound.js +0 -14
- package/dist/js/treeshaking/runtime/index.js +0 -5
- package/dist/js/treeshaking/runtime/plugin.js +0 -134
- package/dist/js/treeshaking/runtime/utils.js +0 -138
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# @modern-js/plugin-router-v5
|
2
2
|
|
3
|
+
## 2.19.1
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- @modern-js/plugin@2.19.1
|
8
|
+
- @modern-js/types@2.19.1
|
9
|
+
- @modern-js/utils@2.19.1
|
10
|
+
|
11
|
+
## 2.19.0
|
12
|
+
|
13
|
+
### Patch Changes
|
14
|
+
|
15
|
+
- Updated dependencies [1134fe2]
|
16
|
+
- @modern-js/utils@2.19.0
|
17
|
+
- @modern-js/plugin@2.19.0
|
18
|
+
- @modern-js/types@2.19.0
|
19
|
+
|
3
20
|
## 2.18.1
|
4
21
|
|
5
22
|
### Patch Changes
|
@@ -61,7 +61,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
61
61
|
return newObj;
|
62
62
|
}
|
63
63
|
const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
|
64
|
-
const
|
64
|
+
const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
|
65
65
|
const isBrow = (0, _runtime.isBrowser)();
|
66
66
|
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
67
67
|
if (isBrow) {
|
@@ -93,7 +93,7 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
|
|
93
93
|
return (props) => {
|
94
94
|
const runner = api.useHookRunners();
|
95
95
|
const routes = runner.modifyRoutes(originRoutes);
|
96
|
-
routesConfig.routes = routes;
|
96
|
+
routesConfig && (routesConfig.routes = routes);
|
97
97
|
return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Router, {
|
98
98
|
history,
|
99
99
|
children: createRoutes ? /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
@@ -116,8 +116,7 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
|
|
116
116
|
const basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
|
117
117
|
const runner = api.useHookRunners();
|
118
118
|
const routes = runner.modifyRoutes(originRoutes);
|
119
|
-
routesConfig.routes = routes;
|
120
|
-
console.log("originRoutes111111111", originRoutes);
|
119
|
+
routesConfig && (routesConfig.routes = routes);
|
121
120
|
return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.StaticRouter, {
|
122
121
|
basename: basename === "/" ? "" : basename,
|
123
122
|
location: location1,
|
@@ -61,7 +61,7 @@ import { renderRoutes, getLocation, urlJoin } from "./utils";
|
|
61
61
|
import { modifyRoutesHook } from "./hooks";
|
62
62
|
export var routerPlugin = function(param) {
|
63
63
|
var _param_serverBase = param.serverBase, serverBase = _param_serverBase === void 0 ? [] : _param_serverBase, customHistory = param.history, _param_supportHtml5History = param.supportHtml5History, supportHtml5History = _param_supportHtml5History === void 0 ? true : _param_supportHtml5History, routesConfig = param.routesConfig, createRoutes = param.createRoutes, _param_historyOptions = param.historyOptions, historyOptions = _param_historyOptions === void 0 ? {} : _param_historyOptions;
|
64
|
-
var originRoutes = routesConfig.routes;
|
64
|
+
var originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
|
65
65
|
var isBrow = isBrowser();
|
66
66
|
var select = function(pathname) {
|
67
67
|
return serverBase.find(function(baseUrl) {
|
@@ -99,7 +99,7 @@ export var routerPlugin = function(param) {
|
|
99
99
|
return function(props) {
|
100
100
|
var runner = api.useHookRunners();
|
101
101
|
var routes = runner.modifyRoutes(originRoutes);
|
102
|
-
routesConfig.routes = routes;
|
102
|
+
routesConfig && (routesConfig.routes = routes);
|
103
103
|
return /* @__PURE__ */ _jsx(Router, {
|
104
104
|
history: history,
|
105
105
|
children: createRoutes ? /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
|
@@ -120,8 +120,7 @@ export var routerPlugin = function(param) {
|
|
120
120
|
var basename = baseUrl2 === "/" ? urlJoin(baseUrl2, historyOptions.basename) : baseUrl2;
|
121
121
|
var runner = api.useHookRunners();
|
122
122
|
var routes = runner.modifyRoutes(originRoutes);
|
123
|
-
routesConfig.routes = routes;
|
124
|
-
console.log("originRoutes111111111", originRoutes);
|
123
|
+
routesConfig && (routesConfig.routes = routes);
|
125
124
|
return /* @__PURE__ */ _jsx(StaticRouter, {
|
126
125
|
basename: basename === "/" ? "" : basename,
|
127
126
|
location: _$location,
|
@@ -8,7 +8,7 @@ import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
|
|
8
8
|
import { renderRoutes, getLocation, urlJoin } from "./utils";
|
9
9
|
import { modifyRoutesHook } from "./hooks";
|
10
10
|
export const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
|
11
|
-
const
|
11
|
+
const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
|
12
12
|
const isBrow = isBrowser();
|
13
13
|
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
14
14
|
if (isBrow) {
|
@@ -40,7 +40,7 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
|
|
40
40
|
return (props) => {
|
41
41
|
const runner = api.useHookRunners();
|
42
42
|
const routes = runner.modifyRoutes(originRoutes);
|
43
|
-
routesConfig.routes = routes;
|
43
|
+
routesConfig && (routesConfig.routes = routes);
|
44
44
|
return /* @__PURE__ */ _jsx(Router, {
|
45
45
|
history,
|
46
46
|
children: createRoutes ? /* @__PURE__ */ _jsx(App, {
|
@@ -63,8 +63,7 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
|
|
63
63
|
const basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
|
64
64
|
const runner = api.useHookRunners();
|
65
65
|
const routes = runner.modifyRoutes(originRoutes);
|
66
|
-
routesConfig.routes = routes;
|
67
|
-
console.log("originRoutes111111111", originRoutes);
|
66
|
+
routesConfig && (routesConfig.routes = routes);
|
68
67
|
return /* @__PURE__ */ _jsx(StaticRouter, {
|
69
68
|
basename: basename === "/" ? "" : basename,
|
70
69
|
location: location1,
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.19.1",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/cli/index.d.ts",
|
21
21
|
"main": "./dist/cjs/cli/index.js",
|
@@ -59,9 +59,9 @@
|
|
59
59
|
"history": "^4.7.9",
|
60
60
|
"hoist-non-react-statics": "^3.3.2",
|
61
61
|
"react-router-dom": "^5.3.4",
|
62
|
-
"@modern-js/plugin": "2.
|
63
|
-
"@modern-js/types": "2.
|
64
|
-
"@modern-js/utils": "2.
|
62
|
+
"@modern-js/plugin": "2.19.1",
|
63
|
+
"@modern-js/types": "2.19.1",
|
64
|
+
"@modern-js/utils": "2.19.1"
|
65
65
|
},
|
66
66
|
"peerDependencies": {
|
67
67
|
"react": ">=17",
|
@@ -79,12 +79,12 @@
|
|
79
79
|
"react-dom": "^18",
|
80
80
|
"ts-jest": "^29.0.4",
|
81
81
|
"typescript": "^4",
|
82
|
-
"@modern-js/app-tools": "2.
|
83
|
-
"@modern-js/
|
84
|
-
"@modern-js/
|
85
|
-
"@
|
86
|
-
"@
|
87
|
-
"@scripts/jest-config": "2.
|
82
|
+
"@modern-js/app-tools": "2.19.1",
|
83
|
+
"@modern-js/core": "2.19.1",
|
84
|
+
"@modern-js/runtime": "2.19.1",
|
85
|
+
"@modern-js/utils": "2.19.1",
|
86
|
+
"@scripts/build": "2.19.1",
|
87
|
+
"@scripts/jest-config": "2.19.1"
|
88
88
|
},
|
89
89
|
"sideEffects": false,
|
90
90
|
"modernConfig": {},
|
@@ -1,128 +0,0 @@
|
|
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
|
package/dist/js/modern/index.js
DELETED
@@ -1,14 +0,0 @@
|
|
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
|
-
};
|
@@ -1,106 +0,0 @@
|
|
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
|
-
historyOptions = {}
|
41
|
-
}) => {
|
42
|
-
const isBrow = isBrowser();
|
43
|
-
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
44
|
-
return {
|
45
|
-
name: "@modern-js/plugin-router",
|
46
|
-
setup: () => {
|
47
|
-
return {
|
48
|
-
init({ context }, next) {
|
49
|
-
context.router = {
|
50
|
-
useRouteMatch,
|
51
|
-
useLocation
|
52
|
-
};
|
53
|
-
return next({ context });
|
54
|
-
},
|
55
|
-
hoc: ({ App }, next) => {
|
56
|
-
const getRouteApp = () => {
|
57
|
-
var _a;
|
58
|
-
if (isBrow) {
|
59
|
-
const baseUrl = ((_a = window._SERVER_DATA) == null ? void 0 : _a.router.baseUrl) || select(location.pathname);
|
60
|
-
historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
|
61
|
-
const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
|
62
|
-
return (props) => /* @__PURE__ */ jsx(Router, {
|
63
|
-
history,
|
64
|
-
children: /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
|
65
|
-
children: routesConfig ? renderRoutes(routesConfig, props) : null
|
66
|
-
}))
|
67
|
-
});
|
68
|
-
}
|
69
|
-
return (props) => {
|
70
|
-
const runtimeContext = useContext(RuntimeReactContext);
|
71
|
-
const { ssrContext } = runtimeContext;
|
72
|
-
const location2 = getLocation(ssrContext);
|
73
|
-
const routerContext = (ssrContext == null ? void 0 : ssrContext.redirection) || {};
|
74
|
-
const request = ssrContext == null ? void 0 : ssrContext.request;
|
75
|
-
const baseUrl = request == null ? void 0 : request.baseUrl;
|
76
|
-
const basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
|
77
|
-
return /* @__PURE__ */ jsx(StaticRouter, {
|
78
|
-
basename: basename === "/" ? "" : basename,
|
79
|
-
location: location2,
|
80
|
-
context: routerContext,
|
81
|
-
children: /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
|
82
|
-
children: routesConfig ? renderRoutes(routesConfig, props) : null
|
83
|
-
}))
|
84
|
-
});
|
85
|
-
};
|
86
|
-
};
|
87
|
-
let RouteApp = getRouteApp();
|
88
|
-
if (App) {
|
89
|
-
RouteApp = hoistNonReactStatics(RouteApp, App);
|
90
|
-
}
|
91
|
-
if (routesConfig == null ? void 0 : routesConfig.globalApp) {
|
92
|
-
return next({
|
93
|
-
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
94
|
-
});
|
95
|
-
}
|
96
|
-
return next({
|
97
|
-
App: RouteApp
|
98
|
-
});
|
99
|
-
}
|
100
|
-
};
|
101
|
-
}
|
102
|
-
};
|
103
|
-
};
|
104
|
-
export {
|
105
|
-
routerPlugin
|
106
|
-
};
|
@@ -1,108 +0,0 @@
|
|
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
|
-
const Layout = (_a) => {
|
34
|
-
var _b = _a, { Component } = _b, props = __objRest(_b, ["Component"]);
|
35
|
-
const GlobalLayout = routesConfig == null ? void 0 : routesConfig.globalApp;
|
36
|
-
if (!GlobalLayout) {
|
37
|
-
return /* @__PURE__ */ jsx(Component, __spreadValues({}, props));
|
38
|
-
}
|
39
|
-
return /* @__PURE__ */ jsx(GlobalLayout, __spreadValues({
|
40
|
-
Component
|
41
|
-
}, props));
|
42
|
-
};
|
43
|
-
const findMatchedRoute = (pathname) => {
|
44
|
-
var _a;
|
45
|
-
return (_a = routesConfig == null ? void 0 : routesConfig.routes) == null ? void 0 : _a.find((route) => {
|
46
|
-
const info = matchPath(pathname, {
|
47
|
-
path: route.path,
|
48
|
-
exact: route.exact,
|
49
|
-
sensitive: route.sensitive
|
50
|
-
});
|
51
|
-
return Boolean(info);
|
52
|
-
});
|
53
|
-
};
|
54
|
-
return /* @__PURE__ */ jsx(Route, {
|
55
|
-
path: "/",
|
56
|
-
render: (props) => {
|
57
|
-
const matchedRoute = findMatchedRoute(props.location.pathname);
|
58
|
-
if (!matchedRoute) {
|
59
|
-
return /* @__PURE__ */ jsx(DefaultNotFound, {});
|
60
|
-
}
|
61
|
-
return /* @__PURE__ */ jsx(Route, {
|
62
|
-
path: matchedRoute.path,
|
63
|
-
exact: matchedRoute.exact,
|
64
|
-
sensitive: matchedRoute.sensitive,
|
65
|
-
render: (routeProps) => /* @__PURE__ */ jsx(Layout, __spreadValues(__spreadValues({
|
66
|
-
Component: matchedRoute.component
|
67
|
-
}, routeProps), extraProps))
|
68
|
-
});
|
69
|
-
}
|
70
|
-
});
|
71
|
-
}
|
72
|
-
function getLocation(serverContext) {
|
73
|
-
var _a;
|
74
|
-
const { pathname, url } = (serverContext == null ? void 0 : serverContext.request) || {};
|
75
|
-
const cleanUrl = (_a = url == null ? void 0 : url.replace("http://", "")) == null ? void 0 : _a.replace("https://", "");
|
76
|
-
const index = (cleanUrl || "").indexOf(pathname);
|
77
|
-
if (index === -1) {
|
78
|
-
return pathname;
|
79
|
-
}
|
80
|
-
return cleanUrl.substring(index);
|
81
|
-
}
|
82
|
-
const urlJoin = (...parts) => {
|
83
|
-
const separator = "/";
|
84
|
-
const replace = new RegExp(`${separator}{1,}`, "g");
|
85
|
-
return standardSlash(parts.join(separator).replace(replace, separator));
|
86
|
-
};
|
87
|
-
function standardSlash(str) {
|
88
|
-
let addr = str;
|
89
|
-
if (!addr || typeof addr !== "string") {
|
90
|
-
return addr;
|
91
|
-
}
|
92
|
-
if (addr.startsWith(".")) {
|
93
|
-
addr = addr.slice(1);
|
94
|
-
}
|
95
|
-
if (!addr.startsWith("/")) {
|
96
|
-
addr = `/${addr}`;
|
97
|
-
}
|
98
|
-
if (addr.endsWith("/") && addr !== "/") {
|
99
|
-
addr = addr.slice(0, addr.length - 1);
|
100
|
-
}
|
101
|
-
return addr;
|
102
|
-
}
|
103
|
-
export {
|
104
|
-
getLocation,
|
105
|
-
renderRoutes,
|
106
|
-
standardSlash,
|
107
|
-
urlJoin
|
108
|
-
};
|
@@ -1,143 +0,0 @@
|
|
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 = {});
|