@modern-js/runtime 3.0.0-alpha.1 → 3.0.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/cli/ssr/index.js +109 -124
- package/dist/cjs/cli/ssr/loadable-bundler-plugin.js +21 -4
- package/dist/cjs/core/browser/index.js +2 -1
- package/dist/cjs/core/compat/requestContext.js +1 -0
- package/dist/cjs/core/context/runtime.js +10 -6
- package/dist/cjs/core/server/stream/createReadableStream.js +2 -15
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +3 -14
- package/dist/cjs/core/server/stream/shared.js +47 -1
- package/dist/cjs/document/cli/index.js +61 -38
- package/dist/cjs/router/runtime/PrefetchLink.js +1 -4
- package/dist/esm/cli/alias.mjs +1 -1
- package/dist/esm/cli/code.mjs +3 -3
- package/dist/esm/cli/entry.mjs +1 -1
- package/dist/esm/cli/index.mjs +7 -7
- package/dist/esm/cli/ssr/index.mjs +3 -19
- package/dist/esm/cli/ssr/loadable-bundler-plugin.mjs +2 -1
- package/dist/esm/cli/template.mjs +1 -1
- package/dist/esm/core/browser/hydrate.mjs +3 -3
- package/dist/esm/core/browser/index.mjs +6 -5
- package/dist/esm/core/compat/index.mjs +1 -1
- package/dist/esm/core/compat/requestContext.mjs +1 -0
- package/dist/esm/core/context/index.mjs +2 -2
- package/dist/esm/core/context/monitors/index.mjs +1 -1
- package/dist/esm/core/context/monitors/index.server.mjs +1 -1
- package/dist/esm/core/context/runtime.mjs +10 -6
- package/dist/esm/core/index.mjs +2 -2
- package/dist/esm/core/plugin/index.mjs +4 -4
- package/dist/esm/core/react/index.mjs +3 -3
- package/dist/esm/core/react/wrapper.mjs +1 -1
- package/dist/esm/core/server/helmet.mjs +1 -1
- package/dist/esm/core/server/index.mjs +1 -1
- package/dist/esm/core/server/react/index.mjs +2 -2
- package/dist/esm/core/server/react/no-ssr-cache/index.mjs +1 -1
- package/dist/esm/core/server/requestHandler.mjs +7 -7
- package/dist/esm/core/server/server.mjs +3 -3
- package/dist/esm/core/server/stream/afterTemplate.mjs +4 -4
- package/dist/esm/core/server/stream/beforeTemplate.mjs +4 -4
- package/dist/esm/core/server/stream/createReadableStream.mjs +11 -14
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +8 -9
- package/dist/esm/core/server/stream/deferredScript.mjs +1 -1
- package/dist/esm/core/server/stream/index.mjs +2 -2
- package/dist/esm/core/server/stream/shared.mjs +38 -5
- package/dist/esm/core/server/stream/template.mjs +2 -2
- package/dist/esm/core/server/string/index.mjs +10 -10
- package/dist/esm/core/server/string/loadable.mjs +1 -1
- package/dist/esm/core/server/string/ssrData.mjs +2 -2
- package/dist/esm/document/Body.mjs +3 -3
- package/dist/esm/document/Comment.mjs +1 -1
- package/dist/esm/document/Head.mjs +5 -5
- package/dist/esm/document/Html.mjs +3 -3
- package/dist/esm/document/Links.mjs +1 -1
- package/dist/esm/document/Root.mjs +2 -2
- package/dist/esm/document/Script.mjs +1 -1
- package/dist/esm/document/Scripts.mjs +1 -1
- package/dist/esm/document/Style.mjs +1 -1
- package/dist/esm/document/Title.mjs +1 -1
- package/dist/esm/document/cli/index.mjs +63 -40
- package/dist/esm/document/index.mjs +12 -12
- package/dist/esm/index.mjs +5 -5
- package/dist/esm/internal.mjs +1 -1
- package/dist/esm/react-server.mjs +3 -3
- package/dist/esm/router/cli/code/getClientRoutes/getRoutes.mjs +4 -4
- package/dist/esm/router/cli/code/getClientRoutes/index.mjs +1 -1
- package/dist/esm/router/cli/code/getClientRoutes/utils.mjs +1 -1
- package/dist/esm/router/cli/code/index.mjs +9 -9
- package/dist/esm/router/cli/code/inspect.mjs +2 -2
- package/dist/esm/router/cli/code/nestedRoutes.mjs +2 -2
- package/dist/esm/router/cli/code/templates.mjs +2 -2
- package/dist/esm/router/cli/code/utils.mjs +1 -1
- package/dist/esm/router/cli/config-routes/converter.mjs +2 -2
- package/dist/esm/router/cli/entry.mjs +2 -2
- package/dist/esm/router/cli/handler.mjs +5 -5
- package/dist/esm/router/cli/index.mjs +3 -3
- package/dist/esm/router/index.mjs +1 -1
- package/dist/esm/router/internal.mjs +2 -2
- package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +3 -3
- package/dist/esm/router/runtime/PrefetchLink.mjs +2 -5
- package/dist/esm/router/runtime/constants.mjs +1 -1
- package/dist/esm/router/runtime/index.mjs +2 -2
- package/dist/esm/router/runtime/internal.mjs +2 -2
- package/dist/esm/router/runtime/plugin.mjs +4 -4
- package/dist/esm/router/runtime/plugin.node.mjs +4 -4
- package/dist/esm/router/runtime/utils.mjs +2 -2
- package/dist/esm-node/cache/index.mjs +1 -0
- package/dist/esm-node/cli/alias.mjs +1 -0
- package/dist/esm-node/cli/code.mjs +1 -0
- package/dist/esm-node/cli/constants.mjs +1 -0
- package/dist/esm-node/cli/entry.mjs +1 -0
- package/dist/esm-node/cli/index.mjs +2 -0
- package/dist/esm-node/cli/ssr/index.mjs +4 -18
- package/dist/esm-node/cli/ssr/loadable-bundler-plugin.mjs +3 -1
- package/dist/esm-node/cli/ssr/mode.mjs +1 -0
- package/dist/esm-node/cli/template.mjs +1 -0
- package/dist/esm-node/cli/template.server.mjs +1 -0
- package/dist/esm-node/common.mjs +1 -0
- package/dist/esm-node/core/browser/hydrate.mjs +1 -0
- package/dist/esm-node/core/browser/index.mjs +3 -1
- package/dist/esm-node/core/browser/withCallback.mjs +1 -0
- package/dist/esm-node/core/compat/hooks.mjs +1 -0
- package/dist/esm-node/core/compat/index.mjs +1 -0
- package/dist/esm-node/core/compat/requestContext.mjs +2 -0
- package/dist/esm-node/core/config.mjs +1 -0
- package/dist/esm-node/core/constants.mjs +1 -0
- package/dist/esm-node/core/context/index.mjs +1 -0
- package/dist/esm-node/core/context/monitors/default.mjs +1 -0
- package/dist/esm-node/core/context/monitors/index.mjs +1 -0
- package/dist/esm-node/core/context/monitors/index.server.mjs +1 -0
- package/dist/esm-node/core/context/request/index.mjs +1 -0
- package/dist/esm-node/core/context/request/index.server.mjs +1 -0
- package/dist/esm-node/core/context/response/index.mjs +1 -0
- package/dist/esm-node/core/context/response/index.server.mjs +1 -0
- package/dist/esm-node/core/context/runtime.mjs +11 -6
- package/dist/esm-node/core/context/serverPayload/index.mjs +1 -0
- package/dist/esm-node/core/context/serverPayload/index.server.mjs +1 -0
- package/dist/esm-node/core/index.mjs +1 -0
- package/dist/esm-node/core/plugin/index.mjs +1 -0
- package/dist/esm-node/core/plugin/types.mjs +1 -0
- package/dist/esm-node/core/react/index.mjs +1 -0
- package/dist/esm-node/core/react/wrapper.mjs +1 -0
- package/dist/esm-node/core/server/constants.mjs +1 -0
- package/dist/esm-node/core/server/helmet.mjs +1 -0
- package/dist/esm-node/core/server/index.mjs +1 -0
- package/dist/esm-node/core/server/react/index.mjs +1 -0
- package/dist/esm-node/core/server/react/no-ssr-cache/index.mjs +1 -0
- package/dist/esm-node/core/server/react/nossr/index.mjs +1 -0
- package/dist/esm-node/core/server/requestHandler.mjs +1 -0
- package/dist/esm-node/core/server/server.mjs +1 -0
- package/dist/esm-node/core/server/shared.mjs +1 -0
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +1 -0
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +5 -1
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +6 -8
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +5 -5
- package/dist/esm-node/core/server/stream/deferredScript.mjs +1 -0
- package/dist/esm-node/core/server/stream/index.mjs +1 -0
- package/dist/esm-node/core/server/stream/shared.mjs +35 -1
- package/dist/esm-node/core/server/stream/template.mjs +1 -0
- package/dist/esm-node/core/server/string/index.mjs +1 -0
- package/dist/esm-node/core/server/string/loadable.mjs +5 -1
- package/dist/esm-node/core/server/string/ssrData.mjs +1 -0
- package/dist/esm-node/core/server/string/types.mjs +1 -0
- package/dist/esm-node/core/server/tracer.mjs +1 -0
- package/dist/esm-node/core/server/utils.mjs +1 -0
- package/dist/esm-node/core/types.mjs +1 -0
- package/dist/esm-node/document/Body.mjs +1 -0
- package/dist/esm-node/document/Comment.mjs +1 -0
- package/dist/esm-node/document/DocumentContext.mjs +1 -0
- package/dist/esm-node/document/DocumentStructureContext.mjs +1 -0
- package/dist/esm-node/document/Head.mjs +1 -0
- package/dist/esm-node/document/Html.mjs +1 -0
- package/dist/esm-node/document/Links.mjs +1 -0
- package/dist/esm-node/document/Root.mjs +1 -0
- package/dist/esm-node/document/Script.mjs +1 -0
- package/dist/esm-node/document/Scripts.mjs +1 -0
- package/dist/esm-node/document/Style.mjs +1 -0
- package/dist/esm-node/document/Title.mjs +1 -0
- package/dist/esm-node/document/cli/index.mjs +64 -39
- package/dist/esm-node/document/constants.mjs +1 -0
- package/dist/esm-node/document/index.mjs +1 -0
- package/dist/esm-node/exports/config-routes.mjs +1 -0
- package/dist/esm-node/exports/head.mjs +1 -0
- package/dist/esm-node/exports/loadable.mjs +1 -0
- package/dist/esm-node/index.mjs +1 -0
- package/dist/esm-node/internal.mjs +1 -0
- package/dist/esm-node/react-server.mjs +1 -0
- package/dist/esm-node/router/cli/code/getClientRoutes/getRoutes.mjs +1 -0
- package/dist/esm-node/router/cli/code/getClientRoutes/index.mjs +1 -0
- package/dist/esm-node/router/cli/code/getClientRoutes/utils.mjs +1 -0
- package/dist/esm-node/router/cli/code/index.mjs +1 -0
- package/dist/esm-node/router/cli/code/inspect.mjs +1 -0
- package/dist/esm-node/router/cli/code/makeLegalIdentifier.mjs +1 -0
- package/dist/esm-node/router/cli/code/nestedRoutes.mjs +1 -0
- package/dist/esm-node/router/cli/code/templates.mjs +2 -0
- package/dist/esm-node/router/cli/code/utils.mjs +1 -0
- package/dist/esm-node/router/cli/config-routes/converter.mjs +1 -0
- package/dist/esm-node/router/cli/config-routes/parseRouteConfig.mjs +1 -0
- package/dist/esm-node/router/cli/constants.mjs +1 -0
- package/dist/esm-node/router/cli/entry.mjs +1 -0
- package/dist/esm-node/router/cli/handler.mjs +1 -0
- package/dist/esm-node/router/cli/index.mjs +5 -1
- package/dist/esm-node/router/index.mjs +1 -0
- package/dist/esm-node/router/internal.mjs +1 -0
- package/dist/esm-node/router/runtime/DefaultNotFound.mjs +1 -0
- package/dist/esm-node/router/runtime/DeferredDataScripts.mjs +1 -0
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +1 -0
- package/dist/esm-node/router/runtime/PrefetchLink.mjs +2 -4
- package/dist/esm-node/router/runtime/constants.mjs +1 -0
- package/dist/esm-node/router/runtime/hooks.mjs +1 -0
- package/dist/esm-node/router/runtime/index.mjs +1 -0
- package/dist/esm-node/router/runtime/internal.mjs +1 -0
- package/dist/esm-node/router/runtime/plugin.mjs +1 -0
- package/dist/esm-node/router/runtime/plugin.node.mjs +1 -0
- package/dist/esm-node/router/runtime/routerHelper.mjs +1 -0
- package/dist/esm-node/router/runtime/rsc-router.mjs +1 -0
- package/dist/esm-node/router/runtime/rsc.mjs +1 -0
- package/dist/esm-node/router/runtime/server.mjs +1 -0
- package/dist/esm-node/router/runtime/types.mjs +1 -0
- package/dist/esm-node/router/runtime/utils.mjs +1 -0
- package/dist/esm-node/router/runtime/withRouter.mjs +1 -0
- package/dist/esm-node/rsc/client.mjs +1 -0
- package/dist/esm-node/rsc/server.mjs +1 -0
- package/dist/types/cli/ssr/loadable-bundler-plugin.d.ts +22 -1
- package/dist/types/core/context/runtime.d.ts +4 -0
- package/dist/types/core/server/stream/shared.d.ts +4 -0
- package/package.json +31 -59
- package/rstest.config.ts +83 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { renderSSRStream } from "@modern-js/render/ssr";
|
|
2
2
|
import { storage } from "@modern-js/runtime-utils/node";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { getTemplates } from "./template";
|
|
3
|
+
import { ESCAPED_SHELL_STREAM_END_MARK } from "../../../common.mjs";
|
|
4
|
+
import { RenderLevel } from "../../constants.mjs";
|
|
5
|
+
import { enqueueFromEntries } from "./deferredScript.mjs";
|
|
6
|
+
import { ShellChunkStatus, encodeForWebStream, getReadableStreamFromString, resolveStreamingMode } from "./shared.mjs";
|
|
7
|
+
import { getTemplates } from "./template.mjs";
|
|
9
8
|
const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
10
9
|
let shellChunkStatus = ShellChunkStatus.START;
|
|
11
10
|
const chunkVec = [];
|
|
@@ -33,9 +32,9 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
33
32
|
readableOriginal.allReady.then(()=>{
|
|
34
33
|
options?.onAllReady?.();
|
|
35
34
|
});
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
35
|
+
const forceStreamToString = Boolean("u" > typeof process && process.env?.MODERN_JS_STREAM_TO_STRING);
|
|
36
|
+
const { waitForAllReady } = resolveStreamingMode(request, forceStreamToString);
|
|
37
|
+
if (waitForAllReady) await readableOriginal.allReady;
|
|
39
38
|
const reader = readableOriginal.getReader();
|
|
40
39
|
const stream = new ReadableStream({
|
|
41
40
|
start (controller) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRenderStreaming } from "./shared";
|
|
2
|
-
const createReadableStreamFromElement = 'edge' === process.env.MODERN_SSR_ENV ? import("./createReadableStream.worker.mjs").then((m)=>m.createReadableStreamFromElement) : import("./createReadableStream").then((m)=>m.createReadableStreamFromElement);
|
|
1
|
+
import { createRenderStreaming } from "./shared.mjs";
|
|
2
|
+
const createReadableStreamFromElement = 'edge' === process.env.MODERN_SSR_ENV ? import("./createReadableStream.worker.mjs").then((m)=>m.createReadableStreamFromElement) : import("./createReadableStream.mjs").then((m)=>m.createReadableStreamFromElement);
|
|
3
3
|
const renderStreaming = createRenderStreaming(createReadableStreamFromElement);
|
|
4
4
|
export { renderStreaming };
|
|
@@ -1,14 +1,47 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { time } from "@modern-js/runtime-utils/time";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import isbot from "isbot";
|
|
4
|
+
import { JSX_SHELL_STREAM_END_MARK } from "../../../common.mjs";
|
|
5
|
+
import { wrapRuntimeContextProvider } from "../../react/wrapper.mjs";
|
|
6
|
+
import { SSRErrors, SSRTimings } from "../tracer.mjs";
|
|
7
|
+
import { getSSRConfigByEntry } from "../utils.mjs";
|
|
7
8
|
var shared_ShellChunkStatus = /*#__PURE__*/ function(ShellChunkStatus) {
|
|
8
9
|
ShellChunkStatus[ShellChunkStatus["START"] = 0] = "START";
|
|
9
10
|
ShellChunkStatus[ShellChunkStatus["FINISH"] = 1] = "FINISH";
|
|
10
11
|
return ShellChunkStatus;
|
|
11
12
|
}({});
|
|
13
|
+
const SHOULD_STREAM_ALL_HEADER = 'x-should-stream-all';
|
|
14
|
+
function parseShouldStreamAllFlag(value) {
|
|
15
|
+
if (!value) return;
|
|
16
|
+
const normalized = value.trim().toLowerCase();
|
|
17
|
+
if ('false' === normalized) return false;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
function resolveStreamingMode(request, forceStreamToString) {
|
|
21
|
+
const shouldStreamAll = parseShouldStreamAllFlag(request.headers.get(SHOULD_STREAM_ALL_HEADER));
|
|
22
|
+
const isSsgRender = 'true' === request.headers.get('x-modern-ssg-render');
|
|
23
|
+
const isBot = isbot(request.headers.get('user-agent'));
|
|
24
|
+
if (shouldStreamAll) return {
|
|
25
|
+
onReady: 'onAllReady',
|
|
26
|
+
waitForAllReady: true
|
|
27
|
+
};
|
|
28
|
+
if (forceStreamToString) return {
|
|
29
|
+
onReady: 'onAllReady',
|
|
30
|
+
waitForAllReady: true
|
|
31
|
+
};
|
|
32
|
+
if (isBot) return {
|
|
33
|
+
onReady: 'onAllReady',
|
|
34
|
+
waitForAllReady: true
|
|
35
|
+
};
|
|
36
|
+
if (isSsgRender) return {
|
|
37
|
+
onReady: 'onAllReady',
|
|
38
|
+
waitForAllReady: true
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
onReady: 'onShellReady',
|
|
42
|
+
waitForAllReady: false
|
|
43
|
+
};
|
|
44
|
+
}
|
|
12
45
|
let encoder;
|
|
13
46
|
function encodeForWebStream(thing) {
|
|
14
47
|
if (!encoder) encoder = new TextEncoder();
|
|
@@ -72,4 +105,4 @@ function createRenderStreaming(createReadableStreamPromise) {
|
|
|
72
105
|
return stream;
|
|
73
106
|
};
|
|
74
107
|
}
|
|
75
|
-
export { shared_ShellChunkStatus as ShellChunkStatus, createRenderStreaming, encodeForWebStream, getReadableStreamFromString };
|
|
108
|
+
export { shared_ShellChunkStatus as ShellChunkStatus, createRenderStreaming, encodeForWebStream, getReadableStreamFromString, resolveStreamingMode };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { buildShellAfterTemplate } from "./afterTemplate";
|
|
2
|
-
import { buildShellBeforeTemplate } from "./beforeTemplate";
|
|
1
|
+
import { buildShellAfterTemplate } from "./afterTemplate.mjs";
|
|
2
|
+
import { buildShellBeforeTemplate } from "./beforeTemplate.mjs";
|
|
3
3
|
const HTML_SEPARATOR = '<!--<?- html ?>-->';
|
|
4
4
|
const getTemplates = async (htmlTemplate, options)=>{
|
|
5
5
|
const [beforeAppTemplate = '', afterAppHtmlTemplate = ''] = htmlTemplate.split(HTML_SEPARATOR) || [];
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { time } from "@modern-js/runtime-utils/time";
|
|
2
2
|
import server from "react-dom/server";
|
|
3
3
|
import react_helmet from "react-helmet";
|
|
4
|
-
import { RenderLevel } from "../../constants";
|
|
5
|
-
import { getGlobalInternalRuntimeContext } from "../../context";
|
|
6
|
-
import { wrapRuntimeContextProvider } from "../../react/wrapper";
|
|
7
|
-
import { CHUNK_CSS_PLACEHOLDER, CHUNK_JS_PLACEHOLDER, HTML_PLACEHOLDER, SSR_DATA_PLACEHOLDER } from "../constants";
|
|
8
|
-
import { createReplaceHelemt } from "../helmet";
|
|
9
|
-
import { buildHtml } from "../shared";
|
|
10
|
-
import { SSRErrors, SSRTimings } from "../tracer";
|
|
11
|
-
import { getSSRConfigByEntry, safeReplace } from "../utils";
|
|
12
|
-
import { LoadableCollector } from "./loadable";
|
|
13
|
-
import { SSRDataCollector } from "./ssrData";
|
|
4
|
+
import { RenderLevel } from "../../constants.mjs";
|
|
5
|
+
import { getGlobalInternalRuntimeContext } from "../../context/index.mjs";
|
|
6
|
+
import { wrapRuntimeContextProvider } from "../../react/wrapper.mjs";
|
|
7
|
+
import { CHUNK_CSS_PLACEHOLDER, CHUNK_JS_PLACEHOLDER, HTML_PLACEHOLDER, SSR_DATA_PLACEHOLDER } from "../constants.mjs";
|
|
8
|
+
import { createReplaceHelemt } from "../helmet.mjs";
|
|
9
|
+
import { buildHtml } from "../shared.mjs";
|
|
10
|
+
import { SSRErrors, SSRTimings } from "../tracer.mjs";
|
|
11
|
+
import { getSSRConfigByEntry, safeReplace } from "../utils.mjs";
|
|
12
|
+
import { LoadableCollector } from "./loadable.mjs";
|
|
13
|
+
import { SSRDataCollector } from "./ssrData.mjs";
|
|
14
14
|
const renderString = async (request, serverRoot, options)=>{
|
|
15
15
|
const { resource, runtimeContext, config, onError, onTiming } = options;
|
|
16
16
|
const tracer = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChunkExtractor } from "@loadable/server";
|
|
2
|
-
import { attributesToString, checkIsNode } from "../utils";
|
|
2
|
+
import { attributesToString, checkIsNode } from "../utils.mjs";
|
|
3
3
|
const extname = (uri)=>{
|
|
4
4
|
if ('string' != typeof uri || !uri.includes('.')) return '';
|
|
5
5
|
return `.${uri?.split('.').pop()}` || '';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
2
|
-
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../../constants";
|
|
3
|
-
import { attributesToString, serializeErrors } from "../utils";
|
|
2
|
+
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../../constants.mjs";
|
|
3
|
+
import { attributesToString, serializeErrors } from "../utils.mjs";
|
|
4
4
|
function _check_private_redeclaration(obj, privateCollection) {
|
|
5
5
|
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
6
6
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
-
import { DocumentStructureContext } from "./DocumentStructureContext";
|
|
4
|
-
import { DefaultRoot } from "./Root";
|
|
5
|
-
import { BODY_PARTICALS_SEPARATOR, DOCUMENT_CHUNKSMAP_PLACEHOLDER, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER } from "./constants";
|
|
3
|
+
import { DocumentStructureContext } from "./DocumentStructureContext.mjs";
|
|
4
|
+
import { DefaultRoot } from "./Root.mjs";
|
|
5
|
+
import { BODY_PARTICALS_SEPARATOR, DOCUMENT_CHUNKSMAP_PLACEHOLDER, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER } from "./constants.mjs";
|
|
6
6
|
function Body(props) {
|
|
7
7
|
const { hasSetRoot } = useContext(DocumentStructureContext);
|
|
8
8
|
const { children, ...rest } = props;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { DOCUMENT_COMMENT_PLACEHOLDER_END, DOCUMENT_COMMENT_PLACEHOLDER_START } from "./constants";
|
|
3
|
+
import { DOCUMENT_COMMENT_PLACEHOLDER_END, DOCUMENT_COMMENT_PLACEHOLDER_START } from "./constants.mjs";
|
|
4
4
|
function Comment(props) {
|
|
5
5
|
const { comment, children } = props;
|
|
6
6
|
const commentStr = encodeURIComponent(children || comment || '');
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
|
-
import { DocumentStructureContext } from "./DocumentStructureContext";
|
|
4
|
-
import { Links } from "./Links";
|
|
5
|
-
import { Scripts } from "./Scripts";
|
|
6
|
-
import { Title } from "./Title";
|
|
7
|
-
import { DOCUMENT_META_PLACEHOLDER, HEAD_PARTICALS_SEPARATOR, TOP_PARTICALS_SEPARATOR } from "./constants";
|
|
3
|
+
import { DocumentStructureContext } from "./DocumentStructureContext.mjs";
|
|
4
|
+
import { Links } from "./Links.mjs";
|
|
5
|
+
import { Scripts } from "./Scripts.mjs";
|
|
6
|
+
import { Title } from "./Title.mjs";
|
|
7
|
+
import { DOCUMENT_META_PLACEHOLDER, HEAD_PARTICALS_SEPARATOR, TOP_PARTICALS_SEPARATOR } from "./constants.mjs";
|
|
8
8
|
function Head(props) {
|
|
9
9
|
const { hasSetScripts, hasSetLinks, hasSetTitle } = useContext(DocumentStructureContext);
|
|
10
10
|
const { children, ...rest } = props;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { Body } from "./Body";
|
|
4
|
-
import { DocumentStructureContext } from "./DocumentStructureContext";
|
|
5
|
-
import { Head } from "./Head";
|
|
3
|
+
import { Body } from "./Body.mjs";
|
|
4
|
+
import { DocumentStructureContext } from "./DocumentStructureContext.mjs";
|
|
5
|
+
import { Head } from "./Head.mjs";
|
|
6
6
|
function findTargetChildByName(tag, children) {
|
|
7
7
|
return children.find((item)=>getEleType(item) === tag);
|
|
8
8
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { DOCUMENT_LINKS_PLACEHOLDER } from "./constants";
|
|
3
|
+
import { DOCUMENT_LINKS_PLACEHOLDER } from "./constants.mjs";
|
|
4
4
|
function Links() {
|
|
5
5
|
return /*#__PURE__*/ jsx(Fragment, {
|
|
6
6
|
children: DOCUMENT_LINKS_PLACEHOLDER
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { omit } from "@modern-js/utils/lodash";
|
|
3
3
|
import { useContext } from "react";
|
|
4
|
-
import { DocumentContext } from "./DocumentContext";
|
|
5
|
-
import { DOCUMENT_SSR_PLACEHOLDER } from "./constants";
|
|
4
|
+
import { DocumentContext } from "./DocumentContext.mjs";
|
|
5
|
+
import { DOCUMENT_SSR_PLACEHOLDER } from "./constants.mjs";
|
|
6
6
|
function Root(props) {
|
|
7
7
|
const { rootId, children, ...rest } = props;
|
|
8
8
|
const legalProperties = omit(rest, 'id');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { renderToString } from "react-dom/server";
|
|
3
|
-
import { DOCUMENT_SCRIPT_ATTRIBUTES_END, DOCUMENT_SCRIPT_ATTRIBUTES_START, DOCUMENT_SCRIPT_PLACEHOLDER_END, DOCUMENT_SCRIPT_PLACEHOLDER_START } from "./constants";
|
|
3
|
+
import { DOCUMENT_SCRIPT_ATTRIBUTES_END, DOCUMENT_SCRIPT_ATTRIBUTES_START, DOCUMENT_SCRIPT_PLACEHOLDER_END, DOCUMENT_SCRIPT_PLACEHOLDER_START } from "./constants.mjs";
|
|
4
4
|
function Script(props) {
|
|
5
5
|
const { content, ...rests } = props;
|
|
6
6
|
const contentStr = content?.toString();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { DOCUMENT_SCRIPTS_PLACEHOLDER } from "./constants";
|
|
3
|
+
import { DOCUMENT_SCRIPTS_PLACEHOLDER } from "./constants.mjs";
|
|
4
4
|
function Scripts() {
|
|
5
5
|
return /*#__PURE__*/ jsx(Fragment, {
|
|
6
6
|
children: `${DOCUMENT_SCRIPTS_PLACEHOLDER}`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { DOCUMENT_STYLE_PLACEHOLDER_END, DOCUMENT_STYLE_PLACEHOLDER_START } from "./constants";
|
|
3
|
+
import { DOCUMENT_STYLE_PLACEHOLDER_END, DOCUMENT_STYLE_PLACEHOLDER_START } from "./constants.mjs";
|
|
4
4
|
function Style(props) {
|
|
5
5
|
const { content, children } = props;
|
|
6
6
|
const contentStr = children || content;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import module_0, { builtinModules } from "module";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { createDebugger, findExists, fs } from "@modern-js/utils";
|
|
3
|
+
import { createDebugger, findExists, fs, logger } from "@modern-js/utils";
|
|
4
4
|
import { decodeHTML } from "entities";
|
|
5
|
-
import { BODY_PARTICALS_SEPARATOR, DOCUMENT_CHUNKSMAP_PLACEHOLDER, DOCUMENT_COMMENT_PLACEHOLDER_END, DOCUMENT_COMMENT_PLACEHOLDER_START, DOCUMENT_FILE_NAME, DOCUMENT_LINKS_PLACEHOLDER, DOCUMENT_META_PLACEHOLDER, DOCUMENT_SCRIPTS_PLACEHOLDER, DOCUMENT_SCRIPT_ATTRIBUTES_END, DOCUMENT_SCRIPT_ATTRIBUTES_START, DOCUMENT_SCRIPT_PLACEHOLDER_END, DOCUMENT_SCRIPT_PLACEHOLDER_START, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER, DOCUMENT_SSR_PLACEHOLDER, DOCUMENT_STYLE_PLACEHOLDER_END, DOCUMENT_STYLE_PLACEHOLDER_START, DOCUMENT_TITLE_PLACEHOLDER, DOC_EXT, HEAD_PARTICALS_SEPARATOR, HTML_SEPARATOR, PLACEHOLDER_REPLACER_MAP, TOP_PARTICALS_SEPARATOR } from "../constants";
|
|
5
|
+
import { BODY_PARTICALS_SEPARATOR, DOCUMENT_CHUNKSMAP_PLACEHOLDER, DOCUMENT_COMMENT_PLACEHOLDER_END, DOCUMENT_COMMENT_PLACEHOLDER_START, DOCUMENT_FILE_NAME, DOCUMENT_LINKS_PLACEHOLDER, DOCUMENT_META_PLACEHOLDER, DOCUMENT_SCRIPTS_PLACEHOLDER, DOCUMENT_SCRIPT_ATTRIBUTES_END, DOCUMENT_SCRIPT_ATTRIBUTES_START, DOCUMENT_SCRIPT_PLACEHOLDER_END, DOCUMENT_SCRIPT_PLACEHOLDER_START, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER, DOCUMENT_SSR_PLACEHOLDER, DOCUMENT_STYLE_PLACEHOLDER_END, DOCUMENT_STYLE_PLACEHOLDER_START, DOCUMENT_TITLE_PLACEHOLDER, DOC_EXT, HEAD_PARTICALS_SEPARATOR, HTML_SEPARATOR, PLACEHOLDER_REPLACER_MAP, TOP_PARTICALS_SEPARATOR } from "../constants.mjs";
|
|
6
6
|
const debug = createDebugger('document');
|
|
7
7
|
const entryName2DocCode = new Map();
|
|
8
8
|
const CONSTANTS = {
|
|
@@ -96,12 +96,13 @@ const applyExternalsPlugin = (child, compiler)=>{
|
|
|
96
96
|
EXTERNAL_MAPPINGS
|
|
97
97
|
]).apply(child);
|
|
98
98
|
};
|
|
99
|
-
const generateEntryCode = (docPath, _entryName)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
const generateEntryCode = (docPath, _entryName)=>{
|
|
100
|
+
const runtimeAPI = require.resolve('../');
|
|
101
|
+
const esmRuntimeAPI = runtimeAPI.replace("cjs", "esm").replace(/.js$/, '.mjs');
|
|
102
|
+
return `import React from 'react';
|
|
103
|
+
import ReactDomServer from 'react-dom/server';
|
|
104
|
+
import Document from ${JSON.stringify(docPath)};
|
|
105
|
+
import { DocumentContext } from ${JSON.stringify(esmRuntimeAPI)};
|
|
105
106
|
|
|
106
107
|
// expose to global for host to consume
|
|
107
108
|
var g = (typeof globalThis !== 'undefined' ? globalThis : global);
|
|
@@ -118,7 +119,8 @@ function render(documentParams) {
|
|
|
118
119
|
|
|
119
120
|
g.__MODERN_DOC_RENDERERS__[${JSON.stringify(_entryName)}] = render;
|
|
120
121
|
|
|
121
|
-
|
|
122
|
+
export default { render: render };`;
|
|
123
|
+
};
|
|
122
124
|
const processChildCompilation = async (entryName, docPath, compilation, compiler, appDirectory, internalDirectory)=>new Promise((resolve, reject)=>{
|
|
123
125
|
const outFile = path.posix.join(CONSTANTS.DOCUMENT_OUTPUT_DIR, `${CONSTANTS.HTML_OUTPUT_PREFIX}${entryName}${CONSTANTS.HTML_OUTPUT_SUFFIX}`);
|
|
124
126
|
const child = compilation.createChildCompiler(`${CONSTANTS.CHILD_COMPILER_PREFIX}${entryName}`, {
|
|
@@ -139,31 +141,48 @@ const processChildCompilation = async (entryName, docPath, compilation, compiler
|
|
|
139
141
|
name: `${CONSTANTS.CHILD_COMPILER_PREFIX}${entryName}`
|
|
140
142
|
}).apply(child);
|
|
141
143
|
child.runAsChild((err, _entries, childCompilation)=>{
|
|
142
|
-
if (err)
|
|
144
|
+
if (err) {
|
|
145
|
+
logger.error(`Document child compiler failed for entry "${entryName}": ${err.message}`);
|
|
146
|
+
return reject(err);
|
|
147
|
+
}
|
|
143
148
|
try {
|
|
144
149
|
if (!childCompilation) throw new Error('Child compilation is undefined');
|
|
145
150
|
const asset = childCompilation.assets[outFile] || childCompilation.getAsset?.(outFile)?.source;
|
|
146
151
|
const code = 'function' == typeof asset?.source ? asset.source().toString() : 'string' == typeof asset ? asset : asset?.buffer?.().toString?.() || '';
|
|
147
|
-
if (code) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
if (!code) {
|
|
153
|
+
const errorMsg = `Document child compiler produced empty output for entry "${entryName}". Please check your Document component for syntax errors.`;
|
|
154
|
+
logger.error(errorMsg);
|
|
155
|
+
reject(new Error(errorMsg));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
entryName2DocCode.set(entryName, code);
|
|
159
|
+
debug('Document child compiler: cached injected bundle for %s', entryName);
|
|
151
160
|
resolve();
|
|
152
161
|
} catch (e) {
|
|
153
|
-
|
|
162
|
+
const err = e;
|
|
163
|
+
logger.error(`Document child compiler failed to process output for entry "${entryName}": ${err.message}`);
|
|
164
|
+
reject(err);
|
|
154
165
|
}
|
|
155
166
|
});
|
|
156
167
|
} catch (e) {
|
|
157
|
-
|
|
168
|
+
const err = e;
|
|
169
|
+
logger.error(`Document child compiler failed to initialize for entry "${entryName}": ${err.message}`);
|
|
170
|
+
reject(err);
|
|
158
171
|
}
|
|
159
172
|
};
|
|
160
173
|
try {
|
|
161
174
|
fs.ensureFile(tempEntry).then(()=>{
|
|
162
175
|
const entryCode = generateEntryCode(docPath, entryName);
|
|
163
176
|
return fs.writeFile(tempEntry, entryCode);
|
|
164
|
-
}).then(finalize).catch((e)=>
|
|
177
|
+
}).then(finalize).catch((e)=>{
|
|
178
|
+
const err = e;
|
|
179
|
+
logger.error(`Document child compiler failed to prepare entry file for "${entryName}": ${err.message}`);
|
|
180
|
+
reject(err);
|
|
181
|
+
});
|
|
165
182
|
} catch (e) {
|
|
166
|
-
|
|
183
|
+
const err = e;
|
|
184
|
+
logger.error(`Document child compiler failed to create entry directory for "${entryName}": ${err.message}`);
|
|
185
|
+
reject(err);
|
|
167
186
|
}
|
|
168
187
|
});
|
|
169
188
|
const documentPlugin = ()=>({
|
|
@@ -189,7 +208,10 @@ const documentPlugin = ()=>({
|
|
|
189
208
|
}
|
|
190
209
|
await Promise.all(tasks);
|
|
191
210
|
} catch (e) {
|
|
211
|
+
const err = e;
|
|
212
|
+
logger.error(`Document child compiler failed: ${err.message}`);
|
|
192
213
|
debug('Document child compiler make hook failed: %o', e);
|
|
214
|
+
throw err;
|
|
193
215
|
}
|
|
194
216
|
});
|
|
195
217
|
}
|
|
@@ -197,21 +219,13 @@ const documentPlugin = ()=>({
|
|
|
197
219
|
this.name = 'ModernJsDocumentChildCompilerPlugin';
|
|
198
220
|
}
|
|
199
221
|
}
|
|
200
|
-
api.config(()=>{
|
|
201
|
-
const documentPath = require.resolve('../');
|
|
202
|
-
return {
|
|
203
|
-
resolve: {
|
|
204
|
-
alias: {
|
|
205
|
-
'@meta/runtime/document$': documentPath.replace(`${path.sep}cjs${path.sep}`, `${path.sep}esm${path.sep}`).replace(/.js$/, '.mjs')
|
|
206
|
-
}
|
|
207
|
-
},
|
|
222
|
+
api.config(()=>({
|
|
208
223
|
tools: {
|
|
209
224
|
bundlerChain: (chain)=>{
|
|
210
225
|
chain.plugin('modernjs-document-child-compiler').use(ModernJsDocumentChildCompilerPlugin, []);
|
|
211
226
|
}
|
|
212
227
|
}
|
|
213
|
-
};
|
|
214
|
-
});
|
|
228
|
+
}));
|
|
215
229
|
const getDocParams = (params)=>{
|
|
216
230
|
const { config, templateParameters, entryName } = params;
|
|
217
231
|
return {
|
|
@@ -230,11 +244,13 @@ const documentPlugin = ()=>({
|
|
|
230
244
|
renderer: globalRenderer
|
|
231
245
|
};
|
|
232
246
|
const cached = entryName2DocCode.get(entryName);
|
|
233
|
-
if (!cached) throw new Error(`
|
|
247
|
+
if (!cached) throw new Error(`Document bundle not found for entry "${entryName}". The Document component compilation may have failed.`);
|
|
234
248
|
const filename = path.join(internalDirectory, `./${CONSTANTS.DOCUMENT_OUTPUT_DIR}/${CONSTANTS.HTML_OUTPUT_PREFIX}${entryName}${CONSTANTS.HTML_OUTPUT_SUFFIX}`);
|
|
235
249
|
requireFromString(cached, filename);
|
|
250
|
+
const renderer = renderers[entryName];
|
|
251
|
+
if (!renderer) throw new Error(`Document renderer not found for entry "${entryName}". Please ensure your Document component exports a valid default component.`);
|
|
236
252
|
return {
|
|
237
|
-
renderer
|
|
253
|
+
renderer
|
|
238
254
|
};
|
|
239
255
|
};
|
|
240
256
|
const processPartials = (html, entryName, partialsByEntrypoint)=>{
|
|
@@ -250,17 +266,17 @@ const documentPlugin = ()=>({
|
|
|
250
266
|
}
|
|
251
267
|
return html.replace(TOP_PARTICALS_SEPARATOR, ()=>partialsContent.partialsTop).replace(HEAD_PARTICALS_SEPARATOR, ()=>partialsContent.partialsHead).replace(BODY_PARTICALS_SEPARATOR, ()=>partialsContent.partialsBody);
|
|
252
268
|
};
|
|
253
|
-
const extractHtmlTags = (
|
|
269
|
+
const extractHtmlTags = (htmlPlugin, templateParameters)=>{
|
|
254
270
|
const scripts = [
|
|
255
|
-
|
|
256
|
-
|
|
271
|
+
htmlPlugin.tags.headTags.filter((item)=>"script" === item.tagName).join(''),
|
|
272
|
+
htmlPlugin.tags.bodyTags.toString()
|
|
257
273
|
].join('');
|
|
258
|
-
const links =
|
|
274
|
+
const links = htmlPlugin.tags.headTags.filter((item)=>'link' === item.tagName).join('');
|
|
259
275
|
const metas = [
|
|
260
276
|
templateParameters.meta,
|
|
261
|
-
|
|
277
|
+
htmlPlugin.tags.headTags.filter((item)=>"script" !== item.tagName && 'link' !== item.tagName && 'title' !== item.tagName).join('')
|
|
262
278
|
].join('');
|
|
263
|
-
const titles =
|
|
279
|
+
const titles = htmlPlugin.tags.headTags.filter((item)=>'title' === item.tagName).join('').replace('<title>', '').replace('</title>', '');
|
|
264
280
|
return {
|
|
265
281
|
scripts,
|
|
266
282
|
links,
|
|
@@ -279,19 +295,26 @@ const documentPlugin = ()=>({
|
|
|
279
295
|
const { entrypoints, internalDirectory, appDirectory } = api.getAppContext();
|
|
280
296
|
const documentFilePath = getDocumentByEntryName(entrypoints, entryName, appDirectory);
|
|
281
297
|
if (!documentFilePath) return null;
|
|
282
|
-
return async ({
|
|
298
|
+
return async ({ htmlPlugin })=>{
|
|
283
299
|
const config = api.getNormalizedConfig();
|
|
284
300
|
const documentParams = getDocParams({
|
|
285
301
|
config: config,
|
|
286
302
|
entryName,
|
|
287
303
|
templateParameters
|
|
288
304
|
});
|
|
289
|
-
|
|
290
|
-
|
|
305
|
+
let html;
|
|
306
|
+
try {
|
|
307
|
+
const { renderer } = await loadRender(entryName, internalDirectory);
|
|
308
|
+
html = renderer(documentParams);
|
|
309
|
+
} catch (error) {
|
|
310
|
+
const err = error;
|
|
311
|
+
logger.error(`Failed to render Document for entry "${entryName}": ${err.message}`);
|
|
312
|
+
throw err;
|
|
313
|
+
}
|
|
291
314
|
debug("entry %s's document jsx rendered html: %o", entryName, html);
|
|
292
315
|
const { partialsByEntrypoint } = api.getAppContext();
|
|
293
316
|
html = processPartials(html, entryName, partialsByEntrypoint || {});
|
|
294
|
-
const { scripts, links, metas, titles } = extractHtmlTags(
|
|
317
|
+
const { scripts, links, metas, titles } = extractHtmlTags(htmlPlugin, templateParameters);
|
|
295
318
|
return processPlaceholders(html, config, scripts, links, metas, titles);
|
|
296
319
|
};
|
|
297
320
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from "./Html";
|
|
2
|
-
export * from "./DocumentContext";
|
|
3
|
-
export * from "./DocumentStructureContext";
|
|
4
|
-
export * from "./Head";
|
|
5
|
-
export * from "./Body";
|
|
6
|
-
export * from "./Root";
|
|
7
|
-
export * from "./Links";
|
|
8
|
-
export * from "./Comment";
|
|
9
|
-
export * from "./Style";
|
|
10
|
-
export * from "./Scripts";
|
|
11
|
-
export * from "./Script";
|
|
12
|
-
export * from "./constants";
|
|
1
|
+
export * from "./Html.mjs";
|
|
2
|
+
export * from "./DocumentContext.mjs";
|
|
3
|
+
export * from "./DocumentStructureContext.mjs";
|
|
4
|
+
export * from "./Head.mjs";
|
|
5
|
+
export * from "./Body.mjs";
|
|
6
|
+
export * from "./Root.mjs";
|
|
7
|
+
export * from "./Links.mjs";
|
|
8
|
+
export * from "./Comment.mjs";
|
|
9
|
+
export * from "./Style.mjs";
|
|
10
|
+
export * from "./Scripts.mjs";
|
|
11
|
+
export * from "./Script.mjs";
|
|
12
|
+
export * from "./constants.mjs";
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isBrowser } from "./common";
|
|
2
|
-
import { getMonitors } from "./core/context/monitors";
|
|
3
|
-
import { getRequest } from "./core/context/request";
|
|
4
|
-
import { redirect, setHeaders, setStatus } from "./core/context/response";
|
|
5
|
-
import { RuntimeContext, defineRuntimeConfig, useRuntimeContext } from "./core";
|
|
1
|
+
import { isBrowser } from "./common.mjs";
|
|
2
|
+
import { getMonitors } from "./core/context/monitors/index.mjs";
|
|
3
|
+
import { getRequest } from "./core/context/request/index.mjs";
|
|
4
|
+
import { redirect, setHeaders, setStatus } from "./core/context/response/index.mjs";
|
|
5
|
+
import { RuntimeContext, defineRuntimeConfig, useRuntimeContext } from "./core/index.mjs";
|
|
6
6
|
export { RuntimeContext, defineRuntimeConfig, getMonitors, getRequest, isBrowser, redirect, setHeaders, setStatus, useRuntimeContext };
|
package/dist/esm/internal.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { InternalRuntimeContext } from "./core/context/runtime";
|
|
1
|
+
import { InternalRuntimeContext } from "./core/context/runtime.mjs";
|
|
2
2
|
export { InternalRuntimeContext };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getRequest } from "./core/context/request";
|
|
2
|
-
import { getMonitors } from "./core/context/monitors";
|
|
3
|
-
import { redirect, setHeaders, setStatus } from "./core/context/response";
|
|
1
|
+
import { getRequest } from "./core/context/request/index.mjs";
|
|
2
|
+
import { getMonitors } from "./core/context/monitors/index.mjs";
|
|
3
|
+
import { redirect, setHeaders, setStatus } from "./core/context/response/index.mjs";
|
|
4
4
|
export { getMonitors, getRequest, redirect, setHeaders, setStatus };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
import { FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_INDEX } from "../../constants";
|
|
4
|
-
import { makeLegalIdentifier } from "../makeLegalIdentifier";
|
|
5
|
-
import { replaceWithAlias } from "../utils";
|
|
6
|
-
import { debug, getRouteWeight, shouldSkip } from "./utils";
|
|
3
|
+
import { FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_INDEX } from "../../constants.mjs";
|
|
4
|
+
import { makeLegalIdentifier } from "../makeLegalIdentifier.mjs";
|
|
5
|
+
import { replaceWithAlias } from "../utils.mjs";
|
|
6
|
+
import { debug, getRouteWeight, shouldSkip } from "./utils.mjs";
|
|
7
7
|
const compName = (srcDirectory, filePath)=>{
|
|
8
8
|
const legalCompName = makeLegalIdentifier(path.relative(srcDirectory, filePath));
|
|
9
9
|
return `Comp_${legalCompName}`;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { getClientRoutes } from "./getRoutes";
|
|
1
|
+
import { getClientRoutes } from "./getRoutes.mjs";
|
|
2
2
|
export { getClientRoutes };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { JS_EXTENSIONS, createDebugger, fs } from "@modern-js/utils";
|
|
3
|
-
import { FILE_SYSTEM_ROUTES_IGNORED_REGEX } from "../../constants";
|
|
3
|
+
import { FILE_SYSTEM_ROUTES_IGNORED_REGEX } from "../../constants.mjs";
|
|
4
4
|
const debug = createDebugger('get-client-routes');
|
|
5
5
|
const getRouteWeight = (route)=>'*' === route ? 999 : route.split(':').length - 1;
|
|
6
6
|
const shouldSkip = (file)=>{
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { filterRoutesForServer, filterRoutesLoader, fs, getEntryOptions, isUseRsc, isUseSSRBundle, logger, markRoutes } from "@modern-js/utils";
|
|
3
3
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
4
|
-
import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME } from "../../../cli/constants";
|
|
5
|
-
import { resolveSSRMode } from "../../../cli/ssr/mode";
|
|
6
|
-
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "../constants";
|
|
7
|
-
import { walk } from "./nestedRoutes";
|
|
8
|
-
import { fileSystemRoutes, routesForServer, ssrLoaderCombinedModule } from "./templates";
|
|
9
|
-
import { getServerCombinedModueFile, getServerLoadersFile } from "./utils";
|
|
4
|
+
import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME } from "../../../cli/constants.mjs";
|
|
5
|
+
import { resolveSSRMode } from "../../../cli/ssr/mode.mjs";
|
|
6
|
+
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "../constants.mjs";
|
|
7
|
+
import { walk } from "./nestedRoutes.mjs";
|
|
8
|
+
import { fileSystemRoutes, routesForServer, ssrLoaderCombinedModule } from "./templates.mjs";
|
|
9
|
+
import { getServerCombinedModueFile, getServerLoadersFile } from "./utils.mjs";
|
|
10
10
|
async function generateRoutesForEntry(entrypoint, appContext) {
|
|
11
11
|
const routes = [];
|
|
12
12
|
if (entrypoint.nestedRoutesEntry) {
|
|
@@ -26,10 +26,10 @@ async function generateRoutesForEntry(entrypoint, appContext) {
|
|
|
26
26
|
const fileRoutes = routes.length > 0 ? Array.isArray(routes) ? routes : [
|
|
27
27
|
routes
|
|
28
28
|
] : [];
|
|
29
|
-
const { discoverAndParseConfigRoutes } = await import("../config-routes/parseRouteConfig");
|
|
29
|
+
const { discoverAndParseConfigRoutes } = await import("../config-routes/parseRouteConfig.mjs");
|
|
30
30
|
const configRoutesData = await discoverAndParseConfigRoutes(entrypoint, appContext, fileRoutes);
|
|
31
31
|
if (configRoutesData) {
|
|
32
|
-
const { processConfigRoutes } = await import("../config-routes/converter");
|
|
32
|
+
const { processConfigRoutes } = await import("../config-routes/converter.mjs");
|
|
33
33
|
const processedConfigRoutes = await processConfigRoutes(configRoutesData.routes, entrypoint.entryName, entrypoint.isMainEntry || false, path.dirname(configRoutesData.filePath), {
|
|
34
34
|
name: appContext.internalSrcAlias,
|
|
35
35
|
basename: appContext.srcDirectory
|
|
@@ -62,7 +62,7 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
|
|
|
62
62
|
if (pageRoutesEntry || nestedRoutesEntry) {
|
|
63
63
|
const initialRoutes = [];
|
|
64
64
|
const generatedRoutes = await generateRoutesForEntry(entrypoint, appContext);
|
|
65
|
-
const { normalizeRoutes: removeComponentFields } = await import("../config-routes/converter");
|
|
65
|
+
const { normalizeRoutes: removeComponentFields } = await import("../config-routes/converter.mjs");
|
|
66
66
|
const normalizedRoutes = removeComponentFields(generatedRoutes);
|
|
67
67
|
for (const route of normalizedRoutes)initialRoutes.unshift(route);
|
|
68
68
|
const ssrByRouteIds = config.server.ssrByRouteIds || [];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
3
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
4
|
-
import { modifyEntrypoints } from "../entry";
|
|
5
|
-
import { generateRoutesForEntry } from "./index";
|
|
4
|
+
import { modifyEntrypoints } from "../entry.mjs";
|
|
5
|
+
import { generateRoutesForEntry } from "./index.mjs";
|
|
6
6
|
function convertRouteToInspectFormat(route) {
|
|
7
7
|
const inspectRoute = {
|
|
8
8
|
path: route.path ?? void 0,
|