From 6ff1a247739c39cc1f7c8f08f4f05ea55ad590e5 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Thu, 4 Sep 2025 22:48:55 +0200 Subject: [PATCH] Removes excessive logging Removes console log statements used for debugging during development, resulting in cleaner output and improved performance in production. --- main.ts | 16 ---------------- src/converters/MarkdownPreprocessor.ts | 8 +------- src/converters/PandocTypstConverter.ts | 13 ------------- src/converters/PdfToImageConverter.ts | 7 ------- src/core/TempDirectoryManager.ts | 1 - 5 files changed, 1 insertion(+), 44 deletions(-) diff --git a/main.ts b/main.ts index ae01619..90be292 100644 --- a/main.ts +++ b/main.ts @@ -78,8 +78,6 @@ export class obsidianTypstPDFExport extends Plugin { // Cache available fonts (async, don't await) this.cacheAvailableFonts(); - - console.log('Obsidian Typst PDF Export plugin loaded'); } /** @@ -140,7 +138,6 @@ export class obsidianTypstPDFExport extends Plugin { await this.app.vault.adapter.write('.obsidian/plugins/obsidian-typst-pdf-export/fonts-cache.json', JSON.stringify(cacheData, null, 2)); - console.log('Cached', fonts.length, 'fonts from typst'); } catch (error) { console.error('Failed to cache fonts from typst:', error); @@ -501,14 +498,12 @@ export class obsidianTypstPDFExport extends Plugin { // Process PDF embeds if any were found if (processedResult.metadata.pdfEmbeds && processedResult.metadata.pdfEmbeds.length > 0) { - console.log(`Export: Processing ${processedResult.metadata.pdfEmbeds.length} PDF embeds`); const embedPdfFiles = config.embedPdfFiles ?? this.settings.behavior.embedPdfFiles; await this.processPdfEmbeds(processedResult, vaultPath, tempDir, file, embedPdfFiles); } // Process image embeds if any were found if (processedResult.metadata.imageEmbeds && processedResult.metadata.imageEmbeds.length > 0) { - console.log(`Export: Processing ${processedResult.metadata.imageEmbeds.length} image embeds`); await this.processImageEmbeds(processedResult, vaultPath, tempDir, file); } @@ -725,10 +720,8 @@ ${dependencyResult.allAvailable // Try each possible path until we find one that exists for (const possiblePath of possiblePaths) { - console.log(`Export: Checking path: ${possiblePath}`); try { await fs.promises.access(possiblePath); - console.log(`Export: Found PDF at: ${possiblePath}`); return possiblePath; } catch { // File doesn't exist, continue to next path @@ -819,13 +812,11 @@ ${dependencyResult.allAvailable const pathModule = require('path'); const fs = require('fs'); - console.log(`Export: Processing ${processedResult.metadata.pdfEmbeds.length} PDF embeds`); let updatedContent = processedResult.content; for (const pdfEmbed of processedResult.metadata.pdfEmbeds) { try { - console.log(`Export: Processing PDF embed: ${pdfEmbed.originalPath}`); // Resolve PDF path using helper method const fullPdfPath = await this.resolvePdfPath(pdfEmbed.sanitizedPath, vaultBasePath, currentFile); @@ -871,7 +862,6 @@ ${dependencyResult.allAvailable // Replace the placeholder with the combined output updatedContent = updatedContent.replace(pdfEmbed.marker, combinedOutput); - console.log(`Export: Successfully processed PDF embed: ${pdfEmbed.baseName}`); } else { console.warn(`Export: Failed to convert PDF to image: ${result.error}`); const relativePdfPath = pathModule.relative(vaultBasePath, fullPdfPath); @@ -911,13 +901,11 @@ ${dependencyResult.allAvailable const pathModule = require('path'); const fs = require('fs'); - console.log(`Export: Processing ${processedResult.metadata.imageEmbeds.length} image embeds`); let updatedContent = processedResult.content; for (const imageEmbed of processedResult.metadata.imageEmbeds) { try { - console.log(`Export: Processing image embed: ${imageEmbed.originalPath}`); // Decode the URL-encoded sanitized path back to normal characters const decodedPath = decodeURIComponent(imageEmbed.sanitizedPath); @@ -939,7 +927,6 @@ ${dependencyResult.allAvailable try { await fs.promises.access(possiblePath); fullImagePath = possiblePath; - console.log(`Export: Found image at: ${fullImagePath}`); break; } catch { // File doesn't exist, continue to next path @@ -964,7 +951,6 @@ ${dependencyResult.allAvailable updatedContent = updatedContent.replace(imageEmbed.marker, markdownImage); - console.log(`Export: Successfully processed image embed: ${imageEmbed.originalPath}`); } catch (error) { const { fallback } = ExportErrorHandler.handleProcessingError( 'image embed', @@ -1070,7 +1056,6 @@ ${dependencyResult.allAvailable const result = cleanupManager.cleanupAllTempDirs(); if (this.settings.behavior.debugMode) { - console.log('Export: Startup cleanup completed', result); } } catch (error) { console.warn('Export: Startup temp directory cleanup failed (non-critical):', error); @@ -1093,7 +1078,6 @@ ${dependencyResult.allAvailable console.warn('Export: Failed to clean up temp directories during unload:', error); } - console.log('Obsidian Typst PDF Export plugin unloaded'); } } diff --git a/src/converters/MarkdownPreprocessor.ts b/src/converters/MarkdownPreprocessor.ts index aa56cc4..6286e7a 100644 --- a/src/converters/MarkdownPreprocessor.ts +++ b/src/converters/MarkdownPreprocessor.ts @@ -225,7 +225,6 @@ export class MarkdownPreprocessor { if (this.noteTitle) { const yaml = require('js-yaml'); const titleFrontmatter = yaml.dump({ title: this.noteTitle }); - console.log('Replacing frontmatter with title:', titleFrontmatter); processedContent = `---\n${titleFrontmatter}---\n${parsed.content}`; } else { processedContent = parsed.content; @@ -252,7 +251,6 @@ export class MarkdownPreprocessor { if (this.noteTitle) { const yaml = require('js-yaml'); const titleFrontmatter = yaml.dump({ title: this.noteTitle }); - console.log('Adding title frontmatter:', titleFrontmatter); return `---\n${titleFrontmatter}---\n${content}`; } else { return content; @@ -345,8 +343,6 @@ export class MarkdownPreprocessor { return ''; } - console.log('MarkdownPreprocessor: Formatting frontmatter for display:', frontmatter); - const lines: string[] = []; lines.push('**Document Information**'); lines.push(''); @@ -415,13 +411,11 @@ export class MarkdownPreprocessor { // Add a line break after the label for regular values lines.push(`**${formattedKey}:**\n${formattedValue}`); } - console.log(`MarkdownPreprocessor: Formatted ${key} ->`, JSON.stringify(formattedValue)); - } + } } // Join with double newlines to ensure proper spacing between fields const result = lines.join('\n\n'); - console.log('MarkdownPreprocessor: Final formatted frontmatter:', JSON.stringify(result)); return result; } diff --git a/src/converters/PandocTypstConverter.ts b/src/converters/PandocTypstConverter.ts index dc20911..8d686ff 100644 --- a/src/converters/PandocTypstConverter.ts +++ b/src/converters/PandocTypstConverter.ts @@ -100,7 +100,6 @@ export class PandocTypstConverter { await this.ensureTempDirectory(); const tempInputPath = path.join(this.tempDir!, `temp-${Date.now()}.md`); - console.log('PandocTypstConverter: Writing markdown content to temp file:', JSON.stringify(content.substring(0, 1000))); await fsPromises.writeFile(tempInputPath, content, 'utf-8'); // Merge options @@ -149,7 +148,6 @@ export class PandocTypstConverter { for (const pdfEmbed of processedResult.metadata.pdfEmbeds) { try { - console.log(`Export: Processing PDF embed: ${pdfEmbed.originalPath}`); // Resolve full path to the PDF const fullPdfPath = path.resolve(vaultBasePath, pdfEmbed.sanitizedPath); @@ -198,7 +196,6 @@ export class PandocTypstConverter { // Replace marker with output processedResult.content = processedResult.content.replace(pdfEmbed.marker, combinedOutput); - console.log(`Export: Successfully converted PDF: ${pdfEmbed.fileName} -> ${path.basename(conversionResult.imagePath)}`); } else { console.error(`Export: PDF conversion failed: ${conversionResult.error}`); @@ -311,7 +308,6 @@ export class PandocTypstConverter { for (const attachPath of commonAttachmentPaths) { if (fs.existsSync(attachPath)) { args.push('--resource-path', attachPath); - console.log('Added resource path:', attachPath); } } @@ -326,7 +322,6 @@ export class PandocTypstConverter { // Use cached resource paths for (const cachedPath of this.resourcePathCache) { args.push('--resource-path', cachedPath); - console.log('Added cached resource path:', cachedPath); } } else { // Cache is invalid or expired, perform fresh scan @@ -356,7 +351,6 @@ export class PandocTypstConverter { if (hasImages) { foundResourcePaths.push(itemPath); args.push('--resource-path', itemPath); - console.log('Added note-specific resource path:', itemPath); } } catch (e) { // Ignore directories we can't read @@ -368,7 +362,6 @@ export class PandocTypstConverter { this.resourcePathCache = foundResourcePaths; this.resourcePathCacheTimestamp = now; this.resourcePathCacheVaultPath = this.pandocOptions.vaultBasePath; - console.log(`Export: Cached ${foundResourcePaths.length} resource paths for future use`); } catch (e) { console.warn('Could not scan vault for attachment directories:', e); } @@ -381,7 +374,6 @@ export class PandocTypstConverter { const fs = require('fs'); const absolutePluginDir = this.pandocOptions.pluginDir || ''; const wrapperPath = path.resolve(absolutePluginDir, 'templates', 'universal-wrapper.pandoc.typ'); - console.log('Universal wrapper path:', wrapperPath); // Verify wrapper exists if (!fs.existsSync(wrapperPath)) { @@ -560,7 +552,6 @@ export class PandocTypstConverter { const timeout = this.pandocOptions.timeout || 60000; // Log the exact command being executed for debugging - console.log('Executing Pandoc command:', pandocPath, args.join(' ')); progressCallback?.('Starting Pandoc process...', 40); @@ -569,12 +560,10 @@ export class PandocTypstConverter { if (this.pandocOptions.vaultBasePath) { workingDir = this.pandocOptions.vaultBasePath; - console.log('Pandoc working directory (vault):', workingDir); } else { // Fallback to plugin directory const pluginDir = this.pandocOptions.pluginDir || process.cwd(); workingDir = pluginDir; - console.log('Pandoc working directory (plugin fallback):', workingDir); } // Augment PATH to include common binary locations @@ -615,7 +604,6 @@ export class PandocTypstConverter { pandocProcess.stderr?.on('data', (data: Buffer) => { const output = data.toString(); stderr += output; - console.log('Pandoc stderr:', output); // Parse progress information from stderr if available this.parseProgressFromOutput(output, progressCallback); @@ -649,7 +637,6 @@ export class PandocTypstConverter { // Handle process errors pandocProcess.on('error', (error: Error) => { clearTimeout(timeoutHandle); - console.log('Pandoc process error:', error); resolve({ success: false, error: `Failed to start Pandoc process: ${error.message}`, diff --git a/src/converters/PdfToImageConverter.ts b/src/converters/PdfToImageConverter.ts index 349209e..e7b06b7 100644 --- a/src/converters/PdfToImageConverter.ts +++ b/src/converters/PdfToImageConverter.ts @@ -149,8 +149,6 @@ export class PdfToImageConverter { const pdf2imgPath = path.join(pluginDir, 'node_modules', '.bin', 'pdf2img'); - console.log(`Plugin directory: ${pluginDir}`); - console.log(`PDF2IMG path: ${pdf2imgPath}`); // Check if the binary exists const fs2 = require('fs'); @@ -173,7 +171,6 @@ export class PdfToImageConverter { '--pages', '1' // Only convert the first page ].join(' '); - console.log(`PDF conversion command: ${cliCommand}`); try { // Set environment variables to ensure node can be found @@ -191,7 +188,6 @@ export class PdfToImageConverter { const result = await execAsync(cliCommand, { env }); - console.log(`PDF conversion stdout: ${result.stdout}`); if (result.stderr) { console.warn(`PDF conversion stderr: ${result.stderr}`); } @@ -214,12 +210,10 @@ export class PdfToImageConverter { // Debug: List what files are actually in the output directory try { const files = await fs.readdir(outputDir); - console.log(`Files in output directory (${outputDir}):`, files); // Look for any PNG files that might match const pngFiles = files.filter(f => f.endsWith('.png')); if (pngFiles.length > 0) { - console.log(`Found PNG files:`, pngFiles); // Try to find a file that matches the pattern (with or without exact name) // pdf2img might sanitize filenames differently @@ -234,7 +228,6 @@ export class PdfToImageConverter { if (matchingFile) { actualOutputPath = path.join(outputDir, matchingFile); - console.log(`Using found PNG file: ${actualOutputPath}`); } } } catch (listError) { diff --git a/src/core/TempDirectoryManager.ts b/src/core/TempDirectoryManager.ts index cb2da96..27bc2bc 100644 --- a/src/core/TempDirectoryManager.ts +++ b/src/core/TempDirectoryManager.ts @@ -62,7 +62,6 @@ export class TempDirectoryManager { for (const file of files) { this.fs.unlinkSync(this.path.join(tempDir, file)); } - console.log(`Export: Cleaned up ${type === 'images' ? 'temp-images' : 'temp-pandoc'} directory`); return true; } } catch (error) {