diff --git a/packages/runtime/src/helpers/utils.ts b/packages/runtime/src/helpers/utils.ts index 1aa185b686..08cc0a160b 100644 --- a/packages/runtime/src/helpers/utils.ts +++ b/packages/runtime/src/helpers/utils.ts @@ -196,4 +196,7 @@ export const getCustomImageResponseHeaders = (headers: Header[]): Record<string, } return null } + +export const isBundleSizeCheckDisabled = () => + process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK === '1' || process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK === 'true' /* eslint-enable max-lines */ diff --git a/packages/runtime/src/helpers/verification.ts b/packages/runtime/src/helpers/verification.ts index 594201ab99..3d94517b6e 100644 --- a/packages/runtime/src/helpers/verification.ts +++ b/packages/runtime/src/helpers/verification.ts @@ -11,6 +11,8 @@ import { satisfies } from 'semver' import { LAMBDA_MAX_SIZE } from '../constants' +import { isBundleSizeCheckDisabled } from './utils' + // This is when nft support was added const REQUIRED_BUILD_VERSION = '>=18.16.0' @@ -105,6 +107,15 @@ export const checkForRootPublish = ({ } export const checkZipSize = async (file: string, maxSize: number = LAMBDA_MAX_SIZE): Promise<void> => { + // Requires contacting the Netlify Support team to fully enable. + // Enabling this without contacting them can result in failed deploys. + if (isBundleSizeCheckDisabled()) { + console.warn( + 'Function bundle size check was DISABLED with the DISABLE_BUNDLE_ZIP_SIZE_CHECK environment variable. Your deployment will break if it exceeds the maximum supported size of function zip files in your account.', + ) + return + } + if (!existsSync(file)) { console.warn(`Could not check zip size because ${file} does not exist`) return diff --git a/test/helpers/verification.spec.ts b/test/helpers/verification.spec.ts index 44c3bb13fd..85096d5194 100644 --- a/test/helpers/verification.spec.ts +++ b/test/helpers/verification.spec.ts @@ -1,11 +1,15 @@ -import { checkNextSiteHasBuilt } from '../../packages/runtime/src/helpers/verification' +import Chance from 'chance' +import { checkNextSiteHasBuilt, checkZipSize } from '../../packages/runtime/src/helpers/verification' import { outdent } from 'outdent' import type { NetlifyPluginUtils } from '@netlify/build' type FailBuild = NetlifyPluginUtils['build']['failBuild'] +const chance = new Chance() + jest.mock('fs', () => { return { + ...jest.requireActual('fs'), existsSync: jest.fn(), } }) @@ -78,3 +82,21 @@ describe('checkNextSiteHasBuilt', () => { expect(failBuildMock).toHaveBeenCalledWith(expectedFailureMessage) }) }) + +describe('checkZipSize', () => { + let consoleSpy + + beforeEach(() => { + consoleSpy = jest.spyOn(global.console, 'warn') + }) + + afterEach(() => { + delete process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK + }) + + it('emits a warning that DISABLE_BUNDLE_ZIP_SIZE_CHECK was enabled', async () => { + process.env.DISABLE_BUNDLE_ZIP_SIZE_CHECK = 'true' + await checkZipSize(chance.string()) + expect(consoleSpy).toHaveBeenCalledWith('Function bundle size check was DISABLED with the DISABLE_BUNDLE_ZIP_SIZE_CHECK environment variable. Your deployment will break if it exceeds the maximum supported size of function zip files in your account.') + }) +})