Skip to content

Commit 03e2f4a

Browse files
bgotinkmerceyz
authored andcommitted
fix(esbuild): make foo/bar external if package foo is external (#4209)
1 parent aedfbea commit 03e2f4a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

.yarn/versions/5e49f6c7.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
releases:
2+
"@yarnpkg/esbuild-plugin-pnp": patch
3+
4+
declined:
5+
- "@yarnpkg/builder"

packages/esbuild-plugin-pnp/sources/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,18 @@ function isExternal(path: string, externals: Array<External>): boolean {
3131
return true;
3232
}
3333
} else {
34-
if (path === external) {
34+
if (path === external)
3535
return true;
36+
37+
// If the module "foo" has been marked as external, we also want to treat
38+
// paths into that module such as "foo/bar" as external too.
39+
// References:
40+
// - https://github.com/evanw/esbuild/blob/537195ae84bee1510fac14235906d588084c39cd/internal/resolver/resolver.go#L651-L652
41+
// - https://github.com/evanw/esbuild/blob/537195ae84bee1510fac14235906d588084c39cd/internal/resolver/resolver.go#L1688-L1691
42+
if (!external.startsWith(`/`) && !external.startsWith(`./`) && !external.startsWith(`../`) && external !== `.` && external !== `..`) {
43+
if (path.startsWith(`${external}/`)) {
44+
return true;
45+
}
3646
}
3747
}
3848
}

0 commit comments

Comments
 (0)