-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat(config): allow imports from local workspace tsconfig paths (#5370) #17286
Conversation
|
I'm not entirely sure why the windows-latest build is failing; doesn't seem to be related to my changes. Edit to add: It's running out of memory in the unit tests. I've run the tests on a Windows 10 machine and Node 20, and all tests pass. |
41431a7
to
8c947cb
Compare
That's better - all tests passing now 🥳 It's worth pointing out that I have created an Nx workspace with my patched version of Vite, to demonstrate how a shared config file can be imported and extended - https://github.com/garydex/nx-vite-tsconfig-paths |
Vite doesn't respect the tsconfig paths today, hence I don't think we should fix the problem this way. Similarly in #6828 where we had discussed and decided that we don't want to have builtin support for it. Tsconfig paths describes the (Vite) runtime and doesn't define it. Sorry for not reviewing this earlier before. |
I appreciate the response. A few points:
The issue you mentioned is about resolving tsconfig paths across the entirety of Vite. This isn't trying to do that, or replicate/replace vite-tsconfig-paths or similar plugins. It's specific to config, and only executes if there's a tsconfig file that has paths in the codebase. The other advantage of using the tsconfig paths in this context is that it I actually think we may need both this and #17323 - while that PR may fix imports with npm/yarn workspaces, it still doesn't work in a repo that uses tsconfig paths, such as an Nx workspace. |
The config loading is part of the "experience" of using Vite, so that issue is relevant here too. We can't have tsconfig paths sometimes work here but not there when they work in a Vite project. |
Fair point, though I do think it's an equally jarring experience for users who can easily get tsconfig paths to work everywhere in their code except the config file. I understand it's via plugins and out of the scope of Vite itself - but ideally one would be able to at least opt-in for something like this. |
resolvedPath: string, | ||
): Promise<string[]> { | ||
const { tsconfig } = await parse(resolvedPath) | ||
const paths = tsconfig?.compilerOptions?.paths || {} |
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.
How about using the ?? operator instead of ||?
I think ?? would be more appropriate in this context.
if (!tsConfigPaths.length) { | ||
return false | ||
} |
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.
Since Array.prototype.some always returns false when called on an empty array, the tsConfigPaths.length check is unnecessary.
Related #16718 Closing this as it's not something we want to support in the config. |
Description
Fixes #5370 nrwl/nx#17019 remix-run/remix#9171
Uses existing
tsconfck
dependency to loads the nearest tsconfig file if it exists, grabs anypaths
fromcompilerOptions
and then makes sure these are not caught by theexternalise-deps
plugin when resolving imports in the config file.This functionality is isolated to
loadConfigFromFile
so does not need to replicate functionality fromtsconfig-paths
or similar, nor does it duplicate any existing plugins likevite-tsconfig-paths
or@esbuild-plugins/tsconfig-paths
.