mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(compat): ESM resolver for package subpath (#13599)
This commit is contained in:
parent
a7850d7fe6
commit
d0dd838521
5 changed files with 23 additions and 1 deletions
|
@ -903,7 +903,7 @@ fn parse_package_name(
|
|||
}
|
||||
|
||||
let package_name = if let Some(index) = separator_index {
|
||||
specifier[0..=index].to_string()
|
||||
specifier[0..index].to_string()
|
||||
} else {
|
||||
specifier.to_string()
|
||||
};
|
||||
|
@ -1195,6 +1195,22 @@ mod tests {
|
|||
assert_eq!(actual.to_result().unwrap(), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn package_subpath() {
|
||||
let cwd = testdir("subpath");
|
||||
let main = Url::from_file_path(cwd.join("main.js")).unwrap();
|
||||
let actual = node_resolve("foo", main.as_str(), &cwd).unwrap();
|
||||
let expected =
|
||||
Url::from_file_path(cwd.join("node_modules/foo/index.js")).unwrap();
|
||||
matches!(actual, ResolveResponse::CommonJs(_));
|
||||
assert_eq!(actual.to_result().unwrap(), expected);
|
||||
let actual = node_resolve("foo/server.js", main.as_str(), &cwd).unwrap();
|
||||
let expected =
|
||||
Url::from_file_path(cwd.join("node_modules/foo/server.js")).unwrap();
|
||||
matches!(actual, ResolveResponse::CommonJs(_));
|
||||
assert_eq!(actual.to_result().unwrap(), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_deps() {
|
||||
let cwd = testdir("basic_deps");
|
||||
|
|
2
cli/compat/testdata/subpath/main.js
vendored
Normal file
2
cli/compat/testdata/subpath/main.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
import "foo";
|
||||
import "foo/server.js";
|
0
cli/compat/testdata/subpath/node_modules/foo/index.js
generated
vendored
Normal file
0
cli/compat/testdata/subpath/node_modules/foo/index.js
generated
vendored
Normal file
4
cli/compat/testdata/subpath/node_modules/foo/package.json
generated
vendored
Normal file
4
cli/compat/testdata/subpath/node_modules/foo/package.json
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name": "foo",
|
||||
"main": "index.js"
|
||||
}
|
0
cli/compat/testdata/subpath/node_modules/foo/server.js
generated
vendored
Normal file
0
cli/compat/testdata/subpath/node_modules/foo/server.js
generated
vendored
Normal file
Loading…
Reference in a new issue