@modern-js/runtime 2.55.0 → 2.56.1
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/cli/index.js +2 -3
- package/dist/cjs/cli/ssr/index.js +30 -14
- package/dist/cjs/core/browser/index.js +21 -1
- package/dist/cjs/core/plugin/index.js +2 -2
- package/dist/cjs/core/server/stream/createReadableStream.js +3 -3
- package/dist/cjs/core/server/string/index.js +2 -2
- package/dist/cjs/core/server/string/loadable.js +1 -1
- package/dist/cjs/core/server/string/prefetch.js +3 -3
- package/dist/cjs/core/utils/merge.js +53 -0
- package/dist/cjs/router/cli/code/index.js +2 -2
- package/dist/cjs/router/cli/entry.js +16 -15
- package/dist/cjs/router/runtime/PrefetchLink.js +1 -1
- package/dist/cjs/router/runtime/plugin.node.js +10 -17
- package/dist/esm/cli/index.js +1 -2
- package/dist/esm/cli/ssr/index.js +33 -16
- package/dist/esm/core/browser/index.js +19 -1
- package/dist/esm/core/plugin/index.js +1 -1
- package/dist/esm/core/server/stream/createReadableStream.js +99 -78
- package/dist/esm/core/server/string/index.js +3 -3
- package/dist/esm/core/server/string/loadable.js +1 -1
- package/dist/esm/core/server/string/prefetch.js +5 -5
- package/dist/esm/core/utils/merge.js +32 -0
- package/dist/esm/router/cli/code/index.js +3 -3
- package/dist/esm/router/cli/entry.js +19 -17
- package/dist/esm/router/runtime/PrefetchLink.js +1 -1
- package/dist/esm/router/runtime/plugin.node.js +10 -51
- package/dist/esm-node/cli/index.js +1 -2
- package/dist/esm-node/cli/ssr/index.js +30 -14
- package/dist/esm-node/core/browser/index.js +21 -1
- package/dist/esm-node/core/plugin/index.js +1 -1
- package/dist/esm-node/core/server/stream/createReadableStream.js +2 -2
- package/dist/esm-node/core/server/string/index.js +2 -2
- package/dist/esm-node/core/server/string/loadable.js +1 -1
- package/dist/esm-node/core/server/string/prefetch.js +3 -3
- package/dist/esm-node/core/utils/merge.js +29 -0
- package/dist/esm-node/router/cli/code/index.js +2 -2
- package/dist/esm-node/router/cli/entry.js +16 -15
- package/dist/esm-node/router/runtime/PrefetchLink.js +1 -1
- package/dist/esm-node/router/runtime/plugin.node.js +10 -16
- package/dist/types/core/browser/index.d.ts +1 -0
- package/dist/types/core/plugin/index.d.ts +1 -1
- package/dist/types/core/server/string/prefetch.d.ts +2 -1
- package/dist/types/core/utils/merge.d.ts +6 -0
- package/dist/types/router/runtime/plugin.node.d.ts +0 -2
- package/package.json +14 -15
|
@@ -111,7 +111,7 @@ class LoadableCollector {
|
|
|
111
111
|
return link;
|
|
112
112
|
}
|
|
113
113
|
}));
|
|
114
|
-
chunkSet.
|
|
114
|
+
chunkSet.cssChunk += css.filter((css2) => Boolean(css2)).join("");
|
|
115
115
|
}
|
|
116
116
|
generateAttributes(extraAtr = {}) {
|
|
117
117
|
const { config } = this.options;
|
|
@@ -5,13 +5,13 @@ import { time } from "@modern-js/runtime-utils/time";
|
|
|
5
5
|
import { parseHeaders } from "@modern-js/runtime-utils/universal/request";
|
|
6
6
|
import React from "react";
|
|
7
7
|
import { SSRErrors, SSRTimings } from "../tracer";
|
|
8
|
-
const prefetch = async (App, request, options, { onError, onTiming }) => {
|
|
8
|
+
const prefetch = async (App, request, options, ssrConfig, { onError, onTiming }) => {
|
|
9
9
|
const headersData = parseHeaders(request);
|
|
10
|
-
const { runtimeContext: context, resource
|
|
10
|
+
const { runtimeContext: context, resource } = options;
|
|
11
11
|
const { entryName, loadableStats } = resource;
|
|
12
12
|
return run(headersData, async () => {
|
|
13
13
|
var _context_store;
|
|
14
|
-
if (!
|
|
14
|
+
if (typeof ssrConfig === "boolean" || !ssrConfig.disablePrerender) {
|
|
15
15
|
try {
|
|
16
16
|
const end = time();
|
|
17
17
|
if (loadableStats) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function isObject(obj) {
|
|
2
|
+
return obj && typeof obj === "object" && !Array.isArray(obj);
|
|
3
|
+
}
|
|
4
|
+
function merge(target, ...sources) {
|
|
5
|
+
if (!sources.length) {
|
|
6
|
+
return target;
|
|
7
|
+
}
|
|
8
|
+
const source = sources.shift();
|
|
9
|
+
if (isObject(target) && isObject(source)) {
|
|
10
|
+
for (const key in source) {
|
|
11
|
+
if (isObject(source[key])) {
|
|
12
|
+
if (!target[key]) {
|
|
13
|
+
Object.assign(target, {
|
|
14
|
+
[key]: {}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
merge(target[key], source[key]);
|
|
18
|
+
} else {
|
|
19
|
+
Object.assign(target, {
|
|
20
|
+
[key]: source[key]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return merge(target, ...sources);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
merge
|
|
29
|
+
};
|
|
@@ -14,10 +14,10 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
14
14
|
const oldVersion = typeof (config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
|
|
15
15
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
16
16
|
async function generateEntryCode(entrypoint) {
|
|
17
|
-
const { entryName, isMainEntry, isAutoMount,
|
|
17
|
+
const { entryName, isMainEntry, isAutoMount, pageRoutesEntry, nestedRoutesEntry } = entrypoint;
|
|
18
18
|
const { metaName } = api.useAppContext();
|
|
19
19
|
if (isAutoMount) {
|
|
20
|
-
if (
|
|
20
|
+
if (pageRoutesEntry || nestedRoutesEntry) {
|
|
21
21
|
var _config_output;
|
|
22
22
|
let initialRoutes = [];
|
|
23
23
|
let nestedRoutes = null;
|
|
@@ -18,29 +18,30 @@ const modifyEntrypoints = (entrypoints, config = {}) => {
|
|
|
18
18
|
if (!entrypoint.isAutoMount) {
|
|
19
19
|
return entrypoint;
|
|
20
20
|
}
|
|
21
|
+
if (entrypoint === null || entrypoint === void 0 ? void 0 : entrypoint.isCustomSourceEntry) {
|
|
22
|
+
if (entrypoint.fileSystemRoutes) {
|
|
23
|
+
if (isRouterV5(config)) {
|
|
24
|
+
throw Error("Custom entries with conventional routing not support use react router v5!");
|
|
25
|
+
}
|
|
26
|
+
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
27
|
+
}
|
|
28
|
+
return entrypoint;
|
|
29
|
+
}
|
|
21
30
|
const isHasApp = hasApp(entrypoint.absoluteEntryDir);
|
|
22
31
|
if (isHasApp) {
|
|
23
32
|
return entrypoint;
|
|
24
33
|
}
|
|
25
|
-
const isHasNestedRoutes = hasNestedRoutes(entrypoint.absoluteEntryDir);
|
|
26
34
|
const isHasPages = hasPages(entrypoint.absoluteEntryDir);
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
if (entrypoint.fileSystemRoutes && !isRouterV5(config)) {
|
|
31
|
-
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
32
|
-
} else if (!entrypoint.fileSystemRoutes) {
|
|
35
|
+
if (isHasPages) {
|
|
36
|
+
entrypoint.pageRoutesEntry = path.join(entrypoint.absoluteEntryDir, PAGES_DIR_NAME);
|
|
33
37
|
entrypoint.fileSystemRoutes = {
|
|
38
|
+
...entrypoint.fileSystemRoutes,
|
|
34
39
|
globalApp: findExists(JS_EXTENSIONS.map((ext) => path.resolve(entrypoint.absoluteEntryDir, `./${PAGES_DIR_NAME}/${FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT}${ext}`)))
|
|
35
40
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
entrypoint.nestedRoutesEntry = path.join(entrypoint.absoluteEntryDir, NESTED_ROUTES_DIR);
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
throw Error("Custom entries with conventional routing not support use react router v5!");
|
|
41
|
+
}
|
|
42
|
+
const isHasNestedRoutes = hasNestedRoutes(entrypoint.absoluteEntryDir);
|
|
43
|
+
if (isHasNestedRoutes) {
|
|
44
|
+
entrypoint.nestedRoutesEntry = path.join(entrypoint.absoluteEntryDir, NESTED_ROUTES_DIR);
|
|
44
45
|
}
|
|
45
46
|
return entrypoint;
|
|
46
47
|
});
|
|
@@ -70,7 +70,7 @@ async function loadRouteModule(route, routeAssets) {
|
|
|
70
70
|
}
|
|
71
71
|
try {
|
|
72
72
|
await Promise.all(chunkIds.map((chunkId) => {
|
|
73
|
-
return __webpack_chunk_load__ === null || __webpack_chunk_load__ === void 0 ? void 0 : __webpack_chunk_load__(
|
|
73
|
+
return __webpack_chunk_load__ === null || __webpack_chunk_load__ === void 0 ? void 0 : __webpack_chunk_load__(chunkId);
|
|
74
74
|
}));
|
|
75
75
|
} catch (error) {
|
|
76
76
|
console.error(error);
|
|
@@ -12,20 +12,15 @@ import { getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
|
|
|
12
12
|
import { renderRoutes, urlJoin } from "./utils";
|
|
13
13
|
import { modifyRoutes as modifyRoutesHook } from "./hooks";
|
|
14
14
|
import DeferredDataScripts from "./DeferredDataScripts.node";
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
headers.set(key, values);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return headers;
|
|
15
|
+
function createRemixReuqest(request) {
|
|
16
|
+
const method = "GET";
|
|
17
|
+
const { headers } = request;
|
|
18
|
+
const controller = new AbortController();
|
|
19
|
+
return new Request(request.url, {
|
|
20
|
+
method,
|
|
21
|
+
headers,
|
|
22
|
+
signal: controller.signal
|
|
23
|
+
});
|
|
29
24
|
}
|
|
30
25
|
const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
31
26
|
return {
|
|
@@ -66,7 +61,7 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
66
61
|
const { query } = createStaticHandler(routes, {
|
|
67
62
|
basename: _basename
|
|
68
63
|
});
|
|
69
|
-
const remixRequest = context.ssrContext.request.raw;
|
|
64
|
+
const remixRequest = createRemixReuqest(context.ssrContext.request.raw);
|
|
70
65
|
const end = time();
|
|
71
66
|
const routerContext = await query(remixRequest, {
|
|
72
67
|
requestContext
|
|
@@ -150,7 +145,6 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
150
145
|
const modifyRoutes = () => {
|
|
151
146
|
};
|
|
152
147
|
export {
|
|
153
|
-
createFetchHeaders,
|
|
154
148
|
modifyRoutes,
|
|
155
149
|
routerPlugin
|
|
156
150
|
};
|
|
@@ -17,4 +17,4 @@ export declare function registerPlugin(internalPlugins: Plugin[], runtimeConfig?
|
|
|
17
17
|
pickedContext: import("../context/runtime").TRuntimeContext;
|
|
18
18
|
}, import("../context/runtime").TRuntimeContext>;
|
|
19
19
|
}>;
|
|
20
|
-
export declare function mergeConfig(config: Record<string, any>, ...otherConfig: Record<string, any>[]): any
|
|
20
|
+
export declare function mergeConfig(config: Record<string, any>, ...otherConfig: Record<string, any>[]): Record<string, any>;
|
|
@@ -2,7 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import { LoaderResult } from '../../loader/loaderManager';
|
|
3
3
|
import { HandleRequestOptions } from '../requestHandler';
|
|
4
4
|
import { Tracer } from '../tracer';
|
|
5
|
-
|
|
5
|
+
import { SSRConfig } from '../shared';
|
|
6
|
+
export declare const prefetch: (App: React.ReactElement, request: Request, options: HandleRequestOptions, ssrConfig: SSRConfig, { onError, onTiming }: Tracer) => Promise<{
|
|
6
7
|
initialData: Record<string, unknown> | undefined;
|
|
7
8
|
i18nData: any;
|
|
8
9
|
loadersData?: undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type PlainObject = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
5
|
+
export declare function merge<T extends PlainObject, U extends PlainObject[]>(target: T, ...sources: U): T & UnionToIntersection<U[number]>;
|
|
6
|
+
export {};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { Plugin } from '../../core';
|
|
2
|
-
import { SSRServerContext } from '../../core/types';
|
|
3
2
|
import type { RouterConfig } from './types';
|
|
4
|
-
export declare function createFetchHeaders(requestHeaders: SSRServerContext['request']['headers']): Headers;
|
|
5
3
|
export declare const routerPlugin: ({ basename, routesConfig, createRoutes, }: RouterConfig) => Plugin;
|
|
6
4
|
export declare const modifyRoutes: () => void;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.56.1",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -175,14 +175,13 @@
|
|
|
175
175
|
}
|
|
176
176
|
},
|
|
177
177
|
"dependencies": {
|
|
178
|
-
"@babel/core": "^7.
|
|
179
|
-
"@babel/types": "^7.
|
|
178
|
+
"@babel/core": "^7.24.7",
|
|
179
|
+
"@babel/types": "^7.24.7",
|
|
180
180
|
"cookie": "0.5.0",
|
|
181
181
|
"isbot": "3.7.1",
|
|
182
182
|
"@loadable/babel-plugin": "5.15.3",
|
|
183
183
|
"@loadable/component": "5.15.3",
|
|
184
184
|
"@loadable/server": "5.15.3",
|
|
185
|
-
"@loadable/webpack-plugin": "5.15.2",
|
|
186
185
|
"@modern-js-reduck/plugin-auto-actions": "^1.1.10",
|
|
187
186
|
"@modern-js-reduck/plugin-devtools": "^1.1.10",
|
|
188
187
|
"@modern-js-reduck/plugin-effects": "^1.1.10",
|
|
@@ -200,18 +199,18 @@
|
|
|
200
199
|
"react-side-effect": "^2.1.1",
|
|
201
200
|
"styled-components": "^5.3.1",
|
|
202
201
|
"@swc/helpers": "0.5.3",
|
|
203
|
-
"@modern-js/types": "2.
|
|
204
|
-
"@modern-js/plugin
|
|
205
|
-
"@modern-js/utils": "2.
|
|
206
|
-
"@modern-js/
|
|
207
|
-
"@modern-js/
|
|
202
|
+
"@modern-js/types": "2.56.1",
|
|
203
|
+
"@modern-js/plugin": "2.56.1",
|
|
204
|
+
"@modern-js/utils": "2.56.1",
|
|
205
|
+
"@modern-js/plugin-data-loader": "2.56.1",
|
|
206
|
+
"@modern-js/runtime-utils": "2.56.1"
|
|
208
207
|
},
|
|
209
208
|
"peerDependencies": {
|
|
210
209
|
"react": ">=17",
|
|
211
210
|
"react-dom": ">=17"
|
|
212
211
|
},
|
|
213
212
|
"devDependencies": {
|
|
214
|
-
"@rsbuild/core": "0.
|
|
213
|
+
"@rsbuild/core": "1.0.1-beta.3",
|
|
215
214
|
"@types/cookie": "0.5.1",
|
|
216
215
|
"@remix-run/web-fetch": "^4.1.3",
|
|
217
216
|
"@testing-library/react": "^13.4.0",
|
|
@@ -226,11 +225,11 @@
|
|
|
226
225
|
"react-dom": "^18",
|
|
227
226
|
"ts-jest": "^29.1.0",
|
|
228
227
|
"typescript": "^5",
|
|
229
|
-
"webpack": "^5.
|
|
230
|
-
"@modern-js/app-tools": "2.
|
|
231
|
-
"@modern-js/core": "2.
|
|
232
|
-
"@scripts/
|
|
233
|
-
"@scripts/
|
|
228
|
+
"webpack": "^5.93.0",
|
|
229
|
+
"@modern-js/app-tools": "2.56.1",
|
|
230
|
+
"@modern-js/core": "2.56.1",
|
|
231
|
+
"@scripts/build": "2.56.1",
|
|
232
|
+
"@scripts/jest-config": "2.56.1"
|
|
234
233
|
},
|
|
235
234
|
"sideEffects": false,
|
|
236
235
|
"publishConfig": {
|