Skip to content

Commit

Permalink
Make NF extensions static
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter committed Jan 21, 2024
1 parent a1d1fe9 commit eaf4bc5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions packages/knip/src/plugins/netlify/helpers.ts
Original file line number Diff line number Diff line change
@@ -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] ?? []),
Expand Down
6 changes: 3 additions & 3 deletions packages/knip/src/plugins/netlify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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[] = [];

Expand All @@ -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)];
Expand Down

0 comments on commit eaf4bc5

Please sign in to comment.