From d60608aad1576efe2526decd6046540842612ffb Mon Sep 17 00:00:00 2001 From: Jason Morse <35609178+JasonVMo@users.noreply.github.com> Date: Thu, 23 Jan 2025 01:42:08 -0800 Subject: [PATCH] feat(typescript-service): pick up the writeFile override from the LanguageServiceHost when it is overridden (#3491) --- .changeset/serious-olives-relate.md | 6 ++++++ packages/typescript-service/src/project.ts | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/serious-olives-relate.md 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; }