feat: update version and refactor ignore patterns in project listener
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/project-search",
|
"name": "@kevisual/project-search",
|
||||||
"version": "0.0.2",
|
"version": "0.0.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -24,11 +24,12 @@
|
|||||||
"fast-glob": "^3.3.3",
|
"fast-glob": "^3.3.3",
|
||||||
"meilisearch": "^0.55.0",
|
"meilisearch": "^0.55.0",
|
||||||
"zod": "^4.3.6",
|
"zod": "^4.3.6",
|
||||||
"@parcel/watcher": "^2.5.6",
|
|
||||||
"es-toolkit": "^1.45.1",
|
"es-toolkit": "^1.45.1",
|
||||||
"eventemitter3": "^5.0.4"
|
"eventemitter3": "^5.0.4"
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
|
"@parcel/watcher": "^2.5.6"
|
||||||
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./dist/app.js",
|
".": "./dist/app.js",
|
||||||
"./routes": "./dist/app.js",
|
"./routes": "./dist/app.js",
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ import ParcelWatcher, { subscribe } from '@parcel/watcher';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import { EventEmitter } from "eventemitter3";
|
import { EventEmitter } from "eventemitter3";
|
||||||
const defaultIgnore = ['node_modules', 'dist', 'pack-dist', 'build', 'out', 'coverage', '.git', '.svn', '.hg',
|
import { normalizeIgnorePattern, defaultIgnorePatterns } from '../utils';
|
||||||
'.next',
|
|
||||||
'.astro',
|
|
||||||
".swc"
|
|
||||||
];
|
|
||||||
|
|
||||||
export class ProjectListener {
|
export class ProjectListener {
|
||||||
projectPath: string;
|
projectPath: string;
|
||||||
@@ -30,7 +26,7 @@ export class ProjectListener {
|
|||||||
.map(line => line.trim())
|
.map(line => line.trim())
|
||||||
.filter(line => line && !line.startsWith('#'));
|
.filter(line => line && !line.startsWith('#'));
|
||||||
}
|
}
|
||||||
const allIgnore = [...defaultIgnore, ...ignorePatterns];
|
const allIgnore = [...defaultIgnorePatterns, ...ignorePatterns];
|
||||||
const sub = await subscribe(
|
const sub = await subscribe(
|
||||||
this.projectPath, // 监听路径(支持数组)
|
this.projectPath, // 监听路径(支持数组)
|
||||||
async (err, events) => {
|
async (err, events) => {
|
||||||
@@ -69,7 +65,7 @@ export class ProjectListener {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ignore: allIgnore.map(pattern => `**/${pattern}/**`),
|
ignore: allIgnore.map(normalizeIgnorePattern),
|
||||||
backend: 'watchman', // 可选:'fs-events'(默认)、'inotify'、'windows'、'watchman'
|
backend: 'watchman', // 可选:'fs-events'(默认)、'inotify'、'windows'、'watchman'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import fs from 'node:fs';
|
|||||||
import fg from 'fast-glob';
|
import fg from 'fast-glob';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { Scheduler } from '../../scheduler/index';
|
import { Scheduler } from '../../scheduler/index';
|
||||||
|
import { normalizeIgnorePattern, defaultIgnorePatterns } from '../utils';
|
||||||
|
|
||||||
export type FileProjectData = {
|
export type FileProjectData = {
|
||||||
/**
|
/**
|
||||||
@@ -265,8 +266,7 @@ export class ProjectSearch {
|
|||||||
.map(l => l.trim())
|
.map(l => l.trim())
|
||||||
.filter(l => l && !l.startsWith('#'))
|
.filter(l => l && !l.startsWith('#'))
|
||||||
: [];
|
: [];
|
||||||
const defaultIgnore = ['node_modules', 'dist', 'pack-dist', 'build', 'out', 'coverage', '.git', '.svn', '.hg', '.next', '.astro', '.swc'];
|
const allIgnore = [...defaultIgnorePatterns, ...gitIgnore].map(normalizeIgnorePattern);
|
||||||
const allIgnore = [...defaultIgnore, ...gitIgnore];
|
|
||||||
|
|
||||||
const files = await fg('**', {
|
const files = await fg('**', {
|
||||||
cwd: projectPath,
|
cwd: projectPath,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const getGitPathname = (repoPath: string): string | null => {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Failed to get remote URL for repo at ${repoPath}:`, err);
|
console.warn(`[getGitPathname] Failed to get git remote url for ${repoPath}:`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
36
src/project/utils.ts
Normal file
36
src/project/utils.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* 规范化 ignore 模式,用于文件和目录监听器的 ignore 选项
|
||||||
|
* - 如果已包含通配符 (* 或 ?),保持原样
|
||||||
|
* - 如果以 / 结尾,视为目录
|
||||||
|
* - 其他情况默认视为目录
|
||||||
|
*/
|
||||||
|
export function normalizeIgnorePattern(pattern: string): string {
|
||||||
|
// 如果已经是完整的 glob 模式(包含通配符),保持原样
|
||||||
|
if (pattern.includes('*') || pattern.includes('?')) {
|
||||||
|
return pattern;
|
||||||
|
}
|
||||||
|
// 以斜杠结尾 → 视为目录,加 /**
|
||||||
|
if (pattern.endsWith('/')) {
|
||||||
|
return `**/${pattern.replace(/\/$/, '')}/**`;
|
||||||
|
}
|
||||||
|
// 其他情况(文件名或目录名),加 /**
|
||||||
|
return `**/${pattern}/**`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认忽略的目录/文件列表
|
||||||
|
*/
|
||||||
|
export const defaultIgnorePatterns = [
|
||||||
|
'node_modules',
|
||||||
|
'dist',
|
||||||
|
'pack-dist',
|
||||||
|
'build',
|
||||||
|
'out',
|
||||||
|
'coverage',
|
||||||
|
'.git',
|
||||||
|
'.svn',
|
||||||
|
'.hg',
|
||||||
|
'.next',
|
||||||
|
'.astro',
|
||||||
|
'.swc',
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user