diff --git a/packages/knip/src/plugins/netlify/helpers.ts b/packages/knip/src/plugins/netlify/helpers.ts index 903e97370..c30b0d4e5 100644 --- a/packages/knip/src/plugins/netlify/helpers.ts +++ b/packages/knip/src/plugins/netlify/helpers.ts @@ -1,7 +1,6 @@ import type { FunctionsConfig } from './types.js'; -export const validFunctionExtensions = () => - ['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts'].map(ext => ext.slice(1)).join(','); +export const NETLIFY_FUNCTIONS_EXTS = 'js,mjs,cjs,ts,mts,cts'; export const extractFunctionsConfigProperty = (config: FunctionsConfig, property: keyof FunctionsConfig) => [ ...(config[property] ?? []), diff --git a/packages/knip/src/plugins/netlify/index.ts b/packages/knip/src/plugins/netlify/index.ts index 05c7f0960..9a65b93ee 100644 --- a/packages/knip/src/plugins/netlify/index.ts +++ b/packages/knip/src/plugins/netlify/index.ts @@ -2,7 +2,7 @@ import { join } from '../../util/path.js'; import { timerify } from '../../util/Performance.js'; import { hasDependency, load } from '../../util/plugin.js'; import { toProductionEntryPattern } from '../../util/protocols.js'; -import { extractFunctionsConfigProperty, validFunctionExtensions } from './helpers.js'; +import { NETLIFY_FUNCTIONS_EXTS, extractFunctionsConfigProperty } from './helpers.js'; import type { NetlifyConfig } from './types.js'; import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js'; @@ -18,7 +18,7 @@ const CONFIG_FILE_PATTERNS: string[] = ['netlify.toml']; const ENTRY_FILE_PATTERNS: string[] = []; -const PRODUCTION_ENTRY_FILE_PATTERNS: string[] = [`netlify/functions/**/*.{${validFunctionExtensions()}}`]; +const PRODUCTION_ENTRY_FILE_PATTERNS: string[] = [`netlify/functions/**/*.{${NETLIFY_FUNCTIONS_EXTS}}`]; const PROJECT_FILE_PATTERNS: string[] = []; @@ -37,7 +37,7 @@ const findPluginDependencies: GenericPluginCallback = async (configFilePath, opt ]; const entryFiles = [ ...extractFunctionsConfigProperty(localConfig.functions || {}, 'included_files'), - join(localConfig.functions?.directory ?? 'netlify/functions', `**/*.{${validFunctionExtensions()}}`), + join(localConfig.functions?.directory ?? 'netlify/functions', `**/*.{${NETLIFY_FUNCTIONS_EXTS}}`), ].filter(file => !file.startsWith('!')); return [...dependencies, ...entryFiles.map(toProductionEntryPattern)];