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 setting baseUrl to root directory #7755

Merged
merged 1 commit into from Oct 2, 2019
Merged

Support setting baseUrl to root directory #7755

merged 1 commit into from Oct 2, 2019

Conversation

rovansteen
Copy link
Contributor

@rovansteen rovansteen commented Sep 30, 2019

This PR adds support for setting the baseUrl in tsconfig.json/jsconfig.json to the root directory (.).

Initially I planned to add support for aliases but that turned out to be quite difficult due to difference in implementation between webpack and TypeScript. Instead this PR aims to facility the most requested option to import files with their absolute path (as seen from root) like src/components/Button.js. (#6850)

We don't want users to import from any directory other than src so the implementation maps a baseUrl of . to an alias that transforms src to the absolute appSrc directory. This should prevent users from doing something like import { something } from 'library/utils.js'.

  • Update error message to communicate that . is allowed as baseUrl

@iansu iansu added this to In progress in v3.3 via automation Sep 30, 2019
@iansu iansu added this to the 3.2 milestone Sep 30, 2019
@rovansteen
Copy link
Contributor Author

Are there any known issues with the CI right now? Some of the failures (FetchError: request to http://localhost:4873/prefix failed, reason: connect ECONNREFUSED 127.0.0.1:4873) seem unrelated to the changes in this PR.

@mrmckeb
Copy link
Contributor

mrmckeb commented Oct 1, 2019

Trying to fix CI.

@mrmckeb mrmckeb closed this Oct 1, 2019
v3.3 automation moved this from In progress to Done Oct 1, 2019
@mrmckeb mrmckeb reopened this Oct 1, 2019
v3.3 automation moved this from Done to In progress Oct 1, 2019
@mrmckeb
Copy link
Contributor

mrmckeb commented Oct 1, 2019

@rovansteen So at this stage we're not allowing people to configure aliases - maybe we can talk about that this week some more.

I personally don't like aliases, but a lot of people love them... so it would be cool to get them in.

@rovansteen
Copy link
Contributor Author

@mrmckeb I agree, but I haven't had the time yet to properly research how aliases work in TypeScript as I have never used them personally.

However this PR shouldn't get in the way of any future work on proper alias support, we just use aliases behind the scenes to prevent users from importing from any other directory than src.

@mrmckeb mrmckeb modified the milestones: 3.3, 3.2 Oct 1, 2019
@mrmckeb mrmckeb merged commit 7e2b6b1 into facebook:master Oct 2, 2019
v3.3 automation moved this from In progress to Done Oct 2, 2019
@rovansteen rovansteen deleted the baseurl-root branch October 3, 2019 09:24
@lock lock bot locked and limited conversation to collaborators Oct 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
v3.3
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants