Skip to content

Conversation

CertainLach
Copy link
Contributor

@CertainLach CertainLach commented Sep 17, 2025

While in web you can have multiple import maps, Deno only allows one to be specified right now.

importMaps are merged at WorkspaceResolver level, and passed as a list everywhere else, as it is useful to look at all requirements sometimes, e.g on package installer level - resolver might want to take into account all the requirements, including overriden.

The current implementation lacks tests, especially around LSP part, as I haven't figured out some parts about the implementation that Deno team wants, e.g: right now deno disallows specifying both import map and imports in deno.json, yet this check seems to be redundant in case of multiple import maps present.

Fixes: #25450 #30689

@CertainLach
Copy link
Contributor Author

Given that multiple import maps are possible now, should --import-map argument be mutually exclusive with deno.json importMap field? I believe it should just take priority over, same as I did with "deno.json working as an import_map file"

@CertainLach
Copy link
Contributor Author

Note that the import_map loading process is not recursive right now, so it won't be possible to point importMap field to another workspaces deno.json, the initial focus is only on loading standard-compliant import maps, without nested importMap field.

Comment on lines +346 to +356
dependencies: maybe_external_import_maps
.into_iter()
.flat_map(deno_config::import_map::import_map_deps)
.chain(
root_folder
.deno_json
.as_deref()
.map(|d| d.dependencies())
.unwrap_or_default(),
)
.collect(),
Copy link
Contributor Author

@CertainLach CertainLach Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged importmap approach won't work here either, since by spec the first importmap with resolved import takes precedence, yet in case of multiple jsr/npm imports - during the merge we might want to satisfy version requirements of all import maps here, and this is only possible if we'll be able to access all the referenced import maps.

@CertainLach CertainLach force-pushed the feat/multiple-import-maps branch from c4234ad to f93c9b5 Compare September 18, 2025 01:50
@CertainLach
Copy link
Contributor Author

LSP resolver is broken, an I'm not sure right now how it should work in the first place.

Resolver seem to work fine for other purposes, yet there is still no tests for updated functionality.

@CertainLach CertainLach marked this pull request as ready for review September 18, 2025 02:43
@CertainLach
Copy link
Contributor Author

Remaining LSP resolver test failures are caused by ImportMap::resolve method, which may resolve paths like /~/ into themselves even if mapping does not exists:

  pub fn resolve(
    &self,
    specifier: &str,
    referrer: &Url,
  ) -> Result<Url, ImportMapError> {
    let as_url: Option<Url> = try_url_like_specifier(specifier, referrer);
...
    // The specifier was able to be turned into a URL, but wasn't remapped into anything.
    if let Some(as_url) = as_url {
      return Ok(as_url);
    }
  }

Thus not triggering the "continue to the next import_map" logic.
Changes are required on the import_map crate side.

@CLAassistant
Copy link

CLAassistant commented Sep 18, 2025

CLA assistant check
All committers have signed the CLA.

@CertainLach CertainLach force-pushed the feat/multiple-import-maps branch from 2851085 to fa26b18 Compare September 18, 2025 21:05
@CertainLach
Copy link
Contributor Author

After the last commits there is no failing tests. Import map merging is used for lsp, but not in a way I wanted to. Still, I believe diagnostics and further improvements should be developed in later PRs.

CI doesn't pass here, as I am adding workspace patch for my import_map PR (denoland/import_map#91), and despite it declared in .gitmodules - it seems that CI is not doing recursive clone, thus fails.

@bartlomieju bartlomieju added this to the 2.6.0 milestone Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for multiple import maps
4 participants