@modern-js/plugin-router-v5 2.63.3 → 2.63.4
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/cli/index.js +40 -42
- package/dist/cjs/runtime/plugin.js +1 -6
- package/dist/esm/cli/index.js +45 -47
- package/dist/esm/runtime/plugin.js +1 -6
- package/dist/esm-node/cli/index.js +40 -42
- package/dist/esm-node/runtime/plugin.js +1 -6
- package/dist/types/cli/index.d.ts +2 -2
- package/dist/types/runtime/plugin.d.ts +0 -10
- package/package.json +12 -11
package/dist/cjs/cli/index.js
CHANGED
@@ -31,51 +31,49 @@ const routerPlugin = () => ({
|
|
31
31
|
],
|
32
32
|
setup: (api) => {
|
33
33
|
let routerExportsUtils;
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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 =
|
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));
|
package/dist/esm/cli/index.js
CHANGED
@@ -11,55 +11,53 @@ var routerPlugin = function() {
|
|
11
11
|
],
|
12
12
|
setup: function(api) {
|
13
13
|
var routerExportsUtils;
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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 =
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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 =
|
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,
|
1
|
+
import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
|
2
2
|
import './types';
|
3
|
-
export declare const routerPlugin: () =>
|
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.
|
18
|
+
"version": "2.63.4",
|
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.
|
63
|
-
"@modern-js/
|
64
|
-
"@modern-js/
|
65
|
-
"@modern-js/
|
62
|
+
"@modern-js/plugin": "2.63.4",
|
63
|
+
"@modern-js/plugin-v2": "2.63.4",
|
64
|
+
"@modern-js/runtime-utils": "2.63.4",
|
65
|
+
"@modern-js/types": "2.63.4",
|
66
|
+
"@modern-js/utils": "2.63.4"
|
66
67
|
},
|
67
68
|
"peerDependencies": {
|
68
69
|
"react": ">=17",
|
69
70
|
"react-dom": ">=17",
|
70
|
-
"@modern-js/runtime": "^2.63.
|
71
|
+
"@modern-js/runtime": "^2.63.4"
|
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.
|
83
|
-
"@modern-js/core": "2.63.
|
84
|
-
"@modern-js/runtime": "2.63.
|
85
|
-
"@scripts/build": "2.63.
|
86
|
-
"@scripts/jest-config": "2.63.
|
83
|
+
"@modern-js/app-tools": "2.63.4",
|
84
|
+
"@modern-js/core": "2.63.4",
|
85
|
+
"@modern-js/runtime": "2.63.4",
|
86
|
+
"@scripts/build": "2.63.4",
|
87
|
+
"@scripts/jest-config": "2.63.4"
|
87
88
|
},
|
88
89
|
"sideEffects": false,
|
89
90
|
"publishConfig": {
|