Unverified Commit e09e0f5e authored by Leah's avatar Leah Committed by GitHub

chore: extract edge-app-route loader template (#56424)




Closes WEB-1705
parent 00aea747
......@@ -356,6 +356,7 @@ export function getEdgeServerEntry(opts: {
layer: WEBPACK_LAYERS.reactServerComponents,
}
}
if (isMiddlewareFile(opts.page)) {
const loaderParams: MiddlewareLoaderOptions = {
absolutePagePath: opts.absolutePagePath,
......
......@@ -19,12 +19,18 @@ const TEMPLATES_ESM_FOLDER = path.normalize(
* handle replacement values that are related to imports.
*
* @param entrypoint the entrypoint to load
* @param replacements the replacements to perform
* @param replacements string replacements to perform
* @param injections code injections to perform
* @returns the loaded file with the replacements
*/
export async function loadEntrypoint(
entrypoint: 'pages' | 'pages-api' | 'app-page' | 'app-route',
entrypoint:
| 'pages'
| 'pages-api'
| 'app-page'
| 'app-route'
| 'edge-app-route',
replacements: Record<`VAR_${string}`, string>,
injections?: Record<string, string>
): Promise<string> {
......
import { EdgeRouteModuleWrapper } from '../../server/web/edge-route-module-wrapper'
// Import the userland code.
// @ts-expect-error - replaced by webpack/turbopack loader
import * as module from 'VAR_USERLAND'
export const ComponentMod = module
export default EdgeRouteModuleWrapper.wrap(module.routeModule)
......@@ -4,6 +4,7 @@ import { NextConfig } from '../../../../server/config-shared'
import { webpack } from 'next/dist/compiled/webpack/webpack'
import { WEBPACK_RESOURCE_QUERIES } from '../../../../lib/constants'
import { MiddlewareConfig } from '../../../analysis/get-page-static-info'
import { loadEntrypoint } from '../../../load-entrypoint'
export type EdgeAppRouteLoaderQuery = {
absolutePagePath: string
......@@ -15,7 +16,7 @@ export type EdgeAppRouteLoaderQuery = {
}
const EdgeAppRouteLoader: webpack.LoaderDefinitionFunction<EdgeAppRouteLoaderQuery> =
function (this) {
async function (this) {
const {
page,
absolutePagePath,
......@@ -52,13 +53,9 @@ const EdgeAppRouteLoader: webpack.LoaderDefinitionFunction<EdgeAppRouteLoaderQue
stringifiedPagePath.length - 1
)}?${WEBPACK_RESOURCE_QUERIES.edgeSSREntry}`
return `
import { EdgeRouteModuleWrapper } from 'next/dist/esm/server/web/edge-route-module-wrapper'
import * as module from ${JSON.stringify(modulePath)}
export const ComponentMod = module
export default EdgeRouteModuleWrapper.wrap(module.routeModule)`
return await loadEntrypoint('edge-app-route', {
VAR_USERLAND: modulePath,
})
}
export default EdgeAppRouteLoader
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment