summaryrefslogtreecommitdiff
path: root/cli/tools/vendor/mappings.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-02-22 14:15:25 -0500
committerGitHub <noreply@github.com>2023-02-22 14:15:25 -0500
commita6ca4d0d61c95b9f7fa79ecce81a31a6d1f6cc5d (patch)
tree278a915d7722a8a3d1fffbfa1f3a12752f44d13f /cli/tools/vendor/mappings.rs
parent0f9daaeacb402a7199e58b14ad01ec0091ac2c8d (diff)
refactor: use deno_graph for npm specifiers (#17858)
This changes npm specifiers to be handled by deno_graph and resolved to an npm package name and version when the specifier is encountered. It also slightly changes how npm specifier resolution occurs—previously it would collect all the npm specifiers and resolve them all at once, but now it resolves them on the fly as they are encountered in the module graph. https://github.com/denoland/deno_graph/pull/232 --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tools/vendor/mappings.rs')
-rw-r--r--cli/tools/vendor/mappings.rs58
1 files changed, 33 insertions, 25 deletions
diff --git a/cli/tools/vendor/mappings.rs b/cli/tools/vendor/mappings.rs
index 399002ea3..1ecc14edf 100644
--- a/cli/tools/vendor/mappings.rs
+++ b/cli/tools/vendor/mappings.rs
@@ -39,8 +39,9 @@ impl Mappings {
remote_modules: &[&Module],
output_dir: &Path,
) -> Result<Self, AnyError> {
- let partitioned_specifiers =
- partition_by_root_specifiers(remote_modules.iter().map(|m| &m.specifier));
+ let partitioned_specifiers = partition_by_root_specifiers(
+ remote_modules.iter().map(|m| m.specifier()),
+ );
let mut mapped_paths = HashSet::new();
let mut mappings = HashMap::new();
let mut proxies = HashMap::new();
@@ -52,7 +53,12 @@ impl Mappings {
&mut mapped_paths,
);
for specifier in specifiers {
- let media_type = graph.get(&specifier).unwrap().media_type;
+ let module = graph.get(&specifier).unwrap();
+ let media_type = match module {
+ Module::Esm(module) => module.media_type,
+ Module::Json(_) => MediaType::Json,
+ Module::Node(_) | Module::Npm(_) | Module::External(_) => continue,
+ };
let sub_path = sanitize_filepath(&make_url_relative(&root, &{
let mut specifier = specifier.clone();
specifier.set_query(None);
@@ -75,28 +81,30 @@ impl Mappings {
// resolve all the "proxy" paths to use for when an x-typescript-types header is specified
for module in remote_modules {
- if let Some(resolved) = &module
- .maybe_types_dependency
- .as_ref()
- .and_then(|d| d.dependency.ok())
- {
- let range = &resolved.range;
- // hack to tell if it's an x-typescript-types header
- let is_ts_types_header =
- range.start == Position::zeroed() && range.end == Position::zeroed();
- if is_ts_types_header {
- let module_path = mappings.get(&module.specifier).unwrap();
- let proxied_path = get_unique_path(
- path_with_stem_suffix(module_path, ".proxied"),
- &mut mapped_paths,
- );
- proxies.insert(
- module.specifier.clone(),
- ProxiedModule {
- output_path: proxied_path,
- declaration_specifier: resolved.specifier.clone(),
- },
- );
+ if let Some(module) = module.esm() {
+ if let Some(resolved) = &module
+ .maybe_types_dependency
+ .as_ref()
+ .and_then(|d| d.dependency.ok())
+ {
+ let range = &resolved.range;
+ // hack to tell if it's an x-typescript-types header
+ let is_ts_types_header = range.start == Position::zeroed()
+ && range.end == Position::zeroed();
+ if is_ts_types_header {
+ let module_path = mappings.get(&module.specifier).unwrap();
+ let proxied_path = get_unique_path(
+ path_with_stem_suffix(module_path, ".proxied"),
+ &mut mapped_paths,
+ );
+ proxies.insert(
+ module.specifier.clone(),
+ ProxiedModule {
+ output_path: proxied_path,
+ declaration_specifier: resolved.specifier.clone(),
+ },
+ );
+ }
}
}
}