forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Expensify#37771 from ruben-rebelo/ts-migration/sto…
…rybook [No QA][TS migration] Migrate Storybook files
- Loading branch information
Showing
6 changed files
with
107 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
import dotenv from 'dotenv'; | ||
import path from 'path'; | ||
import {DefinePlugin} from 'webpack'; | ||
import type {Configuration, RuleSetRule} from 'webpack'; | ||
|
||
type CustomWebpackConfig = { | ||
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; |