fix(npmextra): update to new format

This commit is contained in:
2025-12-13 11:42:39 +00:00
parent f8d0895aab
commit 3b1c84d7e8
18 changed files with 1951 additions and 1801 deletions

View File

@@ -122,7 +122,7 @@ export class ConfigManager {
const npmextraJsonPath = plugins.path.join(this.projectDir, 'npmextra.json');
// Check if file exists
const fileExists = await plugins.smartfile.fs.fileExists(npmextraJsonPath);
const fileExists = await plugins.fsInstance.file(npmextraJsonPath).exists();
if (!fileExists) {
return;
}
@@ -138,13 +138,13 @@ export class ConfigManager {
}
// Read the npmextra.json file
const npmextraJsonFile = await plugins.smartfile.SmartFile.fromFilePath(npmextraJsonPath);
const npmextraJsonFile = await plugins.smartfileFactory.fromFilePath(npmextraJsonPath);
const npmextraContent = JSON.parse(npmextraJsonFile.contents.toString());
// Check for tsdoc context configuration
if (npmextraContent?.tsdoc?.context) {
if (npmextraContent?.['@git.zone/tsdoc']?.context) {
// Merge with default config
this.config = this.mergeConfigs(this.config, npmextraContent.tsdoc.context);
this.config = this.mergeConfigs(this.config, npmextraContent['@git.zone/tsdoc'].context);
}
// Cache the config
@@ -292,8 +292,8 @@ export class ConfigManager {
const npmextraJsonPath = plugins.path.join(this.projectDir, 'npmextra.json');
let npmextraContent = {};
if (await plugins.smartfile.fs.fileExists(npmextraJsonPath)) {
const npmextraJsonFile = await plugins.smartfile.SmartFile.fromFilePath(npmextraJsonPath);
if (await plugins.fsInstance.file(npmextraJsonPath).exists()) {
const npmextraJsonFile = await plugins.smartfileFactory.fromFilePath(npmextraJsonPath);
npmextraContent = JSON.parse(npmextraJsonFile.contents.toString()) || {};
}
@@ -304,7 +304,7 @@ export class ConfigManager {
// Write back to npmextra.json
const updatedContent = JSON.stringify(npmextraContent, null, 2);
await plugins.smartfile.memory.toFs(updatedContent, npmextraJsonPath);
await plugins.fsInstance.file(npmextraJsonPath).encoding('utf8').write(updatedContent);
} catch (error) {
console.error('Error updating context configuration:', error);
}

View File

@@ -116,7 +116,7 @@ export class ContextAnalyzer {
// Parse imports from each file
for (const meta of metadata) {
try {
const contents = await plugins.smartfile.fs.toStringSync(meta.path);
const contents = await plugins.fsInstance.file(meta.path).encoding('utf8').read() as string;
const imports = this.extractImports(contents, meta.path);
const deps = graph.get(meta.path)!;

View File

@@ -39,13 +39,13 @@ export class ContextCache {
}
// Ensure cache directory exists
await plugins.smartfile.fs.ensureDir(this.cacheDir);
await plugins.fsInstance.directory(this.cacheDir).recursive().create();
// Load cache index if it exists
try {
const indexExists = await plugins.smartfile.fs.fileExists(this.cacheIndexPath);
const indexExists = await plugins.fsInstance.file(this.cacheIndexPath).exists();
if (indexExists) {
const indexContent = await plugins.smartfile.fs.toStringSync(this.cacheIndexPath);
const indexContent = await plugins.fsInstance.file(this.cacheIndexPath).encoding('utf8').read() as string;
const indexData = JSON.parse(indexContent) as ICacheEntry[];
if (Array.isArray(indexData)) {
for (const entry of indexData) {
@@ -278,7 +278,7 @@ export class ContextCache {
try {
const entries = Array.from(this.cache.values());
const content = JSON.stringify(entries, null, 2);
await plugins.smartfile.memory.toFs(content, this.cacheIndexPath);
await plugins.fsInstance.file(this.cacheIndexPath).encoding('utf8').write(content);
} catch (error) {
console.warn('Failed to persist cache index:', error.message);
}

View File

@@ -120,7 +120,7 @@ export class EnhancedContext {
originalTokenCount = cached.tokenCount;
} else {
// Load file
const fileData = await plugins.smartfile.fs.toStringSync(fileAnalysis.path);
const fileData = await plugins.fsInstance.file(fileAnalysis.path).encoding('utf8').read() as string;
contents = fileData;
originalTokenCount = this.countTokens(contents);

View File

@@ -463,7 +463,7 @@ Do not wrap the JSON in markdown code blocks or add any other text.`,
}
// Load from disk
const contents = await plugins.smartfile.fs.toStringSync(filePath);
const contents = await plugins.fsInstance.file(filePath).encoding('utf8').read() as string;
const tokenCount = this.countTokens(contents);
const relativePath = plugins.path.relative(this.projectRoot, filePath);

View File

@@ -31,16 +31,32 @@ export class LazyFileLoader {
for (const globPattern of globs) {
try {
const smartFiles = await plugins.smartfile.fs.fileTreeToObject(this.projectRoot, globPattern);
const fileArray = Array.isArray(smartFiles) ? smartFiles : [smartFiles];
const virtualDir = await plugins.smartfileFactory.virtualDirectoryFromPath(this.projectRoot);
// Filter files based on glob pattern using simple pattern matching
const smartFiles = virtualDir.filter(file => {
// Simple glob matching
const relativePath = file.relative;
if (globPattern.includes('**')) {
// Handle ** patterns - match any path
const pattern = globPattern.replace(/\*\*/g, '.*').replace(/\*/g, '[^/]*');
return new RegExp(`^${pattern}$`).test(relativePath);
} else if (globPattern.includes('*')) {
// Handle single * patterns
const pattern = globPattern.replace(/\*/g, '[^/]*');
return new RegExp(`^${pattern}$`).test(relativePath);
} else {
// Exact match
return relativePath === globPattern;
}
}).listFiles();
for (const smartFile of fileArray) {
for (const smartFile of smartFiles) {
try {
const meta = await this.getMetadata(smartFile.path);
const meta = await this.getMetadata(smartFile.absolutePath);
metadata.push(meta);
} catch (error) {
// Skip files that can't be read
console.warn(`Failed to get metadata for ${smartFile.path}:`, error.message);
console.warn(`Failed to get metadata for ${smartFile.absolutePath}:`, error.message);
}
}
} catch (error) {
@@ -104,7 +120,7 @@ export class LazyFileLoader {
// Load files in parallel
const loadPromises = metadata.map(async (meta) => {
try {
const contents = await plugins.smartfile.fs.toStringSync(meta.path);
const contents = await plugins.fsInstance.file(meta.path).encoding('utf8').read() as string;
const tokenCount = tokenizer(contents);
const fileInfo: IFileInfo = {
@@ -138,7 +154,7 @@ export class LazyFileLoader {
tokenizer: (content: string) => number
): Promise<IFileInfo> {
const meta = await this.getMetadata(filePath);
const contents = await plugins.smartfile.fs.toStringSync(filePath);
const contents = await plugins.fsInstance.file(filePath).encoding('utf8').read() as string;
const tokenCount = tokenizer(contents);
const relativePath = plugins.path.relative(this.projectRoot, filePath);