-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: Remove baseUrl from tsconfig #505
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
Merged
kingston
merged 1 commit into
main
from
kingston/eng-637-remove-baseurl-from-tsconfig-and-make-ui-components-to-use
Apr 21, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@halfdomelabs/fastify-generators': patch | ||
| '@halfdomelabs/react-generators': patch | ||
| --- | ||
|
|
||
| Remove baseUrl from tsconfig.json since it is no longer necessary and ensure better consistency with imports |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/project-builder-server/src/plugins/node-plugin-store.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
💡 Verification agent
🧩 Analysis chain
Verify
pathsmapping without an explicitbaseUrl.TypeScript’s
pathsfeature generally requires abaseUrlto resolve non-relative imports. Since you’ve removedbaseUrlhere, please confirm that the extended config (@halfdomelabs/tools/tsconfig.node.cli.json) still defines it; otherwise, you may encounter TS5028 errors at build time. If it isn’t defined downstream, consider reintroducing:"compilerOptions": { + "baseUrl": ".", "outDir": "dist", "paths": { "@src/*": ["./src/*"] } }to ensure module aliases are resolved correctly.
To verify, you can run:
🏁 Script executed:
Length of output: 45
🏁 Script executed:
Length of output: 617
Add a
baseUrlto enable yourpathsmappingWe’ve confirmed that
packages/tools/tsconfig.node.cli.jsondoes not define abaseUrl. Since TypeScript requiresbaseUrlwhenever you usepaths, you will encounter TS5028 errors at build time.Please update
packages/create-project/tsconfig.jsonto include:"compilerOptions": { + "baseUrl": ".", "outDir": "dist", "paths": { "@src/*": ["./src/*"] } }This ensures
@src/*resolves correctly.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.
That is actually inaccurate. You do not need a baseUrl to enable paths mapping since Typescript 4.1. The point of this PR is to remove the baseURL to ensure that we don't allow bare paths in imports e.g. node_modules/random_package.
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.
🧩 Analysis chain
@kingston You're absolutely right, and I apologize for the incorrect information. TypeScript 4.1+ indeed supports paths mapping without baseUrl when using relative paths (with "./").
The approach in your PR makes perfect sense - removing baseUrl while updating path mappings to use explicit relative paths (
"./src/*") accomplishes your goal of preventing bare path imports while maintaining the alias functionality.Thank you for the clarification about the purpose of this change!
🌐 Web query:
💡 Result:
TypeScript 4.1:
pathsMapping WithoutbaseUrlOverview
Starting with TypeScript 4.1, you can use the
pathsoption in yourtsconfig.jsonwithout specifying abaseUrl. This change removed a long-standing restriction and simplified path mapping for TypeScript projects[2][4][5].Previous Behavior
Prior to TypeScript 4.1, if you tried to use the
pathsoption without abaseUrl, the compiler would throw an error:This meant that any path mapping required you to set
baseUrl, usually to either"./"or another root-relative directory.What's Changed in TypeScript 4.1?
baseUrlRequirement:With TypeScript 4.1 and later, you can specify
pathsmappings without definingbaseUrlin yourtsconfig.json.If
baseUrlis not set, the project directory (wheretsconfig.jsonis located) is used as the base for resolving paths[1][4].This update also improved the auto-import suggestions in editors like VS Code, aligning import paths more closely with your intended mappings[1].
Example Configuration
{ "compilerOptions": { "paths": { "@utils/*": ["src/utils/*"], "@components/*": ["src/components/*"] } } }With this configuration (and no
baseUrl),@utils/foowill resolve tosrc/utils/foorelative to the project root[4].References in Official Documentation
baseUrlis no longer required forpaths[2][5].Summary Table
baseUrlRequired forpaths?In Practice
If you want to use
pathsmappings as of TypeScript 4.1 or later, you may safely omitbaseUrlfrom your configuration. TypeScript will resolve the mappings from the directory containing yourtsconfig.json, improving both developer experience and configuration flexibility[1][2][4][5].Citations:
pathscompilerOption withoutbaseUrlmicrosoft/TypeScript#31869@kingston Thank you for correcting me! You're absolutely right - since TypeScript 4.1, path mappings can be used without specifying baseUrl. The web search confirms that when
baseUrlis omitted, TypeScript resolves paths relative to the project directory (where tsconfig.json is located).Your approach of removing baseUrl while updating paths to use explicit relative paths (
"./src/*") perfectly achieves the goal of preventing bare path imports likenode_modules/random_packagewhile maintaining the path alias functionality.I appreciate you sharing this knowledge about TypeScript's behavior!
✏️ Learnings added