mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-18 18:04:26 +00:00
fix: address CodeRabbit review findings
- findSkill: fall through to .md check when parseSkill returns null - Use isPathInside instead of dir.includes(cwd) for location detection - Optional chaining on meta.source in remove --source filter - Track fence delimiter type per CommonMark (backtick vs tilde) - Wrap statSync in try-catch so one bad source doesn't abort all installs - Add cleanup fallback when sparse-checkout/checkout fails
This commit is contained in:
@@ -472,7 +472,15 @@ export class InstallCommand extends Command {
|
||||
mkdirSync(installDir, { recursive: true });
|
||||
}
|
||||
|
||||
const isStandaloneFile = statSync(sourcePath).isFile();
|
||||
let isStandaloneFile: boolean;
|
||||
try {
|
||||
isStandaloneFile = statSync(sourcePath).isFile();
|
||||
} catch {
|
||||
if (!this.quiet) {
|
||||
warn(`Skipping ${skillName} for ${adapter.name} (source not accessible)`);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const targetPath = isStandaloneFile
|
||||
? join(installDir, skillName.endsWith(".md") ? skillName : `${skillName}.md`)
|
||||
: join(installDir, skillName);
|
||||
|
||||
@@ -48,7 +48,7 @@ export class RemoveCommand extends Command {
|
||||
if (this.source) {
|
||||
skillsToRemove = allSkills.filter((s) => {
|
||||
const meta = loadMetadata(s.path);
|
||||
return meta && meta.source.includes(this.source!);
|
||||
return meta?.source?.includes(this.source!) ?? false;
|
||||
}).map((s) => ({ name: s.name, path: s.path }));
|
||||
if (skillsToRemove.length === 0) {
|
||||
warn(`No skills found from source: ${this.source}`);
|
||||
|
||||
@@ -104,27 +104,34 @@ export async function cloneRepo(
|
||||
}
|
||||
|
||||
if (partialCloneOk) {
|
||||
execFileSync('git', ['-C', tempDir, 'sparse-checkout', 'init', '--cone'], {
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
});
|
||||
try {
|
||||
execFileSync('git', ['-C', tempDir, 'sparse-checkout', 'init', '--cone'], {
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
});
|
||||
|
||||
const sparsePaths = [...SKILL_DISCOVERY_PATHS];
|
||||
if (options.subpath) {
|
||||
sparsePaths.push(options.subpath);
|
||||
for (const dp of SKILL_DISCOVERY_PATHS) {
|
||||
sparsePaths.push(`${options.subpath}/${dp}`);
|
||||
const sparsePaths = [...SKILL_DISCOVERY_PATHS];
|
||||
if (options.subpath) {
|
||||
sparsePaths.push(options.subpath);
|
||||
for (const dp of SKILL_DISCOVERY_PATHS) {
|
||||
sparsePaths.push(`${options.subpath}/${dp}`);
|
||||
}
|
||||
}
|
||||
execFileSync(
|
||||
'git',
|
||||
['-C', tempDir, 'sparse-checkout', 'set', '--', ...sparsePaths],
|
||||
{ stdio: ['pipe', 'pipe', 'pipe'] },
|
||||
);
|
||||
|
||||
options.onProgress?.('Checking out files');
|
||||
await spawnGit(['-C', tempDir, 'checkout'], options.onProgress);
|
||||
|
||||
return;
|
||||
} catch {
|
||||
options.onProgress?.('Sparse checkout failed, falling back to full clone');
|
||||
if (existsSync(tempDir)) {
|
||||
rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
execFileSync(
|
||||
'git',
|
||||
['-C', tempDir, 'sparse-checkout', 'set', '--', ...sparsePaths],
|
||||
{ stdio: ['pipe', 'pipe', 'pipe'] },
|
||||
);
|
||||
|
||||
options.onProgress?.('Checking out files');
|
||||
await spawnGit(['-C', tempDir, 'checkout'], options.onProgress);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ function ruleMatchesFileType(rule: SecurityRule, fileType: string | undefined):
|
||||
|
||||
function stripMarkdownCodeAndFrontmatter(content: string): string {
|
||||
const lines = content.split('\n');
|
||||
let inCodeBlock = false;
|
||||
let fenceDelimiter: string | null = null;
|
||||
let inFrontmatter = false;
|
||||
let frontmatterDone = false;
|
||||
|
||||
@@ -82,11 +82,18 @@ function stripMarkdownCodeAndFrontmatter(content: string): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (/^(`{3,}|~{3,})/.test(trimmed)) {
|
||||
inCodeBlock = !inCodeBlock;
|
||||
return line;
|
||||
const fenceMatch = trimmed.match(/^(`{3,}|~{3,})/);
|
||||
if (fenceMatch) {
|
||||
const char = fenceMatch[1][0];
|
||||
if (fenceDelimiter === null) {
|
||||
fenceDelimiter = char;
|
||||
return line;
|
||||
} else if (char === fenceDelimiter) {
|
||||
fenceDelimiter = null;
|
||||
return line;
|
||||
}
|
||||
}
|
||||
if (inCodeBlock) return '';
|
||||
if (fenceDelimiter !== null) return '';
|
||||
|
||||
return line;
|
||||
}).join('\n');
|
||||
|
||||
@@ -314,11 +314,12 @@ export function findSkill(name: string, searchDirs: string[]): Skill | null {
|
||||
for (const dir of searchDirs) {
|
||||
if (!existsSync(dir)) continue;
|
||||
|
||||
const location: SkillLocation = dir.includes(process.cwd()) ? 'project' : 'global';
|
||||
const location: SkillLocation = isPathInside(dir, process.cwd()) ? 'project' : 'global';
|
||||
|
||||
const skillPath = join(dir, name);
|
||||
if (existsSync(skillPath)) {
|
||||
return parseSkill(skillPath, location);
|
||||
const skill = parseSkill(skillPath, location);
|
||||
if (skill) return skill;
|
||||
}
|
||||
|
||||
const mdPath = join(dir, name.endsWith('.md') ? name : `${name}.md`);
|
||||
@@ -337,7 +338,7 @@ export function findAllSkills(searchDirs: string[]): Skill[] {
|
||||
for (const dir of searchDirs) {
|
||||
if (!existsSync(dir)) continue;
|
||||
|
||||
const location: SkillLocation = dir.includes(process.cwd()) ? 'project' : 'global';
|
||||
const location: SkillLocation = isPathInside(dir, process.cwd()) ? 'project' : 'global';
|
||||
const discovered = discoverSkills(dir);
|
||||
|
||||
for (const skill of discovered) {
|
||||
|
||||
Reference in New Issue
Block a user