这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions crates/turbopack-core/src/chunk/chunking_context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::fmt::Debug;

use anyhow::Result;
use turbo_tasks::primitives::{BoolVc, StringVc};
use turbo_tasks_fs::FileSystemPathVc;

use super::{ChunkVc, EvaluatableAssetsVc};
use crate::{
asset::{AssetVc, AssetsVc},
environment::EnvironmentVc,
ident::AssetIdentVc,
};

/// A context for the chunking that influences the way chunks are created
#[turbo_tasks::value_trait]
pub trait ChunkingContext {
fn context_path(&self) -> FileSystemPathVc;
fn output_root(&self) -> FileSystemPathVc;

// TODO remove this, a chunking context should not be bound to a specific
// environment since this can change due to transitions in the module graph
fn environment(&self) -> EnvironmentVc;

// TODO(alexkirsz) Remove this from the chunking context. This should be at the
// discretion of chunking context implementors. However, we currently use this
// in a couple of places in `turbopack-css`, so we need to remove that
// dependency first.
fn chunk_path(&self, ident: AssetIdentVc, extension: &str) -> FileSystemPathVc;

// TODO(alexkirsz) Remove this from the chunking context.
/// Reference Source Map Assets for chunks
fn reference_chunk_source_maps(&self, chunk: AssetVc) -> BoolVc;

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

fn asset_path(&self, content_hash: &str, extension: &str) -> FileSystemPathVc;

fn is_hot_module_replacement_enabled(&self) -> BoolVc {
BoolVc::cell(false)
}

fn layer(&self) -> StringVc {
StringVc::cell("".to_string())
}

fn with_layer(&self, layer: &str) -> ChunkingContextVc;

fn chunk_group(&self, entry: ChunkVc) -> AssetsVc;

fn evaluated_chunk_group(
&self,
entry: ChunkVc,
evaluatable_assets: EvaluatableAssetsVc,
) -> AssetsVc;
}
16 changes: 2 additions & 14 deletions crates/turbopack-core/src/chunk/evaluate.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use anyhow::{bail, Result};
use turbo_tasks::{Value, ValueToString};

use super::{ChunkVc, ChunkableAsset, ChunkableAssetVc, ChunkingContext, ChunkingContextVc};
use super::{ChunkableAsset, ChunkableAssetVc};
use crate::{
asset::{Asset, AssetVc, AssetsVc},
asset::{Asset, AssetVc},
context::{AssetContext, AssetContextVc},
reference_type::{EntryReferenceSubType, ReferenceType},
};
Expand Down Expand Up @@ -52,15 +52,3 @@ impl EvaluatableAssetsVc {
Ok(EvaluatableAssets(entries).cell())
}
}

/// Trait for chunking contexts which can generate evaluated chunks.
#[turbo_tasks::value_trait]
pub trait EvaluateChunkingContext: ChunkingContext {
/// Create a chunk that evaluates the given entries.
fn evaluate_chunk(
&self,
entry_chunk: ChunkVc,
other_assets: AssetsVc,
evaluatable_assets: EvaluatableAssetsVc,
) -> AssetVc;
}
Loading