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: github issue #4439: case insensitive compare of file paths. #4440

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion cli/run/loadConfigFile.ts
Expand Up @@ -103,12 +103,19 @@ async function getDefaultFromTranspiledConfigFile(
return loadConfigFromBundledFile(fileName, code);
}

function isSamePath(fileName1: string, fileName2: string): boolean {
if (process.platform === 'win32') {
return fileName1.toUpperCase() === fileName2.toUpperCase();
}
return fileName1 === fileName2;
}

async function loadConfigFromBundledFile(fileName: string, bundledCode: string): Promise<unknown> {
const resolvedFileName = await fs.realpath(fileName);
const extension = extname(resolvedFileName);
const defaultLoader = require.extensions[extension];
require.extensions[extension] = (module: NodeModule, requiredFileName: string) => {
if (requiredFileName === resolvedFileName) {
if (isSamePath(requiredFileName, resolvedFileName)) {
(module as NodeModuleWithCompile)._compile(bundledCode, requiredFileName);
} else {
defaultLoader(module, requiredFileName);
Expand Down
2 changes: 1 addition & 1 deletion scripts/load-perf-config.js
Expand Up @@ -28,7 +28,7 @@ exports.loadPerfConfig = async () => {
function loadConfigFromCode(code) {
const defaultLoader = require.extensions['.js'];
require.extensions['.js'] = (module, filename) => {
if (filename === configFile) {
if (rollup.isSamePath(filename, configFile)) {
lovettchris marked this conversation as resolved.
Show resolved Hide resolved
module._compile(code, filename);
} else {
defaultLoader(module, filename);
Expand Down
7 changes: 7 additions & 0 deletions src/utils/path.ts
Expand Up @@ -15,4 +15,11 @@ export function normalize(path: string): string {
return path.replace(BACKSLASH_REGEX, '/');
}

export function isSamePath(fileName1: string, fileName2: string): boolean {
if (process.platform === 'win32') {
return fileName1.toUpperCase() === fileName2.toUpperCase();
}
return fileName1 === fileName2;
}

export { basename, dirname, extname, relative, resolve } from 'path';
2 changes: 1 addition & 1 deletion src/utils/sanitizeFileName.ts
@@ -1,7 +1,7 @@
// https://datatracker.ietf.org/doc/html/rfc2396
// eslint-disable-next-line no-control-regex
const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g;
const DRIVE_LETTER_REGEX = /^[a-z]:/i;
const DRIVE_LETTER_REGEX = /^[a-zA-Z]:/i;

export function sanitizeFileName(name: string): string {
const match = DRIVE_LETTER_REGEX.exec(name);
Expand Down