@modern-js/plugin-router-v5 2.35.1 → 2.37.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,7 +108,7 @@ const routerPlugin = () => ({
103
108
  },
104
109
  addRuntimeExports() {
105
110
  const userConfig = api.useResolvedConfigContext();
106
- if ((0, _utils.isRouterV5)(userConfig)) {
111
+ if ((0, import_utils.isRouterV5)(userConfig)) {
107
112
  pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/plugin-router-v5/runtime'`);
108
113
  routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@modern-js/plugin-router-v5/runtime'`);
109
114
  }
@@ -111,4 +116,8 @@ const routerPlugin = () => ({
111
116
  };
112
117
  }
113
118
  });
114
- 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,43 +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 _browser = require("@modern-js/runtime-utils/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
44
  const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
24
- const isBrow = (0, _runtime.isBrowser)();
45
+ const isBrow = (0, import_runtime.isBrowser)();
25
46
  const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
26
47
  let routes = [];
27
48
  if (isBrow) {
28
- window._SERVER_DATA = (0, _browser.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
49
+ window._SERVER_DATA = (0, import_browser.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
29
50
  }
30
51
  return {
31
52
  name: "@modern-js/plugin-router",
32
53
  registerHook: {
33
- modifyRoutes: _hooks.modifyRoutesHook
54
+ modifyRoutes: import_hooks.modifyRoutesHook
34
55
  },
35
56
  setup: (api) => {
36
57
  return {
37
58
  init({ context }, next) {
38
59
  context.router = {
39
- useRouteMatch: _reactrouterdom.useRouteMatch,
40
- useLocation: _reactrouterdom.useLocation
60
+ useRouteMatch: import_react_router_dom.useRouteMatch,
61
+ useLocation: import_react_router_dom.useLocation
41
62
  };
42
63
  Object.defineProperty(context, "routes", {
43
64
  get() {
@@ -53,56 +74,56 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
53
74
  if (isBrow) {
54
75
  var _window__SERVER_DATA;
55
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);
56
- historyOptions.basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
57
- 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));
58
79
  return (props) => {
59
80
  const runner = api.useHookRunners();
60
81
  routes = runner.modifyRoutes(originRoutes);
61
82
  routesConfig && (routesConfig.routes = routes);
62
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Router, {
83
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Router, {
63
84
  history,
64
- children: createRoutes ? /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
85
+ children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
65
86
  ...props,
66
87
  Component: createRoutes()
67
- }) : /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
88
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
68
89
  ...props,
69
- children: (0, _utils.renderRoutes)(routesConfig, props)
90
+ children: (0, import_utils.renderRoutes)(routesConfig, props)
70
91
  })
71
92
  });
72
93
  };
73
94
  }
74
95
  return (props) => {
75
- const runtimeContext = (0, _react.useContext)(_runtime.RuntimeReactContext);
96
+ const runtimeContext = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
76
97
  const { ssrContext } = runtimeContext;
77
- const location1 = (0, _utils.getLocation)(ssrContext);
98
+ const location1 = (0, import_utils.getLocation)(ssrContext);
78
99
  const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
79
100
  const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
80
101
  const baseUrl = request === null || request === void 0 ? void 0 : request.baseUrl;
81
- const basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
102
+ const basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
82
103
  const runner = api.useHookRunners();
83
104
  const routes2 = runner.modifyRoutes(originRoutes);
84
105
  routesConfig && (routesConfig.routes = routes2);
85
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.StaticRouter, {
106
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.StaticRouter, {
86
107
  basename: basename === "/" ? "" : basename,
87
108
  location: location1,
88
109
  context: routerContext,
89
- children: createRoutes ? /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
110
+ children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
90
111
  ...props,
91
112
  Component: createRoutes()
92
- }) : /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
113
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
93
114
  ...props,
94
- children: (0, _utils.renderRoutes)(routesConfig, props)
115
+ children: (0, import_utils.renderRoutes)(routesConfig, props)
95
116
  })
96
117
  });
97
118
  };
98
119
  };
99
120
  let RouteApp = getRouteApp();
100
121
  if (App) {
101
- RouteApp = (0, _hoistnonreactstatics.default)(RouteApp, App);
122
+ RouteApp = (0, import_hoist_non_react_statics.default)(RouteApp, App);
102
123
  }
