@modern-js/plugin-router-v5 2.15.0 → 2.17.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 +21 -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
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
# @modern-js/plugin-router-v5
|
2
2
|
|
3
|
+
## 2.17.0
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- @modern-js/types@2.17.0
|
8
|
+
- @modern-js/utils@2.17.0
|
9
|
+
|
10
|
+
## 2.16.0
|
11
|
+
|
12
|
+
### Patch Changes
|
13
|
+
|
14
|
+
- 4e876ab: chore: package.json include the monorepo-relative directory
|
15
|
+
|
16
|
+
chore: 在 package.json 中声明 monorepo 的子路径
|
17
|
+
|
18
|
+
- Updated dependencies [5954330]
|
19
|
+
- Updated dependencies [7596520]
|
20
|
+
- Updated dependencies [4e876ab]
|
21
|
+
- @modern-js/utils@2.16.0
|
22
|
+
- @modern-js/types@2.16.0
|
23
|
+
|
3
24
|
## 2.15.0
|
4
25
|
|
5
26
|
### Patch Changes
|
package/dist/cjs/cli/index.js
CHANGED
@@ -1,122 +1,94 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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 cli_exports = {};
|
19
|
-
__export(cli_exports, {
|
20
|
-
default: () => cli_default
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "default", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => _default
|
21
8
|
});
|
22
|
-
|
23
|
-
|
24
|
-
var import_types2 = require("./types");
|
9
|
+
const _utils = require("@modern-js/utils");
|
10
|
+
require("./types");
|
25
11
|
const PLUGIN_IDENTIFIER = "router";
|
26
12
|
const ROUTES_IDENTIFIER = "routes";
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
|
49
|
-
"@modern-js/runtime/router-v5": routerExportsUtils.getPath()
|
13
|
+
const _default = () => {
|
14
|
+
return {
|
15
|
+
name: "@modern-js/plugin-router-v5",
|
16
|
+
required: [
|
17
|
+
"@modern-js/runtime"
|
18
|
+
],
|
19
|
+
setup: (api) => {
|
20
|
+
const runtimeConfigMap = /* @__PURE__ */ new Map();
|
21
|
+
let pluginsExportsUtils;
|
22
|
+
let routerExportsUtils;
|
23
|
+
return {
|
24
|
+
config() {
|
25
|
+
const appContext = api.useAppContext();
|
26
|
+
pluginsExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, "plugins");
|
27
|
+
routerExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, "router");
|
28
|
+
return {
|
29
|
+
source: {
|
30
|
+
alias: {
|
31
|
+
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
|
32
|
+
"@modern-js/runtime/router-v5": routerExportsUtils.getPath()
|
33
|
+
}
|
50
34
|
}
|
35
|
+
};
|
36
|
+
},
|
37
|
+
validateSchema() {
|
38
|
+
return _utils.PLUGIN_SCHEMAS["@modern-js/plugin-router"];
|
39
|
+
},
|
40
|
+
modifyEntryImports({ entrypoint, imports }) {
|
41
|
+
const { entryName } = entrypoint;
|
42
|
+
const userConfig = api.useResolvedConfigContext();
|
43
|
+
const { packageName } = api.useAppContext();
|
44
|
+
const runtimeConfig = (0, _utils.getEntryOptions)(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
|
45
|
+
runtimeConfigMap.set(entryName, runtimeConfig);
|
46
|
+
if ((0, _utils.isRouterV5)(userConfig)) {
|
47
|
+
imports.push({
|
48
|
+
value: "@modern-js/runtime/plugins",
|
49
|
+
specifiers: [
|
50
|
+
{
|
51
|
+
imported: PLUGIN_IDENTIFIER
|
52
|
+
}
|
53
|
+
]
|
54
|
+
});
|
55
|
+
} else {
|
56
|
+
throw new Error(`should enable runtime.router.mode for entry ${entryName}`);
|
57
|
+
}
|
58
|
+
return {
|
59
|
+
entrypoint,
|
60
|
+
imports
|
61
|
+
};
|
62
|
+
},
|
63
|
+
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
64
|
+
const { entryName, fileSystemRoutes } = entrypoint;
|
65
|
+
const { serverRoutes } = api.useAppContext();
|
66
|
+
const runtimeConfig = runtimeConfigMap.get(entryName);
|
67
|
+
const userConfig = api.useResolvedConfigContext();
|
68
|
+
if ((0, _utils.isRouterV5)(userConfig)) {
|
69
|
+
const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
|
70
|
+
plugins.push({
|
71
|
+
name: PLUGIN_IDENTIFIER,
|
72
|
+
options: JSON.stringify({
|
73
|
+
serverBase,
|
74
|
+
...runtimeConfig.router,
|
75
|
+
routesConfig: fileSystemRoutes ? `{ ${ROUTES_IDENTIFIER}, globalApp: App }` : void 0
|
76
|
+
}).replace(/"routesConfig"\s*:\s*"((\S|\s)+)"/g, '"routesConfig": $1,')
|
77
|
+
});
|
78
|
+
}
|
79
|
+
return {
|
80
|
+
entrypoint,
|
81
|
+
plugins
|
82
|
+
};
|
83
|
+
},
|
84
|
+
addRuntimeExports() {
|
85
|
+
const userConfig = api.useResolvedConfigContext();
|
86
|
+
if ((0, _utils.isRouterV5)(userConfig)) {
|
87
|
+
pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/plugin-router-v5/runtime'`);
|
88
|
+
routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@modern-js/plugin-router-v5/runtime'`);
|
51
89
|
}
|
52
|
-
};
|
53
|
-
},
|
54
|
-
validateSchema() {
|
55
|
-
return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-router"];
|
56
|
-
},
|
57
|
-
modifyEntryImports({ entrypoint, imports }) {
|
58
|
-
const { entryName } = entrypoint;
|
59
|
-
const userConfig = api.useResolvedConfigContext();
|
60
|
-
const { packageName } = api.useAppContext();
|
61
|
-
const runtimeConfig = (0, import_utils.getEntryOptions)(
|
62
|
-
entryName,
|
63
|
-
userConfig.runtime,
|
64
|
-
userConfig.runtimeByEntries,
|
65
|
-
packageName
|
66
|
-
);
|
67
|
-
runtimeConfigMap.set(entryName, runtimeConfig);
|
68
|
-
if ((0, import_utils.isRouterV5)(userConfig)) {
|
69
|
-
imports.push({
|
70
|
-
value: "@modern-js/runtime/plugins",
|
71
|
-
specifiers: [{ imported: PLUGIN_IDENTIFIER }]
|
72
|
-
});
|
73
|
-
} else {
|
74
|
-
throw new Error(
|
75
|
-
`should enable runtime.router.mode for entry ${entryName}`
|
76
|
-
);
|
77
|
-
}
|
78
|
-
return {
|
79
|
-
entrypoint,
|
80
|
-
imports
|
81
|
-
};
|
82
|
-
},
|
83
|
-
modifyEntryRuntimePlugins({ entrypoint, plugins }) {
|
84
|
-
const { entryName, fileSystemRoutes } = entrypoint;
|
85
|
-
const { serverRoutes } = api.useAppContext();
|
86
|
-
const runtimeConfig = runtimeConfigMap.get(entryName);
|
87
|
-
const userConfig = api.useResolvedConfigContext();
|
88
|
-
if ((0, import_utils.isRouterV5)(userConfig)) {
|
89
|
-
const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
|
90
|
-
plugins.push({
|
91
|
-
name: PLUGIN_IDENTIFIER,
|
92
|
-
options: JSON.stringify({
|
93
|
-
serverBase,
|
94
|
-
...runtimeConfig.router,
|
95
|
-
routesConfig: fileSystemRoutes ? `{ ${ROUTES_IDENTIFIER}, globalApp: App }` : void 0
|
96
|
-
}).replace(
|
97
|
-
/"routesConfig"\s*:\s*"((\S|\s)+)"/g,
|
98
|
-
'"routesConfig": $1,'
|
99
|
-
)
|
100
|
-
});
|
101
|
-
}
|
102
|
-
return {
|
103
|
-
entrypoint,
|
104
|
-
plugins
|
105
|
-
};
|
106
|
-
},
|
107
|
-
addRuntimeExports() {
|
108
|
-
const userConfig = api.useResolvedConfigContext();
|
109
|
-
if ((0, import_utils.isRouterV5)(userConfig)) {
|
110
|
-
pluginsExportsUtils.addExport(
|
111
|
-
`export { default as router } from '@modern-js/plugin-router-v5/runtime'`
|
112
|
-
);
|
113
|
-
routerExportsUtils == null ? void 0 : routerExportsUtils.addExport(
|
114
|
-
`export * from '@modern-js/plugin-router-v5/runtime'`
|
115
|
-
);
|
116
90
|
}
|
117
|
-
}
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
121
|
-
// Annotate the CommonJS export names for ESM import in node:
|
122
|
-
0 && (module.exports = {});
|
91
|
+
};
|
92
|
+
}
|
93
|
+
};
|
94
|
+
};
|
package/dist/cjs/cli/types.js
CHANGED
package/dist/cjs/index.js
CHANGED
@@ -1,37 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
var src_exports = {};
|
30
|
-
__export(src_exports, {
|
31
|
-
default: () => import_runtime.default
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
32
4
|
});
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
5
|
+
Object.defineProperty(exports, "default", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => _runtime.default
|
8
|
+
});
|
9
|
+
const _runtime = /* @__PURE__ */ _interop_require_default(_export_star(require("./runtime"), exports));
|
10
|
+
function _export_star(from, to) {
|
11
|
+
Object.keys(from).forEach(function(k) {
|
12
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
13
|
+
Object.defineProperty(to, k, {
|
14
|
+
enumerable: true,
|
15
|
+
get: function() {
|
16
|
+
return from[k];
|
17
|
+
}
|
18
|
+
});
|
19
|
+
}
|
20
|
+
});
|
21
|
+
return from;
|
22
|
+
}
|
23
|
+
function _interop_require_default(obj) {
|
24
|
+
return obj && obj.__esModule ? obj : {
|
25
|
+
default: obj
|
26
|
+
};
|
27
|
+
}
|
@@ -1,40 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
21
4
|
});
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
5
|
+
Object.defineProperty(exports, "DefaultNotFound", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => DefaultNotFound
|
8
|
+
});
|
9
|
+
const _jsxruntime = require("react/jsx-runtime");
|
10
|
+
const _react = /* @__PURE__ */ _interop_require_default(require("react"));
|
11
|
+
function _interop_require_default(obj) {
|
12
|
+
return obj && obj.__esModule ? obj : {
|
13
|
+
default: obj
|
14
|
+
};
|
15
|
+
}
|
16
|
+
const DefaultNotFound = () => /* @__PURE__ */ (0, _jsxruntime.jsx)("div", {
|
17
|
+
style: {
|
18
|
+
margin: "150px auto",
|
19
|
+
textAlign: "center",
|
20
|
+
display: "flex",
|
21
|
+
alignItems: "center",
|
22
|
+
justifyContent: "center"
|
23
|
+
},
|
24
|
+
children: "404"
|
40
25
|
});
|
@@ -1,29 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
22
4
|
});
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
5
|
+
Object.defineProperty(exports, "default", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => _default
|
8
|
+
});
|
9
|
+
const _plugin = require("./plugin");
|
10
|
+
_export_star(require("react-router-dom"), exports);
|
11
|
+
_export_star(require("history"), exports);
|
12
|
+
function _export_star(from, to) {
|
13
|
+
Object.keys(from).forEach(function(k) {
|
14
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
15
|
+
Object.defineProperty(to, k, {
|
16
|
+
enumerable: true,
|
17
|
+
get: function() {
|
18
|
+
return from[k];
|
19
|
+
}
|
20
|
+
});
|
21
|
+
}
|
22
|
+
});
|
23
|
+
return from;
|
24
|
+
}
|
25
|
+
const _default = _plugin.routerPlugin;
|
@@ -1,55 +1,69 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
-
mod
|
26
|
-
));
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
-
var plugin_exports = {};
|
29
|
-
__export(plugin_exports, {
|
30
|
-
routerPlugin: () => routerPlugin
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "routerPlugin", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => routerPlugin
|
31
8
|
});
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
9
|
+
const _jsxruntime = require("react/jsx-runtime");
|
10
|
+
const _react = /* @__PURE__ */ _interop_require_wildcard(require("react"));
|
11
|
+
const _history = require("history");
|
12
|
+
const _reactrouterdom = require("react-router-dom");
|
13
|
+
const _hoistnonreactstatics = /* @__PURE__ */ _interop_require_default(require("hoist-non-react-statics"));
|
14
|
+
const _runtime = require("@modern-js/runtime");
|
15
|
+
const _runtime1 = require("@modern-js/utils/runtime");
|
16
|
+
const _utils = require("./utils");
|
17
|
+
function _interop_require_default(obj) {
|
18
|
+
return obj && obj.__esModule ? obj : {
|
19
|
+
default: obj
|
20
|
+
};
|
21
|
+
}
|
22
|
+
function _getRequireWildcardCache(nodeInterop) {
|
23
|
+
if (typeof WeakMap !== "function")
|
24
|
+
return null;
|
25
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
26
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
27
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
28
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
29
|
+
})(nodeInterop);
|
30
|
+
}
|
31
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
32
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
33
|
+
return obj;
|
34
|
+
}
|
35
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
36
|
+
return {
|
37
|
+
default: obj
|
38
|
+
};
|
39
|
+
}
|
40
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
41
|
+
if (cache && cache.has(obj)) {
|
42
|
+
return cache.get(obj);
|
43
|
+
}
|
44
|
+
var newObj = {};
|
45
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
46
|
+
for (var key in obj) {
|
47
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
48
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
49
|
+
if (desc && (desc.get || desc.set)) {
|
50
|
+
Object.defineProperty(newObj, key, desc);
|
51
|
+
} else {
|
52
|
+
newObj[key] = obj[key];
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
newObj.default = obj;
|
57
|
+
if (cache) {
|
58
|
+
cache.set(obj, newObj);
|
59
|
+
}
|
60
|
+
return newObj;
|
61
|
+
}
|
62
|
+
const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
|
63
|
+
const isBrow = (0, _runtime.isBrowser)();
|
50
64
|
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
51
65
|
if (isBrow) {
|
52
|
-
window._SERVER_DATA = (0,
|
66
|
+
window._SERVER_DATA = (0, _runtime1.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
|
53
67
|
}
|
54
68
|
return {
|
55
69
|
name: "@modern-js/plugin-router",
|
@@ -57,46 +71,60 @@ const routerPlugin = ({
|
|
57
71
|
return {
|
58
72
|
init({ context }, next) {
|
59
73
|
context.router = {
|
60
|
-
useRouteMatch:
|
61
|
-
useLocation:
|
74
|
+
useRouteMatch: _reactrouterdom.useRouteMatch,
|
75
|
+
useLocation: _reactrouterdom.useLocation
|
62
76
|
};
|
63
|
-
return next({
|
77
|
+
return next({
|
78
|
+
context
|
79
|
+
});
|
64
80
|
},
|
65
81
|
hoc: ({ App }, next) => {
|
66
82
|
const getRouteApp = () => {
|
67
|
-
var _a;
|
68
83
|
if (isBrow) {
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
84
|
+
var _window__SERVER_DATA;
|
85
|
+
const baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
|
86
|
+
historyOptions.basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
|
87
|
+
const history = customHistory || (supportHtml5History ? (0, _history.createBrowserHistory)(historyOptions) : (0, _history.createHashHistory)(historyOptions));
|
88
|
+
return (props) => /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Router, {
|
89
|
+
history,
|
90
|
+
children: createRoutes ? /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
91
|
+
...props,
|
92
|
+
Component: createRoutes()
|
93
|
+
}) : /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
94
|
+
...props,
|
95
|
+
children: (0, _utils.renderRoutes)(routesConfig, props)
|
96
|
+
})
|
97
|
+
});
|
73
98
|
}
|
74
99
|
return (props) => {
|
75
|
-
const runtimeContext = (0,
|
100
|
+
const runtimeContext = (0, _react.useContext)(_runtime.RuntimeReactContext);
|
76
101
|
const { ssrContext } = runtimeContext;
|
77
|
-
const
|
78
|
-
const routerContext = (ssrContext
|
79
|
-
const request = ssrContext
|
80
|
-
const baseUrl = request
|
81
|
-
const basename = baseUrl === "/" ? (0,
|
82
|
-
return /* @__PURE__ */ (0,
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
}
|
90
|
-
|
102
|
+
const location1 = (0, _utils.getLocation)(ssrContext);
|
103
|
+
const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
|
104
|
+
const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
|
105
|
+
const baseUrl = request === null || request === void 0 ? void 0 : request.baseUrl;
|
106
|
+
const basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
|
107
|
+
return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.StaticRouter, {
|
108
|
+
basename: basename === "/" ? "" : basename,
|
109
|
+
location: location1,
|
110
|
+
context: routerContext,
|
111
|
+
children: createRoutes ? /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
112
|
+
...props,
|
113
|
+
Component: createRoutes()
|
114
|
+
}) : /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
|
115
|
+
...props,
|
116
|
+
children: (0, _utils.renderRoutes)(routesConfig, props)
|
117
|
+
})
|
118
|
+
});
|
91
119
|
};
|
92
120
|
};
|
93
121
|
let RouteApp = getRouteApp();
|
94
122
|
if (App) {
|
95
|
-
RouteApp = (0,
|
123
|
+
RouteApp = (0, _hoistnonreactstatics.default)(RouteApp, App);
|
96
124
|
}
|
97
|
-
if (routesConfig
|
125
|
+
if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
|
98
126
|
return next({
|
99
|
-
App: (0,
|
127
|
+
App: (0, _hoistnonreactstatics.default)(RouteApp, routesConfig.globalApp)
|
100
128
|
});
|
101
129
|
}
|
102
130
|
return next({
|
@@ -107,7 +135,3 @@ const routerPlugin = ({
|
|
107
135
|
}
|
108
136
|
};
|
109
137
|
};
|
110
|
-
// Annotate the CommonJS export names for ESM import in node:
|
111
|
-
0 && (module.exports = {
|
112
|
-
routerPlugin
|
113
|
-
});
|