@@ -60,19 +60,15 @@ export async function spliceConfig({
60
60
return fs . writeFile ( fileName , out )
61
61
}
62
62
63
- function loadGatsbyConfig ( { gatsbyRoot, utils } ) : GatsbyConfig | never {
63
+ function loadGatsbyConfig ( { gatsbyRoot } ) : GatsbyConfig {
64
64
const gatsbyConfigFile = resolve ( gatsbyRoot , 'gatsby-config.js' )
65
65
66
66
if ( ! existsSync ( gatsbyConfigFile ) ) {
67
67
return { }
68
68
}
69
69
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
76
72
}
77
73
78
74
function hasPlugin ( plugins : PluginRef [ ] , pluginName : string ) : boolean {
@@ -85,15 +81,12 @@ function hasPlugin(plugins: PluginRef[], pluginName: string): boolean {
85
81
)
86
82
}
87
83
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 {
91
89
// warn if gatsby-plugin-netlify is missing
92
- const gatsbyConfig = loadGatsbyConfig ( {
93
- utils,
94
- gatsbyRoot,
95
- } )
96
-
97
90
if ( hasPlugin ( gatsbyConfig . plugins , 'gatsby-plugin-netlify' ) ) {
98
91
if (
99
92
! ( await checkPackageVersion (
@@ -121,6 +114,29 @@ export async function checkConfig({ utils, netlifyConfig }): Promise<void> {
121
114
)
122
115
utils . build . failBuild ( 'Incompatible Gatsby plugin installed' )
123
116
}
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
+ }
124
140
125
141
if (
126
142
netlifyConfig . plugins . some (
0 commit comments