Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Jul 30, 2024
1 parent f03be42 commit 449e71a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
2 changes: 1 addition & 1 deletion crates/turbopack-core/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2575,7 +2575,7 @@ async fn handle_exports_imports_field(

let values = exports_imports_field
.lookup(&req)
.map(|m| m.try_into_self())
.map(AliasMatch::try_into_self)
.collect::<Result<Vec<_>>>()?;

for value in values.iter() {
Expand Down
15 changes: 8 additions & 7 deletions crates/turbopack-core/src/resolve/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@ pub enum ImportMapping {
Dynamic(Vc<Box<dyn ImportMappingReplacement>>),
}

/// An `ImportMapping` that was applied to a pattern. See `ImportMapping` for
/// more details on the variants.
#[turbo_tasks::value(shared)]
#[derive(Clone)]
pub enum ReplacedImportMapping {
External(Option<RcStr>, ExternalType),
/// An already resolved result that will be returned directly.
Direct(Vc<ResolveResult>),
/// A request alias that will be resolved first, and fall back to resolving
/// the original request if it fails. Useful for the tsconfig.json
/// `compilerOptions.paths` option and Next aliases.
PrimaryAlternative(Pattern, Option<Vc<FileSystemPath>>),
Ignore,
Empty,
Expand Down Expand Up @@ -423,9 +421,12 @@ impl ImportMap {
self.map.lookup(&request_pattern)
};
if let Some(result) = lookup.next() {
let x: Vc<ReplacedImportMapping> = result.try_join_into_self().await?;
return import_mapping_to_result(x, lookup_path, request).await;
} else {
return import_mapping_to_result(
result.try_join_into_self().await?,
lookup_path,
request,
)
.await;
}
}
Ok(ImportMapResult::NoEntry)
Expand Down
22 changes: 2 additions & 20 deletions crates/turbopack-core/src/resolve/remap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,13 @@ pub enum SubpathValue {
Excluded,
}

/// The result an "exports"/"imports" field describes. Can represent multiple
/// alternatives, conditional result, ignored result (null mapping) and a plain
/// result.
/// A `SubpathValue` that was applied to a pattern. See `SubpathValue` for
/// more details on the variants.
#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
pub enum SubpathValueResult {
/// Alternative subpaths, defined with `"path": ["other1", "other2"]`,
/// allows for specifying multiple possible remappings to be tried. This
/// may be that conditions didn't match, or that a particular path
/// wasn't found.
Alternatives(Vec<SubpathValueResult>),

/// Conditional subpaths, defined with `"path": { "condition": "other"}`,
/// allow remapping based on certain predefined conditions. Eg, if using
/// ESM import syntax, the `import` condition allows you to remap to a
/// file that uses ESM syntax.
/// Node defines several conditions in https://nodejs.org/api/packages.html#conditional-exports
/// TODO: Should this use an enum of predefined keys?
Conditional(Vec<(RcStr, SubpathValueResult)>),

/// A result subpath, defined with `"path": "other"`, remaps imports of
/// `path` to `other`.
Result(Pattern),

/// An excluded subpath, defined with `"path": null`, prevents importing
/// this subpath.
Excluded,
}

Expand Down

0 comments on commit 449e71a

Please sign in to comment.