Skip to content

Commit 8680012

Browse files
committed
pass asset to chunk_path to allow to use content hash later
1 parent a8afbbf commit 8680012

File tree

16 files changed

+62
-27
lines changed

16 files changed

+62
-27
lines changed

crates/next-api/src/app.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,11 @@ impl AppEndpoint {
12931293
let next_package = get_next_package(project.project_path());
12941294
let polyfill_source =
12951295
FileSource::new(next_package.join("dist/build/polyfills/polyfill-nomodule.js".into()));
1296-
let polyfill_output_path =
1297-
client_chunking_context.chunk_path(polyfill_source.ident(), ".js".into());
1296+
let polyfill_output_path = client_chunking_context.chunk_path(
1297+
Some(Vc::upcast(polyfill_source)),
1298+
polyfill_source.ident(),
1299+
".js".into(),
1300+
);
12981301
let polyfill_output_asset = ResolvedVc::upcast(
12991302
RawOutput::new(polyfill_output_path, Vc::upcast(polyfill_source))
13001303
.to_resolved()

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use turbo_rcstr::RcStr;
44
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Upcast, Value, ValueToString, Vc};
55
use turbo_tasks_fs::FileSystemPath;
66
use turbopack_core::{
7+
asset::Asset,
78
chunk::{
89
availability_info::AvailabilityInfo,
910
chunk_group::{make_chunk_group, MakeChunkGroupResult},
@@ -337,6 +338,7 @@ impl ChunkingContext for BrowserChunkingContext {
337338
#[turbo_tasks::function]
338339
async fn chunk_path(
339340
&self,
341+
_asset: Option<Vc<Box<dyn Asset>>>,
340342
ident: Vc<AssetIdent>,
341343
extension: RcStr,
342344
) -> Result<Vc<FileSystemPath>> {

turbopack/crates/turbopack-browser/src/ecmascript/chunk.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ impl EcmascriptBrowserChunk {
101101
#[turbo_tasks::value_impl]
102102
impl OutputAsset for EcmascriptBrowserChunk {
103103
#[turbo_tasks::function]
104-
fn path(&self) -> Vc<FileSystemPath> {
105-
let ident = self.ident_for_path();
106-
self.chunking_context.chunk_path(ident, ".js".into())
104+
async fn path(self: Vc<Self>) -> Result<Vc<FileSystemPath>> {
105+
let this = self.await?;
106+
let ident = this.ident_for_path();
107+
Ok(this
108+
.chunking_context
109+
.chunk_path(Some(Vc::upcast(self)), ident, ".js".into()))
107110
}
108111

109112
#[turbo_tasks::function]

turbopack/crates/turbopack-browser/src/ecmascript/evaluate/chunk.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ impl OutputAsset for EcmascriptBrowserEvaluateChunk {
244244
async fn path(self: Vc<Self>) -> Result<Vc<FileSystemPath>> {
245245
let this = self.await?;
246246
let ident = self.ident_for_path();
247-
Ok(this.chunking_context.chunk_path(ident, ".js".into()))
247+
Ok(this
248+
.chunking_context
249+
.chunk_path(Some(Vc::upcast(self)), ident, ".js".into()))
248250
}
249251

250252
#[turbo_tasks::function]

turbopack/crates/turbopack-browser/src/ecmascript/list/asset.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ fn chunk_key() -> Vc<RcStr> {
9191
#[turbo_tasks::value_impl]
9292
impl OutputAsset for EcmascriptDevChunkList {
9393
#[turbo_tasks::function]
94-
async fn path(&self) -> Result<Vc<FileSystemPath>> {
95-
let mut ident = self.ident.owned().await?;
94+
async fn path(self: Vc<Self>) -> Result<Vc<FileSystemPath>> {
95+
let this = self.await?;
96+
let mut ident = this.ident.owned().await?;
9697
ident.add_modifier(modifier().to_resolved().await?);
9798

98-
match self.source {
99+
match this.source {
99100
EcmascriptDevChunkListSource::Entry => {}
100101
EcmascriptDevChunkListSource::Dynamic => {
101102
ident.add_modifier(dynamic_modifier().to_resolved().await?);
@@ -107,7 +108,9 @@ impl OutputAsset for EcmascriptDevChunkList {
107108
// removed from the list.
108109

109110
let ident = AssetIdent::new(Value::new(ident));
110-
Ok(self.chunking_context.chunk_path(ident, ".js".into()))
111+
Ok(this
112+
.chunking_context
113+
.chunk_path(Some(Vc::upcast(self)), ident, ".js".into()))
111114
}
112115

113116
#[turbo_tasks::function]

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use turbo_tasks_hash::DeterministicHash;
88

99
use super::{availability_info::AvailabilityInfo, ChunkableModule, EvaluatableAssets};
1010
use crate::{
11+
asset::Asset,
1112
chunk::{ChunkItem, ChunkType, ModuleId},
1213
environment::Environment,
1314
ident::AssetIdent,
@@ -143,7 +144,12 @@ pub trait ChunkingContext {
143144
// discretion of chunking context implementors. However, we currently use this
144145
// in a couple of places in `turbopack-css`, so we need to remove that
145146
// dependency first.
146-
fn chunk_path(self: Vc<Self>, ident: Vc<AssetIdent>, extension: RcStr) -> Vc<FileSystemPath>;
147+
fn chunk_path(
148+
self: Vc<Self>,
149+
asset: Option<Vc<Box<dyn Asset>>>,
150+
ident: Vc<AssetIdent>,
151+
extension: RcStr,
152+
) -> Vc<FileSystemPath>;
147153

148154
/// Reference Source Map Assets for chunks
149155
fn reference_chunk_source_maps(self: Vc<Self>, chunk: Vc<Box<dyn OutputAsset>>) -> Vc<bool>;

turbopack/crates/turbopack-core/src/source_map/source_map_asset.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl OutputAsset for SourceMapAsset {
7777
chunking_context,
7878
ident_for_path,
7979
} => chunking_context
80-
.chunk_path(*ident_for_path, ".js".into())
80+
.chunk_path(Some(Vc::upcast(self)), *ident_for_path, ".js".into())
8181
.append(".map".into()),
8282
PathType::Fixed { path } => path.append(".map".into()),
8383
})

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl OutputAsset for CssChunk {
323323
Ok(self
324324
.await?
325325
.chunking_context
326-
.chunk_path(ident, ".css".into()))
326+
.chunk_path(Some(Vc::upcast(self)), ident, ".css".into()))
327327
}
328328

329329
#[turbo_tasks::function]

turbopack/crates/turbopack-css/src/chunk/single_item_chunk/chunk.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ fn single_item_modifier() -> Vc<RcStr> {
9898
impl OutputAsset for SingleItemCssChunk {
9999
#[turbo_tasks::function]
100100
async fn path(self: Vc<Self>) -> Result<Vc<FileSystemPath>> {
101-
Ok(self
102-
.await?
103-
.chunking_context
104-
.chunk_path(self.ident_for_path(), ".single.css".into()))
101+
Ok(self.await?.chunking_context.chunk_path(
102+
Some(Vc::upcast(self)),
103+
self.ident_for_path(),
104+
".single.css".into(),
105+
))
105106
}
106107

107108
#[turbo_tasks::function]

turbopack/crates/turbopack-css/src/chunk/single_item_chunk/source_map.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ impl OutputAsset for SingleItemCssChunkSourceMapAsset {
3333
.chunk
3434
.await?
3535
.chunking_context
36-
.chunk_path(this.chunk.ident_for_path(), ".single.css".into())
36+
.chunk_path(
37+
Some(Vc::upcast(self)),
38+
this.chunk.ident_for_path(),
39+
".single.css".into(),
40+
)
3741
.append(".map".into()))
3842
}
3943
}

turbopack/crates/turbopack-css/src/chunk/source_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl OutputAsset for CssChunkSourceMapAsset {
3434
.chunk
3535
.await?
3636
.chunking_context
37-
.chunk_path(ident, ".css".into())
37+
.chunk_path(Some(Vc::upcast(self)), ident, ".css".into())
3838
.append(".map".into()))
3939
}
4040
}

turbopack/crates/turbopack-node/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub async fn get_intermediate_asset(
256256
other_entries: Vc<EvaluatableAssets>,
257257
) -> Result<Vc<Box<dyn OutputAsset>>> {
258258
Ok(Vc::upcast(chunking_context.root_entry_chunk_group_asset(
259-
chunking_context.chunk_path(main_entry.ident(), ".js".into()),
259+
chunking_context.chunk_path(None, main_entry.ident(), ".js".into()),
260260
other_entries.with_entry(*main_entry),
261261
ModuleGraph::from_modules(Vc::cell(vec![ChunkGroupEntry::Entry(
262262
other_entries

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use turbo_rcstr::RcStr;
44
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Upcast, Value, ValueToString, Vc};
55
use turbo_tasks_fs::FileSystemPath;
66
use turbopack_core::{
7+
asset::Asset,
78
chunk::{
89
availability_info::AvailabilityInfo,
910
chunk_group::{make_chunk_group, MakeChunkGroupResult},
@@ -276,6 +277,7 @@ impl ChunkingContext for NodeJsChunkingContext {
276277
#[turbo_tasks::function]
277278
async fn chunk_path(
278279
&self,
280+
_asset: Option<Vc<Box<dyn Asset>>>,
279281
ident: Vc<AssetIdent>,
280282
extension: RcStr,
281283
) -> Result<Vc<FileSystemPath>> {

turbopack/crates/turbopack-nodejs/src/ecmascript/node/chunk.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ impl EcmascriptBuildNodeChunk {
7878
#[turbo_tasks::value_impl]
7979
impl OutputAsset for EcmascriptBuildNodeChunk {
8080
#[turbo_tasks::function]
81-
fn path(&self) -> Vc<FileSystemPath> {
82-
let ident = self.chunk.ident().with_modifier(modifier());
83-
self.chunking_context.chunk_path(ident, ".js".into())
81+
async fn path(self: Vc<Self>) -> Result<Vc<FileSystemPath>> {
82+
let this = self.await?;
83+
let ident = this.chunk.ident().with_modifier(modifier());
84+
Ok(this
85+
.chunking_context
86+
.chunk_path(Some(Vc::upcast(self)), ident, ".js".into()))
8487
}
8588

8689
#[turbo_tasks::function]

turbopack/crates/turbopack-nodejs/src/ecmascript/node/entry/runtime.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ impl OutputAsset for EcmascriptBuildNodeRuntimeChunk {
129129
let this = self.await?;
130130
let ident = self.ident_for_path();
131131

132-
Ok(this.chunking_context.chunk_path(ident, ".js".into()))
132+
Ok(this
133+
.chunking_context
134+
.chunk_path(Some(Vc::upcast(self)), ident, ".js".into()))
133135
}
134136

135137
#[turbo_tasks::function]

turbopack/crates/turbopack-wasm/src/output_asset.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::Result;
12
use turbo_rcstr::RcStr;
23
use turbo_tasks::{ResolvedVc, Vc};
34
use turbo_tasks_fs::FileSystemPath;
@@ -40,9 +41,12 @@ impl WebAssemblyAsset {
4041
#[turbo_tasks::value_impl]
4142
impl OutputAsset for WebAssemblyAsset {
4243
#[turbo_tasks::function]
43-
fn path(&self) -> Vc<FileSystemPath> {
44-
let ident = self.source.ident().with_modifier(modifier());
45-
self.chunking_context.chunk_path(ident, ".wasm".into())
44+
async fn path(self: Vc<Self>) -> Result<Vc<FileSystemPath>> {
45+
let this = self.await?;
46+
let ident = this.source.ident().with_modifier(modifier());
47+
Ok(this
48+
.chunking_context
49+
.chunk_path(Some(Vc::upcast(self)), ident, ".wasm".into()))
4650
}
4751
}
4852

0 commit comments

Comments
 (0)