-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Svelte: Migrate @storybook/svelte to Typescript #8770
Svelte: Migrate @storybook/svelte to Typescript #8770
Conversation
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/storybook/monorepo/f132e08ce |
769ce18
to
5c91031
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.
Great job @aromanarguello!!! A few minor comments above
app/svelte/package.json
Outdated
"@storybook/core": "5.3.0-alpha.41", | ||
"core-js": "^3.0.1", | ||
"global": "^4.3.2", | ||
"regenerator-runtime": "^0.13.3", | ||
"ts-dedent": "^1.1.0" | ||
"ts-dedent": "^1.1.0", | ||
"webpack": "^4.33.0" |
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.
why?
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 added webpack to be able to import the Configuration
type
import { Configuration } from 'webpack';
export function webpack(config: Configuration) {
in the framework-preset-svelte
. What would be the best alternative to this? @shilman
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.
Does webpack now ships its own types? There's also https://www.npmjs.com/package/@types/webpack
In app/angular @ndelangen added it to devDeps and peerDeps along with @types/webpack-env
🤔 (according to git blame)
https://github.com/storybookjs/storybook/blame/next/app/angular/package.json
In app/react webpack
it is a direct dependency and also includes @types/webpack
as a devDep
in app/vue it's the same as in app/react
Back to this PR: would it work with only @types/webpack
as devDependency?
Shipping new direct dependencies is sometimes the root cause of new issues. Do svelte apps install it's own webpack dependency? If yes, then we should ship it as a peerDependency. If not then something under the hood of svelte might already ship it as a direct dependency (kind of like angular)
If svelte does not ship webpack at all it might be ok to ship a directDependency of webpack
@gaetanmaisse Can you assist on this as well?
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 there is no need to add webpack
as dependency
neither as devDependency
. What leads me to that is that:
Configuration
type is used inserver
part of@storybook/svelte
which is not exported to the outside world viatypes/main
properties ofpackage.json
, onlyclient
is.- This package does not use
webpack
directly, it just override/create a webpack config. - This package has
@storybook/core
as a dependency, the latter useswebpack
and have it asdependencies
However, just removing webpack
from package.json
leads to a no-extraneous-dependencies eslint error in server/framework-preset-svelte.ts
. But maybe our context is a good reason to disable this rule for this import?
We should maybe add @types/webpack
as devDependency
as we are using Configuration
type in svelte/src/server
codebase 🤷♂ even if everything looks good to TS compiler without adding it (surely because @types/webpack
is required by another module of SB monorepo). Does anyone know TS best practices when we want to use some dependency typings but not the dependency itself?
What's your mind about 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.
I'm fine with ignoring the no-extraneous-dependencies
warning
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.
Rethinking about it, this issue will maybe be solved when @storybook/core
will be migrated to TS.
If @storybook/core
defines and exports a WebpackConfiguration
type:
import { Configuration } from 'webpack';
export type WebpackConfiguration = Configuration
then using it in @storybook/svelte
will not cause no-extraneous-dependencies
as @storybook/core
is a dependency. And everything should be good for TS if @storybook/core
will have webpack
and @types/webpack
as dependencies.
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.
How do we want to proceed in the meantime? Should we mark config:any
until @storybook/core
is migrated, or ignoring the no-extraneous-dependencies
warning?
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.
@aromanarguello You can add the comment to ignore no-extraneous-dependencies
rule for this line, remove webpack
from dependencies and 🚀
379777c
to
bed95e7
Compare
bed95e7
to
e67b92e
Compare
c1ea4b1
to
35a6011
Compare
b735fbb
to
7d04427
Compare
All comments addressed :) LMK if any other changes are necessary @shilman |
app/svelte/src/index.d.ts
Outdated
@@ -0,0 +1,2 @@ | |||
declare module '@storybook/core/*'; |
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.
This file should be named app/svelte/src/typings.d.ts
instead of app/svelte/src/index.d.ts
app/svelte/tsconfig.json
Outdated
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": ".", |
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.
Use should set :rootDir": "./src",
otherwise dist
folder generated during TS "compilation" is not as expected:
In order to be able to do that you have to use const packageJson = require('../../package.json');
in src/server/options.ts
instead of import packageJson from '../../package.json';
. As it is done for react
for instance:
const packageJson = require('../../package.json'); |
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.
BTW, not related at all to your PR, there is a weird thing with *.d.ts
files, they are compiled to JS files while they shouldn't. I will take a look when I have time to. cc @ndelangen @kroeder
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.
Got it! Thanks for your advice and tips, I am learning a lot :)
@aromanarguello Thanks a lot for your work 👏 ! I just made 2 TS related comments that you can easily fix 💪 . Your PR also puts in the light the |
@@ -1,4 +1,4 @@ | |||
import packageJson from '../../package.json'; | |||
const packageJson = require('../../package.json'); |
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.
why?? @gaetanmaisse
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.
Just saw your comment. Still this seems weird to me. Any references I can look at?
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.
By setting "rootDir": "./src"
we are telling TS compiler that all sources will be in src
folder. As package.json
is not in src
it can not be imported directly (i.e. at compile time) without throwing: File '/Path/to/package.json' is not under 'rootDir' '/Path/To/App/src/'. 'rootDir' is expected to contain all source files.
require
will import the file at runtime so TS compiler will not try to load it and finally everyone is happy.
44d5446
to
16bcc0e
Compare
@gaetanmaisse @aromanarguello are we good to merge this now? |
@shilman, @aromanarguello will add one last commit for #8770 (comment) and we will be good |
aee7968
to
3c76269
Compare
all done @shilman @gaetanmaisse :) |
@aromanarguello Congratulations on your first OSS PR merge!!! 🎉🎉🎉 @gaetanmaisse Thanks for shepherding!!! 🙏🙏🙏 |
Issue: #5030