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