evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.58k stars 1.11k forks source link

Support for the new "${configDir}" template variable coming in TS v5.5.0 #3782

Closed fabiospampinato closed 3 weeks ago

fabiospampinato commented 1 month ago

In TS v5.5.0 a new ${configDir} template variables will be supported.

Trying to bundle a project that uses that variables in its tsconfig.json with the following command with esbuild@0.21.4:

esbuild --bundle --minify --format=esm --platform=node src/bin.ts > dist/bin.js  

Results in the following warnings:

▲ [WARNING] Non-relative path "${configDir}/src" is not allowed when "baseUrl" is not set (did you forget a leading "./"?) [tsconfig.json]

    node_modules/tsex/tsconfig.json:47:12:
      47 │       "~": ["${configDir}/src"],
         ╵             ~~~~~~~~~~~~~~~~~~

▲ [WARNING] Non-relative path "${configDir}/src/*" is not allowed when "baseUrl" is not set (did you forget a leading "./"?) [tsconfig.json]

    node_modules/tsex/tsconfig.json:48:14:
      48 │       "~/*": ["${configDir}/src/*"]
         ╵               ~~~~~~~~~~~~~~~~~~~~

2 warnings
evanw commented 3 weeks ago

Just looked into https://github.com/microsoft/TypeScript/pull/58042 a bit. It looks like as far as esbuild is concerned, this only affects baseUrl and paths. If the string starts with "${configDir}" (only at the start, not anywhere else), I need to replace that prefix with "./" and then resolve that into an absolute path relative to the directory containing the root-level tsconfig.json file. In particular, it looks like you don't need to use a slash after ${configDir} since "${configDir}/lib" becomes ".//lib" after this substitution. Hopefully I'm understanding everything correctly.

fabiospampinato commented 3 weeks ago

Yeah if there's something that should be done differently in your implementation I don't know what it is. Thanks 👍