@modern-js/plugin-router-v5 2.34.0 → 2.35.1

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.
@@ -104,9 +104,8 @@ const routerPlugin = () => ({
104
104
  addRuntimeExports() {
105
105
  const userConfig = api.useResolvedConfigContext();
106
106
  if ((0, _utils.isRouterV5)(userConfig)) {
107
- var _routerExportsUtils;
108
107
  pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/plugin-router-v5/runtime'`);
109
- (_routerExportsUtils = routerExportsUtils) === null || _routerExportsUtils === void 0 ? void 0 : _routerExportsUtils.addExport(`export * from '@modern-js/plugin-router-v5/runtime'`);
108
+ routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@modern-js/plugin-router-v5/runtime'`);
110
109
  }
111
110
  }
112
111
  };
@@ -16,17 +16,16 @@ const _history = require("history");
16
16
  const _reactrouterdom = require("react-router-dom");
17
17
  const _hoistnonreactstatics = /* @__PURE__ */ _interop_require_default._(require("hoist-non-react-statics"));
18
18
  const _runtime = require("@modern-js/runtime");
19
- const _runtimebrowser = require("@modern-js/utils/runtime-browser");
19
+ const _browser = require("@modern-js/runtime-utils/browser");
20
20
  const _utils = require("./utils");
21
21
  const _hooks = require("./hooks");
22
22
  const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
23
- var _routesConfig;
24
- const originRoutes = ((_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.routes) || [];
23
+ const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
25
24
  const isBrow = (0, _runtime.isBrowser)();
26
25
  const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
27
26
  let routes = [];
28
27
  if (isBrow) {
29
- window._SERVER_DATA = (0, _runtimebrowser.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
28
+ window._SERVER_DATA = (0, _browser.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
30
29
  }
31
30
  return {
32
31
  name: "@modern-js/plugin-router",
@@ -50,7 +49,6 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
50
49
  });
51
50
  },
52
51
  hoc: ({ App }, next) => {
53
- var _routesConfig2;
54
52
  const getRouteApp = () => {
55
53
  if (isBrow) {
56
54
  var _window__SERVER_DATA;
@@ -74,13 +72,12 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
74
72
  };
75
73
  }
76
74
  return (props) => {
77
- var _ssrContext, _ssrContext1, _request;
78
75
  const runtimeContext = (0, _react.useContext)(_runtime.RuntimeReactContext);
79
76
  const { ssrContext } = runtimeContext;
80
77
  const location1 = (0, _utils.getLocation)(ssrContext);
81
- const routerContext = ((_ssrContext = ssrContext) === null || _ssrContext === void 0 ? void 0 : _ssrContext.redirection) || {};
82
- const request = (_ssrContext1 = ssrContext) === null || _ssrContext1 === void 0 ? void 0 : _ssrContext1.request;
83
- const baseUrl = (_request = request) === null || _request === void 0 ? void 0 : _request.baseUrl;
78
+ const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
79
+ const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
80
+ const baseUrl = request === null || request === void 0 ? void 0 : request.baseUrl;
84
81
  const basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
85
82
  const runner = api.useHookRunners();
86
83
  const routes2 = runner.modifyRoutes(originRoutes);
@@ -103,7 +100,7 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
103
100
  if (App) {
104
101
  RouteApp = (0, _hoistnonreactstatics.default)(RouteApp, App);
105
102
  }
106
- if ((_routesConfig2 = routesConfig) === null || _routesConfig2 === void 0 ? void 0 : _routesConfig2.globalApp) {
103
+ if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
107
104
  return next({
108
105
  App: (0, _hoistnonreactstatics.default)(RouteApp, routesConfig.globalApp)
109
106
  });
@@ -33,8 +33,7 @@ function renderRoutes(routesConfig, extraProps = {}) {
33
33
  return null;
34
34
  }
35
35
  const Layout = ({ Component, ...props }) => {
36
- var _routesConfig;
37
- const GlobalLayout = (_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.globalApp;
36
+ const GlobalLayout = routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp;
38
37
  if (!GlobalLayout) {
39
38
  return /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {
40
39
  ...props
@@ -46,8 +45,8 @@ function renderRoutes(routesConfig, extraProps = {}) {
46
45
  });
47
46
  };
48
47
  const findMatchedRoute = (pathname) => {
49
- var _routesConfig_routes, _routesConfig;
50
- return (_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : (_routesConfig_routes = _routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find((route) => {
48
+ var _routesConfig_routes;
49
+ return routesConfig === null || routesConfig === void 0 ? void 0 : (_routesConfig_routes = routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find((route) => {
51
50
  const info = (0, _reactrouterdom.matchPath)(pathname, {
52
51
  path: route.path,
53
52
  exact: route.exact,
@@ -77,9 +76,9 @@ function renderRoutes(routesConfig, extraProps = {}) {
77
76
  });
78
77
  }
79
78
  function getLocation(serverContext) {
80
- var _serverContext, _url_replace, _url;
81
- const { pathname, url } = ((_serverContext = serverContext) === null || _serverContext === void 0 ? void 0 : _serverContext.request) || {};
82
- const cleanUrl = (_url = url) === null || _url === void 0 ? void 0 : (_url_replace = _url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
79
+ var _url_replace;
80
+ const { pathname, url } = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
81
+ const cleanUrl = url === null || url === void 0 ? void 0 : (_url_replace = url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
83
82
  const index = (cleanUrl || "").indexOf(pathname);
84
83
  if (index === -1) {
85
84
  return pathname;
@@ -96,9 +96,8 @@ export var routerPlugin = function() {
96
96
  addRuntimeExports: function addRuntimeExports() {
97
97
  var userConfig = api.useResolvedConfigContext();
98
98
  if (isV5(userConfig)) {
99
- var _routerExportsUtils;
100
99
  pluginsExportsUtils.addExport("export { default as router } from '@modern-js/plugin-router-v5/runtime'");
101
- (_routerExportsUtils = routerExportsUtils) === null || _routerExportsUtils === void 0 ? void 0 : _routerExportsUtils.addExport("export * from '@modern-js/plugin-router-v5/runtime'");
100
+ routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport("export * from '@modern-js/plugin-router-v5/runtime'");
102
101
  }
103
102
  }
104
103
  };
@@ -6,13 +6,12 @@ import { createBrowserHistory, createHashHistory } from "history";
6
6
  import { Router, StaticRouter, useRouteMatch, useLocation } from "react-router-dom";
7
7
  import hoistNonReactStatics from "hoist-non-react-statics";
8
8
  import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
9
- import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
9
+ import { parsedJSONFromElement } from "@modern-js/runtime-utils/browser";
10
10
  import { renderRoutes, getLocation, urlJoin } from "./utils";
11
11
  import { modifyRoutesHook } from "./hooks";
12
12
  export var routerPlugin = function(param) {
13
13
  var _param_serverBase = param.serverBase, serverBase = _param_serverBase === void 0 ? [] : _param_serverBase, customHistory = param.history, _param_supportHtml5History = param.supportHtml5History, supportHtml5History = _param_supportHtml5History === void 0 ? true : _param_supportHtml5History, routesConfig = param.routesConfig, createRoutes = param.createRoutes, _param_historyOptions = param.historyOptions, historyOptions = _param_historyOptions === void 0 ? {} : _param_historyOptions;
14
- var _routesConfig;
15
- var originRoutes = ((_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.routes) || [];
14
+ var originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
16
15
  var isBrow = isBrowser();
17
16
  var select = function(pathname) {
18
17
  return serverBase.find(function(baseUrl) {
@@ -47,7 +46,6 @@ export var routerPlugin = function(param) {
47
46
  },
48
47
  hoc: function(param2, next) {
49
48
  var App = param2.App;
50
- var _routesConfig2;
51
49
  var getRouteApp = function() {
52
50
  if (isBrow) {
53
51
  var _window__SERVER_DATA;
@@ -69,13 +67,12 @@ export var routerPlugin = function(param) {
69
67
  };
70
68
  }
71
69
  return function(props) {
72
- var _ssrContext, _ssrContext1, _request;
73
70
  var runtimeContext = useContext(RuntimeReactContext);
74
71
  var ssrContext = runtimeContext.ssrContext;
75
72
  var _$location = getLocation(ssrContext);
76
- var routerContext = ((_ssrContext = ssrContext) === null || _ssrContext === void 0 ? void 0 : _ssrContext.redirection) || {};
77
- var request = (_ssrContext1 = ssrContext) === null || _ssrContext1 === void 0 ? void 0 : _ssrContext1.request;
78
- var baseUrl2 = (_request = request) === null || _request === void 0 ? void 0 : _request.baseUrl;
73
+ var routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
74
+ var request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
75
+ var baseUrl2 = request === null || request === void 0 ? void 0 : request.baseUrl;
79
76
  var basename = baseUrl2 === "/" ? urlJoin(baseUrl2, historyOptions.basename) : baseUrl2;
80
77
  var runner = api.useHookRunners();
81
78
  var routes2 = runner.modifyRoutes(originRoutes);
@@ -96,7 +93,7 @@ export var routerPlugin = function(param) {
96
93
  if (App) {
97
94
  RouteApp = hoistNonReactStatics(RouteApp, App);
98
95
  }
99
- if ((_routesConfig2 = routesConfig) === null || _routesConfig2 === void 0 ? void 0 : _routesConfig2.globalApp) {
96
+ if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
100
97
  return next({
101
98
  App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
102
99
  });
@@ -12,8 +12,7 @@ export function renderRoutes(routesConfig) {
12
12
  var Component = _param.Component, props = _object_without_properties(_param, [
13
13
  "Component"
14
14
  ]);
15
- var _routesConfig;
16
- var GlobalLayout = (_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.globalApp;
15
+ var GlobalLayout = routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp;
17
16
  if (!GlobalLayout) {
18
17
  return /* @__PURE__ */ _jsx(Component, _object_spread({}, props));
19
18
  }
@@ -22,8 +21,8 @@ export function renderRoutes(routesConfig) {
22
21
  }, props));
23
22
  };
24
23
  var findMatchedRoute = function(pathname) {
25
- var _routesConfig_routes, _routesConfig;
26
- return (_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : (_routesConfig_routes = _routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find(function(route) {
24
+ var _routesConfig_routes;
25
+ return routesConfig === null || routesConfig === void 0 ? void 0 : (_routesConfig_routes = routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find(function(route) {
27
26
  var info = matchPath(pathname, {
28
27
  path: route.path,
29
28
  exact: route.exact,
@@ -53,9 +52,9 @@ export function renderRoutes(routesConfig) {
53
52
  });
54
53
  }
55
54
  export function getLocation(serverContext) {
56
- var _serverContext, _url_replace, _url;
57
- var _ref = ((_serverContext = serverContext) === null || _serverContext === void 0 ? void 0 : _serverContext.request) || {}, pathname = _ref.pathname, url = _ref.url;
58
- var cleanUrl = (_url = url) === null || _url === void 0 ? void 0 : (_url_replace = _url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
55
+ var _url_replace;
56
+ var _ref = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {}, pathname = _ref.pathname, url = _ref.url;
57
+ var cleanUrl = url === null || url === void 0 ? void 0 : (_url_replace = url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
59
58
  var index = (cleanUrl || "").indexOf(pathname);
60
59
  if (index === -1) {
61
60
  return pathname;
@@ -85,9 +85,8 @@ export const routerPlugin = () => ({
85
85
  addRuntimeExports() {
86
86
  const userConfig = api.useResolvedConfigContext();
87
87
  if (isV5(userConfig)) {
88
- var _routerExportsUtils;
89
88
  pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/plugin-router-v5/runtime'`);
90
- (_routerExportsUtils = routerExportsUtils) === null || _routerExportsUtils === void 0 ? void 0 : _routerExportsUtils.addExport(`export * from '@modern-js/plugin-router-v5/runtime'`);
89
+ routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@modern-js/plugin-router-v5/runtime'`);
91
90
  }
92
91
  }
93
92
  };
@@ -4,12 +4,11 @@ import { createBrowserHistory, createHashHistory } from "history";
4
4
  import { Router, StaticRouter, useRouteMatch, useLocation } from "react-router-dom";
5
5
  import hoistNonReactStatics from "hoist-non-react-statics";
6
6
  import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
7
- import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
7
+ import { parsedJSONFromElement } from "@modern-js/runtime-utils/browser";
8
8
  import { renderRoutes, getLocation, urlJoin } from "./utils";
9
9
  import { modifyRoutesHook } from "./hooks";
10
10
  export const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
11
- var _routesConfig;
12
- const originRoutes = ((_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.routes) || [];
11
+ const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
13
12
  const isBrow = isBrowser();
14
13
  const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
15
14
  let routes = [];
@@ -38,7 +37,6 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
38
37
  });
39
38
  },
40
39
  hoc: ({ App }, next) => {
41
- var _routesConfig2;
42
40
  const getRouteApp = () => {
43
41
  if (isBrow) {
44
42
  var _window__SERVER_DATA;
@@ -62,13 +60,12 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
62
60
  };
63
61
  }
64
62
  return (props) => {
65
- var _ssrContext, _ssrContext1, _request;
66
63
  const runtimeContext = useContext(RuntimeReactContext);
67
64
  const { ssrContext } = runtimeContext;
68
65
  const location1 = getLocation(ssrContext);
69
- const routerContext = ((_ssrContext = ssrContext) === null || _ssrContext === void 0 ? void 0 : _ssrContext.redirection) || {};
70
- const request = (_ssrContext1 = ssrContext) === null || _ssrContext1 === void 0 ? void 0 : _ssrContext1.request;
71
- const baseUrl = (_request = request) === null || _request === void 0 ? void 0 : _request.baseUrl;
66
+ const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
67
+ const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
68
+ const baseUrl = request === null || request === void 0 ? void 0 : request.baseUrl;
72
69
  const basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
73
70
  const runner = api.useHookRunners();
74
71
  const routes2 = runner.modifyRoutes(originRoutes);
@@ -91,7 +88,7 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
91
88
  if (App) {
92
89
  RouteApp = hoistNonReactStatics(RouteApp, App);
93
90
  }
94
- if ((_routesConfig2 = routesConfig) === null || _routesConfig2 === void 0 ? void 0 : _routesConfig2.globalApp) {
91
+ if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
95
92
  return next({
96
93
  App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
97
94
  });
@@ -6,8 +6,7 @@ export function renderRoutes(routesConfig, extraProps = {}) {
6
6
  return null;
7
7
  }
8
8
  const Layout = ({ Component, ...props }) => {
9
- var _routesConfig;
10
- const GlobalLayout = (_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.globalApp;
9
+ const GlobalLayout = routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp;
11
10
  if (!GlobalLayout) {
12
11
  return /* @__PURE__ */ _jsx(Component, {
13
12
  ...props
@@ -19,8 +18,8 @@ export function renderRoutes(routesConfig, extraProps = {}) {
19
18
  });
20
19
  };
21
20
  const findMatchedRoute = (pathname) => {
22
- var _routesConfig_routes, _routesConfig;
23
- return (_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : (_routesConfig_routes = _routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find((route) => {
21
+ var _routesConfig_routes;
22
+ return routesConfig === null || routesConfig === void 0 ? void 0 : (_routesConfig_routes = routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find((route) => {
24
23
  const info = matchPath(pathname, {
25
24
  path: route.path,
26
25
  exact: route.exact,
@@ -50,9 +49,9 @@ export function renderRoutes(routesConfig, extraProps = {}) {
50
49
  });
51
50
  }
52
51
  export function getLocation(serverContext) {
53
- var _serverContext, _url_replace, _url;
54
- const { pathname, url } = ((_serverContext = serverContext) === null || _serverContext === void 0 ? void 0 : _serverContext.request) || {};
55
- const cleanUrl = (_url = url) === null || _url === void 0 ? void 0 : (_url_replace = _url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
52
+ var _url_replace;
53
+ const { pathname, url } = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
54
+ const cleanUrl = url === null || url === void 0 ? void 0 : (_url_replace = url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
56
55
  const index = (cleanUrl || "").indexOf(pathname);
57
56
  if (index === -1) {
58
57
  return pathname;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.34.0",
18
+ "version": "2.35.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/cli/index.d.ts",
21
21
  "main": "./dist/cjs/cli/index.js",
@@ -60,9 +60,9 @@
60
60
  "hoist-non-react-statics": "^3.3.2",
61
61
  "react-router-dom": "^5.3.4",
62
62
  "@swc/helpers": "0.5.1",
63
- "@modern-js/plugin": "2.34.0",
64
- "@modern-js/types": "2.34.0",
65
- "@modern-js/utils": "2.34.0"
63
+ "@modern-js/plugin": "2.35.1",
64
+ "@modern-js/types": "2.35.1",
65
+ "@modern-js/utils": "2.35.1"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "react": ">=17",
@@ -78,12 +78,13 @@
78
78
  "react-dom": "^18",
79
79
  "ts-jest": "^29.1.0",
80
80
  "typescript": "^5",
81
- "@modern-js/app-tools": "2.34.0",
82
- "@modern-js/core": "2.34.0",
83
- "@modern-js/runtime": "2.34.0",
84
- "@modern-js/utils": "2.34.0",
85
- "@scripts/build": "2.34.0",
86
- "@scripts/jest-config": "2.34.0"
81
+ "@modern-js/app-tools": "2.35.1",
82
+ "@modern-js/core": "2.35.1",
83
+ "@modern-js/runtime": "2.35.1",
84
+ "@modern-js/utils": "2.35.1",
85
+ "@modern-js/runtime-utils": "2.35.1",
86
+ "@scripts/jest-config": "2.35.1",
87
+ "@scripts/build": "2.35.1"
87
88
  },
88
89
  "sideEffects": false,
89
90
  "publishConfig": {