Unverified Commit 0d8d6865 authored by Josh Story's avatar Josh Story Committed by GitHub

Use emitted app entries for post-build processing (#97139)

Route discovery currently feeds app page keys both into compilation and
into post-build work like adapters and standalone output. This instead
filters the discovered keys against app-paths-manifest after compilation
and uses that emitted set for post-build processing. Today every
discovered app entry is emitted, so this does not change behavior. It
just makes the build output, rather than the earlier discovery input,
the source of truth for work that happens after compilation.
parent b08bf488
...@@ -797,7 +797,7 @@ async function writeStandaloneDirectory( ...@@ -797,7 +797,7 @@ async function writeStandaloneDirectory(
nextBuildSpan: Span, nextBuildSpan: Span,
distDir: string, distDir: string,
pageKeys: { pages: string[]; app: string[] | undefined }, pageKeys: { pages: string[]; app: string[] | undefined },
denormalizedAppPages: string[] | undefined, appPageKeys: string[] | undefined,
outputFileTracingRoot: string, outputFileTracingRoot: string,
requiredServerFiles: RequiredServerFilesManifest, requiredServerFiles: RequiredServerFilesManifest,
middlewareManifest: MiddlewareManifest, middlewareManifest: MiddlewareManifest,
...@@ -815,7 +815,7 @@ async function writeStandaloneDirectory( ...@@ -815,7 +815,7 @@ async function writeStandaloneDirectory(
requiredServerFiles.appDir, requiredServerFiles.appDir,
distDir, distDir,
pageKeys.pages, pageKeys.pages,
denormalizedAppPages, appPageKeys,
outputFileTracingRoot, outputFileTracingRoot,
requiredServerFiles.config, requiredServerFiles.config,
middlewareManifest, middlewareManifest,
...@@ -1494,10 +1494,14 @@ export default async function build( ...@@ -1494,10 +1494,14 @@ export default async function build(
const conflictingAppPagePaths: [pagePath: string, appPath: string][] = [] const conflictingAppPagePaths: [pagePath: string, appPath: string][] = []
const appPageKeys = new Set<string>() const appPageKeys = new Set<string>()
let denormalizedAppPages: string[] | undefined
// Discovery produces the entries we ask the compiler to build. Keep this
// input separate from the entries the compiler actually emits.
let discoveredAppPageKeys: string[] | undefined
let emittedAppPageKeys: string[] | undefined
if (discovery.mappedAppPages) { if (discovery.mappedAppPages) {
denormalizedAppPages = Object.keys(discovery.mappedAppPages) discoveredAppPageKeys = Object.keys(discovery.mappedAppPages)
for (const appKey of denormalizedAppPages) { for (const appKey of discoveredAppPageKeys) {
const normalizedAppPageKey = normalizeAppPath(appKey) const normalizedAppPageKey = normalizeAppPath(appKey)
const pagePath = NextBuildContext.mappedPages[normalizedAppPageKey] const pagePath = NextBuildContext.mappedPages[normalizedAppPageKey]
if (pagePath) { if (pagePath) {
...@@ -2178,6 +2182,14 @@ export default async function build( ...@@ -2178,6 +2182,14 @@ export default async function build(
path.join(distDir, SERVER_DIRECTORY, APP_PATHS_MANIFEST) path.join(distDir, SERVER_DIRECTORY, APP_PATHS_MANIFEST)
) )
// The app paths manifest contains only entries the compiler emitted.
// Post-build consumers use this filtered list so they do not look for
// output files belonging to candidates that were not emitted.
const emittedAppPageKeySet = new Set(Object.keys(appPathsManifest))
emittedAppPageKeys = discoveredAppPageKeys?.filter((appPageKey) =>
emittedAppPageKeySet.has(appPageKey)
)
for (const key in appPathsManifest) { for (const key in appPathsManifest) {
appPathRoutes[key] = normalizeAppPath(key) appPathRoutes[key] = normalizeAppPath(key)
} }
...@@ -4454,7 +4466,7 @@ export default async function build( ...@@ -4454,7 +4466,7 @@ export default async function build(
hasInstrumentationHook, hasInstrumentationHook,
adapterPath, adapterPath,
pageKeys: pageKeys.pages, pageKeys: pageKeys.pages,
appPageKeys: denormalizedAppPages, appPageKeys: emittedAppPageKeys,
routesManifest, routesManifest,
prerenderManifest, prerenderManifest,
middlewareManifest, middlewareManifest,
...@@ -4474,7 +4486,7 @@ export default async function build( ...@@ -4474,7 +4486,7 @@ export default async function build(
nextBuildSpan, nextBuildSpan,
distDir, distDir,
pageKeys, pageKeys,
denormalizedAppPages, emittedAppPageKeys,
outputFileTracingRoot, outputFileTracingRoot,
requiredServerFilesManifest, requiredServerFilesManifest,
middlewareManifest, middlewareManifest,
......
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