Skip to content

Commit

Permalink
feat(typescript-service): pick up the writeFile override from the Lan…
Browse files Browse the repository at this point in the history
…guageServiceHost when it is overridden (#3491)
  • Loading branch information
JasonVMo authored Jan 23, 2025
1 parent 242df82 commit d60608a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/serious-olives-relate.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 4 additions & 1 deletion packages/typescript-service/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d60608a

Please sign in to comment.