mirror of
https://github.com/denoland/deno.git
synced 2025-01-20 20:42:19 -05:00
scoped jsx import source config
This commit is contained in:
parent
971ec9b194
commit
1e9e24f1f2
4 changed files with 52 additions and 17 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -1767,8 +1767,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "deno_graph"
|
||||
version = "0.87.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f56d4eb4b7c81ae920b6d18c45a1866924f93110caee80bbbc362dc28143f2bb"
|
||||
source = "git+https://github.com/denoland/deno_graph.git?rev=70ca7ebbb7fe9bb6cf35115ef9531aa58aadec55#70ca7ebbb7fe9bb6cf35115ef9531aa58aadec55"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"capacity_builder 0.5.0",
|
||||
|
|
|
@ -49,6 +49,10 @@ edition = "2021"
|
|||
license = "MIT"
|
||||
repository = "https://github.com/denoland/deno"
|
||||
|
||||
# TODO(nayeemrmn): Use proper version when https://github.com/denoland/deno_graph/pull/565 lands!
|
||||
[patch.crates-io]
|
||||
deno_graph = { git = "https://github.com/denoland/deno_graph.git", rev = "70ca7ebbb7fe9bb6cf35115ef9531aa58aadec55" }
|
||||
|
||||
[workspace.dependencies]
|
||||
deno_ast = { version = "=0.44.0", features = ["transpiling"] }
|
||||
deno_core = { version = "0.331.0" }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::error::Error;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
@ -854,14 +855,22 @@ impl ModuleGraphBuilder {
|
|||
&self,
|
||||
) -> Result<CliGraphResolver, deno_json::ToMaybeJsxImportSourceConfigError>
|
||||
{
|
||||
let jsx_import_source_config = self
|
||||
let jsx_import_source_config_unscoped = self
|
||||
.cli_options
|
||||
.start_dir
|
||||
.to_maybe_jsx_import_source_config()?;
|
||||
let mut jsx_import_source_config_by_scope = BTreeMap::default();
|
||||
for (dir_url, dir) in &self.cli_options.all_dirs {
|
||||
let jsx_import_source_config_unscoped =
|
||||
dir.to_maybe_jsx_import_source_config()?;
|
||||
jsx_import_source_config_by_scope
|
||||
.insert(dir_url.clone(), jsx_import_source_config_unscoped);
|
||||
}
|
||||
Ok(CliGraphResolver {
|
||||
cjs_tracker: &self.cjs_tracker,
|
||||
resolver: &self.resolver,
|
||||
jsx_import_source_config,
|
||||
jsx_import_source_config_unscoped,
|
||||
jsx_import_source_config_by_scope,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1193,28 +1202,45 @@ fn format_deno_graph_error(err: &dyn Error) -> String {
|
|||
struct CliGraphResolver<'a> {
|
||||
cjs_tracker: &'a CliCjsTracker,
|
||||
resolver: &'a CliResolver,
|
||||
jsx_import_source_config: Option<JsxImportSourceConfig>,
|
||||
jsx_import_source_config_unscoped: Option<JsxImportSourceConfig>,
|
||||
jsx_import_source_config_by_scope:
|
||||
BTreeMap<Arc<ModuleSpecifier>, Option<JsxImportSourceConfig>>,
|
||||
}
|
||||
|
||||
impl<'a> deno_graph::source::Resolver for CliGraphResolver<'a> {
|
||||
fn default_jsx_import_source(&self) -> Option<String> {
|
||||
fn default_jsx_import_source(
|
||||
&self,
|
||||
referrer: &ModuleSpecifier,
|
||||
) -> Option<String> {
|
||||
self
|
||||
.jsx_import_source_config
|
||||
.as_ref()
|
||||
.jsx_import_source_config_by_scope
|
||||
.iter()
|
||||
.rfind(|(s, _)| referrer.as_str().starts_with(s.as_str()))
|
||||
.map(|(_, c)| c.as_ref())
|
||||
.unwrap_or(self.jsx_import_source_config_unscoped.as_ref())
|
||||
.and_then(|c| c.default_specifier.clone())
|
||||
}
|
||||
|
||||
fn default_jsx_import_source_types(&self) -> Option<String> {
|
||||
fn default_jsx_import_source_types(
|
||||
&self,
|
||||
referrer: &ModuleSpecifier,
|
||||
) -> Option<String> {
|
||||
self
|
||||
.jsx_import_source_config
|
||||
.as_ref()
|
||||
.jsx_import_source_config_by_scope
|
||||
.iter()
|
||||
.rfind(|(s, _)| referrer.as_str().starts_with(s.as_str()))
|
||||
.map(|(_, c)| c.as_ref())
|
||||
.unwrap_or(self.jsx_import_source_config_unscoped.as_ref())
|
||||
.and_then(|c| c.default_types_specifier.clone())
|
||||
}
|
||||
|
||||
fn jsx_import_source_module(&self) -> &str {
|
||||
fn jsx_import_source_module(&self, referrer: &ModuleSpecifier) -> &str {
|
||||
self
|
||||
.jsx_import_source_config
|
||||
.as_ref()
|
||||
.jsx_import_source_config_by_scope
|
||||
.iter()
|
||||
.rfind(|(s, _)| referrer.as_str().starts_with(s.as_str()))
|
||||
.map(|(_, c)| c.as_ref())
|
||||
.unwrap_or(self.jsx_import_source_config_unscoped.as_ref())
|
||||
.map(|c| c.module.as_str())
|
||||
.unwrap_or(deno_graph::source::DEFAULT_JSX_IMPORT_SOURCE_MODULE)
|
||||
}
|
||||
|
|
|
@ -978,19 +978,25 @@ pub struct SingleReferrerGraphResolver<'a> {
|
|||
}
|
||||
|
||||
impl<'a> deno_graph::source::Resolver for SingleReferrerGraphResolver<'a> {
|
||||
fn default_jsx_import_source(&self) -> Option<String> {
|
||||
fn default_jsx_import_source(
|
||||
&self,
|
||||
_referrer: &ModuleSpecifier,
|
||||
) -> Option<String> {
|
||||
self
|
||||
.jsx_import_source_config
|
||||
.and_then(|c| c.default_specifier.clone())
|
||||
}
|
||||
|
||||
fn default_jsx_import_source_types(&self) -> Option<String> {
|
||||
fn default_jsx_import_source_types(
|
||||
&self,
|
||||
_referrer: &ModuleSpecifier,
|
||||
) -> Option<String> {
|
||||
self
|
||||
.jsx_import_source_config
|
||||
.and_then(|c| c.default_types_specifier.clone())
|
||||
}
|
||||
|
||||
fn jsx_import_source_module(&self) -> &str {
|
||||
fn jsx_import_source_module(&self, _referrer: &ModuleSpecifier) -> &str {
|
||||
self
|
||||
.jsx_import_source_config
|
||||
.map(|c| c.module.as_str())
|
||||
|
|
Loading…
Add table
Reference in a new issue