@modern-js/plugin-router-v5 2.5.0 → 2.7.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.
@@ -24,10 +24,6 @@ var import_utils = require("@modern-js/utils");
24
24
  var import_types2 = require("./types");
25
25
  const PLUGIN_IDENTIFIER = "router";
26
26
  const ROUTES_IDENTIFIER = "routes";
27
- const isV5 = (config) => {
28
- var _a, _b, _c;
29
- 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";
30
- };
31
27
  var cli_default = () => ({
32
28
  name: "@modern-js/plugin-router-v5",
33
29
  required: ["@modern-js/runtime"],
@@ -69,7 +65,7 @@ var cli_default = () => ({
69
65
  packageName
70
66
  );
71
67
  runtimeConfigMap.set(entryName, runtimeConfig);
72
- if (isV5(userConfig)) {
68
+ if ((0, import_utils.isRouterV5)(userConfig)) {
73
69
  imports.push({
74
70
  value: "@modern-js/runtime/plugins",
75
71
  specifiers: [{ imported: PLUGIN_IDENTIFIER }]
@@ -89,7 +85,7 @@ var cli_default = () => ({
89
85
  const { serverRoutes } = api.useAppContext();
90
86
  const runtimeConfig = runtimeConfigMap.get(entryName);
91
87
  const userConfig = api.useResolvedConfigContext();
92
- if (isV5(userConfig)) {
88
+ if ((0, import_utils.isRouterV5)(userConfig)) {
93
89
  const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
94
90
  plugins.push({
95
91
  name: PLUGIN_IDENTIFIER,
@@ -110,7 +106,7 @@ var cli_default = () => ({
110
106
  },
111
107
  addRuntimeExports() {
112
108
  const userConfig = api.useResolvedConfigContext();
113
- if (isV5(userConfig)) {
109
+ if ((0, import_utils.isRouterV5)(userConfig)) {
114
110
  pluginsExportsUtils.addExport(
115
111
  `export { default as router } from '@modern-js/plugin-router-v5/runtime'`
116
112
  );
package/dist/cjs/index.js CHANGED
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  };
19
19
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
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.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -21,16 +21,19 @@ __export(DefaultNotFound_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(DefaultNotFound_exports);
23
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
- });
24
+ const DefaultNotFound = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
25
+ "div",
26
+ {
27
+ style: {
28
+ margin: "150px auto",
29
+ textAlign: "center",
30
+ display: "flex",
31
+ alignItems: "center",
32
+ justifyContent: "center"
33
+ },
34
+ children: "404"
35
+ }
36
+ );
34
37
  // Annotate the CommonJS export names for ESM import in node:
35
38
  0 && (module.exports = {
36
39
  DefaultNotFound
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
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.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -61,16 +65,7 @@ const routerPlugin = ({
61
65
  const baseUrl = ((_a = window._SERVER_DATA) == null ? void 0 : _a.router.baseUrl) || select(location.pathname);
62
66
  historyOptions.basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
63
67
  const history = customHistory || (supportHtml5History ? (0, import_history.createBrowserHistory)(historyOptions) : (0, import_history.createHashHistory)(historyOptions));
64
- return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Router, {
65
- history,
66
- children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
67
- ...props,
68
- Component: createRoutes()
69
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
70
- ...props,
71
- children: (0, import_utils.renderRoutes)(routesConfig, props)
72
- })
73
- });
68
+ return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Router, { history, children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, { ...props, Component: createRoutes() }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, { ...props, children: (0, import_utils.renderRoutes)(routesConfig, props) }) });
74
69
  }
75
70
  return (props) => {
76
71
  const runtimeContext = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
@@ -80,18 +75,15 @@ const routerPlugin = ({
80
75
  const request = ssrContext == null ? void 0 : ssrContext.request;
81
76
  const baseUrl = request == null ? void 0 : request.baseUrl;
82
77
  const basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
83
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.StaticRouter, {
84
- basename: basename === "/" ? "" : basename,
85
- location: location2,
86
- context: routerContext,
87
- children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
88
- ...props,
89
- Component: createRoutes()
90
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
91
- ...props,
92
- children: (0, import_utils.renderRoutes)(routesConfig, props)
93
- })
94
- });
78
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
79
+ import_react_router_dom.StaticRouter,
80
+ {
81
+ basename: basename === "/" ? "" : basename,
82
+ location: location2,
83
+ context: routerContext,
84
+ children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, { ...props, Component: createRoutes() }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, { ...props, children: (0, import_utils.renderRoutes)(routesConfig, props) })
85
+ }
86
+ );
95
87
  };
96
88
  };
97
89
  let RouteApp = getRouteApp();
@@ -33,14 +33,9 @@ function renderRoutes(routesConfig, extraProps = {}) {
33
33
  const Layout = ({ Component, ...props }) => {
34
34
  const GlobalLayout = routesConfig == null ? void 0 : routesConfig.globalApp;
35
35
  if (!GlobalLayout) {
36
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
37
- ...props
38
- });
36
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props });
39
37
  }
40
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GlobalLayout, {
41
- Component,
42
- ...props
43
- });
38
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GlobalLayout, { Component, ...props });
44
39
  };
45
40
  const findMatchedRoute = (pathname) => {
46
41
  var _a;
@@ -53,25 +48,34 @@ function renderRoutes(routesConfig, extraProps = {}) {
53
48
  return Boolean(info);
54
49
  });
55
50
  };
56
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, {
57
- path: "/",
58
- render: (props) => {
59
- const matchedRoute = findMatchedRoute(props.location.pathname);
60
- if (!matchedRoute) {
61
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DefaultNotFound.DefaultNotFound, {});
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
+ );
62
76
  }
63
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, {
64
- path: matchedRoute.path,
65
- exact: matchedRoute.exact,
66
- sensitive: matchedRoute.sensitive,
67
- render: (routeProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Layout, {
68
- Component: matchedRoute.component,
69
- ...routeProps,
70
- ...extraProps
71
- })
72
- });
73
77
  }
