diff --git a/README.md b/README.md index 78d97240e..1231418df 100644 --- a/README.md +++ b/README.md @@ -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[]; after?: TransformerFactory[]; } )_ +#### getCustomTransformers _( (program: Program) => { before?: TransformerFactory[]; after?: TransformerFactory[]; } )_ 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). diff --git a/src/instances.ts b/src/instances.ts index 4b3c5fd41..abe806dcb 100644 --- a/src/instances.ts +++ b/src/instances.ts @@ -188,7 +188,7 @@ function successfulTypeScriptInstance( program, dependencyGraph: {}, reverseDependencyGraph: {}, - transformers: getCustomTransformers(), + transformers: getCustomTransformers(program), colors }; @@ -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, @@ -267,6 +267,8 @@ function successfulTypeScriptInstance( instance.program = instance.watchOfFilesAndCompilerOptions .getProgram() .getProgram(); + + instance.transformers = getCustomTransformers(instance.program); } else { const servicesHost = makeServicesHost( scriptRegex, diff --git a/src/interfaces.ts b/src/interfaces.ts index 738d523a7..11914aab3 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -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; diff --git a/test/comparison-tests/customTransformer/webpack.config.js b/test/comparison-tests/customTransformer/webpack.config.js index 2bb254c68..6a52c41e5 100644 --- a/test/comparison-tests/customTransformer/webpack.config.js +++ b/test/comparison-tests/customTransformer/webpack.config.js @@ -17,7 +17,7 @@ module.exports = { test: /\.ts$/, loader: 'ts-loader', options: { - getCustomTransformers: () => ({ + getCustomTransformers: (program) => ({ before: [uppercaseStringLiteralTransformer] }) } diff --git a/test/comparison-tests/customTransformerUsingPathString/customerTransformers.js b/test/comparison-tests/customTransformerUsingPathString/customerTransformers.js index 977213398..a72044526 100644 --- a/test/comparison-tests/customTransformerUsingPathString/customerTransformers.js +++ b/test/comparison-tests/customTransformerUsingPathString/customerTransformers.js @@ -1,5 +1,5 @@ var uppercaseStringLiteralTransformer = require('./uppercaseStringLiteralTransformer').default; -module.exports = () => ({ +module.exports = (program) => ({ before: [uppercaseStringLiteralTransformer] }); \ No newline at end of file