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 repo-root-relative import paths #319

Merged
merged 2 commits into from
Mar 15, 2021
Merged

Conversation

himdel
Copy link
Collaborator

@himdel himdel commented Mar 10, 2021

This adds resolve.alias to the webpack config, and compilerOptions.baseUrl + compilerOptions.paths to tsconfig,
allowing for JS/TS imports relative to the repository root (as long as they live under src/).

(The second commit just updates most imports, I skipped the ./ ones and only changed the ones with ../, can be trivially regenerated.)


Cc @newswangerd , @ZitaNemeckova WDYT? :)

Does it make sense to go with src as the alias? It fits the path so it seems like a reasonable default,
except there is a src npm package (we don't depend on it, and it's related to redis, so, unlikely in frontend JS), so we may want to consider something a bit more exotic like ^/src or @/src?

himdel added 2 commits March 10, 2021 22:06
… to repo root

for both webpack and typescript, this aliases src/... to resolve in the actual src/ dir in the repo root.

This allows for imports like..

    -import { UserType, UserAPI } from '../../api';
    +import { UserType, UserAPI } from 'src/api';

regardless of the requiree location
    cd src/
    perl -i -npe 's/from '\''\.\./from '\''src/' */*.*
    perl -i -npe 's/from '\''\.\.\/\.\./from '\''src/' */*/*.*
    perl -i -npe 's/from '\''\.\.\/\.\.\/\.\./from '\''src/' */*/*/*.*
Copy link
Member

@newswangerd newswangerd left a comment

Choose a reason for hiding this comment

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

this is fantastic!

@himdel himdel merged commit 9d8138f into ansible:master Mar 15, 2021
@himdel himdel deleted the alias branch March 15, 2021 16:59
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Feb 7, 2023
himdel added a commit that referenced this pull request Feb 8, 2023
* Drop more insights-related code

No-Issue

* npm run imports-to-relative, find-unused-exports, imports-to-src

and clean up unused exports

(#3178, #319)

* prettier: add plugin to sort imports

sort external imports first, then src/, then any relative paths
sort imports by source name, sort specifiers

bump prettier to 2.8
ensure app.scss goes before patternfly.scss

(#3198)

* npm run prettier

* sort index.ts exports

    perl -i -npe 's/^export/import/' src/**/index.ts
    npm run prettier
    perl -i -npe 's/^import/export/' src/**/index.ts
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.

2 participants