Skip to content

Enforce case sensitivity when serving static files #9260

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

Closed
4 tasks done
benmccann opened this issue Jul 20, 2022 · 1 comment · Fixed by #10475
Closed
4 tasks done

Enforce case sensitivity when serving static files #9260

benmccann opened this issue Jul 20, 2022 · 1 comment · Fixed by #10475
Labels
enhancement New feature or request p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Comments

@benmccann
Copy link
Collaborator

benmccann commented Jul 20, 2022

Description

SvelteKit enforces case sensitivity so that your code works if you develop on Mac / Windows and then deploy to Linux. It also becomes easier to work on a code base where people are using different OS.

I'd like to remove SvelteKit's static file serving and rely on Vite's, but we'd first need to standardize the behaviors so that they're the same.

Suggested solution

Here's SvelteKit's solution:

/**
 * 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;
}

Luke has said he doesn't want to add it as an option in sirv (lukeed/sirv#141), so it would need to be implemented in Vite.

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

@benmccann benmccann added enhancement New feature or request p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) labels Jul 20, 2022
@dominikg
Copy link
Contributor

Not sure if needed here but this exists in case you want to know if the os is insensitive.

export const isCaseInsensitiveFS = testCaseInsensitiveFS()

patak-dev pushed a commit that referenced this issue Nov 12, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants