feat: 更新版本至0.0.9并增强文件哈希生成逻辑

This commit is contained in:
xiongxiao
2026-03-14 03:39:04 +08:00
committed by cnb
parent 7689dd512d
commit 1aa46b92c0
3 changed files with 20 additions and 4 deletions

View File

@@ -23,13 +23,23 @@ const TEXT_FILE_EXTENSIONS = [
'.sh', '.bash', '.zsh', '.fish', '.ps1', '.bat', '.cmd', '.psm1',
// 其他
'.sql', '.graphql', '.gql', '.proto', '.dockerfile', '.gitignore', '.gitattributes', '.editorconfig', '.eslintrc', '.prettierrc', '.prettierignore', '.npmrc', '.yarnrc', '.babelrc', '.webpackrc',
// lock 文件
'.lock', '-lock.json', '-lock.yaml', '-lock.yml', '.lockb',
// 其他配置文件
'.pem', '.key', '.crt', '.cer', '.p12', '.pfx',
];
// 没有扩展名的配置文件
const CONFIG_FILE_NAMES = [
'.gitignore', '.gitattributes', '.dockerignore', '.editorconfig', '.env', '.env.local', '.env.development', '.env.production',
'.gitignore', '.gitattributes', '.dockerignore', '.editorconfig', '.env', '.env.local', '.env.development', '.env.production', '.env.test', '.env.staging', '.env.example', '.env.sample',
'Dockerfile', 'Makefile', 'CMakeLists.txt', 'Vagrantfile', 'Gemfile', 'Podfile', 'Cartfile',
'.bashrc', '.zshrc', '.vimrc', '.inputrc',
// lock 文件
'bun.lockb', 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'pnpm-workspace.yaml',
'Gemfile.lock', 'Podfile.lock', 'Cartfile.resolved', 'composer.lock', 'requirements.txt',
'Pipfile.lock', 'poetry.lock', 'Cargo.lock', 'go.sum', 'go.mod',
// IDE 配置
'.vscode', '.idea',
];
export const isText = (filePath: string): boolean => {

View File

@@ -53,9 +53,15 @@ function fileId(filePath: string): string {
return Buffer.from(filePath).toString('base64url');
}
/** 根据文件绝对路径生成 md5 hash */
/** 根据文件内容生成 md5 hash,用于检测文件变更 */
function fileHash(filePath: string): string {
return crypto.createHash('md5').update(filePath).digest('hex');
try {
const content = fs.readFileSync(filePath);
return crypto.createHash('md5').update(content).digest('hex');
} catch {
// 文件不可读时回退为路径 hash
return crypto.createHash('md5').update(filePath).digest('hex');
}
}
export class ProjectSearch {