-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Build: Migrate @storybook/scripts to strict-ts #23818
Conversation
scripts/task.ts
Outdated
getTaskKey(task), | ||
details.key, | ||
startTime, | ||
err instanceof Error ? err : new Error(String(err)), |
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 what err
might be here so this seemed safest. But if it's expected always to be an Error
it might be better to make writeJunitXml
take unknown
and use an invariant similar to what sendTelemetryError
does in #23632 .
Nice! Do we also run the new task in circle CI? @stilt0n |
@kasperpeulen I haven't added it to the CI, but I can see if I can add it later today. I only took a short look, but is the CI just running |
@stilt0n I think so. |
code/package.json
Outdated
"check": "NODE_ENV=production node ../scripts/check-package.js", | ||
"check:scripts": "cd ../scripts && ./prepare/check-scripts.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.
With the "nx"
field these can be picked up by nx run
and nx run-many
. Unfortunately, if we try to do this all in one command, the check task would also run check-package
which I think we don't want it to do.
I considered renaming check
to check:package
, but then I would need to know everywhere it is used so it can be renamed, which is tricky using just text search.
scripts/tasks/check.ts
Outdated
const linkCommand = `nx run-many --target="check" --all --parallel=${parallel} --exclude=@storybook/addon-storyshots,@storybook/addon-storyshots-puppeteer,@storybook/vue,@storybook/svelte,@storybook/vue3,@storybook/angular,root && nx run root:check:scripts`; | ||
const nolinkCommand = `nx run-many --target="check" --all --parallel=${parallel} --exclude=@storybook/addon-storyshots,@storybook/addon-storyshots-puppeteer,root && nx run root:check:scripts`; |
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.
Here we could avoid using two commands with:
'nx run-many --target="check","check:scripts" --all <...>'
But I think we'd need to rename the "check" script in code/package.json
to make that work.
I've added a commit to make the new typechecking script run on CI. I've left a few comments on parts where I think it might be able to be improved. I think the current solution ought to work as is, but I'd be interested in suggestions on how to improve it. |
@stilt0n Discussed this with @yannbf storybook/.circleci/config.yml Lines 186 to 201 in 5c3c839
As the scripts directory is kind of outside of the monorepo. Maybe we could just run it before the tets:
|
@kasperpeulen Thanks for the suggestion! That seems much better than what I have. |
@stilt0n Thanks! I will do a proper review tomorrow. |
// TS "tests" | ||
// deepscan-disable-next-line | ||
function test(mv: MaybeOptionValues<typeof allOptions>, v: OptionValues<typeof allOptions>) { | ||
console.log(mv.first, mv.second, mv.third, mv.fourth, mv.fifth, mv.sixth); | ||
// @ts-expect-error as it's not allowed | ||
console.log(mv.seventh); | ||
console.log(v.first, v.second, v.third, v.fourth, v.fifth, v.sixth); | ||
// @ts-expect-error as it's not allowed | ||
console.log(v.seventh); | ||
} | ||
|
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 don't really think it makes a lot of sense to keep this "test" but if it were really important to prevent these particular cases from being changed this could be wrapped in a trivial test to silence compiler warnings, e.g.
describe('TS "tests"', () => {
it('MaybeOptionValues and OptionValues type test', () => {
// deepscan-disable-next-line
function test(mv: MaybeOptionValues<typeof allOptions>, v: OptionValues<typeof allOptions>) {
console.log(mv.first, mv.second, mv.third, mv.fourth, mv.fifth, mv.sixth);
// @ts-expect-error as it's not allowed
console.log(mv.seventh);
console.log(v.first, v.second, v.third, v.fourth, v.fifth, v.sixth);
// @ts-expect-error as it's not allowed
console.log(v.seventh);
}
expect(test).toBeDefined();
});
});
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.
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 don't think this test matters that much indeed, so I'm just gonna merge it thanks!
@stilt0n I changed the |
e84f7dc
to
fb89a4d
Compare
fb89a4d
to
56da460
Compare
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.
LGTM!
Part of #22176
What I did
Migrate @storybook/scripts to strict-ts
More specifically:
tsconfig.json
to use strict types@storybook/scripts
based on the one inprepare/check.ts
check:scripts
to CIHow to test
Check types with
cd scripts && yarn check
. The typecheck script should run in CI now as well.Checklist
MIGRATION.MD
Maintainers
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
["cleanup", "BREAKING CHANGE", "feature request", "bug", "build", "documentation", "maintenance", "dependencies", "other"]