- Changed adapter.list() to use empty string for vault root instead of absolute path - Convert vault-relative paths to absolute paths when returning for external tools - Fixes cross-platform compatibility issues per CodeRabbit review - Maintains existing functionality while following Obsidian API best practices 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
6.9 KiB
CodeRabbit Suggestions Implementation Plan
Overview
This plan documents the CodeRabbit review suggestions from PR #5 that should be implemented to improve cross-platform compatibility, code quality, and robustness of the Obsidian Typst PDF Export plugin.
Implementation Tasks
1. manifest.json - Version Compatibility SKIPPED
- Current:
minAppVersion: "1.9.12" - Decision: Keep as-is - only up-to-date users should use the plugin
- Status: ✅ Skipped per user preference
2. PandocCommandBuilder.ts - Path Quoting Fix
File: src/converters/pandoc/PandocCommandBuilder.ts
Line: 113
Issue: Extra quotes around path can break spawn command
Current Code:
args.push('--resource-path', `"${templatesDir}"`);
Fix:
args.push('--resource-path', templatesDir);
Reason: The spawn command handles quoting automatically. Manual quotes can cause issues, especially on Windows.
3. ResourcePathResolver.ts - Vault-Relative Paths
File: src/converters/pandoc/ResourcePathResolver.ts
Issues:
adapter.list()should use vault-relative paths, not absolute- Should return absolute paths for external tools
- Need better error handling
Changes Needed:
- Ensure all
adapter.list()calls use vault-relative paths - Convert to absolute paths only when returning for external tool consumption
- Add try-catch blocks around path operations
- Validate paths before adding to resource list
4. BinaryLocator.ts - Windows Compatibility
File: src/converters/pdf/BinaryLocator.ts
Issues:
- Missing Windows executable extensions (.cmd, .bat, .ps1)
- No platform-specific binary detection
- Limited fallback mechanisms
Changes Needed:
// Add Windows-specific executable detection
const windowsExtensions = process.platform === 'win32'
? ['.cmd', '.bat', '.ps1', '.exe']
: [''];
// Check for platform-specific binaries
const binaryName = process.platform === 'win32'
? 'pdf2img.cmd'
: 'pdf2img';
// Add multiple fallback paths for different installation methods
const fallbackPaths = [
path.join(pluginDir, 'node_modules', '.bin'),
path.join(pluginDir, 'node_modules', 'pdf-to-img', 'bin'),
// Windows-specific paths
path.join(process.env.APPDATA || '', 'npm'),
path.join(process.env.LOCALAPPDATA || '', 'npm-cache')
];
5. FileDiscovery.ts - Dynamic File Extension Support
File: src/converters/pdf/FileDiscovery.ts
Issues:
- Hardcoded to only look for '.png' files
- Should support multiple image formats
- Pattern matching too restrictive
Changes Needed:
// Dynamic extension support
const supportedImageExtensions = ['.png', '.jpg', '.jpeg', '.webp', '.gif'];
// Update file filtering
const imageFiles = files.filter(f =>
supportedImageExtensions.some(ext => f.toLowerCase().endsWith(ext))
);
// Improve pattern matching to handle more filename variations
private static matchFilePattern(files: string[], expectedFileName: string): string | null {
const expectedBase = path.basename(expectedFileName, path.extname(expectedFileName));
// Try multiple matching strategies
// 1. Exact match
// 2. Base name match with any supported extension
// 3. Sanitized pattern match
// 4. Fuzzy match for pdf2img output patterns
}
6. ExportOrchestrator.ts - Plugin Name for Temp Dir
File: src/plugin/ExportOrchestrator.ts
Line: 147
Issue: TempDirectoryManager should receive plugin name for proper namespacing
Current Code:
const tempManager = new TempDirectoryManager({
vaultPath: vaultPath,
configDir: this.plugin.app.vault.configDir,
app: this.plugin.app
});
Fix:
const tempManager = new TempDirectoryManager({
vaultPath: vaultPath,
configDir: this.plugin.app.vault.configDir,
app: this.plugin.app,
pluginName: this.plugin.manifest.id
});
7. FontManager.ts - Consistent Path Handling
File: src/plugin/FontManager.ts
Issues:
- Mixed use of absolute and vault-relative paths
- Potential issues with cross-platform font discovery
- Need better validation
Changes Needed:
- Ensure all vault.adapter operations use vault-relative paths
- Add platform-specific font discovery improvements
- Validate font paths before caching
- Add error recovery for corrupted cache
8. General Improvements
Error Handling
- Add comprehensive try-catch blocks
- Provide meaningful error messages to users
- Log detailed errors for debugging
- Implement graceful degradation
TypeScript Type Safety
- Remove any remaining
anytypes - Add proper type guards
- Use strict null checks
- Validate external data
Resource Cleanup
- Ensure temp files are always cleaned up
- Add finally blocks for cleanup operations
- Implement proper abort handling
- Clean up on plugin unload
Cross-Platform Testing Matrix
- Windows 10/11
- macOS (Intel and Apple Silicon)
- Linux (Ubuntu/Debian)
- Different Obsidian versions
Implementation Order
-
Critical Path Fixes (High Priority)
- PandocCommandBuilder.ts - Remove path quotes
- ResourcePathResolver.ts - Fix path handling
- PathUtils.fileExists - Already fixed in previous commit
-
Cross-Platform Compatibility (Medium Priority)
- BinaryLocator.ts - Windows support
- FileDiscovery.ts - Dynamic extensions
- FontManager.ts - Platform-specific paths
-
Code Quality (Lower Priority)
- ExportOrchestrator.ts - Plugin namespacing
- General error handling improvements
- TypeScript type safety enhancements
Testing Plan
Unit Tests Needed
- Path resolution with various input formats
- Binary detection on different platforms
- File discovery with multiple extensions
- Font caching and retrieval
Integration Tests
- Full export pipeline on Windows/Mac/Linux
- Embedded file resolution
- Template loading and processing
- Temp directory cleanup
Manual Testing Checklist
- Export with embedded PDFs
- Export with various image formats
- Export with custom templates
- Export on Windows
- Export on macOS
- Export on Linux
- Verify temp directory cleanup
- Test cancellation during export
- Test with special characters in paths
Expected Outcomes
-
Improved Reliability
- Fewer "file not found" errors
- Better error messages
- Graceful degradation
-
Better Cross-Platform Support
- Windows users can use the plugin
- Consistent behavior across platforms
- Platform-specific optimizations
-
Cleaner Codebase
- Better TypeScript types
- Consistent error handling
- Improved maintainability
Notes
- All changes should maintain backward compatibility
- Test thoroughly before release
- Document any breaking changes
- Consider adding automated tests in future
References
- Original PR: https://github.com/AlexKucera/obsidian-typst-pdf-export/pull/5
- CodeRabbit Review Comments: See PR comments
- Obsidian API Documentation: https://docs.obsidian.md/
- TypeScript Best Practices: https://www.typescriptlang.org/docs/handbook/