diff --git a/libs/node_resolver/resolution.rs b/libs/node_resolver/resolution.rs index 47de40278c..b0b10e32ce 100644 --- a/libs/node_resolver/resolution.rs +++ b/libs/node_resolver/resolution.rs @@ -553,10 +553,9 @@ impl< // } let p_str = path.to_str().unwrap(); - let path = if p_str.ends_with('/') { - PathBuf::from(&p_str[p_str.len() - 1..]) - } else { - path + let path = match p_str.strip_suffix('/') { + Some(s) => Cow::Borrowed(Path::new(s)), + None => Cow::Owned(path), }; let maybe_file_type = self.sys.get_file_type(&path); @@ -570,7 +569,7 @@ impl< .find(|e| self.sys.is_file(&path.join(e))); Err( UnsupportedDirImportError { - dir_url: UrlOrPath::Path(path), + dir_url: UrlOrPath::Path(path.into_owned()), maybe_referrer: maybe_referrer.map(|r| r.display()), suggested_file_name, } @@ -607,7 +606,7 @@ impl< Ok( maybe_url .map(UrlOrPath::Url) - .unwrap_or(UrlOrPath::Path(path)), + .unwrap_or(UrlOrPath::Path(path.into_owned())), ) } _ => { @@ -626,7 +625,7 @@ impl< ModuleNotFoundError { suggested_ext: self .module_not_found_ext_suggestion(&path, resolved_method), - specifier: UrlOrPath::Path(path), + specifier: UrlOrPath::Path(path.into_owned()), maybe_referrer: maybe_referrer.map(|r| r.display()), } .into(), diff --git a/tests/specs/bundle/require_dotdot/__test__.jsonc b/tests/specs/bundle/require_dotdot/__test__.jsonc new file mode 100644 index 0000000000..1dcf32ec04 --- /dev/null +++ b/tests/specs/bundle/require_dotdot/__test__.jsonc @@ -0,0 +1,13 @@ +{ + "tempDir": true, + "steps": [ + { + "args": "bundle -o out.js ./repro/foo.cjs", + "output": "[WILDCARD]" + }, + { + "args": "run -A out.js", + "output": "hello from index\n" + } + ] +} diff --git a/tests/specs/bundle/require_dotdot/index.js b/tests/specs/bundle/require_dotdot/index.js new file mode 100644 index 0000000000..a67a5209e7 --- /dev/null +++ b/tests/specs/bundle/require_dotdot/index.js @@ -0,0 +1 @@ +module.exports = "hello from index"; diff --git a/tests/specs/bundle/require_dotdot/package.json b/tests/specs/bundle/require_dotdot/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/tests/specs/bundle/require_dotdot/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/specs/bundle/require_dotdot/repro/foo.cjs b/tests/specs/bundle/require_dotdot/repro/foo.cjs new file mode 100644 index 0000000000..61ad270acd --- /dev/null +++ b/tests/specs/bundle/require_dotdot/repro/foo.cjs @@ -0,0 +1,2 @@ +const index = require(".."); +console.log(index);