From 21ed9e122f6a727cf3aaa2e543a3a1308fd72500 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Thu, 25 Sep 2025 16:41:27 +0200 Subject: [PATCH] fix(FontManager): Improve cross-platform PATH handling and deduplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Set both PATH and Path environment variables for Windows compatibility - Add tilde (~) path expansion for user home directories - Implement actual path deduplication using Set instead of just filtering empty strings - Properly split and combine existing PATH with additional platform-specific paths Ensures spawned typst processes can find executables reliably across all platforms. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/plugin/FontManager.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/plugin/FontManager.ts b/src/plugin/FontManager.ts index 64f7af3..388c736 100644 --- a/src/plugin/FontManager.ts +++ b/src/plugin/FontManager.ts @@ -23,9 +23,11 @@ export class FontManager { // Use spawn instead of exec for security - arguments passed separately const stdout = await new Promise((resolve, reject) => { // Build platform-specific environment with enhanced PATH + const pathValue = this.buildPlatformSpecificPATH(); const enhancedEnv = { ...process.env, - PATH: this.buildPlatformSpecificPATH() + PATH: pathValue, + Path: pathValue }; const typstProcess = spawn(typstPath, ['fonts'], { @@ -179,6 +181,15 @@ export class FontManager { const currentPath = process.env.PATH || ''; const pathSeparator = process.platform === 'win32' ? ';' : ':'; + // Helper function to expand tilde paths + const expandTildePath = (path: string): string => { + if (path.startsWith('~')) { + const homeDir = process.env.HOME || process.env.USERPROFILE || ''; + return path.replace('~', homeDir); + } + return path; + }; + // Platform-specific common installation paths let additionalPaths: string[] = []; @@ -222,8 +233,18 @@ export class FontManager { additionalPaths = ['/usr/local/bin', '/usr/bin', '/bin']; } - // Combine current PATH with additional paths, avoiding duplicates - const allPaths = [...additionalPaths, currentPath].filter(path => path.length > 0); - return allPaths.join(pathSeparator); + // Expand tilde paths and filter empty strings + const expandedPaths = additionalPaths + .map(expandTildePath) + .filter(path => path.length > 0); + + // Split current PATH and combine with additional paths + const currentPaths = currentPath.split(pathSeparator).filter(path => path.length > 0); + const allPaths = [...expandedPaths, ...currentPaths]; + + // Remove duplicates while preserving order + const uniquePaths = [...new Set(allPaths)]; + + return uniquePaths.join(pathSeparator); } } \ No newline at end of file