import { readFile } from 'node:fs/promises'; export const AUTOTOOL_MARK = 'managed-by-autotool'; /** * @deprecated remove */ export const OLD_MARK = 'autogenerated'; export const isManagedContent = (content: string, mark = AUTOTOOL_MARK): boolean => { return content.includes(mark) || content.includes(OLD_MARK); }; export const isManagedFile = async (path: string, mark = AUTOTOOL_MARK): Promise => { try { const content = await readFile(path, { encoding: 'utf8' }); return isManagedContent(content, mark); } catch (error) { // The file not exists error is the only one we treat as valid return (error as NodeJS.ErrnoException).code === 'ENOENT'; } };