Skip to content

Conversation

@agilgur5
Copy link
Contributor

Summary

Fixes a bug (#49050) where getDefaultLibFilePath returns mixed path separators on Windows

Details

  • 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

Testing

All existing tests pass, but I couldn't find an existing unit test for getDefaultLibFilePath, and the APISample tests are meant to be 1-to-1 with the Wiki, so I didn't think that was the right place for them either.
It seemed like nearly all of the tests were integration tests and did not directly test single files or functions such as this one, at least as far as I could tell -- please let me know if that's incorrect! I did find a unittests dir, but there was only one file in it, so not sure if that's the right place for a test for this either.

The CONTRIBUTING.md seems to only cover adding fixtures/integration tests (not sure what the "proper" word for it is in this codebase since testing terminology is a bit team-dependent I find), and not a unit test of a function like this.

Please direct me as to where it would be best to add a test for this!

References

Fixes #49050
Also fixes downstream ezolenko/rollup-plugin-typescript2#321 (comment)

- 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
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label May 10, 2022
@RyanCavanaugh RyanCavanaugh merged commit da00ba6 into microsoft:main May 12, 2022
@agilgur5 agilgur5 deleted the fix-defaultLibFilePath-normalization branch July 7, 2023 20:01
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getDefaultLibFilePath returns with mixed OS separators on Windows (both \\ and /)

4 participants