vibe-coder-mcp
Version:
Production-ready MCP server with complete agent integration, multi-transport support, and comprehensive development automation tools for AI-assisted workflows.
92 lines (91 loc) • 3.07 kB
JavaScript
import logger from '../../../logger.js';
import { resolveImport, clearImportCache, getImportCacheSize } from './importResolver.no-cache.js';
export class ImportResolverManager {
static instance;
config = {
enabled: false,
useCache: false,
expandSecurityBoundary: true
};
constructor() {
this.config = {
enabled: false,
useCache: false,
expandSecurityBoundary: true
};
}
static getInstance() {
if (!ImportResolverManager.instance) {
ImportResolverManager.instance = new ImportResolverManager();
}
return ImportResolverManager.instance;
}
initialize(config) {
this.config = {
...this.config,
...config,
expandSecurityBoundary: true
};
logger.debug({ config: this.config }, 'Initialized import resolver');
if (config.expandSecurityBoundary === false) {
logger.warn('expandSecurityBoundary was set to false but is being forced to true for better import resolution');
}
}
resolveImport(importPath, fromFile, language, projectRoot, includeAbsolutePath) {
if (!this.config.enabled) {
return includeAbsolutePath ? { resolvedPath: importPath } : importPath;
}
if (importPath === 'unknown') {
return includeAbsolutePath ? { resolvedPath: importPath } : importPath;
}
try {
const extensions = this.config.extensions?.[language];
const options = {
projectRoot,
fromFile,
language,
useCache: this.config.useCache,
extensions,
expandSecurityBoundary: true,
includeAbsolutePath: includeAbsolutePath === true
};
const result = resolveImport(importPath, options);
if (includeAbsolutePath) {
if (typeof result === 'string') {
return { resolvedPath: result };
}
else {
return {
resolvedPath: result.relativePath,
absolutePath: result.absolutePath
};
}
}
else {
if (typeof result === 'string') {
return result;
}
else {
return result.relativePath || importPath;
}
}
}
catch (error) {
logger.warn({ err: error, importPath, fromFile }, 'Error resolving import with import resolver');
return includeAbsolutePath ? { resolvedPath: importPath } : importPath;
}
}
clearCache() {
clearImportCache();
logger.debug('Cleared import resolver cache');
}
getCacheSize() {
return getImportCacheSize();
}
getConfig() {
return { ...this.config };
}
isEnabled() {
return this.config.enabled;
}
}