vite
vite copied to clipboard
Enforce case sensitivity when serving static files
Description
I'd like to serve a file if the case matches what's on the filesystem. That's how it works on Linux, but Mac and Windows have a different behavior. It'd be nice to enforce case sensitivity so that it works if you develop on one OS and then deploy to another
Suggested solution
If possible, add this as an option to sirv
(https://github.com/lukeed/sirv/issues/141) and then turn on that option. Otherwise, implement it directly here:
/**
* Determine if a file is being requested with the correct case,
* to ensure consistent behaviour between dev and prod and across
* operating systems. Note that we can't use realpath here,
* because we don't want to follow symlinks
* @param {string} file
* @param {string} assets
* @returns {boolean}
*/
function has_correct_case(file, assets) {
if (file === assets) return true;
const parent = path.dirname(file);
if (fs.readdirSync(parent).includes(path.basename(file))) {
return has_correct_case(parent, assets);
}
return false;
}
Alternative
No response
Additional context
SvelteKit historically hasn't used the publicDir
and base
options, but does its own static asset serving. I put together a branch to use Vite's implementation, but some of our tests are failing with it due to this issue, which is a blocker for us.
https://github.com/sveltejs/kit/pull/5601/files#r925101030
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Not sure if needed here but this exists in case you want to know if the os is insensitive. https://github.com/vitejs/vite/blob/1e078ad1902ae980741d6920fc3a72d182fcf179/packages/vite/src/node/utils.ts#L203