From f8142f995a5d400ad79bfc519dfdf224f0368e1a Mon Sep 17 00:00:00 2001 From: Jarvis Date: Thu, 25 Sep 2025 12:25:25 +0200 Subject: [PATCH] refactor: migrate PandocCommandBuilder.ts to use PathUtils - Replace fs.existsSync with PathUtils.fileExists() - Replace path.resolve with PathUtils.joinPath() for vault paths - Remove fs require, add PathUtils import - Keep path module for external tool relative path operations (path.relative) - Follow plan guidance for minimal path usage with external tools --- src/converters/pandoc/PandocCommandBuilder.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/converters/pandoc/PandocCommandBuilder.ts b/src/converters/pandoc/PandocCommandBuilder.ts index ca88717..8976e61 100644 --- a/src/converters/pandoc/PandocCommandBuilder.ts +++ b/src/converters/pandoc/PandocCommandBuilder.ts @@ -9,6 +9,7 @@ import { TypstVariableMapper } from './TypstVariableMapper'; import { ResourcePathResolver } from './ResourcePathResolver'; import { PathResolver } from '../../plugin/PathResolver'; import type { obsidianTypstPDFExport } from '../../../main'; +import { PathUtils } from '../../core/PathUtils'; export class PandocCommandBuilder { private plugin: obsidianTypstPDFExport; @@ -95,19 +96,19 @@ export class PandocCommandBuilder { private async addTemplateConfiguration(args: string[], pandocOptions: PandocOptions): Promise { // Use universal wrapper with --template and pass actual template as template_path variable if (pandocOptions.template) { - const fs = require('fs'); + const pathUtils = new PathUtils(this.plugin.app); const absolutePluginDir = pandocOptions.pluginDir || ''; - const wrapperPath = path.resolve(absolutePluginDir, 'templates', 'universal-wrapper.pandoc.typ'); - + const wrapperPath = pathUtils.joinPath(absolutePluginDir, 'templates', 'universal-wrapper.pandoc.typ'); + // Verify wrapper exists - if (!fs.existsSync(wrapperPath)) { + if (!(await pathUtils.fileExists(wrapperPath))) { throw new Error(`Universal wrapper template not found at: ${wrapperPath}`); } - + args.push('--template', wrapperPath); - + // Add plugin templates directory as a resource path so Typst can find template files - const templatesDir = path.resolve(absolutePluginDir, 'templates'); + const templatesDir = pathUtils.joinPath(absolutePluginDir, 'templates'); // Quote the path to handle spaces and special characters args.push('--resource-path', `"${templatesDir}"`);