Skip to content

Commit 68e3526

Browse files
refactor: Remove unnecessary console logs and improve error handling in project file and dependency loading
1 parent 3c09872 commit 68e3526

File tree

4 files changed

+3
-50
lines changed

4 files changed

+3
-50
lines changed

src/services/typescript-project/dependency-loader.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,17 @@ export class DependencyLoader {
1616
*/
1717
static async loadProjectDependencyTypes(projectPath: string): Promise<void> {
1818
try {
19-
console.log('Loading project dependency types...');
2019

2120
// Parse package.json to get actual dependencies
2221
const packageJsonPath = `${projectPath}/package.json`;
2322
const packageJson = await TSConfigLoader.parsePackageJson(packageJsonPath);
2423

2524
if (!packageJson) {
26-
console.log('No package.json found, skipping dependency type loading');
2725
return;
2826
}
2927

3028
// Get all dependencies
3129
const allDependencies = DependencyLoader.getAllDependencies(packageJson);
32-
console.log(`Found ${Object.keys(allDependencies).length} dependencies to analyze for types`);
3330

3431
// Process dependencies in batches to avoid overwhelming the system
3532
const batchSize = 10;
@@ -48,7 +45,6 @@ export class DependencyLoader {
4845
}
4946
}
5047

51-
console.log('Finished loading dependency types');
5248
} catch (error) {
5349
console.error('Error loading project dependency types:', error);
5450
}
@@ -81,7 +77,6 @@ export class DependencyLoader {
8177
// Check if the package exists
8278
const depPackageJson = await TSConfigLoader.parsePackageJson(`${depPath}/package.json`);
8379
if (!depPackageJson) {
84-
console.log(`Package ${dependencyName} not found in node_modules`);
8580
return;
8681
}
8782

@@ -105,7 +100,7 @@ export class DependencyLoader {
105100
}
106101

107102
} catch (error) {
108-
console.log(`Error loading types for ${dependencyName}:`, error);
103+
// noop
109104
}
110105
}
111106

@@ -129,7 +124,6 @@ export class DependencyLoader {
129124
packagePath: string,
130125
packageJson: PackageJson
131126
): Promise<void> {
132-
console.log(`Loading framework types for ${packageName}`);
133127

134128
// Load built-in types first
135129
await DependencyLoader.loadBuiltInTypes(packageName, packagePath, packageJson);
@@ -208,8 +202,6 @@ export class DependencyLoader {
208202
}
209203
}
210204

211-
console.log(`Loaded ${totalLoaded} Next.js type files`);
212-
213205
// Also try to load @types/react if it exists (Next.js depends on React)
214206
await DependencyLoader.loadCorrespondingTypesPackage(projectPath, 'react');
215207

@@ -257,7 +249,7 @@ export class DependencyLoader {
257249

258250
// Try to load all entry points in parallel (truly parallel openFile)
259251
const loadPromises = typeEntryPoints.map((entryPoint) => {
260-
const fullPath = entryPoint!.startsWith('/') ?
252+
const fullPath = entryPoint?.startsWith('/') ?
261253
`${packagePath}${entryPoint}` :
262254
`${packagePath}/${entryPoint}`;
263255

@@ -268,7 +260,6 @@ export class DependencyLoader {
268260
const { content } = result;
269261
const virtualPath = `file:///node_modules/${packageName}/${entryPoint}`;
270262
monaco.languages.typescript.typescriptDefaults.addExtraLib(content, virtualPath);
271-
console.log(`Loaded built-in types for ${packageName} from ${entryPoint}`);
272263
return true;
273264
})
274265
.catch(() => false);
@@ -375,10 +366,6 @@ export class DependencyLoader {
375366
}
376367
}
377368

378-
if (totalLoaded > 0) {
379-
console.log(`Loaded ${totalLoaded} type files for ${packageName}`);
380-
}
381-
382369
} catch (error) {
383370
console.warn(`Failed to search for type files in ${packagePath}:`, error);
384371
}

