Skip to content

Commit

Permalink
Pass source file path to compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
Demivan committed Jul 25, 2023
1 parent c80542d commit b376b34
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/types/compilers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type FileExtension = string;

export type SyncCompilerFn = (source: string) => string;
export type AsyncCompilerFn = (source: string) => Promise<string>;
export type SyncCompilerFn = (source: string, path: string) => string;
export type AsyncCompilerFn = (source: string, path: string) => Promise<string>;

export type SyncCompilers = Map<FileExtension, SyncCompilerFn>;
export type AsyncCompilers = Map<FileExtension, AsyncCompilerFn>;
4 changes: 2 additions & 2 deletions src/typescript/SourceFileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit b376b34

Please sign in to comment.