74
- });
78
+ );
75
79
  }
76
80
  function getLocation(serverContext) {
77
81
  var _a;
@@ -50,14 +50,10 @@ function _objectSpreadProps(target, source) {
50
50
  }
51
51
  return target;
52
52
  }
53
- import { getEntryOptions, createRuntimeExportsUtils, PLUGIN_SCHEMAS } from "@modern-js/utils";
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 isV5 = function(config) {
58
- var _config_runtime, _config_runtime1, _config_runtime_router;
59
- return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
60
- };
61
57
  var cli_default = function() {
62
58
  return {
63
59
  name: "@modern-js/plugin-router-v5",
@@ -1,15 +1,12 @@
1
1
  import {
2
2
  getEntryOptions,
3
3
  createRuntimeExportsUtils,
4
- PLUGIN_SCHEMAS
4
+ PLUGIN_SCHEMAS,
5
+ isRouterV5 as isV5
5
6
  } from "@modern-js/utils";
6
7
  import "./types";
7
8
  const PLUGIN_IDENTIFIER = "router";
8
9
  const ROUTES_IDENTIFIER = "routes";
9
- const isV5 = (config) => {
10
- var _a, _b, _c;
11
- 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";
12
- };
13
10
  var cli_default = () => ({
14
11
  name: "@modern-js/plugin-router-v5",
15
12
  required: ["@modern-js/runtime"],
@@ -1,14 +1,17 @@
1
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
- });
2
+ const DefaultNotFound = () => /* @__PURE__ */ jsx(
3
+ "div",
4
+ {
5
+ style: {
6
+ margin: "150px auto",
7
+ textAlign: "center",
8
+ display: "flex",
9
+ alignItems: "center",
10
+ justifyContent: "center"
11
+ },
12
+ children: "404"
13
+ }
14
+ );
12
15
  export {
13
16
  DefaultNotFound
14
17
  };
@@ -41,16 +41,7 @@ const routerPlugin = ({
41
41
  const baseUrl = ((_a = window._SERVER_DATA) == null ? void 0 : _a.router.baseUrl) || select(location.pathname);
42
42
  historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
43
43
  const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
44
- return (props) => /* @__PURE__ */ jsx(Router, {
45
- history,
46
- children: createRoutes ? /* @__PURE__ */ jsx(App, {
47
- ...props,
48
- Component: createRoutes()
49
- }) : /* @__PURE__ */ jsx(App, {
50
- ...props,
51
- children: renderRoutes(routesConfig, props)
52
- })
53
- });
44
+ return (props) => /* @__PURE__ */ jsx(Router, { history, children: createRoutes ? /* @__PURE__ */ jsx(App, { ...props, Component: createRoutes() }) : /* @__PURE__ */ jsx(App, { ...props, children: renderRoutes(routesConfig, props) }) });
54
45
  }
55
46
  return (props) => {
56
47
  const runtimeContext = useContext(RuntimeReactContext);
@@ -60,18 +51,15 @@ const routerPlugin = ({
60
51
  const request = ssrContext == null ? void 0 : ssrContext.request;
61
52
  const baseUrl = request == null ? void 0 : request.baseUrl;
62
53
  const basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
63
- return /* @__PURE__ */ jsx(StaticRouter, {
64
- basename: basename === "/" ? "" : basename,
65
- location: location2,
66
- context: routerContext,
67
- children: createRoutes ? /* @__PURE__ */ jsx(App, {
68
- ...props,
69
- Component: createRoutes()
70
- }) : /* @__PURE__ */ jsx(App, {
71
- ...props,
72
- children: renderRoutes(routesConfig, props)
73
- })
74
- });
54
+ return /* @__PURE__ */ jsx(
55
+ StaticRouter,
56
+ {
57
+ basename: basename === "/" ? "" : basename,
58
+ location: location2,
59
+ context: routerContext,
60
+ children: createRoutes ? /* @__PURE__ */ jsx(App, { ...props, Component: createRoutes() }) : /* @__PURE__ */ jsx(App, { ...props, children: renderRoutes(routesConfig, props) })
61
+ }
62
+ );
75
63
  };
76
64
  };
77
65
  let RouteApp = getRouteApp();
@@ -8,14 +8,9 @@ function renderRoutes(routesConfig, extraProps = {}) {
8
8
  const Layout = ({ Component, ...props }) => {
9
9
  const GlobalLayout = routesConfig == null ? void 0 : routesConfig.globalApp;
10
10
  if (!GlobalLayout) {
11
- return /* @__PURE__ */ jsx(Component, {
12
- ...props
13
- });
11
+ return /* @__PURE__ */ jsx(Component, { ...props });
14
12
  }
15
- return /* @__PURE__ */ jsx(GlobalLayout, {
16
- Component,
17
- ...props
18
- });
13
+ return /* @__PURE__ */ jsx(GlobalLayout, { Component, ...props });
19
14
  };
20
15
  const findMatchedRoute = (pathname) => {
21
16
  var _a;
@@ -28,25 +23,34 @@ function renderRoutes(routesConfig, extraProps = {}) {
28
23
  return Boolean(info);
29
24
  });
30
25
  };
31
- return /* @__PURE__ */ jsx(Route, {
32
- path: "/",
33
- render: (props) => {
34
- const matchedRoute = findMatchedRoute(props.location.pathname);
35
- if (!matchedRoute) {
36
- return /* @__PURE__ */ jsx(DefaultNotFound, {});
26
+ return /* @__PURE__ */ jsx(
27
+ Route,
28
+ {
29
+ path: "/",
30
+ render: (props) => {
31
+ const matchedRoute = findMatchedRoute(props.location.pathname);
32
+ if (!matchedRoute) {
33
+ return /* @__PURE__ */ jsx(DefaultNotFound, {});
34
+ }
35
+ return /* @__PURE__ */ jsx(
36
+ Route,
37
+ {
38
+ path: matchedRoute.path,
39
+ exact: matchedRoute.exact,
40
+ sensitive: matchedRoute.sensitive,
41
+ render: (routeProps) => /* @__PURE__ */ jsx(
42
+ Layout,
43
+ {
44
+ Component: matchedRoute.component,
45
+ ...routeProps,
46
+ ...extraProps
47
+ }
48
+ )
49
+ }
50
+ );
37
51
  }
38
- return /* @__PURE__ */ jsx(Route, {
39
- path: matchedRoute.path,
40
- exact: matchedRoute.exact,
41
- sensitive: matchedRoute.sensitive,
42
- render: (routeProps) => /* @__PURE__ */ jsx(Layout, {
43
- Component: matchedRoute.component,
44
- ...routeProps,
45
- ...extraProps
46
- })
47
- });
48
52
  }
49
- });
53
+ );
50
54
  }
51
55
  function getLocation(serverContext) {
52
56
  var _a;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.5.0",
14
+ "version": "2.7.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/cli/index.d.ts",
17
17
  "main": "./dist/cjs/cli/index.js",
@@ -47,37 +47,37 @@
47
47
  }
48
48
  },
49
49
  "dependencies": {
50
- "history": "^4.7.9",
51
- "react-router-dom": "^5.1.2",
52
- "hoist-non-react-statics": "^3.3.2",
53
50
  "@types/history": "^4.7.9",
54
51
  "@types/react-router-dom": "^5.1.8",
55
- "@modern-js/utils": "2.5.0",
56
- "@modern-js/types": "2.5.0"
52
+ "history": "^4.7.9",
53
+ "hoist-non-react-statics": "^3.3.2",
54
+ "react-router-dom": "^5.3.4",
55
+ "@modern-js/types": "2.7.0",
56
+ "@modern-js/utils": "2.7.0"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "react": ">=17",
60
60
  "react-dom": ">=17"
61
61
  },
62
62
  "devDependencies": {
63
- "react": "^18",
64
- "react-dom": "^18",
65
- "ts-jest": "^27.0.4",
66
- "typescript": "^4",
67
- "jest": "^27",
68
63
  "@babel/core": "^7.18.0",
69
64
  "@babel/runtime": "^7.18.0",
70
- "@types/jest": "^27",
71
- "@types/node": "^14",
72
65
  "@testing-library/react": "^13.4.0",
73
66
  "@testing-library/react-hooks": "^8.0.1",
74
67
  "@types/invariant": "^2.2.30",
75
- "@modern-js/runtime": "2.5.0",
76
- "@modern-js/core": "2.5.0",
77
- "@modern-js/utils": "2.5.0",
78
- "@scripts/build": "2.5.0",
79
- "@modern-js/app-tools": "2.5.0",
80
- "@scripts/jest-config": "2.5.0"
68
+ "@types/jest": "^27",
69
+ "@types/node": "^14",
70
+ "jest": "^27",
71
+ "react": "^18",
72
+ "react-dom": "^18",
73
+ "ts-jest": "^27.0.4",
74
+ "typescript": "^4",
75
+ "@modern-js/app-tools": "2.7.0",
76
+ "@modern-js/core": "2.7.0",
77
+ "@modern-js/runtime": "2.7.0",
78
+ "@modern-js/utils": "2.7.0",
79
+ "@scripts/build": "2.7.0",
80
+ "@scripts/jest-config": "2.7.0"
81
81
  },
82
82
  "sideEffects": false,
83
83
  "modernConfig": {},