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

[Feature]: Allow swc to transform jest.config.ts #12156

Open
Chooks22 opened this issue Dec 17, 2021 · 2 comments
Open

[Feature]: Allow swc to transform jest.config.ts #12156

Chooks22 opened this issue Dec 17, 2021 · 2 comments

Comments

@Chooks22
Copy link

🚀 Feature Proposal

Mostly similar in nature with #11989.

Motivation

@swc/jest lets you transform your files using swc, so having ts-node as another dev dependency just to use .ts extension for the config file seems like a waste.

Example

No response

Pitch

Projects are already using swc, so I guess it fits to make it work with existing tooling

@Craga89
Copy link

Craga89 commented Mar 30, 2022

This PR needs to be merged for this to work properly: swc-project/swc-node#647

For those of you wanting an interim solution to this, if you're not using ts-node at all and only require it for jest config transpilation...

We can create a small shim that replicates the functionality of ts-node#register, using @swc-node/register:

// ts-node-shim/package.json
{
  "name": "ts-node-shim",
  "version": "1.0.0",
  "main": "index.js",
  "license": "UNLICENSED",
  "private": true
}

// ts-node-shim/index.js
const swcNode = require('@swc-node/register/register');
module.exports.register = (options) => {
    let revert;
    return {
        enabled: (enabled) => {
            if (revert) { revert(): }
            if (enabled === true) {
                revert = swcNode.register(options);
            }
        }
    };
}

Then we alias the ts-node package using your package manager (npm, pnpm, yarn) to a local shim using link: or file:

{
   // ...other properties
  "devDependencies": {
     // ...other packages
     "ts-node": "link:./ts-node-shim/index.js"
  }
}

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

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

3 participants