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
9 changes: 9 additions & 0 deletions crates/pack-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ impl AppProject {

let transition_options = TransitionOptions {
named_transitions,
transition_rules: if matches!(&*project.platform().await?, Platform::Web) {
pack_core::module_reference::rules(
project.project_path().owned().await?,
project.config(),
)
.await?
} else {
Vec::new()
},
..Default::default()
}
.cell();
Expand Down
9 changes: 9 additions & 0 deletions crates/pack-api/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ impl LibraryEndpoint {
Ok(ModuleAssetContext::new(
// FIXME:
TransitionOptions {
transition_rules: if matches!(platform, Platform::Web) {
pack_core::module_reference::rules(
project.project_path().owned().await?,
project.config(),
)
.await?
} else {
Vec::new()
},
..Default::default()
}
.cell(),
Expand Down
52 changes: 52 additions & 0 deletions crates/pack-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,10 +1090,52 @@ pub struct ExperimentalConfig {
#[derive(Clone, Debug, Deserialize, OperationValue)]
#[serde(rename_all = "camelCase")]
pub struct ModuleConfig {
#[serde(default)]
#[bincode(with = "turbo_bincode::indexmap")]
pub rules: FxIndexMap<RcStr, RuleConfigCollection>,
#[serde(default)]
pub references: Vec<ModuleReferenceConfig>,
}

/// Browser-only replacement of a source module with framework-provided references.
#[turbo_tasks::value]
#[derive(Clone, Debug, Serialize, Deserialize, OperationValue)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ModuleReferenceConfig {
pub resource: RcStr,
pub references: Vec<ModuleReference>,
pub exports: Vec<ModuleReferenceExport>,
}

#[turbo_tasks::value]
#[derive(Clone, Debug, Serialize, Deserialize, OperationValue)]
#[serde(deny_unknown_fields)]
pub struct ModuleReference {
pub id: RcStr,
pub factory: ModuleReferenceFactory,
#[bincode(with = "turbo_bincode::serde_self_describing")]
pub data: JsonValue,
}

#[turbo_tasks::value]
#[derive(Clone, Debug, Serialize, Deserialize, OperationValue)]
#[serde(deny_unknown_fields)]
pub struct ModuleReferenceFactory {
pub module: RcStr,
pub export: RcStr,
}

#[turbo_tasks::value]
#[derive(Clone, Debug, Serialize, Deserialize, OperationValue)]
#[serde(deny_unknown_fields)]
pub struct ModuleReferenceExport {
pub name: RcStr,
pub reference: RcStr,
}

#[turbo_tasks::value(transparent)]
pub struct ModuleReferences(Vec<ModuleReferenceConfig>);

#[turbo_tasks::value]
#[derive(Clone, Debug, Serialize, Deserialize, OperationValue)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -1660,6 +1702,16 @@ impl Config {
Vc::cell(self.entry.clone())
}

#[turbo_tasks::function]
pub fn module_references(&self) -> Vc<ModuleReferences> {
Vc::cell(
self.module
.as_ref()
.map(|module| module.references.clone())
.unwrap_or_default(),
)
}

#[turbo_tasks::function]
pub fn webpack_rules(&self, project_path: FileSystemPath) -> Result<Vc<WebpackRules>> {
let Some(turbo_rules) = self.module.as_ref().map(|t| &t.rules) else {
Expand Down
1 change: 1 addition & 0 deletions crates/pack-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod emit;
pub mod import_map;
pub mod library;
pub mod mode;
pub mod module_reference;
pub mod node_polyfill;
pub mod server;
pub mod server_reference;
Expand Down
Loading