|
1 | | -use anyhow::{Result, bail}; |
2 | | -use tracing::Instrument; |
3 | | -use turbo_rcstr::{RcStr, rcstr}; |
| 1 | +use anyhow::Result; |
| 2 | +use turbo_rcstr::RcStr; |
4 | 3 | use turbo_tasks::{ResolvedVc, ValueToString, Vc}; |
5 | 4 | use turbo_tasks_fs::FileSystemPath; |
6 | 5 | use turbopack_core::{ |
7 | | - chunk::{ChunkableModuleReference, ChunkingType, ChunkingTypeOption}, |
8 | | - file_source::FileSource, |
9 | | - raw_module::RawModule, |
10 | | - reference::ModuleReference, |
11 | | - resolve::{ |
12 | | - ModuleResolveResult, RequestKey, |
13 | | - pattern::{Pattern, PatternMatch, read_matches}, |
14 | | - }, |
| 6 | + file_source::FileSource, raw_module::RawModule, reference::ModuleReference, |
| 7 | + resolve::ModuleResolveResult, |
15 | 8 | }; |
16 | 9 |
|
17 | 10 | #[turbo_tasks::value] |
@@ -53,125 +46,3 @@ impl ValueToString for PackageJsonReference { |
53 | 46 | )) |
54 | 47 | } |
55 | 48 | } |
56 | | - |
57 | | -#[turbo_tasks::value] |
58 | | -#[derive(Hash, Debug)] |
59 | | -pub struct DirAssetReference { |
60 | | - pub context_dir: FileSystemPath, |
61 | | - pub path: ResolvedVc<Pattern>, |
62 | | -} |
63 | | - |
64 | | -#[turbo_tasks::value_impl] |
65 | | -impl DirAssetReference { |
66 | | - #[turbo_tasks::function] |
67 | | - pub fn new(context_dir: FileSystemPath, path: ResolvedVc<Pattern>) -> Vc<Self> { |
68 | | - Self::cell(DirAssetReference { context_dir, path }) |
69 | | - } |
70 | | -} |
71 | | - |
72 | | -async fn resolve_reference_from_dir( |
73 | | - context_dir: FileSystemPath, |
74 | | - path: Vc<Pattern>, |
75 | | -) -> Result<Vc<ModuleResolveResult>> { |
76 | | - let path_ref = path.await?; |
77 | | - let (abs_path, rel_path) = path_ref.split_could_match("/ROOT/"); |
78 | | - if abs_path.is_none() && rel_path.is_none() { |
79 | | - return Ok(*ModuleResolveResult::unresolvable()); |
80 | | - } |
81 | | - |
82 | | - let abs_matches = if let Some(abs_path) = &abs_path { |
83 | | - Some( |
84 | | - read_matches( |
85 | | - context_dir.root().owned().await?, |
86 | | - rcstr!("/ROOT/"), |
87 | | - true, |
88 | | - Pattern::new(abs_path.or_any_nested_file()), |
89 | | - ) |
90 | | - .await?, |
91 | | - ) |
92 | | - } else { |
93 | | - None |
94 | | - }; |
95 | | - let rel_matches = if let Some(rel_path) = &rel_path { |
96 | | - Some( |
97 | | - read_matches( |
98 | | - context_dir, |
99 | | - rcstr!(""), |
100 | | - true, |
101 | | - Pattern::new(rel_path.or_any_nested_file()), |
102 | | - ) |
103 | | - .await?, |
104 | | - ) |
105 | | - } else { |
106 | | - None |
107 | | - }; |
108 | | - |
109 | | - let matches = abs_matches |
110 | | - .into_iter() |
111 | | - .flatten() |
112 | | - .chain(rel_matches.into_iter().flatten()); |
113 | | - |
114 | | - let mut affecting_sources = Vec::new(); |
115 | | - let mut results = Vec::new(); |
116 | | - for pat_match in matches { |
117 | | - match pat_match { |
118 | | - PatternMatch::File(matched_path, file) => { |
119 | | - let realpath = file.realpath_with_links().await?; |
120 | | - for symlink in &realpath.symlinks { |
121 | | - affecting_sources.push(ResolvedVc::upcast( |
122 | | - FileSource::new(symlink.clone()).to_resolved().await?, |
123 | | - )); |
124 | | - } |
125 | | - let path: FileSystemPath = match &realpath.path_result { |
126 | | - Ok(path) => path.clone(), |
127 | | - Err(e) => bail!(e.as_error_message(file, &realpath)), |
128 | | - }; |
129 | | - results.push(( |
130 | | - RequestKey::new(matched_path.clone()), |
131 | | - ResolvedVc::upcast( |
132 | | - RawModule::new(Vc::upcast(FileSource::new(path))) |
133 | | - .to_resolved() |
134 | | - .await?, |
135 | | - ), |
136 | | - )); |
137 | | - } |
138 | | - PatternMatch::Directory(..) => {} |
139 | | - } |
140 | | - } |
141 | | - Ok(*ModuleResolveResult::modules_with_affecting_sources( |
142 | | - results, |
143 | | - affecting_sources, |
144 | | - )) |
145 | | -} |
146 | | - |
147 | | -#[turbo_tasks::value_impl] |
148 | | -impl ModuleReference for DirAssetReference { |
149 | | - #[turbo_tasks::function] |
150 | | - async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> { |
151 | | - let span = tracing::info_span!( |
152 | | - "trace directory", |
153 | | - pattern = display(self.path.to_string().await?) |
154 | | - ); |
155 | | - resolve_reference_from_dir(self.context_dir.clone(), *self.path) |
156 | | - .instrument(span) |
157 | | - .await |
158 | | - } |
159 | | -} |
160 | | - |
161 | | -#[turbo_tasks::value_impl] |
162 | | -impl ChunkableModuleReference for DirAssetReference { |
163 | | - #[turbo_tasks::function] |
164 | | - fn chunking_type(&self) -> Vc<ChunkingTypeOption> { |
165 | | - Vc::cell(Some(ChunkingType::Traced)) |
166 | | - } |
167 | | -} |
168 | | - |
169 | | -#[turbo_tasks::value_impl] |
170 | | -impl ValueToString for DirAssetReference { |
171 | | - #[turbo_tasks::function] |
172 | | - async fn to_string(&self) -> Result<Vc<RcStr>> { |
173 | | - Ok(Vc::cell( |
174 | | - format!("directory assets {}", self.path.to_string().await?,).into(), |
175 | | - )) |
176 | | - } |
177 | | -} |
0 commit comments