Skip to content

Commit 721c53b

Browse files
author
Lichu Acuña
committed
Added a GlobalInformation struct, which is made available through the ChunkingContext trait.
Constructing a new GlobalInformation object takes a Project parameter, giving the constructor access to global information
1 parent d24b396 commit 721c53b

File tree

9 files changed

+31
-0
lines changed

9 files changed

+31
-0
lines changed

crates/turbopack-browser/src/chunking_context.rs

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use turbopack_core::{
66
chunk::{
77
availability_info::AvailabilityInfo,
88
chunk_group::{make_chunk_group, MakeChunkGroupResult},
9+
global_information::OptionGlobalInformation,
910
Chunk, ChunkGroupResult, ChunkItem, ChunkableModule, ChunkingContext,
1011
EntryChunkGroupResult, EvaluatableAssets, MinifyType, ModuleId,
1112
},
@@ -122,6 +123,8 @@ pub struct BrowserChunkingContext {
122123
minify_type: MinifyType,
123124
/// Whether to use manifest chunks for lazy compilation
124125
manifest_chunks: bool,
126+
/// Global information
127+
global_information: Vc<OptionGlobalInformation>,
125128
}
126129

127130
impl BrowserChunkingContext {
@@ -133,6 +136,7 @@ impl BrowserChunkingContext {
133136
asset_root_path: Vc<FileSystemPath>,
134137
environment: Vc<Environment>,
135138
runtime_type: RuntimeType,
139+
global_information: Vc<OptionGlobalInformation>,
136140
) -> BrowserChunkingContextBuilder {
137141
BrowserChunkingContextBuilder {
138142
chunking_context: BrowserChunkingContext {
@@ -151,6 +155,7 @@ impl BrowserChunkingContext {
151155
runtime_type,
152156
minify_type: MinifyType::NoMinify,
153157
manifest_chunks: false,
158+
global_information,
154159
},
155160
}
156161
}

crates/turbopack-cli/src/build/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ async fn build_internal(
197197
NodeEnv::Development => RuntimeType::Development,
198198
NodeEnv::Production => RuntimeType::Production,
199199
},
200+
Vc::cell(None),
200201
)
201202
.minify_type(minify_type)
202203
.build(),

crates/turbopack-cli/src/dev/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ async fn source(
255255
build_output_root.join("assets".into()),
256256
node_build_environment(),
257257
RuntimeType::Development,
258+
Vc::cell(None),
258259
)
259260
.build();
260261

crates/turbopack-cli/src/dev/web_entry_source.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub fn get_client_chunking_context(
4545
server_root.join("/_assets".into()),
4646
environment,
4747
RuntimeType::Development,
48+
Vc::cell(None),
4849
)
4950
.hot_module_replacement()
5051
.build(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[turbo_tasks::value]
2+
#[derive(Clone, Debug)]
3+
pub struct GlobalInformation {}
4+
5+
#[turbo_tasks::value(transparent)]
6+
pub struct OptionGlobalInformation(Option<GlobalInformation>);

crates/turbopack-core/src/chunk/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub(crate) mod chunking_context;
66
pub(crate) mod containment_tree;
77
pub(crate) mod data;
88
pub(crate) mod evaluate;
9+
pub mod global_information;
910
pub mod optimize;
1011

1112
use std::{

crates/turbopack-nodejs/src/chunking_context.rs

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use turbopack_core::{
88
chunk::{
99
availability_info::AvailabilityInfo,
1010
chunk_group::{make_chunk_group, MakeChunkGroupResult},
11+
global_information::OptionGlobalInformation,
1112
Chunk, ChunkGroupResult, ChunkItem, ChunkableModule, ChunkingContext,
1213
EntryChunkGroupResult, EvaluatableAssets, MinifyType, ModuleId,
1314
},
@@ -84,6 +85,8 @@ pub struct NodeJsChunkingContext {
8485
minify_type: MinifyType,
8586
/// Whether to use manifest chunks for lazy compilation
8687
manifest_chunks: bool,
88+
/// Global information
89+
global_information: Vc<OptionGlobalInformation>,
8790
}
8891

8992
impl NodeJsChunkingContext {
@@ -96,6 +99,7 @@ impl NodeJsChunkingContext {
9699
asset_root_path: Vc<FileSystemPath>,
97100
environment: Vc<Environment>,
98101
runtime_type: RuntimeType,
102+
global_information: Vc<OptionGlobalInformation>,
99103
) -> NodeJsChunkingContextBuilder {
100104
NodeJsChunkingContextBuilder {
101105
chunking_context: NodeJsChunkingContext {
@@ -109,6 +113,7 @@ impl NodeJsChunkingContext {
109113
runtime_type,
110114
minify_type: MinifyType::NoMinify,
111115
manifest_chunks: false,
116+
global_information,
112117
},
113118
}
114119
}
@@ -131,6 +136,14 @@ impl NodeJsChunkingContext {
131136

132137
#[turbo_tasks::value_impl]
133138
impl NodeJsChunkingContext {
139+
#[turbo_tasks::function]
140+
async fn chunk_item_id_from_ident(
141+
self: Vc<Self>,
142+
ident: Vc<AssetIdent>,
143+
) -> Result<Vc<ModuleId>> {
144+
Ok(ModuleId::String(ident.to_string().await?.clone_value()).cell())
145+
}
146+
134147
#[turbo_tasks::function]
135148
fn new(this: Value<NodeJsChunkingContext>) -> Vc<Self> {
136149
this.into_value().cell()

crates/turbopack-tests/tests/execution.rs

+1
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ async fn run_test(prepared_test: Vc<PreparedTest>) -> Result<Vc<RunTestResult>>
322322
static_root_path,
323323
env,
324324
RuntimeType::Development,
325+
Vc::cell(None),
325326
)
326327
.build();
327328

crates/turbopack-tests/tests/snapshot.rs

+2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ async fn run_test(resource: RcStr) -> Result<Vc<FileSystemPath>> {
319319
static_root_path,
320320
env,
321321
options.runtime_type,
322+
Vc::cell(None),
322323
)
323324
.build(),
324325
),
@@ -331,6 +332,7 @@ async fn run_test(resource: RcStr) -> Result<Vc<FileSystemPath>> {
331332
static_root_path,
332333
env,
333334
options.runtime_type,
335+
Vc::cell(None),
334336
)
335337
.minify_type(options.minify_type)
336338
.build(),

0 commit comments

Comments
 (0)