Skip to content

Commit 7b52c85

Browse files
committed
refactor: include sharp module when ipx is disabled
don't add ipx function to netlifyConfig if ipx is disabled
1 parent e40b75b commit 7b52c85

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

packages/runtime/src/helpers/config.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import slash from 'slash'
88
import { HANDLER_FUNCTION_NAME, ODB_FUNCTION_NAME } from '../constants'
99

1010
import type { RoutesManifest } from './types'
11+
import { isEnvSet } from './utils'
1112

1213
const ROUTES_MANIFEST_FILE = 'routes-manifest.json'
1314

@@ -77,16 +78,20 @@ const resolveModuleRoot = (moduleName) => {
7778
}
7879
}
7980

80-
const DEFAULT_EXCLUDED_MODULES = ['sharp', 'electron']
81+
const configureDefaultExcludedModules = () => (isEnvSet('DISABLE_IPX') ? ['electron'] : ['sharp', 'electron'])
82+
83+
const DEFAULT_EXCLUDED_MODULES = configureDefaultExcludedModules()
8184

8285
export const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore = [] }) => {
8386
const config = await getRequiredServerFiles(publish)
8487
const files = config.files || []
8588
const cssFilesToInclude = files.filter((f) => f.startsWith(`${publish}/static/css/`))
8689

8790
/* eslint-disable no-underscore-dangle */
88-
netlifyConfig.functions._ipx ||= {}
89-
netlifyConfig.functions._ipx.node_bundler = 'nft'
91+
if (!isEnvSet('DISABLE_IPX')) {
92+
netlifyConfig.functions._ipx ||= {}
93+
netlifyConfig.functions._ipx.node_bundler = 'nft'
94+
}
9095

9196
/* eslint-enable no-underscore-dangle */
9297
;[HANDLER_FUNCTION_NAME, ODB_FUNCTION_NAME].forEach((functionName) => {

packages/runtime/src/helpers/functions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { join, relative, resolve } from 'pathe'
77
import { HANDLER_FUNCTION_NAME, ODB_FUNCTION_NAME, IMAGE_FUNCTION_NAME, DEFAULT_FUNCTIONS_SRC } from '../constants'
88
import { getHandler } from '../templates/getHandler'
99
import { getPageResolver } from '../templates/getPageResolver'
10+
1011
import { isEnvSet } from './utils'
1112

1213
export const generateFunctions = async (
@@ -70,8 +71,7 @@ export const setupImageFunction = async ({
7071
remotePatterns: RemotePattern[]
7172
responseHeaders?: Record<string, string>
7273
}): Promise<void> => {
73-
74-
if(!isEnvSet('DISABLE_IPX')) {
74+
if (!isEnvSet('DISABLE_IPX')) {
7575
const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC
7676
const functionName = `${IMAGE_FUNCTION_NAME}.js`
7777
const functionDirectory = join(functionsPath, IMAGE_FUNCTION_NAME)
@@ -83,7 +83,7 @@ export const setupImageFunction = async ({
8383
remotePatterns,
8484
responseHeaders,
8585
})
86-
86+
8787
await copyFile(join(__dirname, '..', '..', 'lib', 'templates', 'ipx.js'), join(functionDirectory, functionName))
8888

8989
const imagePath = imageconfig.path || '/_next/image'
@@ -96,12 +96,12 @@ export const setupImageFunction = async ({
9696
to: `${basePath}/${IMAGE_FUNCTION_NAME}/w_:width,q_:quality/:url`,
9797
status: 301,
9898
})
99-
99+
100100
netlifyConfig.redirects.push({
101101
from: `${basePath}/${IMAGE_FUNCTION_NAME}/*`,
102102
to: `/.netlify/builders/${IMAGE_FUNCTION_NAME}`,
103103
status: 200,
104-
})
104+
})
105105
}
106106

107107
if (basePath) {

packages/runtime/src/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ import {
2525
import { moveStaticPages, movePublicFiles, patchNextFiles } from './helpers/files'
2626
import { generateFunctions, setupImageFunction, generatePagesResolver } from './helpers/functions'
2727
import { generateRedirects, generateStaticRedirects } from './helpers/redirects'
28-
import {
29-
shouldSkip,
30-
isNextAuthInstalled,
31-
getCustomImageResponseHeaders,
32-
getRemotePatterns,
33-
} from './helpers/utils'
28+
import { shouldSkip, isNextAuthInstalled, getCustomImageResponseHeaders, getRemotePatterns } from './helpers/utils'
3429
import {
3530
verifyNetlifyBuildVersion,
3631
checkNextSiteHasBuilt,
@@ -69,7 +64,6 @@ const plugin: NetlifyPlugin = {
6964
netlifyConfig.build.environment.NEXT_PRIVATE_TARGET = 'server'
7065
},
7166

72-
// eslint-disable-next-line max-lines-per-function
7367
async onBuild({
7468
constants,
7569
netlifyConfig,

0 commit comments

Comments
 (0)