Skip to content

Commit 8bd9e47

Browse files
refactor(config): drop the fallback for an unresolvable browserslist config half
No suite can reach it: browserslist's own entry requires that module, so a packaging change hiding it would already break the handler's own require of browserslist, and the fallback would answer for a build that cannot run.
1 parent e680a94 commit 8bd9e47

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

‎lib/config/target.js‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@ const getBrowserslistTargetHandler = memoize(() =>
1313
);
1414

1515
// The half of browserslist that finds a config, the same module instance the
16-
// queries use, so its caches stay shared. A packaging change could stop
17-
// resolving it, hence the fallback to loading browserslist itself.
18-
const getBrowserslistConfigLoader = memoize(() => {
19-
try {
20-
return require("browserslist/node");
21-
} catch (_err) {
22-
return undefined;
23-
}
24-
});
16+
// queries use, so its caches stay shared and a request for one costs nothing
17+
// twice. browserslist's own entry requires it, so it resolves wherever that does
18+
const getBrowserslistConfigLoader = memoize(() => require("browserslist/node"));
2519

2620
/**
2721
* Gets default target.
@@ -32,8 +26,8 @@ const getDefaultTarget = (context) => {
3226
// WHY: the default only turns on whether a browserslist config exists, and
3327
// the config half answers that without the caniuse data the queries read —
3428
// 1.3 MB that a build with no such config never uses.
35-
const configLoader = getBrowserslistConfigLoader();
36-
if (configLoader && !configLoader.loadConfig({ path: context })) return "web";
29+
const config = getBrowserslistConfigLoader().loadConfig({ path: context });
30+
if (!config) return "web";
3731
const browsers = getBrowserslistTargetHandler().load(undefined, context);
3832
return browsers ? "browserslist" : "web";
3933
};

0 commit comments

Comments
 (0)