Skip to content

Commit

Permalink
import alias config
Browse files Browse the repository at this point in the history
  • Loading branch information
b4s36t4 committed Oct 28, 2023
1 parent 70900ae commit 419e077
Show file tree
Hide file tree
Showing 8 changed files with 449 additions and 93 deletions.
25 changes: 24 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const restrictedImportPatterns = [
];

module.exports = {
extends: ['expensify', 'plugin:storybook/recommended', 'plugin:react-hooks/recommended', 'plugin:react-native-a11y/basic', 'prettier'],
extends: ['expensify', 'plugin:storybook/recommended', 'plugin:react-hooks/recommended', 'plugin:react-native-a11y/basic', 'plugin:@dword-design/import-alias/recommended', 'prettier'],
plugins: ['react-hooks', 'react-native-a11y'],
parser: 'babel-eslint',
ignorePatterns: ['!.*', 'src/vendor', '.github/actions/**/index.js', 'desktop/dist/*.js', 'dist/*.js', 'node_modules/.bin/**', 'node_modules/.cache/**', '.git/**'],
Expand All @@ -49,8 +49,31 @@ module.exports = {
touchables: ['PressableWithoutFeedback', 'PressableWithFeedback'],
},
],
'@dword-design/import-alias/prefer-alias': [
'warn',
{
alias: {
'@assets': './assets',
'@components': './src/components',
'@hooks': './src/hooks',
// This is needed up here, if not @libs/actions would take the priority
'@userActions': './src/libs/actions',
'@libs': './src/libs',
'@navigation': './src/libs/Navigation',
'@pages': './src/pages',
'@styles': './src/styles',
// This path is provide alias for files like `ONYXKEYS` and `CONST`.
'@src': './src',
},
},
],
},
},
// This helps disable the `prefer-alias` rule to be enabled for specific directories
{
files: ['tests/**/*.js', 'tests/**/*.ts', 'tests/**/*.jsx', 'assets/**/*.js', '.storybook/**/*.js'],
rules: {'@dword-design/import-alias/prefer-alias': ['off']},
},
{
files: ['*.js', '*.jsx'],
settings: {
Expand Down
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ module.exports = {
arrowParens: 'always',
printWidth: 190,
singleAttributePerLine: true,
importOrder: ['@assets/(.*)$', '@components/(.*)$', '@hooks/(.*)$', '@libs/(.*)$', '@navigation/(.*)$', '@pages/(.*)$', '@styles/(.*)$', '@userActions/(.*)$', '@src/(.*)$', '^[./]'],
importOrderSortSpecifiers: true,
importOrderCaseInsensitive: true,
};
3 changes: 3 additions & 0 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ module.exports = ({config}) => {
'react-native-web': '@expensify/react-native-web',
'@react-native-community/netinfo': path.resolve(__dirname, '../__mocks__/@react-native-community/netinfo.js'),
'@react-navigation/native': path.resolve(__dirname, '../__mocks__/@react-navigation/native'),

// Module alias support for storybook files, coping from `webpack.common.js`
...custom.resolve.alias,
};

// Necessary to overwrite the values in the existing DefinePlugin hardcoded to the Config staging values
Expand Down
36 changes: 36 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,42 @@ const metro = {
['@babel/plugin-proposal-private-property-in-object', {loose: true}],
// The reanimated babel plugin needs to be last, as stated here: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation
'react-native-reanimated/plugin',
// Import alias for native devices
[
'module-resolver',
{
extensions: [
'.native.js',
'.native.jsx',
'.native.ts',
'.native.tsx',
'.js',
'.jsx',
'.ts',
'.tsx',
'.ios.js',
'.ios.jsx',
'.ios.ts',
'.ios.tsx',
'.android.js',
'.android.jsx',
'.android.ts',
'.android.tx',
],
alias: {
'@assets': './assets',
'@components': './src/components',
'@hooks': './src/hooks',
'@libs': './src/libs',
'@navigation': './src/libs/Navigation',
'@pages': './src/pages',
'@styles': './src/styles',
// This path is provide alias for files like `ONYXKEYS` and `CONST`.
'@src': './src',
'@userActions': './src/libs/actions',
},
},
],
],
};

Expand Down
13 changes: 13 additions & 0 deletions config/webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,19 @@ const webpackConfig = ({envFile = '.env', platform = 'web'}) => ({
'react-native-web': '@expensify/react-native-web',
'react-content-loader/native': 'react-content-loader',
'lottie-react-native': 'react-native-web-lottie',

// Module alias for web & desktop
// https://webpack.js.org/configuration/resolve/#resolvealias
'@assets': path.resolve(__dirname, '../../assets'),
'@components': path.resolve(__dirname, '../../src/components/'),
'@hooks': path.resolve(__dirname, '../../src/hooks/'),
'@libs': path.resolve(__dirname, '../../src/libs/'),
'@navigation': path.resolve(__dirname, '../../src/libs/Navigation/'),
'@pages': path.resolve(__dirname, '../../src/pages/'),
'@styles': path.resolve(__dirname, '../../src/styles/'),
// This path is provide alias for files like `ONYXKEYS` and `CONST`.
'@src': path.resolve(__dirname, '../../src/'),
'@userActions': path.resolve(__dirname, '../../src/libs/actions/'),
},

// React Native libraries may have web-specific module implementations that appear with the extension `.web.js`
Expand Down
Loading

0 comments on commit 419e077

Please sign in to comment.