Skip to content
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

refactor: switch to using @/ for in-app imports #1170

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

tackley
Copy link
Collaborator

@tackley tackley commented Apr 23, 2024

Use @/name for app imports, as opposed to just name as previously. This is the modern convention for web apps, and makes clearer when imports are coming from the application as opposed to npm modules.

There's a few deep ../../ style imports remaining - these get worse if I move them to @/-style imports, and I think are better left until we move the files around a bit more in a subsequent PR.

Use `@/name` for app imports, as opposed to just `name` as previously. This is the modern convention for web apps, and makes clearer when imports are coming from the application as opposed to npm modules.

There's a few deep `../../` style imports remaining - these get worse if I move them to `@/`-style imports, and I think are better left until we move the files around a bit more in a subsequent PR.
@tackley tackley requested a review from a team as a code owner April 23, 2024 08:01
Copy link

[puLL-Merge] - brave/ads-ui@1170

Here is my review of the pull request:

Description

This PR updates import statements throughout the codebase to use absolute imports with a @ alias pointing to the src directory. This allows importing modules using a consistent syntax like import { Foo } from "@/path/to/Foo" rather than relative paths like import { Foo } from "../../path/to/Foo".

Changes

Changes

  • tsconfig.json: Adds a paths configuration to map the @ alias to the src directory.
  • All files under src: Updates import statements to use the @ absolute import alias instead of relative import paths.

Security Hotspots

No obvious security issues. The changes are limited to updating import statements which should not introduce any vulnerabilities.

The use of absolute imports with an alias has a few benefits:

  1. Makes import statements more readable and consistent
  2. Avoids issues with long and hard to follow relative import paths
  3. Allows easily moving files around without having to update many relative imports

Overall this is a straightforward refactor that improves the developer experience without changing any functionality. The changes look good to me and I would approve this PR.

Let me know if you have any other questions!

@tackley tackley merged commit 7fe5577 into master Apr 24, 2024
8 checks passed
@tackley tackley deleted the refactor/use-modern-paths branch April 24, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants