Skip to content

Commit

Permalink
fix(node): #1180 - Adjust tsconfig compiler options
Browse files Browse the repository at this point in the history
Accidentally applied `es6` when compilerOptions.module was not defined.
  • Loading branch information
matthewh committed Jun 19, 2024
1 parent c54a1fd commit c175fef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
## Main

<!-- Your comment below this -->

- [#1180] Set module properly when tsconfig does not contain compilerOptions.module [@matthewh]
<!-- Your comment above this -->

## 12.3.2
Expand Down
12 changes: 8 additions & 4 deletions source/runner/runners/utils/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,14 @@ const sanitizeTSConfig = (config: any, esm: boolean = false) => {
//
// @see https://github.com/apollographql/react-apollo/pull/1402#issuecomment-351810274
//
if (!esm && safeConfig.compilerOptions.module) {
safeConfig.compilerOptions.module = "commonjs"
} else {
safeConfig.compilerOptions.module = "es6"
if (safeConfig.compilerOptions.module) {

This comment has been minimized.

Copy link
@FrederickEngelhardt

FrederickEngelhardt Jun 20, 2024

Hello, will this fix the issue for tsconfig.json when using extends which references another tsconfig.(XYZ).json compilerOptions that set a module?

Perhaps an alternative would be to directly reference or allow referencing of a specific typescript config file.

We are unable to use danger 12.3.2 or 12.3.3 (breaking CI/CD, pipelines due to this).

Example:

  • tsconfig.json (for all files to use typescript but not the base, typically used for IDE)
  • tsconfig.base.json (for extending tsconfig.json + other variants such as builds)

tsconfig.build.json

  "compilerOptions": {
    "module": "es2020",
  },

tsconfig.json

  "extends": "./tsconfig.base.json",

This comment has been minimized.

Copy link
@FrederickEngelhardt

FrederickEngelhardt Jun 20, 2024

Edit. Looks like it does work in 12.3.3!

TLDR skip 12.3.2 if you use modules that are not common or es6.

Though I don't think this block will work with extended files. (But es2020 does not have issues with danger).

This comment has been minimized.

Copy link
@matthewh

matthewh Jun 20, 2024

Author Contributor

es6 was the minimum version I tested that worked properly across my project samples. Obviously there are many ways to setup your tsconfig.json! I can experiment with not setting compiler options at all for esm if it's already defined.

This comment has been minimized.

Copy link
@FrederickEngelhardt

FrederickEngelhardt Jun 20, 2024

Yeah, I wish there was a simpler way to access the inheritance structure of tsconfig.json b/c solving for an extend only gets to the next file in the chain if you have a deeply nested monorepo project.

Thanks for the quick fix in 12.3.3 👍

if (!esm) {
// .ts files should fall back to commonjs
safeConfig.compilerOptions.module = "commonjs"
} else {
// .mts files must use `import`/`export` syntax
safeConfig.compilerOptions.module = "es6"
}
}

return safeConfig
Expand Down

0 comments on commit c175fef

Please sign in to comment.