Typescript: Suggestion: Add the ability to specify paths to custom transformers in tsconfig.json

Created on 14 Mar 2017  ·  1Comment  ·  Source: microsoft/TypeScript

Background

13940 adds customTransformers to Program.emit() that "run custom transformations before and after the main transformation pipeline".

So the code to do this looks like the following:

const transformers: ts.CustomTransformers = {
    before: [transformFactory, otherTransformFactory],
    after: [someAfterTransformFactory]
};
const program = ts.createProgram(...);
program.emit(...etc...., transformers);

Problem

In order to apply a custom transformation, the compiler api must be used. It's takes a bit of work to set this up and most people won't do this for the sake of custom transformations.

It would be nice if there was an easy way to be able to apply custom transformations so that they could be easily shared with others.

Potential Solution

Add the ability so specify paths to custom transformers in tsconfig.json.

So for example:

{
  "compilerOptions": {
    "customTransformers": {
      before: ["node_modules/sometransformfactorypackage"],
      after: ["myTransformFactories/customTransformFactory"]
    }
  }
}

This would most likely use the default export from the package or file specified (requiring it to export a TransformerFactory<SourceFile> object).

Declined Suggestion

>All comments

As noted in https://github.com/Microsoft/TypeScript/issues/14419#issuecomment-283721389, we have no plans to do this in the time being.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manekinekko picture manekinekko  ·  3Comments

dlaberge picture dlaberge  ·  3Comments

fwanicka picture fwanicka  ·  3Comments

Roam-Cooper picture Roam-Cooper  ·  3Comments

uber5001 picture uber5001  ·  3Comments