diff --git a/fixtures/enhanced-resolve/test/fixtures/node_modules/m2/package.json b/fixtures/enhanced-resolve/test/fixtures/node_modules/m2/package.json index 0967ef42..998f25ae 100644 --- a/fixtures/enhanced-resolve/test/fixtures/node_modules/m2/package.json +++ b/fixtures/enhanced-resolve/test/fixtures/node_modules/m2/package.json @@ -1 +1,4 @@ -{} +{ + "name": "m2", + "main": "./b.js" +} diff --git a/src/lib.rs b/src/lib.rs index c68420f7..b3e38cfc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -485,7 +485,7 @@ impl ResolverGeneric { } // 2. If X begins with '/' // a. set Y to be the file system root - let path = self.cache.value(Path::new(specifier)); + let path = self.cache.value(Path::new(specifier.trim_end_matches('/'))); if let Some(path) = self.load_as_file_or_directory(&path, specifier, tsconfig, ctx)? { return Ok(path); } diff --git a/src/tests/resolve.rs b/src/tests/resolve.rs index 80e5fb79..6754be89 100644 --- a/src/tests/resolve.rs +++ b/src/tests/resolve.rs @@ -9,10 +9,15 @@ fn resolve() { let resolver = Resolver::default(); let main1_js_path = f.join("main1.js").to_string_lossy().to_string(); + let m2 = f.join("node_modules").join("m2"); + let m2_specifier = m2.to_string_lossy().to_string(); + let m2_trailing_slash = m2_specifier.clone() + "/"; #[rustfmt::skip] let pass = [ ("absolute path", f.clone(), main1_js_path.as_str(), f.join("main1.js")), + ("absolute path to package", f.clone(), m2_specifier.as_str(), m2.join("b.js")), + ("absolute path to package with trailing slash", f.clone(), m2_trailing_slash.as_str(), m2.join("b.js")), ("file with .js", f.clone(), "./main1.js", f.join("main1.js")), ("file without extension", f.clone(), "./main1", f.join("main1.js")), ("another file with .js", f.clone(), "./a.js", f.join("a.js")),