Skip to content

Commit 1bbba2a

Browse files
authored
Revert "[turbopack] Add bundling support for worker_threads" (vercel#88725)
Reverts vercel#87746 because of this build error: ``` > Build error occurred Error: Turbopack build failed with 1 errors: ./node_modules/.pnpm/thread-stream@3.1.0/node_modules/thread-stream/index.js non-evaluatable module Worker thread module must be evaluatable ```
1 parent 633e274 commit 1bbba2a

File tree

23 files changed

+279
-755
lines changed

23 files changed

+279
-755
lines changed

.rustfmt.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
edition = "2024"
21
max_width = 100
32

43
comment_width = 100

crates/next-api/src/middleware.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ use turbo_tasks::{Completion, ResolvedVc, Vc};
1414
use turbo_tasks_fs::{self, File, FileContent, FileSystemPath};
1515
use turbopack_core::{
1616
asset::AssetContent,
17-
chunk::{ChunkingContextExt, EntryChunkGroupResult, availability_info::AvailabilityInfo},
17+
chunk::{
18+
ChunkingContext, ChunkingContextExt, EntryChunkGroupResult,
19+
availability_info::AvailabilityInfo,
20+
},
1821
context::AssetContext,
1922
module::Module,
2023
module_graph::{
@@ -135,7 +138,7 @@ impl MiddlewareEndpoint {
135138
};
136139

137140
let EntryChunkGroupResult { asset: chunk, .. } = *chunking_context
138-
.root_entry_chunk_group(
141+
.entry_chunk_group(
139142
this.project
140143
.node_root()
141144
.await?
@@ -144,6 +147,7 @@ impl MiddlewareEndpoint {
144147
module_graph,
145148
OutputAssets::empty(),
146149
OutputAssets::empty(),
150+
AvailabilityInfo::root(),
147151
)
148152
.await?;
149153
Ok(*chunk)

crates/next-api/src/nft_json.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,30 @@ impl OutputAsset for NftJsonAsset {
7676
}
7777
}
7878

79+
#[turbo_tasks::value(transparent)]
80+
pub struct OutputSpecifier(Option<RcStr>);
81+
7982
fn get_output_specifier(
80-
chunk_path: &FileSystemPath,
83+
path_ref: &FileSystemPath,
8184
ident_folder: &FileSystemPath,
8285
ident_folder_in_project_fs: &FileSystemPath,
8386
output_root: &FileSystemPath,
8487
project_root: &FileSystemPath,
85-
) -> Option<RcStr> {
88+
) -> Result<RcStr> {
8689
// include assets in the outputs such as referenced chunks
87-
if chunk_path.is_inside_ref(output_root) {
88-
return Some(ident_folder.get_relative_path_to(chunk_path).unwrap());
90+
if path_ref.is_inside_ref(output_root) {
91+
return Ok(ident_folder.get_relative_path_to(path_ref).unwrap());
8992
}
9093

9194
// include assets in the project root such as images and traced references (externals)
92-
if chunk_path.is_inside_ref(project_root) {
93-
return Some(
94-
ident_folder_in_project_fs
95-
.get_relative_path_to(chunk_path)
96-
.unwrap(),
97-
);
95+
if path_ref.is_inside_ref(project_root) {
96+
return Ok(ident_folder_in_project_fs
97+
.get_relative_path_to(path_ref)
98+
.unwrap());
9899
}
99-
None
100+
101+
// This should effectively be unreachable
102+
bail!("NftJsonAsset: cannot handle filepath {path_ref}");
100103
}
101104

102105
/// Apply outputFileTracingIncludes patterns to find additional files
@@ -282,21 +285,13 @@ impl Asset for NftJsonAsset {
282285
}
283286
}
284287

285-
let Some(specifier) = get_output_specifier(
288+
let specifier = get_output_specifier(
286289
&referenced_chunk_path,
287290
&ident_folder,
288291
&ident_folder_in_project_fs,
289292
&output_root_ref,
290293
&project_root_ref,
291-
) else {
292-
// This should effectively be unreachable
293-
bail!(
294-
"NftJsonAsset: cannot handle filepath '{chunk_path}' for \
295-
{referenced_chunk:?} it is not under the output_root: \
296-
'{output_root_ref}' or the project_root: '{project_root_ref}'",
297-
chunk_path = referenced_chunk_path.value_to_string().await?
298-
);
299-
};
294+
)?;
300295

301296
result.insert(specifier);
302297
}

test/e2e/app-dir/node-worker-threads/app/api/simple-worker-test/route.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/e2e/app-dir/node-worker-threads/app/api/worker-test/route.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

test/e2e/app-dir/node-worker-threads/app/layout.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/e2e/app-dir/node-worker-threads/app/worker-dir/simple-worker.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/e2e/app-dir/node-worker-threads/node-worker-threads.test.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

turbopack/crates/turbopack-browser/src/chunking_context.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,10 @@ impl BrowserChunkingContext {
354354
}
355355
}
356356
}
357+
358+
#[turbo_tasks::value_impl]
357359
impl BrowserChunkingContext {
360+
#[turbo_tasks::function]
358361
fn generate_evaluate_chunk(
359362
self: Vc<Self>,
360363
ident: Vc<AssetIdent>,
@@ -371,6 +374,8 @@ impl BrowserChunkingContext {
371374
module_graph,
372375
))
373376
}
377+
378+
#[turbo_tasks::function]
374379
fn generate_chunk_list_register_chunk(
375380
self: Vc<Self>,
376381
ident: Vc<AssetIdent>,
@@ -386,30 +391,26 @@ impl BrowserChunkingContext {
386391
source,
387392
))
388393
}
394+
395+
#[turbo_tasks::function]
389396
async fn generate_chunk(
390397
self: Vc<Self>,
391398
chunk: ResolvedVc<Box<dyn Chunk>>,
392-
) -> Result<ResolvedVc<Box<dyn OutputAsset>>> {
399+
) -> Result<Vc<Box<dyn OutputAsset>>> {
393400
Ok(
394401
if let Some(ecmascript_chunk) = ResolvedVc::try_downcast_type::<EcmascriptChunk>(chunk)
395402
{
396-
ResolvedVc::upcast(
397-
EcmascriptBrowserChunk::new(self, *ecmascript_chunk)
398-
.to_resolved()
399-
.await?,
400-
)
403+
Vc::upcast(EcmascriptBrowserChunk::new(self, *ecmascript_chunk))
401404
} else if let Some(output_asset) =
402405
ResolvedVc::try_sidecast::<Box<dyn OutputAsset>>(chunk)
403406
{
404-
output_asset
407+
*output_asset
405408
} else {
406409
bail!("Unable to generate output asset for chunk");
407410
},
408411
)
409412
}
410-
}
411-
#[turbo_tasks::value_impl]
412-
impl BrowserChunkingContext {
413+
413414
#[turbo_tasks::function]
414415
pub fn current_chunk_method(&self) -> Vc<CurrentChunkMethod> {
415416
self.current_chunk_method.cell()
@@ -698,7 +699,7 @@ impl ChunkingContext for BrowserChunkingContext {
698699

699700
let mut assets = chunks
700701
.iter()
701-
.map(|chunk| self.generate_chunk(*chunk))
702+
.map(|chunk| self.generate_chunk(**chunk).to_resolved())
702703
.try_join()
703704
.await?;
704705

@@ -766,7 +767,7 @@ impl ChunkingContext for BrowserChunkingContext {
766767

767768
let mut assets: Vec<ResolvedVc<Box<dyn OutputAsset>>> = chunks
768769
.iter()
769-
.map(|chunk| self.generate_chunk(*chunk))
770+
.map(|chunk| self.generate_chunk(**chunk).to_resolved())
770771
.try_join()
771772
.await?;
772773

turbopack/crates/turbopack-ecmascript/src/references/mod.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ use crate::{
139139
exports_info::{ExportsInfoBinding, ExportsInfoRef},
140140
ident::IdentReplacement,
141141
member::MemberReplacement,
142-
node::PackageJsonReference,
142+
node::{FilePathModuleReference, PackageJsonReference},
143143
raw::{DirAssetReference, FileSourceReference},
144144
require_context::{RequireContextAssetReference, RequireContextMap},
145145
type_issue::SpecifiedModuleTypeIssue,
@@ -1935,7 +1935,7 @@ where
19351935

19361936
if *compile_time_info.environment().rendering().await? == Rendering::Client {
19371937
analysis.add_reference_code_gen(
1938-
WorkerAssetReference::new_web_worker(
1938+
WorkerAssetReference::new(
19391939
origin,
19401940
Request::parse(pat).to_resolved().await?,
19411941
issue_source(source, span),
@@ -1950,7 +1950,8 @@ where
19501950
// Ignore (e.g. dynamic parameter or string literal), just as Webpack does
19511951
return Ok(());
19521952
}
1953-
WellKnownFunctionKind::NodeWorkerConstructor => {
1953+
WellKnownFunctionKind::NodeWorkerConstructor if analysis.analyze_mode.is_tracing() => {
1954+
// Only for tracing, not for bundling (yet?)
19541955
let args = linked_args().await?;
19551956
if !args.is_empty() {
19561957
let pat = js_value_to_pattern(&args[0]);
@@ -1967,20 +1968,17 @@ where
19671968
return Ok(());
19681969
}
19691970
}
1970-
1971-
analysis.add_reference_code_gen(
1972-
WorkerAssetReference::new_node_worker_thread(
1973-
origin,
1974-
// WorkerThreads resolve filepaths relative to the process root
1971+
analysis.add_reference(
1972+
FilePathModuleReference::new(
1973+
origin.asset_context(),
19751974
get_traced_project_dir().await?,
1976-
Pattern::new(pat).to_resolved().await?,
1975+
Pattern::new(pat),
19771976
collect_affecting_sources,
19781977
get_issue_source(),
1979-
in_try,
1980-
),
1981-
ast_path.to_vec().into(),
1978+
)
1979+
.to_resolved()
1980+
.await?,
19821981
);
1983-
19841982
return Ok(());
19851983
}
19861984
let (args, hints) = explain_args(args);

0 commit comments

Comments
 (0)