@modern-js/runtime 2.49.3 → 2.50.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.
- package/dist/cjs/router/runtime/plugin.node.js +2 -1
- package/dist/cjs/ssr/cli/index.js +9 -13
- package/dist/esm/router/runtime/plugin.node.js +5 -5
- package/dist/esm/ssr/cli/index.js +9 -13
- package/dist/esm-node/router/runtime/plugin.node.js +3 -2
- package/dist/esm-node/ssr/cli/index.js +9 -13
- package/dist/types/document/Body.d.ts +2 -4
- package/dist/types/document/Root.d.ts +2 -3
- package/dist/types/document/Style.d.ts +2 -2
- package/dist/types/exports/server.d.ts +1 -1
- package/dist/types/router/runtime/types.d.ts +2 -2
- package/package.json +10 -10
|
@@ -80,6 +80,7 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
|
|
|
80
80
|
setup: (api) => {
|
|
81
81
|
return {
|
|
82
82
|
async init({ context }, next) {
|
|
83
|
+
var _context_ssrContext;
|
|
83
84
|
if (!routesConfig && !createRoutes) {
|
|
84
85
|
return next({
|
|
85
86
|
context
|
|
@@ -89,7 +90,7 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
|
|
|
89
90
|
const baseUrl = originalBaseUrl || request.baseUrl;
|
|
90
91
|
const _basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, basename) : baseUrl;
|
|
91
92
|
const { reporter, serverTiming } = context.ssrContext;
|
|
92
|
-
const requestContext = (0, import_node.createRequestContext)();
|
|
93
|
+
const requestContext = (0, import_node.createRequestContext)((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.loaderContext);
|
|
93
94
|
requestContext.set(import_node.reporterCtx, reporter);
|
|
94
95
|
let routes = createRoutes ? createRoutes() : (0, import_router2.createRoutesFromElements)((0, import_utils.renderRoutes)({
|
|
95
96
|
routesConfig,
|
|
@@ -65,30 +65,26 @@ const ssrPlugin = () => ({
|
|
|
65
65
|
return {
|
|
66
66
|
config() {
|
|
67
67
|
const appContext = api.useAppContext();
|
|
68
|
-
const userConfig = api.useConfigContext();
|
|
69
68
|
pluginsExportsUtils = (0, import_utils.createRuntimeExportsUtils)(appContext.internalDirectory, "plugins");
|
|
70
69
|
const { bundlerType = "webpack" } = api.useAppContext();
|
|
71
70
|
const babelHandler = (() => {
|
|
72
71
|
if (bundlerType === "webpack") {
|
|
73
72
|
return (config) => {
|
|
74
73
|
var _config_plugins;
|
|
75
|
-
const
|
|
74
|
+
const userConfig = api.useResolvedConfigContext();
|
|
76
75
|
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(import_path.default.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
77
|
-
if ((0, import_utils.isUseSSRBundle)(
|
|
76
|
+
if ((0, import_utils.isUseSSRBundle)(userConfig) && checkUseStringSSR(userConfig)) {
|
|
78
77
|
var _config_plugins1;
|
|
79
78
|
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
80
79
|
}
|
|
81
80
|
};
|
|
82
81
|
} else if (bundlerType === "rspack") {
|
|
83
82
|
return (config) => {
|
|
84
|
-
const
|
|
85
|
-
if ((0, import_utils.isUseSSRBundle)(
|
|
86
|
-
var _config_plugins;
|
|
83
|
+
const userConfig = api.useResolvedConfigContext();
|
|
84
|
+
if ((0, import_utils.isUseSSRBundle)(userConfig) && checkUseStringSSR(userConfig)) {
|
|
85
|
+
var _config_plugins, _config_plugins1;
|
|
87
86
|
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(import_path.default.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
88
|
-
|
|
89
|
-
var _config_plugins1;
|
|
90
|
-
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
91
|
-
}
|
|
87
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
92
88
|
}
|
|
93
89
|
};
|
|
94
90
|
}
|
|
@@ -106,8 +102,8 @@ const ssrPlugin = () => ({
|
|
|
106
102
|
},
|
|
107
103
|
tools: {
|
|
108
104
|
bundlerChain(chain, { isServer, isServiceWorker }) {
|
|
109
|
-
const
|
|
110
|
-
if ((0, import_utils.isUseSSRBundle)(
|
|
105
|
+
const userConfig = api.useResolvedConfigContext();
|
|
106
|
+
if ((0, import_utils.isUseSSRBundle)(userConfig) && !isServer && !isServiceWorker && checkUseStringSSR(userConfig)) {
|
|
111
107
|
const LoadableBundlerPlugin = require("./loadable-bundler-plugin.js");
|
|
112
108
|
chain.plugin("loadable").use(LoadableBundlerPlugin, [
|
|
113
109
|
{
|
|
@@ -116,7 +112,7 @@ const ssrPlugin = () => ({
|
|
|
116
112
|
]);
|
|
117
113
|
}
|
|
118
114
|
},
|
|
119
|
-
babel:
|
|
115
|
+
babel: babelHandler
|
|
120
116
|
}
|
|
121
117
|
};
|
|
122
118
|
},
|
|
@@ -10,7 +10,7 @@ import { createStaticHandler } from "@modern-js/runtime-utils/remix-router";
|
|
|
10
10
|
import { createStaticRouter, StaticRouterProvider } from "@modern-js/runtime-utils/node/router";
|
|
11
11
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
12
12
|
import { createRoutesFromElements } from "@modern-js/runtime-utils/router";
|
|
13
|
-
import {
|
|
13
|
+
import { reporterCtx, createRequestContext } from "@modern-js/runtime-utils/node";
|
|
14
14
|
import { time } from "@modern-js/runtime-utils/time";
|
|
15
15
|
import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
|
|
16
16
|
import { RuntimeReactContext } from "../../core";
|
|
@@ -88,7 +88,7 @@ var routerPlugin = function(param) {
|
|
|
88
88
|
init: function init(param2, next) {
|
|
89
89
|
var context = param2.context;
|
|
90
90
|
return _async_to_generator(function() {
|
|
91
|
-
var _context_ssrContext, request, ssrMode, nonce, baseUrl, _basename,
|
|
91
|
+
var _context_ssrContext, _context_ssrContext1, request, ssrMode, nonce, baseUrl, _basename, _context_ssrContext2, reporter, serverTiming, requestContext, routes, runner, query, remixRequest, end, routerContext, cost, router;
|
|
92
92
|
return _ts_generator(this, function(_state) {
|
|
93
93
|
switch (_state.label) {
|
|
94
94
|
case 0:
|
|
@@ -100,11 +100,11 @@ var routerPlugin = function(param) {
|
|
|
100
100
|
})
|
|
101
101
|
];
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
_context_ssrContext1 = context.ssrContext, request = _context_ssrContext1.request, ssrMode = _context_ssrContext1.mode, nonce = _context_ssrContext1.nonce;
|
|
104
104
|
baseUrl = originalBaseUrl || request.baseUrl;
|
|
105
105
|
_basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
|
|
106
|
-
|
|
107
|
-
requestContext = createRequestContext();
|
|
106
|
+
_context_ssrContext2 = context.ssrContext, reporter = _context_ssrContext2.reporter, serverTiming = _context_ssrContext2.serverTiming;
|
|
107
|
+
requestContext = createRequestContext((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.loaderContext);
|
|
108
108
|
requestContext.set(reporterCtx, reporter);
|
|
109
109
|
routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
|
|
110
110
|
routesConfig,
|
|
@@ -53,30 +53,26 @@ var ssrPlugin = function() {
|
|
|
53
53
|
return {
|
|
54
54
|
config: function config() {
|
|
55
55
|
var appContext = api.useAppContext();
|
|
56
|
-
var userConfig = api.useConfigContext();
|
|
57
56
|
pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "plugins");
|
|
58
57
|
var _api_useAppContext = api.useAppContext(), _api_useAppContext_bundlerType = _api_useAppContext.bundlerType, bundlerType = _api_useAppContext_bundlerType === void 0 ? "webpack" : _api_useAppContext_bundlerType;
|
|
59
58
|
var babelHandler = function() {
|
|
60
59
|
if (bundlerType === "webpack") {
|
|
61
60
|
return function(config2) {
|
|
62
61
|
var _config_plugins;
|
|
63
|
-
var
|
|
62
|
+
var userConfig = api.useResolvedConfigContext();
|
|
64
63
|
(_config_plugins = config2.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
65
|
-
if (isUseSSRBundle(
|
|
64
|
+
if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
|
|
66
65
|
var _config_plugins1;
|
|
67
66
|
(_config_plugins1 = config2.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
68
67
|
}
|
|
69
68
|
};
|
|
70
69
|
} else if (bundlerType === "rspack") {
|
|
71
70
|
return function(config2) {
|
|
72
|
-
var
|
|
73
|
-
if (isUseSSRBundle(
|
|
74
|
-
var _config_plugins;
|
|
71
|
+
var userConfig = api.useResolvedConfigContext();
|
|
72
|
+
if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
|
|
73
|
+
var _config_plugins, _config_plugins1;
|
|
75
74
|
(_config_plugins = config2.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
76
|
-
|
|
77
|
-
var _config_plugins1;
|
|
78
|
-
(_config_plugins1 = config2.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
79
|
-
}
|
|
75
|
+
(_config_plugins1 = config2.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
80
76
|
}
|
|
81
77
|
};
|
|
82
78
|
}
|
|
@@ -96,8 +92,8 @@ var ssrPlugin = function() {
|
|
|
96
92
|
tools: {
|
|
97
93
|
bundlerChain: function bundlerChain(chain, param) {
|
|
98
94
|
var isServer = param.isServer, isServiceWorker = param.isServiceWorker;
|
|
99
|
-
var
|
|
100
|
-
if (isUseSSRBundle(
|
|
95
|
+
var userConfig = api.useResolvedConfigContext();
|
|
96
|
+
if (isUseSSRBundle(userConfig) && !isServer && !isServiceWorker && checkUseStringSSR(userConfig)) {
|
|
101
97
|
var LoadableBundlerPlugin = require("./loadable-bundler-plugin.js");
|
|
102
98
|
chain.plugin("loadable").use(LoadableBundlerPlugin, [
|
|
103
99
|
{
|
|
@@ -106,7 +102,7 @@ var ssrPlugin = function() {
|
|
|
106
102
|
]);
|
|
107
103
|
}
|
|
108
104
|
},
|
|
109
|
-
babel:
|
|
105
|
+
babel: babelHandler
|
|
110
106
|
}
|
|
111
107
|
};
|
|
112
108
|
},
|
|
@@ -4,7 +4,7 @@ import { createStaticHandler } from "@modern-js/runtime-utils/remix-router";
|
|
|
4
4
|
import { createStaticRouter, StaticRouterProvider } from "@modern-js/runtime-utils/node/router";
|
|
5
5
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
6
6
|
import { createRoutesFromElements } from "@modern-js/runtime-utils/router";
|
|
7
|
-
import {
|
|
7
|
+
import { reporterCtx, createRequestContext } from "@modern-js/runtime-utils/node";
|
|
8
8
|
import { time } from "@modern-js/runtime-utils/time";
|
|
9
9
|
import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
|
|
10
10
|
import { RuntimeReactContext } from "../../core";
|
|
@@ -45,6 +45,7 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
|
|
|
45
45
|
setup: (api) => {
|
|
46
46
|
return {
|
|
47
47
|
async init({ context }, next) {
|
|
48
|
+
var _context_ssrContext;
|
|
48
49
|
if (!routesConfig && !createRoutes) {
|
|
49
50
|
return next({
|
|
50
51
|
context
|
|
@@ -54,7 +55,7 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
|
|
|
54
55
|
const baseUrl = originalBaseUrl || request.baseUrl;
|
|
55
56
|
const _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
|
|
56
57
|
const { reporter, serverTiming } = context.ssrContext;
|
|
57
|
-
const requestContext = createRequestContext();
|
|
58
|
+
const requestContext = createRequestContext((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.loaderContext);
|
|
58
59
|
requestContext.set(reporterCtx, reporter);
|
|
59
60
|
let routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
|
|
60
61
|
routesConfig,
|
|
@@ -31,30 +31,26 @@ const ssrPlugin = () => ({
|
|
|
31
31
|
return {
|
|
32
32
|
config() {
|
|
33
33
|
const appContext = api.useAppContext();
|
|
34
|
-
const userConfig = api.useConfigContext();
|
|
35
34
|
pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "plugins");
|
|
36
35
|
const { bundlerType = "webpack" } = api.useAppContext();
|
|
37
36
|
const babelHandler = (() => {
|
|
38
37
|
if (bundlerType === "webpack") {
|
|
39
38
|
return (config) => {
|
|
40
39
|
var _config_plugins;
|
|
41
|
-
const
|
|
40
|
+
const userConfig = api.useResolvedConfigContext();
|
|
42
41
|
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
43
|
-
if (isUseSSRBundle(
|
|
42
|
+
if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
|
|
44
43
|
var _config_plugins1;
|
|
45
44
|
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
46
45
|
}
|
|
47
46
|
};
|
|
48
47
|
} else if (bundlerType === "rspack") {
|
|
49
48
|
return (config) => {
|
|
50
|
-
const
|
|
51
|
-
if (isUseSSRBundle(
|
|
52
|
-
var _config_plugins;
|
|
49
|
+
const userConfig = api.useResolvedConfigContext();
|
|
50
|
+
if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
|
|
51
|
+
var _config_plugins, _config_plugins1;
|
|
53
52
|
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
54
|
-
|
|
55
|
-
var _config_plugins1;
|
|
56
|
-
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
57
|
-
}
|
|
53
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
58
54
|
}
|
|
59
55
|
};
|
|
60
56
|
}
|
|
@@ -72,8 +68,8 @@ const ssrPlugin = () => ({
|
|
|
72
68
|
},
|
|
73
69
|
tools: {
|
|
74
70
|
bundlerChain(chain, { isServer, isServiceWorker }) {
|
|
75
|
-
const
|
|
76
|
-
if (isUseSSRBundle(
|
|
71
|
+
const userConfig = api.useResolvedConfigContext();
|
|
72
|
+
if (isUseSSRBundle(userConfig) && !isServer && !isServiceWorker && checkUseStringSSR(userConfig)) {
|
|
77
73
|
const LoadableBundlerPlugin = require("./loadable-bundler-plugin.js");
|
|
78
74
|
chain.plugin("loadable").use(LoadableBundlerPlugin, [
|
|
79
75
|
{
|
|
@@ -82,7 +78,7 @@ const ssrPlugin = () => ({
|
|
|
82
78
|
]);
|
|
83
79
|
}
|
|
84
80
|
},
|
|
85
|
-
babel:
|
|
81
|
+
babel: babelHandler
|
|
86
82
|
}
|
|
87
83
|
};
|
|
88
84
|
},
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export declare function Root(props: {
|
|
3
|
-
children?: any;
|
|
4
3
|
rootId?: string;
|
|
5
|
-
}): JSX.Element;
|
|
4
|
+
} & React.DOMAttributes<HTMLDivElement>): JSX.Element;
|
|
6
5
|
export declare function DefaultRoot(props: {
|
|
7
6
|
children?: any;
|
|
8
7
|
}): JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AfterMatchContext, AfterRenderContext, MiddlewareContext, NextFunction } from '@modern-js/types';
|
|
2
|
-
export type { Container, CacheControl, CacheOptionProvider, CacheOption, } from '@modern-js/types';
|
|
2
|
+
export type { Container, CacheControl, CacheOptionProvider, CacheOption, UnstableMiddlewareContext, UnstableMiddleware, UnstableNext, } from '@modern-js/types';
|
|
3
3
|
export declare const hook: (attacher: ({ addMiddleware, afterMatch, afterRender, }: {
|
|
4
4
|
addMiddleware: (mid: Middleware) => void;
|
|
5
5
|
afterRender: (hook: AfterRenderHook) => void;
|
|
@@ -56,7 +56,7 @@ interface DataFunctionArgs<D = any> {
|
|
|
56
56
|
params: Params;
|
|
57
57
|
context?: D;
|
|
58
58
|
}
|
|
59
|
-
export type LoaderFunctionArgs = DataFunctionArgs<RequestContext
|
|
59
|
+
export type LoaderFunctionArgs<P extends Record<string, unknown> = any> = DataFunctionArgs<RequestContext<P>>;
|
|
60
60
|
declare type DataFunctionValue = Response | NonNullable<unknown> | null;
|
|
61
|
-
export type LoaderFunction = (args: LoaderFunctionArgs) => Promise<DataFunctionValue> | DataFunctionValue;
|
|
61
|
+
export type LoaderFunction = <P extends Record<string, unknown> = Record<string, unknown>>(args: LoaderFunctionArgs<P>) => Promise<DataFunctionValue> | DataFunctionValue;
|
|
62
62
|
export {};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.50.0",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -170,10 +170,10 @@
|
|
|
170
170
|
"react-side-effect": "^2.1.1",
|
|
171
171
|
"styled-components": "^5.3.1",
|
|
172
172
|
"@swc/helpers": "0.5.3",
|
|
173
|
-
"@modern-js/plugin": "2.
|
|
174
|
-
"@modern-js/
|
|
175
|
-
"@modern-js/
|
|
176
|
-
"@modern-js/runtime-utils": "2.
|
|
173
|
+
"@modern-js/plugin": "2.50.0",
|
|
174
|
+
"@modern-js/types": "2.50.0",
|
|
175
|
+
"@modern-js/utils": "2.50.0",
|
|
176
|
+
"@modern-js/runtime-utils": "2.50.0"
|
|
177
177
|
},
|
|
178
178
|
"peerDependencies": {
|
|
179
179
|
"react": ">=17",
|
|
@@ -194,11 +194,11 @@
|
|
|
194
194
|
"ts-jest": "^29.1.0",
|
|
195
195
|
"typescript": "^5",
|
|
196
196
|
"webpack": "^5.91.0",
|
|
197
|
-
"@modern-js/app-tools": "2.
|
|
198
|
-
"@modern-js/core": "2.
|
|
199
|
-
"@
|
|
200
|
-
"@
|
|
201
|
-
"@scripts/jest-config": "2.
|
|
197
|
+
"@modern-js/app-tools": "2.50.0",
|
|
198
|
+
"@modern-js/server-core": "2.50.0",
|
|
199
|
+
"@modern-js/core": "2.50.0",
|
|
200
|
+
"@scripts/build": "2.50.0",
|
|
201
|
+
"@scripts/jest-config": "2.50.0"
|
|
202
202
|
},
|
|
203
203
|
"sideEffects": false,
|
|
204
204
|
"publishConfig": {
|