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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

support plugins section from compilerOptions #1916

Closed
rifler opened this issue Aug 31, 2020 · 8 comments
Closed

support plugins section from compilerOptions #1916

rifler opened this issue Aug 31, 2020 · 8 comments
Labels
馃殌 Feature Request new suggested feature

Comments

@rifler
Copy link

rifler commented Aug 31, 2020

馃殌 Feature Proposal

If you use ttypescript, you can define plugins section in compilerOptions
It would be great to make it visible in ts-jest

Motivation

do not duplicate plugins in tsconfig.json and jest.config.js

Example

@rifler rifler added the 馃殌 Feature Request new suggested feature label Aug 31, 2020
@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 31, 2020

However, if you mean Language Service plugins, then it is not possible to do and also not necessary to have.

ttypescript plug-in is a different concept than Language Service plugin. I don鈥檛 know which concept do you refer to ? What do you want to achieve ?

@rifler
Copy link
Author

rifler commented Aug 31, 2020

I mean transform plugins, for example https://www.npmjs.com/package/@zerollup/ts-transform-paths

Use case:
I define "baseUrl": "." in tsconfig.json and write imports like import { xxx } from 'server/middlewares'. Typescript itself doesn't provide any settings to make it work in nodejs/jest, so I have to define NODE_PATH=. variable to notify nodejs where to search modules except node_modules folder.
But in my opinion this work should be done by plugins (in an ideal world by TS). For example NODE_PATH will not work for es modules

So @zerollup/ts-transform-paths rewrites from 'server/middlewares' to, for example, from '../../server/middlewares', depending on source module location. There are many other transform plugins, that do different work - https://github.com/cevek/ttypescript#transformers

And it would be great to define them in one place (tsconfig.json) and then jest just "see" them and apply

@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 31, 2020

Ah ha, what you meant is called custom AST transformers, which are already supported. You can check online documentation here https://kulshekhar.github.io/ts-jest/user/config/astTransformers

In general, ts-jest follows standard TypeScript API. Plugins in compiler options for standard TypeScript API is Language Service plugin, which is not the same as custom compiler like ttypescript. Natively, TypeScript doesn鈥檛 support custom AST transformers via tsconfig, that was why ts-jest decided to use an option in jest config to define that. The choice was to prevent conflict with Language Service plugins.

I think from design wise, support custom AST transformers should still stay like it is right now, separately from plugins of compilerOptions.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 31, 2020

Another option is extending standard tsconfig json schema to have a new field to define these transformers.

However, this will lead to not good in design wise. ts-jest is a jest transformer so it is tightly coupled with jest config.

Since AST transformers impact to how codes are transformed for jest to execute, not related to tsc, it makes sense to keep custom ast transformers config limited to jest config only

@rifler
Copy link
Author

rifler commented Aug 31, 2020

My point is that will be great to keep custom plugins in one place rather then copy&paste them between tsconfig and jest config. But I agree that it is not standard feature and can lead errors in feature. As I understand, ttypescript use items with transform field from plugins, and TypeScript itself ignores such items?

Any way, thanks for answers, we can close this issue

which are already supported. You can check online documentation here https://kulshekhar.github.io/ts-jest/user/config/astTransformers

I found that page, but this setting doesn't work for me, maybe I have old version of ts-jest 24.3.0

@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 31, 2020

Yes I think ttypescript picked something uniquely and not used by TypeScript team so they can avoid conflict.

The current documentation is showing new config, which was introduced in #1831, that is why it was different comparing to 24.3.0.

The setting in 24.3.0 is still working with current version but is deprecated and will be removed in v27.

@ahnpnl ahnpnl closed this as completed Aug 31, 2020
@rifler
Copy link
Author

rifler commented Sep 2, 2020

can I see online documentation for old versions of ts-jest?

upd:
also it is unclear from docs how to pass options to transformers

@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 2, 2020

https://github.com/kulshekhar/ts-jest/blob/v26.1.4/docs/user/config/astTransformers.md

You cannot pass option to directly to transformer but you can use ConfigSet as an input. ConfigSet represents ts-jest config. You can check the example of hoist-jest or README which is linked in online documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
馃殌 Feature Request new suggested feature
Projects
None yet
Development

No branches or pull requests

2 participants