103
124
  if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
104
125
  return next({
105
- App: (0, _hoistnonreactstatics.default)(RouteApp, routesConfig.globalApp)
126
+ App: (0, import_hoist_non_react_statics.default)(RouteApp, routesConfig.globalApp)
106
127
  });
107
128
  }
108
129
  return next({
@@ -113,3 +134,7 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
113
134
  }
114
135
  };
115
136
  };
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ routerPlugin
140
+ });
@@ -1,33 +1,32 @@
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;
@@ -35,11 +34,11 @@ function renderRoutes(routesConfig, extraProps = {}) {
35
34
  const Layout = ({ Component, ...props }) => {
36
35
  const GlobalLayout = routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp;
37
36
  if (!GlobalLayout) {
38
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {
37
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
39
38
  ...props
40
39
  });
41
40
  }
42
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(GlobalLayout, {
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GlobalLayout, {
43
42
  Component,
44
43
  ...props
45
44
  });
@@ -47,7 +46,7 @@ function renderRoutes(routesConfig, extraProps = {}) {
47
46
  const findMatchedRoute = (pathname) => {
48
47
  var _routesConfig_routes;
49
48
  return routesConfig === null || routesConfig === void 0 ? void 0 : (_routesConfig_routes = routesConfig.routes) === null || _routesConfig_routes === void 0 ? void 0 : _routesConfig_routes.find((route) => {
50
- const info = (0, _reactrouterdom.matchPath)(pathname, {
49
+ const info = (0, import_react_router_dom.matchPath)(pathname, {
51
50
  path: route.path,
52
51
  exact: route.exact,
53
52
  sensitive: route.sensitive
@@ -55,18 +54,18 @@ function renderRoutes(routesConfig, extraProps = {}) {
55
54
  return Boolean(info);
56
55
  });
57
56
  };
58
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Route, {
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, {
59
58
  path: "/",
60
59
  render: (props) => {
61
60
  const matchedRoute = findMatchedRoute(props.location.pathname);
62
61
  if (!matchedRoute) {
63
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_DefaultNotFound.DefaultNotFound, {});
62
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DefaultNotFound.DefaultNotFound, {});
64
63
  }
65
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Route, {
64
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, {
66
65
  path: matchedRoute.path,
67
66
  exact: matchedRoute.exact,
68
67
  sensitive: matchedRoute.sensitive,
69
- render: (routeProps) => /* @__PURE__ */ (0, _jsxruntime.jsx)(Layout, {
68
+ render: (routeProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Layout, {
70
69
  Component: matchedRoute.component,
71
70
  ...routeProps,
72
71
  ...extraProps
@@ -106,3 +105,10 @@ function standardSlash(str) {
106
105
  }
107
106
  return addr;
108
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,15 +82,15 @@ 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() {
@@ -104,4 +104,8 @@ export var routerPlugin = function() {
104
104
  }
105
105
  };
106
106
  };
107
- 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
+ };
@@ -9,7 +9,7 @@ import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
9
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
14
  var originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
15
15
  var isBrow = isBrowser();
@@ -32,8 +32,8 @@ export var routerPlugin = function(param) {
32
32
  init: function init(param2, next) {
33
33
  var context = param2.context;
34
34
  context.router = {
35
- useRouteMatch: useRouteMatch,
36
- useLocation: useLocation
35
+ useRouteMatch,
36
+ useLocation
37
37
  };
38
38
  Object.defineProperty(context, "routes", {
39
39
  get: function get() {
@@ -41,7 +41,7 @@ export var routerPlugin = function(param) {
41
41
  }
42
42
  });
43
43
  return next({
44
- context: context
44
+ context
45
45
  });
46
46
  },
47
47
  hoc: function(param2, next) {
@@ -57,7 +57,7 @@ export var routerPlugin = function(param) {
57
57
  routes = runner.modifyRoutes(originRoutes);
58
58
  routesConfig && (routesConfig.routes = routes);
59
59
  return /* @__PURE__ */ _jsx(Router, {
60
- history: history,
60
+ history,
61
61
  children: createRoutes ? /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
62
62
  Component: createRoutes()
63
63
  })) : /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
@@ -106,3 +106,6 @@ export var routerPlugin = function(param) {
106
106
  }
107
107
  };
108
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;
@@ -17,7 +17,7 @@ export function renderRoutes(routesConfig) {
17
17
  return /* @__PURE__ */ _jsx(Component, _object_spread({}, props));
18
18
  }
19
19
  return /* @__PURE__ */ _jsx(GlobalLayout, _object_spread({
20
- Component: Component
20
+ Component
21
21
  }, props));
22
22
  };
23
23
  var findMatchedRoute = function(pathname) {
@@ -51,7 +51,7 @@ export function renderRoutes(routesConfig) {
51
51
  }
52
52
  });
53
53
  }
54
- export function getLocation(serverContext) {
54
+ function getLocation(serverContext) {
55
55
  var _url_replace;
56
56
  var _ref = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {}, pathname = _ref.pathname, url = _ref.url;
57
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://", "");
@@ -61,7 +61,7 @@ export function getLocation(serverContext) {
61
61
  }
62
62
  return cleanUrl.substring(index);
63
63
  }
64
- export var urlJoin = function() {
64
+ var urlJoin = function() {
65
65
  for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
66
66
  parts[_key] = arguments[_key];
67
67
  }
@@ -69,7 +69,7 @@ export var urlJoin = function() {
69
69
  var replace = new RegExp("".concat(separator, "{1,}"), "g");
70
70
  return standardSlash(parts.join(separator).replace(replace, separator));
71
71
  };
72
- export function standardSlash(str) {
72
+ function standardSlash(str) {
73
73
  var addr = str;
74
74
  if (!addr || typeof addr !== "string") {
75
75
  return addr;
@@ -85,3 +85,9 @@ export function standardSlash(str) {
85
85
  }
86
86
  return addr;
87
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"
@@ -92,4 +92,8 @@ export const routerPlugin = () => ({
92
92
  };
93
93
  }
94
94
  });
95
- 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
+ };
@@ -7,7 +7,7 @@ import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
7
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 = {} }) => {
10
+ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
11
11
  const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
12
12
  const isBrow = isBrowser();
13
13
  const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
@@ -101,3 +101,6 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
101
101
  }
102
102
  };
103
103
  };
104
+ export {
105
+ routerPlugin
106
+ };
@@ -1,7 +1,7 @@
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
  }
@@ -48,7 +48,7 @@ export function renderRoutes(routesConfig, extraProps = {}) {
48
48
  }
49
49
  });
50
50
  }
51
- export function getLocation(serverContext) {
51
+ function getLocation(serverContext) {
52
52
  var _url_replace;
53
53
  const { pathname, url } = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
54
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://", "");
@@ -58,12 +58,12 @@ export function getLocation(serverContext) {
58
58
  }
59
59
  return cleanUrl.substring(index);
60
60
  }
61
- export const urlJoin = (...parts) => {
61
+ const urlJoin = (...parts) => {
62
62
  const separator = "/";
63
63
  const replace = new RegExp(`${separator}{1,}`, "g");
64
64
  return standardSlash(parts.join(separator).replace(replace, separator));
65
65
  };
66
- export function standardSlash(str) {
66
+ function standardSlash(str) {
67
67
  let addr = str;
68
68
  if (!addr || typeof addr !== "string") {
69
69
  return addr;
@@ -79,3 +79,9 @@ export function standardSlash(str) {
79
79
  }
80
80
  return addr;
81
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.1",
18
+ "version": "2.37.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.1",
64
- "@modern-js/types": "2.35.1",
65
- "@modern-js/utils": "2.35.1"
63
+ "@modern-js/plugin": "2.37.0",
64
+ "@modern-js/types": "2.37.0",
65
+ "@modern-js/utils": "2.37.0"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "react": ">=17",
@@ -78,13 +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.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"
81
+ "@modern-js/app-tools": "2.37.0",
82
+ "@modern-js/core": "2.37.0",
83
+ "@modern-js/runtime": "2.37.0",
84
+ "@modern-js/utils": "2.37.0",
85
+ "@modern-js/runtime-utils": "2.37.0",
86
+ "@scripts/build": "2.37.0",
87
+ "@scripts/jest-config": "2.37.0"
88
88
  },
89
89
  "sideEffects": false,
90
90
  "publishConfig": {