@reckona/mreact-router 0.0.90 → 0.0.91
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/dev-server.d.ts.map +1 -1
- package/dist/dev-server.js +8 -1
- package/dist/dev-server.js.map +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +46 -24
- package/dist/render.js.map +1 -1
- package/dist/vite-config.d.ts +2 -0
- package/dist/vite-config.d.ts.map +1 -1
- package/dist/vite-config.js +2 -0
- package/dist/vite-config.js.map +1 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +9 -2
- package/dist/vite.js.map +1 -1
- package/package.json +11 -11
- package/src/dev-server.ts +9 -1
- package/src/render.ts +53 -3
- package/src/vite-config.ts +6 -0
- package/src/vite.ts +16 -3
package/dist/dev-server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAItD,OAAO,EAAoC,KAAK,UAAU,EAAsB,MAAM,MAAM,CAAC;AAC7F,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAkC,KAAK,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAMhE,OAAO,EAKL,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,WAAW,qBAAsB,SAAQ,uBAAuB;IACpE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,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S,CAAC;IACrC,UAAU,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IACxC,aAAa,CAAC,EAAE,4BAA4B,GAAG,SAAS,CAAC;IACzD,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACpC,SAAS,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;CAC5C;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC;IAAE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAuHlE"}
|
package/dist/dev-server.js
CHANGED
|
@@ -17,10 +17,16 @@ export async function startDevServer(options) {
|
|
|
17
17
|
const port = options.port ?? resolved.serverPort ?? 3001;
|
|
18
18
|
const routeCache = options.routeCache ?? createMemoryRouteCache();
|
|
19
19
|
const declaredPackages = await readDeclaredProjectPackages(project.projectRoot);
|
|
20
|
+
const configImportPolicy = resolved.importPolicy;
|
|
20
21
|
const importPolicy = {
|
|
22
|
+
...configImportPolicy,
|
|
21
23
|
...options.importPolicy,
|
|
22
24
|
allowedPackages: [
|
|
23
|
-
...new Set([
|
|
25
|
+
...new Set([
|
|
26
|
+
...declaredPackages,
|
|
27
|
+
...(configImportPolicy?.allowedPackages ?? []),
|
|
28
|
+
...(options.importPolicy?.allowedPackages ?? []),
|
|
29
|
+
]),
|
|
24
30
|
],
|
|
25
31
|
};
|
|
26
32
|
let vite;
|
|
@@ -144,6 +150,7 @@ async function resolveStartDevServerProject(options) {
|
|
|
144
150
|
}
|
|
145
151
|
const config = await loadOptionalMreactRouterViteConfig(resolve(options.projectRoot ?? process.cwd()));
|
|
146
152
|
return {
|
|
153
|
+
...(config?.importPolicy === undefined ? {} : { importPolicy: config.importPolicy }),
|
|
147
154
|
project: resolveAppRouterProjectOptions({
|
|
148
155
|
...config?.project,
|
|
149
156
|
...definedProjectOptions(options),
|
package/dist/d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C;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,qBAAqB,CAAC,OAA8B;IAC3D,OAAO;QACL,GAAG,CAAC,OAAO,CAAC,iBAAiB,KAAK,SAAS;YACzC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC;QACrD,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QACnE,GAAG,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;QAClF,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;QAC5E,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;KAC7E,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,QAAwB,EAAE,KAAc;IAClE,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,2BAA2B,CAAC,CAAC;IAChE,QAAQ,CAAC,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import { createServer, type Server } from \"node:http\";\nimport type { ServerResponse } from \"node:http\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { createServer as createViteServer, type UserConfig, type ViteDevServer } from \"vite\";\nimport type { AppRouterServerActionOptions } from \"./actions.js\";\nimport { createMemoryRouteCache, type AppRouterCache } from \"./cache.js\";\nimport { resolveAppRouterProjectOptions, type AppRouterProjectOptions } from \"./config.js\";\nimport type { AppRouterImportPolicy } from \"./import-policy.js\";\nimport { createAppRouterVitePlugin } from \"./vite.js\";\nimport {\n loadMreactRouterViteConfigDetails,\n type LoadedMreactRouterViteConfig,\n} from \"./vite-config.js\";\nimport {\n emitRouterLog,\n logDurationMs,\n logNow,\n nodeRequestPath,\n type AppRouterLogger,\n} from \"./logger.js\";\nimport type { HttpUpgradeHandler } from \"./upgrade.js\";\n\nexport interface StartDevServerOptions extends AppRouterProjectOptions {\n port?: number | undefined;\n hostname?: string;\n importPolicy?: AppRouterImportPolicy | undefined;\n logger?: AppRouterLogger | undefined;\n routeCache?: AppRouterCache | undefined;\n serverActions?: AppRouterServerActionOptions | undefined;\n viteConfig?: UserConfig | undefined;\n onUpgrade?: HttpUpgradeHandler | undefined;\n}\n\nexport async function startDevServer(\n options: StartDevServerOptions,\n): Promise<{ close(): Promise<void>; server: Server; url: string }> {\n const hostname = options.hostname ?? \"127.0.0.1\";\n const resolved = await resolveStartDevServerProject(options);\n const project = resolved.project;\n const userViteConfig = options.viteConfig ?? resolved.viteConfig ?? {};\n const userViteServerConfig =\n typeof userViteConfig.server === \"object\" ? userViteConfig.server : {};\n const userHmrConfig =\n typeof userViteServerConfig.hmr === \"object\" ? userViteServerConfig.hmr : {};\n const port = options.port ?? resolved.serverPort ?? 3001;\n const routeCache = options.routeCache ?? createMemoryRouteCache();\n const declaredPackages = await readDeclaredProjectPackages(project.projectRoot);\n const importPolicy: AppRouterImportPolicy = {\n ...options.importPolicy,\n allowedPackages: [\n ...new Set([...declaredPackages, ...(options.importPolicy?.allowedPackages ?? [])]),\n ],\n };\n let vite: ViteDevServer | undefined;\n const server = createServer((incoming, outgoing) => {\n const logger = options.logger;\n const startedAt = logger === undefined ? undefined : logNow();\n const logFields =\n logger === undefined\n ? undefined\n : {\n method: incoming.method ?? \"GET\",\n path: nodeRequestPath(incoming.url),\n runtime: \"node\" as const,\n };\n\n if (logger !== undefined && logFields !== undefined && startedAt !== undefined) {\n emitRouterLog(logger, \"info\", {\n ...logFields,\n type: \"router:request:start\",\n });\n outgoing.once(\"finish\", () => {\n emitRouterLog(logger, \"info\", {\n ...logFields,\n durationMs: logDurationMs(startedAt),\n status: outgoing.statusCode,\n type: \"router:request:end\",\n });\n });\n }\n\n if (vite === undefined) {\n sendDevServerError(outgoing, new Error(\"Vite dev server is not initialized.\"));\n return;\n }\n\n vite.middlewares(incoming, outgoing, (error?: unknown) => {\n if (error !== undefined) {\n if (error instanceof Error) {\n vite?.ssrFixStacktrace(error);\n }\n sendDevServerError(outgoing, error);\n return;\n }\n\n outgoing.statusCode = 404;\n outgoing.setHeader(\"content-type\", \"text/plain; charset=utf-8\");\n outgoing.end(\"Not Found\");\n });\n });\n\n if (options.onUpgrade !== undefined) {\n server.on(\"upgrade\", options.onUpgrade);\n }\n\n vite = await createViteServer({\n ...userViteConfig,\n appType: \"custom\",\n configFile: false,\n root: project.projectRoot,\n server: {\n ...userViteServerConfig,\n hmr: { ...userHmrConfig, server },\n middlewareMode: true,\n },\n plugins: [\n ...(userViteConfig.plugins ?? []),\n createAppRouterVitePlugin({\n allowedSourceDirs: project.allowedSourceDirs,\n projectRoot: project.projectRoot,\n publicDir: project.publicDir,\n routesDir: project.routesDir,\n importPolicy,\n routeCache,\n serverActions: options.serverActions,\n }),\n ],\n });\n\n try {\n await listenDevHttpServer(server, port, hostname);\n } catch (error) {\n await vite.close();\n throw error;\n }\n const address = server.address();\n const actualPort = typeof address === \"object\" && address !== null ? address.port : port;\n\n return {\n server,\n url: `http://${hostname}:${actualPort}`,\n close: async () => {\n await vite?.close();\n await new Promise<void>((resolve, reject) => {\n server.close((error) => (error ? reject(error) : resolve()));\n });\n },\n };\n}\n\nfunction listenDevHttpServer(server: Server, port: number, hostname: string): Promise<void> {\n return new Promise((resolve, reject) => {\n const onError = (error: Error) => {\n server.off(\"listening\", onListening);\n reject(formatDevListenError(error, hostname, port));\n };\n const onListening = () => {\n server.off(\"error\", onError);\n resolve();\n };\n\n server.once(\"error\", onError);\n server.once(\"listening\", onListening);\n server.listen(port, hostname);\n });\n}\n\nfunction formatDevListenError(error: Error, hostname: string, port: number): Error {\n if (isNodeErrorCode(error, \"EADDRINUSE\")) {\n return new Error(\n `mreact dev server could not start because ${hostname}:${port} is already in use. Stop the process using that port or run with PORT=<free-port>.`,\n );\n }\n\n return error;\n}\n\nfunction isNodeErrorCode(error: unknown, code: string): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n (error as { code?: unknown }).code === code\n );\n}\n\nasync function resolveStartDevServerProject(options: StartDevServerOptions): Promise<{\n project: ReturnType<typeof resolveAppRouterProjectOptions>;\n serverPort?: number | undefined;\n viteConfig?: LoadedMreactRouterViteConfig[\"viteConfig\"];\n}> {\n if (options.appDir !== undefined || options.routesDir !== undefined) {\n return { project: resolveAppRouterProjectOptions(options) };\n }\n\n const config = await loadOptionalMreactRouterViteConfig(\n resolve(options.projectRoot ?? process.cwd()),\n );\n\n return {\n project: resolveAppRouterProjectOptions({\n ...config?.project,\n ...definedProjectOptions(options),\n }),\n serverPort: config?.serverPort,\n viteConfig: config?.viteConfig,\n };\n}\n\nasync function loadOptionalMreactRouterViteConfig(cwd: string) {\n try {\n return await loadMreactRouterViteConfigDetails({\n command: \"serve\",\n cwd,\n });\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"vite.config.ts is required\")) {\n return undefined;\n }\n\n throw error;\n }\n}\n\nasync function readDeclaredProjectPackages(projectRoot: string): Promise<string[]> {\n try {\n const json = JSON.parse(await readFile(resolve(projectRoot, \"package.json\"), \"utf8\")) as {\n dependencies?: Record<string, unknown> | undefined;\n devDependencies?: Record<string, unknown> | undefined;\n optionalDependencies?: Record<string, unknown> | undefined;\n peerDependencies?: Record<string, unknown> | undefined;\n };\n\n return [\n ...Object.keys(json.dependencies ?? {}),\n ...Object.keys(json.devDependencies ?? {}),\n ...Object.keys(json.optionalDependencies ?? {}),\n ...Object.keys(json.peerDependencies ?? {}),\n ];\n } catch {\n return [];\n }\n}\n\nfunction definedProjectOptions(options: StartDevServerOptions): AppRouterProjectOptions {\n return {\n ...(options.allowedSourceDirs === undefined\n ? {}\n : { allowedSourceDirs: options.allowedSourceDirs }),\n ...(options.appDir === undefined ? {} : { appDir: options.appDir }),\n ...(options.projectRoot === undefined ? {} : { projectRoot: options.projectRoot }),\n ...(options.publicDir === undefined ? {} : { publicDir: options.publicDir }),\n ...(options.routesDir === undefined ? {} : { routesDir: options.routesDir }),\n };\n}\n\nfunction sendDevServerError(outgoing: ServerResponse, error: unknown): void {\n outgoing.statusCode = 500;\n outgoing.setHeader(\"content-type\", \"text/plain; charset=utf-8\");\n outgoing.end(error instanceof Error ? error.stack : String(error));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dev-server.js","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAuC,MAAM,MAAM,CAAC;AAE7F,OAAO,EAAE,sBAAsB,EAAuB,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,8BAA8B,EAAgC,MAAM,aAAa,CAAC;AAE3F,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EACL,iCAAiC,GAElC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,aAAa,EACb,aAAa,EACb,MAAM,EACN,eAAe,GAEhB,MAAM,aAAa,CAAC;AAcrB,MAAM,CAAC,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AAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QACnE,GAAG,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;QAClF,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;QAC5E,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;KAC7E,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,QAAwB,EAAE,KAAc;IAClE,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,2BAA2B,CAAC,CAAC;IAChE,QAAQ,CAAC,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import { createServer, type Server } from \"node:http\";\nimport type { ServerResponse } from \"node:http\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { createServer as createViteServer, type UserConfig, type ViteDevServer } from \"vite\";\nimport type { AppRouterServerActionOptions } from \"./actions.js\";\nimport { createMemoryRouteCache, type AppRouterCache } from \"./cache.js\";\nimport { resolveAppRouterProjectOptions, type AppRouterProjectOptions } from \"./config.js\";\nimport type { AppRouterImportPolicy } from \"./import-policy.js\";\nimport { createAppRouterVitePlugin } from \"./vite.js\";\nimport {\n loadMreactRouterViteConfigDetails,\n type LoadedMreactRouterViteConfig,\n} from \"./vite-config.js\";\nimport {\n emitRouterLog,\n logDurationMs,\n logNow,\n nodeRequestPath,\n type AppRouterLogger,\n} from \"./logger.js\";\nimport type { HttpUpgradeHandler } from \"./upgrade.js\";\n\nexport interface StartDevServerOptions extends AppRouterProjectOptions {\n port?: number | undefined;\n hostname?: string;\n importPolicy?: AppRouterImportPolicy | undefined;\n logger?: AppRouterLogger | undefined;\n routeCache?: AppRouterCache | undefined;\n serverActions?: AppRouterServerActionOptions | undefined;\n viteConfig?: UserConfig | undefined;\n onUpgrade?: HttpUpgradeHandler | undefined;\n}\n\nexport async function startDevServer(\n options: StartDevServerOptions,\n): Promise<{ close(): Promise<void>; server: Server; url: string }> {\n const hostname = options.hostname ?? \"127.0.0.1\";\n const resolved = await resolveStartDevServerProject(options);\n const project = resolved.project;\n const userViteConfig = options.viteConfig ?? resolved.viteConfig ?? {};\n const userViteServerConfig =\n typeof userViteConfig.server === \"object\" ? userViteConfig.server : {};\n const userHmrConfig =\n typeof userViteServerConfig.hmr === \"object\" ? userViteServerConfig.hmr : {};\n const port = options.port ?? resolved.serverPort ?? 3001;\n const routeCache = options.routeCache ?? createMemoryRouteCache();\n const declaredPackages = await readDeclaredProjectPackages(project.projectRoot);\n const configImportPolicy = resolved.importPolicy;\n const importPolicy: AppRouterImportPolicy = {\n ...configImportPolicy,\n ...options.importPolicy,\n allowedPackages: [\n ...new Set([\n ...declaredPackages,\n ...(configImportPolicy?.allowedPackages ?? []),\n ...(options.importPolicy?.allowedPackages ?? []),\n ]),\n ],\n };\n let vite: ViteDevServer | undefined;\n const server = createServer((incoming, outgoing) => {\n const logger = options.logger;\n const startedAt = logger === undefined ? undefined : logNow();\n const logFields =\n logger === undefined\n ? undefined\n : {\n method: incoming.method ?? \"GET\",\n path: nodeRequestPath(incoming.url),\n runtime: \"node\" as const,\n };\n\n if (logger !== undefined && logFields !== undefined && startedAt !== undefined) {\n emitRouterLog(logger, \"info\", {\n ...logFields,\n type: \"router:request:start\",\n });\n outgoing.once(\"finish\", () => {\n emitRouterLog(logger, \"info\", {\n ...logFields,\n durationMs: logDurationMs(startedAt),\n status: outgoing.statusCode,\n type: \"router:request:end\",\n });\n });\n }\n\n if (vite === undefined) {\n sendDevServerError(outgoing, new Error(\"Vite dev server is not initialized.\"));\n return;\n }\n\n vite.middlewares(incoming, outgoing, (error?: unknown) => {\n if (error !== undefined) {\n if (error instanceof Error) {\n vite?.ssrFixStacktrace(error);\n }\n sendDevServerError(outgoing, error);\n return;\n }\n\n outgoing.statusCode = 404;\n outgoing.setHeader(\"content-type\", \"text/plain; charset=utf-8\");\n outgoing.end(\"Not Found\");\n });\n });\n\n if (options.onUpgrade !== undefined) {\n server.on(\"upgrade\", options.onUpgrade);\n }\n\n vite = await createViteServer({\n ...userViteConfig,\n appType: \"custom\",\n configFile: false,\n root: project.projectRoot,\n server: {\n ...userViteServerConfig,\n hmr: { ...userHmrConfig, server },\n middlewareMode: true,\n },\n plugins: [\n ...(userViteConfig.plugins ?? []),\n createAppRouterVitePlugin({\n allowedSourceDirs: project.allowedSourceDirs,\n projectRoot: project.projectRoot,\n publicDir: project.publicDir,\n routesDir: project.routesDir,\n importPolicy,\n routeCache,\n serverActions: options.serverActions,\n }),\n ],\n });\n\n try {\n await listenDevHttpServer(server, port, hostname);\n } catch (error) {\n await vite.close();\n throw error;\n }\n const address = server.address();\n const actualPort = typeof address === \"object\" && address !== null ? address.port : port;\n\n return {\n server,\n url: `http://${hostname}:${actualPort}`,\n close: async () => {\n await vite?.close();\n await new Promise<void>((resolve, reject) => {\n server.close((error) => (error ? reject(error) : resolve()));\n });\n },\n };\n}\n\nfunction listenDevHttpServer(server: Server, port: number, hostname: string): Promise<void> {\n return new Promise((resolve, reject) => {\n const onError = (error: Error) => {\n server.off(\"listening\", onListening);\n reject(formatDevListenError(error, hostname, port));\n };\n const onListening = () => {\n server.off(\"error\", onError);\n resolve();\n };\n\n server.once(\"error\", onError);\n server.once(\"listening\", onListening);\n server.listen(port, hostname);\n });\n}\n\nfunction formatDevListenError(error: Error, hostname: string, port: number): Error {\n if (isNodeErrorCode(error, \"EADDRINUSE\")) {\n return new Error(\n `mreact dev server could not start because ${hostname}:${port} is already in use. Stop the process using that port or run with PORT=<free-port>.`,\n );\n }\n\n return error;\n}\n\nfunction isNodeErrorCode(error: unknown, code: string): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n (error as { code?: unknown }).code === code\n );\n}\n\nasync function resolveStartDevServerProject(options: StartDevServerOptions): Promise<{\n project: ReturnType<typeof resolveAppRouterProjectOptions>;\n serverPort?: number | undefined;\n importPolicy?: LoadedMreactRouterViteConfig[\"importPolicy\"];\n viteConfig?: LoadedMreactRouterViteConfig[\"viteConfig\"];\n}> {\n if (options.appDir !== undefined || options.routesDir !== undefined) {\n return { project: resolveAppRouterProjectOptions(options) };\n }\n\n const config = await loadOptionalMreactRouterViteConfig(\n resolve(options.projectRoot ?? process.cwd()),\n );\n\n return {\n ...(config?.importPolicy === undefined ? {} : { importPolicy: config.importPolicy }),\n project: resolveAppRouterProjectOptions({\n ...config?.project,\n ...definedProjectOptions(options),\n }),\n serverPort: config?.serverPort,\n viteConfig: config?.viteConfig,\n };\n}\n\nasync function loadOptionalMreactRouterViteConfig(cwd: string) {\n try {\n return await loadMreactRouterViteConfigDetails({\n command: \"serve\",\n cwd,\n });\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"vite.config.ts is required\")) {\n return undefined;\n }\n\n throw error;\n }\n}\n\nasync function readDeclaredProjectPackages(projectRoot: string): Promise<string[]> {\n try {\n const json = JSON.parse(await readFile(resolve(projectRoot, \"package.json\"), \"utf8\")) as {\n dependencies?: Record<string, unknown> | undefined;\n devDependencies?: Record<string, unknown> | undefined;\n optionalDependencies?: Record<string, unknown> | undefined;\n peerDependencies?: Record<string, unknown> | undefined;\n };\n\n return [\n ...Object.keys(json.dependencies ?? {}),\n ...Object.keys(json.devDependencies ?? {}),\n ...Object.keys(json.optionalDependencies ?? {}),\n ...Object.keys(json.peerDependencies ?? {}),\n ];\n } catch {\n return [];\n }\n}\n\nfunction definedProjectOptions(options: StartDevServerOptions): AppRouterProjectOptions {\n return {\n ...(options.allowedSourceDirs === undefined\n ? {}\n : { allowedSourceDirs: options.allowedSourceDirs }),\n ...(options.appDir === undefined ? {} : { appDir: options.appDir }),\n ...(options.projectRoot === undefined ? {} : { projectRoot: options.projectRoot }),\n ...(options.publicDir === undefined ? {} : { publicDir: options.publicDir }),\n ...(options.routesDir === undefined ? {} : { routesDir: options.routesDir }),\n };\n}\n\nfunction sendDevServerError(outgoing: ServerResponse, error: unknown): void {\n outgoing.statusCode = 500;\n outgoing.setHeader(\"content-type\", \"text/plain; charset=utf-8\");\n outgoing.end(error instanceof Error ? error.stack : String(error));\n}\n"]}
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAUA,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAC;AAwB/B,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,2BAA2B,EAGjC,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,KAAK,cAAc,EAMpB,MAAM,YAAY,CAAC;AAUpB,OAAO,EAAqC,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEnG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,EAAmC,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAU7F,OAAO,EAAwC,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EAKL,KAAK,sBAAsB,EAC5B,MAAM,kBAAkB,CAAC;AAU1B,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EAOL,KAAK,sBAAsB,EAC5B,MAAM,iBAAiB,CAAC;AA2CzB,UA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AG,SAAS,CAAC;CACnD,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBlB;AAslDD,wBAAsB,2BAA2B,CAAC,OAAO,EAAE;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IAC/D,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IACjD,WAAW,CAAC,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,CAAC;CACnD,GAAG,OAAO,CAAC,MAAM,CAAC,CAuBlB"}
|
package/dist/render.js
CHANGED
|
@@ -626,7 +626,7 @@ async function renderAppRequestInternal(options) {
|
|
|
626
626
|
params: matched.params,
|
|
627
627
|
queryClient,
|
|
628
628
|
request: options.request,
|
|
629
|
-
}, matched.route.file, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins));
|
|
629
|
+
}, matched.route.file, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins, undefined, options.importPolicy));
|
|
630
630
|
const pageHtml = renderedPage.html;
|
|
631
631
|
const pageHtmlForLayout = clientRoute
|
|
632
632
|
? withHydrationMarkers({
|
|
@@ -664,6 +664,7 @@ async function renderAppRequestInternal(options) {
|
|
|
664
664
|
clientRouteInferenceCache,
|
|
665
665
|
timing,
|
|
666
666
|
vitePlugins: options.vitePlugins,
|
|
667
|
+
importPolicy: options.importPolicy,
|
|
667
668
|
}));
|
|
668
669
|
const metadata = await loadComposedRouteMetadata({
|
|
669
670
|
appDir: options.appDir,
|
|
@@ -750,6 +751,7 @@ async function renderAppRequestInternal(options) {
|
|
|
750
751
|
serverSourceFiles: options.serverSourceFiles,
|
|
751
752
|
vitePlugins: options.vitePlugins,
|
|
752
753
|
clientRouteInferenceCache,
|
|
754
|
+
importPolicy: options.importPolicy,
|
|
753
755
|
script: clientScript,
|
|
754
756
|
clientReferenceManifest: output.metadata.clientReferenceManifest,
|
|
755
757
|
});
|
|
@@ -780,6 +782,7 @@ async function renderAppRequestInternal(options) {
|
|
|
780
782
|
serverSourceFiles: options.serverSourceFiles,
|
|
781
783
|
vitePlugins: options.vitePlugins,
|
|
782
784
|
clientRouteInferenceCache,
|
|
785
|
+
importPolicy: options.importPolicy,
|
|
783
786
|
clientRoute,
|
|
784
787
|
script: clientScript,
|
|
785
788
|
clientReferenceManifest: output.metadata.clientReferenceManifest,
|
|
@@ -827,7 +830,7 @@ async function renderAppRequestInternal(options) {
|
|
|
827
830
|
params: matched.params,
|
|
828
831
|
queryClient,
|
|
829
832
|
request: options.request,
|
|
830
|
-
}, matched.route.file, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins, timing));
|
|
833
|
+
}, matched.route.file, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins, timing, options.importPolicy));
|
|
831
834
|
finishRenderTimingPhase(timing, phaseStartedAt, "pageRenderMs");
|
|
832
835
|
const pageHtml = renderedPage.html;
|
|
833
836
|
// Wrap the page (not the full document) with the hydration marker so
|
|
@@ -1670,9 +1673,9 @@ async function runServerModule(code, props, sourcefile, serverModules, serverMod
|
|
|
1670
1673
|
const component = await loadServerComponent(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins);
|
|
1671
1674
|
return component(props);
|
|
1672
1675
|
}
|
|
1673
|
-
async function runServerModuleWithSlots(code, props, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins, timing) {
|
|
1676
|
+
async function runServerModuleWithSlots(code, props, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins, timing, importPolicy) {
|
|
1674
1677
|
const moduleLoadStartedAt = renderTimingPhaseStartedAt(timing);
|
|
1675
|
-
const module = await loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins);
|
|
1678
|
+
const module = await loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins, importPolicy);
|
|
1676
1679
|
finishRenderTimingPhase(timing, moduleLoadStartedAt, "pageModuleLoadMs");
|
|
1677
1680
|
const component = selectServerComponent(module);
|
|
1678
1681
|
const componentStartedAt = renderTimingPhaseStartedAt(timing);
|
|
@@ -1686,7 +1689,7 @@ async function runServerModuleWithSlots(code, props, sourcefile, serverModules,
|
|
|
1686
1689
|
slots,
|
|
1687
1690
|
};
|
|
1688
1691
|
}
|
|
1689
|
-
async function loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins) {
|
|
1692
|
+
async function loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins, importPolicy) {
|
|
1690
1693
|
const artifact = serverModules?.get(sourcefile)?.string;
|
|
1691
1694
|
const codeHash = memoizedHashText(code);
|
|
1692
1695
|
const prebuiltCode = prebuiltServerComponentModuleCode(artifact, code, codeHash);
|
|
@@ -1702,11 +1705,20 @@ async function loadServerModule(code, sourcefile, serverModules, serverModuleCac
|
|
|
1702
1705
|
const moduleCode = prebuiltCode ?? code;
|
|
1703
1706
|
const cacheKey = serverModuleCacheVersion === undefined
|
|
1704
1707
|
? undefined
|
|
1705
|
-
: `server-component:${serverModuleCacheVersion}:${sourcefile}:${moduleCode === code ? codeHash : memoizedHashText(moduleCode)}:${vitePluginsCacheKey(vitePlugins)}`;
|
|
1708
|
+
: `server-component:${serverModuleCacheVersion}:${sourcefile}:${moduleCode === code ? codeHash : memoizedHashText(moduleCode)}:${importPolicyCacheKey(importPolicy)}:${vitePluginsCacheKey(vitePlugins)}`;
|
|
1706
1709
|
return await importAppRouterSourceModule({
|
|
1707
1710
|
cacheKey,
|
|
1708
1711
|
code: moduleCode,
|
|
1709
1712
|
label: `server-component:${sourcefile}`,
|
|
1713
|
+
plugins: importPolicy === undefined
|
|
1714
|
+
? undefined
|
|
1715
|
+
: [
|
|
1716
|
+
createAppRouterImportPolicyPlugin({
|
|
1717
|
+
appDir: dirname(sourcefile),
|
|
1718
|
+
importPolicy,
|
|
1719
|
+
label: "Server component",
|
|
1720
|
+
}),
|
|
1721
|
+
],
|
|
1710
1722
|
...(prebuiltCode === undefined
|
|
1711
1723
|
? {
|
|
1712
1724
|
resolveDir: dirname(sourcefile),
|
|
@@ -1732,8 +1744,8 @@ async function importBuiltServerModuleFile(options) {
|
|
|
1732
1744
|
file: options.file,
|
|
1733
1745
|
});
|
|
1734
1746
|
}
|
|
1735
|
-
async function loadServerComponent(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins) {
|
|
1736
|
-
const module = await loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins);
|
|
1747
|
+
async function loadServerComponent(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins, importPolicy) {
|
|
1748
|
+
const module = await loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins, importPolicy);
|
|
1737
1749
|
return selectServerComponent(module);
|
|
1738
1750
|
}
|
|
1739
1751
|
function selectServerComponent(module) {
|
|
@@ -1761,8 +1773,9 @@ function runServerStreamModule(code, options) {
|
|
|
1761
1773
|
serverModules: options.serverModules,
|
|
1762
1774
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
1763
1775
|
vitePlugins: options.vitePlugins,
|
|
1776
|
+
importPolicy: options.importPolicy,
|
|
1764
1777
|
});
|
|
1765
|
-
const layoutShells = await layoutShellsForPage(options.appDir, options.pageFile, options.props, slots, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.clientRouteInferenceCache, options.vitePlugins);
|
|
1778
|
+
const layoutShells = await layoutShellsForPage(options.appDir, options.pageFile, options.props, slots, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.clientRouteInferenceCache, options.vitePlugins, options.importPolicy);
|
|
1766
1779
|
const marker = options.clientRoute
|
|
1767
1780
|
? hydrationMarkerParts({
|
|
1768
1781
|
assetBaseUrl: options.assetBaseUrl,
|
|
@@ -1786,7 +1799,7 @@ function runServerStreamModule(code, options) {
|
|
|
1786
1799
|
sink.append(shell.prefix);
|
|
1787
1800
|
}
|
|
1788
1801
|
sink.append(marker?.prefix ?? "");
|
|
1789
|
-
await appendServerStreamModule(code, sink, options.props, options.pageFile, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins);
|
|
1802
|
+
await appendServerStreamModule(code, sink, options.props, options.pageFile, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins, options.importPolicy);
|
|
1790
1803
|
sink.append(marker?.suffix ?? "");
|
|
1791
1804
|
for (const shell of [...layoutShells].reverse()) {
|
|
1792
1805
|
sink.append(shell.suffix);
|
|
@@ -1895,7 +1908,7 @@ async function runServerStreamModuleWithLoading(code, options) {
|
|
|
1895
1908
|
queryClient: options.queryClient,
|
|
1896
1909
|
request: options.request,
|
|
1897
1910
|
};
|
|
1898
|
-
const layoutShells = await layoutShellsForPage(options.appDir, options.pageFile, loadingProps, {}, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.clientRouteInferenceCache, options.vitePlugins);
|
|
1911
|
+
const layoutShells = await layoutShellsForPage(options.appDir, options.pageFile, loadingProps, {}, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.clientRouteInferenceCache, options.vitePlugins, options.importPolicy);
|
|
1899
1912
|
const loadingHtml = await renderServerFileToHtml(options.loadingFile, loadingProps, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.vitePlugins);
|
|
1900
1913
|
const marker = options.clientRoute
|
|
1901
1914
|
? hydrationMarkerParts({
|
|
@@ -1926,7 +1939,7 @@ async function runServerStreamModuleWithLoading(code, options) {
|
|
|
1926
1939
|
params: options.params,
|
|
1927
1940
|
queryClient: options.queryClient,
|
|
1928
1941
|
request: options.request,
|
|
1929
|
-
}, options.pageFile, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins);
|
|
1942
|
+
}, options.pageFile, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins, options.importPolicy);
|
|
1930
1943
|
}, {
|
|
1931
1944
|
placeholder(boundarySink) {
|
|
1932
1945
|
boundarySink.append(loadingHtml);
|
|
@@ -1965,8 +1978,8 @@ async function renderVisibleOutOfOrderFragment(sink, id, value, render, options)
|
|
|
1965
1978
|
await fragmentSink.drain();
|
|
1966
1979
|
sink.append(`<template data-mreact-oob-fragment="${escapeHtmlAttribute(id)}">${fragmentSink.toString()}</template>`);
|
|
1967
1980
|
}
|
|
1968
|
-
async function appendServerStreamModule(code, sink, props, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins) {
|
|
1969
|
-
const module = await loadServerStreamModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins);
|
|
1981
|
+
async function appendServerStreamModule(code, sink, props, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins, importPolicy) {
|
|
1982
|
+
const module = await loadServerStreamModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins, importPolicy);
|
|
1970
1983
|
const component = selectStreamComponent(module);
|
|
1971
1984
|
await component(sink, props);
|
|
1972
1985
|
}
|
|
@@ -1974,7 +1987,7 @@ async function renderServerStreamSlots(code, options) {
|
|
|
1974
1987
|
if (!hasRouteSlotsExport(code)) {
|
|
1975
1988
|
return {};
|
|
1976
1989
|
}
|
|
1977
|
-
const module = await loadServerStreamModule(code, options.pageFile, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins);
|
|
1990
|
+
const module = await loadServerStreamModule(code, options.pageFile, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins, options.importPolicy);
|
|
1978
1991
|
if (module.slots === undefined) {
|
|
1979
1992
|
return {};
|
|
1980
1993
|
}
|
|
@@ -1994,7 +2007,7 @@ async function renderServerStreamSlots(code, options) {
|
|
|
1994
2007
|
function hasRouteSlotsExport(code) {
|
|
1995
2008
|
return /^\s*export\s+const\s+slots\s*=/m.test(code);
|
|
1996
2009
|
}
|
|
1997
|
-
async function loadServerStreamModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins) {
|
|
2010
|
+
async function loadServerStreamModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins, importPolicy) {
|
|
1998
2011
|
const artifactCode = serverModules?.get(sourcefile)?.stream;
|
|
1999
2012
|
const codeHash = memoizedHashText(code);
|
|
2000
2013
|
const prebuiltCode = prebuiltServerComponentModuleCode(artifactCode, code, codeHash);
|
|
@@ -2010,11 +2023,20 @@ async function loadServerStreamModule(code, sourcefile, serverModules, serverMod
|
|
|
2010
2023
|
const moduleCode = prebuiltCode ?? code;
|
|
2011
2024
|
const cacheKey = serverModuleCacheVersion === undefined
|
|
2012
2025
|
? undefined
|
|
2013
|
-
: `server-stream-component:${serverModuleCacheVersion}:${sourcefile}:${moduleCode === code ? codeHash : memoizedHashText(moduleCode)}:${vitePluginsCacheKey(vitePlugins)}`;
|
|
2026
|
+
: `server-stream-component:${serverModuleCacheVersion}:${sourcefile}:${moduleCode === code ? codeHash : memoizedHashText(moduleCode)}:${importPolicyCacheKey(importPolicy)}:${vitePluginsCacheKey(vitePlugins)}`;
|
|
2014
2027
|
return await importAppRouterSourceModule({
|
|
2015
2028
|
cacheKey,
|
|
2016
2029
|
code: moduleCode,
|
|
2017
2030
|
label: `server-stream-component:${sourcefile}`,
|
|
2031
|
+
plugins: importPolicy === undefined
|
|
2032
|
+
? undefined
|
|
2033
|
+
: [
|
|
2034
|
+
createAppRouterImportPolicyPlugin({
|
|
2035
|
+
appDir: dirname(sourcefile),
|
|
2036
|
+
importPolicy,
|
|
2037
|
+
label: "Server stream component",
|
|
2038
|
+
}),
|
|
2039
|
+
],
|
|
2018
2040
|
...(prebuiltCode === undefined
|
|
2019
2041
|
? {
|
|
2020
2042
|
resolveDir: dirname(sourcefile),
|
|
@@ -2043,7 +2065,7 @@ async function applyLayouts(options) {
|
|
|
2043
2065
|
let shellHasOutOfOrderBoundary = false;
|
|
2044
2066
|
const slotContext = createSlotRenderContext(options.slots);
|
|
2045
2067
|
for (const shell of layoutFiles.reverse()) {
|
|
2046
|
-
const rendered = await renderShellPrefixSuffix(options.appDir, shell, options.props, slotContext, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.clientRouteInferenceCache, options.timing, options.vitePlugins);
|
|
2068
|
+
const rendered = await renderShellPrefixSuffix(options.appDir, shell, options.props, slotContext, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.clientRouteInferenceCache, options.timing, options.vitePlugins, options.importPolicy);
|
|
2047
2069
|
shellHasOutOfOrderBoundary ||= rendered.hasOutOfOrderBoundary;
|
|
2048
2070
|
html = `${rendered.prefix}${html}${rendered.suffix}`;
|
|
2049
2071
|
}
|
|
@@ -2062,12 +2084,12 @@ async function applyLayouts(options) {
|
|
|
2062
2084
|
await sink.drain();
|
|
2063
2085
|
return sink.toString();
|
|
2064
2086
|
}
|
|
2065
|
-
async function layoutShellsForPage(appDir, pageFile, props, slots, serverModules, serverModuleCacheVersion, serverSourceFiles, clientRouteInferenceCache, vitePlugins) {
|
|
2087
|
+
async function layoutShellsForPage(appDir, pageFile, props, slots, serverModules, serverModuleCacheVersion, serverSourceFiles, clientRouteInferenceCache, vitePlugins, importPolicy) {
|
|
2066
2088
|
const layoutFiles = await shellFilesForPage(appDir, pageFile, serverModuleCacheVersion);
|
|
2067
2089
|
const shells = [];
|
|
2068
2090
|
const slotContext = createSlotRenderContext(slots);
|
|
2069
2091
|
for (const shell of layoutFiles) {
|
|
2070
|
-
shells.push(await renderShellPrefixSuffix(appDir, shell, props, slotContext, serverModules, serverModuleCacheVersion, serverSourceFiles, clientRouteInferenceCache, undefined, vitePlugins));
|
|
2092
|
+
shells.push(await renderShellPrefixSuffix(appDir, shell, props, slotContext, serverModules, serverModuleCacheVersion, serverSourceFiles, clientRouteInferenceCache, undefined, vitePlugins, importPolicy));
|
|
2071
2093
|
}
|
|
2072
2094
|
warnUnconsumedRouteSlots({
|
|
2073
2095
|
appDir,
|
|
@@ -2077,11 +2099,11 @@ async function layoutShellsForPage(appDir, pageFile, props, slots, serverModules
|
|
|
2077
2099
|
});
|
|
2078
2100
|
return shells;
|
|
2079
2101
|
}
|
|
2080
|
-
async function renderShellPrefixSuffix(appDir, shell, props, slotContext, serverModules, serverModuleCacheVersion, serverSourceFiles, clientRouteInferenceCache, timing, vitePlugins) {
|
|
2102
|
+
async function renderShellPrefixSuffix(appDir, shell, props, slotContext, serverModules, serverModuleCacheVersion, serverSourceFiles, clientRouteInferenceCache, timing, vitePlugins, importPolicy) {
|
|
2081
2103
|
const hasNamedSlots = Object.keys(slotContext.namedSlots).length > 0;
|
|
2082
2104
|
const cacheKey = serverModuleCacheVersion === undefined || hasNamedSlots || shell.kind === "template"
|
|
2083
2105
|
? undefined
|
|
2084
|
-
: `${appDir}\0${shell.file}\0${serverModuleCacheVersion}\0${vitePluginsCacheKey(vitePlugins)}`;
|
|
2106
|
+
: `${appDir}\0${shell.file}\0${serverModuleCacheVersion}\0${importPolicyCacheKey(importPolicy)}\0${vitePluginsCacheKey(vitePlugins)}`;
|
|
2085
2107
|
if (cacheKey !== undefined) {
|
|
2086
2108
|
const cached = readRouterRuntimeCacheEntry(renderedShellCache, cacheKey, renderedShellCacheCounters);
|
|
2087
2109
|
if (cached !== undefined && cached !== "impure") {
|
|
@@ -2125,8 +2147,8 @@ async function renderShellPrefixSuffix(appDir, shell, props, slotContext, server
|
|
|
2125
2147
|
}
|
|
2126
2148
|
phaseStartedAt = renderTimingPhaseStartedAt(timing);
|
|
2127
2149
|
const component = shellUsesAwait
|
|
2128
|
-
? selectStreamComponent(await loadServerStreamModule(output.code, shell.file, serverModules, serverModuleCacheVersion, vitePlugins))
|
|
2129
|
-
: await loadServerComponent(output.code, shell.file, serverModules, serverModuleCacheVersion, vitePlugins);
|
|
2150
|
+
? selectStreamComponent(await loadServerStreamModule(output.code, shell.file, serverModules, serverModuleCacheVersion, vitePlugins, importPolicy))
|
|
2151
|
+
: await loadServerComponent(output.code, shell.file, serverModules, serverModuleCacheVersion, vitePlugins, importPolicy);
|
|
2130
2152
|
addRenderTimingPhaseDuration(timing, phaseStartedAt, "layoutModuleLoadMs");
|
|
2131
2153
|
phaseStartedAt = renderTimingPhaseStartedAt(timing);
|
|
2132
2154
|
const layoutHtml = shellUsesAwait
|