TypescriptServices and custom CompilerHost #1478

Closed
opened 2025-08-09 17:20:17 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @dazinator on 7/23/2016

I'm fairly new to typescript, but reading some docs, the typescript compiler has an interface that abstracts away the underlying file system, it looks like this:

interface CompilerHost {
    getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
    getDefaultLibFilename(options: CompilerOptions): string;
    getCancellationToken?(): CancellationToken;
    writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
    getCurrentDirectory(): string;
    getCanonicalFileName(fileName: string): string;
    useCaseSensitiveFileNames(): boolean;
    getNewLine(): string;
}

Heres an implementation: 59608778a6/src/harness/unittests/reuseProgramStructure.ts (L106)

How cool would it be, if we could implement one of these, where getSourceFile() calls back into the IFileProvider that NodeServices is using in your aspnet core app?

This would allow us to run a typescript compiler, that can see / access all the files that your asp.net application can see - which may include files from any source, not just physical files.

Am I barking up the wrong tree here?

I'd be happy to try and give this ago but i'm not sure where to start with how to implement a callback from nodejs code into .net to hook my .NET IFileProvider.. I'm assuming i'd have to fork NodeServices and make changes somewhere..

If we did do such a thing, we could put this in a project called TypeScriptServices ?

*Originally created by @dazinator on 7/23/2016* I'm fairly new to typescript, but reading some docs, the typescript compiler has an interface that abstracts away the underlying file system, it looks like this: ``` interface CompilerHost { getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile; getDefaultLibFilename(options: CompilerOptions): string; getCancellationToken?(): CancellationToken; writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; getCurrentDirectory(): string; getCanonicalFileName(fileName: string): string; useCaseSensitiveFileNames(): boolean; getNewLine(): string; } ``` Heres an implementation: https://github.com/Microsoft/TypeScript/blob/59608778a64a599c42351e68749fe4543935836d/src/harness/unittests/reuseProgramStructure.ts#L106 How cool would it be, if we could implement one of these, where `getSourceFile()` calls back into the `IFileProvider` that NodeServices is using in your aspnet core app? This would allow us to run a typescript compiler, that can see / access all the files that your asp.net application can see - which may include files from any source, not just physical files. Am I barking up the wrong tree here? I'd be happy to try and give this ago but i'm not sure where to start with how to implement a callback from nodejs code into .net to hook my .NET IFileProvider.. I'm assuming i'd have to fork `NodeServices` and make changes somewhere.. If we did do such a thing, we could put this in a project called `TypeScriptServices` ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1478
No description provided.