Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass ts.Program to getCustomTransformers() #889

Merged
merged 3 commits into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v5.3.3

* [fix: Pass ts.Program to getCustomTransformers](https://github.com/TypeStrong/ts-loader/pull/889) (#860) - thanks @andersekdahl!

## v5.3.2

* [feat: enable experimentalFileCaching by default](https://github.com/TypeStrong/ts-loader/pull/885) (#868) - thanks @timocov!
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ This will ensure that the plugin checks for both syntactic errors (eg `const arr

Also, if you are using `thread-loader` in watch mode, remember to set `poolTimeout: Infinity` so workers don't die.

#### getCustomTransformers _( () => { before?: TransformerFactory<SourceFile>[]; after?: TransformerFactory<SourceFile>[]; } )_
#### getCustomTransformers _( (program: Program) => { before?: TransformerFactory<SourceFile>[]; after?: TransformerFactory<SourceFile>[]; } )_

Provide custom transformers - only compatible with TypeScript 2.3+ (and 2.4 if using `transpileOnly` mode). For example usage take a look at [typescript-plugin-styled-components](https://github.com/Igorbek/typescript-plugin-styled-components) or our [test](test/comparison-tests/customTransformer).

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-loader",
"version": "5.3.2",
"version": "5.3.3",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist/types/index.d.ts",
Expand Down
8 changes: 6 additions & 2 deletions src/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function successfulTypeScriptInstance(
program,
dependencyGraph: {},
reverseDependencyGraph: {},
transformers: getCustomTransformers(),
transformers: getCustomTransformers(program),
colors
};

Expand Down Expand Up @@ -235,7 +235,7 @@ function successfulTypeScriptInstance(
otherFiles,
languageService: null,
version: 0,
transformers: getCustomTransformers(),
transformers: {} as typescript.CustomTransformers, // this is only set temporarily, custom transformers are created further down
dependencyGraph: {},
reverseDependencyGraph: {},
modifiedFiles: null,
Expand Down Expand Up @@ -267,6 +267,8 @@ function successfulTypeScriptInstance(
instance.program = instance.watchOfFilesAndCompilerOptions
.getProgram()
.getProgram();

instance.transformers = getCustomTransformers(instance.program);
} else {
const servicesHost = makeServicesHost(
scriptRegex,
Expand All @@ -285,6 +287,8 @@ function successfulTypeScriptInstance(
if (servicesHost.clearCache !== null) {
loader._compiler.hooks.watchRun.tap('ts-loader', servicesHost.clearCache);
}

instance.transformers = getCustomTransformers(instance.languageService!.getProgram());
}

loader._compiler.hooks.afterCompile.tapAsync(
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export interface LoaderOptions {
happyPackMode: boolean;
getCustomTransformers?:
| string
| (() => typescript.CustomTransformers | undefined);
| ((program: typescript.Program) => typescript.CustomTransformers | undefined);
experimentalWatchApi: boolean;
allowTsInNodeModules: boolean;
experimentalFileCaching: boolean;
Expand Down
2 changes: 1 addition & 1 deletion test/comparison-tests/customTransformer/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
test: /\.ts$/,
loader: 'ts-loader',
options: {
getCustomTransformers: () => ({
getCustomTransformers: (program) => ({
before: [uppercaseStringLiteralTransformer]
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var uppercaseStringLiteralTransformer = require('./uppercaseStringLiteralTransformer').default;

module.exports = () => ({
module.exports = (program) => ({
before: [uppercaseStringLiteralTransformer]
});