-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
base: trunk
Are you sure you want to change the base?
Conversation
packages/js/data/package.json
Outdated
@@ -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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
packages/js/data/package.json
Outdated
"service": true | ||
}, | ||
"build:project:esm": { | ||
"command": "tsc --project tsconfig.json", | ||
"command": "tsc --project tsconfig.json || pnpm babel src --out-dir build --extensions \".ts,.tsx\"", |
There was a problem hiding this comment.
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
?
plugins/woocommerce/package.json
Outdated
@@ -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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 usesbabel
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:
pnpm build:project:cjs
pnpm build:project:esm
Changelog entry
Significance
Type
Message
Comment