Skip to content

Commit be33a9d

Browse files
authored
Turbopack: Deterministic builds (prerender-manifest, .next/package.json, ./next/postcss.js) (#84081)
### What? * Make order of routes in prerender manifest deterministic * Write the same package.json content to distDir * fix output directory for postcss/webpack loaders entrypoint
1 parent 6779a5c commit be33a9d

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

crates/next-api/src/project.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,9 @@ impl Project {
815815
let node_execution_chunking_context = Vc::upcast(
816816
NodeJsChunkingContext::builder(
817817
self.project_root_path().owned().await?,
818-
node_root.clone(),
818+
node_root.join("build")?,
819819
self.node_root_to_root_path().owned().await?,
820-
node_root.clone(),
820+
node_root.join("build")?,
821821
node_root.join("build/chunks")?,
822822
node_root.join("build/assets")?,
823823
node_build_environment().to_resolved().await?,

packages/next/src/build/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,6 +2818,10 @@ export default async function build(
28182818
)
28192819
)
28202820

2821+
const sortedStaticPaths = Array.from(staticPaths.entries()).sort(
2822+
([a], [b]) => a.localeCompare(b)
2823+
)
2824+
28212825
const exportApp = (require('../export') as typeof import('../export'))
28222826
.default as typeof import('../export').default
28232827

@@ -2885,7 +2889,7 @@ export default async function build(
28852889

28862890
// TODO: output manifest specific to app paths and their
28872891
// revalidate periods and dynamicParams settings
2888-
staticPaths.forEach((routes, originalAppPath) => {
2892+
sortedStaticPaths.forEach(([originalAppPath, routes]) => {
28892893
const appConfig = appDefaultConfigs.get(originalAppPath)
28902894
const isDynamicError = appConfig?.dynamic === 'error'
28912895

@@ -3054,7 +3058,7 @@ export default async function build(
30543058
await fs.unlink(serverBundle)
30553059
}
30563060

3057-
staticPaths.forEach((prerenderedRoutes, originalAppPath) => {
3061+
sortedStaticPaths.forEach(([originalAppPath, prerenderedRoutes]) => {
30583062
const page = appNormalizedPaths.get(originalAppPath)
30593063
if (!page) throw new InvariantError('Page not found')
30603064

packages/next/src/build/turbopack-build/impl.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,7 @@ export async function turbopackBuild(): Promise<{
104104
})
105105
await fs.writeFile(
106106
path.join(distDir, 'package.json'),
107-
JSON.stringify(
108-
{
109-
type: 'commonjs',
110-
},
111-
null,
112-
2
113-
)
107+
'{"type": "commonjs"}'
114108
)
115109

116110
// eslint-disable-next-line @typescript-eslint/no-unused-vars

0 commit comments

Comments
 (0)