diff --git a/.changeset/serious-olives-relate.md b/.changeset/serious-olives-relate.md new file mode 100644 index 000000000..ee59ae819 --- /dev/null +++ b/.changeset/serious-olives-relate.md @@ -0,0 +1,6 @@ +--- +"@rnx-kit/typescript-service": patch +--- + +Projects should use the writeFile set in the LanguageServiceHost to write files +if it is overridden. diff --git a/packages/typescript-service/src/project.ts b/packages/typescript-service/src/project.ts index c296fe1d6..dbcd4c811 100644 --- a/packages/typescript-service/src/project.ts +++ b/packages/typescript-service/src/project.ts @@ -10,6 +10,7 @@ export class Project { private externalFiles: ExternalFileCache; private languageService: ts.LanguageService; + private writeFile: (fileName: string, content: string) => void; constructor( documentRegistry: ts.DocumentRegistry, @@ -93,6 +94,8 @@ export class Project { if (enhanceLanguageServiceHost) { enhanceLanguageServiceHost(languageServiceHost); } + // if someone replaces writeFile when they enhance the language service host, use that for writing + this.writeFile = languageServiceHost.writeFile || ts.sys.writeFile; this.languageService = ts.createLanguageService( languageServiceHost, @@ -157,7 +160,7 @@ export class Project { return false; } output.outputFiles.forEach((o) => { - ts.sys.writeFile(o.name, o.text); + this.writeFile(o.name, o.text); }); return true; }