Skip to content

chore(internal): revisit tsconfig files #1667

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

Merged

Conversation

dreamorosi
Copy link
Contributor

@dreamorosi dreamorosi commented Sep 2, 2023

Description of your changes

This PR introduces changes to the TypeScript configuration of the project by revisiting and standardizing the configurations across packages. Before this PR each workspace was defining and maintaining its own TypeScript configuration, this defeated the purpose of using a monorepo structure and made maintenance time consuming.

In this PR we define the main tsconfig.json file at the root of the project and then use the extends option to define a more specific one in each workspace package.

This way the main settings for the project are defined centrally simplifying maintenance and enforcing increased consistency. At the same time, workspace packages can still override any of the settings locally ensuring customizability.

For example, given a tsconfig.json file at the project's root:

{
  "compilerOptions": {
    "incremental": true,
    "composite": true,
    "target": "ES2020", // Node.js 14
    "experimentalDecorators": true, // TODO: remove this once we move to TypeScript 5.x
    "module": "commonjs",
  }
}

we can define a more specific one in packages/logger/tsconfig.json by extending the main one:

{
    "extends": "../../tsconfig.json",
    "compilerOptions": {
        "outDir": "./lib",
        "rootDir": "./src",
    },
    "include": [
        "./src/**/*"
    ],
}

Starting from this PR we also introduce a dedicated tsconfig.json file in the tests directory of each workspace, i.e. packages/logger/tests/tsconfig.json:

{
    "extends": "../tsconfig.json",
    "compilerOptions": {
        "rootDir": "../",
        "noEmit": true
    },
    "include": [
        "../src/**/*",
        "./**/*",
    ]
}

This allows us to finally include the tests as part of the TS configuration but still keep them excluded from the compilation.

In addition to the changes above, we have also reviewed every option available and considered its impact on the project. As a result of this work we have introduced a couple new options that should bring performance improvements at build time:

  • Start using references and composite to the project: "Project references are a way to structure your TypeScript programs into smaller pieces. Using Project References can greatly improve build and editor interaction times, enforce logical separation between components, and organize your code in new and improved ways."
  • Start using the incremental setting to tell "TypeScript to save information about the project graph from the last compilation to files stored on disk. This creates a series of .tsbuildinfo files in the same folder as your compilation output."

The two changes above open the door to potential additional build performance improvements in the future by caching incremental build artifacts or parallelizing commands but still having TS figure out dependencies between modules.

In addition to the above, we have identified a few other areas that we'd like to experiment in the near future but that we have intentionally left out due to potential breaking changes, like:

  • importHelpers, noEmitHelpers, and downlevelIteration which would allow to move helpers to an external tslib module shared across files rather than emitting the same helpers multiple times
  • isolatedModules which would allow to ensure that each file can be safely transpiled without relying on other imports, thus further improving build perf

Related issues, RFCs

Issue number: #617

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective and works
  • The PR title follows the conventional commit semantics

Breaking change checklist

Is it a breaking change?: NO

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@dreamorosi dreamorosi self-assigned this Sep 2, 2023
@dreamorosi dreamorosi requested a review from a team September 2, 2023 14:59
@dreamorosi dreamorosi linked an issue Sep 2, 2023 that may be closed by this pull request
@boring-cyborg boring-cyborg bot added batch This item relates to the Batch Processing Utility commons This item relates to the Commons Utility documentation Improvements or additions to documentation dependencies Changes that touch dependencies, e.g. Dependabot, etc. internal PRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.) tests PRs that add or change tests labels Sep 2, 2023
@pull-request-size pull-request-size bot added the size/XXL PRs with 1K+ LOC, largely documentation related label Sep 2, 2023
@dreamorosi dreamorosi changed the title chore(build): revisit tsconfig files chore(internal): revisit tsconfig files Sep 3, 2023
@dreamorosi dreamorosi force-pushed the 617-maintenance-simplify-and-revisit-tsconfig-files-settings branch from 89edc53 to 6364b0e Compare September 4, 2023 08:56
@boring-cyborg boring-cyborg bot added the automation This item relates to automation label Sep 4, 2023
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@dreamorosi dreamorosi merged commit 858d2f2 into main Sep 4, 2023
@dreamorosi dreamorosi deleted the 617-maintenance-simplify-and-revisit-tsconfig-files-settings branch September 4, 2023 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automation This item relates to automation batch This item relates to the Batch Processing Utility commons This item relates to the Commons Utility dependencies Changes that touch dependencies, e.g. Dependabot, etc. documentation Improvements or additions to documentation internal PRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.) size/XXL PRs with 1K+ LOC, largely documentation related tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance: simplify and revisit tsconfig files & settings
1 participant