@@ -60,19 +60,15 @@ export async function spliceConfig({
6060 return fs . writeFile ( fileName , out )
6161}
6262
63- function loadGatsbyConfig ( { gatsbyRoot, utils } ) : GatsbyConfig | never {
63+ function loadGatsbyConfig ( { gatsbyRoot } ) : GatsbyConfig {
6464 const gatsbyConfigFile = resolve ( gatsbyRoot , 'gatsby-config.js' )
6565
6666 if ( ! existsSync ( gatsbyConfigFile ) ) {
6767 return { }
6868 }
6969
70- try {
71- // eslint-disable-next-line n/global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
72- return require ( gatsbyConfigFile ) as GatsbyConfig
73- } catch ( error ) {
74- utils . build . failBuild ( 'Could not load gatsby-config.js' , { error } )
75- }
70+ // eslint-disable-next-line n/global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
71+ return require ( gatsbyConfigFile ) as GatsbyConfig
7672}
7773
7874function hasPlugin ( plugins : PluginRef [ ] , pluginName : string ) : boolean {
@@ -85,15 +81,12 @@ function hasPlugin(plugins: PluginRef[], pluginName: string): boolean {
8581 )
8682}
8783
88- export async function checkConfig ( { utils, netlifyConfig } ) : Promise < void > {
89- const gatsbyRoot = getGatsbyRoot ( netlifyConfig . build . publish )
90-
84+ async function checkGatsbyPluginsCompatibility ( {
85+ utils,
86+ gatsbyRoot,
87+ gatsbyConfig,
88+ } ) : Promise < void > | never {
9189 // warn if gatsby-plugin-netlify is missing
92- const gatsbyConfig = loadGatsbyConfig ( {
93- utils,
94- gatsbyRoot,
95- } )
96-
9790 if ( hasPlugin ( gatsbyConfig . plugins , 'gatsby-plugin-netlify' ) ) {
9891 if (
9992 ! ( await checkPackageVersion (
@@ -121,6 +114,29 @@ export async function checkConfig({ utils, netlifyConfig }): Promise<void> {
121114 )
122115 utils . build . failBuild ( 'Incompatible Gatsby plugin installed' )
123116 }
117+ }
118+
119+ export async function checkConfig ( { utils, netlifyConfig } ) : Promise < void > {
120+ const gatsbyRoot = getGatsbyRoot ( netlifyConfig . build . publish )
121+
122+ let gatsbyConfig : GatsbyConfig | undefined
123+ try {
124+ gatsbyConfig = loadGatsbyConfig ( {
125+ gatsbyRoot,
126+ } )
127+ } catch ( error ) {
128+ console . error (
129+ `Could not load gatsby-config.js: ${ error . message } \n\nUnable to validate if 'gatsby-plugin-netlify' is setup correctly.` ,
130+ )
131+ }
132+
133+ if ( gatsbyConfig ) {
134+ await checkGatsbyPluginsCompatibility ( {
135+ utils,
136+ gatsbyConfig,
137+ gatsbyRoot,
138+ } )
139+ }
124140
125141 if (
126142 netlifyConfig . plugins . some (
0 commit comments