-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Type check production files #31555
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
Type check production files #31555
Conversation
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.
2 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
|
View your CI Pipeline Execution ↗ for commit bcffd61.
☁️ Nx Cloud last updated this comment at |
293b741 to
2884be3
Compare
8de30d0 to
898fa94
Compare
5dfd25a to
977ccc0
Compare
|
So what we're stuck on now is that |
|
The addon-vitest one is curious, looks like tsup can't handle nodenext module resolutions? |
| "check": "jiti ../../../scripts/prepare/check.ts", | ||
| "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" |
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.
can you explain why these scripts need to be renamed?
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 can. I find nx a bit impenetrable, but it seems that if a user runs nx check, and nx finds a script called check in package.json, it'll run that script rather than its own, ignoring all nx config.
So the options were either rename all the check scripts in all package.json, which is churny but not user visible, or rename the top-level nx command, which would potentially confuse users.
| async function getTSFilesAndConfig(tsconfigPath: string, production = false) { | ||
| const content = await fs.readJson(tsconfigPath); | ||
| if (production) { | ||
| content.compilerOptions.skipLibCheck = false; |
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 see, so the current check is running a check on the src and this new "production" is type-checking the dist, which you can only do, if you have this flag as false, correct?
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.
Yes - skipLibCheck needs to be false to check .d.ts files. I see that storybook's custom reporter is already eliminating errors that come from outside the sources root, so it could probably be safely set to true globally.
| "executor": "nx:run-commands", | ||
| "options": { | ||
| "cwd": "{projectRoot}", | ||
| "command": "yarn typecheck" |
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.
Could we keep this name check, to reduce the amount of changes needed?
| "command": "yarn typecheck" | |
| "command": "yarn check" |
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.
See above, as far as I can tell nx will prefer package.json definitions to its own if the names match. In the likely event I'm wrong it can be changed, but it took me five times as long to get nx working as to get the type checking working.
scripts/tasks/check.ts
Outdated
|
|
||
| export const check: Task = { | ||
| description: 'Typecheck the source code of the monorepo', | ||
| dependsOn: ['compile'], |
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 it's preferable if we can still typecheck our src without compiling first; this would make that impossible?
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.
All of the nx check tasks already depend on the build task (which is, confusingly, what the compile task runs...), so this makes minimal difference; at the very least it should include install to support running type checking from a cold-start
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 suppose it does somewhat reduce the degree of parallelisation available as all build tasks need to be completed before check tasks can start. The stacked task runners do make this hard to follow sometimes.
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 49 | 49 | 0 |
| Self size | 31.87 MB | 31.85 MB | 🎉 -16 KB 🎉 |
| Dependency size | 17.41 MB | 17.41 MB | 0 B |
| Bundle Size Analyzer | Link | Link |
sb
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 50 | 50 | 0 |
| Self size | 1 KB | 1 KB | 0 B |
| Dependency size | 49.27 MB | 49.26 MB | 🎉 -16 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/cli
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 216 | 216 | 0 |
| Self size | 582 KB | 582 KB | 0 B |
| Dependency size | 94.59 MB | 94.57 MB | 🎉 -16 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/codemod
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 185 | 185 | 0 |
| Self size | 31 KB | 31 KB | 🚨 +4 B 🚨 |
| Dependency size | 78.72 MB | 78.71 MB | 🎉 -16 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
|
Unfortunately the line from typescript appears to be "Don't have type errors in your public API": microsoft/TypeScript#38628 |
|
@ndelangen and @JReinhold. Can you take a brief look at this PR as part of the ESM project, since you are about to revamp the build process entirely. Thanks! |
|
Closing in favour of #32447 |
Closes #31554
What I did
As recommended by tsup, this runs type checking over generated
.d.tsfiles to ensure tsup has not generated invalid production typescript.Unfortunately, whilst the script works fine when invoked manually, I've no idea how to get nx to actually run it - there's a bit too much implicit magic going on for my to understand what's needed.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>Greptile Summary
This PR enhances TypeScript type checking by validating both source and production files, particularly the generated
.d.tsfiles from tsup.check.tsscript that disables path aliases andskipLibCheckfor dist fileschecktask configuration innx.jsonwith production mode option