Skip to content

Commit

Permalink
fallback to normal resolving if alias doesn't resolve (#7778)
Browse files Browse the repository at this point in the history
### Description

fixes vercel/next.js#62037

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->


Closes PACK-2800
  • Loading branch information
sokra authored Mar 20, 2024
1 parent 043544e commit 1db933a
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/turbopack-core/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,9 @@ async fn resolve_internal_inline(
// Typescript resolution algorithm does in case an alias match
// doesn't resolve to anything: fall back to resolving the request normally.
if let Some(result) = resolved_result {
return Ok(result);
if !*result.is_unresolveable().await? {
return Ok(result);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import foo from "@foo";
import fooBar from "@foo/bar";
import bazFoo from "@baz/foo";
import srcBazFoo from "@src/baz/foo";

it("should resolve an alias to a local file", () => {
expect(foo).toBe("foo");
expect(require("@foo")).toHaveProperty("default", "foo");
});

it("should fallback from an alias", () => {
expect(fooBar).toBe("@foo/bar");
expect(require("@foo/bar")).toHaveProperty("default", "@foo/bar");
});

it("should prefer alias over normal resolving", () => {
expect(bazFoo).toBe("baz/foo");
expect(require("@baz/foo")).toHaveProperty("default", "baz/foo");
});

it("should resolve the alternative alias value", () => {
expect(srcBazFoo).toBe("baz/foo");
expect(require("@src/baz/foo")).toHaveProperty("default", "baz/foo");
});

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.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "baz/foo";
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,7 @@
{
"compilerOptions": {
"paths": {
"@*": ["./src/*", "./*"]
}
}
}

0 comments on commit 1db933a

Please sign in to comment.