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

Support custom transformers for ts-loader #731

Open
lionel-bijaoui opened this issue Apr 12, 2022 · 0 comments
Open

Support custom transformers for ts-loader #731

lionel-bijaoui opened this issue Apr 12, 2022 · 0 comments

Comments

@lionel-bijaoui
Copy link

Feature motivation

It is impossible to perform transformation to the file before type checking.
ts-loader custom transformer are not taken into account. fork-ts-checker-webpack-plugin seem to only check against the original files.
When using ts-import-plugin, a plugin that change the import statements, it can cause issue.

example

I'm using the plugin to avoid having to create "index" files for folders while still being able to use simple import with alias.
In a folder like that:

  • src/
    • app.js
    • modules/
      • index.ts
      • moduleA.ts
      • moduleB.ts
      • moduleC.ts

With alias @ for src/ and alias modules for src/modules/index.ts

// index.ts
export { default as moduleA } from "./moduleA"
export { default as moduleB } from "./moduleB";
export { default as moduleC } from "./moduleC";

// moduleA.ts
export default class moduleA {
  //...
}

// moduleB.ts
const propertyB = "propertyB";
const methodB = () => { return propertyB; }

export default { propertyB, methodB }

// moduleC.ts
import { moduleA, moduleB } from "modules";

export default function() {
  return  new moduleA(moduleB.methodB());
}

// app.ts
import { moduleB, moduleC } from "modules";

console.log(moduleB.propertyB);
moduleC();

Without the transform, I need to maintain index.ts manually to use the simple import syntax. Mind you, my example is very simple, but this system is used with many more module folders and files.
I also need to create the necessary alias, both in tsconfig and webpack.

With a little config of the transformer, I am able to completely avoid using index.ts as the import are transformed to something like this:

// moduleC.ts
import moduleA from "@/modules/moduleA"
import moduleB from "@/modules/moduleB"

export default function() {
  return  new moduleA(moduleB.methodB());
}

// app.ts
import moduleB from "@/modules/moduleB";
import moduleC from "@/modules/moduleC";

console.log(moduleB.propertyB);
moduleC();

And no need for the alias, since they are transformed on the fly.
Except in fork-ts-checker-webpack-plugin, where I need both to maintain the index files and the alias.

Feature description

Ideally it would take any transform into account before type checking.
More realistically, it should have an option similar to ts-loader custom transformer, assuming I might not need to apply all transform. It would make setup a little more verbose but would allow for more control over what transform I want to apply, for performance reasons (some transform might not impact type checking ability).
It might help with .vue files, allowing to avoid having custom option for it, simply apply a transform to the files, but I'm not sure about that.

Feature implementation

Adding an option getcustomtransformers, that apply a change to a file before type checking phase. I don't know the internal of the plugin so I don't know the feasibility.
Ideally, it should use the same interface as ts-loader, to allow plugin reuse.
I shouldn't hurt multi-threading, since transform are applied on a file by file basis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant