From b376b346147b03cf56094b61457b701af57af028 Mon Sep 17 00:00:00 2001 From: Ivan Demchuk Date: Tue, 25 Jul 2023 10:28:58 +0300 Subject: [PATCH] Pass source file path to compilers --- src/types/compilers.ts | 4 ++-- src/typescript/SourceFileManager.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/types/compilers.ts b/src/types/compilers.ts index 2301237c0..d31d311c6 100644 --- a/src/types/compilers.ts +++ b/src/types/compilers.ts @@ -1,7 +1,7 @@ type FileExtension = string; -export type SyncCompilerFn = (source: string) => string; -export type AsyncCompilerFn = (source: string) => Promise; +export type SyncCompilerFn = (source: string, path: string) => string; +export type AsyncCompilerFn = (source: string, path: string) => Promise; export type SyncCompilers = Map; export type AsyncCompilers = Map; diff --git a/src/typescript/SourceFileManager.ts b/src/typescript/SourceFileManager.ts index d2b15d9b6..077427289 100644 --- a/src/typescript/SourceFileManager.ts +++ b/src/typescript/SourceFileManager.ts @@ -26,7 +26,7 @@ export class SourceFileManager { if (typeof contents !== 'string') throw new Error(`Unable to read ${filePath}`); const ext = extname(filePath); const compiler = this.syncCompilers?.get(ext); - const compiled = compiler ? compiler(contents) : contents; + const compiled = compiler ? compiler(contents, filePath) : contents; if (compiler) debugLog(`Compiled ${filePath}`); return this.createSourceFile(filePath, compiled); } @@ -46,7 +46,7 @@ export class SourceFileManager { const ext = extname(filePath); const compiler = this.asyncCompilers?.get(ext); if (compiler) { - const compiled = await compiler(contents); + const compiled = await compiler(contents, filePath); debugLog(`Compiled ${filePath}`); this.createSourceFile(filePath, compiled); }