-
-
Notifications
You must be signed in to change notification settings - Fork 51
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 for ${configDir} syntax #156
Comments
I had the same problem in my monorepo and was forced to fall back to Vite resolve aliases: Base tsconfig.json:
Local tsconfig.json
Local vite.config.ts:
|
Sharing my workaround for my use case. I am only using vitest for a back-end monorepo. I have several packages with multiple aliases (all declared globally in a base tsconfig). Discovered that order matters (e.g., Not wanting to enforce a string order in my tsconfig, I resorted to just importing the tsconfig and clamping each alias with a regex. This doesn't account for wildcards, so if you need those, additional work will be needed. Also does not follow project references or support alias reuse (e.g., import path from 'path';
import tsconfig from './tsconfig.base.json';
const alias = Object.entries(tsconfig.compilerOptions.paths).map(([module, modulePath]) => ({
find: new RegExp(`^${module}$`),
replacement: path.resolve(import.meta.dirname, modulePath[0]),
})); edit: This could be a separate issue also. Been using |
+1 - I ran into this as well |
This was added upstream in dominikg/tsconfck#172. Try refreshing your lockfile and let me know if it works already. If it doesn't work, find |
Same issue. Installed version of tsconfck is 3.1.4. Tracked the issue, here is my findings : Setup/home/[redacted]/workspace/tsconfig.base.json (excerpt) : "include": ["${configDir}/app", "${configDir}/gen"],
"compilerOptions": {
"paths": {
"~/*": ["${configDir}/app/*"],
"~gen/*": ["${configDir}/gen/*"]
}
} /home/[redacted]/workspace/apps/accounts/tsconfig.json : {"extends": "../../tsconfig.base.json"} /home/[redacted]/workspace/apps/accounts/app/routes/_auth.tsx includes ~/gen/types (which resolves to /home/[redacted]/workspace/apps/accounts/gen/types/index.ts). Note that tsc has no issue with the setup, the error arises when building with vite. The issueThe isIncludedRelative test fails (https://github.com/aleclarson/vite-tsconfig-paths/blob/master/src/index.ts#L320) : if(id === "~gen/types") console.log({id, project: project.tsconfigFile, baseUrl, paths, configDir, importerFile, relativeImporterFile, included: isIncludedRelative(relativeImporterFile), include: config.includ, include: config.include}); {
id: '~gen/types',
project: '/home/[redacted]/workspace/apps/accounts/tsconfig.json',
baseUrl: undefined,
paths: {
'~/*': [ '/home/[redacted]/workspace/apps/accounts/app/*' ],
'~gen/*': [ '/home/[redacted]/workspace/apps/accounts/gen/*' ]
},
configDir: '/home/[redacted]/workspace/apps/accounts',
importerFile: '/home/[redacted]/workspace/apps/accounts/app/routes/_auth.tsx',
relativeImporterFile: 'app/routes/_auth.tsx',
included: false,
include: [
'/home/[redacted]/workspace/apps/accounts/app',
'/home/[redacted]/workspace/apps/accounts/gen'
]
} The issue is that the globs are absolute, not relative : if(path2 === "./app/routes/_auth.tsx") console.log({path2, includers}); {
path2: './app/routes/_auth.tsx',
includers: [
/^\.\/?\/home\/[redacted]\/workspace\/apps\/accounts\/app\/((?:[^/]*(?:\/|$))*)$/,
/^\.\/?\/home\/[redacted]\/workspace\/apps\/accounts\/gen\/((?:[^/]*(?:\/|$))*)$/
]
} The fixReplacing const isIncludedRelative = getIncluder(
config.include,
config.exclude,
outDir
) with const isIncludedRelative = getIncluder(
config.include.map(path => relative(configDir, path)),
config.exclude.map(path => relative(configDir, path)),
outDir
) Fixed the issue for me. |
Great sleuthing, @sloonz! 👏 Fixed in v5.1.1 |
Since typescript 5.5, it is possible to use the ${configDir} variable inside
include
/exclude
clauses to reference the directory path where the current tsconfig is located, but unfortunately vite-tsconfig-paths does not support this feature yet, so path aliases are not set when using it.Example
If I remove the
"include": ["src"]
at the end oftsconfig.app.json
, the path aliases stop working in vite, but it shouldn't since${configDir)/src
expands to./src
The text was updated successfully, but these errors were encountered: