mirror of
https://github.com/denoland/deno.git
synced 2025-03-10 06:07:03 -04:00
fix(config): do not canonicalize config file path before loading (#19436)
I'm unsure why we canonicalize the config file path when loading and the canonicalization is causing issues in #19431 because everything in the lsp is not canonicalized except the config file (actually, the config file is only canonicalized when auto-discovered and not whens pecified). We also don't canonicalize module paths when loading them. Canonicalization was added in https://github.com/denoland/deno/pull/7621
This commit is contained in:
parent
573cf00648
commit
8a737f5a16
2 changed files with 40 additions and 53 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use crate::args::ConfigFlag;
|
use crate::args::ConfigFlag;
|
||||||
use crate::args::Flags;
|
use crate::args::Flags;
|
||||||
use crate::util::fs::canonicalize_path;
|
|
||||||
use crate::util::path::specifier_parent;
|
use crate::util::path::specifier_parent;
|
||||||
use crate::util::path::specifier_to_file_path;
|
use crate::util::path::specifier_to_file_path;
|
||||||
|
|
||||||
|
@ -709,6 +708,24 @@ impl ConfigFile {
|
||||||
start: &Path,
|
start: &Path,
|
||||||
checked: &mut HashSet<PathBuf>,
|
checked: &mut HashSet<PathBuf>,
|
||||||
) -> Result<Option<ConfigFile>, AnyError> {
|
) -> Result<Option<ConfigFile>, AnyError> {
|
||||||
|
fn is_skippable_err(e: &AnyError) -> bool {
|
||||||
|
if let Some(ioerr) = e.downcast_ref::<std::io::Error>() {
|
||||||
|
use std::io::ErrorKind::*;
|
||||||
|
match ioerr.kind() {
|
||||||
|
InvalidInput | PermissionDenied | NotFound => {
|
||||||
|
// ok keep going
|
||||||
|
true
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
const NOT_A_DIRECTORY: i32 = 20;
|
||||||
|
cfg!(unix) && ioerr.raw_os_error() == Some(NOT_A_DIRECTORY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Filenames that Deno will recognize when discovering config.
|
/// Filenames that Deno will recognize when discovering config.
|
||||||
const CONFIG_FILE_NAMES: [&str; 2] = ["deno.json", "deno.jsonc"];
|
const CONFIG_FILE_NAMES: [&str; 2] = ["deno.json", "deno.jsonc"];
|
||||||
|
|
||||||
|
@ -729,20 +746,11 @@ impl ConfigFile {
|
||||||
log::debug!("Config file found at '{}'", f.display());
|
log::debug!("Config file found at '{}'", f.display());
|
||||||
return Ok(Some(cf));
|
return Ok(Some(cf));
|
||||||
}
|
}
|
||||||
|
Err(e) if is_skippable_err(&e) => {
|
||||||
|
// ok, keep going
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if let Some(ioerr) = e.downcast_ref::<std::io::Error>() {
|
return Err(e);
|
||||||
use std::io::ErrorKind::*;
|
|
||||||
match ioerr.kind() {
|
|
||||||
InvalidInput | PermissionDenied | NotFound => {
|
|
||||||
// ok keep going
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
return Err(e); // Unknown error. Stop.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Err(e); // Parse error or something else. Stop.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -755,50 +763,31 @@ impl ConfigFile {
|
||||||
pub fn read(config_path: &Path) -> Result<Self, AnyError> {
|
pub fn read(config_path: &Path) -> Result<Self, AnyError> {
|
||||||
debug_assert!(config_path.is_absolute());
|
debug_assert!(config_path.is_absolute());
|
||||||
|
|
||||||
// perf: Check if the config file exists before canonicalizing path.
|
let specifier =
|
||||||
if !config_path.exists() {
|
ModuleSpecifier::from_file_path(config_path).map_err(|_| {
|
||||||
return Err(
|
|
||||||
std::io::Error::new(
|
|
||||||
std::io::ErrorKind::InvalidInput,
|
|
||||||
format!(
|
|
||||||
"Could not find the config file: {}",
|
|
||||||
config_path.to_string_lossy()
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let config_path = canonicalize_path(config_path).map_err(|_| {
|
|
||||||
std::io::Error::new(
|
|
||||||
std::io::ErrorKind::InvalidInput,
|
|
||||||
format!(
|
|
||||||
"Could not find the config file: {}",
|
|
||||||
config_path.to_string_lossy()
|
|
||||||
),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
let config_specifier = ModuleSpecifier::from_file_path(&config_path)
|
|
||||||
.map_err(|_| {
|
|
||||||
anyhow!(
|
anyhow!(
|
||||||
"Could not convert path to specifier. Path: {}",
|
"Could not convert config file path to specifier. Path: {}",
|
||||||
config_path.display()
|
config_path.display()
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
Self::from_specifier(config_specifier)
|
Self::from_specifier_and_path(specifier, config_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_specifier(specifier: ModuleSpecifier) -> Result<Self, AnyError> {
|
pub fn from_specifier(specifier: ModuleSpecifier) -> Result<Self, AnyError> {
|
||||||
let config_path = specifier_to_file_path(&specifier)?;
|
let config_path =
|
||||||
let config_text = match std::fs::read_to_string(config_path) {
|
specifier_to_file_path(&specifier).with_context(|| {
|
||||||
Ok(text) => text,
|
format!("Invalid config file path for '{}'.", specifier)
|
||||||
Err(err) => bail!(
|
})?;
|
||||||
"Error reading config file {}: {}",
|
Self::from_specifier_and_path(specifier, &config_path)
|
||||||
specifier,
|
}
|
||||||
err.to_string()
|
|
||||||
),
|
fn from_specifier_and_path(
|
||||||
};
|
specifier: ModuleSpecifier,
|
||||||
Self::new(&config_text, specifier)
|
config_path: &Path,
|
||||||
|
) -> Result<Self, AnyError> {
|
||||||
|
let text = std::fs::read_to_string(config_path)
|
||||||
|
.with_context(|| format!("Error reading config file '{}'.", specifier))?;
|
||||||
|
Self::new(&text, specifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(text: &str, specifier: ModuleSpecifier) -> Result<Self, AnyError> {
|
pub fn new(text: &str, specifier: ModuleSpecifier) -> Result<Self, AnyError> {
|
||||||
|
|
|
@ -396,8 +396,6 @@ fn discover_package_json(
|
||||||
// `package.json` is ignored in bundle/compile/etc.
|
// `package.json` is ignored in bundle/compile/etc.
|
||||||
|
|
||||||
if let Some(package_json_dir) = flags.package_json_search_dir(current_dir) {
|
if let Some(package_json_dir) = flags.package_json_search_dir(current_dir) {
|
||||||
let package_json_dir =
|
|
||||||
canonicalize_path_maybe_not_exists(&package_json_dir)?;
|
|
||||||
return package_json::discover_from(&package_json_dir, maybe_stop_at);
|
return package_json::discover_from(&package_json_dir, maybe_stop_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue