Repository navigation
[No QA][TS migration] Migrate Storybook files #37771
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
Changes from all commits
e3c79db
d906791
2f5bf90
1acd6ea
cadc458
57fe5e7
58ab1f2
68210c3
7da601f
4fc0eed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,20 @@ | ||
| module.exports = { | ||
| import type {StorybookConfig} from '@storybook/core-common'; | ||
|
|
||
| type Main = { | ||
| managerHead: (head: string) => string; | ||
| } & StorybookConfig; | ||
|
|
||
| const main: Main = { | ||
| stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], | ||
| addons: ['@storybook/addon-essentials', '@storybook/addon-a11y', '@storybook/addon-react-native-web'], | ||
| staticDirs: ['./public', {from: '../assets/css', to: 'css'}, {from: '../assets/fonts/web', to: 'fonts'}], | ||
| core: { | ||
| builder: 'webpack5', | ||
| }, | ||
| managerHead: (head) => ` | ||
| managerHead: (head: string) => ` | ||
| ${head} | ||
| ${process.env.ENV === 'staging' ? '<meta name="robots" content="noindex">' : ''} | ||
| `, | ||
| }; | ||
|
|
||
| export default main; | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* eslint-disable no-underscore-dangle */ | ||
|
|
||
| /* eslint-disable no-param-reassign */ | ||
|
|
||
| /* eslint-disable @typescript-eslint/naming-convention */ | ||
|
ruben-rebelo marked this conversation as resolved.
Resolved
|
||
| import dotenv from 'dotenv'; | ||
| import path from 'path'; | ||
| import {DefinePlugin} from 'webpack'; | ||
| import type {Configuration, RuleSetRule} from 'webpack'; | ||
|
|
||
| type CustomWebpackConfig = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you check if there is already some
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are already using Configuration from webpack. CustomWebpackConfig was created to workaround some type issues, without this type we would need to have a lot of condition to TS comply with the correct typing. |
||
| resolve: { | ||
| alias: Record<string, string>; | ||
| extensions: string[]; | ||
| }; | ||
| module: { | ||
| rules: RuleSetRule[]; | ||
| }; | ||
| }; | ||
|
|
||
| let envFile: string; | ||
| switch (process.env.ENV) { | ||
| case 'production': | ||
| envFile = '.env.production'; | ||
| break; | ||
| case 'staging': | ||
| envFile = '.env.staging'; | ||
| break; | ||
| default: | ||
| envFile = '.env'; | ||
| } | ||
|
|
||
| const env = dotenv.config({path: path.resolve(__dirname, `../${envFile}`)}); | ||
| const custom: CustomWebpackConfig = require('../config/webpack/webpack.common')({ | ||
| envFile, | ||
| }); | ||
|
|
||
| const webpackConfig = ({config}: {config: Configuration}) => { | ||
| if (config.resolve && config.plugins && config.module) { | ||
| config.resolve.alias = { | ||
| 'react-native-config': 'react-web-config', | ||
| 'react-native$': 'react-native-web', | ||
| '@react-native-community/netinfo': path.resolve(__dirname, '../__mocks__/@react-native-community/netinfo.ts'), | ||
| '@react-navigation/native': path.resolve(__dirname, '../__mocks__/@react-navigation/native'), | ||
| ...custom.resolve.alias, | ||
| }; | ||
|
|
||
| // Necessary to overwrite the values in the existing DefinePlugin hardcoded to the Config staging values | ||
| const definePluginIndex = config.plugins.findIndex((plugin) => plugin instanceof DefinePlugin); | ||
| if (definePluginIndex !== -1 && config.plugins[definePluginIndex] instanceof DefinePlugin) { | ||
| const definePlugin = config.plugins[definePluginIndex] as DefinePlugin; | ||
| if (definePlugin.definitions) { | ||
| definePlugin.definitions.__REACT_WEB_CONFIG__ = JSON.stringify(env); | ||
| } | ||
| } | ||
| config.resolve.extensions = custom.resolve.extensions; | ||
|
|
||
| const babelRulesIndex = custom.module.rules.findIndex((rule) => rule.loader === 'babel-loader'); | ||
| const babelRule = custom.module.rules[babelRulesIndex]; | ||
| if (babelRule) { | ||
| config.module.rules?.push(babelRule); | ||
| } | ||
|
|
||
| const fileLoaderRule = config.module.rules?.find( | ||
| (rule): rule is RuleSetRule => | ||
| typeof rule !== 'boolean' && typeof rule !== 'string' && typeof rule !== 'number' && !!rule?.test && rule.test instanceof RegExp && rule.test.test('.svg'), | ||
| ); | ||
| if (fileLoaderRule) { | ||
| fileLoaderRule.exclude = /\.svg$/; | ||
| } | ||
| config.module.rules?.push({ | ||
| test: /\.svg$/, | ||
| enforce: 'pre', | ||
| loader: require.resolve('@svgr/webpack'), | ||
| }); | ||
| } | ||
|
|
||
| return config; | ||
| }; | ||
|
|
||
| export default webpackConfig; | ||
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.
Also for this there is a built in type
import { StorybookConfig } from '@storybook/core-common';