@modern-js/plugin-router-v5 2.37.1 → 2.37.2-fix.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,96 +24,52 @@ __export(cli_exports, {
24
24
  module.exports = __toCommonJS(cli_exports);
25
25
  var import_utils = require("@modern-js/utils");
26
26
  var import_types = require("./types");
27
- const PLUGIN_IDENTIFIER = "router";
28
- const ROUTES_IDENTIFIER = "routes";
29
27
  const routerPlugin = () => ({
30
28
  name: "@modern-js/plugin-router-v5",
31
29
  required: [
32
30
  "@modern-js/runtime"
33
31
  ],
34
32
  setup: (api) => {
35
- const runtimeConfigMap = /* @__PURE__ */ new Map();
36
- let pluginsExportsUtils;
37
33
  let routerExportsUtils;
38
- return {
39
- config() {
40
- const appContext = api.useAppContext();
41
- pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(appContext.internalDirectory, "plugins");
42
- routerExportsUtils = (0, import_utils.createRuntimeExportsUtils)(appContext.internalDirectory, "router");
43
- return {
44
- source: {
45
- alias: {
46
- "@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
47
- "@modern-js/runtime/router-v5": routerExportsUtils.getPath()
48
- }
49
- }
50
- };
51
- },
52
- validateSchema() {
53
- return [
54
- {
55
- target: "runtime.router",
56
- schema: {
57
- type: [
58
- "boolean",
59
- "object"
60
- ]
61
- }
62
- }
63
- ];
64
- },
65
- modifyEntryImports({ entrypoint, imports }) {
66
- const { entryName, isMainEntry } = entrypoint;
67
- const userConfig = api.useResolvedConfigContext();
68
- const { packageName } = api.useAppContext();
69
- const runtimeConfig = (0, import_utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
70
- runtimeConfigMap.set(entryName, runtimeConfig);
71
- if ((0, import_utils.isRouterV5)(userConfig)) {
72
- imports.push({
73
- value: "@modern-js/runtime/plugins",
74
- specifiers: [
75
- {
76
- imported: PLUGIN_IDENTIFIER
77
- }
78
- ]
79
- });
80
- } else {
81
- throw new Error(`should enable runtime.router.mode for entry ${entryName}`);
34
+ api._internalRuntimePlugins(({ entrypoint, plugins }) => {
35
+ var _getEntryOptions;
36
+ const userConfig = api.getNormalizedConfig();
37
+ const { serverRoutes, metaName, packageName } = api.getAppContext();
38
+ const routerConfig = (_getEntryOptions = (0, import_utils.getEntryOptions)(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
39
+ const serverBase = serverRoutes.filter((route) => route.entryName === entrypoint.entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
40
+ plugins.push({
41
+ name: "router",
42
+ path: `@${metaName}/plugin-router-v5/runtime`,
43
+ config: typeof routerConfig === "boolean" ? {
44
+ serverBase
45
+ } : {
46
+ ...routerConfig,
47
+ serverBase
82
48
  }
83
- return {
84
- entrypoint,
85
- imports
86
- };
87
- },
88
- modifyEntryRuntimePlugins({ entrypoint, plugins }) {
89
- const { entryName, fileSystemRoutes } = entrypoint;
90
- const { serverRoutes } = api.useAppContext();
91
- const runtimeConfig = runtimeConfigMap.get(entryName);
92
- const userConfig = api.useResolvedConfigContext();
93
- if ((0, import_utils.isRouterV5)(userConfig)) {
94
- const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
95
- plugins.push({
96
- name: PLUGIN_IDENTIFIER,
97
- options: JSON.stringify({
98
- serverBase,
99
- ...runtimeConfig.router,
100
- routesConfig: fileSystemRoutes ? `{ ${ROUTES_IDENTIFIER}, globalApp: App }` : void 0
101
- }).replace(/"routesConfig"\s*:\s*"((\S|\s)+)"/g, '"routesConfig": $1,')
102
- });
103
- }
104
- return {
105
- entrypoint,
106
- plugins
107
- };
108
- },
109
- addRuntimeExports() {
110
- const userConfig = api.useResolvedConfigContext();
111
- if ((0, import_utils.isRouterV5)(userConfig)) {
112
- pluginsExportsUtils.addExport(`export { default as router } 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'`);
49
+ });
50
+ return {
51
+ entrypoint,
52
+ plugins
53
+ };
54
+ });
55
+ api.config(() => {
56
+ const { internalDirectory, metaName } = api.getAppContext();
57
+ routerExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "router");
58
+ return {
59
+ source: {
60
+ alias: {
61
+ [`@${metaName}/runtime/router-v5`]: routerExportsUtils.getPath()
62
+ }
114
63
  }
115
- }
116
- };
64
+ };
65
+ });
66
+ api.addRuntimeExports(() => {
67
+ const userConfig = api.getNormalizedConfig();
68
+ const { internalDirectory, metaName } = api.getAppContext();
69
+ const pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "plugins");
70
+ pluginsExportsUtils.addExport(`export { default as router } from '@${metaName}/plugin-router-v5/runtime'`);
71
+ routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@${metaName}/plugin-router-v5/runtime'`);
72
+ });
117
73
  }
118
74
  });
119
75
  var cli_default = routerPlugin;
@@ -21,8 +21,8 @@ __export(hooks_exports, {
21
21
  modifyRoutesHook: () => modifyRoutesHook
22
22
  });
23
23
  module.exports = __toCommonJS(hooks_exports);
24
- var import_plugin = require("@modern-js/plugin");
25
- const modifyRoutesHook = (0, import_plugin.createWaterfall)();
24
+ var import_plugin_v2 = require("@modern-js/plugin-v2");
25
+ const modifyRoutesHook = (0, import_plugin_v2.createSyncHook)();
26
26
  // Annotate the CommonJS export names for ESM import in node:
27
27
  0 && (module.exports = {
28
28
  modifyRoutesHook
@@ -19,15 +19,18 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var runtime_exports = {};
21
21
  __export(runtime_exports, {
22
- default: () => runtime_default
22
+ default: () => runtime_default,
23
+ routerPlugin: () => import_plugin2.routerPlugin
23
24
  });
24
25
  module.exports = __toCommonJS(runtime_exports);
25
26
  var import_plugin = require("./plugin");
27
+ var import_plugin2 = require("./plugin");
26
28
  __reExport(runtime_exports, require("react-router-dom"), module.exports);
27
29
  __reExport(runtime_exports, require("history"), module.exports);
28
30
  var runtime_default = import_plugin.routerPlugin;
29
31
  // Annotate the CommonJS export names for ESM import in node:
30
32
  0 && (module.exports = {
33
+ routerPlugin,
31
34
  ...require("react-router-dom"),
32
35
  ...require("history")
33
36
  });
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var plugin_exports = {};
30
20
  __export(plugin_exports, {
@@ -32,105 +22,93 @@ __export(plugin_exports, {
32
22
  });
33
23
  module.exports = __toCommonJS(plugin_exports);
34
24
  var import_jsx_runtime = require("react/jsx-runtime");
35
- var import_react = require("react");
25
+ var import_runtime = require("@meta/runtime");
26
+ var import_context = require("@meta/runtime/context");
27
+ var import_merge = require("@modern-js/runtime-utils/merge");
36
28
  var import_history = require("history");
29
+ var import_react = require("react");
37
30
  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
31
  var import_hooks = require("./hooks");
43
- const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
44
- const originRoutes = (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.routes) || [];
45
- const isBrow = (0, import_runtime.isBrowser)();
46
- const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
47
- let routes = [];
48
- if (isBrow) {
49
- window._SERVER_DATA = (0, import_browser.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
50
- }
32
+ var import_utils = require("./utils");
33
+ let routes = [];
34
+ const routerPlugin = (userConfig = {}) => {
51
35
  return {
52
36
  name: "@modern-js/plugin-router",
53
- registerHook: {
37
+ registryHooks: {
54
38
  modifyRoutes: import_hooks.modifyRoutesHook
55
39
  },
56
40
  setup: (api) => {
57
- return {
58
- init({ context }, next) {
59
- context.router = {
60
- useRouteMatch: import_react_router_dom.useRouteMatch,
61
- useLocation: import_react_router_dom.useLocation
62
- };
63
- Object.defineProperty(context, "routes", {
64
- get() {
65
- return routes;
66
- }
67
- });
68
- return next({
69
- context
70
- });
71
- },
72
- hoc: ({ App }, next) => {
73
- const getRouteApp = () => {
74
- if (isBrow) {
75
- var _window__SERVER_DATA;
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);
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));
79
- return (props) => {
80
- const runner = api.useHookRunners();
81
- routes = runner.modifyRoutes(originRoutes);
82
- routesConfig && (routesConfig.routes = routes);
83
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Router, {
84
- history,
85
- children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
86
- ...props,
87
- Component: createRoutes()
88
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
89
- ...props,
90
- children: (0, import_utils.renderRoutes)(routesConfig, props)
91
- })
92
- });
93
- };
94
- }
41
+ api.onBeforeRender((context) => {
42
+ context.router = {
43
+ useRouteMatch: import_react_router_dom.useRouteMatch,
44
+ useLocation: import_react_router_dom.useLocation,
45
+ useHistory: import_react_router_dom.useHistory
46
+ };
47
+ Object.defineProperty(context, "routes", {
48
+ get() {
49
+ return routes;
50
+ }
51
+ });
52
+ });
53
+ api.wrapRoot((App) => {
54
+ const pluginConfig = api.getRuntimeConfig();
55
+ const { serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} } = (0, import_merge.merge)(pluginConfig.router || {}, userConfig);
56
+ const finalRouteConfig = {
57
+ routes: (0, import_context.getGlobalRoutes)(),
58
+ globalApp: (0, import_context.getGlobalLayoutApp)(),
59
+ ...routesConfig
60
+ };
61
+ const originRoutes = finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes;
62
+ const isBrow = (0, import_runtime.isBrowser)();
63
+ const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
64
+ const getRouteApp = () => {
65
+ if (isBrow) {
95
66
  return (props) => {
96
67
  const runtimeContext = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
97
- const { ssrContext } = runtimeContext;
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;
103
- const runner = api.useHookRunners();
104
- const routes2 = runner.modifyRoutes(originRoutes);
105
- routesConfig && (routesConfig.routes = routes2);
106
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.StaticRouter, {
107
- basename: basename === "/" ? "" : basename,
108
- location: location1,
109
- context: routerContext,
68
+ const baseUrl = select(location.pathname).replace(/^\/*/, "/");
69
+ const basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
70
+ historyOptions.basename = basename;
71
+ const history = customHistory || (supportHtml5History ? (0, import_history.createBrowserHistory)(historyOptions) : (0, import_history.createHashHistory)(historyOptions));
72
+ const hooks = api.getHooks();
73
+ routes = hooks.modifyRoutes.call(originRoutes);
74
+ finalRouteConfig && (finalRouteConfig.routes = routes);
75
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Router, {
76
+ history,
110
77
  children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
111
- ...props,
112
78
  Component: createRoutes()
113
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
114
- ...props,
115
- children: (0, import_utils.renderRoutes)(routesConfig, props)
116
- })
79
+ }) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
80
+ ...props
81
+ }) : (0, import_utils.renderRoutes)(finalRouteConfig, props)
117
82
  });
118
83
  };
119
- };
120
- let RouteApp = getRouteApp();
121
- if (App) {
122
- RouteApp = (0, import_hoist_non_react_statics.default)(RouteApp, App);
123
84
  }
124
- if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
125
- return next({
126
- App: (0, import_hoist_non_react_statics.default)(RouteApp, routesConfig.globalApp)
85
+ return (props) => {
86
+ var _request_baseUrl;
87
+ const runtimeContext = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
88
+ const { ssrContext } = runtimeContext;
89
+ const location1 = (0, import_utils.getLocation)(ssrContext);
90
+ const routerContext = (ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.redirection) || {};
91
+ const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
92
+ const baseUrl = request === null || request === void 0 ? void 0 : (_request_baseUrl = request.baseUrl) === null || _request_baseUrl === void 0 ? void 0 : _request_baseUrl.replace(/^\/*/, "/");
93
+ const basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
94
+ const hooks = api.getHooks();
95
+ const routes2 = hooks.modifyRoutes.call(originRoutes);
96
+ finalRouteConfig && (finalRouteConfig.routes = routes2);
97
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.StaticRouter, {
98
+ basename: basename === "/" ? "" : basename,
99
+ location: location1,
100
+ context: routerContext,
101
+ children: createRoutes ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
102
+ Component: createRoutes(),
103
+ ...props
104
+ }) : App && !(finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
105
+ ...props
106
+ }) : (0, import_utils.renderRoutes)(finalRouteConfig, props)
127
107
  });
128
- }
129
- return next({
130
- App: RouteApp
131
- });
132
- }
133
- };
108
+ };
109
+ };
110
+ return getRouteApp();
111
+ });
134
112
  }
135
113
  };
136
114
  };
@@ -1,9 +1,8 @@
1
+ import { _ as _define_property } from "@swc/helpers/_/_define_property";
1
2
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
3
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
- import { getEntryOptions, createRuntimeExportsUtils, isRouterV5 as isV5 } from "@modern-js/utils";
4
+ import { createRuntimeExportsUtils, getEntryOptions } from "@modern-js/utils";
4
5
  import "./types";
5
- var PLUGIN_IDENTIFIER = "router";
6
- var ROUTES_IDENTIFIER = "routes";
7
6
  var routerPlugin = function() {
8
7
  return {
9
8
  name: "@modern-js/plugin-router-v5",
@@ -11,96 +10,50 @@ var routerPlugin = function() {
11
10
  "@modern-js/runtime"
12
11
  ],
13
12
  setup: function(api) {
14
- var runtimeConfigMap = /* @__PURE__ */ new Map();
15
- var pluginsExportsUtils;
16
13
  var routerExportsUtils;
17
- return {
18
- config: function config() {
19
- var appContext = api.useAppContext();
20
- pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "plugins");
21
- routerExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "router");
22
- return {
23
- source: {
24
- alias: {
25
- "@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
26
- "@modern-js/runtime/router-v5": routerExportsUtils.getPath()
27
- }
28
- }
29
- };
30
- },
31
- validateSchema: function validateSchema() {
32
- return [
33
- {
34
- target: "runtime.router",
35
- schema: {
36
- type: [
37
- "boolean",
38
- "object"
39
- ]
40
- }
41
- }
42
- ];
43
- },
44
- modifyEntryImports: function modifyEntryImports(param) {
45
- var entrypoint = param.entrypoint, imports = param.imports;
46
- var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
47
- var userConfig = api.useResolvedConfigContext();
48
- var packageName = api.useAppContext().packageName;
49
- var runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
50
- runtimeConfigMap.set(entryName, runtimeConfig);
51
- if (isV5(userConfig)) {
52
- imports.push({
53
- value: "@modern-js/runtime/plugins",
54
- specifiers: [
55
- {
56
- imported: PLUGIN_IDENTIFIER
57
- }
58
- ]
59
- });
60
- } else {
61
- throw new Error("should enable runtime.router.mode for entry ".concat(entryName));
14
+ api._internalRuntimePlugins(function(param) {
15
+ var entrypoint = param.entrypoint, plugins = param.plugins;
16
+ var _getEntryOptions;
17
+ var userConfig = api.getNormalizedConfig();
18
+ var _api_getAppContext = api.getAppContext(), serverRoutes = _api_getAppContext.serverRoutes, metaName = _api_getAppContext.metaName, packageName = _api_getAppContext.packageName;
19
+ var routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
20
+ var serverBase = serverRoutes.filter(function(route) {
21
+ return route.entryName === entrypoint.entryName;
22
+ }).map(function(route) {
23
+ return route.urlPath;
24
+ }).sort(function(a, b) {
25
+ return a.length - b.length > 0 ? -1 : 1;
26
+ });
27
+ plugins.push({
28
+ name: "router",
29
+ path: "@".concat(metaName, "/plugin-router-v5/runtime"),
30
+ config: typeof routerConfig === "boolean" ? {
31
+ serverBase
32
+ } : _object_spread_props(_object_spread({}, routerConfig), {
33
+ serverBase
34
+ })
35
+ });
36
+ return {
37
+ entrypoint,
38
+ plugins
39
+ };
40
+ });
41
+ api.config(function() {
42
+ var _api_getAppContext = api.getAppContext(), internalDirectory = _api_getAppContext.internalDirectory, metaName = _api_getAppContext.metaName;
43
+ routerExportsUtils = createRuntimeExportsUtils(internalDirectory, "router");
44
+ return {
45
+ source: {
46
+ alias: _define_property({}, "@".concat(metaName, "/runtime/router-v5"), routerExportsUtils.getPath())
62
47
  }
63
- return {
64
- entrypoint,
65
- imports
66
- };
67
- },
68
- modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(param) {
69
- var entrypoint = param.entrypoint, plugins = param.plugins;
70
- var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes;
71
- var serverRoutes = api.useAppContext().serverRoutes;
72
- var runtimeConfig = runtimeConfigMap.get(entryName);
73
- var userConfig = api.useResolvedConfigContext();
74
- if (isV5(userConfig)) {
75
- var serverBase = serverRoutes.filter(function(route) {
76
- return route.entryName === entryName;
77
- }).map(function(route) {
78
- return route.urlPath;
79
- }).sort(function(a, b) {
80
- return a.length - b.length > 0 ? -1 : 1;
81
- });
82
- plugins.push({
83
- name: PLUGIN_IDENTIFIER,
84
- options: JSON.stringify(_object_spread_props(_object_spread({
85
- serverBase
86
- }, runtimeConfig.router), {
87
- routesConfig: fileSystemRoutes ? "{ ".concat(ROUTES_IDENTIFIER, ", globalApp: App }") : void 0
88
- })).replace(/"routesConfig"\s*:\s*"((\S|\s)+)"/g, '"routesConfig": $1,')
89
- });
90
- }
91
- return {
92
- entrypoint,
93
- plugins
94
- };
95
- },
96
- addRuntimeExports: function addRuntimeExports() {
97
- var userConfig = api.useResolvedConfigContext();
98
- if (isV5(userConfig)) {
99
- pluginsExportsUtils.addExport("export { default as router } 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'");
101
- }
102
- }
103
- };
48
+ };
49
+ });
50
+ api.addRuntimeExports(function() {
51
+ var userConfig = api.getNormalizedConfig();
52
+ var _api_getAppContext = api.getAppContext(), internalDirectory = _api_getAppContext.internalDirectory, metaName = _api_getAppContext.metaName;
53
+ var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
54
+ pluginsExportsUtils.addExport("export { default as router } from '@".concat(metaName, "/plugin-router-v5/runtime'"));
55
+ routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport("export * from '@".concat(metaName, "/plugin-router-v5/runtime'"));
56
+ });
104
57
  }
105
58
  };
106
59
  };
@@ -1,5 +1,5 @@
1
- import { createWaterfall } from "@modern-js/plugin";
2
- var modifyRoutesHook = createWaterfall();
1
+ import { createSyncHook } from "@modern-js/plugin-v2";
2
+ var modifyRoutesHook = createSyncHook();
3
3
  export {
4
4
  modifyRoutesHook
5
5
  };
@@ -1,7 +1,9 @@
1
1
  import { routerPlugin } from "./plugin";
2
+ import { routerPlugin as routerPlugin2 } from "./plugin";
2
3
  var runtime_default = routerPlugin;
3
4
  export * from "react-router-dom";
4
5
  export * from "history";
5
6
  export {
6
- runtime_default as default
7
+ runtime_default as default,
8
+ routerPlugin2 as routerPlugin
7
9
  };