mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
fix(cli/fmt): Strip "\\?\" prefix when displaying Windows paths (#8135)
This commit is contained in:
parent
1854c6f73b
commit
6be6c517d0
6 changed files with 31 additions and 18 deletions
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
use crate::colors;
|
use crate::colors;
|
||||||
use crate::diff::diff;
|
use crate::diff::diff;
|
||||||
|
use crate::fs::canonicalize_path;
|
||||||
use crate::fs::files_in_subtree;
|
use crate::fs::files_in_subtree;
|
||||||
use crate::text_encoding;
|
use crate::text_encoding;
|
||||||
use deno_core::error::generic_error;
|
use deno_core::error::generic_error;
|
||||||
|
@ -238,16 +239,16 @@ pub fn collect_files(
|
||||||
|
|
||||||
if files.is_empty() {
|
if files.is_empty() {
|
||||||
target_files.extend(files_in_subtree(
|
target_files.extend(files_in_subtree(
|
||||||
std::env::current_dir()?.canonicalize()?,
|
canonicalize_path(&std::env::current_dir()?)?,
|
||||||
is_supported,
|
is_supported,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
for file in files {
|
for file in files {
|
||||||
if file.is_dir() {
|
if file.is_dir() {
|
||||||
target_files
|
target_files
|
||||||
.extend(files_in_subtree(file.canonicalize()?, is_supported));
|
.extend(files_in_subtree(canonicalize_path(&file)?, is_supported));
|
||||||
} else {
|
} else {
|
||||||
target_files.push(file.canonicalize()?);
|
target_files.push(canonicalize_path(&file)?);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
cli/fs.rs
16
cli/fs.rs
|
@ -4,7 +4,7 @@ use deno_core::error::AnyError;
|
||||||
pub use deno_core::normalize_path;
|
pub use deno_core::normalize_path;
|
||||||
use std::env::current_dir;
|
use std::env::current_dir;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::Write;
|
use std::io::{Error, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
|
@ -47,6 +47,20 @@ pub fn write_file_2<T: AsRef<[u8]>>(
|
||||||
file.write_all(data.as_ref())
|
file.write_all(data.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Similar to `std::fs::canonicalize()` but strips UNC prefixes on Windows.
|
||||||
|
pub fn canonicalize_path(path: &Path) -> Result<PathBuf, Error> {
|
||||||
|
let mut canonicalized_path = path.canonicalize()?;
|
||||||
|
if cfg!(windows) {
|
||||||
|
canonicalized_path = PathBuf::from(
|
||||||
|
canonicalized_path
|
||||||
|
.display()
|
||||||
|
.to_string()
|
||||||
|
.trim_start_matches("\\\\?\\"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(canonicalized_path)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, AnyError> {
|
pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, AnyError> {
|
||||||
let resolved_path = if path.is_absolute() {
|
let resolved_path = if path.is_absolute() {
|
||||||
path.to_owned()
|
path.to_owned()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use crate::flags::Flags;
|
use crate::flags::Flags;
|
||||||
|
use crate::fs::canonicalize_path;
|
||||||
use deno_core::error::generic_error;
|
use deno_core::error::generic_error;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::url::Url;
|
use deno_core::url::Url;
|
||||||
|
@ -84,7 +85,7 @@ deno {} "$@"
|
||||||
fn get_installer_root() -> Result<PathBuf, io::Error> {
|
fn get_installer_root() -> Result<PathBuf, io::Error> {
|
||||||
if let Ok(env_dir) = env::var("DENO_INSTALL_ROOT") {
|
if let Ok(env_dir) = env::var("DENO_INSTALL_ROOT") {
|
||||||
if !env_dir.is_empty() {
|
if !env_dir.is_empty() {
|
||||||
return PathBuf::from(env_dir).canonicalize();
|
return canonicalize_path(&PathBuf::from(env_dir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Note: on Windows, the $HOME environment variable may be set by users or by
|
// Note: on Windows, the $HOME environment variable may be set by users or by
|
||||||
|
@ -127,7 +128,7 @@ pub fn install(
|
||||||
force: bool,
|
force: bool,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let root = if let Some(root) = root {
|
let root = if let Some(root) = root {
|
||||||
root.canonicalize()?
|
canonicalize_path(&root)?
|
||||||
} else {
|
} else {
|
||||||
get_installer_root()?
|
get_installer_root()?
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// Some deserializer fields are only used on Unix and Windows build fails without it
|
// Some deserializer fields are only used on Unix and Windows build fails without it
|
||||||
use super::io::std_file_resource;
|
use super::io::std_file_resource;
|
||||||
use super::io::{FileMetadata, StreamResource, StreamResourceHolder};
|
use super::io::{FileMetadata, StreamResource, StreamResourceHolder};
|
||||||
|
use crate::fs::canonicalize_path;
|
||||||
use crate::permissions::Permissions;
|
use crate::permissions::Permissions;
|
||||||
use deno_core::error::custom_error;
|
use deno_core::error::custom_error;
|
||||||
use deno_core::error::type_error;
|
use deno_core::error::type_error;
|
||||||
|
@ -934,11 +935,8 @@ fn op_realpath_sync(
|
||||||
debug!("op_realpath_sync {}", path.display());
|
debug!("op_realpath_sync {}", path.display());
|
||||||
// corresponds to the realpath on Unix and
|
// corresponds to the realpath on Unix and
|
||||||
// CreateFile and GetFinalPathNameByHandle on Windows
|
// CreateFile and GetFinalPathNameByHandle on Windows
|
||||||
let realpath = std::fs::canonicalize(&path)?;
|
let realpath = canonicalize_path(&path)?;
|
||||||
let mut realpath_str = into_string(realpath.into_os_string())?;
|
let realpath_str = into_string(realpath.into_os_string())?;
|
||||||
if cfg!(windows) {
|
|
||||||
realpath_str = realpath_str.trim_start_matches("\\\\?\\").to_string();
|
|
||||||
}
|
|
||||||
Ok(json!(realpath_str))
|
Ok(json!(realpath_str))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -963,11 +961,8 @@ async fn op_realpath_async(
|
||||||
debug!("op_realpath_async {}", path.display());
|
debug!("op_realpath_async {}", path.display());
|
||||||
// corresponds to the realpath on Unix and
|
// corresponds to the realpath on Unix and
|
||||||
// CreateFile and GetFinalPathNameByHandle on Windows
|
// CreateFile and GetFinalPathNameByHandle on Windows
|
||||||
let realpath = std::fs::canonicalize(&path)?;
|
let realpath = canonicalize_path(&path)?;
|
||||||
let mut realpath_str = into_string(realpath.into_os_string())?;
|
let realpath_str = into_string(realpath.into_os_string())?;
|
||||||
if cfg!(windows) {
|
|
||||||
realpath_str = realpath_str.trim_start_matches("\\\\?\\").to_string();
|
|
||||||
}
|
|
||||||
Ok(json!(realpath_str))
|
Ok(json!(realpath_str))
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::disk_cache::DiskCache;
|
||||||
use crate::file_fetcher::SourceFile;
|
use crate::file_fetcher::SourceFile;
|
||||||
use crate::file_fetcher::SourceFileFetcher;
|
use crate::file_fetcher::SourceFileFetcher;
|
||||||
use crate::flags::Flags;
|
use crate::flags::Flags;
|
||||||
|
use crate::fs::canonicalize_path;
|
||||||
use crate::js;
|
use crate::js;
|
||||||
use crate::media_type::MediaType;
|
use crate::media_type::MediaType;
|
||||||
use crate::module_graph::ModuleGraph;
|
use crate::module_graph::ModuleGraph;
|
||||||
|
@ -174,7 +175,7 @@ impl CompilerConfig {
|
||||||
|
|
||||||
// Convert the PathBuf to a canonicalized string. This is needed by the
|
// Convert the PathBuf to a canonicalized string. This is needed by the
|
||||||
// compiler to properly deal with the configuration.
|
// compiler to properly deal with the configuration.
|
||||||
let config_path = config_file.canonicalize().map_err(|_| {
|
let config_path = canonicalize_path(&config_file).map_err(|_| {
|
||||||
io::Error::new(
|
io::Error::new(
|
||||||
io::ErrorKind::InvalidInput,
|
io::ErrorKind::InvalidInput,
|
||||||
format!(
|
format!(
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
use crate::fs::canonicalize_path;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::serde_json;
|
use deno_core::serde_json;
|
||||||
use deno_core::serde_json::json;
|
use deno_core::serde_json::json;
|
||||||
|
@ -266,7 +267,7 @@ impl TsConfig {
|
||||||
if let Some(path) = maybe_path {
|
if let Some(path) = maybe_path {
|
||||||
let cwd = std::env::current_dir()?;
|
let cwd = std::env::current_dir()?;
|
||||||
let config_file = cwd.join(path);
|
let config_file = cwd.join(path);
|
||||||
let config_path = config_file.canonicalize().map_err(|_| {
|
let config_path = canonicalize_path(&config_file).map_err(|_| {
|
||||||
std::io::Error::new(
|
std::io::Error::new(
|
||||||
std::io::ErrorKind::InvalidInput,
|
std::io::ErrorKind::InvalidInput,
|
||||||
format!(
|
format!(
|
||||||
|
|
Loading…
Reference in a new issue