@modern-js/plugin-router-v5 2.63.3 → 2.63.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,51 +31,49 @@ const routerPlugin = () => ({
31
31
  ],
32
32
  setup: (api) => {
33
33
  let routerExportsUtils;
34
- return {
35
- _internalRuntimePlugins({ entrypoint, plugins }) {
36
- const userConfig = api.useResolvedConfigContext();
37
- const { serverRoutes, metaName, packageName } = api.useAppContext();
38
- if ((0, import_utils.isRouterV5)(userConfig)) {
39
- var _getEntryOptions;
40
- const routerConfig = (_getEntryOptions = (0, import_utils.getEntryOptions)(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
41
- const serverBase = serverRoutes.filter((route) => route.entryName === entrypoint.entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
42
- plugins.push({
43
- name: "router",
44
- path: `@${metaName}/plugin-router-v5/runtime`,
45
- config: typeof routerConfig === "boolean" ? {
46
- serverBase
47
- } : {
48
- ...routerConfig,
49
- serverBase
50
- }
51
- });
52
- }
53
- return {
54
- entrypoint,
55
- plugins
56
- };
57
- },
58
- config() {
59
- const { internalDirectory, metaName } = api.useAppContext();
60
- routerExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "router");
61
- return {
62
- source: {
63
- alias: {
64
- [`@${metaName}/runtime/router-v5`]: routerExportsUtils.getPath()
65
- }
34
+ api._internalRuntimePlugins(({ entrypoint, plugins }) => {
35
+ const userConfig = api.getNormalizedConfig();
36
+ const { serverRoutes, metaName, packageName } = api.getAppContext();
37
+ if ((0, import_utils.isRouterV5)(userConfig)) {
38
+ var _getEntryOptions;
39
+ const routerConfig = (_getEntryOptions = (0, import_utils.getEntryOptions)(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
40
+ const serverBase = serverRoutes.filter((route) => route.entryName === entrypoint.entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
41
+ plugins.push({
42
+ name: "router",
43
+ path: `@${metaName}/plugin-router-v5/runtime`,
44
+ config: typeof routerConfig === "boolean" ? {
45
+ serverBase
46
+ } : {
47
+ ...routerConfig,
48
+ serverBase
49
+ }
50
+ });
51
+ }
52
+ return {
53
+ entrypoint,
54
+ plugins
55
+ };
56
+ });
57
+ api.config(() => {
58
+ const { internalDirectory, metaName } = api.getAppContext();
59
+ routerExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "router");
60
+ return {
61
+ source: {
62
+ alias: {
63
+ [`@${metaName}/runtime/router-v5`]: routerExportsUtils.getPath()
66
64
  }
67
- };
68
- },
69
- addRuntimeExports() {
70
- const userConfig = api.useResolvedConfigContext();
71
- const { internalDirectory, metaName } = api.useAppContext();
72
- const pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "plugins");
73
- if ((0, import_utils.isRouterV5)(userConfig)) {
74
- pluginsExportsUtils.addExport(`export { default as router } from '@${metaName}/plugin-router-v5/runtime'`);
75
- routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@${metaName}/plugin-router-v5/runtime'`);
76
65
  }
66
+ };
67
+ });
68
+ api.addRuntimeExports(() => {
69
+ const userConfig = api.getNormalizedConfig();
70
+ const { internalDirectory, metaName } = api.getAppContext();
71
+ const pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(internalDirectory, "plugins");
72
+ if ((0, import_utils.isRouterV5)(userConfig)) {
73
+ pluginsExportsUtils.addExport(`export { default as router } from '@${metaName}/plugin-router-v5/runtime'`);
74
+ routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@${metaName}/plugin-router-v5/runtime'`);
77
75
  }
78
- };
76
+ });
79
77
  }
80
78
  });
81
79
  var cli_default = routerPlugin;
@@ -25,7 +25,6 @@ var import_jsx_runtime = require("react/jsx-runtime");
25
25
  var import_runtime = require("@meta/runtime");
26
26
  var import_context = require("@meta/runtime/context");
27
27
  var import_merge = require("@modern-js/runtime-utils/merge");
28
- var import_parsed = require("@modern-js/runtime-utils/parsed");
29
28
  var import_history = require("history");
30
29
  var import_react = require("react");
31
30
  var import_react_router_dom = require("react-router-dom");
@@ -63,15 +62,11 @@ const routerPlugin = (userConfig = {}) => {
63
62
  const originRoutes = finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes;
64
63
  const isBrow = (0, import_runtime.isBrowser)();
65
64
  const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
66
- if (isBrow) {
67
- window._SERVER_DATA = (0, import_parsed.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
68
- }
69
65
  const getRouteApp = () => {
70
66
  if (isBrow) {
71
67
  return (props) => {
72
- var _window__SERVER_DATA;
73
68
  const runtimeContext = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
74
- const baseUrl = (((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
69
+ const baseUrl = select(location.pathname).replace(/^\/*/, "/");
75
70
  const basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
76
71
  historyOptions.basename = basename;
77
72
  const history = customHistory || (supportHtml5History ? (0, import_history.createBrowserHistory)(historyOptions) : (0, import_history.createHashHistory)(historyOptions));
@@ -11,55 +11,53 @@ var routerPlugin = function() {
11
11
  ],
12
12
  setup: function(api) {
13
13
  var routerExportsUtils;
14
- return {
15
- _internalRuntimePlugins: function _internalRuntimePlugins(param) {
16
- var entrypoint = param.entrypoint, plugins = param.plugins;
17
- var userConfig = api.useResolvedConfigContext();
18
- var _api_useAppContext = api.useAppContext(), serverRoutes = _api_useAppContext.serverRoutes, metaName = _api_useAppContext.metaName, packageName = _api_useAppContext.packageName;
19
- if (isV5(userConfig)) {
20
- var _getEntryOptions;
21
- var routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
22
- var serverBase = serverRoutes.filter(function(route) {
23
- return route.entryName === entrypoint.entryName;
24
- }).map(function(route) {
25
- return route.urlPath;
26
- }).sort(function(a, b) {
27
- return a.length - b.length > 0 ? -1 : 1;
28
- });
29
- plugins.push({
30
- name: "router",
31
- path: "@".concat(metaName, "/plugin-router-v5/runtime"),
32
- config: typeof routerConfig === "boolean" ? {
33
- serverBase
34
- } : _object_spread_props(_object_spread({}, routerConfig), {
35
- serverBase
36
- })
37
- });
38
- }
39
- return {
40
- entrypoint,
41
- plugins
42
- };
43
- },
44
- config: function config() {
45
- var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
46
- routerExportsUtils = createRuntimeExportsUtils(internalDirectory, "router");
47
- return {
48
- source: {
49
- alias: _define_property({}, "@".concat(metaName, "/runtime/router-v5"), routerExportsUtils.getPath())
50
- }
51
- };
52
- },
53
- addRuntimeExports: function addRuntimeExports() {
54
- var userConfig = api.useResolvedConfigContext();
55
- var _api_useAppContext = api.useAppContext(), internalDirectory = _api_useAppContext.internalDirectory, metaName = _api_useAppContext.metaName;
56
- var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
57
- if (isV5(userConfig)) {
58
- pluginsExportsUtils.addExport("export { default as router } from '@".concat(metaName, "/plugin-router-v5/runtime'"));
59
- routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport("export * from '@".concat(metaName, "/plugin-router-v5/runtime'"));
14
+ api._internalRuntimePlugins(function(param) {
15
+ var entrypoint = param.entrypoint, plugins = param.plugins;
16
+ var userConfig = api.getNormalizedConfig();
17
+ var _api_getAppContext = api.getAppContext(), serverRoutes = _api_getAppContext.serverRoutes, metaName = _api_getAppContext.metaName, packageName = _api_getAppContext.packageName;
18
+ if (isV5(userConfig)) {
19
+ var _getEntryOptions;
20
+ var routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
21
+ var serverBase = serverRoutes.filter(function(route) {
22
+ return route.entryName === entrypoint.entryName;
23
+ }).map(function(route) {
24
+ return route.urlPath;
25
+ }).sort(function(a, b) {
26
+ return a.length - b.length > 0 ? -1 : 1;
27
+ });
28
+ plugins.push({
29
+ name: "router",
30
+ path: "@".concat(metaName, "/plugin-router-v5/runtime"),
31
+ config: typeof routerConfig === "boolean" ? {
32
+ serverBase
33
+ } : _object_spread_props(_object_spread({}, routerConfig), {
34
+ serverBase
35
+ })
36
+ });
37
+ }
38
+ return {
39
+ entrypoint,
40
+ plugins
41
+ };
42
+ });
43
+ api.config(function() {
44
+ var _api_getAppContext = api.getAppContext(), internalDirectory = _api_getAppContext.internalDirectory, metaName = _api_getAppContext.metaName;
45
+ routerExportsUtils = createRuntimeExportsUtils(internalDirectory, "router");
46
+ return {
47
+ source: {
48
+ alias: _define_property({}, "@".concat(metaName, "/runtime/router-v5"), routerExportsUtils.getPath())
60
49
  }
50
+ };
51
+ });
52
+ api.addRuntimeExports(function() {
53
+ var userConfig = api.getNormalizedConfig();
54
+ var _api_getAppContext = api.getAppContext(), internalDirectory = _api_getAppContext.internalDirectory, metaName = _api_getAppContext.metaName;
55
+ var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
56
+ if (isV5(userConfig)) {
57
+ pluginsExportsUtils.addExport("export { default as router } from '@".concat(metaName, "/plugin-router-v5/runtime'"));
58
+ routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport("export * from '@".concat(metaName, "/plugin-router-v5/runtime'"));
61
59
  }
62
- };
60
+ });
63
61
  }
64
62
  };
65
63
  };
@@ -3,7 +3,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { RuntimeReactContext, isBrowser } from "@meta/runtime";
4
4
  import { getGlobalLayoutApp, getGlobalRoutes } from "@meta/runtime/context";
5
5
  import { merge } from "@modern-js/runtime-utils/merge";
6
- import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
7
6
  import { createBrowserHistory, createHashHistory } from "history";
8
7
  import { useContext } from "react";
9
8
  import { Router, StaticRouter, useHistory, useLocation, useRouteMatch } from "react-router-dom";
@@ -45,15 +44,11 @@ var routerPlugin = function() {
45
44
  return pathname.search(baseUrl) === 0;
46
45
  }) || "/";
47
46
  };
48
- if (isBrow) {
49
- window._SERVER_DATA = parsedJSONFromElement("__MODERN_SERVER_DATA__");
50
- }
51
47
  var getRouteApp = function() {
52
48
  if (isBrow) {
53
49
  return function(props) {
54
- var _window__SERVER_DATA;
55
50
  var runtimeContext = useContext(RuntimeReactContext);
56
- var baseUrl = (((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
51
+ var baseUrl = select(location.pathname).replace(/^\/*/, "/");
57
52
  var basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
58
53
  historyOptions.basename = basename;
59
54
  var history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
@@ -7,51 +7,49 @@ const routerPlugin = () => ({
7
7
  ],
8
8
  setup: (api) => {
9
9
  let routerExportsUtils;
10
- return {
11
- _internalRuntimePlugins({ entrypoint, plugins }) {
12
- const userConfig = api.useResolvedConfigContext();
13
- const { serverRoutes, metaName, packageName } = api.useAppContext();
14
- if (isV5(userConfig)) {
15
- var _getEntryOptions;
16
- const routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
17
- const serverBase = serverRoutes.filter((route) => route.entryName === entrypoint.entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
18
- plugins.push({
19
- name: "router",
20
- path: `@${metaName}/plugin-router-v5/runtime`,
21
- config: typeof routerConfig === "boolean" ? {
22
- serverBase
23
- } : {
24
- ...routerConfig,
25
- serverBase
26
- }
27
- });
28
- }
29
- return {
30
- entrypoint,
31
- plugins
32
- };
33
- },
34
- config() {
35
- const { internalDirectory, metaName } = api.useAppContext();
36
- routerExportsUtils = createRuntimeExportsUtils(internalDirectory, "router");
37
- return {
38
- source: {
39
- alias: {
40
- [`@${metaName}/runtime/router-v5`]: routerExportsUtils.getPath()
41
- }
10
+ api._internalRuntimePlugins(({ entrypoint, plugins }) => {
11
+ const userConfig = api.getNormalizedConfig();
12
+ const { serverRoutes, metaName, packageName } = api.getAppContext();
13
+ if (isV5(userConfig)) {
14
+ var _getEntryOptions;
15
+ const routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
16
+ const serverBase = serverRoutes.filter((route) => route.entryName === entrypoint.entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
17
+ plugins.push({
18
+ name: "router",
19
+ path: `@${metaName}/plugin-router-v5/runtime`,
20
+ config: typeof routerConfig === "boolean" ? {
21
+ serverBase
22
+ } : {
23
+ ...routerConfig,
24
+ serverBase
25
+ }
26
+ });
27
+ }
28
+ return {
29
+ entrypoint,
30
+ plugins
31
+ };
32
+ });
33
+ api.config(() => {
34
+ const { internalDirectory, metaName } = api.getAppContext();
35
+ routerExportsUtils = createRuntimeExportsUtils(internalDirectory, "router");
36
+ return {
37
+ source: {
38
+ alias: {
39
+ [`@${metaName}/runtime/router-v5`]: routerExportsUtils.getPath()
42
40
  }
43
- };
44
- },
45
- addRuntimeExports() {
46
- const userConfig = api.useResolvedConfigContext();
47
- const { internalDirectory, metaName } = api.useAppContext();
48
- const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
49
- if (isV5(userConfig)) {
50
- pluginsExportsUtils.addExport(`export { default as router } from '@${metaName}/plugin-router-v5/runtime'`);
51
- routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@${metaName}/plugin-router-v5/runtime'`);
52
41
  }
42
+ };
43
+ });
44
+ api.addRuntimeExports(() => {
45
+ const userConfig = api.getNormalizedConfig();
46
+ const { internalDirectory, metaName } = api.getAppContext();
47
+ const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
48
+ if (isV5(userConfig)) {
49
+ pluginsExportsUtils.addExport(`export { default as router } from '@${metaName}/plugin-router-v5/runtime'`);
50
+ routerExportsUtils === null || routerExportsUtils === void 0 ? void 0 : routerExportsUtils.addExport(`export * from '@${metaName}/plugin-router-v5/runtime'`);
53
51
  }
54
- };
52
+ });
55
53
  }
56
54
  });
57
55
  var cli_default = routerPlugin;
@@ -2,7 +2,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { RuntimeReactContext, isBrowser } from "@meta/runtime";
3
3
  import { getGlobalLayoutApp, getGlobalRoutes } from "@meta/runtime/context";
4
4
  import { merge } from "@modern-js/runtime-utils/merge";
5
- import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
6
5
  import { createBrowserHistory, createHashHistory } from "history";
7
6
  import { useContext } from "react";
8
7
  import { Router, StaticRouter, useHistory, useLocation, useRouteMatch } from "react-router-dom";
@@ -40,15 +39,11 @@ const routerPlugin = (userConfig = {}) => {
40
39
  const originRoutes = finalRouteConfig === null || finalRouteConfig === void 0 ? void 0 : finalRouteConfig.routes;
41
40
  const isBrow = isBrowser();
42
41
  const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
43
- if (isBrow) {
44
- window._SERVER_DATA = parsedJSONFromElement("__MODERN_SERVER_DATA__");
45
- }
46
42
  const getRouteApp = () => {
47
43
  if (isBrow) {
48
44
  return (props) => {
49
- var _window__SERVER_DATA;
50
45
  const runtimeContext = useContext(RuntimeReactContext);
51
- const baseUrl = (((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
46
+ const baseUrl = select(location.pathname).replace(/^\/*/, "/");
52
47
  const basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || historyOptions.basename) : baseUrl;
53
48
  historyOptions.basename = basename;
54
49
  const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
@@ -1,4 +1,4 @@
1
- import type { AppTools, CliPlugin } from '@modern-js/app-tools';
1
+ import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
2
2
  import './types';
3
- export declare const routerPlugin: () => CliPlugin<AppTools>;
3
+ export declare const routerPlugin: () => CliPluginFuture<AppTools>;
4
4
  export default routerPlugin;
@@ -2,16 +2,6 @@ import type { Plugin } from '@modern-js/runtime';
2
2
  import { type BrowserHistoryBuildOptions, type HashHistoryBuildOptions, type History } from 'history';
3
3
  import type React from 'react';
4
4
  import { type RouteProps } from 'react-router-dom';
5
- declare global {
6
- interface Window {
7
- _SERVER_DATA?: {
8
- router: {
9
- baseUrl: string;
10
- params: Record<string, string>;
11
- };
12
- };
13
- }
14
- }
15
5
  export type SingleRouteConfig = RouteProps & {
16
6
  redirect?: string;
17
7
  routes?: SingleRouteConfig[];
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.63.3",
18
+ "version": "2.63.5",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/cli/index.d.ts",
21
21
  "main": "./dist/cjs/cli/index.js",
@@ -59,15 +59,16 @@
59
59
  "@types/react-router-dom": "^5.1.8",
60
60
  "history": "^4.7.9",
61
61
  "react-router-dom": "^5.3.4",
62
- "@modern-js/plugin": "2.63.3",
63
- "@modern-js/runtime-utils": "2.63.3",
64
- "@modern-js/types": "2.63.3",
65
- "@modern-js/utils": "2.63.3"
62
+ "@modern-js/plugin": "2.63.5",
63
+ "@modern-js/plugin-v2": "2.63.5",
64
+ "@modern-js/runtime-utils": "2.63.5",
65
+ "@modern-js/types": "2.63.5",
66
+ "@modern-js/utils": "2.63.5"
66
67
  },
67
68
  "peerDependencies": {
68
69
  "react": ">=17",
69
70
  "react-dom": ">=17",
70
- "@modern-js/runtime": "^2.63.3"
71
+ "@modern-js/runtime": "^2.63.5"
71
72
  },
72
73
  "devDependencies": {
73
74
  "@testing-library/react": "^13.4.0",
@@ -79,11 +80,11 @@
79
80
  "react-dom": "^18.3.1",
80
81
  "ts-jest": "^29.1.0",
81
82
  "typescript": "^5",
82
- "@modern-js/app-tools": "2.63.3",
83
- "@modern-js/core": "2.63.3",
84
- "@modern-js/runtime": "2.63.3",
85
- "@scripts/build": "2.63.3",
86
- "@scripts/jest-config": "2.63.3"
83
+ "@modern-js/core": "2.63.5",
84
+ "@modern-js/app-tools": "2.63.5",
85
+ "@modern-js/runtime": "2.63.5",
86
+ "@scripts/build": "2.63.5",
87
+ "@scripts/jest-config": "2.63.5"
87
88
  },
88
89
  "sideEffects": false,
89
90
  "publishConfig": {