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
This commit is contained in:
Jarvis committed 2025-09-25 12:25:25 +02:00
1 parent 948ec77ae6
commit f8142f995a
1 file changed
+8 -7
@@ -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<void> {
// 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}"`);