diff options
-rw-r--r-- | cli/compat/esm_resolver.rs | 18 | ||||
-rw-r--r-- | cli/compat/testdata/subpath/main.js | 2 | ||||
-rw-r--r-- | cli/compat/testdata/subpath/node_modules/foo/index.js | 0 | ||||
-rw-r--r-- | cli/compat/testdata/subpath/node_modules/foo/package.json | 4 | ||||
-rw-r--r-- | cli/compat/testdata/subpath/node_modules/foo/server.js | 0 |
5 files changed, 23 insertions, 1 deletions
diff --git a/cli/compat/esm_resolver.rs b/cli/compat/esm_resolver.rs index 13eb1efe6..357a95de8 100644 --- a/cli/compat/esm_resolver.rs +++ b/cli/compat/esm_resolver.rs @@ -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() }; @@ -1196,6 +1196,22 @@ mod tests { } #[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"); let main = Url::from_file_path(cwd.join("main.js")).unwrap(); diff --git a/cli/compat/testdata/subpath/main.js b/cli/compat/testdata/subpath/main.js new file mode 100644 index 000000000..ed1fe019e --- /dev/null +++ b/cli/compat/testdata/subpath/main.js @@ -0,0 +1,2 @@ +import "foo"; +import "foo/server.js"; diff --git a/cli/compat/testdata/subpath/node_modules/foo/index.js b/cli/compat/testdata/subpath/node_modules/foo/index.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/cli/compat/testdata/subpath/node_modules/foo/index.js diff --git a/cli/compat/testdata/subpath/node_modules/foo/package.json b/cli/compat/testdata/subpath/node_modules/foo/package.json new file mode 100644 index 000000000..26f2d565a --- /dev/null +++ b/cli/compat/testdata/subpath/node_modules/foo/package.json @@ -0,0 +1,4 @@ +{ + "name": "foo", + "main": "index.js" +}
\ No newline at end of file diff --git a/cli/compat/testdata/subpath/node_modules/foo/server.js b/cli/compat/testdata/subpath/node_modules/foo/server.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/cli/compat/testdata/subpath/node_modules/foo/server.js |