-
Notifications
You must be signed in to change notification settings - Fork 27.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source trait (vercel/turborepo#5483)
### Description * rename SourceAsset to FileSource * rename VirtualAsset to VirtualSource * add Source trait * use SourceVc in some places next.js PR: #52511
- Loading branch information
Showing
64 changed files
with
355 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use anyhow::{Context, Result}; | ||
|
||
use crate::asset::{Asset, AssetOptionVc, AssetVc}; | ||
|
||
/// (Unparsed) Source Code. Source Code is processed into [Module]s by the | ||
/// [AssetContext]. All [Source]s have content and an identifier. | ||
#[turbo_tasks::value_trait] | ||
pub trait Source: Asset {} | ||
|
||
#[turbo_tasks::value(transparent)] | ||
pub struct OptionSource(Option<SourceVc>); | ||
|
||
#[turbo_tasks::value(transparent)] | ||
pub struct Sources(Vec<SourceVc>); | ||
|
||
/// This is a temporary function that should be removed once the [Source] trait | ||
/// completely replaces the [Asset] trait. | ||
/// TODO make this function unnecessary | ||
#[turbo_tasks::function] | ||
pub async fn asset_to_source(asset: AssetVc) -> Result<SourceVc> { | ||
SourceVc::resolve_from(asset) | ||
.await? | ||
.context("Asset must be a Source") | ||
} | ||
|
||
/// This is a temporary function that should be removed once the [Source] trait | ||
/// completely replaces the [Asset] trait. | ||
/// TODO make this function unnecessary | ||
#[turbo_tasks::function] | ||
pub async fn option_asset_to_source(asset: AssetOptionVc) -> Result<OptionSourceVc> { | ||
if let Some(asset) = *asset.await? { | ||
Ok(OptionSourceVc::cell(Some( | ||
SourceVc::resolve_from(asset) | ||
.await? | ||
.context("Asset must be a Source")?, | ||
))) | ||
} else { | ||
Ok(OptionSourceVc::cell(None)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.