Skip to content

Commit 6d69ae0

Browse files
committed
chore: abstract function skip env var checks
1 parent 2cf1662 commit 6d69ae0

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

plugin/src/helpers/config.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,10 @@ async function readFunctionSkipFile(cacheDir: string) {
221221

222222
// eslint-disable-next-line complexity
223223
function overrideNeededFunctions(neededFunctions) {
224-
const skipAll =
225-
process.env.NETLIFY_SKIP_GATSBY_FUNCTIONS === 'true' ||
226-
process.env.NETLIFY_SKIP_GATSBY_FUNCTIONS === '1'
227-
228-
const skipAPI =
229-
process.env.NETLIFY_SKIP_API_FUNCTION === 'true' ||
230-
process.env.NETLIFY_SKIP_API_FUNCTION === '1'
231-
232-
const skipSSR =
233-
process.env.NETLIFY_SKIP_SSR_FUNCTION === 'true' ||
234-
process.env.NETLIFY_SKIP_SSR_FUNCTION === '1'
235-
236-
const skipDSG =
237-
process.env.NETLIFY_SKIP_DSG_FUNCTION === 'true' ||
238-
process.env.NETLIFY_SKIP_DSG_FUNCTION === '1'
224+
const skipAll = isEnvSet('NETLIFY_SKIP_GATSBY_FUNCTIONS')
225+
const skipAPI = isEnvSet('NETLIFY_SKIP_API_FUNCTION')
226+
const skipSSR = isEnvSet('NETLIFY_SKIP_SSR_FUNCTION')
227+
const skipDSG = isEnvSet('NETLIFY_SKIP_DSG_FUNCTION')
239228

240229
return {
241230
API: skipAll || skipAPI ? false : neededFunctions.API,
@@ -244,6 +233,10 @@ function overrideNeededFunctions(neededFunctions) {
244233
}
245234
}
246235

236+
function isEnvSet(envVar: string) {
237+
return process.env[envVar] === 'true' || process.env[envVar] === '1'
238+
}
239+
247240
export function getGatsbyRoot(publish: string): string {
248241
return path.resolve(path.dirname(publish))
249242
}

0 commit comments

Comments
 (0)