@@ -60,15 +60,30 @@ export async function spliceConfig({
6060 return fs . writeFile ( fileName , out )
6161}
6262
63- function loadGatsbyConfig ( { gatsbyRoot } ) : GatsbyConfig {
64- const gatsbyConfigFile = resolve ( gatsbyRoot , 'gatsby-config.js' )
63+ function loadGatsbyConfig ( { gatsbyRoot } ) {
64+ const gatsbyConfigFileJS = resolve ( gatsbyRoot , 'gatsby-config.js' ) ;
65+ const gatsbyConfigFileTS = resolve ( gatsbyRoot , 'gatsby-config.ts' ) ;
6566
66- if ( ! existsSync ( gatsbyConfigFile ) ) {
67- return { }
67+ let gatsbyConfigFile = '' ;
68+
69+ if ( existsSync ( gatsbyConfigFileJS ) ) {
70+ gatsbyConfigFile = gatsbyConfigFileJS ;
71+ } else if ( existsSync ( gatsbyConfigFileTS ) ) {
72+ gatsbyConfigFile = gatsbyConfigFileTS ;
73+ } else {
74+ return { } ;
75+ }
76+
77+ const resolvedGatsbyConfigFile = resolveModule . sync ( gatsbyConfigFile , {
78+ extensions : [ '.js' , '.ts' ] ,
79+ } ) ;
80+
81+ if ( ! resolvedGatsbyConfigFile ) {
82+ return { } ;
6883 }
6984
7085 // eslint-disable-next-line n/global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
71- return require ( gatsbyConfigFile ) as GatsbyConfig
86+ return require ( resolvedGatsbyConfigFile ) ;
7287}
7388
7489function hasPlugin ( plugins : PluginRef [ ] , pluginName : string ) : boolean {
0 commit comments