Unverified Commit 09838d61 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Turbopack: Allow distdir in project directory, outside of the application (#80683)

## What?

Allow putting `distDir` anywhere in the monorepo (inside the project
root), not just inside the app's directory.
parent ac59bdad
......@@ -47,13 +47,6 @@ impl NftJsonAsset {
}
.cell()
}
#[turbo_tasks::function]
async fn dist_dir(&self) -> Result<Vc<RcStr>> {
Ok(Vc::cell(
format!("/{}/", self.project.dist_dir().await?).into(),
))
}
}
#[turbo_tasks::value_impl]
......@@ -114,11 +107,13 @@ impl Asset for NftJsonAsset {
let client_root = this.project.client_fs().root();
let client_root_ref = client_root.await?;
// Example: [output]/apps/my-website/.next/server/app -- without the `.nft.json`
let ident_folder = self.path().parent().await?;
// Example: [project]/apps/my-website/.next/server/app -- without the `.nft.json`
let ident_folder_in_project_fs = this
.project
.project_path()
.join(ident_folder.path.clone())
.project_root_path() // Example: [project]
.join(ident_folder.path.clone()) // apps/my-website/.next/server/app
.await?;
let chunk = this.chunk;
......
......@@ -33,7 +33,10 @@ use turbo_tasks::{
trace::TraceRawVcs,
};
use turbo_tasks_env::{EnvMap, ProcessEnv};
use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath, VirtualFileSystem, invalidation};
use turbo_tasks_fs::{
DiskFileSystem, FileSystem, FileSystemPath, VirtualFileSystem, get_relative_path_to,
invalidation,
};
use turbopack::{
ModuleAssetContext, evaluate_context::node_build_environment,
global_module_ids::get_global_module_id_strategy, transition::TransitionOptions,
......@@ -662,7 +665,7 @@ impl Project {
#[turbo_tasks::function]
pub fn output_fs(&self) -> Vc<DiskFileSystem> {
DiskFileSystem::new(rcstr!("output"), self.project_path.clone(), vec![])
DiskFileSystem::new(rcstr!("output"), self.root_path.clone(), vec![])
}
#[turbo_tasks::function]
......@@ -673,7 +676,13 @@ impl Project {
#[turbo_tasks::function]
pub async fn node_root(self: Vc<Self>) -> Result<Vc<FileSystemPath>> {
let this = self.await?;
Ok(self.output_fs().root().join(this.dist_dir.clone()))
let relative_from_root_to_project_path =
get_relative_path_to(&this.root_path, &this.project_path);
Ok(self
.output_fs()
.root()
.join(relative_from_root_to_project_path.into())
.join(this.dist_dir.clone()))
}
#[turbo_tasks::function]
......
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>hello world</p>
}
const path = require('path')
module.exports = {
distDir: '../.next',
turbopack: {
root: path.join(__dirname, '../..'),
},
}
import { nextTestSetup, isNextDev } from 'e2e-utils'
describe('upward-distdir', () => {
const { next } = nextTestSetup({
skipDeployment: true,
files: __dirname,
installCommand: 'pnpm install',
buildCommand: 'pnpm next build apps/next-nx-test',
startCommand: isNextDev
? 'pnpm next dev apps/next-nx-test'
: 'pnpm next start apps/next-nx-test',
})
it('should work', async () => {
const $ = await next.render$('/')
expect($('p').text()).toBe('hello world')
})
})
......@@ -3909,13 +3909,13 @@
"runtimeError": false
},
"test/e2e/app-dir/nx-handling/nx-handling.test.ts": {
"passed": [],
"failed": [
"passed": [
"nx-handling should work for pages API",
"nx-handling should work for pages page",
"nx-handling should work with app page",
"nx-handling should work with app route"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
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