You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
would resolve @database as '^@database/(.*)$': '/path/to/monorepo/packages/package_1/prisma/$1' when loading from package_1/tsconfig.json.
I know it would be much more easier to just defined @database at tsconfig.json package level but unfortunately TS does not let extend the compilerOptions.paths property with the root one, it overwrites it...
The text was updated successfully, but these errors were encountered:
mister-good-deal
changed the title
[Feature]: handle ${configDir} TS template var in pathsToModuleNameMapper
[Feature]: handle ${configDir} TS template var in compilerOptions.paths
Jan 25, 2025
As a workaround, if someone encounter this issue, here is a build script i'm using to replace ${configDir} using esbuild tsconfigRaw property with custom made tsconfig.json.
build.mjs
importesbuildfrom"esbuild";importpathfrom"node:path";import{fileURLToPath}from"node:url";importbaseTsConfigfrom"../../../tsconfig.base.json"with{type: "json"};importprojectTsConfigfrom"../tsconfig.json"with{type: "json"};const__dirname=path.dirname(fileURLToPath(import.meta.url));constPROJECT_ROOT=path.resolve(__dirname,"..");constMONOREPO_ROOT=path.resolve(PROJECT_ROOT,"../..");// Process paths to use absolute pathsconstprocessedPaths=Object.fromEntries(Object.entries(baseTsConfig.compilerOptions.paths).map(([key,value])=>[key,value.map(configPath=>{// Handle ${configDir} replacementif(configPath.includes("${configDir}"))returnconfigPath.replace("${configDir}",PROJECT_ROOT);// Handle @monorepo/* pathsif(key.startsWith("@monorepo/"))returnpath.resolve(MONOREPO_ROOT,configPath);returnconfigPath;})]));// Merge configurationsconstmergedConfig={
...baseTsConfig,
...projectTsConfig,compilerOptions: {
...baseTsConfig.compilerOptions,
...projectTsConfig.compilerOptions,paths: processedPaths,baseUrl: MONOREPO_ROOT},extends: undefined// Remove the extends field as it's not needed in the final configuration};awaitesbuild.build({entryPoints: [`${PROJECT_ROOT}/src/index.ts`],bundle: true,platform: "node",target: "node23",format: "esm",outdir: `${PROJECT_ROOT}/dist`,tsconfigRaw: JSON.stringify(mergedConfig),resolveExtensions: [".ts",".js",".mjs",".json"],nodePaths: [MONOREPO_ROOT],banner: {js: ` import { createRequire } from 'module'; import { fileURLToPath } from 'url'; import { dirname } from 'path'; const require = createRequire(import.meta.url); const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); `}});
🚀 Feature Proposal
In TS v5.5, there is a new template var
${configDir}
incompilerOptions.paths
definition see official docEsbuild should handle it and replace this var with the correct path value.
Motivation
Keep being updated with TS standard
Example
The following project monorepo structure
with a defined tsconfig.base.json
would resolve
@database
as'^@database/(.*)$': '/path/to/monorepo/packages/package_1/prisma/$1'
when loading frompackage_1/tsconfig.json
.I know it would be much more easier to just defined
@database
attsconfig.json
package level but unfortunately TS does not let extend thecompilerOptions.paths
property with the root one, it overwrites it...The text was updated successfully, but these errors were encountered: