Skip to content

Commit 5eca929

Browse files
authored
fix loading esm js config (#1459)
1 parent 0d9ec01 commit 5eca929

File tree

4 files changed

+98
-175
lines changed

4 files changed

+98
-175
lines changed

.changeset/light-wolves-happen.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'graphql-config': minor
3+
---
4+
5+
- fix loading esm js config
6+
7+
- add support of `*.mjs` configs

src/helpers/cosmiconfig.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export function createCosmiConfig(moduleName: string, legacy: boolean) {
3636

3737
export function createCosmiConfigSync(moduleName: string, legacy: boolean) {
3838
const options = prepareCosmiconfig(moduleName, legacy);
39-
4039
return cosmiconfigSync(moduleName, options);
4140
}
4241

@@ -53,15 +52,22 @@ const loadToml: Loader = (...args) => {
5352
return createCustomLoader(loadToml)(...args);
5453
};
5554

56-
function prepareCosmiconfig(moduleName: string, legacy: boolean) {
57-
const loadYaml = createCustomLoader(defaultLoaders['.yaml']);
55+
const loadYaml = createCustomLoader(defaultLoaders['.yaml']);
5856

57+
function prepareCosmiconfig(
58+
moduleName: string,
59+
legacy: boolean,
60+
): {
61+
searchPlaces: string[];
62+
loaders: Record<string, Loader>;
63+
} {
5964
const searchPlaces = [
6065
'#.config.ts',
6166
'#.config.cts',
6267
'#.config.mts',
6368
'#.config.js',
6469
'#.config.cjs',
70+
'#.config.mjs',
6571
'#.config.json',
6672
'#.config.yaml',
6773
'#.config.yml',
@@ -72,6 +78,7 @@ function prepareCosmiconfig(moduleName: string, legacy: boolean) {
7278
'.#rc.mts',
7379
'.#rc.js',
7480
'.#rc.cjs',
81+
'.#rc.mjs',
7582
'.#rc.json',
7683
'.#rc.yml',
7784
'.#rc.yaml',
@@ -89,10 +96,11 @@ function prepareCosmiconfig(moduleName: string, legacy: boolean) {
8996
searchPlaces: searchPlaces.map((place) => place.replace('#', moduleName)),
9097
loaders: {
9198
'.ts': loadTypeScript,
92-
'.mts': loadTypeScript,
9399
'.cts': loadTypeScript,
94-
'.js': defaultLoaders['.js'],
95-
'.json': createCustomLoader(defaultLoaders['.json']),
100+
'.mts': loadTypeScript,
101+
'.js': loadTypeScript,
102+
'.mjs': loadTypeScript,
103+
'.json': defaultLoaders['.json'],
96104
'.yaml': loadYaml,
97105
'.yml': loadYaml,
98106
'.toml': loadToml,

0 commit comments

Comments
 (0)