Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssr): add normalizePath to require.resolve, fix #2393 #4980

Merged
merged 1 commit into from
Sep 19, 2021
Merged

fix(ssr): add normalizePath to require.resolve, fix #2393 #4980

merged 1 commit into from
Sep 19, 2021

Conversation

untp
Copy link
Contributor

@untp untp commented Sep 19, 2021

Description

Solves #2393

Additional context

On windows, entry is a string with / and requireEntry is a string with \. When requireEntry passed to normalizePath, it becomes a string with /.

                          entry: C:/Users/U/Desktop/solid-hackernews/node_modules/solid-js/dist/solid.js
                   requireEntry: C:\Users\U\Desktop\solid-hackernews\node_modules\solid-js\dist\static.cjs
requireEntry with normalizePath: C:/Users/U/Desktop/solid-hackernews/node_modules/solid-js/dist/static.cjs
                          entry: C:/Users/U/Desktop/solid-hackernews/node_modules/jiti/lib/index.js
                   requireEntry: C:\Users\U\Desktop\solid-hackernews\node_modules\jiti\lib\index.js
requireEntry with normalizePath: C:/Users/U/Desktop/solid-hackernews/node_modules/jiti/lib/index.js
                          entry: C:/Users/U/Desktop/solid-hackernews/node_modules/rollup-route-manifest/dist/index.mjs
                   requireEntry: C:\Users\U\Desktop\solid-hackernews\node_modules\rollup-route-manifest\dist\index.js
requireEntry with normalizePath: C:/Users/U/Desktop/solid-hackernews/node_modules/rollup-route-manifest/dist/index.js
                          entry: C:/Users/U/Desktop/solid-hackernews/node_modules/vite/dist/node/index.js
                   requireEntry: C:\Users\U\Desktop\solid-hackernews\node_modules\vite\dist\node\index.js
requireEntry with normalizePath: C:/Users/U/Desktop/solid-hackernews/node_modules/vite/dist/node/index.js
                          entry: C:/Users/U/Desktop/solid-hackernews/node_modules/vite-plugin-solid/dist/esm/index.mjs
                   requireEntry: C:\Users\U\Desktop\solid-hackernews\node_modules\vite-plugin-solid\dist\cjs\index.cjs
requireEntry with normalizePath: C:/Users/U/Desktop/solid-hackernews/node_modules/vite-plugin-solid/dist/cjs/index.cjs
                          entry: C:/Users/U/Desktop/solid-hackernews/node_modules/compression/index.js
                   requireEntry: C:\Users\U\Desktop\solid-hackernews\node_modules\compression\index.js
requireEntry with normalizePath: C:/Users/U/Desktop/solid-hackernews/node_modules/compression/index.js
                          entry: C:/Users/U/Desktop/solid-hackernews/node_modules/express/index.js
                   requireEntry: C:\Users\U\Desktop\solid-hackernews\node_modules\express\index.js
requireEntry with normalizePath: C:/Users/U/Desktop/solid-hackernews/node_modules/express/index.js
                          entry: C:/Users/U/Desktop/solid-hackernews/node_modules/fastify/fastify.js
                   requireEntry: C:\Users\U\Desktop\solid-hackernews\node_modules\fastify\fastify.js
requireEntry with normalizePath: C:/Users/U/Desktop/solid-hackernews/node_modules/fastify/fastify.js
                          entry: C:/Users/U/Desktop/solid-hackernews/node_modules/node-fetch/lib/index.mjs
                   requireEntry: C:\Users\U\Desktop\solid-hackernews\node_modules\node-fetch\lib\index.js
requireEntry with normalizePath: C:/Users/U/Desktop/solid-hackernews/node_modules/node-fetch/lib/index.js
                          entry: C:/Users/U/Desktop/solid-hackernews/node_modules/serve-static/index.js
                   requireEntry: C:\Users\U\Desktop\solid-hackernews\node_modules\serve-static\index.js
requireEntry with normalizePath: C:/Users/U/Desktop/solid-hackernews/node_modules/serve-static/index.js
                          entry: C:/Users/U/Desktop/solid-hackernews/node_modules/solid-app-router/dist/index.js
                   requireEntry: C:\Users\U\Desktop\solid-hackernews\node_modules\solid-app-router\dist\index.js
requireEntry with normalizePath: C:/Users/U/Desktop/solid-hackernews/node_modules/solid-app-router/dist/index.js

Also in #2393 @rturnq said

Simply using Vite's path normalization utility on requireEntry also doesn't quite work as, at least in my case, the paths end up with slightly different casing: "C:\..." vs "c:\..."

but I can't reproduce it.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@patak-dev
Copy link
Member

Thanks for the PR. I think we can merge this one as is, but it would be good to extend the test suite to avoid regressions in the future. @untp if you want to work a small test case in this or a subsequent PR you can follow this guide https://github.com/vitejs/vite/blob/main/CONTRIBUTING.md#extending-the-test-suite, and extend one of the SSR playgrounds.

@patak-dev patak-dev changed the title fix(ssr): add normalizePath to require.resolve (fix #2393) fix(ssr): add normalizePath to require.resolve, fix #2393 Sep 19, 2021
@patak-dev patak-dev merged commit 417208c into vitejs:main Sep 19, 2021
patak-dev pushed a commit that referenced this pull request Sep 19, 2021
ygj6 pushed a commit to ygj6/vite that referenced this pull request Sep 22, 2021
ygj6 pushed a commit to ygj6/vite that referenced this pull request Sep 22, 2021
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants