microsoft / microsoft/TypeScript
Exposing canonical filename logic
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms
canonical filename
Suggestion
I'd like to re-use the get-canonical-filename logic:
https://github.com/microsoft/TypeScript/blob/d68295e74e4897f588e73edf72089eb238904f02/src/compiler/core.ts#L1906-L1909
Use Cases
I want to use ts.resolveModuleName and the accompanying ts.createModuleResolutionCache to resolve ImportDeclarations (as per this comment's suggestion).
createModuleResolutionCache requires a parameter getCanonicalFileName. I think it makes the most sense to use the same logic as the compiler itself here, which is the function I linked above.
I could just copy-and-paste this function, but that feels wrong and might lead to discrepancies in the future if toFileNameLowerCase (which is not exposed either) is ever updated.
Examples
const cache = ts.createModuleResolutionCache(currentDirectory, ts.createGetCanonicalFileName(true/false));
const resolved = ts.resolveModuleName(name, file, compilerOptions, host, cache);
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the canonical filename logic at src/compiler/core.ts lines 1906-1909 and inspect the createModuleResolutionCache entry point. Compare it with toFileNameLowerCase, also linked in the issue, and determine the public helper shape needed by the example. Done means consumers can reuse the compiler's canonical filename behavior for module resolution without copying the logic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, compilers
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100