@modern-js/runtime 3.1.0 → 3.1.2
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/code.js +9 -8
- package/dist/cjs/cli/template.js +46 -8
- package/dist/cjs/document/Html.js +11 -1
- package/dist/cjs/router/runtime/PrefetchLink.js +1 -4
- package/dist/esm/cli/code.mjs +19 -18
- package/dist/esm/cli/index.mjs +2 -1
- package/dist/esm/cli/ssr/index.mjs +2 -1
- package/dist/esm/cli/ssr/loadable-bundler-plugin.mjs +1 -1
- package/dist/esm/cli/template.mjs +48 -10
- package/dist/esm/core/constants.mjs +1 -1
- package/dist/esm/core/context/index.mjs +3 -3
- package/dist/esm/core/index.mjs +2 -3
- package/dist/esm/core/server/index.mjs +3 -2
- package/dist/esm/core/server/react/index.mjs +2 -3
- package/dist/esm/core/server/server.mjs +3 -4
- package/dist/esm/core/server/stream/shared.mjs +1 -1
- package/dist/esm/document/Html.mjs +11 -1
- package/dist/esm/document/cli/index.mjs +2 -1
- package/dist/esm/exports/head.mjs +2 -1
- package/dist/esm/exports/loadable.mjs +1 -1
- package/dist/esm/index.mjs +5 -6
- package/dist/esm/internal.mjs +1 -2
- package/dist/esm/react-server.mjs +3 -4
- package/dist/esm/router/cli/code/getClientRoutes/index.mjs +1 -2
- package/dist/esm/router/cli/code/index.mjs +5 -5
- package/dist/esm/router/cli/code/nestedRoutes.mjs +7 -7
- package/dist/esm/router/cli/handler.mjs +3 -3
- package/dist/esm/router/cli/index.mjs +2 -1
- package/dist/esm/router/internal.mjs +1 -2
- package/dist/esm/router/runtime/DeferredDataScripts.mjs +1 -1
- package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +1 -1
- package/dist/esm/router/runtime/PrefetchLink.mjs +1 -5
- package/dist/esm/router/runtime/index.mjs +2 -2
- package/dist/esm/router/runtime/internal.mjs +3 -2
- package/dist/esm/router/runtime/plugin.mjs +1 -1
- package/dist/esm-node/cli/code.mjs +19 -18
- package/dist/esm-node/cli/index.mjs +2 -1
- package/dist/esm-node/cli/ssr/index.mjs +2 -1
- package/dist/esm-node/cli/ssr/loadable-bundler-plugin.mjs +1 -1
- package/dist/esm-node/cli/template.mjs +48 -10
- package/dist/esm-node/core/constants.mjs +1 -1
- package/dist/esm-node/core/context/index.mjs +3 -3
- package/dist/esm-node/core/index.mjs +2 -3
- package/dist/esm-node/core/server/index.mjs +3 -2
- package/dist/esm-node/core/server/react/index.mjs +2 -3
- package/dist/esm-node/core/server/server.mjs +3 -4
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +2 -2
- package/dist/esm-node/core/server/stream/shared.mjs +1 -1
- package/dist/esm-node/core/server/string/loadable.mjs +2 -2
- package/dist/esm-node/document/Html.mjs +11 -1
- package/dist/esm-node/document/cli/index.mjs +2 -1
- package/dist/esm-node/exports/head.mjs +2 -1
- package/dist/esm-node/exports/loadable.mjs +1 -1
- package/dist/esm-node/index.mjs +5 -6
- package/dist/esm-node/internal.mjs +1 -2
- package/dist/esm-node/react-server.mjs +3 -4
- package/dist/esm-node/router/cli/code/getClientRoutes/index.mjs +1 -2
- package/dist/esm-node/router/cli/code/index.mjs +5 -5
- package/dist/esm-node/router/cli/code/nestedRoutes.mjs +7 -7
- package/dist/esm-node/router/cli/handler.mjs +3 -3
- package/dist/esm-node/router/cli/index.mjs +4 -3
- package/dist/esm-node/router/internal.mjs +1 -2
- package/dist/esm-node/router/runtime/DeferredDataScripts.mjs +1 -1
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +1 -1
- package/dist/esm-node/router/runtime/PrefetchLink.mjs +1 -5
- package/dist/esm-node/router/runtime/index.mjs +2 -2
- package/dist/esm-node/router/runtime/internal.mjs +3 -2
- package/dist/esm-node/router/runtime/plugin.mjs +1 -1
- package/dist/types/cli/template.d.ts +2 -1
- package/package.json +11 -11
- package/{rstest.config.ts → rstest.config.mts} +0 -6
package/dist/cjs/cli/code.js
CHANGED
|
@@ -59,13 +59,7 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
59
59
|
nestedRoutesEntry
|
|
60
60
|
});
|
|
61
61
|
let indexCode = '';
|
|
62
|
-
indexCode =
|
|
63
|
-
metaName,
|
|
64
|
-
entryName,
|
|
65
|
-
mountId,
|
|
66
|
-
urlPath: serverRoutes.find((route)=>route.entryName === entryName)?.urlPath,
|
|
67
|
-
isNestedRouter: entrypoint.nestedRoutesEntry
|
|
68
|
-
}) : external_template_js_namespaceObject.index({
|
|
62
|
+
indexCode = ssrMode || !config.server.rsc || customEntry ? external_template_js_namespaceObject.index({
|
|
69
63
|
srcDirectory,
|
|
70
64
|
internalSrcAlias,
|
|
71
65
|
metaName,
|
|
@@ -75,6 +69,12 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
75
69
|
mountId,
|
|
76
70
|
enableRsc: config.server.rsc,
|
|
77
71
|
isNestedRouter: !!entrypoint.nestedRoutesEntry
|
|
72
|
+
}) : external_template_js_namespaceObject.entryForCSRWithRSC({
|
|
73
|
+
metaName,
|
|
74
|
+
entryName,
|
|
75
|
+
mountId,
|
|
76
|
+
urlPath: serverRoutes.find((route)=>route.entryName === entryName)?.urlPath,
|
|
77
|
+
isNestedRouter: entrypoint.nestedRoutesEntry
|
|
78
78
|
});
|
|
79
79
|
const indexFile = external_path_default().resolve(internalDirectory, `./${entryName}/${external_constants_js_namespaceObject.ENTRY_POINT_FILE_NAME}`);
|
|
80
80
|
await utils_namespaceObject.fs.outputFile(indexFile, indexCode, 'utf8');
|
|
@@ -141,7 +141,8 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
141
141
|
});
|
|
142
142
|
await utils_namespaceObject.fs.outputFile(AppProxyPath, appProxyCode);
|
|
143
143
|
contextCode = external_template_js_namespaceObject.runtimeGlobalContextForRSCClient({
|
|
144
|
-
metaName
|
|
144
|
+
metaName,
|
|
145
|
+
customEntry
|
|
145
146
|
});
|
|
146
147
|
const contextServerCode = external_template_js_namespaceObject.runtimeGlobalContextForRSCServer({
|
|
147
148
|
metaName
|
package/dist/cjs/cli/template.js
CHANGED
|
@@ -197,16 +197,54 @@ const runtimeGlobalContextForRSCServer = ({ metaName })=>`
|
|
|
197
197
|
App: DefaultRoot,
|
|
198
198
|
RSCRoot: AppProxy,
|
|
199
199
|
});`;
|
|
200
|
-
const runtimeGlobalContextForRSCClient = ({ metaName })=>`
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
const runtimeGlobalContextForRSCClient = ({ metaName, customEntry })=>`
|
|
201
|
+
${customEntry ? `import {
|
|
202
|
+
RscClientRoot,
|
|
203
|
+
createFromFetch,
|
|
204
|
+
createFromReadableStream,
|
|
205
|
+
isRedirectResponse,
|
|
206
|
+
rscStream,
|
|
207
|
+
callServer,
|
|
208
|
+
setServerCallback,
|
|
209
|
+
} from '@${metaName}/runtime/rsc/client';` : ''}
|
|
210
|
+
import { createElement, Fragment } from 'react';
|
|
211
|
+
import { setGlobalContext } from '@${metaName}/runtime/context';
|
|
203
212
|
|
|
204
|
-
|
|
205
|
-
createElement(Fragment, null, children);
|
|
213
|
+
${customEntry ? 'setServerCallback(callServer);' : ''}
|
|
206
214
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
215
|
+
${customEntry ? `const handleRedirectResponse = (res: Response) => {
|
|
216
|
+
const { headers } = res;
|
|
217
|
+
const location = headers.get('X-Modernjs-Redirect');
|
|
218
|
+
const baseUrl = headers.get('X-Modernjs-BaseUrl');
|
|
219
|
+
if (location) {
|
|
220
|
+
if (baseUrl && baseUrl !== '/') {
|
|
221
|
+
window.location.replace(baseUrl + location);
|
|
222
|
+
} else {
|
|
223
|
+
window.location.replace(location);
|
|
224
|
+
}
|
|
225
|
+
return res;
|
|
226
|
+
}
|
|
227
|
+
return res;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const data = ${process.env.MODERN_DISABLE_INJECT_RSC_DATA ? `createFromFetch(
|
|
231
|
+
fetch(location.pathname, {
|
|
232
|
+
headers: {
|
|
233
|
+
'x-rsc-tree': 'true',
|
|
234
|
+
},
|
|
235
|
+
}).then(handleRedirectResponse),
|
|
236
|
+
)` : `createFromReadableStream(rscStream, {
|
|
237
|
+
callServer: callServer,
|
|
238
|
+
})`};` : ''}
|
|
239
|
+
|
|
240
|
+
const DefaultRoot = ({ children }: { children?: ReactNode }) =>
|
|
241
|
+
createElement(Fragment, null, children);
|
|
242
|
+
|
|
243
|
+
${customEntry ? 'const RSCRoot = () => createElement(RscClientRoot, { rscPayload: data });' : ''}
|
|
244
|
+
|
|
245
|
+
setGlobalContext({
|
|
246
|
+
App: ${customEntry ? 'RSCRoot' : 'DefaultRoot'}
|
|
247
|
+
});`;
|
|
210
248
|
const AppProxyForRSC = ({ srcDirectory, internalSrcAlias, entry, customEntry })=>`
|
|
211
249
|
import App from '${(0, utils_namespaceObject.formatImportPath)(customEntry ? entry.replace(/entry\.[tj]sx/, 'App').replace(srcDirectory, internalSrcAlias) : entry.replace(srcDirectory, internalSrcAlias).replace('.tsx', ''))}';
|
|
212
250
|
import React from 'react';
|
|
@@ -31,12 +31,22 @@ require("react");
|
|
|
31
31
|
const external_Body_js_namespaceObject = require("./Body.js");
|
|
32
32
|
const external_DocumentStructureContext_js_namespaceObject = require("./DocumentStructureContext.js");
|
|
33
33
|
const external_Head_js_namespaceObject = require("./Head.js");
|
|
34
|
+
const external_Root_js_namespaceObject = require("./Root.js");
|
|
34
35
|
function findTargetChildByName(tag, children) {
|
|
35
36
|
return children.find((item)=>getEleType(item) === tag);
|
|
36
37
|
}
|
|
37
38
|
function findTargetChildByComponent(component, children) {
|
|
38
39
|
return children.find((item)=>item?.type === component);
|
|
39
40
|
}
|
|
41
|
+
function findTargetElementByComponent(component, children) {
|
|
42
|
+
if (0 === children.length) return null;
|
|
43
|
+
let nextChildren = [];
|
|
44
|
+
for (const item of children){
|
|
45
|
+
if (item?.type === component) return item;
|
|
46
|
+
if (item?.props?.children) nextChildren = nextChildren.concat(item.props.children);
|
|
47
|
+
}
|
|
48
|
+
return findTargetElementByComponent(component, nextChildren);
|
|
49
|
+
}
|
|
40
50
|
function getEleType(ele) {
|
|
41
51
|
return 'function' == typeof ele?.type ? ele.type.name : ele?.type;
|
|
42
52
|
}
|
|
@@ -55,7 +65,7 @@ function Html(props) {
|
|
|
55
65
|
const hasSetScripts = Boolean(findTargetElement('Scripts', children));
|
|
56
66
|
const hasSetLinks = Boolean(findTargetElement('Links', children));
|
|
57
67
|
const hasSetBody = Boolean(findTargetChildByComponent(external_Body_js_namespaceObject.Body, children) || findTargetChildByName('Body', children));
|
|
58
|
-
const hasSetRoot = Boolean(
|
|
68
|
+
const hasSetRoot = Boolean(findTargetElementByComponent(external_Root_js_namespaceObject.Root, children) || findTargetChildByName('Root', children));
|
|
59
69
|
const hasSetTitle = Boolean(findTargetElement('title', children));
|
|
60
70
|
const notMissMustChild = [
|
|
61
71
|
hasSetHead,
|
|
@@ -18,9 +18,6 @@ var __webpack_require__ = {};
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
})();
|
|
21
|
-
(()=>{
|
|
22
|
-
__webpack_require__.e = ()=>Promise.resolve();
|
|
23
|
-
})();
|
|
24
21
|
(()=>{
|
|
25
22
|
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
23
|
})();
|
|
@@ -183,7 +180,7 @@ const createPrefetchLink = (Link)=>/*#__PURE__*/ external_react_default().forwar
|
|
|
183
180
|
...props,
|
|
184
181
|
...prefetchHandlers
|
|
185
182
|
}),
|
|
186
|
-
shouldPrefetch &&
|
|
183
|
+
shouldPrefetch && __webpack_chunk_load__ && !isAbsolute ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(PrefetchPageLinks, {
|
|
187
184
|
path: resolvedPath
|
|
188
185
|
}) : null
|
|
189
186
|
]
|
package/dist/esm/cli/code.mjs
CHANGED
|
@@ -2,8 +2,8 @@ import path from "path";
|
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
3
|
import { ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_POINT_REGISTER_FILE_NAME, ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME, ENTRY_SERVER_BOOTSTRAP_FILE_NAME, INDEX_FILE_NAME, SERVER_ENTRY_POINT_FILE_NAME } from "./constants.mjs";
|
|
4
4
|
import { resolveSSRMode } from "./ssr/mode.mjs";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import * as __rspack_external__template_mjs_d6ab8956 from "./template.mjs";
|
|
6
|
+
import * as __rspack_external__template_server_mjs_38d6edb1 from "./template.server.mjs";
|
|
7
7
|
const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
8
8
|
const { mountId } = config.html;
|
|
9
9
|
const { enableAsyncEntry } = config.source;
|
|
@@ -21,13 +21,7 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
21
21
|
nestedRoutesEntry
|
|
22
22
|
});
|
|
23
23
|
let indexCode = '';
|
|
24
|
-
indexCode =
|
|
25
|
-
metaName,
|
|
26
|
-
entryName,
|
|
27
|
-
mountId,
|
|
28
|
-
urlPath: serverRoutes.find((route)=>route.entryName === entryName)?.urlPath,
|
|
29
|
-
isNestedRouter: entrypoint.nestedRoutesEntry
|
|
30
|
-
}) : index({
|
|
24
|
+
indexCode = ssrMode || !config.server.rsc || customEntry ? __rspack_external__template_mjs_d6ab8956.index({
|
|
31
25
|
srcDirectory,
|
|
32
26
|
internalSrcAlias,
|
|
33
27
|
metaName,
|
|
@@ -37,6 +31,12 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
37
31
|
mountId,
|
|
38
32
|
enableRsc: config.server.rsc,
|
|
39
33
|
isNestedRouter: !!entrypoint.nestedRoutesEntry
|
|
34
|
+
}) : __rspack_external__template_mjs_d6ab8956.entryForCSRWithRSC({
|
|
35
|
+
metaName,
|
|
36
|
+
entryName,
|
|
37
|
+
mountId,
|
|
38
|
+
urlPath: serverRoutes.find((route)=>route.entryName === entryName)?.urlPath,
|
|
39
|
+
isNestedRouter: entrypoint.nestedRoutesEntry
|
|
40
40
|
});
|
|
41
41
|
const indexFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
|
|
42
42
|
await fs.outputFile(indexFile, indexCode, 'utf8');
|
|
@@ -47,7 +47,7 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
47
47
|
if (ssrMode) await fs.outputFile(bootstrapServerFile, `export const requestHandler = import('./${SERVER_ENTRY_POINT_FILE_NAME}').then((m) => m.requestHandler)`, 'utf8');
|
|
48
48
|
}
|
|
49
49
|
if (ssrMode) {
|
|
50
|
-
const indexServerCode = serverIndex({
|
|
50
|
+
const indexServerCode = __rspack_external__template_server_mjs_38d6edb1.serverIndex({
|
|
51
51
|
entry,
|
|
52
52
|
entryName,
|
|
53
53
|
internalSrcAlias,
|
|
@@ -61,16 +61,16 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
61
61
|
await fs.outputFile(indexServerFile, indexServerCode, 'utf8');
|
|
62
62
|
} else if (config.server.rsc) {
|
|
63
63
|
const indexServerFile = path.resolve(internalDirectory, `./${entryName}/${SERVER_ENTRY_POINT_FILE_NAME}`);
|
|
64
|
-
const indexServerCode =
|
|
64
|
+
const indexServerCode = __rspack_external__template_server_mjs_38d6edb1.entryForCSRWithRSC({
|
|
65
65
|
entryName,
|
|
66
66
|
metaName
|
|
67
67
|
});
|
|
68
68
|
await fs.outputFile(indexServerFile, indexServerCode, 'utf8');
|
|
69
69
|
}
|
|
70
|
-
const registerCode = register();
|
|
70
|
+
const registerCode = __rspack_external__template_mjs_d6ab8956.register();
|
|
71
71
|
const registerFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_REGISTER_FILE_NAME}`);
|
|
72
72
|
await fs.outputFile(registerFile, registerCode, 'utf8');
|
|
73
|
-
const registerRuntimeCode = runtimeRegister({
|
|
73
|
+
const registerRuntimeCode = __rspack_external__template_mjs_d6ab8956.runtimeRegister({
|
|
74
74
|
entryName,
|
|
75
75
|
srcDirectory,
|
|
76
76
|
internalSrcAlias,
|
|
@@ -84,7 +84,7 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
84
84
|
if (!config.server.rsc || entrypoint.nestedRoutesEntry) {
|
|
85
85
|
const route = serverRoutes.find((r)=>r.entryName === entryName);
|
|
86
86
|
const basename = route?.urlPath || '/';
|
|
87
|
-
contextCode = runtimeGlobalContext({
|
|
87
|
+
contextCode = __rspack_external__template_mjs_d6ab8956.runtimeGlobalContext({
|
|
88
88
|
entryName,
|
|
89
89
|
srcDirectory,
|
|
90
90
|
internalSrcAlias,
|
|
@@ -95,17 +95,18 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
95
95
|
});
|
|
96
96
|
} else {
|
|
97
97
|
const AppProxyPath = path.join(internalDirectory, entryName, './AppProxy.jsx');
|
|
98
|
-
const appProxyCode = AppProxyForRSC({
|
|
98
|
+
const appProxyCode = __rspack_external__template_mjs_d6ab8956.AppProxyForRSC({
|
|
99
99
|
srcDirectory,
|
|
100
100
|
internalSrcAlias,
|
|
101
101
|
entry,
|
|
102
102
|
customEntry
|
|
103
103
|
});
|
|
104
104
|
await fs.outputFile(AppProxyPath, appProxyCode);
|
|
105
|
-
contextCode = runtimeGlobalContextForRSCClient({
|
|
106
|
-
metaName
|
|
105
|
+
contextCode = __rspack_external__template_mjs_d6ab8956.runtimeGlobalContextForRSCClient({
|
|
106
|
+
metaName,
|
|
107
|
+
customEntry
|
|
107
108
|
});
|
|
108
|
-
const contextServerCode = runtimeGlobalContextForRSCServer({
|
|
109
|
+
const contextServerCode = __rspack_external__template_mjs_d6ab8956.runtimeGlobalContextForRSCServer({
|
|
109
110
|
metaName
|
|
110
111
|
});
|
|
111
112
|
const contextFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}.server.js`);
|
package/dist/esm/cli/index.mjs
CHANGED
|
@@ -89,4 +89,5 @@ const runtimePlugin = (params)=>({
|
|
|
89
89
|
}
|
|
90
90
|
});
|
|
91
91
|
const cli = runtimePlugin;
|
|
92
|
-
export
|
|
92
|
+
export default cli;
|
|
93
|
+
export { documentPlugin, isRuntimeEntry, routerPlugin, runtimePlugin, ssrPlugin };
|
|
@@ -152,16 +152,54 @@ const runtimeGlobalContextForRSCServer = ({ metaName })=>`
|
|
|
152
152
|
App: DefaultRoot,
|
|
153
153
|
RSCRoot: AppProxy,
|
|
154
154
|
});`;
|
|
155
|
-
const runtimeGlobalContextForRSCClient = ({ metaName })=>`
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
155
|
+
const runtimeGlobalContextForRSCClient = ({ metaName, customEntry })=>`
|
|
156
|
+
${customEntry ? `import {
|
|
157
|
+
RscClientRoot,
|
|
158
|
+
createFromFetch,
|
|
159
|
+
createFromReadableStream,
|
|
160
|
+
isRedirectResponse,
|
|
161
|
+
rscStream,
|
|
162
|
+
callServer,
|
|
163
|
+
setServerCallback,
|
|
164
|
+
} from '@${metaName}/runtime/rsc/client';` : ''}
|
|
165
|
+
import { createElement, Fragment } from 'react';
|
|
166
|
+
import { setGlobalContext } from '@${metaName}/runtime/context';
|
|
167
|
+
|
|
168
|
+
${customEntry ? 'setServerCallback(callServer);' : ''}
|
|
169
|
+
|
|
170
|
+
${customEntry ? `const handleRedirectResponse = (res: Response) => {
|
|
171
|
+
const { headers } = res;
|
|
172
|
+
const location = headers.get('X-Modernjs-Redirect');
|
|
173
|
+
const baseUrl = headers.get('X-Modernjs-BaseUrl');
|
|
174
|
+
if (location) {
|
|
175
|
+
if (baseUrl && baseUrl !== '/') {
|
|
176
|
+
window.location.replace(baseUrl + location);
|
|
177
|
+
} else {
|
|
178
|
+
window.location.replace(location);
|
|
179
|
+
}
|
|
180
|
+
return res;
|
|
181
|
+
}
|
|
182
|
+
return res;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const data = ${process.env.MODERN_DISABLE_INJECT_RSC_DATA ? `createFromFetch(
|
|
186
|
+
fetch(location.pathname, {
|
|
187
|
+
headers: {
|
|
188
|
+
'x-rsc-tree': 'true',
|
|
189
|
+
},
|
|
190
|
+
}).then(handleRedirectResponse),
|
|
191
|
+
)` : `createFromReadableStream(rscStream, {
|
|
192
|
+
callServer: callServer,
|
|
193
|
+
})`};` : ''}
|
|
194
|
+
|
|
195
|
+
const DefaultRoot = ({ children }: { children?: ReactNode }) =>
|
|
196
|
+
createElement(Fragment, null, children);
|
|
197
|
+
|
|
198
|
+
${customEntry ? 'const RSCRoot = () => createElement(RscClientRoot, { rscPayload: data });' : ''}
|
|
199
|
+
|
|
200
|
+
setGlobalContext({
|
|
201
|
+
App: ${customEntry ? 'RSCRoot' : 'DefaultRoot'}
|
|
202
|
+
});`;
|
|
165
203
|
const AppProxyForRSC = ({ srcDirectory, internalSrcAlias, entry, customEntry })=>`
|
|
166
204
|
import App from '${formatImportPath(customEntry ? entry.replace(/entry\.[tj]sx/, 'App').replace(srcDirectory, internalSrcAlias) : entry.replace(srcDirectory, internalSrcAlias).replace('.tsx', ''))}';
|
|
167
205
|
import React from 'react';
|
|
@@ -5,4 +5,4 @@ var constants_RenderLevel = /*#__PURE__*/ function(RenderLevel) {
|
|
|
5
5
|
}({});
|
|
6
6
|
const SSR_DATA_JSON_ID = '__MODERN_SSR_DATA__';
|
|
7
7
|
const ROUTER_DATA_JSON_ID = '__MODERN_ROUTER_DATA__';
|
|
8
|
-
export { ROUTER_DATA_JSON_ID, constants_RenderLevel as RenderLevel
|
|
8
|
+
export { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID, constants_RenderLevel as RenderLevel };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { InternalRuntimeContext, RuntimeContext, getInitialContext } from "./runtime.mjs";
|
|
2
|
-
import { getServerPayload, setServerPayload } from "./serverPayload/index.mjs";
|
|
3
1
|
const globalContext = {};
|
|
4
2
|
function getGlobalIsRscClient() {
|
|
5
3
|
return globalContext.isRscClient;
|
|
@@ -42,4 +40,6 @@ function getGlobalLayoutApp() {
|
|
|
42
40
|
function getGlobalBasename() {
|
|
43
41
|
return globalContext.basename;
|
|
44
42
|
}
|
|
45
|
-
export { InternalRuntimeContext, RuntimeContext,
|
|
43
|
+
export { InternalRuntimeContext, RuntimeContext, getInitialContext } from "./runtime.mjs";
|
|
44
|
+
export { getServerPayload, setServerPayload } from "./serverPayload/index.mjs";
|
|
45
|
+
export { getCurrentEntryName, getGlobalApp, getGlobalBasename, getGlobalEnableRsc, getGlobalInternalRuntimeContext, getGlobalIsRscClient, getGlobalLayoutApp, getGlobalRSCRoot, getGlobalRoutes, setGlobalContext, setGlobalInternalRuntimeContext };
|
package/dist/esm/core/index.mjs
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { RuntimeContext, defineRuntimeConfig, useRuntimeContext };
|
|
1
|
+
export { defineRuntimeConfig } from "./config.mjs";
|
|
2
|
+
export { RuntimeContext, useRuntimeContext } from "./context/runtime.mjs";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { NoSSR, NoSSRCache } from "./react/index.mjs";
|
|
2
1
|
const ssr = (_config)=>({
|
|
3
2
|
name: '@modern-js/plugin-ssr',
|
|
4
3
|
setup: (_api)=>{}
|
|
5
4
|
});
|
|
6
5
|
const server = ssr;
|
|
7
|
-
export { NoSSR, NoSSRCache
|
|
6
|
+
export { NoSSR, NoSSRCache } from "./react/index.mjs";
|
|
7
|
+
export default server;
|
|
8
|
+
export { ssr };
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { NoSSR, NoSSRCache };
|
|
1
|
+
export { NoSSR } from "./nossr/index.mjs";
|
|
2
|
+
export { NoSSRCache } from "./no-ssr-cache/index.mjs";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { createRequestHandler, renderStreaming, renderString };
|
|
1
|
+
export { renderString } from "./string/index.mjs";
|
|
2
|
+
export { renderStreaming } from "./stream/index.mjs";
|
|
3
|
+
export { createRequestHandler } from "./requestHandler.mjs";
|
|
@@ -105,4 +105,4 @@ function createRenderStreaming(createReadableStreamPromise) {
|
|
|
105
105
|
return stream;
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
|
-
export {
|
|
108
|
+
export { createRenderStreaming, encodeForWebStream, getReadableStreamFromString, resolveStreamingMode, shared_ShellChunkStatus as ShellChunkStatus };
|
|
@@ -3,12 +3,22 @@ import "react";
|
|
|
3
3
|
import { Body } from "./Body.mjs";
|
|
4
4
|
import { DocumentStructureContext } from "./DocumentStructureContext.mjs";
|
|
5
5
|
import { Head } from "./Head.mjs";
|
|
6
|
+
import { Root } from "./Root.mjs";
|
|
6
7
|
function findTargetChildByName(tag, children) {
|
|
7
8
|
return children.find((item)=>getEleType(item) === tag);
|
|
8
9
|
}
|
|
9
10
|
function findTargetChildByComponent(component, children) {
|
|
10
11
|
return children.find((item)=>item?.type === component);
|
|
11
12
|
}
|
|
13
|
+
function findTargetElementByComponent(component, children) {
|
|
14
|
+
if (0 === children.length) return null;
|
|
15
|
+
let nextChildren = [];
|
|
16
|
+
for (const item of children){
|
|
17
|
+
if (item?.type === component) return item;
|
|
18
|
+
if (item?.props?.children) nextChildren = nextChildren.concat(item.props.children);
|
|
19
|
+
}
|
|
20
|
+
return findTargetElementByComponent(component, nextChildren);
|
|
21
|
+
}
|
|
12
22
|
function getEleType(ele) {
|
|
13
23
|
return 'function' == typeof ele?.type ? ele.type.name : ele?.type;
|
|
14
24
|
}
|
|
@@ -27,7 +37,7 @@ function Html(props) {
|
|
|
27
37
|
const hasSetScripts = Boolean(findTargetElement('Scripts', children));
|
|
28
38
|
const hasSetLinks = Boolean(findTargetElement('Links', children));
|
|
29
39
|
const hasSetBody = Boolean(findTargetChildByComponent(Body, children) || findTargetChildByName('Body', children));
|
|
30
|
-
const hasSetRoot = Boolean(
|
|
40
|
+
const hasSetRoot = Boolean(findTargetElementByComponent(Root, children) || findTargetChildByName('Root', children));
|
|
31
41
|
const hasSetTitle = Boolean(findTargetElement('title', children));
|
|
32
42
|
const notMissMustChild = [
|
|
33
43
|
hasSetHead,
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { RuntimeContext, defineRuntimeConfig, getMonitors, getRequest, isBrowser, redirect, setHeaders, setStatus, useRuntimeContext };
|
|
1
|
+
export { isBrowser } from "./common.mjs";
|
|
2
|
+
export { getMonitors } from "./core/context/monitors/index.mjs";
|
|
3
|
+
export { getRequest } from "./core/context/request/index.mjs";
|
|
4
|
+
export { redirect, setHeaders, setStatus } from "./core/context/response/index.mjs";
|
|
5
|
+
export { RuntimeContext, defineRuntimeConfig, useRuntimeContext } from "./core/index.mjs";
|
package/dist/esm/internal.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { InternalRuntimeContext };
|
|
1
|
+
export { InternalRuntimeContext } from "./core/context/runtime.mjs";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { getMonitors, getRequest, redirect, setHeaders, setStatus };
|
|
1
|
+
export { getRequest } from "./core/context/request/index.mjs";
|
|
2
|
+
export { getMonitors } from "./core/context/monitors/index.mjs";
|
|
3
|
+
export { redirect, setHeaders, setStatus } from "./core/context/response/index.mjs";
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { getClientRoutes };
|
|
1
|
+
export { getClientRoutes } from "./getRoutes.mjs";
|
|
@@ -5,8 +5,8 @@ import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME } from "../../../cli/const
|
|
|
5
5
|
import { resolveSSRMode } from "../../../cli/ssr/mode.mjs";
|
|
6
6
|
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "../constants.mjs";
|
|
7
7
|
import { walk } from "./nestedRoutes.mjs";
|
|
8
|
-
import { fileSystemRoutes, routesForServer, ssrLoaderCombinedModule } from "./templates.mjs";
|
|
9
8
|
import { getServerCombinedModuleFile, getServerLoadersFile } from "./utils.mjs";
|
|
9
|
+
import * as __rspack_external__templates_mjs_4da4c6c8 from "./templates.mjs";
|
|
10
10
|
async function generateRoutesForEntry(entrypoint, appContext) {
|
|
11
11
|
const routes = [];
|
|
12
12
|
if (entrypoint.nestedRoutesEntry) {
|
|
@@ -81,7 +81,7 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
|
|
|
81
81
|
}
|
|
82
82
|
const { code } = await hooks.onBeforeGenerateRoutes.call({
|
|
83
83
|
entrypoint,
|
|
84
|
-
code: await fileSystemRoutes({
|
|
84
|
+
code: await __rspack_external__templates_mjs_4da4c6c8.fileSystemRoutes({
|
|
85
85
|
metaName,
|
|
86
86
|
routes: routes,
|
|
87
87
|
ssrMode: isUseRsc(config) ? 'stream' : ssrMode,
|
|
@@ -98,12 +98,12 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
|
|
|
98
98
|
const routesServerFile = getServerLoadersFile(internalDirectory, entryName);
|
|
99
99
|
const filtedRoutesForServer = filterRoutesForServer(routes);
|
|
100
100
|
const routesForServerLoaderMatches = filterRoutesLoader(routes);
|
|
101
|
-
const code = routesForServer({
|
|
101
|
+
const code = __rspack_external__templates_mjs_4da4c6c8.routesForServer({
|
|
102
102
|
routesForServerLoaderMatches
|
|
103
103
|
});
|
|
104
104
|
await fs.ensureFile(routesServerFile);
|
|
105
105
|
await fs.writeFile(routesServerFile, code);
|
|
106
|
-
const serverRoutesCode = await fileSystemRoutes({
|
|
106
|
+
const serverRoutesCode = await __rspack_external__templates_mjs_4da4c6c8.fileSystemRoutes({
|
|
107
107
|
metaName,
|
|
108
108
|
routes: filtedRoutesForServer,
|
|
109
109
|
ssrMode,
|
|
@@ -117,7 +117,7 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
|
|
|
117
117
|
});
|
|
118
118
|
await fs.outputFile(path.resolve(internalDirectory, `./${entryName}/routes.server.js`), serverRoutesCode, 'utf8');
|
|
119
119
|
}
|
|
120
|
-
const serverLoaderCombined = ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext);
|
|
120
|
+
const serverLoaderCombined = __rspack_external__templates_mjs_4da4c6c8.ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext);
|
|
121
121
|
if (serverLoaderCombined) {
|
|
122
122
|
const serverLoaderFile = getServerCombinedModuleFile(internalDirectory, entryName);
|
|
123
123
|
await fs.outputFile(serverLoaderFile, serverLoaderCombined);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { extname as external_path_extname, join, relative, sep } from "path";
|
|
2
1
|
import { JS_EXTENSIONS, fs, normalizeToPosixPath } from "@modern-js/utils";
|
|
3
2
|
import { NESTED_ROUTE } from "../constants.mjs";
|
|
4
3
|
import { getPathWithoutExt, hasAction, replaceWithAlias } from "./utils.mjs";
|
|
4
|
+
import * as __rspack_external_path from "path";
|
|
5
5
|
const conventionNames = Object.values(NESTED_ROUTE);
|
|
6
6
|
const replaceDynamicPath = (routePath)=>routePath.replace(/\[(.*?)\]/g, ':$1');
|
|
7
7
|
const getRouteId = (componentPath, routesDir, entryName, isMainEntry)=>{
|
|
8
|
-
const relativePath = normalizeToPosixPath(relative(routesDir, componentPath));
|
|
8
|
+
const relativePath = normalizeToPosixPath(__rspack_external_path.relative(routesDir, componentPath));
|
|
9
9
|
const pathWithoutExt = getPathWithoutExt(relativePath);
|
|
10
10
|
let id = "";
|
|
11
11
|
id = isMainEntry ? pathWithoutExt : `${entryName}_${pathWithoutExt}`;
|
|
@@ -64,8 +64,8 @@ const walk = async (options)=>{
|
|
|
64
64
|
if (!await fs.pathExists(dirname)) return null;
|
|
65
65
|
const isDirectory = (await fs.stat(dirname)).isDirectory();
|
|
66
66
|
if (!isDirectory) return null;
|
|
67
|
-
const relativeDir = relative(rootDir, dirname);
|
|
68
|
-
const pathSegments = relativeDir.split(sep);
|
|
67
|
+
const relativeDir = __rspack_external_path.relative(rootDir, dirname);
|
|
68
|
+
const pathSegments = relativeDir.split(__rspack_external_path.sep);
|
|
69
69
|
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
70
70
|
const isRoot = '' === lastSegment;
|
|
71
71
|
const isPathlessLayout = lastSegment.startsWith('__');
|
|
@@ -93,9 +93,9 @@ const walk = async (options)=>{
|
|
|
93
93
|
let splatAction = '';
|
|
94
94
|
const items = await fs.readdir(dirname);
|
|
95
95
|
for (const item of items){
|
|
96
|
-
const itemPath = join(dirname, item);
|
|
96
|
+
const itemPath = __rspack_external_path.join(dirname, item);
|
|
97
97
|
const itemPathWithAlias = alias ? getPathWithoutExt(replaceWithAlias(alias.basename, itemPath, alias.name)) : getPathWithoutExt(itemPath);
|
|
98
|
-
const extname =
|
|
98
|
+
const extname = __rspack_external_path.extname(item);
|
|
99
99
|
const itemWithoutExt = item.slice(0, -extname.length);
|
|
100
100
|
const isDirectory = (await fs.stat(itemPath)).isDirectory();
|
|
101
101
|
if (isDirectory) {
|
|
@@ -168,7 +168,7 @@ const walk = async (options)=>{
|
|
|
168
168
|
let finalRoute = createRoute({
|
|
169
169
|
...route,
|
|
170
170
|
origin: 'file-system'
|
|
171
|
-
}, rootDir, join(dirname, `${NESTED_ROUTE.LAYOUT_FILE}.ts`), entryName, isMainEntry);
|
|
171
|
+
}, rootDir, __rspack_external_path.join(dirname, `${NESTED_ROUTE.LAYOUT_FILE}.ts`), entryName, isMainEntry);
|
|
172
172
|
if (isPathlessLayout) delete finalRoute.path;
|
|
173
173
|
const childRoutes = finalRoute.children = finalRoute.children?.filter((childRoute)=>childRoute);
|
|
174
174
|
if (childRoutes && 0 === childRoutes.length && !finalRoute.index && !finalRoute._component) return null;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { getMeta } from "@modern-js/utils";
|
|
3
3
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
4
|
-
import { runtimeGlobalContext } from "./code/templates.mjs";
|
|
5
4
|
import { isPageComponentFile } from "./code/utils.mjs";
|
|
6
5
|
import { modifyEntrypoints } from "./entry.mjs";
|
|
6
|
+
import * as __rspack_external__code_templates_mjs_5e908598 from "./code/templates.mjs";
|
|
7
7
|
let originEntrypoints = [];
|
|
8
8
|
async function handleModifyEntrypoints(entrypoints) {
|
|
9
9
|
return modifyEntrypoints(entrypoints);
|
|
@@ -20,7 +20,7 @@ async function handleGeneratorEntryCode(api, entrypoints) {
|
|
|
20
20
|
if (entrypoint.nestedRoutesEntry || entrypoint.pageRoutesEntry) {
|
|
21
21
|
const route = appContext.serverRoutes.find((r)=>r.entryName === entrypoint.entryName);
|
|
22
22
|
const basename = route?.urlPath || '/';
|
|
23
|
-
generatorRegisterCode(internalDirectory, entrypoint.entryName, await runtimeGlobalContext({
|
|
23
|
+
generatorRegisterCode(internalDirectory, entrypoint.entryName, await __rspack_external__code_templates_mjs_5e908598.runtimeGlobalContext({
|
|
24
24
|
entryName: entrypoint.entryName,
|
|
25
25
|
metaName: appContext.metaName,
|
|
26
26
|
srcDirectory: appContext.srcDirectory,
|
|
@@ -30,7 +30,7 @@ async function handleGeneratorEntryCode(api, entrypoints) {
|
|
|
30
30
|
rscType: enableRsc ? 'client' : void 0,
|
|
31
31
|
basename
|
|
32
32
|
}));
|
|
33
|
-
if (enableRsc) generatorServerRegisterCode(internalDirectory, entrypoint.entryName, await runtimeGlobalContext({
|
|
33
|
+
if (enableRsc) generatorServerRegisterCode(internalDirectory, entrypoint.entryName, await __rspack_external__code_templates_mjs_5e908598.runtimeGlobalContext({
|
|
34
34
|
entryName: entrypoint.entryName,
|
|
35
35
|
metaName: appContext.metaName,
|
|
36
36
|
srcDirectory: appContext.srcDirectory,
|
|
@@ -77,4 +77,5 @@ const routerPlugin = ()=>({
|
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
const cli = routerPlugin;
|
|
80
|
-
export
|
|
80
|
+
export default cli;
|
|
81
|
+
export { handleFileChange, handleModifyEntrypoints, isRouteEntry, routerPlugin };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const DeferredDataScripts = ()=>null;
|
|
2
|
-
export
|
|
2
|
+
export default DeferredDataScripts;
|