Skip to content

Commit

Permalink
fix: getDefaultLibFilePath should normalize __dirname (#49051)
Browse files Browse the repository at this point in the history
- this currently causes a bug on Windows with mixed path separators
  - it returns a POSIX backslash path for __dirname, and then adds a
    forward slash from the directorySeparator, causing mixed separators
    - TS uses `/` internally and lets the host convert if needed, so
      I assume this should be normalized to all forward slashses instead
  - example of the bug from my tests:
    ```
    Expected: "D:\\a\\rollup-plugin-typescript2\\rollup-plugin-typescript2\\node_modules\\typescript\\lib\\lib.d.ts"
    Received: "D:\\a\\rollup-plugin-typescript2\\rollup-plugin-typescript2\\node_modules\\typescript\\lib/lib.d.ts"
    ```

- every other use of __dirname in the codebase seems to be normalized
  except for this one
  - could use normalizeSlashes for this, but I figure combinePaths is
    more appropriate since that will handle it and combine properly as
    well without any `+ directorySeparator +` stuff
  • Loading branch information
agilgur5 authored May 12, 2022
1 parent 1ba6096 commit da00ba6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2880,7 +2880,7 @@ namespace ts {
export function getDefaultLibFilePath(options: CompilerOptions): string {
// Check __dirname is defined and that we are on a node.js system.
if (typeof __dirname !== "undefined") {
return __dirname + directorySeparator + getDefaultLibFileName(options);
return combinePaths(__dirname, getDefaultLibFileName(options));
}

throw new Error("getDefaultLibFilePath is only supported when consumed as a node module. ");
Expand Down

0 comments on commit da00ba6

Please sign in to comment.