-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
chore: enable absolute import paths #14556
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
base: main
Are you sure you want to change the base?
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
@joaoloureirop do we have linting on import orders? How does absolute imports fit in to the import order? E.g. will the ordering be: // Global imports
import { ... } from 'react-native'
// Absolute imports
import {...} from '~/foo'
// Relative imports
import {...} from '../bar' |
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.
Q: 2 questions:
- Is this ~ home syntax also available for mocking link in
jest.mock('../../../../util/Logger');
to bejest.mock('~/util/Logger');
? - is there any risk for the ~ to be mixed up with the user home ~ in shell commands or scripts?
I would order in terms of the relationship between components rather than by the import path format. // 3rd party packages
import { ... } from 'react-native'
// shared components
import {...} from '~/foo'
import { ... } from '../../../CommonView'
// feature components
import { ... } from '../../FeatureTextInput'
import { ... } from '~/hooks/Feature/useFeature' |
Good question. Jest might also need a config entry to resolve the aliases. e.g. "moduleNameMapper": {
"~/app/(.*)": "<rootDir>/app/$1"
},
These aliases are only applied on module paths that are resolved by the bundler through babel. It should not interfere with the shell |
Need to investigate why these code changes interfere with jest and Related issue: I'll consider mocking the function if no obvious solution is found |
Personally, I feel this approach tends to introduce more complexity than it resolves in most cases. A few concerns that come to mind at first glance:
For context, a similar proposal was made in the extension project and ultimately not pursued: That said, just my two cents. |
In fact, it is easier to refactor with import path aliases relative to the project root.
Agreed. The amount of extra setup required might outweigh the pros of custom path aliases. |
Description
https://reactnative.dev/docs/typescript#using-custom-path-aliases-with-typescript
Allow absolute import paths relative to project root dir.
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Can be refactored into
Pre-merge author checklist
Pre-merge reviewer checklist