Skip to content

Commit

Permalink
Merge pull request #130 from vercel/bugfix/chunk-ext
Browse files Browse the repository at this point in the history
ensure to put the correct extension to chunks
  • Loading branch information
sokra committed Jul 19, 2022
2 parents 17f7947 + 84cdbd3 commit 03970c6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions crates/turbopack-core/src/chunk/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,22 @@ pub struct DevChunkingContext {
#[turbo_tasks::value_impl]
impl ChunkingContext for DevChunkingContext {
#[turbo_tasks::function]
async fn as_chunk_path(&self, path: FileSystemPathVc) -> Result<FileSystemPathVc> {
async fn as_chunk_path(
&self,
path: FileSystemPathVc,
extension: &str,
) -> Result<FileSystemPathVc> {
fn clean(s: &str) -> String {
s.replace('/', "_")
}
let name = if let Some(inner) = self.context_path.await?.get_path_to(&*path.await?) {
let mut name = if let Some(inner) = self.context_path.await?.get_path_to(&*path.await?) {
clean(inner)
} else {
clean(&*path.to_string().await?)
};
if !name.ends_with(extension) {
name += extension;
}
Ok(self.chunk_root_path.join(&name))
}

Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-core/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum ChunkId {
/// A context for the chunking that influences the way chunks are created
#[turbo_tasks::value_trait]
pub trait ChunkingContext {
fn as_chunk_path(&self, path: FileSystemPathVc) -> FileSystemPathVc;
fn as_chunk_path(&self, path: FileSystemPathVc, extension: &str) -> FileSystemPathVc;

fn can_be_in_same_chunk(&self, asset_a: AssetVc, asset_b: AssetVc) -> BoolVc;

Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-css/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl ValueToString for CssChunk {
impl Asset for CssChunk {
#[turbo_tasks::function]
fn path(&self) -> FileSystemPathVc {
self.context.as_chunk_path(self.entry.path())
self.context.as_chunk_path(self.entry.path(), ".css")
}

#[turbo_tasks::function]
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-ecmascript/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async fn module_factory(content: EcmascriptChunkItemContentVc) -> Result<StringV
impl Asset for EcmascriptChunk {
#[turbo_tasks::function]
fn path(&self) -> FileSystemPathVc {
self.context.as_chunk_path(self.entry.path())
self.context.as_chunk_path(self.entry.path(), ".js")
}

#[turbo_tasks::function]
Expand Down

0 comments on commit 03970c6

Please sign in to comment.