Skip to content

Commit d432f57

Browse files
committed
refactor(config-loader): do not lookup package.json with explicit extensions
Currently when a config has an explicit extension, the config-loader still tries resolving/traversing for a `package.json` file. This can be slow, and also break in some environments with sandboxing; especially when used in combination with Bazel. It doesn't seem investigating why the calls are stuck, if the logic should not run in general when an explicit extension is provided.
1 parent 93ab3ca commit d432f57

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changeset/nice-guests-invent.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@web/config-loader': patch
3+
---
4+
5+
Optimizes config loading to not look for `package.json` in file system if the
6+
config extension is already informing whether CommonJS or ESM is used.
7+
8+
Currently config loading did unnecessarily traverse the file system. This could
9+
be unnecessary slowness, or cause issues in sandbox environments (like Bazel)

packages/config-loader/src/importOrRequireConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ function importConfig(configPath) {
1717
* @param {string} basedir
1818
*/
1919
async function importOrRequireConfig(configPath, basedir) {
20-
const packageType = await getPackageType(basedir);
2120
const ext = path.extname(configPath);
2221

2322
switch (ext) {
@@ -26,6 +25,7 @@ async function importOrRequireConfig(configPath, basedir) {
2625
case '.cjs':
2726
return requireConfig(configPath);
2827
default:
28+
const packageType = await getPackageType(basedir);
2929
return packageType === 'module' ? importConfig(configPath) : requireConfig(configPath);
3030
}
3131
}

0 commit comments

Comments
 (0)