From ed9f3da0d732558bdc51f9b6c27be347081fae92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Lilejeng=C3=A5rd?= Date: Tue, 3 Aug 2021 15:04:48 +0200 Subject: [PATCH] Add function to get the latest program --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/instances.ts | 16 ++++++++++------ src/interfaces.ts | 3 ++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb4f51013..12809d6cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v9.2.5 + +* [Add function to get the latest program](https://github.com/TypeStrong/ts-loader/pull/1352) - thanks @Zn4rk + ## v9.2.4 * [Fix undefined configPath now falls back to default](https://github.com/TypeStrong/ts-loader/pull/1346) - thanks @johnnyreilly diff --git a/package.json b/package.json index a616bbbd3..77c5fb11c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-loader", - "version": "9.2.4", + "version": "9.2.5", "description": "TypeScript loader for webpack", "main": "index.js", "types": "dist", diff --git a/src/instances.ts b/src/instances.ts index 722384209..3b509c29b 100644 --- a/src/instances.ts +++ b/src/instances.ts @@ -377,7 +377,8 @@ export function initializeInstance( }) : instance.compiler.createProgram([], instance.compilerOptions)); - instance.transformers = getCustomTransformers(program); + const getProgram = () => program; + instance.transformers = getCustomTransformers(program, getProgram); // Setup watch run for solution building if (instance.solutionBuilderHost) { addAssetHooks(loader, instance); @@ -407,9 +408,13 @@ export function initializeInstance( instance.compiler.createWatchProgram(instance.watchHost); instance.builderProgram = instance.watchOfFilesAndCompilerOptions.getProgram(); - instance.program = instance.builderProgram.getProgram(); - instance.transformers = getCustomTransformers(instance.program); + const getProgram = () => instance.builderProgram?.getProgram(); + instance.program = getProgram(); + instance.transformers = getCustomTransformers( + instance.program, + getProgram + ); } else { instance.servicesHost = makeServicesHost( getScriptRegexp(instance), @@ -423,9 +428,8 @@ export function initializeInstance( instance.compiler.createDocumentRegistry() ); - instance.transformers = getCustomTransformers( - instance.languageService!.getProgram() - ); + const getProgram = () => instance.languageService!.getProgram(); + instance.transformers = getCustomTransformers(getProgram(), getProgram); } addAssetHooks(loader, instance); diff --git a/src/interfaces.ts b/src/interfaces.ts index 275a046d2..301705e13 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -270,7 +270,8 @@ export interface LoaderOptions { getCustomTransformers: | string | (( - program: typescript.Program + program: typescript.Program, + getProgram: () => typescript.Program ) => typescript.CustomTransformers | undefined); experimentalWatchApi: boolean; allowTsInNodeModules: boolean;