diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/fs/std_fs.rs | 10 | ||||
-rw-r--r-- | ext/node/ops/require.rs | 10 | ||||
-rw-r--r-- | ext/node/polyfills/01_require.js | 6 |
3 files changed, 6 insertions, 20 deletions
diff --git a/ext/fs/std_fs.rs b/ext/fs/std_fs.rs index 49d113c01..4bdbf4943 100644 --- a/ext/fs/std_fs.rs +++ b/ext/fs/std_fs.rs @@ -647,15 +647,7 @@ fn metadata_to_fsstat(metadata: fs::Metadata) -> FsStat { } fn realpath(path: impl AsRef<Path>) -> FsResult<PathBuf> { - let canonicalized_path = path.as_ref().canonicalize()?; - #[cfg(windows)] - let canonicalized_path = PathBuf::from( - canonicalized_path - .display() - .to_string() - .trim_start_matches("\\\\?\\"), - ); - Ok(canonicalized_path) + Ok(deno_core::strip_unc_prefix(path.as_ref().canonicalize()?)) } fn read_dir(path: impl AsRef<Path>) -> FsResult<Vec<FsDirEntry>> { diff --git a/ext/node/ops/require.rs b/ext/node/ops/require.rs index 34eac8475..1c8647bab 100644 --- a/ext/node/ops/require.rs +++ b/ext/node/ops/require.rs @@ -287,15 +287,7 @@ where let path = PathBuf::from(request); ensure_read_permission::<Env::P>(state, &path)?; let fs = state.borrow::<Arc<dyn NodeFs>>(); - let mut canonicalized_path = fs.canonicalize(&path)?; - if cfg!(windows) { - canonicalized_path = PathBuf::from( - canonicalized_path - .display() - .to_string() - .trim_start_matches("\\\\?\\"), - ); - } + let canonicalized_path = deno_core::strip_unc_prefix(fs.canonicalize(&path)?); Ok(canonicalized_path.to_string_lossy().to_string()) } diff --git a/ext/node/polyfills/01_require.js b/ext/node/polyfills/01_require.js index 8fbe5078c..ce7312ee8 100644 --- a/ext/node/polyfills/01_require.js +++ b/ext/node/polyfills/01_require.js @@ -861,9 +861,11 @@ Module.prototype.load = function (filename) { throw Error("Module already loaded"); } - this.filename = filename; + // Canonicalize the path so it's not pointing to the symlinked directory + // in `node_modules` directory of the referrer. + this.filename = ops.op_require_real_path(filename); this.paths = Module._nodeModulePaths( - pathDirname(filename), + pathDirname(this.filename), ); const extension = findLongestRegisteredExtension(filename); // allow .mjs to be overriden |