Download next.js/turbopack/crates/turbopack-ecmascript/src/references/node.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 5.47 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript/src/references/node.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-ecmascript/src/references/node.rs
-
curl -L -o node.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript/src/references/node.rs
5.47 kB
| use anyhow::Result; | |
| use either::Either; | |
| use turbo_rcstr::{RcStr, rcstr}; | |
| use turbo_tasks::{ResolvedVc, ValueToString, Vc}; | |
| use turbo_tasks_fs::FileSystemPath; | |
| use turbopack_core::{ | |
| chunk::{ChunkableModuleReference, ChunkingType, ChunkingTypeOption}, | |
| file_source::FileSource, | |
| raw_module::RawModule, | |
| reference::ModuleReference, | |
| resolve::{ | |
| ModuleResolveResult, RequestKey, | |
| pattern::{Pattern, PatternMatch, read_matches}, | |
| }, | |
| source::Source, | |
| }; | |
| pub struct PackageJsonReference { | |
| pub package_json: FileSystemPath, | |
| } | |
| impl PackageJsonReference { | |
| pub fn new(package_json: FileSystemPath) -> Vc<Self> { | |
| Self::cell(PackageJsonReference { package_json }) | |
| } | |
| } | |
| impl ModuleReference for PackageJsonReference { | |
| async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> { | |
| Ok(*ModuleResolveResult::module(ResolvedVc::upcast( | |
| RawModule::new(Vc::upcast(FileSource::new(self.package_json.clone()))) | |
| .to_resolved() | |
| .await?, | |
| ))) | |
| } | |
| } | |
| impl ValueToString for PackageJsonReference { | |
| async fn to_string(&self) -> Result<Vc<RcStr>> { | |
| Ok(Vc::cell( | |
| format!( | |
| "package.json {}", | |
| self.package_json.value_to_string().await? | |
| ) | |
| .into(), | |
| )) | |
| } | |
| } | |
| pub struct DirAssetReference { | |
| pub source: ResolvedVc<Box<dyn Source>>, | |
| pub path: ResolvedVc<Pattern>, | |
| } | |
| impl DirAssetReference { | |
| pub fn new(source: ResolvedVc<Box<dyn Source>>, path: ResolvedVc<Pattern>) -> Vc<Self> { | |
| Self::cell(DirAssetReference { source, path }) | |
| } | |
| } | |
| async fn resolve_reference_from_dir( | |
| parent_path: FileSystemPath, | |
| path: Vc<Pattern>, | |
| ) -> Result<Vc<ModuleResolveResult>> { | |
| let path_ref = path.await?; | |
| let (abs_path, rel_path) = path_ref.split_could_match("/ROOT/"); | |
| let matches = match (abs_path, rel_path) { | |
| (Some(abs_path), Some(rel_path)) => Either::Right( | |
| read_matches( | |
| parent_path.root().owned().await?, | |
| rcstr!("/ROOT/"), | |
| true, | |
| Pattern::new(abs_path.or_any_nested_file()), | |
| ) | |
| .await? | |
| .into_iter() | |
| .chain( | |
| read_matches( | |
| parent_path, | |
| rcstr!(""), | |
| true, | |
| Pattern::new(rel_path.or_any_nested_file()), | |
| ) | |
| .await? | |
| .into_iter(), | |
| ), | |
| ), | |
| (Some(abs_path), None) => Either::Left( | |
| // absolute path only | |
| read_matches( | |
| parent_path.root().owned().await?, | |
| rcstr!("/ROOT/"), | |
| true, | |
| Pattern::new(abs_path.or_any_nested_file()), | |
| ) | |
| .await? | |
| .into_iter(), | |
| ), | |
| (None, Some(rel_path)) => Either::Left( | |
| // relative path only | |
| read_matches( | |
| parent_path, | |
| rcstr!(""), | |
| true, | |
| Pattern::new(rel_path.or_any_nested_file()), | |
| ) | |
| .await? | |
| .into_iter(), | |
| ), | |
| (None, None) => return Ok(*ModuleResolveResult::unresolvable()), | |
| }; | |
| let mut affecting_sources = Vec::new(); | |
| let mut results = Vec::new(); | |
| for pat_match in matches { | |
| match pat_match { | |
| PatternMatch::File(matched_path, file) => { | |
| let realpath = file.realpath_with_links().await?; | |
| for symlink in &realpath.symlinks { | |
| affecting_sources.push(ResolvedVc::upcast( | |
| FileSource::new(symlink.clone()).to_resolved().await?, | |
| )); | |
| } | |
| results.push(( | |
| RequestKey::new(matched_path.clone()), | |
| ResolvedVc::upcast( | |
| RawModule::new(Vc::upcast(FileSource::new(realpath.path.clone()))) | |
| .to_resolved() | |
| .await?, | |
| ), | |
| )); | |
| } | |
| PatternMatch::Directory(..) => {} | |
| } | |
| } | |
| Ok(*ModuleResolveResult::modules_with_affecting_sources( | |
| results, | |
| affecting_sources, | |
| )) | |
| } | |
| impl ModuleReference for DirAssetReference { | |
| async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> { | |
| let parent_path = self.source.ident().path().await?.parent(); | |
| Ok(resolve_reference_from_dir(parent_path, *self.path)) | |
| } | |
| } | |
| impl ChunkableModuleReference for DirAssetReference { | |
| fn chunking_type(&self) -> Vc<ChunkingTypeOption> { | |
| Vc::cell(Some(ChunkingType::Traced)) | |
| } | |
| } | |
| impl ValueToString for DirAssetReference { | |
| async fn to_string(&self) -> Result<Vc<RcStr>> { | |
| Ok(Vc::cell( | |
| format!("directory assets {}", self.path.to_string().await?,).into(), | |
| )) | |
| } | |
| } | |