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

POC: Emit TS errors as warnings #47486

Draft
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Draft

POC: Emit TS errors as warnings #47486

wants to merge 7 commits into from

Conversation

rrennick
Copy link
Contributor

@rrennick rrennick commented May 14, 2024

Changes proposed in this Pull Request:

This is a proof of concept for easing TS compiler strictness to allow updating our packages to use wp-6.4. It uses babel to build the output files if the TS build fails.

See #45535 .

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Run pnpm build:project:cjs
  2. Run pnpm build:project:esm
  3. Run watches of both

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

@github-actions github-actions bot added focus: monorepo infrastructure Issues and PRs related to monorepo tooling. package: @woocommerce/data issues related to @woocommerce/data labels May 14, 2024
@@ -131,7 +132,7 @@
},
"wireit": {
"build:project:cjs": {
"command": "tsc --project tsconfig-cjs.json",
"command": "tsc --project tsconfig-cjs.json || pnpm babel src --out-dir build --extensions \".ts,.tsx\" --watch",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not implement tsc --noEmit because this would stop generating the build files if no TS errors occurred.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rrennick I think I made a mistake in my initial analysis because the libraries need to emit build types that each other library uses 😭 and only TS can generate those. I'm sorry I don't know why I didn't think of that at the time.

I think we can only use type checking approach in consuming packages such as blocks, admin, product editor, basically anywhere we use a webpack config. In those projects we can use something like https://github.com/TypeStrong/fork-ts-checker-webpack-plugin but not have it block building.

I still think it would generously help the situation because we'd only be limited to fixing problems in the library packages themselves not in the downstream projects that consume them. If there is a type change due to dependency update, teams will have time to fix them instead of it immediately breaking their builds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I made a mistake in my initial analysis because the libraries need to emit build types that each other library uses 😭 and only TS can generate those.

I thought it would be worth a try to add tsc --emitDeclarationOnly before adding another dependency. This seems to work okay from my testing. The CI build fails on the components package. Does this mean we would need to make these changes to all of the packages in the same PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rrennick if we do it in this direction where we start with the packages everything depends on then yes there is a good chance we'll break all consuming packages.

Before what we tried was basically both directions: we fix all the type issues in the packages, then all the consumers break because the types are different so we fix those as well (all within the same gigantic PR). My rough idea here that supposedly cuts the work in half is to have type errors on build in consuming packages be turned into warnings, then fix all the types in one package at a time (although this will cause some cascading type issues in some cases like data package may now break components like you're encountering) but in theory it reduces the workload to just fixing types within the packages.

Please let me know if you'd like any help or support with this, we could probably work together on it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ts-loader has transpileOnly setting and combined with https://github.com/TypeStrong/fork-ts-checker-webpack-plugin it will still check and report errors during development but not block building

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will still check and report errors during development but not block building

@samueljseay I'll have a look at it tomorrow.

Please let me know if you'd like any help or support with this, we could probably work together on it.

That sounds great. Once we have the POC working the way we want then we can plan the larger project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will still check and report errors during development but not block building

@samueljseay I wasn't able to get build output with the transpileOnly option (only updated the build:project:esm command to webpack). I've pushed my last iteration of config changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rrennick you're not supposed to get build output from transpile only. and build:project:esm belongs to packages. maybe you misunderstood what I'm suggesting here.

I'm suggesting leaving type checking and build as normal in the packages that don't have a webpack.config already

then in existing webpack builds like woocommerce-admin or product-editor (any package with webpack.config.js) using the https://github.com/TypeStrong/fork-ts-checker-webpack-plugin to do type checking / reporting but not fail because it won't actually compile the TS only check it. This would mean we still have to fix type issues in packages but not in product editor or wc-admin for example

"service": true
},
"build:project:esm": {
"command": "tsc --project tsconfig.json",
"command": "tsc --project tsconfig.json || pnpm babel src --out-dir build --extensions \".ts,.tsx\"",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need two configuration files for babel?

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label May 15, 2024
@@ -418,7 +418,6 @@
"node_modules/@woocommerce/e2e-core-tests/CHANGELOG.md",
"node_modules/@woocommerce/api/dist/",
"node_modules/@woocommerce/admin-e2e-tests/build",
"node_modules/@woocommerce/classic-assets/build",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this line keeps getting removed when I run pnpm i. We should restore this line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rrennick dependencyOutputs is auto generated by the .pnpmfile.cjs if it's removing this there may be a bug there to investigate.

@github-actions github-actions bot removed the plugin: woocommerce Issues related to the WooCommerce Core plugin. label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: monorepo infrastructure Issues and PRs related to monorepo tooling. package: @woocommerce/data issues related to @woocommerce/data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants