| |
| |
| |
| |
| |
|
|
| import path from 'node:path'; |
| import { resolveToRealPath } from './paths.js'; |
|
|
| |
| |
| |
| |
| export const EXACT_BUILD_FILENAMES: ReadonlySet<string> = new Set([ |
| |
| 'BUILD', |
| 'BUILD.bazel', |
| 'WORKSPACE', |
| 'WORKSPACE.bazel', |
| 'MODULE.bazel', |
| '.bazelrc', |
| '.blazerc', |
|
|
| |
| 'Makefile', |
| 'makefile', |
| 'GNUmakefile', |
| 'CMakeLists.txt', |
|
|
| |
| 'package.json', |
| 'package-lock.json', |
| 'pnpm-lock.yaml', |
| 'yarn.lock', |
| 'bun.lockb', |
|
|
| |
| 'setup.py', |
| 'setup.cfg', |
| 'pyproject.toml', |
|
|
| |
| 'go.mod', |
| 'go.sum', |
|
|
| |
| 'Cargo.toml', |
| 'Cargo.lock', |
|
|
| |
| 'pom.xml', |
| 'build.gradle', |
| 'build.gradle.kts', |
| 'settings.gradle', |
| 'settings.gradle.kts', |
|
|
| |
| 'Dockerfile', |
| 'Containerfile', |
| ]); |
|
|
| |
| |
| |
| export const BUILD_FILE_EXTENSIONS: ReadonlySet<string> = new Set([ |
| '.bzl', |
| '.bazel', |
| '.bzlmod', |
| '.mk', |
| '.cmake', |
| ]); |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function isBuildFile(filePath: string): boolean { |
| if (!filePath) { |
| return false; |
| } |
|
|
| |
| let cleanPath = filePath.replace(/\0/g, ''); |
| if (process.platform === 'win32') { |
| let end = cleanPath.length; |
| while ( |
| end > 0 && |
| (cleanPath[end - 1] === '.' || cleanPath[end - 1] === ' ') |
| ) { |
| end--; |
| } |
| cleanPath = cleanPath.slice(0, end); |
| } |
|
|
| |
| const normalizedPath = cleanPath.replace(/\\/g, '/'); |
| |
| let resolvedPath = normalizedPath; |
| try { |
| resolvedPath = resolveToRealPath(normalizedPath); |
| } catch { |
| resolvedPath = path.resolve(normalizedPath); |
| } |
| const basename = path.basename(resolvedPath); |
|
|
| if (EXACT_BUILD_FILENAMES.has(basename)) { |
| return true; |
| } |
|
|
| |
| if ( |
| basename.startsWith('Dockerfile.') || |
| basename.startsWith('Containerfile.') |
| ) { |
| return true; |
| } |
|
|
| const ext = path.extname(basename).toLowerCase(); |
| if (BUILD_FILE_EXTENSIONS.has(ext)) { |
| return true; |
| } |
|
|
| return false; |
| } |
|
|
| interface FilePathLike { |
| file_path?: unknown; |
| path?: unknown; |
| filePath?: unknown; |
| file?: unknown; |
| } |
|
|
| |
| function isFilePathLike(value: unknown): value is FilePathLike { |
| return typeof value === 'object' && value !== null; |
| } |
|
|
| |
| |
| |
| export function extractFilePathFromArgs(args: unknown): string | undefined { |
| if (!isFilePathLike(args)) { |
| return undefined; |
| } |
| const target = args.file_path ?? args.path ?? args.filePath ?? args.file; |
| return typeof target === 'string' ? target : undefined; |
| } |
|
|