@modern-js/plugin-router-v5 2.14.0 → 2.16.0

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