Skip to content

Conversation

sheetalkamat
Copy link
Member

@sheetalkamat sheetalkamat commented Apr 2, 2024

  • ${configDir} on any paths is replced with config files directory instead of making it relative to file its declared in.
  • This is allowed on all the isFilePath options, paths, files, include and exclude
  • Not allowed to pass from command line

7b1a848 is just tests change
9fcd0d6 actual change

Fixes #57485

TODO:
Actual string to use for replacement from design meeting:

  • configLocation
  • configFolder
  • configDirectory
  • projectLocation
  • projectFolder
  • projectDirectory

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Apr 2, 2024
Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a --showConfig on a config with paths like these show the input ${configDir} or the resolved disk paths?

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...Do we need to allow escaping $ so you can actually use a $ in a path, rather than as one of these templates? Like if I (somehow - the character is forbidden on NTFS) had an actual directory named ${configDir} - how do you escape from the pattern back to a literal interpretation?

@sheetalkamat
Copy link
Member Author

Does a --showConfig on a config with paths like these show the input ${configDir} or the resolved disk paths?

https://github.com/microsoft/TypeScript/pull/58042/files#diff-dfa255ce269b3c80a416b7c133db82a20292076b8c53370637b1aeaff7b8e7f3R110 shows resolved path and i think its useful to show it like that.

@sheetalkamat
Copy link
Member Author

...Do we need to allow escaping $ so you can actually use a $ in a path, rather than as one of these templates? Like if I (somehow - the character is forbidden on NTFS) had an actual directory named ${configDir} - how do you escape from the pattern back to a literal interpretation?

Not sure. i think we should keep this simple as otherwise we need to ensure all the paths are normalized to contain escaped $ we can choose other template pattern as well its a TODO but we shouldnt have to do escaping

@@ -1034,6 +1037,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
name: "paths",
type: "object",
affectsModuleResolution: true,
allowConfigDirTemplateSubstitution: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long term, I do wonder if we'll need some other flag here given we'll introduce more substitutions, but thankfully this is internal!

@sheetalkamat sheetalkamat merged commit cbae6cf into main Apr 16, 2024
@sheetalkamat sheetalkamat deleted the configDir branch April 16, 2024 23:25
Boshen added a commit to oxc-project/oxc-resolver that referenced this pull request Apr 23, 2024
…mpilerOptions.paths

closes #129

NOTE: All tests cases are just a head replacement of `${configDir}`, so we are constrained as such.

Reference: microsoft/TypeScript#58042
Boshen added a commit to oxc-project/oxc-resolver that referenced this pull request Apr 23, 2024
…mpilerOptions.paths

closes #129

NOTE: All tests cases are just a head replacement of `${configDir}`, so we are constrained as such.

Reference: microsoft/TypeScript#58042
@zhangzhuang15
Copy link

@sheetalkamat It's a good feature of ${configDir}, but it's not perfect. Using ${configDir}, we can make paths more simple, avoid trapping into black hole of relative path, such as "@root/*" : ["../../../../../a/b/c/*"]. Unfortunately, we still trap into this black hole when we config extends. I suggest that we should bring a template variable or a method, let user set it a path, and user can apply it into tsconfig.json or tell typescript figure it out. For example:

/a/b/tsconfig.variables.json:

{
  "root": "./"
}

now, ${root} refers to /a/b/, and it can be shared in all tsconfig.json under /a/b/, such as /a/b/**/tsconfig.json;

/a/b/c/tsconfig.json:

{
  "compilerOptions": {
    "paths": {
        "@root/*": ["${root}/*"]
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add template variable ${configDir} (name to be determined) for file path substitution
6 participants