Skip to content

Commit

Permalink
Add function to get the latest program
Browse files Browse the repository at this point in the history
  • Loading branch information
Zn4rK committed Aug 3, 2021
1 parent 55d2a85 commit e41dc35
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion 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",
Expand Down
16 changes: 10 additions & 6 deletions src/instances.ts
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces.ts
Expand Up @@ -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;
Expand Down

0 comments on commit e41dc35

Please sign in to comment.