Skip to content

Commit 9a524d9

Browse files
authored
respect browser overrides (#1261)
1 parent 0c11d98 commit 9a524d9

File tree

1 file changed

+7
-2
lines changed
  • packages/repl/src/lib/workers

1 file changed

+7
-2
lines changed

packages/repl/src/lib/workers/npm.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export function resolve_subpath(pkg: Package, subpath: string): string {
172172

173173
if (typeof pkg.meta.browser === 'object') {
174174
// this will either return `pkg.browser[subpath]` or `subpath`
175-
return resolve.legacy(pkg, {
175+
return resolve.legacy(pkg.meta, {
176176
browser: subpath
177177
}) as string;
178178
}
@@ -182,7 +182,12 @@ export function resolve_subpath(pkg: Package, subpath: string): string {
182182

183183
export function add_suffix(pkg: Package, path: string) {
184184
for (const suffix of ['', '.js', '.mjs', '.cjs', '/index.js', '/index.mjs', '/index.cjs']) {
185-
const with_suffix = path + suffix;
185+
let with_suffix = path + suffix;
186+
187+
if (pkg.meta.browser) {
188+
with_suffix = pkg.meta.browser[`./${with_suffix}`]?.replace('./', '') ?? with_suffix;
189+
}
190+
186191
const file = pkg.contents[with_suffix];
187192

188193
if (file && file.type === 'file') {

0 commit comments

Comments
 (0)