@modern-js/plugin-router-v5 0.0.0-next-20221220061243

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 ADDED
@@ -0,0 +1,45 @@
1
+ # @modern-js/plugin-router-v5
2
+
3
+ ## 0.0.0-next-20221220061243
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3: chore: v2
8
+
9
+ ### Patch Changes
10
+
11
+ - fe17f5105: fix: change plugin-router-legacy exports field for node environment
12
+ fix: 修改 plugin-router-legacy 的 exports 字段
13
+ - 6bda14ed7: feat: refactor router with react-router@6.4
14
+
15
+ feat: 使用 react-router@6.4 重构路由模块
16
+
17
+ - Updated dependencies [7879e8f71]
18
+ - Updated dependencies [6aca87501]
19
+ - Updated dependencies [2e6031955]
20
+ - Updated dependencies [7b7d12cf8]
21
+ - Updated dependencies [92f0eade3]
22
+ - Updated dependencies [edd1cfb1a]
23
+ - Updated dependencies [cc971eabf]
24
+ - Updated dependencies [5b9049f2e]
25
+ - Updated dependencies [6bda14ed7]
26
+ - Updated dependencies [92004d190]
27
+ - Updated dependencies [b8bbe036c]
28
+ - Updated dependencies [40ed5874c]
29
+ - Updated dependencies [87c1ff86b]
30
+ - Updated dependencies [d5a31df78]
31
+ - Updated dependencies [dda38c9c3]
32
+ - Updated dependencies [102d32e4b]
33
+ - Updated dependencies [8b8e1bb57]
34
+ - Updated dependencies [3bbea92b2]
35
+ - Updated dependencies [b710adb84]
36
+ - Updated dependencies [f17974937]
37
+ - Updated dependencies [ea7cf0625]
38
+ - Updated dependencies [bbe4c4ab6]
39
+ - Updated dependencies [e4558a0bc]
40
+ - Updated dependencies [abf3421a7]
41
+ - Updated dependencies [543be9558]
42
+ - Updated dependencies [14b712da8]
43
+ - @modern-js/types@0.0.0-next-20221220061243
44
+ - @modern-js/utils@0.0.0-next-20221220061243
45
+ - @modern-js/plugin@0.0.0-next-20221220061243
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Modern.js
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+
2
+ <p align="center">
3
+ <a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
4
+ </p>
5
+ <p align="center">
6
+ 现代 Web 工程体系
7
+ <br/>
8
+ <a href="https://modernjs.dev" target="blank">
9
+ modernjs.dev
10
+ </a>
11
+ </p>
12
+ <p align="center">
13
+ The meta-framework suite designed from scratch for frontend-focused modern web development
14
+ </p>
15
+
16
+ # Introduction
17
+
18
+ > The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.
19
+
20
+ - [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)
21
+
22
+ ## Getting Started
23
+
24
+ - [Quick Start](https://modernjs.dev/docs/start)
25
+ - [Guides](https://modernjs.dev/docs/guides)
26
+ - [API References](https://modernjs.dev/docs/apis)
27
+
28
+ ## Contributing
29
+
30
+ - [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)
@@ -0,0 +1,127 @@
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
+ const PLUGIN_IDENTIFIER = "router";
26
+ const ROUTES_IDENTIFIER = "routes";
27
+ const isV5 = (config) => {
28
+ var _a, _b;
29
+ return ((_b = (_a = config == null ? void 0 : config.runtime) == null ? void 0 : _a.router) == null ? void 0 : _b.mode) === "react-router-5";
30
+ };
31
+ var cli_default = () => ({
32
+ name: "@modern-js/plugin-router-v5",
33
+ required: ["@modern-js/runtime"],
34
+ setup: (api) => {
35
+ const runtimeConfigMap = /* @__PURE__ */ new Map();
36
+ let pluginsExportsUtils;
37
+ let routerExportsUtils;
38
+ return {
39
+ config() {
40
+ const appContext = api.useAppContext();
41
+ pluginsExportsUtils = createRuntimeExportsUtils(
42
+ appContext.internalDirectory,
43
+ "plugins"
44
+ );
45
+ routerExportsUtils = createRuntimeExportsUtils(
46
+ appContext.internalDirectory,
47
+ "router"
48
+ );
49
+ return {
50
+ source: {
51
+ alias: {
52
+ "@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
53
+ "@modern-js/runtime/router-v5": routerExportsUtils.getPath()
54
+ }
55
+ }
56
+ };
57
+ },
58
+ validateSchema() {
59
+ return PLUGIN_SCHEMAS["@modern-js/plugin-router"];
60
+ },
61
+ modifyEntryImports({ entrypoint, imports }) {
62
+ const { entryName } = entrypoint;
63
+ const userConfig = api.useResolvedConfigContext();
64
+ const { packageName } = api.useAppContext();
65
+ const runtimeConfig = getEntryOptions(
66
+ entryName,
67
+ userConfig.runtime,
68
+ userConfig.runtimeByEntries,
69
+ packageName
70
+ );
71
+ runtimeConfigMap.set(entryName, runtimeConfig);
72
+ if (isV5(userConfig)) {
73
+ imports.push({
74
+ value: "@modern-js/runtime/plugins",
75
+ specifiers: [{ imported: PLUGIN_IDENTIFIER }]
76
+ });
77
+ } else {
78
+ throw new Error(
79
+ `should enable runtime.router.mode for entry ${entryName}`
80
+ );
81
+ }
82
+ return {
83
+ entrypoint,
84
+ imports
85
+ };
86
+ },
87
+ modifyEntryRuntimePlugins({ entrypoint, plugins }) {
88
+ const { entryName, fileSystemRoutes } = entrypoint;
89
+ const { serverRoutes } = api.useAppContext();
90
+ const runtimeConfig = runtimeConfigMap.get(entryName);
91
+ const userConfig = api.useResolvedConfigContext();
92
+ if (isV5(userConfig)) {
93
+ const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
94
+ plugins.push({
95
+ name: PLUGIN_IDENTIFIER,
96
+ options: JSON.stringify(__spreadProps(__spreadValues({
97
+ serverBase
98
+ }, runtimeConfig.router), {
99
+ routesConfig: fileSystemRoutes ? `{ ${ROUTES_IDENTIFIER}, globalApp: App }` : void 0
100
+ })).replace(
101
+ /"routesConfig"\s*:\s*"((\S|\s)+)"/g,
102
+ '"routesConfig": $1,'
103
+ )
104
+ });
105
+ }
106
+ return {
107
+ entrypoint,
108
+ plugins
109
+ };
110
+ },
111
+ addRuntimeExports() {
112
+ const userConfig = api.useResolvedConfigContext();
113
+ if (isV5(userConfig)) {
114
+ pluginsExportsUtils.addExport(
115
+ `export { default as router } from '@modern-js/plugin-router-v5/runtime'`
116
+ );
117
+ routerExportsUtils == null ? void 0 : routerExportsUtils.addExport(
118
+ `export * from '@modern-js/plugin-router-v5/runtime'`
119
+ );
120
+ }
121
+ }
122
+ };
123
+ }
124
+ });
125
+ export {
126
+ cli_default as default
127
+ };
@@ -0,0 +1,5 @@
1
+ import { default as default2 } from "./runtime";
2
+ export * from "./runtime";
3
+ export {
4
+ default2 as default
5
+ };
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,7 @@
1
+ import { routerPlugin } from "./plugin";
2
+ var runtime_default = routerPlugin;
3
+ export * from "react-router-dom";
4
+ export * from "history";
5
+ export {
6
+ runtime_default as default
7
+ };
@@ -0,0 +1,94 @@
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 { Router, StaticRouter } from "react-router-dom";
27
+ import hoistNonReactStatics from "hoist-non-react-statics";
28
+ import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
29
+ import { renderRoutes, getLocation, urlJoin } from "./utils";
30
+ const routerPlugin = ({
31
+ serverBase = [],
32
+ history: customHistory,
33
+ supportHtml5History = true,
34
+ routesConfig,
35
+ historyOptions = {}
36
+ }) => {
37
+ const isBrow = isBrowser();
38
+ const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
39
+ return {
40
+ name: "@modern-js/plugin-router",
41
+ setup: () => {
42
+ return {
43
+ hoc: ({ App }, next) => {
44
+ const getRouteApp = () => {
45
+ var _a;
46
+ if (isBrow) {
47
+ const baseUrl = ((_a = window._SERVER_DATA) == null ? void 0 : _a.router.baseUrl) || select(location.pathname);
48
+ historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
49
+ const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
50
+ return (props) => /* @__PURE__ */ jsx(Router, {
51
+ history,
52
+ children: /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
53
+ children: routesConfig ? renderRoutes(routesConfig, props) : null
54
+ }))
55
+ });
56
+ }
57
+ return (props) => {
58
+ const runtimeContext = useContext(RuntimeReactContext);
59
+ const { ssrContext } = runtimeContext;
60
+ const location2 = getLocation(ssrContext);
61
+ const routerContext = (ssrContext == null ? void 0 : ssrContext.redirection) || {};
62
+ const request = ssrContext == null ? void 0 : ssrContext.request;
63
+ const baseUrl = request == null ? void 0 : request.baseUrl;
64
+ const basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
65
+ return /* @__PURE__ */ jsx(StaticRouter, {
66
+ basename: basename === "/" ? "" : basename,
67
+ location: location2,
68
+ context: routerContext,
69
+ children: /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
70
+ children: routesConfig ? renderRoutes(routesConfig, props) : null
71
+ }))
72
+ });
73
+ };
74
+ };
75
+ let RouteApp = getRouteApp();
76
+ if (App) {
77
+ RouteApp = hoistNonReactStatics(RouteApp, App);
78
+ }
79
+ if (routesConfig == null ? void 0 : routesConfig.globalApp) {
80
+ return next({
81
+ App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
82
+ });
83
+ }
84
+ return next({
85
+ App: RouteApp
86
+ });
87
+ }
88
+ };
89
+ }
90
+ };
91
+ };
92
+ export {
93
+ routerPlugin
94
+ };
@@ -0,0 +1,108 @@
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
+ };
@@ -0,0 +1,142 @@
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
+ const PLUGIN_IDENTIFIER = "router";
42
+ const ROUTES_IDENTIFIER = "routes";
43
+ const isV5 = (config) => {
44
+ var _a, _b;
45
+ return ((_b = (_a = config == null ? void 0 : config.runtime) == null ? void 0 : _a.router) == null ? void 0 : _b.mode) === "react-router-5";
46
+ };
47
+ var cli_default = () => ({
48
+ name: "@modern-js/plugin-router-v5",
49
+ required: ["@modern-js/runtime"],
50
+ setup: (api) => {
51
+ const runtimeConfigMap = /* @__PURE__ */ new Map();
52
+ let pluginsExportsUtils;
53
+ let routerExportsUtils;
54
+ return {
55
+ config() {
56
+ const appContext = api.useAppContext();
57
+ pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(
58
+ appContext.internalDirectory,
59
+ "plugins"
60
+ );
61
+ routerExportsUtils = (0, import_utils.createRuntimeExportsUtils)(
62
+ appContext.internalDirectory,
63
+ "router"
64
+ );
65
+ return {
66
+ source: {
67
+ alias: {
68
+ "@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
69
+ "@modern-js/runtime/router-v5": routerExportsUtils.getPath()
70
+ }
71
+ }
72
+ };
73
+ },
74
+ validateSchema() {
75
+ return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-router"];
76
+ },
77
+ modifyEntryImports({ entrypoint, imports }) {
78
+ const { entryName } = entrypoint;
79
+ const userConfig = api.useResolvedConfigContext();
80
+ const { packageName } = api.useAppContext();
81
+ const runtimeConfig = (0, import_utils.getEntryOptions)(
82
+ entryName,
83
+ userConfig.runtime,
84
+ userConfig.runtimeByEntries,
85
+ packageName
86
+ );
87
+ runtimeConfigMap.set(entryName, runtimeConfig);
88
+ if (isV5(userConfig)) {
89
+ imports.push({
90
+ value: "@modern-js/runtime/plugins",
91
+ specifiers: [{ imported: PLUGIN_IDENTIFIER }]
92
+ });
93
+ } else {
94
+ throw new Error(
95
+ `should enable runtime.router.mode for entry ${entryName}`
96
+ );
97
+ }
98
+ return {
99
+ entrypoint,
100
+ imports
101
+ };
102
+ },
103
+ modifyEntryRuntimePlugins({ entrypoint, plugins }) {
104
+ const { entryName, fileSystemRoutes } = entrypoint;
105
+ const { serverRoutes } = api.useAppContext();
106
+ const runtimeConfig = runtimeConfigMap.get(entryName);
107
+ const userConfig = api.useResolvedConfigContext();
108
+ if (isV5(userConfig)) {
109
+ const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
110
+ plugins.push({
111
+ name: PLUGIN_IDENTIFIER,
112
+ options: JSON.stringify(__spreadProps(__spreadValues({
113
+ serverBase
114
+ }, runtimeConfig.router), {
115
+ routesConfig: fileSystemRoutes ? `{ ${ROUTES_IDENTIFIER}, globalApp: App }` : void 0
116
+ })).replace(
117
+ /"routesConfig"\s*:\s*"((\S|\s)+)"/g,
118
+ '"routesConfig": $1,'
119
+ )
120
+ });
121
+ }
122
+ return {
123
+ entrypoint,
124
+ plugins
125
+ };
126
+ },
127
+ addRuntimeExports() {
128
+ const userConfig = api.useResolvedConfigContext();
129
+ if (isV5(userConfig)) {
130
+ pluginsExportsUtils.addExport(
131
+ `export { default as router } from '@modern-js/plugin-router-v5/runtime'`
132
+ );
133
+ routerExportsUtils == null ? void 0 : routerExportsUtils.addExport(
134
+ `export * from '@modern-js/plugin-router-v5/runtime'`
135
+ );
136
+ }
137
+ }
138
+ };
139
+ }
140
+ });
141
+ // Annotate the CommonJS export names for ESM import in node:
142
+ 0 && (module.exports = {});
@@ -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 = {});
File without changes
@@ -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
+ });