@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
|
@@ -3,10 +3,6 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { Link as router_Link, NavLink, matchRoutes, useHref, useMatches, useResolvedPath } from "@modern-js/runtime-utils/router";
|
|
4
4
|
import react, { useContext, useMemo } from "react";
|
|
5
5
|
import { InternalRuntimeContext } from "../../core/context/index.mjs";
|
|
6
|
-
var __webpack_require__ = {};
|
|
7
|
-
(()=>{
|
|
8
|
-
__webpack_require__.e = ()=>Promise.resolve();
|
|
9
|
-
})();
|
|
10
6
|
function composeEventHandlers(theirHandler, ourHandler) {
|
|
11
7
|
return (event)=>{
|
|
12
8
|
theirHandler?.(event);
|
|
@@ -145,7 +141,7 @@ const createPrefetchLink = (Link)=>/*#__PURE__*/ react.forwardRef(({ to, prefetc
|
|
|
145
141
|
...props,
|
|
146
142
|
...prefetchHandlers
|
|
147
143
|
}),
|
|
148
|
-
shouldPrefetch &&
|
|
144
|
+
shouldPrefetch && __webpack_chunk_load__ && !isAbsolute ? /*#__PURE__*/ jsx(PrefetchPageLinks, {
|
|
149
145
|
path: resolvedPath
|
|
150
146
|
}) : null
|
|
151
147
|
]
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useRouteLoaderData } from "@modern-js/runtime-utils/router";
|
|
2
|
-
import { Link, NavLink } from "./PrefetchLink.mjs";
|
|
3
2
|
export * from "@modern-js/runtime-utils/router";
|
|
4
3
|
export * from "./withRouter.mjs";
|
|
5
4
|
const runtime_useRouteLoaderData = (routeId)=>{
|
|
6
5
|
const realRouteId = routeId.replace(/\[(.*?)\]/g, '($1)');
|
|
7
6
|
return useRouteLoaderData(realRouteId);
|
|
8
7
|
};
|
|
9
|
-
export { Link, NavLink
|
|
8
|
+
export { Link, NavLink } from "./PrefetchLink.mjs";
|
|
9
|
+
export { runtime_useRouteLoaderData as useRouteLoaderData };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { modifyRoutes, routerPlugin } from "./plugin.mjs";
|
|
2
|
-
import { renderRoutes } from "./utils.mjs";
|
|
3
2
|
const internal = routerPlugin;
|
|
4
|
-
export {
|
|
3
|
+
export { renderRoutes } from "./utils.mjs";
|
|
4
|
+
export default internal;
|
|
5
|
+
export { modifyRoutes, routerPlugin };
|
|
@@ -2,11 +2,11 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
3
3
|
import { RouterProvider, createBrowserRouter, createHashRouter, createRoutesFromElements, useHref, useLocation, useMatches } from "@modern-js/runtime-utils/router";
|
|
4
4
|
import { normalizePathname } from "@modern-js/runtime-utils/url";
|
|
5
|
+
import * as __rspack_external_react from "react";
|
|
5
6
|
import { InternalRuntimeContext, getGlobalIsRscClient, getGlobalLayoutApp, getGlobalRoutes } from "../../core/context/index.mjs";
|
|
6
7
|
import { modifyRoutes, onBeforeCreateRoutes } from "./hooks.mjs";
|
|
7
8
|
import { createClientRouterFromPayload } from "./rsc-router.mjs";
|
|
8
9
|
import { createRouteObjectsFromConfig, deserializeErrors, renderRoutes, urlJoin } from "./utils.mjs";
|
|
9
|
-
import * as __rspack_external_react from "react";
|
|
10
10
|
let finalRouteConfig = {
|
|
11
11
|
routes: []
|
|
12
12
|
};
|
|
@@ -3,8 +3,8 @@ import path from "path";
|
|
|
3
3
|
import { fs } from "@modern-js/utils";
|
|
4
4
|
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";
|
|
5
5
|
import { resolveSSRMode } from "./ssr/mode.mjs";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import * as __rspack_external__template_mjs_d6ab8956 from "./template.mjs";
|
|
7
|
+
import * as __rspack_external__template_server_mjs_38d6edb1 from "./template.server.mjs";
|
|
8
8
|
const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
9
9
|
const { mountId } = config.html;
|
|
10
10
|
const { enableAsyncEntry } = config.source;
|
|
@@ -22,13 +22,7 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
22
22
|
nestedRoutesEntry
|
|
23
23
|
});
|
|
24
24
|
let indexCode = '';
|
|
25
|
-
indexCode =
|
|
26
|
-
metaName,
|
|
27
|
-
entryName,
|
|
28
|
-
mountId,
|
|
29
|
-
urlPath: serverRoutes.find((route)=>route.entryName === entryName)?.urlPath,
|
|
30
|
-
isNestedRouter: entrypoint.nestedRoutesEntry
|
|
31
|
-
}) : index({
|
|
25
|
+
indexCode = ssrMode || !config.server.rsc || customEntry ? __rspack_external__template_mjs_d6ab8956.index({
|
|
32
26
|
srcDirectory,
|
|
33
27
|
internalSrcAlias,
|
|
34
28
|
metaName,
|
|
@@ -38,6 +32,12 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
38
32
|
mountId,
|
|
39
33
|
enableRsc: config.server.rsc,
|
|
40
34
|
isNestedRouter: !!entrypoint.nestedRoutesEntry
|
|
35
|
+
}) : __rspack_external__template_mjs_d6ab8956.entryForCSRWithRSC({
|
|
36
|
+
metaName,
|
|
37
|
+
entryName,
|
|
38
|
+
mountId,
|
|
39
|
+
urlPath: serverRoutes.find((route)=>route.entryName === entryName)?.urlPath,
|
|
40
|
+
isNestedRouter: entrypoint.nestedRoutesEntry
|
|
41
41
|
});
|
|
42
42
|
const indexFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
|
|
43
43
|
await fs.outputFile(indexFile, indexCode, 'utf8');
|
|
@@ -48,7 +48,7 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
48
48
|
if (ssrMode) await fs.outputFile(bootstrapServerFile, `export const requestHandler = import('./${SERVER_ENTRY_POINT_FILE_NAME}').then((m) => m.requestHandler)`, 'utf8');
|
|
49
49
|
}
|
|
50
50
|
if (ssrMode) {
|
|
51
|
-
const indexServerCode = serverIndex({
|
|
51
|
+
const indexServerCode = __rspack_external__template_server_mjs_38d6edb1.serverIndex({
|
|
52
52
|
entry,
|
|
53
53
|
entryName,
|
|
54
54
|
internalSrcAlias,
|
|
@@ -62,16 +62,16 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
62
62
|
await fs.outputFile(indexServerFile, indexServerCode, 'utf8');
|
|
63
63
|
} else if (config.server.rsc) {
|
|
64
64
|
const indexServerFile = path.resolve(internalDirectory, `./${entryName}/${SERVER_ENTRY_POINT_FILE_NAME}`);
|
|
65
|
-
const indexServerCode =
|
|
65
|
+
const indexServerCode = __rspack_external__template_server_mjs_38d6edb1.entryForCSRWithRSC({
|
|
66
66
|
entryName,
|
|
67
67
|
metaName
|
|
68
68
|
});
|
|
69
69
|
await fs.outputFile(indexServerFile, indexServerCode, 'utf8');
|
|
70
70
|
}
|
|
71
|
-
const registerCode = register();
|
|
71
|
+
const registerCode = __rspack_external__template_mjs_d6ab8956.register();
|
|
72
72
|
const registerFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_REGISTER_FILE_NAME}`);
|
|
73
73
|
await fs.outputFile(registerFile, registerCode, 'utf8');
|
|
74
|
-
const registerRuntimeCode = runtimeRegister({
|
|
74
|
+
const registerRuntimeCode = __rspack_external__template_mjs_d6ab8956.runtimeRegister({
|
|
75
75
|
entryName,
|
|
76
76
|
srcDirectory,
|
|
77
77
|
internalSrcAlias,
|
|
@@ -85,7 +85,7 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
85
85
|
if (!config.server.rsc || entrypoint.nestedRoutesEntry) {
|
|
86
86
|
const route = serverRoutes.find((r)=>r.entryName === entryName);
|
|
87
87
|
const basename = route?.urlPath || '/';
|
|
88
|
-
contextCode = runtimeGlobalContext({
|
|
88
|
+
contextCode = __rspack_external__template_mjs_d6ab8956.runtimeGlobalContext({
|
|
89
89
|
entryName,
|
|
90
90
|
srcDirectory,
|
|
91
91
|
internalSrcAlias,
|
|
@@ -96,17 +96,18 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
96
96
|
});
|
|
97
97
|
} else {
|
|
98
98
|
const AppProxyPath = path.join(internalDirectory, entryName, './AppProxy.jsx');
|
|
99
|
-
const appProxyCode = AppProxyForRSC({
|
|
99
|
+
const appProxyCode = __rspack_external__template_mjs_d6ab8956.AppProxyForRSC({
|
|
100
100
|
srcDirectory,
|
|
101
101
|
internalSrcAlias,
|
|
102
102
|
entry,
|
|
103
103
|
customEntry
|
|
104
104
|
});
|
|
105
105
|
await fs.outputFile(AppProxyPath, appProxyCode);
|
|
106
|
-
contextCode = runtimeGlobalContextForRSCClient({
|
|
107
|
-
metaName
|
|
106
|
+
contextCode = __rspack_external__template_mjs_d6ab8956.runtimeGlobalContextForRSCClient({
|
|
107
|
+
metaName,
|
|
108
|
+
customEntry
|
|
108
109
|
});
|
|
109
|
-
const contextServerCode = runtimeGlobalContextForRSCServer({
|
|
110
|
+
const contextServerCode = __rspack_external__template_mjs_d6ab8956.runtimeGlobalContextForRSCServer({
|
|
110
111
|
metaName
|
|
111
112
|
});
|
|
112
113
|
const contextFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}.server.js`);
|
|
@@ -91,4 +91,5 @@ const runtimePlugin = (params)=>({
|
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
93
|
const cli = runtimePlugin;
|
|
94
|
-
export
|
|
94
|
+
export default cli;
|
|
95
|
+
export { documentPlugin, isRuntimeEntry, routerPlugin, runtimePlugin, ssrPlugin };
|
|
@@ -153,16 +153,54 @@ const runtimeGlobalContextForRSCServer = ({ metaName })=>`
|
|
|
153
153
|
App: DefaultRoot,
|
|
154
154
|
RSCRoot: AppProxy,
|
|
155
155
|
});`;
|
|
156
|
-
const runtimeGlobalContextForRSCClient = ({ metaName })=>`
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
156
|
+
const runtimeGlobalContextForRSCClient = ({ metaName, customEntry })=>`
|
|
157
|
+
${customEntry ? `import {
|
|
158
|
+
RscClientRoot,
|
|
159
|
+
createFromFetch,
|
|
160
|
+
createFromReadableStream,
|
|
161
|
+
isRedirectResponse,
|
|
162
|
+
rscStream,
|
|
163
|
+
callServer,
|
|
164
|
+
setServerCallback,
|
|
165
|
+
} from '@${metaName}/runtime/rsc/client';` : ''}
|
|
166
|
+
import { createElement, Fragment } from 'react';
|
|
167
|
+
import { setGlobalContext } from '@${metaName}/runtime/context';
|
|
168
|
+
|
|
169
|
+
${customEntry ? 'setServerCallback(callServer);' : ''}
|
|
170
|
+
|
|
171
|
+
${customEntry ? `const handleRedirectResponse = (res: Response) => {
|
|
172
|
+
const { headers } = res;
|
|
173
|
+
const location = headers.get('X-Modernjs-Redirect');
|
|
174
|
+
const baseUrl = headers.get('X-Modernjs-BaseUrl');
|
|
175
|
+
if (location) {
|
|
176
|
+
if (baseUrl && baseUrl !== '/') {
|
|
177
|
+
window.location.replace(baseUrl + location);
|
|
178
|
+
} else {
|
|
179
|
+
window.location.replace(location);
|
|
180
|
+
}
|
|
181
|
+
return res;
|
|
182
|
+
}
|
|
183
|
+
return res;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const data = ${process.env.MODERN_DISABLE_INJECT_RSC_DATA ? `createFromFetch(
|
|
187
|
+
fetch(location.pathname, {
|
|
188
|
+
headers: {
|
|
189
|
+
'x-rsc-tree': 'true',
|
|
190
|
+
},
|
|
191
|
+
}).then(handleRedirectResponse),
|
|
192
|
+
)` : `createFromReadableStream(rscStream, {
|
|
193
|
+
callServer: callServer,
|
|
194
|
+
})`};` : ''}
|
|
195
|
+
|
|
196
|
+
const DefaultRoot = ({ children }: { children?: ReactNode }) =>
|
|
197
|
+
createElement(Fragment, null, children);
|
|
198
|
+
|
|
199
|
+
${customEntry ? 'const RSCRoot = () => createElement(RscClientRoot, { rscPayload: data });' : ''}
|
|
200
|
+
|
|
201
|
+
setGlobalContext({
|
|
202
|
+
App: ${customEntry ? 'RSCRoot' : 'DefaultRoot'}
|
|
203
|
+
});`;
|
|
166
204
|
const AppProxyForRSC = ({ srcDirectory, internalSrcAlias, entry, customEntry })=>`
|
|
167
205
|
import App from '${formatImportPath(customEntry ? entry.replace(/entry\.[tj]sx/, 'App').replace(srcDirectory, internalSrcAlias) : entry.replace(srcDirectory, internalSrcAlias).replace('.tsx', ''))}';
|
|
168
206
|
import React from 'react';
|
|
@@ -6,4 +6,4 @@ var constants_RenderLevel = /*#__PURE__*/ function(RenderLevel) {
|
|
|
6
6
|
}({});
|
|
7
7
|
const SSR_DATA_JSON_ID = '__MODERN_SSR_DATA__';
|
|
8
8
|
const ROUTER_DATA_JSON_ID = '__MODERN_ROUTER_DATA__';
|
|
9
|
-
export { ROUTER_DATA_JSON_ID, constants_RenderLevel as RenderLevel
|
|
9
|
+
export { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID, constants_RenderLevel as RenderLevel };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { InternalRuntimeContext, RuntimeContext, getInitialContext } from "./runtime.mjs";
|
|
3
|
-
import { getServerPayload, setServerPayload } from "./serverPayload/index.mjs";
|
|
4
2
|
const globalContext = {};
|
|
5
3
|
function getGlobalIsRscClient() {
|
|
6
4
|
return globalContext.isRscClient;
|
|
@@ -43,4 +41,6 @@ function getGlobalLayoutApp() {
|
|
|
43
41
|
function getGlobalBasename() {
|
|
44
42
|
return globalContext.basename;
|
|
45
43
|
}
|
|
46
|
-
export { InternalRuntimeContext, RuntimeContext,
|
|
44
|
+
export { InternalRuntimeContext, RuntimeContext, getInitialContext } from "./runtime.mjs";
|
|
45
|
+
export { getServerPayload, setServerPayload } from "./serverPayload/index.mjs";
|
|
46
|
+
export { getCurrentEntryName, getGlobalApp, getGlobalBasename, getGlobalEnableRsc, getGlobalInternalRuntimeContext, getGlobalIsRscClient, getGlobalLayoutApp, getGlobalRSCRoot, getGlobalRoutes, setGlobalContext, setGlobalInternalRuntimeContext };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { RuntimeContext, defineRuntimeConfig, useRuntimeContext };
|
|
2
|
+
export { defineRuntimeConfig } from "./config.mjs";
|
|
3
|
+
export { RuntimeContext, useRuntimeContext } from "./context/runtime.mjs";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { NoSSR, NoSSRCache } from "./react/index.mjs";
|
|
3
2
|
const ssr = (_config)=>({
|
|
4
3
|
name: '@modern-js/plugin-ssr',
|
|
5
4
|
setup: (_api)=>{}
|
|
6
5
|
});
|
|
7
6
|
const server = ssr;
|
|
8
|
-
export { NoSSR, NoSSRCache
|
|
7
|
+
export { NoSSR, NoSSRCache } from "./react/index.mjs";
|
|
8
|
+
export default server;
|
|
9
|
+
export { ssr };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { createRequestHandler, renderStreaming, renderString };
|
|
2
|
+
export { renderString } from "./string/index.mjs";
|
|
3
|
+
export { renderStreaming } from "./stream/index.mjs";
|
|
4
|
+
export { createRequestHandler } from "./requestHandler.mjs";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
3
|
-
import { dirname as __rspack_dirname } from "node:path";
|
|
4
2
|
import { matchRoutes } from "@modern-js/runtime-utils/router";
|
|
5
3
|
import react_helmet from "react-helmet";
|
|
6
4
|
import { CHUNK_CSS_PLACEHOLDER } from "../constants.mjs";
|
|
7
5
|
import { createReplaceHelemt } from "../helmet.mjs";
|
|
8
6
|
import { buildHtml } from "../shared.mjs";
|
|
9
7
|
import { checkIsNode, safeReplace } from "../utils.mjs";
|
|
8
|
+
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
9
|
+
import { dirname as __rspack_dirname } from "node:path";
|
|
10
10
|
var beforeTemplate_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
11
11
|
const readAsset = async (chunk)=>{
|
|
12
12
|
const fs = await import("fs/promises");
|
|
@@ -106,4 +106,4 @@ function createRenderStreaming(createReadableStreamPromise) {
|
|
|
106
106
|
return stream;
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
export {
|
|
109
|
+
export { createRenderStreaming, encodeForWebStream, getReadableStreamFromString, resolveStreamingMode, shared_ShellChunkStatus as ShellChunkStatus };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
3
|
-
import { dirname as __rspack_dirname } from "node:path";
|
|
4
2
|
import { ChunkExtractor } from "@loadable/server";
|
|
5
3
|
import { attributesToString, checkIsNode } from "../utils.mjs";
|
|
4
|
+
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
5
|
+
import { dirname as __rspack_dirname } from "node:path";
|
|
6
6
|
var loadable_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
7
7
|
const extname = (uri)=>{
|
|
8
8
|
if ('string' != typeof uri || !uri.includes('.')) return '';
|
|
@@ -4,12 +4,22 @@ import "react";
|
|
|
4
4
|
import { Body } from "./Body.mjs";
|
|
5
5
|
import { DocumentStructureContext } from "./DocumentStructureContext.mjs";
|
|
6
6
|
import { Head } from "./Head.mjs";
|
|
7
|
+
import { Root } from "./Root.mjs";
|
|
7
8
|
function findTargetChildByName(tag, children) {
|
|
8
9
|
return children.find((item)=>getEleType(item) === tag);
|
|
9
10
|
}
|
|
10
11
|
function findTargetChildByComponent(component, children) {
|
|
11
12
|
return children.find((item)=>item?.type === component);
|
|
12
13
|
}
|
|
14
|
+
function findTargetElementByComponent(component, children) {
|
|
15
|
+
if (0 === children.length) return null;
|
|
16
|
+
let nextChildren = [];
|
|
17
|
+
for (const item of children){
|
|
18
|
+
if (item?.type === component) return item;
|
|
19
|
+
if (item?.props?.children) nextChildren = nextChildren.concat(item.props.children);
|
|
20
|
+
}
|
|
21
|
+
return findTargetElementByComponent(component, nextChildren);
|
|
22
|
+
}
|
|
13
23
|
function getEleType(ele) {
|
|
14
24
|
return 'function' == typeof ele?.type ? ele.type.name : ele?.type;
|
|
15
25
|
}
|
|
@@ -28,7 +38,7 @@ function Html(props) {
|
|
|
28
38
|
const hasSetScripts = Boolean(findTargetElement('Scripts', children));
|
|
29
39
|
const hasSetLinks = Boolean(findTargetElement('Links', children));
|
|
30
40
|
const hasSetBody = Boolean(findTargetChildByComponent(Body, children) || findTargetChildByName('Body', children));
|
|
31
|
-
const hasSetRoot = Boolean(
|
|
41
|
+
const hasSetRoot = Boolean(findTargetElementByComponent(Root, children) || findTargetChildByName('Root', children));
|
|
32
42
|
const hasSetTitle = Boolean(findTargetElement('title', children));
|
|
33
43
|
const notMissMustChild = [
|
|
34
44
|
hasSetHead,
|
package/dist/esm-node/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export { RuntimeContext, defineRuntimeConfig, getMonitors, getRequest, isBrowser, redirect, setHeaders, setStatus, useRuntimeContext };
|
|
2
|
+
export { isBrowser } from "./common.mjs";
|
|
3
|
+
export { getMonitors } from "./core/context/monitors/index.mjs";
|
|
4
|
+
export { getRequest } from "./core/context/request/index.mjs";
|
|
5
|
+
export { redirect, setHeaders, setStatus } from "./core/context/response/index.mjs";
|
|
6
|
+
export { RuntimeContext, defineRuntimeConfig, useRuntimeContext } from "./core/index.mjs";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { getMonitors, getRequest, redirect, setHeaders, setStatus };
|
|
2
|
+
export { getRequest } from "./core/context/request/index.mjs";
|
|
3
|
+
export { getMonitors } from "./core/context/monitors/index.mjs";
|
|
4
|
+
export { redirect, setHeaders, setStatus } from "./core/context/response/index.mjs";
|
|
@@ -6,8 +6,8 @@ import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME } from "../../../cli/const
|
|
|
6
6
|
import { resolveSSRMode } from "../../../cli/ssr/mode.mjs";
|
|
7
7
|
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "../constants.mjs";
|
|
8
8
|
import { walk } from "./nestedRoutes.mjs";
|
|
9
|
-
import { fileSystemRoutes, routesForServer, ssrLoaderCombinedModule } from "./templates.mjs";
|
|
10
9
|
import { getServerCombinedModuleFile, getServerLoadersFile } from "./utils.mjs";
|
|
10
|
+
import * as __rspack_external__templates_mjs_4da4c6c8 from "./templates.mjs";
|
|
11
11
|
async function generateRoutesForEntry(entrypoint, appContext) {
|
|
12
12
|
const routes = [];
|
|
13
13
|
if (entrypoint.nestedRoutesEntry) {
|
|
@@ -82,7 +82,7 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
|
|
|
82
82
|
}
|
|
83
83
|
const { code } = await hooks.onBeforeGenerateRoutes.call({
|
|
84
84
|
entrypoint,
|
|
85
|
-
code: await fileSystemRoutes({
|
|
85
|
+
code: await __rspack_external__templates_mjs_4da4c6c8.fileSystemRoutes({
|
|
86
86
|
metaName,
|
|
87
87
|
routes: routes,
|
|
88
88
|
ssrMode: isUseRsc(config) ? 'stream' : ssrMode,
|
|
@@ -99,12 +99,12 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
|
|
|
99
99
|
const routesServerFile = getServerLoadersFile(internalDirectory, entryName);
|
|
100
100
|
const filtedRoutesForServer = filterRoutesForServer(routes);
|
|
101
101
|
const routesForServerLoaderMatches = filterRoutesLoader(routes);
|
|
102
|
-
const code = routesForServer({
|
|
102
|
+
const code = __rspack_external__templates_mjs_4da4c6c8.routesForServer({
|
|
103
103
|
routesForServerLoaderMatches
|
|
104
104
|
});
|
|
105
105
|
await fs.ensureFile(routesServerFile);
|
|
106
106
|
await fs.writeFile(routesServerFile, code);
|
|
107
|
-
const serverRoutesCode = await fileSystemRoutes({
|
|
107
|
+
const serverRoutesCode = await __rspack_external__templates_mjs_4da4c6c8.fileSystemRoutes({
|
|
108
108
|
metaName,
|
|
109
109
|
routes: filtedRoutesForServer,
|
|
110
110
|
ssrMode,
|
|
@@ -118,7 +118,7 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
|
|
|
118
118
|
});
|
|
119
119
|
await fs.outputFile(path.resolve(internalDirectory, `./${entryName}/routes.server.js`), serverRoutesCode, 'utf8');
|
|
120
120
|
}
|
|
121
|
-
const serverLoaderCombined = ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext);
|
|
121
|
+
const serverLoaderCombined = __rspack_external__templates_mjs_4da4c6c8.ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext);
|
|
122
122
|
if (serverLoaderCombined) {
|
|
123
123
|
const serverLoaderFile = getServerCombinedModuleFile(internalDirectory, entryName);
|
|
124
124
|
await fs.outputFile(serverLoaderFile, serverLoaderCombined);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { extname as external_path_extname, join, relative, sep } from "path";
|
|
3
2
|
import { JS_EXTENSIONS, fs, normalizeToPosixPath } from "@modern-js/utils";
|
|
4
3
|
import { NESTED_ROUTE } from "../constants.mjs";
|
|
5
4
|
import { getPathWithoutExt, hasAction, replaceWithAlias } from "./utils.mjs";
|
|
5
|
+
import * as __rspack_external_path from "path";
|
|
6
6
|
const conventionNames = Object.values(NESTED_ROUTE);
|
|
7
7
|
const replaceDynamicPath = (routePath)=>routePath.replace(/\[(.*?)\]/g, ':$1');
|
|
8
8
|
const getRouteId = (componentPath, routesDir, entryName, isMainEntry)=>{
|
|
9
|
-
const relativePath = normalizeToPosixPath(relative(routesDir, componentPath));
|
|
9
|
+
const relativePath = normalizeToPosixPath(__rspack_external_path.relative(routesDir, componentPath));
|
|
10
10
|
const pathWithoutExt = getPathWithoutExt(relativePath);
|
|
11
11
|
let id = "";
|
|
12
12
|
id = isMainEntry ? pathWithoutExt : `${entryName}_${pathWithoutExt}`;
|
|
@@ -65,8 +65,8 @@ const walk = async (options)=>{
|
|
|
65
65
|
if (!await fs.pathExists(dirname)) return null;
|
|
66
66
|
const isDirectory = (await fs.stat(dirname)).isDirectory();
|
|
67
67
|
if (!isDirectory) return null;
|
|
68
|
-
const relativeDir = relative(rootDir, dirname);
|
|
69
|
-
const pathSegments = relativeDir.split(sep);
|
|
68
|
+
const relativeDir = __rspack_external_path.relative(rootDir, dirname);
|
|
69
|
+
const pathSegments = relativeDir.split(__rspack_external_path.sep);
|
|
70
70
|
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
71
71
|
const isRoot = '' === lastSegment;
|
|
72
72
|
const isPathlessLayout = lastSegment.startsWith('__');
|
|
@@ -94,9 +94,9 @@ const walk = async (options)=>{
|
|
|
94
94
|
let splatAction = '';
|
|
95
95
|
const items = await fs.readdir(dirname);
|
|
96
96
|
for (const item of items){
|
|
97
|
-
const itemPath = join(dirname, item);
|
|
97
|
+
const itemPath = __rspack_external_path.join(dirname, item);
|
|
98
98
|
const itemPathWithAlias = alias ? getPathWithoutExt(replaceWithAlias(alias.basename, itemPath, alias.name)) : getPathWithoutExt(itemPath);
|
|
99
|
-
const extname =
|
|
99
|
+
const extname = __rspack_external_path.extname(item);
|
|
100
100
|
const itemWithoutExt = item.slice(0, -extname.length);
|
|
101
101
|
const isDirectory = (await fs.stat(itemPath)).isDirectory();
|
|
102
102
|
if (isDirectory) {
|
|
@@ -169,7 +169,7 @@ const walk = async (options)=>{
|
|
|
169
169
|
let finalRoute = createRoute({
|
|
170
170
|
...route,
|
|
171
171
|
origin: 'file-system'
|
|
172
|
-
}, rootDir, join(dirname, `${NESTED_ROUTE.LAYOUT_FILE}.ts`), entryName, isMainEntry);
|
|
172
|
+
}, rootDir, __rspack_external_path.join(dirname, `${NESTED_ROUTE.LAYOUT_FILE}.ts`), entryName, isMainEntry);
|
|
173
173
|
if (isPathlessLayout) delete finalRoute.path;
|
|
174
174
|
const childRoutes = finalRoute.children = finalRoute.children?.filter((childRoute)=>childRoute);
|
|
175
175
|
if (childRoutes && 0 === childRoutes.length && !finalRoute.index && !finalRoute._component) return null;
|
|
@@ -2,9 +2,9 @@ import "node:module";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { getMeta } from "@modern-js/utils";
|
|
4
4
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
5
|
-
import { runtimeGlobalContext } from "./code/templates.mjs";
|
|
6
5
|
import { isPageComponentFile } from "./code/utils.mjs";
|
|
7
6
|
import { modifyEntrypoints } from "./entry.mjs";
|
|
7
|
+
import * as __rspack_external__code_templates_mjs_5e908598 from "./code/templates.mjs";
|
|
8
8
|
let originEntrypoints = [];
|
|
9
9
|
async function handleModifyEntrypoints(entrypoints) {
|
|
10
10
|
return modifyEntrypoints(entrypoints);
|
|
@@ -21,7 +21,7 @@ async function handleGeneratorEntryCode(api, entrypoints) {
|
|
|
21
21
|
if (entrypoint.nestedRoutesEntry || entrypoint.pageRoutesEntry) {
|
|
22
22
|
const route = appContext.serverRoutes.find((r)=>r.entryName === entrypoint.entryName);
|
|
23
23
|
const basename = route?.urlPath || '/';
|
|
24
|
-
generatorRegisterCode(internalDirectory, entrypoint.entryName, await runtimeGlobalContext({
|
|
24
|
+
generatorRegisterCode(internalDirectory, entrypoint.entryName, await __rspack_external__code_templates_mjs_5e908598.runtimeGlobalContext({
|
|
25
25
|
entryName: entrypoint.entryName,
|
|
26
26
|
metaName: appContext.metaName,
|
|
27
27
|
srcDirectory: appContext.srcDirectory,
|
|
@@ -31,7 +31,7 @@ async function handleGeneratorEntryCode(api, entrypoints) {
|
|
|
31
31
|
rscType: enableRsc ? 'client' : void 0,
|
|
32
32
|
basename
|
|
33
33
|
}));
|
|
34
|
-
if (enableRsc) generatorServerRegisterCode(internalDirectory, entrypoint.entryName, await runtimeGlobalContext({
|
|
34
|
+
if (enableRsc) generatorServerRegisterCode(internalDirectory, entrypoint.entryName, await __rspack_external__code_templates_mjs_5e908598.runtimeGlobalContext({
|
|
35
35
|
entryName: entrypoint.entryName,
|
|
36
36
|
metaName: appContext.metaName,
|
|
37
37
|
srcDirectory: appContext.srcDirectory,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
3
|
-
import { dirname as __rspack_dirname } from "node:path";
|
|
4
2
|
import node_path from "node:path";
|
|
5
3
|
import { NESTED_ROUTE_SPEC_FILE, filterRoutesForServer, fs } from "@modern-js/utils";
|
|
6
4
|
import { isRouteEntry } from "./entry.mjs";
|
|
7
5
|
import { handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints } from "./handler.mjs";
|
|
6
|
+
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
7
|
+
import { dirname as __rspack_dirname } from "node:path";
|
|
8
8
|
var cli_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
9
9
|
const routerPlugin = ()=>({
|
|
10
10
|
name: '@modern-js/plugin-router',
|
|
@@ -81,4 +81,5 @@ const routerPlugin = ()=>({
|
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
const cli = routerPlugin;
|
|
84
|
-
export
|
|
84
|
+
export default cli;
|
|
85
|
+
export { handleFileChange, handleModifyEntrypoints, isRouteEntry, routerPlugin };
|
|
@@ -4,10 +4,6 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
4
4
|
import { Link as router_Link, NavLink, matchRoutes, useHref, useMatches, useResolvedPath } from "@modern-js/runtime-utils/router";
|
|
5
5
|
import react, { useContext, useMemo } from "react";
|
|
6
6
|
import { InternalRuntimeContext } from "../../core/context/index.mjs";
|
|
7
|
-
var __webpack_require__ = {};
|
|
8
|
-
(()=>{
|
|
9
|
-
__webpack_require__.e = ()=>Promise.resolve();
|
|
10
|
-
})();
|
|
11
7
|
function composeEventHandlers(theirHandler, ourHandler) {
|
|
12
8
|
return (event)=>{
|
|
13
9
|
theirHandler?.(event);
|
|
@@ -146,7 +142,7 @@ const createPrefetchLink = (Link)=>/*#__PURE__*/ react.forwardRef(({ to, prefetc
|
|
|
146
142
|
...props,
|
|
147
143
|
...prefetchHandlers
|
|
148
144
|
}),
|
|
149
|
-
shouldPrefetch &&
|
|
145
|
+
shouldPrefetch && __webpack_chunk_load__ && !isAbsolute ? /*#__PURE__*/ jsx(PrefetchPageLinks, {
|
|
150
146
|
path: resolvedPath
|
|
151
147
|
}) : null
|
|
152
148
|
]
|