swc-project / pkgs

node.js packages for SWC
59 stars 19 forks source link

Allow tsconfig setting in `@swc/jest` #37

Closed ghost closed 7 months ago

ghost commented 7 months ago

We use 2 separate tsconfig.json files; one for coding (which is strict: tsconfig.json) and another one which is lax (for builds: tsconfig.build.json, which includes legacy code). The tsconfig.build.json extends on tsconfig.json like this:

{
  "extends": "./tsconfig.json", 
  "compilerOptions": {
    "strictNullChecks": false,
    <...>
  }
}

Therefore, our existing jest config looks like this:

  <...>
  setupFiles: ['<rootDir>/jest/jest_setup.js'],
  transform: {
    '^.+\\.(t|j)sx?$': ['ts-jest', {
      tsconfig: './tsconfig.build.json'
    }],
  },
  <...>

However, just swapping @swc/jest doesn't respect the tsconfig setting; it errors as:

    Failed to deserialize buffer as swc::config::Options
    JSON: {"tsconfig":"./tsconfig.build.json","jsc":{"target":"es2022","transform":{"hidden":{"jest":true}}},"sourceMaps":"inline","module":{"type":"commonjs"},"filename":"<...>/Projects/<project>/jest/jest_setup.js"}

    Caused by:
        unknown field `tsconfig` at line 1 column 234

I also tried to check if @swc/jest even uses the default tsconfig.json - but that's also not happening probably (at least I can't break it with syntax errors in tsconfig.json).

Would be nice if @swc/jest would support our use-case (specifying tsconfig path + tsconfig "extends" support).

ghost commented 7 months ago

I believe I misunderstood https://swc.rs/docs/migrating-from-tsc I thought it said which tsconfig fields it respects (making me think swc has partial tsconfig support).

However, that documentation is about configuring tsconfig for tsc to align with swc. That would make this issue a duplicate of https://github.com/swc-project/swc/issues/1348.

I'm going to close this.