Unverified Commit 94ca98c2 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

fix some small turbopack issues (#59171)

### What?

* remove console.log
* avoid duplicate chunks in app-build-manifest.json
* avoid mutation and duplication in middleware-manifest.json


Closes PACK-2066
parent 8ff1368f
use std::collections::HashMap; use std::collections::HashMap;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use indexmap::IndexSet;
use next_core::{ use next_core::{
app_structure::{ app_structure::{
get_entrypoints, Entrypoint as AppEntrypoint, Entrypoints as AppEntrypoints, LoaderTree, get_entrypoints, Entrypoint as AppEntrypoint, Entrypoints as AppEntrypoints, LoaderTree,
...@@ -626,9 +627,9 @@ impl AppEndpoint { ...@@ -626,9 +627,9 @@ impl AppEndpoint {
); );
let client_references_chunks_ref = client_references_chunks.await?; let client_references_chunks_ref = client_references_chunks.await?;
let mut entry_client_chunks = vec![]; let mut entry_client_chunks = IndexSet::new();
// TODO(alexkirsz) In which manifest does this go? // TODO(alexkirsz) In which manifest does this go?
let mut entry_ssr_chunks = vec![]; let mut entry_ssr_chunks = IndexSet::new();
for client_reference in app_entry_client_references.iter() { for client_reference in app_entry_client_references.iter() {
let client_reference_chunks = client_references_chunks_ref let client_reference_chunks = client_references_chunks_ref
.get(client_reference.ty()) .get(client_reference.ty())
......
...@@ -18,7 +18,10 @@ import type { BuildManifest } from '../../get-page-files' ...@@ -18,7 +18,10 @@ import type { BuildManifest } from '../../get-page-files'
import type { PagesManifest } from '../../../build/webpack/plugins/pages-manifest-plugin' import type { PagesManifest } from '../../../build/webpack/plugins/pages-manifest-plugin'
import type { AppBuildManifest } from '../../../build/webpack/plugins/app-build-manifest-plugin' import type { AppBuildManifest } from '../../../build/webpack/plugins/app-build-manifest-plugin'
import type { PropagateToWorkersField } from './types' import type { PropagateToWorkersField } from './types'
import type { MiddlewareManifest } from '../../../build/webpack/plugins/middleware-plugin' import type {
EdgeFunctionDefinition,
MiddlewareManifest,
} from '../../../build/webpack/plugins/middleware-plugin'
import type { import type {
HMR_ACTION_TYPES, HMR_ACTION_TYPES,
NextJsHotReloaderInterface, NextJsHotReloaderInterface,
...@@ -598,11 +601,12 @@ async function startWatcher(opts: SetupOpts) { ...@@ -598,11 +601,12 @@ async function startWatcher(opts: SetupOpts) {
) as T ) as T
} }
type InstrumentationDefinition = {
files: string[]
name: 'instrumentation'
}
type TurbopackMiddlewareManifest = MiddlewareManifest & { type TurbopackMiddlewareManifest = MiddlewareManifest & {
instrumentation?: { instrumentation?: InstrumentationDefinition
files: string[]
name: 'instrumentation'
}
} }
const buildManifests = new Map<string, BuildManifest>() const buildManifests = new Map<string, BuildManifest>()
...@@ -770,7 +774,7 @@ async function startWatcher(opts: SetupOpts) { ...@@ -770,7 +774,7 @@ async function startWatcher(opts: SetupOpts) {
sortedMiddleware: [], sortedMiddleware: [],
functions: {}, functions: {},
} }
let instrumentation = undefined let instrumentation: InstrumentationDefinition | undefined = undefined
for (const m of manifests) { for (const m of manifests) {
Object.assign(manifest.functions, m.functions) Object.assign(manifest.functions, m.functions)
Object.assign(manifest.middleware, m.middleware) Object.assign(manifest.middleware, m.middleware)
...@@ -778,12 +782,25 @@ async function startWatcher(opts: SetupOpts) { ...@@ -778,12 +782,25 @@ async function startWatcher(opts: SetupOpts) {
instrumentation = m.instrumentation instrumentation = m.instrumentation
} }
} }
const updateFunctionDefinition = (
fun: EdgeFunctionDefinition
): EdgeFunctionDefinition => {
return {
...fun,
files: [...(instrumentation?.files ?? []), ...fun.files],
}
}
for (const key of Object.keys(manifest.middleware)) {
const value = manifest.middleware[key]
manifest.middleware[key] = updateFunctionDefinition(value)
}
for (const key of Object.keys(manifest.functions)) {
const value = manifest.functions[key]
manifest.functions[key] = updateFunctionDefinition(value)
}
for (const fun of Object.values(manifest.functions).concat( for (const fun of Object.values(manifest.functions).concat(
Object.values(manifest.middleware) Object.values(manifest.middleware)
)) { )) {
if (instrumentation) {
fun.files.unshift(...instrumentation.files)
}
for (const matcher of fun.matchers) { for (const matcher of fun.matchers) {
if (!matcher.regexp) { if (!matcher.regexp) {
matcher.regexp = pathToRegexp(matcher.originalSource, [], { matcher.regexp = pathToRegexp(matcher.originalSource, [], {
...@@ -1591,7 +1608,6 @@ async function startWatcher(opts: SetupOpts) { ...@@ -1591,7 +1608,6 @@ async function startWatcher(opts: SetupOpts) {
false, false,
route.dataEndpoint, route.dataEndpoint,
(pageName) => { (pageName) => {
console.log('server change', pageName)
return { return {
event: HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ONLY_CHANGES, event: HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ONLY_CHANGES,
pages: [pageName], pages: [pageName],
......
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