Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback to normal resolving if alias doesn't resolve #7778

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/*", "./*"]
}
}
}
Loading