src/services/typescript-project/file-manager.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@ export class FileManager {
1919
const includePatterns = tsConfig?.include || ['**/*'];
2020
const excludePatterns = tsConfig?.exclude || ['node_modules/**', 'dist/**', 'build/**', '**/*.min.js', '.git/**'];
2121

22-
console.log(`[FileManager] Searching for files with include: ${includePatterns} and exclude: ${excludePatterns}`);
23-
2422
// Get all TypeScript/JavaScript files in the project based on tsconfig
2523
const files = await projectApi.searchFiles('**/*.{ts,tsx,js,jsx,d.ts}', projectPath, {
2624
includePatterns: includePatterns,
2725
excludePatterns: excludePatterns,
2826
});
2927

30-
console.log(`[FileManager] Found ${files.length} files matching tsconfig patterns.`);
31-
3228
// Create a comprehensive file map for better import resolution
3329
const fileMap = new Map<string, string>();
3430
files.forEach(filePath => {
@@ -85,7 +81,6 @@ export class FileManager {
8581

8682
await Promise.allSettled(loadPromises);
8783

88-
console.log(`[FileManager] Loaded ${projectFiles.size} files into Monaco with enhanced import mapping.`);
8984
} catch (error) {
9085
console.error('[FileManager] Error loading project files:', error);
9186
}
@@ -105,16 +100,12 @@ export class FileManager {
105100
const includePatterns = tsConfig?.include || ['**/*'];
106101
const excludePatterns = tsConfig?.exclude || ['node_modules/**', 'dist/**', 'build/**', '**/*.min.js', '.git/**'];
107102

108-
console.log(`[FileManager] Searching for files with include: ${includePatterns} and exclude: ${excludePatterns}`);
109-
110103
// Get all TypeScript/JavaScript files in the project based on tsconfig
111104
const files = await projectApi.searchFiles('**/*.{ts,tsx,js,jsx,d.ts}', projectPath, {
112105
includePatterns: includePatterns,
113106
excludePatterns: excludePatterns,
114107
});
115108

116-
console.log(`[FileManager] Found ${files.length} files matching tsconfig patterns.`);
117-
118109
// Prioritize loading files from common source directories
119110
const sourceFiles = files.filter(f =>
120111
f.includes('/src/') ||
@@ -143,7 +134,6 @@ export class FileManager {
143134

144135
await Promise.allSettled(loadPromises);
145136

146-
console.log(`[FileManager] Loaded ${projectFiles.size} files into Monaco.`);
147137
} catch (error) {
148138
console.error('[FileManager] Error loading project files:', error);
149139
}
@@ -191,7 +181,6 @@ export class FileManager {
191181
// and 'javascript' for both .js and .jsx files
192182
const language = (filePath.endsWith('.ts') || filePath.endsWith('.tsx')) ? 'typescript' : 'javascript';
193183
monaco.editor.createModel(content, language, uri);
194-
console.log(`Created Monaco model for ${relativePath} with language ${language}`);
195184
} else {
196185
// Update existing model
197186
existingModel.setValue(content);
@@ -201,7 +190,6 @@ export class FileManager {
201190
if (filePath.endsWith('.d.ts')) {
202191
const virtualPath = `file:///${relativePath}`;
203192
monaco.languages.typescript.typescriptDefaults.addExtraLib(content, virtualPath);
204-
console.log(`Added .d.ts file to extra libs: ${relativePath}`);
205193
}
206194

207195
} catch (error) {
@@ -286,8 +274,6 @@ export class FileManager {
286274
excludePatterns: ['**/node_modules/**', '**/dist/**', '**/build/**', '.git/**']
287275
});
288276

289-
console.log(`Found ${projectTypeFiles.length} project type definition files`);
290-
291277
// Load each project .d.ts file
292278
const loadPromises = projectTypeFiles.map(async (filePath) => {
293279
try {
@@ -300,7 +286,6 @@ export class FileManager {
300286
const virtualPath = `file:///${relativePath}`;
301287

302288
monaco.languages.typescript.typescriptDefaults.addExtraLib(content, virtualPath);
303-
console.log(`Loaded project type definitions from ${relativePath}`);
304289

305290
} catch (error) {
306291
console.warn(`Failed to load project type file ${filePath}:`, error);

src/services/typescript-project/monaco-config.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,18 @@ export class MonacoConfig {
8888
// Properly configure baseUrl and paths for module resolution
8989
if (options.baseUrl) {
9090
monacoOptions.baseUrl = `${projectPath}${options.baseUrl.replace(/^\./, '')}`;
91-
console.log(`[MonacoConfig] Set baseUrl to: ${monacoOptions.baseUrl}`);
9291
}
9392

9493
if (options.paths) {
9594
monacoOptions.paths = {};
9695
for (const [key, value] of Object.entries(options.paths)) {
9796
monacoOptions.paths[key] = value.map(p => `${projectPath}${p.replace(/^\./, '')}`);
9897
}
99-
console.log(`[MonacoConfig] Set paths to:`, monacoOptions.paths);
10098
}
10199

102100
// Apply to both TypeScript and JavaScript defaults
103101
monaco.languages.typescript.typescriptDefaults.setCompilerOptions(monacoOptions);
104102
monaco.languages.typescript.javascriptDefaults.setCompilerOptions(monacoOptions);
105-
106-
console.log('Applied tsconfig compiler options to Monaco:', monacoOptions);
107-
console.log('Original tsconfig options:', options);
108103
}
109104

110105
/**
@@ -116,7 +111,6 @@ export class MonacoConfig {
116111
// so we need to reset the typescript defaults
117112
monaco.languages.typescript.typescriptDefaults.setExtraLibs([]);
118113
monaco.languages.typescript.javascriptDefaults.setExtraLibs([]);
119-
console.log('Cleared Monaco extra libraries');
120114
} catch (error) {
121115
console.warn('Error clearing Monaco extra libraries:', error);
122116
}
@@ -142,7 +136,6 @@ export class MonacoConfig {
142136

143137
const result = await projectApi.openFile(libFilePath);
144138
if (!result || !result.content) {
145-
console.warn(`Failed to load TypeScript lib: ${libFileName}`);
146139
continue;
147140
}
148141
const { content } = result;
@@ -152,7 +145,6 @@ export class MonacoConfig {
152145
`file:///node_modules/typescript/lib/${libFileName}`
153146
);
154147

155-
console.log(`Loaded TypeScript lib: ${libFileName}`);
156148
} catch (error) {
157149
console.warn(`Could not load TypeScript lib ${lib}:`, error);
158150
}
@@ -182,7 +174,6 @@ export class MonacoConfig {
182174
monaco.languages.typescript.typescriptDefaults.setCompilerOptions(compilerOptions);
183175
monaco.languages.typescript.javascriptDefaults.setCompilerOptions(compilerOptions);
184176

185-
console.log('[MonacoConfig] Enhanced module resolution configured');
186177
} catch (error) {
187178
console.error('[MonacoConfig] Error setting up module resolution:', error);
188179
}

src/services/typescript-project/tsconfig-loader.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@ export class TSConfigLoader {
1818
loadedConfigs.add(configPath);
1919

2020
try {
21-
console.log("loading tsconfig from", configPath);
2221
const result = await projectApi.openFile(configPath);
2322
if (!result || !result.content) {
2423
throw new Error(`Failed to read tsconfig from ${configPath}`);
2524
}
2625
const { content } = result;
2726
const cleanedContent = TSConfigLoader.removeJSONComments(content);
28-
29-
// Debug logging for JSON parsing issues
30-
if (process.env.NODE_ENV === 'development') {
31-
console.log('[TSConfigLoader] Original content length:', content.length);
32-
console.log('[TSConfigLoader] Cleaned content length:', cleanedContent.length);
33-
}
27+
3428

3529
try {
3630
const tsConfig = JSON.parse(cleanedContent) as TSConfig;
@@ -57,7 +51,6 @@ export class TSConfigLoader {
5751
}
5852

5953
} catch (error) {
60-
console.log(`[TSConfigLoader] Failed to load ${configPath}:`, error instanceof Error ? error.message : String(error));
6154
return null;
6255
}
6356
};
@@ -71,12 +64,10 @@ export class TSConfigLoader {
7164
for (const path of possiblePaths) {
7265
const tsConfig = await loadAndMerge(path);
7366
if (tsConfig) {
74-
console.log(`[TSConfigLoader] Loaded final tsconfig from ${path}:`, tsConfig);
7567
return tsConfig;
7668
}
7769
}
7870

79-
console.log('[TSConfigLoader] No valid tsconfig.json or jsconfig.json found.');
8071
return null;
8172
}
8273

@@ -183,7 +174,6 @@ export class TSConfigLoader {
183174
const { content } = result;
184175
return JSON.parse(content);
185176
} catch (error) {
186-
console.log('Could not parse package.json:', error);
187177
return null;
188178
}
189179
}

0 commit comments

Comments
 (0)