diff --git a/README.md b/README.md index a0aafa2..b3e00f8 100644 --- a/README.md +++ b/README.md @@ -131,9 +131,9 @@ For development or the latest changes: ### 1. Install Dependencies **Required:** -- [Pandoc](https://pandoc.org/installing.html) - Markdown to Typst conversion -- [Typst](https://typst.app/docs/reference/foundations/) - PDF generation -- [ImageMagick](https://imagemagick.org/script/download.php) - Enhanced image processing +- [Pandoc](https://pandoc.org/installing.html) 3.7.0+ - Markdown to Typst conversion +- [Typst](https://typst.app/docs/reference/foundations/) 0.13.0+ - PDF generation +- [ImageMagick](https://imagemagick.org/script/download.php) 7.1.2+ - Enhanced image processing ### 2. Export Your First Note @@ -173,11 +173,13 @@ Go to the plugin settings and click **Check Dependencies** to ensure all require ### External Dependencies -| Tool | Purpose | Installation | -|------|---------|-------------| -| **Pandoc** | Markdown → Typst conversion | [Download here](https://pandoc.org/installing.html) or `brew install pandoc` | -| **Typst** | PDF generation | [Download here](https://typst.app/docs/reference/foundations/) or `brew install typst` | -| **ImageMagick** | Enhanced image processing (optional) | [Download here](https://imagemagick.org/script/download.php) or `brew install imagemagick` | +| Tool | Minimum Version | Purpose | Installation | +|------|----------------|---------|-------------| +| **Pandoc** | 3.7.0 | Markdown → Typst conversion | [Download here](https://pandoc.org/installing.html) or `brew install pandoc` | +| **Typst** | 0.13.0 | PDF generation | [Download here](https://typst.app/docs/reference/foundations/) or `brew install typst` | +| **ImageMagick** | 7.1.2 | Enhanced image processing (optional) | [Download here](https://imagemagick.org/script/download.php) or `brew install imagemagick` | + +**Note**: The plugin will display warnings if your installed versions are below the minimum requirements. While older versions may work, they are not officially supported and may cause compatibility issues. ### Dependency Verification @@ -259,6 +261,7 @@ JB |---------|----------| | **"Pandoc not found"** | Install Pandoc and ensure it's in your system PATH | | **"Typst not found"** | Install Typst CLI and verify PATH configuration | +| **Outdated version warning** | Update dependencies to meet minimum versions (Pandoc 3.7.0+, Typst 0.13.0+, ImageMagick 7.1.2+) | | **Export hangs** | Check if files are locked by other applications | | **Images not showing** | Verify image paths and file permissions | | **Template errors** | Check template syntax and file integrity | diff --git a/src/core/DependencyChecker.ts b/src/core/DependencyChecker.ts index 151a3a6..addd5a1 100644 --- a/src/core/DependencyChecker.ts +++ b/src/core/DependencyChecker.ts @@ -23,6 +23,7 @@ import { ExecutableChecker, DependencyInfo } from './ExecutableChecker'; * @property imagemagick - Detailed information about ImageMagick installation * @property allAvailable - True if all dependencies are available * @property missingDependencies - Array of names of missing dependencies + * @property outdatedDependencies - Array of names of dependencies with versions below minimum */ export interface DependencyCheckResult { pandoc: DependencyInfo; @@ -30,6 +31,7 @@ export interface DependencyCheckResult { imagemagick: DependencyInfo; allAvailable: boolean; missingDependencies: string[]; + outdatedDependencies: string[]; } /** @@ -141,21 +143,26 @@ export class DependencyChecker { ]); const [pandocInfo, typstInfo, imagemagickInfo] = await Promise.all([ - ExecutableChecker.checkDependency('Pandoc', pandocExec, '--version', /pandoc\s+([\d.]+)/), - ExecutableChecker.checkDependency('Typst', typstExec, '--version', /typst\s+([\d.]+)/), - ExecutableChecker.checkDependency('ImageMagick', imagemagickExec, '--version', /ImageMagick\s+([\d.-]+)/) + ExecutableChecker.checkDependency('Pandoc', pandocExec, '--version', /pandoc\s+([\d.]+)/i, DEPENDENCY_CONSTANTS.MINIMUM_VERSIONS.pandoc), + ExecutableChecker.checkDependency('Typst', typstExec, '--version', /typst\s+([\d.]+)/i, DEPENDENCY_CONSTANTS.MINIMUM_VERSIONS.typst), + ExecutableChecker.checkDependency('ImageMagick', imagemagickExec, '--version', /ImageMagick\s+([\d.-]+)/i, DEPENDENCY_CONSTANTS.MINIMUM_VERSIONS.imagemagick) ]); const missingDependencies = [pandocInfo, typstInfo, imagemagickInfo] .filter(dep => !dep.isAvailable) .map(dep => dep.name); + const outdatedDependencies = [pandocInfo, typstInfo, imagemagickInfo] + .filter(dep => dep.isAvailable && !dep.meetsMinimumVersion) + .map(dep => dep.name); + return { pandoc: pandocInfo, typst: typstInfo, imagemagick: imagemagickInfo, allAvailable: missingDependencies.length === 0, - missingDependencies + missingDependencies, + outdatedDependencies }; } @@ -289,18 +296,32 @@ export class DependencyChecker { additionalPaths ); - const formatVersion = (dep: DependencyInfo) => dep.isAvailable ? (dep.version || 'Available') : 'Not found'; - + const formatVersion = (dep: DependencyInfo) => { + if (!dep.isAvailable) return 'Not found'; + if (!dep.meetsMinimumVersion) return `${dep.version} (minimum: ${dep.minimumVersion})`; + return dep.version || 'Available'; + }; + + const statusLines: string[] = []; + + // Build status messages + if (!dependencyResult.allAvailable) { + statusLines.push(`Missing dependencies: ${dependencyResult.missingDependencies.join(', ')}. Please install them and check the paths in settings.`); + } else if (dependencyResult.outdatedDependencies.length > 0) { + statusLines.push(`⚠️ Outdated versions detected: ${dependencyResult.outdatedDependencies.join(', ')}.`); + statusLines.push(`Please update to avoid compatibility issues.`); + } else { + statusLines.push('✓ All dependencies found and up to date!'); + } + const message = `Dependency Status: Pandoc: ${formatVersion(dependencyResult.pandoc)} Typst: ${formatVersion(dependencyResult.typst)} ImageMagick: ${formatVersion(dependencyResult.imagemagick)} -${dependencyResult.allAvailable - ? 'All dependencies found!' - : `Missing dependencies: ${dependencyResult.missingDependencies.join(', ')}. Please install them and check the paths in settings.`}`; - - ExportErrorHandler.showProgressNotice(message, 12000); // Show for 12 seconds (longer due to more content) +${statusLines.join('\n')}`; + + ExportErrorHandler.showProgressNotice(message, 15000); // Show for 15 seconds (longer due to version info) } /** diff --git a/src/core/ExecutableChecker.ts b/src/core/ExecutableChecker.ts index 0abd7a8..52c6eca 100644 --- a/src/core/ExecutableChecker.ts +++ b/src/core/ExecutableChecker.ts @@ -11,6 +11,7 @@ import { spawn, spawnSync } from 'child_process'; import { DEPENDENCY_CONSTANTS } from './constants'; +import { isVersionAtLeast } from '../utils/versionUtils'; import * as path from 'path'; /** @@ -20,12 +21,16 @@ import * as path from 'path'; * @property version - Detected version string, or null if unavailable * @property isAvailable - Whether the executable was found and executed successfully * @property executablePath - The resolved path to the executable + * @property meetsMinimumVersion - Whether the version meets the minimum requirement (true if no version check performed) + * @property minimumVersion - The minimum required version string (null if not checked) */ export interface DependencyInfo { name: string; version: string | null; isAvailable: boolean; executablePath: string; + meetsMinimumVersion: boolean; + minimumVersion: string | null; } /** @@ -287,7 +292,8 @@ export class ExecutableChecker { * This method: * 1. Spawns the executable with the version command (e.g., '--version') * 2. Captures stdout and parses version using the provided regex - * 3. Returns comprehensive dependency information + * 3. Optionally validates against minimum required version + * 4. Returns comprehensive dependency information * * Security: Uses spawn instead of exec to prevent command injection. Arguments * are passed separately from the command. @@ -296,6 +302,7 @@ export class ExecutableChecker { * @param executablePath - Path to the executable to check * @param versionCommand - Command argument for version (e.g., '--version') * @param versionRegex - Regex with capture group for version number + * @param minimumVersion - Optional minimum required version (e.g., "0.13.0") * @returns DependencyInfo object with availability and version information * * @example @@ -304,11 +311,14 @@ export class ExecutableChecker { * 'Pandoc', * '/usr/bin/pandoc', * '--version', - * /pandoc (\d+\.\d+(?:\.\d+)?)/ + * /pandoc (\d+\.\d+(?:\.\d+)?)/, + * '3.7.0' * ); * - * if (info.isAvailable) { + * if (info.isAvailable && info.meetsMinimumVersion) { * console.log(`Found ${info.name} version ${info.version}`); + * } else if (info.isAvailable) { + * console.warn(`${info.name} ${info.version} is below minimum ${info.minimumVersion}`); * } else { * console.error(`${info.name} not available at ${info.executablePath}`); * } @@ -318,7 +328,8 @@ export class ExecutableChecker { name: string, executablePath: string, versionCommand: string, - versionRegex: RegExp + versionRegex: RegExp, + minimumVersion: string | null = null ): Promise { try { // Use spawn instead of exec for security - arguments passed separately @@ -354,19 +365,28 @@ export class ExecutableChecker { const match = stdout.match(versionRegex); const version = match ? match[1] : null; - + + // Check version against minimum if both are available + const meetsMinimumVersion = minimumVersion && version + ? isVersionAtLeast(version, minimumVersion) + : true; // No minimum version check or version unavailable + return { name, version, isAvailable: true, - executablePath + executablePath, + meetsMinimumVersion, + minimumVersion }; } catch { return { name, version: null, isAvailable: false, - executablePath + executablePath, + meetsMinimumVersion: true, // Not checking if unavailable + minimumVersion }; } } diff --git a/src/core/constants.ts b/src/core/constants.ts index 9a02335..97222d7 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -201,6 +201,22 @@ export const DEPENDENCY_CONSTANTS = { imagemagick: 'magick' }, + /** + * Minimum required versions for external dependencies. + * + * These versions represent the minimum supported versions that have been + * tested with this plugin. Users with older versions will receive warnings. + * + * @property pandoc - Pandoc 3.7.0 (current stable as of plugin development) + * @property typst - Typst 0.13.0 (version used during plugin development) + * @property imagemagick - ImageMagick 7.1.2 (current stable as of plugin development) + */ + MINIMUM_VERSIONS: { + pandoc: '3.7.0', + typst: '0.13.0', + imagemagick: '7.1.2' + }, + /** * Common installation paths to search for executables. * diff --git a/src/utils/versionUtils.ts b/src/utils/versionUtils.ts new file mode 100644 index 0000000..3d0c3bb --- /dev/null +++ b/src/utils/versionUtils.ts @@ -0,0 +1,54 @@ +/** + * Version Utilities + * + * Lightweight utilities for comparing semantic version strings. + * Used for minimum version validation of external dependencies. + */ + +/** + * Compares two semantic version strings. + * + * @param version1 - First version string (e.g., "0.13.0") + * @param version2 - Second version string (e.g., "0.5.0") + * @returns Negative if version1 < version2, 0 if equal, positive if version1 > version2 + * + * @example + * ```typescript + * compareVersions("0.13.0", "0.5.0") // Returns 8 (0.13.0 > 0.5.0) + * compareVersions("1.0.0", "1.0.0") // Returns 0 (equal) + * ``` + */ +export function compareVersions(version1: string, version2: string): number { + // Extract numeric parts, ignoring pre-release tags and build metadata + const v1Parts = version1.split(/[-+]/)[0].split('.').map(Number); + const v2Parts = version2.split(/[-+]/)[0].split('.').map(Number); + + const maxLength = Math.max(v1Parts.length, v2Parts.length); + for (let i = 0; i < maxLength; i++) { + const v1 = v1Parts[i] || 0; + const v2 = v2Parts[i] || 0; + + if (v1 !== v2) { + return v1 - v2; + } + } + + return 0; +} + +/** + * Checks if a version meets a minimum required version. + * + * @param actualVersion - The detected version string + * @param minimumVersion - The minimum required version string + * @returns True if actualVersion >= minimumVersion + * + * @example + * ```typescript + * isVersionAtLeast("0.13.0", "0.13.0") // Returns true + * isVersionAtLeast("0.12.0", "0.13.0") // Returns false + * ``` + */ +export function isVersionAtLeast(actualVersion: string, minimumVersion: string): boolean { + return compareVersions(actualVersion, minimumVersion) >= 0; +}