Skip to content

Commit

Permalink
Fix bug with imports field from a nested directory (#5366)
Browse files Browse the repository at this point in the history
### Description

When importing a `#foo` subpath import, the resolved file is relative
the the `package.json` containing the `imports` field, not the file with
the import statement. This fixes subpath imports to use the proper
context path during that resolve.

### Testing Instructions

```
RUST_BACKTRACE=1 cargo nextest run -p turbopack-tests -E 'test(snapshot__imports__subpath_imports_nested)' --no-capture
```

Fixes WEB-1216
  • Loading branch information
jridgewell authored Jun 23, 2023
1 parent 9dd26d3 commit a5ceec5
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/turbopack-core/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ async fn resolve_package_internal_with_imports_field(
};

handle_exports_imports_field(
context,
package_json_path.parent(),
*package_json_path,
resolve_options,
imports,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "foo";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import foo from "./nested";

console.log(foo);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import foo from "#foo";
export default foo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "subpath-imports",
"imports": {
"#foo": "./foo.js"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a5ceec5

Please sign in to comment.