From c6b18e5426827b21a60a4ccc816b1572b3b9974e Mon Sep 17 00:00:00 2001 From: Philippe Serhal Date: Mon, 31 Mar 2025 17:32:24 -0400 Subject: [PATCH 1/5] fix: fully wait for build in `functions:build` cmd --- src/commands/functions/functions-build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/functions/functions-build.ts b/src/commands/functions/functions-build.ts index 5c4060d5768..664533cb217 100644 --- a/src/commands/functions/functions-build.ts +++ b/src/commands/functions/functions-build.ts @@ -34,6 +34,6 @@ export const functionsBuild = async (options: OptionValues, command: BaseCommand log(`${NETLIFYDEVLOG} Building functions`) - zipFunctions(src, dst) + await zipFunctions(src, dst) log(`${NETLIFYDEVLOG} Functions built to `, dst) } From 6eb52103b3ff640624cbce279bff1f1612010aaa Mon Sep 17 00:00:00 2001 From: Philippe Serhal Date: Wed, 9 Apr 2025 08:45:48 -0400 Subject: [PATCH 2/5] build: fix suppressed eslint errors --- eslint_temporary_suppressions.js | 8 -------- src/commands/functions/functions-build.ts | 4 ++-- src/utils/functions/functions.ts | 6 +++++- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/eslint_temporary_suppressions.js b/eslint_temporary_suppressions.js index 3076d862193..f96d1c432b7 100644 --- a/eslint_temporary_suppressions.js +++ b/eslint_temporary_suppressions.js @@ -212,14 +212,6 @@ export default [ '@typescript-eslint/no-unsafe-return': 'off', }, }, - { - files: ['src/commands/functions/functions-build.ts'], - rules: { - '@typescript-eslint/no-unsafe-assignment': 'off', - '@typescript-eslint/no-unsafe-argument': 'off', - '@typescript-eslint/no-floating-promises': 'off', - }, - }, { files: ['src/commands/functions/functions-create.ts'], rules: { diff --git a/src/commands/functions/functions-build.ts b/src/commands/functions/functions-build.ts index 664533cb217..cc24bcf273d 100644 --- a/src/commands/functions/functions-build.ts +++ b/src/commands/functions/functions-build.ts @@ -10,7 +10,7 @@ import type BaseCommand from '../base-command.js' export const functionsBuild = async (options: OptionValues, command: BaseCommand) => { const { config } = command.netlify - const src = options.src || config.build.functionsSource + const src = ('src' in options && typeof options.src === 'string' ? options.src : null) ?? config.build.functionsSource const dst = getFunctionsDir({ options, config }) if (src === dst) { @@ -27,7 +27,7 @@ export const functionsBuild = async (options: OptionValues, command: BaseCommand log( `${NETLIFYDEVERR} Error: You must specify a destination functions folder with a --functions flag or a functions field in your config`, ) - exit(1) + return exit(1) } await mkdir(dst, { recursive: true }) diff --git a/src/utils/functions/functions.ts b/src/utils/functions/functions.ts index c562cda537c..b3ab065d202 100644 --- a/src/utils/functions/functions.ts +++ b/src/utils/functions/functions.ts @@ -22,7 +22,11 @@ export const getFunctionsDir = ( options: OptionValues }, defaultValue?: string, -) => options.functions || config.dev?.functions || config.functionsDirectory || defaultValue +): string | undefined => + ('functions' in options && typeof options.functions === 'string' ? options.functions : null) ?? + config.dev?.functions ?? + config.functionsDirectory ?? + defaultValue export const getFunctionsManifestPath = async ({ base, packagePath = '' }: { base: string; packagePath?: string }) => { const path = resolve(base, packagePath, getPathInProject(['functions', 'manifest.json'])) From 036ebb86e5ab36c95b54e3508d67fff87dc2c3f3 Mon Sep 17 00:00:00 2001 From: Philippe Serhal Date: Mon, 14 Apr 2025 16:07:55 -0400 Subject: [PATCH 3/5] fix: avoid empty string functions config regression --- src/utils/functions/functions.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/functions/functions.ts b/src/utils/functions/functions.ts index b3ab065d202..00c6862873c 100644 --- a/src/utils/functions/functions.ts +++ b/src/utils/functions/functions.ts @@ -10,6 +10,8 @@ import type { NormalizedCachedConfigConfig } from '../command-helpers.js' export const INTERNAL_FUNCTIONS_FOLDER = 'functions-internal' export const SERVE_FUNCTIONS_FOLDER = 'functions-serve' +const isNonEmptyString = (s: unknown): s is string => typeof s === 'string' && s.trim().length > 0 + /** * retrieves the function directory out of the flags or config */ @@ -23,9 +25,9 @@ export const getFunctionsDir = ( }, defaultValue?: string, ): string | undefined => - ('functions' in options && typeof options.functions === 'string' ? options.functions : null) ?? - config.dev?.functions ?? - config.functionsDirectory ?? + ('functions' in options && isNonEmptyString(options.functions) ? options.functions : null) ?? + (isNonEmptyString(config.dev?.functions) ? config.dev.functions : null) ?? + (isNonEmptyString(config.functionsDirectory) ? config.functionsDirectory : null) ?? defaultValue export const getFunctionsManifestPath = async ({ base, packagePath = '' }: { base: string; packagePath?: string }) => { From f06b38d7e40c8f37b93cc2705013ac6f39b9006a Mon Sep 17 00:00:00 2001 From: Philippe Serhal Date: Mon, 14 Apr 2025 16:09:52 -0400 Subject: [PATCH 4/5] fix: avoid empty-string functions `src` regression --- src/commands/functions/functions-build.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/commands/functions/functions-build.ts b/src/commands/functions/functions-build.ts index cc24bcf273d..d8fce8fdf56 100644 --- a/src/commands/functions/functions-build.ts +++ b/src/commands/functions/functions-build.ts @@ -10,7 +10,9 @@ import type BaseCommand from '../base-command.js' export const functionsBuild = async (options: OptionValues, command: BaseCommand) => { const { config } = command.netlify - const src = ('src' in options && typeof options.src === 'string' ? options.src : null) ?? config.build.functionsSource + const src = + ('src' in options && typeof options.src === 'string' && options.src.trim().length > 0 ? options.src : null) ?? + config.build.functionsSource const dst = getFunctionsDir({ options, config }) if (src === dst) { From 0a0643f75d8c7ca3946ff0abaf54117729aeb8af Mon Sep 17 00:00:00 2001 From: Philippe Serhal Date: Mon, 14 Apr 2025 17:35:14 -0400 Subject: [PATCH 5/5] fix: undo behavioural change to whitespace-only functions dir handling --- src/utils/functions/functions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/functions/functions.ts b/src/utils/functions/functions.ts index 00c6862873c..245c34cb8ae 100644 --- a/src/utils/functions/functions.ts +++ b/src/utils/functions/functions.ts @@ -10,7 +10,7 @@ import type { NormalizedCachedConfigConfig } from '../command-helpers.js' export const INTERNAL_FUNCTIONS_FOLDER = 'functions-internal' export const SERVE_FUNCTIONS_FOLDER = 'functions-serve' -const isNonEmptyString = (s: unknown): s is string => typeof s === 'string' && s.trim().length > 0 +const isNonEmptyString = (s: unknown): s is string => typeof s === 'string' && s.length > 0 /** * retrieves the function directory out of the flags or config