1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

Compare commits

..

1 commit

Author SHA1 Message Date
Nayeem Rahman
12c1350cad
Merge 971ec9b194 into 5e9b3712de 2025-01-20 16:57:20 +00:00
10 changed files with 25 additions and 114 deletions

3
Cargo.lock generated
View file

@ -1767,7 +1767,8 @@ dependencies = [
[[package]]
name = "deno_graph"
version = "0.87.0"
source = "git+https://github.com/denoland/deno_graph.git?rev=70ca7ebbb7fe9bb6cf35115ef9531aa58aadec55#70ca7ebbb7fe9bb6cf35115ef9531aa58aadec55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f56d4eb4b7c81ae920b6d18c45a1866924f93110caee80bbbc362dc28143f2bb"
dependencies = [
"async-trait",
"capacity_builder 0.5.0",

View file

@ -49,10 +49,6 @@ 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" }

View file

@ -1,6 +1,5 @@
// Copyright 2018-2025 the Deno authors. MIT license.
use std::collections::BTreeMap;
use std::error::Error;
use std::path::PathBuf;
use std::sync::Arc;
@ -855,22 +854,14 @@ impl ModuleGraphBuilder {
&self,
) -> Result<CliGraphResolver, deno_json::ToMaybeJsxImportSourceConfigError>
{
let jsx_import_source_config_unscoped = self
let jsx_import_source_config = 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_unscoped,
jsx_import_source_config_by_scope,
jsx_import_source_config,
})
}
}
@ -1202,45 +1193,28 @@ fn format_deno_graph_error(err: &dyn Error) -> String {
struct CliGraphResolver<'a> {
cjs_tracker: &'a CliCjsTracker,
resolver: &'a CliResolver,
jsx_import_source_config_unscoped: Option<JsxImportSourceConfig>,
jsx_import_source_config_by_scope:
BTreeMap<Arc<ModuleSpecifier>, Option<JsxImportSourceConfig>>,
jsx_import_source_config: Option<JsxImportSourceConfig>,
}
impl<'a> deno_graph::source::Resolver for CliGraphResolver<'a> {
fn default_jsx_import_source(
&self,
referrer: &ModuleSpecifier,
) -> Option<String> {
fn default_jsx_import_source(&self) -> Option<String> {
self
.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())
.jsx_import_source_config
.as_ref()
.and_then(|c| c.default_specifier.clone())
}
fn default_jsx_import_source_types(
&self,
referrer: &ModuleSpecifier,
) -> Option<String> {
fn default_jsx_import_source_types(&self) -> Option<String> {
self
.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())
.jsx_import_source_config
.as_ref()
.and_then(|c| c.default_types_specifier.clone())
}
fn jsx_import_source_module(&self, referrer: &ModuleSpecifier) -> &str {
fn jsx_import_source_module(&self) -> &str {
self
.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())
.jsx_import_source_config
.as_ref()
.map(|c| c.module.as_str())
.unwrap_or(deno_graph::source::DEFAULT_JSX_IMPORT_SOURCE_MODULE)
}

View file

@ -978,25 +978,19 @@ pub struct SingleReferrerGraphResolver<'a> {
}
impl<'a> deno_graph::source::Resolver for SingleReferrerGraphResolver<'a> {
fn default_jsx_import_source(
&self,
_referrer: &ModuleSpecifier,
) -> Option<String> {
fn default_jsx_import_source(&self) -> Option<String> {
self
.jsx_import_source_config
.and_then(|c| c.default_specifier.clone())
}
fn default_jsx_import_source_types(
&self,
_referrer: &ModuleSpecifier,
) -> Option<String> {
fn default_jsx_import_source_types(&self) -> Option<String> {
self
.jsx_import_source_config
.and_then(|c| c.default_types_specifier.clone())
}
fn jsx_import_source_module(&self, _referrer: &ModuleSpecifier) -> &str {
fn jsx_import_source_module(&self) -> &str {
self
.jsx_import_source_config
.map(|c| c.module.as_str())

View file

@ -115,16 +115,10 @@ exec deno {} "$@"
Ok(())
}
fn get_installer_root() -> Result<PathBuf, AnyError> {
if let Some(env_dir) = env::var_os("DENO_INSTALL_ROOT") {
fn get_installer_root() -> Result<PathBuf, io::Error> {
if let Ok(env_dir) = env::var("DENO_INSTALL_ROOT") {
if !env_dir.is_empty() {
let env_dir = PathBuf::from(env_dir);
return canonicalize_path_maybe_not_exists(&env_dir).with_context(|| {
format!(
"Canonicalizing DENO_INSTALL_ROOT ('{}').",
env_dir.display()
)
});
return canonicalize_path_maybe_not_exists(&PathBuf::from(env_dir));
}
}
// Note: on Windows, the $HOME environment variable may be set by users or by
@ -593,22 +587,11 @@ async fn resolve_shim_data(
let copy_path = get_hidden_file_with_ext(&file_path, "deno.json");
executable_args.push("--config".to_string());
executable_args.push(copy_path.to_str().unwrap().to_string());
let mut config_text = fs::read_to_string(config_path)
.with_context(|| format!("error reading {config_path}"))?;
// always remove the import map field because when someone specifies `--import-map` we
// don't want that file to be attempted to be loaded and when they don't specify that
// (which is just something we haven't implemented yet)
if let Some(new_text) = remove_import_map_field_from_text(&config_text) {
if flags.import_map_path.is_none() {
log::warn!(
"{} \"importMap\" field in the specified config file we be ignored. Use the --import-map flag instead.",
crate::colors::yellow("Warning"),
);
}
config_text = new_text;
}
extra_files.push((copy_path, config_text));
extra_files.push((
copy_path,
fs::read_to_string(config_path)
.with_context(|| format!("error reading {config_path}"))?,
));
} else {
executable_args.push("--no-config".to_string());
}
@ -648,16 +631,6 @@ async fn resolve_shim_data(
})
}
fn remove_import_map_field_from_text(config_text: &str) -> Option<String> {
let value =
jsonc_parser::cst::CstRootNode::parse(config_text, &Default::default())
.ok()?;
let root_value = value.object_value()?;
let import_map_value = root_value.get("importMap")?;
import_map_value.remove();
Some(value.to_string())
}
fn get_hidden_file_with_ext(file_path: &Path, ext: &str) -> PathBuf {
// use a dot file to prevent the file from showing up in some
// users shell auto-complete since this directory is on the PATH
@ -1612,17 +1585,4 @@ mod tests {
assert!(!file_path.exists());
}
}
#[test]
fn test_remove_import_map_field_from_text() {
assert_eq!(
remove_import_map_field_from_text(
r#"{
"importMap": "./value.json"
}"#,
)
.unwrap(),
"{}"
);
}
}

View file

@ -1,5 +0,0 @@
{
"tempDir": true,
"args": "install -g --root ./folder --config deno.json main.ts --name my-cli",
"output": "install.out"
}

View file

@ -1,3 +0,0 @@
{
"importMap": "./import_map.json"
}

View file

@ -1,3 +0,0 @@
Warning "importMap" field in the specified config file we be ignored. Use the --import-map flag instead.
✅ Successfully installed my-cli
[WILDCARD]

View file

@ -1 +0,0 @@
console.log(1);