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

♻️ Support absolute import paths #34264

Closed
wants to merge 16 commits into from

Conversation

rcebulko
Copy link
Contributor

@rcebulko rcebulko commented May 6, 2021

Adopts an alias configuration very similar to NuxtJS:

  • @/ maps to the project root (import {dev, user} from '@/src/log')
  • @@/ maps to shared core (import {dict} from '@@/types/object')

NuxtJS provides 4 standard aliases: @@ and ~~ map to the project root; @ and ~ map to the core source directory. I'm open to either convention, or bikeshedding something else.

Eliminates long strings of '../../../..' (and by extension makes it easier to refactor and move files since imports won't need updating)

@rcebulko rcebulko requested a review from jridgewell May 6, 2021 20:39
@amp-owners-bot
Copy link

amp-owners-bot bot commented May 6, 2021

Hey @alanorozco! These files were changed:

build-system/tasks/storybook/amp-env/webpack.config.js
build-system/tasks/storybook/preact-env/webpack.config.js

Hey @jridgewell! These files were changed:

src/core/assert/base.js
src/core/assert/dev.js
src/core/assert/user.js
src/core/constants/action-constants.js
src/core/data-structures/signals.js
src/core/dom/css.js
src/core/error-message-helpers.js

Copy link
Member

@samouri samouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated import statements look lovely!

Unfortunately, it is unclear to me that this is a net-positive.

  1. It adds a level of indirection. Just another item which is strange about AMP's build system.
  2. Do you know if "Click to Definition" will still work in IDEs? This is a huge convenience while working on the codebase and I'd hate to lose it for shorter lines.

@kristoferbaxter
Copy link
Contributor

I too am a bit mixed for the same reasons Jake mentioned. Would like to hear others thoughts though.

@lgtm-com
Copy link

lgtm-com bot commented May 6, 2021

This pull request fixes 7 alerts when merging 7206e5d into a8895fa - view on LGTM.com

fixed alerts:

  • 7 for Useless conditional

@rcebulko
Copy link
Contributor Author

rcebulko commented May 7, 2021

  1. It adds a level of indirection. Just another item which is strange about AMP's build system.

@samouri For a more "normal" feel, WDYT about if we used something like @amp/core which would feel more like importing from packages?

  1. Do you know if "Click to Definition" will still work in IDEs? This is a huge convenience while working on the codebase and I'd hate to lose it for shorter lines.

This part I do not know offhand and didn't consider. My editor indexes by symbol without using import paths, but perhaps vscode is different?
Edit: VSCode has built-in support via jsconfig.js for aliasing absolute import paths in this way

@lgtm-com
Copy link

lgtm-com bot commented May 7, 2021

This pull request fixes 7 alerts when merging 1690c8b into 2e762f0 - view on LGTM.com

fixed alerts:

  • 7 for Useless conditional

@@ -20,12 +20,14 @@ module.exports = ({config}) => {
modules: [
path.join(__dirname, '../node_modules'),
path.join(__dirname, '../../../../node_modules'),
path.join(__dirname, '../../../..'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FMI: Does the Webpack config need to be updated somehow? Can Storybook still get files from src/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm understanding your question correctly, yes, Storybook should be able to use absolute imports as well

@rcebulko rcebulko changed the title ♻️ Enable import mapping in development ♻️ Support absolute import paths May 7, 2021
@rcebulko rcebulko marked this pull request as draft May 7, 2021 16:23
@lgtm-com
Copy link

lgtm-com bot commented May 7, 2021

This pull request fixes 7 alerts when merging f9631c3 into fdad648 - view on LGTM.com

fixed alerts:

  • 7 for Useless conditional

@lgtm-com
Copy link

lgtm-com bot commented May 7, 2021

This pull request fixes 7 alerts when merging a38ba07 into df5b6a1 - view on LGTM.com

fixed alerts:

  • 7 for Useless conditional

@rcebulko rcebulko marked this pull request as ready for review May 7, 2021 20:00
@samouri
Copy link
Member

samouri commented May 7, 2021

Writing to confirm that the jsconfig did alleviate my concerns with VS Code!

@lgtm-com
Copy link

lgtm-com bot commented May 7, 2021

This pull request fixes 7 alerts when merging adfbdb1 into df5b6a1 - view on LGTM.com

fixed alerts:

  • 7 for Useless conditional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants