@modern-js/plugin-router-v5 2.35.0 → 2.36.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,24 +1,29 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
6
7
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- routerPlugin: function() {
14
- return routerPlugin;
15
- },
16
- default: function() {
17
- return _default;
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var cli_exports = {};
20
+ __export(cli_exports, {
21
+ default: () => cli_default,
22
+ routerPlugin: () => routerPlugin
19
23
  });
20
- const _utils = require("@modern-js/utils");
21
- require("./types");
24
+ module.exports = __toCommonJS(cli_exports);
25
+ var import_utils = require("@modern-js/utils");
26
+ var import_types = require("./types");
22
27
  const PLUGIN_IDENTIFIER = "router";
23
28
  const ROUTES_IDENTIFIER = "routes";
24
29
  const routerPlugin = () => ({
@@ -33,8 +38,8 @@ const routerPlugin = () => ({
33
38
  return {
34
39
  config() {
35
40
  const appContext = api.useAppContext();
36
- pluginsExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, "plugins");
37
- routerExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, "router");
41
+ pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(appContext.internalDirectory, "plugins");
42
+ routerExportsUtils = (0, import_utils.createRuntimeExportsUtils)(appContext.internalDirectory, "router");
38
43
  return {
39
44
  source: {
40
45
  alias: {
@@ -61,9 +66,9 @@ const routerPlugin = () => ({
61
66
  const { entryName, isMainEntry } = entrypoint;
62
67
  const userConfig = api.useResolvedConfigContext();
63
68
  const { packageName } = api.useAppContext();
64
- const runtimeConfig = (0, _utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
69
+ const runtimeConfig = (0, import_utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
65
70
  runtimeConfigMap.set(entryName, runtimeConfig);
66
- if ((0, _utils.isRouterV5)(userConfig)) {
71
+ if ((0, import_utils.isRouterV5)(userConfig)) {
67
72
  imports.push({
68
73
  value: "@modern-js/runtime/plugins",
69
74
  specifiers: [
@@ -85,7 +90,7 @@ const routerPlugin = () => ({
85
90
  const { serverRoutes } = api.useAppContext();
86
91
  const runtimeConfig = runtimeConfigMap.get(entryName);
87
92
  const userConfig = api.useResolvedConfigContext();
88
- if ((0, _utils.isRouterV5)(userConfig)) {
93
+ if ((0, import_utils.isRouterV5)(userConfig)) {
89
94
  const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
90
95
  plugins.push({
91
96
  name: PLUGIN_IDENTIFIER,
@@ -103,13 +108,16 @@ const routerPlugin = () => ({
103
108
  },
104
109
  addRuntimeExports() {
105
110
  const userConfig = api.useResolvedConfigContext();
106
- if ((0, _utils.isRouterV5)(userConfig)) {
107
- var _routerExportsUtils;
111
+ if ((0, import_utils.isRouterV5)(userConfig)) {
108
112
  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'`);
113
+ routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@modern-js/plugin-router-v5/runtime'`);
110
114
  }
111
115
  }
112
116
  };
113
117
  }
114
118
  });
115
- const _default = routerPlugin;
119
+ var cli_default = routerPlugin;
120
+ // Annotate the CommonJS export names for ESM import in node:
121
+ 0 && (module.exports = {
122
+ routerPlugin
123
+ });
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
package/dist/cjs/index.js CHANGED
@@ -1,13 +1,40 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
8
- return _runtime.default;
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
17
  }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var src_exports = {};
31
+ __export(src_exports, {
32
+ default: () => import_runtime.default
33
+ });
34
+ module.exports = __toCommonJS(src_exports);
35
+ var import_runtime = __toESM(require("./runtime"));
36
+ __reExport(src_exports, require("./runtime"), module.exports);
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ ...require("./runtime")
10
40
  });
11
- const _export_star = require("@swc/helpers/_/_export_star");
12
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
13
- const _runtime = /* @__PURE__ */ _interop_require_default._(_export_star._(require("./runtime"), exports));
@@ -1,17 +1,28 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "DefaultNotFound", {
6
- enumerable: true,
7
- get: function() {
8
- return DefaultNotFound;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var DefaultNotFound_exports = {};
20
+ __export(DefaultNotFound_exports, {
21
+ DefaultNotFound: () => DefaultNotFound
10
22
  });
11
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
- const _jsxruntime = require("react/jsx-runtime");
13
- const _react = /* @__PURE__ */ _interop_require_default._(require("react"));
14
- const DefaultNotFound = () => /* @__PURE__ */ (0, _jsxruntime.jsx)("div", {
23
+ module.exports = __toCommonJS(DefaultNotFound_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ const DefaultNotFound = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
15
26
  style: {
16
27
  margin: "150px auto",
17
28
  textAlign: "center",
@@ -21,3 +32,7 @@ const DefaultNotFound = () => /* @__PURE__ */ (0, _jsxruntime.jsx)("div", {
21
32
  },
22
33
  children: "404"
23
34
  });
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ DefaultNotFound
38
+ });
@@ -1,12 +1,29 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "modifyRoutesHook", {
6
- enumerable: true,
7
- get: function() {
8
- return modifyRoutesHook;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var hooks_exports = {};
20
+ __export(hooks_exports, {
21
+ modifyRoutesHook: () => modifyRoutesHook
22
+ });
23
+ module.exports = __toCommonJS(hooks_exports);
24
+ var import_plugin = require("@modern-js/plugin");
25
+ const modifyRoutesHook = (0, import_plugin.createWaterfall)();
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ modifyRoutesHook
10
29
  });
11
- const _plugin = require("@modern-js/plugin");
12
- const modifyRoutesHook = (0, _plugin.createWaterfall)();
@@ -1,15 +1,33 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
8
- return _default;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
15
  }
16
+ return to;
17
+ };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var runtime_exports = {};
21
+ __export(runtime_exports, {
22
+ default: () => runtime_default
23
+ });
24
+ module.exports = __toCommonJS(runtime_exports);
25
+ var import_plugin = require("./plugin");
26
+ __reExport(runtime_exports, require("react-router-dom"), module.exports);
27
+ __reExport(runtime_exports, require("history"), module.exports);
28
+ var runtime_default = import_plugin.routerPlugin;
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ ...require("react-router-dom"),
32
+ ...require("history")
10
33
  });
11
- const _export_star = require("@swc/helpers/_/_export_star");
12
- const _plugin = require("./plugin");
13
- _export_star._(require("react-router-dom"), exports);
14
- _export_star._(require("history"), exports);
15
- const _default = _plugin.routerPlugin;
@@ -1,44 +1,64 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "routerPlugin", {
6
- enumerable: true,
7
- get: function() {
8
- return routerPlugin;
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
17
  }
18
+ return to;
19
+ };
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.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var plugin_exports = {};
30
+ __export(plugin_exports, {
31
+ routerPlugin: () => routerPlugin
10
32
  });
11
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
13
- const _jsxruntime = require("react/jsx-runtime");
14
- const _react = /* @__PURE__ */ _interop_require_wildcard._(require("react"));
15
- const _history = require("history");
16
- const _reactrouterdom = require("react-router-dom");
17
- const _hoistnonreactstatics = /* @__PURE__ */ _interop_require_default._(require("hoist-non-react-statics"));
18
- const _runtime = require("@modern-js/runtime");
19
- const _runtimebrowser = require("@modern-js/utils/runtime-browser");
20
- const _utils = require("./utils");
21
- const _hooks = require("./hooks");
33
+ module.exports = __toCommonJS(plugin_exports);
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var import_react = require("react");
36
+ var import_history = require("history");
37
+ var import_react_router_dom = require("react-router-dom");
38
+ var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
39
+ var import_runtime = require("@modern-js/runtime");
40
+ var import_browser = require("@modern-js/runtime-utils/browser");
41
+ var import_utils = require("./utils");
42
+ var import_hooks = require("./hooks");
22
43
  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) || [];
25
- const isBrow = (0, _runtime.isBrowser)();
44
+ const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
45
+ const isBrow = (0, import_runtime.isBrowser)();
26
46
  const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
27
47
  let routes = [];
28
48
  if (isBrow) {
29
- window._SERVER_DATA = (0, _runtimebrowser.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
49
+ window._SERVER_DATA = (0, import_browser.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
30
50
  }
31
51
  return {
32
52
  name: "@modern-js/plugin-router",
33
53
  registerHook: {
34
- modifyRoutes: _hooks.modifyRoutesHook
54
+ modifyRoutes: import_hooks.modifyRoutesHook
35
55
  },
36
56
  setup: (api) => {
37
57
  return {
38
58
  init({ context }, next) {
39
59
  context.router = {
40
- useRouteMatch: _reactrouterdom.useRouteMatch,
41
- useLocation: _reactrouterdom.useLocation
60
+ useRouteMatch: import_react_router_dom.useRouteMatch,
61
+ useLocation: import_react_router_dom.useLocation
42
62
  };
43
63
  Object.defineProperty(context, "routes", {
44
64
  get() {
@@ -50,62 +70,60 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
50
70
  });
51
71
  },
52
72
  hoc: ({ App }, next) => {
53
- var _routesConfig2;
54
73
  const getRouteApp = () => {
55
74
  if (isBrow) {
56
75
  var _window__SERVER_DATA;
57
76
  const baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
58
- historyOptions.basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
59
- const history = customHistory || (supportHtml5History ? (0, _history.createBrowserHistory)(historyOptions) : (0, _history.createHashHistory)(historyOptions));
77
+ historyOptions.basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
78
+ const history = customHistory || (supportHtml5History ? (0, import_history.createBrowserHistory)(historyOptions) : (0, import_history.createHashHistory)(historyOptions));
60
79
  return (props) => {
61
80
  const runner = api.useHookRunners();
62
81
  routes = runner.modifyRoutes(originRoutes);
63
82
  routesConfig && (routesConfig.routes = routes);
64
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Router, {
83
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Router, {
65
84
  history,
66
- children: createRoutes ? /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
85
+ children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
67
86
  ...props,
68
87
  Component: createRoutes()
69
- }) : /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
88
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
70
89
  ...props,
71
- children: (0, _utils.renderRoutes)(routesConfig, props)
90
+ children: (0, import_utils.renderRoutes)(routesConfig, props)
72
91
  })
73
92
  });
74
93
  };
75
94
  }
76
95
  return (props) => {
77
- var _ssrContext, _ssrContext1, _request;
78
- const runtimeContext = (0, _react.useContext)(_runtime.RuntimeReactContext);
96
+ const runtimeContext = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
79
97
  const { ssrContext } = runtimeContext;
80
- 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;
84
- const basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
98
+ const location1 = (0, import_utils.getLocation)(ssrContext);
99
+ const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
100
+ const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
101
+ const baseUrl = request === null || request === void 0 ? void 0 : request.baseUrl;
102
+ const basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
85
103
  const runner = api.useHookRunners();
86
104
  const routes2 = runner.modifyRoutes(originRoutes);
87
105
  routesConfig && (routesConfig.routes = routes2);
88
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.StaticRouter, {
106
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.StaticRouter, {
89
107
  basename: basename === "/" ? "" : basename,
90
108
  location: location1,
91
109
  context: routerContext,
92
- children: createRoutes ? /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
110
+ children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
93
111
  ...props,
94
112
  Component: createRoutes()
95
- }) : /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
113
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
96
114
  ...props,
97
- children: (0, _utils.renderRoutes)(routesConfig, props)
115
+ children: (0, import_utils.renderRoutes)(routesConfig, props)
98
116
  })
99
117
  });
100
118
  };
101
119
  };
102
120
  let RouteApp = getRouteApp();
103
121
  if (App) {
104
- RouteApp = (0, _hoistnonreactstatics.default)(RouteApp, App);
122
+ RouteApp = (0, import_hoist_non_react_statics.default)(RouteApp, App);
105
123
  }
106
- if ((_routesConfig2 = routesConfig) === null || _routesConfig2 === void 0 ? void 0 : _routesConfig2.globalApp) {
124
+ if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
107
125
  return next({
108
- App: (0, _hoistnonreactstatics.default)(RouteApp, routesConfig.globalApp)
126
+ App: (0, import_hoist_non_react_statics.default)(RouteApp, routesConfig.globalApp)
109
127
  });
110
128
  }
111
129
  return next({
@@ -116,3 +134,7 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
116
134
  }
117
135
  };
118
136
  };
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ routerPlugin
140
+ });
@@ -1,54 +1,52 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
6
7
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- renderRoutes: function() {
14
- return renderRoutes;
15
- },
16
- getLocation: function() {
17
- return getLocation;
18
- },
19
- urlJoin: function() {
20
- return urlJoin;
21
- },
22
- standardSlash: function() {
23
- return standardSlash;
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var utils_exports = {};
20
+ __export(utils_exports, {
21
+ getLocation: () => getLocation,
22
+ renderRoutes: () => renderRoutes,
23
+ standardSlash: () => standardSlash,
24
+ urlJoin: () => urlJoin
25
25
  });
26
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
27
- const _jsxruntime = require("react/jsx-runtime");
28
- const _react = /* @__PURE__ */ _interop_require_default._(require("react"));
29
- const _reactrouterdom = require("react-router-dom");
30
- const _DefaultNotFound = require("./DefaultNotFound");
26
+ module.exports = __toCommonJS(utils_exports);
27
+ var import_jsx_runtime = require("react/jsx-runtime");
28
+ var import_react_router_dom = require("react-router-dom");
29
+ var import_DefaultNotFound = require("./DefaultNotFound");
31
30
  function renderRoutes(routesConfig, extraProps = {}) {
32
31
  if (!routesConfig) {
33
32
  return null;
34
33
  }
35
34
  const Layout = ({ Component, ...props }) => {
36
- var _routesConfig;
37
- const GlobalLayout = (_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.globalApp;
35
+ const GlobalLayout = routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp;
38
36
  if (!GlobalLayout) {
39
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {
37
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
40
38
  ...props
41
39
  });
42
40
  }
43
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(GlobalLayout, {
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GlobalLayout, {
44
42
  Component,
45
43
  ...props
46
44
  });
47
45
  };
48
46
  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) => {
51
- const info = (0, _reactrouterdom.matchPath)(pathname, {
47
+ var _routesConfig_routes;
48
+ return routesConfig === null || routesConfig === void 0 ? void 0 : (_routesConfig_routes = routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find((route) => {
49
+ const info = (0, import_react_router_dom.matchPath)(pathname, {
52
50
  path: route.path,
53
51
  exact: route.exact,
54
52
  sensitive: route.sensitive
@@ -56,18 +54,18 @@ function renderRoutes(routesConfig, extraProps = {}) {
56
54
  return Boolean(info);
57
55
  });
58
56
  };
59
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Route, {
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, {
60
58
  path: "/",
61
59
  render: (props) => {
62
60
  const matchedRoute = findMatchedRoute(props.location.pathname);
63
61
  if (!matchedRoute) {
64
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_DefaultNotFound.DefaultNotFound, {});
62
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DefaultNotFound.DefaultNotFound, {});
65
63
  }
66
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Route, {
64
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, {
67
65
  path: matchedRoute.path,
68
66
  exact: matchedRoute.exact,
69
67
  sensitive: matchedRoute.sensitive,
70
- render: (routeProps) => /* @__PURE__ */ (0, _jsxruntime.jsx)(Layout, {
68
+ render: (routeProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Layout, {
71
69
  Component: matchedRoute.component,
72
70
  ...routeProps,
73
71
  ...extraProps
@@ -77,9 +75,9 @@ function renderRoutes(routesConfig, extraProps = {}) {
77
75
  });
78
76
  }
79
77
  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://", "");
78
+ var _url_replace;
79
+ const { pathname, url } = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
80
+ 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
81
  const index = (cleanUrl || "").indexOf(pathname);
84
82
  if (index === -1) {
85
83
  return pathname;
@@ -107,3 +105,10 @@ function standardSlash(str) {
107
105
  }
108
106
  return addr;
109
107
  }
108
+ // Annotate the CommonJS export names for ESM import in node:
109
+ 0 && (module.exports = {
110
+ getLocation,
111
+ renderRoutes,
112
+ standardSlash,
113
+ urlJoin
114
+ });
@@ -4,7 +4,7 @@ import { getEntryOptions, createRuntimeExportsUtils, isRouterV5 as isV5 } from "
4
4
  import "./types";
5
5
  var PLUGIN_IDENTIFIER = "router";
6
6
  var ROUTES_IDENTIFIER = "routes";
7
- export var routerPlugin = function() {
7
+ var routerPlugin = function() {
8
8
  return {
9
9
  name: "@modern-js/plugin-router-v5",
10
10
  required: [
@@ -61,8 +61,8 @@ export var routerPlugin = function() {
61
61
  throw new Error("should enable runtime.router.mode for entry ".concat(entryName));
62
62
  }
63
63
  return {
64
- entrypoint: entrypoint,
65
- imports: imports
64
+ entrypoint,
65
+ imports
66
66
  };
67
67
  },
68
68
  modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(param) {
@@ -82,27 +82,30 @@ export var routerPlugin = function() {
82
82
  plugins.push({
83
83
  name: PLUGIN_IDENTIFIER,
84
84
  options: JSON.stringify(_object_spread_props(_object_spread({
85
- serverBase: serverBase
85
+ serverBase
86
86
  }, runtimeConfig.router), {
87
87
  routesConfig: fileSystemRoutes ? "{ ".concat(ROUTES_IDENTIFIER, ", globalApp: App }") : void 0
88
88
  })).replace(/"routesConfig"\s*:\s*"((\S|\s)+)"/g, '"routesConfig": $1,')
89
89
  });
90
90
  }
91
91
  return {
92
- entrypoint: entrypoint,
93
- plugins: plugins
92
+ entrypoint,
93
+ plugins
94
94
  };
95
95
  },
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
  };
105
104
  }
106
105
  };
107
106
  };
108
- export default routerPlugin;
107
+ var cli_default = routerPlugin;
108
+ export {
109
+ cli_default as default,
110
+ routerPlugin
111
+ };
@@ -1 +0,0 @@
1
- export {};
package/dist/esm/index.js CHANGED
@@ -1,2 +1,5 @@
1
- export { default } from "./runtime";
1
+ import { default as default2 } from "./runtime";
2
2
  export * from "./runtime";
3
+ export {
4
+ default2 as default
5
+ };
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- export var DefaultNotFound = function() {
2
+ var DefaultNotFound = function() {
3
3
  return /* @__PURE__ */ _jsx("div", {
4
4
  style: {
5
5
  margin: "150px auto",
@@ -11,3 +11,6 @@ export var DefaultNotFound = function() {
11
11
  children: "404"
12
12
  });
13
13
  };
14
+ export {
15
+ DefaultNotFound
16
+ };
@@ -1,3 +1,5 @@
1
1
  import { createWaterfall } from "@modern-js/plugin";
2
2
  var modifyRoutesHook = createWaterfall();
3
- export { modifyRoutesHook };
3
+ export {
4
+ modifyRoutesHook
5
+ };
@@ -1,4 +1,7 @@
1
1
  import { routerPlugin } from "./plugin";
2
- export default routerPlugin;
2
+ var runtime_default = routerPlugin;
3
3
  export * from "react-router-dom";
4
4
  export * from "history";
5
+ export {
6
+ runtime_default as default
7
+ };
@@ -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
- export var routerPlugin = function(param) {
12
+ 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) {
@@ -33,8 +32,8 @@ export var routerPlugin = function(param) {
33
32
  init: function init(param2, next) {
34
33
  var context = param2.context;
35
34
  context.router = {
36
- useRouteMatch: useRouteMatch,
37
- useLocation: useLocation
35
+ useRouteMatch,
36
+ useLocation
38
37
  };
39
38
  Object.defineProperty(context, "routes", {
40
39
  get: function get() {
@@ -42,12 +41,11 @@ export var routerPlugin = function(param) {
42
41
  }
43
42
  });
44
43
  return next({
45
- context: context
44
+ context
46
45
  });
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;
@@ -59,7 +57,7 @@ export var routerPlugin = function(param) {
59
57
  routes = runner.modifyRoutes(originRoutes);
60
58
  routesConfig && (routesConfig.routes = routes);
61
59
  return /* @__PURE__ */ _jsx(Router, {
62
- history: history,
60
+ history,
63
61
  children: createRoutes ? /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
64
62
  Component: createRoutes()
65
63
  })) : /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
@@ -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
  });
@@ -109,3 +106,6 @@ export var routerPlugin = function(param) {
109
106
  }
110
107
  };
111
108
  };
109
+ export {
110
+ routerPlugin
111
+ };
@@ -3,7 +3,7 @@ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  import { Route, matchPath } from "react-router-dom";
5
5
  import { DefaultNotFound } from "./DefaultNotFound";
6
- export function renderRoutes(routesConfig) {
6
+ function renderRoutes(routesConfig) {
7
7
  var extraProps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
8
8
  if (!routesConfig) {
9
9
  return null;
@@ -12,18 +12,17 @@ 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
  }
20
19
  return /* @__PURE__ */ _jsx(GlobalLayout, _object_spread({
21
- Component: Component
20
+ Component
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,
@@ -52,17 +51,17 @@ export function renderRoutes(routesConfig) {
52
51
  }
53
52
  });
54
53
  }
55
- 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://", "");
54
+ function getLocation(serverContext) {
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;
62
61
  }
63
62
  return cleanUrl.substring(index);
64
63
  }
65
- export var urlJoin = function() {
64
+ var urlJoin = function() {
66
65
  for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
67
66
  parts[_key] = arguments[_key];
68
67
  }
@@ -70,7 +69,7 @@ export var urlJoin = function() {
70
69
  var replace = new RegExp("".concat(separator, "{1,}"), "g");
71
70
  return standardSlash(parts.join(separator).replace(replace, separator));
72
71
  };
73
- export function standardSlash(str) {
72
+ function standardSlash(str) {
74
73
  var addr = str;
75
74
  if (!addr || typeof addr !== "string") {
76
75
  return addr;
@@ -86,3 +85,9 @@ export function standardSlash(str) {
86
85
  }
87
86
  return addr;
88
87
  }
88
+ export {
89
+ getLocation,
90
+ renderRoutes,
91
+ standardSlash,
92
+ urlJoin
93
+ };
@@ -2,7 +2,7 @@ import { getEntryOptions, createRuntimeExportsUtils, isRouterV5 as isV5 } from "
2
2
  import "./types";
3
3
  const PLUGIN_IDENTIFIER = "router";
4
4
  const ROUTES_IDENTIFIER = "routes";
5
- export const routerPlugin = () => ({
5
+ const routerPlugin = () => ({
6
6
  name: "@modern-js/plugin-router-v5",
7
7
  required: [
8
8
  "@modern-js/runtime"
@@ -85,12 +85,15 @@ 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
  };
94
93
  }
95
94
  });
96
- export default routerPlugin;
95
+ var cli_default = routerPlugin;
96
+ export {
97
+ cli_default as default,
98
+ routerPlugin
99
+ };
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +1,5 @@
1
- export { default } from "./runtime";
1
+ import { default as default2 } from "./runtime";
2
2
  export * from "./runtime";
3
+ export {
4
+ default2 as default
5
+ };
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- export const DefaultNotFound = () => /* @__PURE__ */ _jsx("div", {
2
+ const DefaultNotFound = () => /* @__PURE__ */ _jsx("div", {
3
3
  style: {
4
4
  margin: "150px auto",
5
5
  textAlign: "center",
@@ -9,3 +9,6 @@ export const DefaultNotFound = () => /* @__PURE__ */ _jsx("div", {
9
9
  },
10
10
  children: "404"
11
11
  });
12
+ export {
13
+ DefaultNotFound
14
+ };
@@ -1,3 +1,5 @@
1
1
  import { createWaterfall } from "@modern-js/plugin";
2
2
  const modifyRoutesHook = createWaterfall();
3
- export { modifyRoutesHook };
3
+ export {
4
+ modifyRoutesHook
5
+ };
@@ -1,4 +1,7 @@
1
1
  import { routerPlugin } from "./plugin";
2
- export default routerPlugin;
2
+ var runtime_default = routerPlugin;
3
3
  export * from "react-router-dom";
4
4
  export * from "history";
5
+ export {
6
+ runtime_default as default
7
+ };
@@ -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
- 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) || [];
10
+ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
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
  });
@@ -104,3 +101,6 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
104
101
  }
105
102
  };
106
103
  };
104
+ export {
105
+ routerPlugin
106
+ };
@@ -1,13 +1,12 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Route, matchPath } from "react-router-dom";
3
3
  import { DefaultNotFound } from "./DefaultNotFound";
4
- export function renderRoutes(routesConfig, extraProps = {}) {
4
+ function renderRoutes(routesConfig, extraProps = {}) {
5
5
  if (!routesConfig) {
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,
@@ -49,22 +48,22 @@ export function renderRoutes(routesConfig, extraProps = {}) {
49
48
  }
50
49
  });
51
50
  }
52
- 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://", "");
51
+ function getLocation(serverContext) {
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;
59
58
  }
60
59
  return cleanUrl.substring(index);
61
60
  }
62
- export const urlJoin = (...parts) => {
61
+ const urlJoin = (...parts) => {
63
62
  const separator = "/";
64
63
  const replace = new RegExp(`${separator}{1,}`, "g");
65
64
  return standardSlash(parts.join(separator).replace(replace, separator));
66
65
  };
67
- export function standardSlash(str) {
66
+ function standardSlash(str) {
68
67
  let addr = str;
69
68
  if (!addr || typeof addr !== "string") {
70
69
  return addr;
@@ -80,3 +79,9 @@ export function standardSlash(str) {
80
79
  }
81
80
  return addr;
82
81
  }
82
+ export {
83
+ getLocation,
84
+ renderRoutes,
85
+ standardSlash,
86
+ urlJoin
87
+ };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.35.0",
18
+ "version": "2.36.0",
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.35.0",
64
- "@modern-js/utils": "2.35.0",
65
- "@modern-js/types": "2.35.0"
63
+ "@modern-js/plugin": "2.36.0",
64
+ "@modern-js/types": "2.36.0",
65
+ "@modern-js/utils": "2.36.0"
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.35.0",
82
- "@modern-js/core": "2.35.0",
83
- "@modern-js/runtime": "2.35.0",
84
- "@modern-js/utils": "2.35.0",
85
- "@scripts/jest-config": "2.35.0",
86
- "@scripts/build": "2.35.0"
81
+ "@modern-js/app-tools": "2.36.0",
82
+ "@modern-js/core": "2.36.0",
83
+ "@modern-js/runtime": "2.36.0",
84
+ "@modern-js/utils": "2.36.0",
85
+ "@modern-js/runtime-utils": "2.36.0",
86
+ "@scripts/build": "2.36.0",
87
+ "@scripts/jest-config": "2.36.0"
87
88
  },
88
89
  "sideEffects": false,
89
90
  "publishConfig": {