@modern-js/runtime 2.64.1 → 2.64.3
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 +67 -28
- package/dist/cjs/cli/constants.js +1 -1
- package/dist/cjs/cli/ssr/index.js +4 -1
- package/dist/cjs/cli/template.js +91 -4
- package/dist/cjs/cli/template.server.js +65 -3
- package/dist/cjs/core/context/index.js +6 -0
- package/dist/cjs/core/server/requestHandler.js +11 -5
- package/dist/cjs/core/server/stream/afterTemplate.js +2 -0
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +8 -4
- package/dist/cjs/core/server/stream/index.js +12 -2
- package/dist/cjs/core/server/stream/shared.js +19 -6
- package/dist/cjs/core/server/string/index.js +4 -4
- package/dist/cjs/core/server/string/prefetch.js +3 -3
- package/dist/cjs/core/server/tracer.js +3 -18
- package/dist/cjs/router/cli/code/index.js +1 -1
- package/dist/cjs/router/cli/code/templates.js +27 -15
- package/dist/cjs/rsc/client.js +22 -0
- package/dist/cjs/rsc/server.js +22 -0
- package/dist/esm/cli/code.js +178 -51
- package/dist/esm/cli/constants.js +1 -1
- package/dist/esm/cli/ssr/index.js +4 -1
- package/dist/esm/cli/template.js +29 -4
- package/dist/esm/cli/template.server.js +11 -3
- package/dist/esm/core/context/index.js +5 -0
- package/dist/esm/core/server/requestHandler.js +12 -6
- package/dist/esm/core/server/stream/afterTemplate.js +5 -0
- package/dist/esm/core/server/stream/createReadableStream.worker.js +9 -5
- package/dist/esm/core/server/stream/index.js +5 -1
- package/dist/esm/core/server/stream/shared.js +76 -54
- package/dist/esm/core/server/string/index.js +5 -5
- package/dist/esm/core/server/string/prefetch.js +3 -3
- package/dist/esm/core/server/tracer.js +2 -16
- package/dist/esm/router/cli/code/index.js +1 -1
- package/dist/esm/router/cli/code/templates.js +29 -16
- package/dist/esm/rsc/client.js +1 -0
- package/dist/esm/rsc/server.js +1 -0
- package/dist/esm-node/cli/code.js +67 -28
- package/dist/esm-node/cli/constants.js +1 -1
- package/dist/esm-node/cli/ssr/index.js +4 -1
- package/dist/esm-node/cli/template.js +87 -4
- package/dist/esm-node/cli/template.server.js +64 -3
- package/dist/esm-node/core/context/index.js +5 -0
- package/dist/esm-node/core/server/requestHandler.js +12 -6
- package/dist/esm-node/core/server/stream/afterTemplate.js +2 -0
- package/dist/esm-node/core/server/stream/createReadableStream.worker.js +8 -4
- package/dist/esm-node/core/server/stream/index.js +1 -1
- package/dist/esm-node/core/server/stream/shared.js +20 -7
- package/dist/esm-node/core/server/string/index.js +5 -5
- package/dist/esm-node/core/server/string/prefetch.js +3 -3
- package/dist/esm-node/core/server/tracer.js +2 -15
- package/dist/esm-node/router/cli/code/index.js +1 -1
- package/dist/esm-node/router/cli/code/templates.js +27 -15
- package/dist/esm-node/rsc/client.js +1 -0
- package/dist/esm-node/rsc/server.js +1 -0
- package/dist/types/cli/constants.d.ts +1 -1
- package/dist/types/cli/template.d.ts +20 -1
- package/dist/types/cli/template.server.d.ts +4 -0
- package/dist/types/core/context/index.d.ts +5 -0
- package/dist/types/core/server/requestHandler.d.ts +3 -1
- package/dist/types/core/server/stream/shared.d.ts +8 -2
- package/dist/types/core/server/tracer.d.ts +3 -5
- package/dist/types/core/types.d.ts +3 -2
- package/dist/types/rsc/client.d.ts +1 -0
- package/dist/types/rsc/server.d.ts +1 -0
- package/package.json +29 -12
|
@@ -56,7 +56,7 @@ const prefetch = async (App, request, options, ssrConfig, { onError, onTiming })
|
|
|
56
56
|
onTiming(import_tracer.SSRTimings.PRERENDER, cost);
|
|
57
57
|
} catch (e) {
|
|
58
58
|
const error = e;
|
|
59
|
-
onError(import_tracer.SSRErrors.PRERENDER
|
|
59
|
+
onError(error, import_tracer.SSRErrors.PRERENDER);
|
|
60
60
|
throw e;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -73,13 +73,13 @@ const prefetch = async (App, request, options, ssrConfig, { onError, onTiming })
|
|
|
73
73
|
const cost = end();
|
|
74
74
|
onTiming(import_tracer.SSRTimings.USE_LOADER, cost);
|
|
75
75
|
} catch (e) {
|
|
76
|
-
onError(import_tracer.SSRErrors.USE_LOADER
|
|
76
|
+
onError(e, import_tracer.SSRErrors.USE_LOADER);
|
|
77
77
|
throw e;
|
|
78
78
|
}
|
|
79
79
|
Object.keys(loadersData).forEach((id) => {
|
|
80
80
|
const data = loadersData[id];
|
|
81
81
|
if (data._error) {
|
|
82
|
-
onError(import_tracer.SSRErrors.USE_LOADER
|
|
82
|
+
onError(data._error, import_tracer.SSRErrors.USE_LOADER);
|
|
83
83
|
delete data._error;
|
|
84
84
|
}
|
|
85
85
|
});
|
|
@@ -19,9 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var tracer_exports = {};
|
|
20
20
|
__export(tracer_exports, {
|
|
21
21
|
SSRErrors: () => SSRErrors,
|
|
22
|
-
SSRTimings: () => SSRTimings
|
|
23
|
-
createOnError: () => createOnError,
|
|
24
|
-
createOnTiming: () => createOnTiming
|
|
22
|
+
SSRTimings: () => SSRTimings
|
|
25
23
|
});
|
|
26
24
|
module.exports = __toCommonJS(tracer_exports);
|
|
27
25
|
var SSRTimings;
|
|
@@ -38,23 +36,10 @@ var SSRErrors;
|
|
|
38
36
|
SSRErrors2["RENDER_HTML"] = "App Render To HTML";
|
|
39
37
|
SSRErrors2["RENDER_STREAM"] = "An error occurs during streaming SSR";
|
|
40
38
|
SSRErrors2["RENDER_SHELL"] = "An error occurs during streaming render shell";
|
|
39
|
+
SSRErrors2["LOADER_ERROR"] = "App error occurs during data loader";
|
|
41
40
|
})(SSRErrors || (SSRErrors = {}));
|
|
42
|
-
function createOnError(onError) {
|
|
43
|
-
return (key, e) => {
|
|
44
|
-
const error = e instanceof Error ? e : new Error("Unexpected Server Error");
|
|
45
|
-
error.name = key;
|
|
46
|
-
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function createOnTiming(onTiming) {
|
|
50
|
-
return (key, cost) => {
|
|
51
|
-
onTiming === null || onTiming === void 0 ? void 0 : onTiming(key, cost);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
55
42
|
0 && (module.exports = {
|
|
56
43
|
SSRErrors,
|
|
57
|
-
SSRTimings
|
|
58
|
-
createOnError,
|
|
59
|
-
createOnTiming
|
|
44
|
+
SSRTimings
|
|
60
45
|
});
|
|
@@ -147,7 +147,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
function generatorRegisterCode(internalDirectory, entryName, code) {
|
|
150
|
-
import_utils.fs.outputFileSync(import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}`), code, "utf8");
|
|
150
|
+
import_utils.fs.outputFileSync(import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}.js`), code, "utf8");
|
|
151
151
|
}
|
|
152
152
|
// Annotate the CommonJS export names for ESM import in node:
|
|
153
153
|
0 && (module.exports = {
|
|
@@ -146,6 +146,10 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
146
146
|
}
|
|
147
147
|
return "";
|
|
148
148
|
};
|
|
149
|
+
const createLazyImport = ({ componentPath, routeId, webpackChunkName, eager }) => {
|
|
150
|
+
const importOptions = webpackChunkName ? `/* webpackChunkName: "${routeId}" */ ` : eager ? `/* webpackMode: "eager" */ ` : "";
|
|
151
|
+
return `() => import(${importOptions}'${componentPath}').then(routeModule => handleRouteModule(routeModule, "${routeId}")).catch(handleRouteModuleError)`;
|
|
152
|
+
};
|
|
149
153
|
const traverseRouteTree = (route) => {
|
|
150
154
|
let children;
|
|
151
155
|
if ("children" in route && route.children) {
|
|
@@ -194,24 +198,32 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
194
198
|
configsMap[config] = route.config;
|
|
195
199
|
}
|
|
196
200
|
if (route._component) {
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
if (route.isRoot) {
|
|
202
|
+
lazyImport = createLazyImport({
|
|
203
|
+
componentPath: route._component,
|
|
204
|
+
routeId: route.id
|
|
205
|
+
});
|
|
206
|
+
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
207
|
+
component = "RootLayout";
|
|
208
|
+
} else if (splitRouteChunks) {
|
|
209
|
+
lazyImport = createLazyImport({
|
|
210
|
+
componentPath: route._component,
|
|
211
|
+
routeId: route.id,
|
|
212
|
+
webpackChunkName: true
|
|
213
|
+
});
|
|
214
|
+
component = ssrMode === "string" ? `loadable(${lazyImport})` : `lazy(${lazyImport})`;
|
|
215
|
+
} else {
|
|
216
|
+
if (ssrMode === "string") {
|
|
217
|
+
components.push(route._component);
|
|
218
|
+
component = `component_${components.length - 1}`;
|
|
205
219
|
} else {
|
|
206
|
-
lazyImport =
|
|
220
|
+
lazyImport = createLazyImport({
|
|
221
|
+
componentPath: route._component,
|
|
222
|
+
routeId: route.id,
|
|
223
|
+
eager: true
|
|
224
|
+
});
|
|
207
225
|
component = `lazy(${lazyImport})`;
|
|
208
226
|
}
|
|
209
|
-
} else if (ssrMode === "string") {
|
|
210
|
-
components.push(route._component);
|
|
211
|
-
component = `component_${components.length - 1}`;
|
|
212
|
-
} else {
|
|
213
|
-
lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
|
214
|
-
component = `lazy(${lazyImport})`;
|
|
215
227
|
}
|
|
216
228
|
}
|
|
217
229
|
} else if (route._component) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var client_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(client_exports);
|
|
18
|
+
__reExport(client_exports, require("@modern-js/render/client"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("@modern-js/render/client")
|
|
22
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var server_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(server_exports);
|
|
18
|
+
__reExport(server_exports, require("@modern-js/render/rsc"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("@modern-js/render/rsc")
|
|
22
|
+
});
|
package/dist/esm/cli/code.js
CHANGED
|
@@ -23,18 +23,18 @@ function getSSRMode(entry, config) {
|
|
|
23
23
|
}
|
|
24
24
|
var generateCode = function() {
|
|
25
25
|
var _ref = _async_to_generator(function(entrypoints, appContext, config, hooks) {
|
|
26
|
-
var mountId, enableAsyncEntry, runtimeConfigFile, internalDirectory, internalSrcAlias, metaName, srcDirectory;
|
|
26
|
+
var mountId, enableAsyncEntry, runtimeConfigFile, internalDirectory, internalSrcAlias, metaName, srcDirectory, serverRoutes;
|
|
27
27
|
return _ts_generator(this, function(_state) {
|
|
28
28
|
switch (_state.label) {
|
|
29
29
|
case 0:
|
|
30
30
|
mountId = config.html.mountId;
|
|
31
31
|
enableAsyncEntry = config.source.enableAsyncEntry;
|
|
32
|
-
runtimeConfigFile = appContext.runtimeConfigFile, internalDirectory = appContext.internalDirectory, internalSrcAlias = appContext.internalSrcAlias, metaName = appContext.metaName, srcDirectory = appContext.srcDirectory;
|
|
32
|
+
runtimeConfigFile = appContext.runtimeConfigFile, internalDirectory = appContext.internalDirectory, internalSrcAlias = appContext.internalSrcAlias, metaName = appContext.metaName, srcDirectory = appContext.srcDirectory, serverRoutes = appContext.serverRoutes;
|
|
33
33
|
return [
|
|
34
34
|
4,
|
|
35
35
|
Promise.all(entrypoints.map(function() {
|
|
36
36
|
var _ref2 = _async_to_generator(function(entrypoint) {
|
|
37
|
-
var entryName, isAutoMount, entry, customEntry, customBootstrap, customServerEntry, _ref3, runtimePlugins, indexCode,
|
|
37
|
+
var entryName, isAutoMount, entry, customEntry, customBootstrap, customServerEntry, _ref3, runtimePlugins, ssrMode, indexCode, _serverRoutes_find, indexFile, bootstrapFile, bootstrapServerFile, indexServerCode, indexServerFile, indexServerFile1, indexServerCode1, registerCode, registerFile, registerRuntimeCode, registerRuntimeFile, contextCode, AppProxyPath, appProxyCode, contextServerCode, contextFile, contextFile1;
|
|
38
38
|
return _ts_generator(this, function(_state2) {
|
|
39
39
|
switch (_state2.label) {
|
|
40
40
|
case 0:
|
|
@@ -48,7 +48,24 @@ var generateCode = function() {
|
|
|
48
48
|
];
|
|
49
49
|
case 1:
|
|
50
50
|
_ref3 = _state2.sent(), runtimePlugins = _ref3.plugins;
|
|
51
|
-
if (isAutoMount)
|
|
51
|
+
if (!isAutoMount)
|
|
52
|
+
return [
|
|
53
|
+
3,
|
|
54
|
+
17
|
|
55
|
+
];
|
|
56
|
+
ssrMode = getSSRMode(entryName, config);
|
|
57
|
+
indexCode = "";
|
|
58
|
+
if (!ssrMode && config.server.rsc) {
|
|
59
|
+
;
|
|
60
|
+
indexCode = template.entryForCSRWithRSC({
|
|
61
|
+
metaName,
|
|
62
|
+
entryName,
|
|
63
|
+
mountId,
|
|
64
|
+
urlPath: (_serverRoutes_find = serverRoutes.find(function(route) {
|
|
65
|
+
return route.entryName === entryName;
|
|
66
|
+
})) === null || _serverRoutes_find === void 0 ? void 0 : _serverRoutes_find.urlPath
|
|
67
|
+
});
|
|
68
|
+
} else {
|
|
52
69
|
indexCode = template.index({
|
|
53
70
|
srcDirectory,
|
|
54
71
|
internalSrcAlias,
|
|
@@ -57,55 +74,165 @@ var generateCode = function() {
|
|
|
57
74
|
entryName,
|
|
58
75
|
customEntry,
|
|
59
76
|
customBootstrap,
|
|
60
|
-
mountId
|
|
61
|
-
|
|
62
|
-
indexFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
|
|
63
|
-
fs.outputFileSync(indexFile, indexCode, "utf8");
|
|
64
|
-
ssrMode = getSSRMode(entryName, config);
|
|
65
|
-
if (enableAsyncEntry) {
|
|
66
|
-
bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
|
|
67
|
-
fs.outputFileSync(bootstrapFile, 'import(/* webpackChunkName: "async-'.concat(entryName, `" */ './`).concat(INDEX_FILE_NAME, "');"), "utf8");
|
|
68
|
-
bootstrapServerFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_SERVER_BOOTSTRAP_FILE_NAME));
|
|
69
|
-
if (ssrMode) {
|
|
70
|
-
fs.outputFileSync(bootstrapServerFile, "export const requestHandler = import('./".concat(SERVER_ENTRY_POINT_FILE_NAME, "').then((m) => m.requestHandler)"), "utf8");
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (ssrMode) {
|
|
74
|
-
indexServerCode = serverTemplate.serverIndex({
|
|
75
|
-
entry,
|
|
76
|
-
entryName,
|
|
77
|
-
internalSrcAlias,
|
|
78
|
-
metaName,
|
|
79
|
-
mode: ssrMode,
|
|
80
|
-
customServerEntry,
|
|
81
|
-
srcDirectory
|
|
82
|
-
});
|
|
83
|
-
indexServerFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(SERVER_ENTRY_POINT_FILE_NAME));
|
|
84
|
-
fs.outputFileSync(indexServerFile, indexServerCode, "utf8");
|
|
85
|
-
}
|
|
86
|
-
registerCode = template.register();
|
|
87
|
-
registerFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_REGISTER_FILE_NAME));
|
|
88
|
-
fs.outputFileSync(registerFile, registerCode, "utf8");
|
|
89
|
-
registerRuntimeCode = template.runtimeRegister({
|
|
90
|
-
entryName,
|
|
91
|
-
srcDirectory,
|
|
92
|
-
internalSrcAlias,
|
|
93
|
-
metaName,
|
|
94
|
-
runtimeConfigFile,
|
|
95
|
-
runtimePlugins
|
|
96
|
-
});
|
|
97
|
-
registerRuntimeFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME));
|
|
98
|
-
fs.outputFileSync(registerRuntimeFile, registerRuntimeCode, "utf8");
|
|
99
|
-
contextCode = template.runtimeGlobalContext({
|
|
100
|
-
srcDirectory,
|
|
101
|
-
internalSrcAlias,
|
|
102
|
-
metaName,
|
|
103
|
-
entry,
|
|
104
|
-
customEntry
|
|
77
|
+
mountId,
|
|
78
|
+
enableRsc: config.server.rsc
|
|
105
79
|
});
|
|
106
|
-
contextFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME));
|
|
107
|
-
fs.outputFileSync(contextFile, contextCode, "utf8");
|
|
108
80
|
}
|
|
81
|
+
indexFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
|
|
82
|
+
return [
|
|
83
|
+
4,
|
|
84
|
+
fs.outputFile(indexFile, indexCode, "utf8")
|
|
85
|
+
];
|
|
86
|
+
case 2:
|
|
87
|
+
_state2.sent();
|
|
88
|
+
if (!enableAsyncEntry)
|
|
89
|
+
return [
|
|
90
|
+
3,
|
|
91
|
+
5
|
|
92
|
+
];
|
|
93
|
+
bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
|
|
94
|
+
return [
|
|
95
|
+
4,
|
|
96
|
+
fs.outputFile(bootstrapFile, 'import(/* webpackChunkName: "async-'.concat(entryName, `" */ './`).concat(INDEX_FILE_NAME, "');"), "utf8")
|
|
97
|
+
];
|
|
98
|
+
case 3:
|
|
99
|
+
_state2.sent();
|
|
100
|
+
bootstrapServerFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_SERVER_BOOTSTRAP_FILE_NAME));
|
|
101
|
+
if (!ssrMode)
|
|
102
|
+
return [
|
|
103
|
+
3,
|
|
104
|
+
5
|
|
105
|
+
];
|
|
106
|
+
return [
|
|
107
|
+
4,
|
|
108
|
+
fs.outputFile(bootstrapServerFile, "export const requestHandler = import('./".concat(SERVER_ENTRY_POINT_FILE_NAME, "').then((m) => m.requestHandler)"), "utf8")
|
|
109
|
+
];
|
|
110
|
+
case 4:
|
|
111
|
+
_state2.sent();
|
|
112
|
+
_state2.label = 5;
|
|
113
|
+
case 5:
|
|
114
|
+
if (!ssrMode)
|
|
115
|
+
return [
|
|
116
|
+
3,
|
|
117
|
+
7
|
|
118
|
+
];
|
|
119
|
+
indexServerCode = serverTemplate.serverIndex({
|
|
120
|
+
entry,
|
|
121
|
+
entryName,
|
|
122
|
+
internalSrcAlias,
|
|
123
|
+
metaName,
|
|
124
|
+
mode: ssrMode,
|
|
125
|
+
customServerEntry,
|
|
126
|
+
srcDirectory,
|
|
127
|
+
enableRsc: config.server.rsc
|
|
128
|
+
});
|
|
129
|
+
indexServerFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(SERVER_ENTRY_POINT_FILE_NAME));
|
|
130
|
+
return [
|
|
131
|
+
4,
|
|
132
|
+
fs.outputFile(indexServerFile, indexServerCode, "utf8")
|
|
133
|
+
];
|
|
134
|
+
case 6:
|
|
135
|
+
_state2.sent();
|
|
136
|
+
return [
|
|
137
|
+
3,
|
|
138
|
+
9
|
|
139
|
+
];
|
|
140
|
+
case 7:
|
|
141
|
+
if (!config.server.rsc)
|
|
142
|
+
return [
|
|
143
|
+
3,
|
|
144
|
+
9
|
|
145
|
+
];
|
|
146
|
+
indexServerFile1 = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(SERVER_ENTRY_POINT_FILE_NAME));
|
|
147
|
+
indexServerCode1 = serverTemplate.entryForCSRWithRSC({
|
|
148
|
+
metaName
|
|
149
|
+
});
|
|
150
|
+
return [
|
|
151
|
+
4,
|
|
152
|
+
fs.outputFile(indexServerFile1, indexServerCode1, "utf8")
|
|
153
|
+
];
|
|
154
|
+
case 8:
|
|
155
|
+
_state2.sent();
|
|
156
|
+
_state2.label = 9;
|
|
157
|
+
case 9:
|
|
158
|
+
registerCode = template.register();
|
|
159
|
+
registerFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_REGISTER_FILE_NAME));
|
|
160
|
+
return [
|
|
161
|
+
4,
|
|
162
|
+
fs.outputFile(registerFile, registerCode, "utf8")
|
|
163
|
+
];
|
|
164
|
+
case 10:
|
|
165
|
+
_state2.sent();
|
|
166
|
+
registerRuntimeCode = template.runtimeRegister({
|
|
167
|
+
entryName,
|
|
168
|
+
srcDirectory,
|
|
169
|
+
internalSrcAlias,
|
|
170
|
+
metaName,
|
|
171
|
+
runtimeConfigFile,
|
|
172
|
+
runtimePlugins
|
|
173
|
+
});
|
|
174
|
+
registerRuntimeFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME));
|
|
175
|
+
return [
|
|
176
|
+
4,
|
|
177
|
+
fs.outputFile(registerRuntimeFile, registerRuntimeCode, "utf8")
|
|
178
|
+
];
|
|
179
|
+
case 11:
|
|
180
|
+
_state2.sent();
|
|
181
|
+
contextCode = "";
|
|
182
|
+
if (!!config.server.rsc)
|
|
183
|
+
return [
|
|
184
|
+
3,
|
|
185
|
+
12
|
|
186
|
+
];
|
|
187
|
+
contextCode = template.runtimeGlobalContext({
|
|
188
|
+
srcDirectory,
|
|
189
|
+
internalSrcAlias,
|
|
190
|
+
metaName,
|
|
191
|
+
entry,
|
|
192
|
+
customEntry
|
|
193
|
+
});
|
|
194
|
+
return [
|
|
195
|
+
3,
|
|
196
|
+
15
|
|
197
|
+
];
|
|
198
|
+
case 12:
|
|
199
|
+
AppProxyPath = path.join(internalDirectory, entryName, "./AppProxy.jsx");
|
|
200
|
+
appProxyCode = template.AppProxyForRSC({
|
|
201
|
+
srcDirectory,
|
|
202
|
+
internalSrcAlias,
|
|
203
|
+
entry,
|
|
204
|
+
customEntry
|
|
205
|
+
});
|
|
206
|
+
return [
|
|
207
|
+
4,
|
|
208
|
+
fs.outputFile(AppProxyPath, appProxyCode)
|
|
209
|
+
];
|
|
210
|
+
case 13:
|
|
211
|
+
_state2.sent();
|
|
212
|
+
contextCode = template.runtimeGlobalContextForRSCClient({
|
|
213
|
+
metaName
|
|
214
|
+
});
|
|
215
|
+
contextServerCode = template.runtimeGlobalContextForRSCServer({
|
|
216
|
+
metaName
|
|
217
|
+
});
|
|
218
|
+
contextFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ".server.js"));
|
|
219
|
+
return [
|
|
220
|
+
4,
|
|
221
|
+
fs.outputFile(contextFile, contextServerCode, "utf8")
|
|
222
|
+
];
|
|
223
|
+
case 14:
|
|
224
|
+
_state2.sent();
|
|
225
|
+
_state2.label = 15;
|
|
226
|
+
case 15:
|
|
227
|
+
contextFile1 = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ".js"));
|
|
228
|
+
return [
|
|
229
|
+
4,
|
|
230
|
+
fs.outputFile(contextFile1, contextCode, "utf8")
|
|
231
|
+
];
|
|
232
|
+
case 16:
|
|
233
|
+
_state2.sent();
|
|
234
|
+
_state2.label = 17;
|
|
235
|
+
case 17:
|
|
109
236
|
return [
|
|
110
237
|
2
|
|
111
238
|
];
|
|
@@ -5,7 +5,7 @@ var INDEX_FILE_NAME = "index";
|
|
|
5
5
|
var ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
|
6
6
|
var ENTRY_SERVER_BOOTSTRAP_FILE_NAME = "bootstrap.server.jsx";
|
|
7
7
|
var ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME = "runtime-register.js";
|
|
8
|
-
var ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME = "runtime-global-context
|
|
8
|
+
var ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME = "runtime-global-context";
|
|
9
9
|
var ENTRY_POINT_REGISTER_FILE_NAME = "register.js";
|
|
10
10
|
export {
|
|
11
11
|
APP_FILE_NAME,
|
|
@@ -47,13 +47,16 @@ var ssrBuilderPlugin = function(modernAPI) {
|
|
|
47
47
|
setup: function setup(api) {
|
|
48
48
|
api.modifyEnvironmentConfig(function(config, param) {
|
|
49
49
|
var name = param.name, mergeEnvironmentConfig = param.mergeEnvironmentConfig;
|
|
50
|
+
var _userConfig_deploy_worker, _userConfig_deploy, _userConfig_server;
|
|
50
51
|
var isServerEnvironment = config.output.target === "node" || name === "workerSSR";
|
|
51
52
|
var userConfig = modernAPI.getNormalizedConfig();
|
|
53
|
+
var ssrEnv = ((_userConfig_deploy = userConfig.deploy) === null || _userConfig_deploy === void 0 ? void 0 : (_userConfig_deploy_worker = _userConfig_deploy.worker) === null || _userConfig_deploy_worker === void 0 ? void 0 : _userConfig_deploy_worker.ssr) || ((_userConfig_server = userConfig.server) === null || _userConfig_server === void 0 ? void 0 : _userConfig_server.rsc) ? "edge" : "node";
|
|
52
54
|
var useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig);
|
|
53
55
|
return mergeEnvironmentConfig(config, {
|
|
54
56
|
source: {
|
|
55
57
|
define: {
|
|
56
|
-
"process.env.MODERN_TARGET": isServerEnvironment ? JSON.stringify("node") : JSON.stringify("browser")
|
|
58
|
+
"process.env.MODERN_TARGET": isServerEnvironment ? JSON.stringify("node") : JSON.stringify("browser"),
|
|
59
|
+
"process.env.MODERN_SSR_ENV": JSON.stringify(ssrEnv)
|
|
57
60
|
}
|
|
58
61
|
},
|
|
59
62
|
tools: {
|
package/dist/esm/cli/template.js
CHANGED
|
@@ -2,14 +2,18 @@ import path from "path";
|
|
|
2
2
|
import { JS_EXTENSIONS, findExists, formatImportPath } from "@modern-js/utils";
|
|
3
3
|
import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME } from "./constants";
|
|
4
4
|
var genRenderCode = function(param) {
|
|
5
|
-
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, metaName = param.metaName, entry = param.entry, customEntry = param.customEntry, customBootstrap = param.customBootstrap, mountId = param.mountId;
|
|
5
|
+
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, metaName = param.metaName, entry = param.entry, customEntry = param.customEntry, customBootstrap = param.customBootstrap, mountId = param.mountId, enableRsc = param.enableRsc;
|
|
6
6
|
if (customEntry) {
|
|
7
7
|
return "import '".concat(formatImportPath(entry.replace(srcDirectory, internalSrcAlias)), "'");
|
|
8
8
|
}
|
|
9
|
-
return "import { createRoot } from '@".concat(metaName, "/runtime/react';\nimport { render } from '@").concat(metaName, "/runtime/browser';\n").concat(customBootstrap ? "import customBootstrap from '".concat(formatImportPath(customBootstrap.replace(srcDirectory, internalSrcAlias)), "';") : "", "\n\nconst ModernRoot = createRoot();\n\n").concat(customBootstrap ? "customBootstrap(ModernRoot, () => render(<ModernRoot />, '".concat(mountId || "root", "'));") : "render(<ModernRoot />, '".concat(mountId || "root", "');"));
|
|
9
|
+
return "import { createRoot } from '@".concat(metaName, "/runtime/react';\nimport { render } from '@").concat(metaName, "/runtime/browser';\n\n").concat(enableRsc ? "import { RscClientRoot, createFromReadableStream, rscStream, callServer } from '@".concat(metaName, "/runtime/rsc/client';") : "", "\n\n").concat(enableRsc ? "const data = createFromReadableStream(rscStream, {\n callServer: callServer,\n });" : "", "\n\n").concat(customBootstrap ? "import customBootstrap from '".concat(formatImportPath(customBootstrap.replace(srcDirectory, internalSrcAlias)), "';") : "", "\n\n\n\nconst ModernRoot = createRoot();\n\n").concat(customBootstrap ? "customBootstrap(ModernRoot, () => render(<ModernRoot />, '".concat(mountId || "root", "'));") : enableRsc ? "render(<ModernRoot>\n <RscClientRoot data={data} />\n </ModernRoot>, '".concat(mountId || "root", "');") : "render(<ModernRoot />, '".concat(mountId || "root", "');"));
|
|
10
|
+
};
|
|
11
|
+
var entryForCSRWithRSC = function(param) {
|
|
12
|
+
var metaName = param.metaName, entryName = param.entryName, _param_urlPath = param.urlPath, urlPath = _param_urlPath === void 0 ? "/" : _param_urlPath, _param_mountId = param.mountId, mountId = _param_mountId === void 0 ? "root" : _param_mountId;
|
|
13
|
+
return "\n import '@".concat(metaName, "/runtime/registry/").concat(entryName, "';\n import { render } from '@").concat(metaName, "/runtime/browser';\n import { createRoot } from '@").concat(metaName, "/runtime/react';\n\n import {\n RscClientRoot,\n createFromFetch\n } from '@").concat(metaName, "/runtime/rsc/client';\n\n const content = createFromFetch(\n fetch('").concat(urlPath, "', {\n headers: {\n 'x-rsc-tree': 'true',\n },\n }),\n );\n\n const ModernRoot = createRoot();\n\n render(\n <ModernRoot>\n <RscClientRoot data={content} />\n </ModernRoot>,\n '").concat(mountId, "',\n );\n ");
|
|
10
14
|
};
|
|
11
15
|
var index = function(param) {
|
|
12
|
-
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, metaName = param.metaName, entry = param.entry, entryName = param.entryName, customEntry = param.customEntry, customBootstrap = param.customBootstrap, mountId = param.mountId;
|
|
16
|
+
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, metaName = param.metaName, entry = param.entry, entryName = param.entryName, customEntry = param.customEntry, customBootstrap = param.customBootstrap, mountId = param.mountId, enableRsc = param.enableRsc;
|
|
13
17
|
return "import '@".concat(metaName, "/runtime/registry/").concat(entryName, "';\n").concat(genRenderCode({
|
|
14
18
|
srcDirectory,
|
|
15
19
|
internalSrcAlias,
|
|
@@ -17,7 +21,8 @@ var index = function(param) {
|
|
|
17
21
|
entry,
|
|
18
22
|
customEntry,
|
|
19
23
|
customBootstrap,
|
|
20
|
-
mountId
|
|
24
|
+
mountId,
|
|
25
|
+
enableRsc
|
|
21
26
|
}), "\n");
|
|
22
27
|
};
|
|
23
28
|
var register = function() {
|
|
@@ -46,9 +51,29 @@ var runtimeGlobalContext = function(param) {
|
|
|
46
51
|
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, metaName = param.metaName, entry = param.entry, customEntry = param.customEntry;
|
|
47
52
|
return "import { setGlobalContext } from '@".concat(metaName, "/runtime/context'\n\nimport App from '").concat(formatImportPath(customEntry ? entry.replace(/entry\.[tj]sx/, "App").replace(srcDirectory, internalSrcAlias) : entry.replace(srcDirectory, internalSrcAlias).replace(/\.[tj]sx/, "")), "';\n\nsetGlobalContext({\n App,\n});");
|
|
48
53
|
};
|
|
54
|
+
var runtimeGlobalContextForRSCServer = function(param) {
|
|
55
|
+
var metaName = param.metaName;
|
|
56
|
+
return "\n import { createElement, Fragment } from 'react';\n import { setGlobalContext } from '@".concat(metaName, "/runtime/context';\n import AppProxy from './AppProxy';\n\n const DefaultRoot = ({ children }: { children?: ReactNode }) =>\n createElement(Fragment, null, children);\n\n\n setGlobalContext({\n App: DefaultRoot,\n RSCRoot: AppProxy,\n });");
|
|
57
|
+
};
|
|
58
|
+
var runtimeGlobalContextForRSCClient = function(param) {
|
|
59
|
+
var metaName = param.metaName;
|
|
60
|
+
return "\n import { createElement, Fragment } from 'react';\n import { setGlobalContext } from '@".concat(metaName, "/runtime/context';\n\n const DefaultRoot = ({ children }: { children?: ReactNode }) =>\n createElement(Fragment, null, children);\n\n setGlobalContext({\n App: DefaultRoot\n });");
|
|
61
|
+
};
|
|
62
|
+
var AppProxyForRSC = function(param) {
|
|
63
|
+
var srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, entry = param.entry, customEntry = param.customEntry;
|
|
64
|
+
return "\n import App from '".concat(
|
|
65
|
+
// We need to get the path of App.tsx here, but the entry is `src/entry.tsx`
|
|
66
|
+
formatImportPath(customEntry ? entry.replace(/entry\.[tj]sx/, "App").replace(srcDirectory, internalSrcAlias) : entry.replace(srcDirectory, internalSrcAlias).replace(".tsx", "")),
|
|
67
|
+
"';\n import React from 'react';\n\n export default function Root() {\n return React.createElement(App, null);\n }\n "
|
|
68
|
+
);
|
|
69
|
+
};
|
|
49
70
|
export {
|
|
71
|
+
AppProxyForRSC,
|
|
72
|
+
entryForCSRWithRSC,
|
|
50
73
|
index,
|
|
51
74
|
register,
|
|
52
75
|
runtimeGlobalContext,
|
|
76
|
+
runtimeGlobalContextForRSCClient,
|
|
77
|
+
runtimeGlobalContextForRSCServer,
|
|
53
78
|
runtimeRegister
|
|
54
79
|
};
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { formatImportPath } from "@modern-js/utils";
|
|
2
2
|
var SERVER_ENTRY = "\nimport {\n #render,\n createRequestHandler,\n} from '@#metaName/runtime/ssr/server';\n\nconst handleRequest = async (request, ServerRoot, options) => {\n\n const body = await #render(request, <ServerRoot />, options);\n\n return new Response(body, {\n headers: {\n 'content-type': 'text/html; charset=utf-8',\n #headers\n },\n })\n};\n\nexport const requestHandler = createRequestHandler(handleRequest);\n";
|
|
3
|
+
var SERVER_ENTRY_RSC = "\nimport {\n renderStreaming,\n createRequestHandler,\n} from '@#metaName/runtime/ssr/server';\nimport { RSCServerSlot } from '@#metaName/runtime/rsc/client';\nexport { handleAction } from '@#metaName/runtime/rsc/server';\n\nconst handleRequest = async (request, ServerRoot, options) => {\n\n const body = await renderStreaming(request,\n <ServerRoot>\n <RSCServerSlot />\n </ServerRoot>,\n {\n ...options,\n rscRoot: <options.RSCRoot />,\n },\n );\n\n return new Response(body, {\n headers: {\n 'content-type': 'text/html; charset=utf-8',\n #headers\n },\n })\n};\n\nexport const requestHandler = createRequestHandler(handleRequest, {\n enableRsc: true,\n});\n";
|
|
3
4
|
var serverIndex = function(options) {
|
|
4
5
|
var _options_metaName = options.metaName, metaName = _options_metaName === void 0 ? "modern-js" : _options_metaName, entryName = options.entryName;
|
|
5
6
|
return "\n import '@".concat(metaName, "/runtime/registry/").concat(entryName, "';\n ").concat(genHandlerCode(options), "\n ");
|
|
6
7
|
};
|
|
8
|
+
var entryForCSRWithRSC = function(param) {
|
|
9
|
+
var metaName = param.metaName;
|
|
10
|
+
return "\n import App from './AppProxy';\n import { renderRsc } from '@".concat(metaName, "/runtime/rsc/server'\n export { handleAction } from '@").concat(metaName, "/runtime/rsc/server';\n\n\n export const rscRequestHandler = ({\n clientManifest\n }) => {\n const stream = renderRsc({\n element: <App/>,\n clientManifest,\n })\n\n const response = new Response(stream, {\n headers: {\n 'Transfer-Encoding': 'chunked',\n },\n });\n return response\n }\n");
|
|
11
|
+
};
|
|
7
12
|
function genHandlerCode(param) {
|
|
8
|
-
var mode = param.mode, metaName = param.metaName, customServerEntry = param.customServerEntry, srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias;
|
|
13
|
+
var mode = param.mode, metaName = param.metaName, customServerEntry = param.customServerEntry, srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias, enableRsc = param.enableRsc;
|
|
9
14
|
if (customServerEntry) {
|
|
10
|
-
|
|
15
|
+
var realEntryPath = formatImportPath(customServerEntry.replace(srcDirectory, internalSrcAlias));
|
|
16
|
+
return "\n export * from '".concat(realEntryPath, "';\n export { default as requestHandler } from '").concat(realEntryPath, "'");
|
|
11
17
|
} else {
|
|
12
|
-
var
|
|
18
|
+
var entrySource = enableRsc ? SERVER_ENTRY_RSC : SERVER_ENTRY;
|
|
19
|
+
var serverEntry = transformServerEntry(entrySource, {
|
|
13
20
|
metaName: metaName || "modern-js",
|
|
14
21
|
mode
|
|
15
22
|
});
|
|
@@ -22,5 +29,6 @@ function transformServerEntry(source, options) {
|
|
|
22
29
|
return output;
|
|
23
30
|
}
|
|
24
31
|
export {
|
|
32
|
+
entryForCSRWithRSC,
|
|
25
33
|
serverIndex
|
|
26
34
|
};
|
|
@@ -6,6 +6,10 @@ function setGlobalContext(context) {
|
|
|
6
6
|
globalContext.appInit = context.appInit;
|
|
7
7
|
globalContext.appConfig = typeof context.appConfig === "function" ? context.appConfig() : context.appConfig;
|
|
8
8
|
globalContext.layoutApp = context.layoutApp;
|
|
9
|
+
globalContext.RSCRoot = context.RSCRoot;
|
|
10
|
+
}
|
|
11
|
+
function getGlobalRSCRoot() {
|
|
12
|
+
return globalContext.RSCRoot;
|
|
9
13
|
}
|
|
10
14
|
function setGlobalInternalRuntimeContext(context) {
|
|
11
15
|
globalContext.internalRuntimeContext = context;
|
|
@@ -37,6 +41,7 @@ export {
|
|
|
37
41
|
getGlobalAppInit,
|
|
38
42
|
getGlobalInternalRuntimeContext,
|
|
39
43
|
getGlobalLayoutApp,
|
|
44
|
+
getGlobalRSCRoot,
|
|
40
45
|
getGlobalRoutes,
|
|
41
46
|
getInitialContext,
|
|
42
47
|
setGlobalContext,
|