Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

module: normalize path when computing cache key. #8145

Closed
wants to merge 1 commit into from

Conversation

misterdjules
Copy link

When adding a new module to the cache, and also when querying the cache,
normalize the path so that modules don't get loaded more than once when:

  • They are referenced by the same file name but with different case for
    the drive letter on Windows.
  • They are referenced by two different paths that point to the same
    file.

Tested on Windows, Ubuntu 12.04, MacOS X and SmartOS.

Fixes #7031.

@refack
Copy link
Contributor

refack commented Aug 14, 2014

👍

When adding a new module to the cache, and also when querying the cache,
normalize the path so that modules don't get loaded more than once when:
- They are referenced by the same filename but with different case for
  the drive letter on Windows.
- They are referenced by two different paths that point to the same
  file.

Fixes nodejs#7031.
@trevnorris
Copy link

/cc @tjfontaine

@Jokero
Copy link

Jokero commented Jul 31, 2015

When are you going to merge it? I think it is critical issue for Windows users

@jasnell
Copy link
Member

jasnell commented Aug 13, 2015

@misterdjules ... are you able to get back to this?

@FransGH
Copy link

FransGH commented May 14, 2016

There seem to be two core issues coming up in the various discussions around case sensitivity of require():

  1. on case sensitive files systems, some modules might not load (throwing an error)
  2. on case insensitive file systems, calling require() for the same module but with different case loads the module multiple times (breaking singletons)

The 2nd issue really sounds like a bug that this pull request elegantly resolves.

What would be required to get this merged?

@FransGH
Copy link

FransGH commented May 15, 2016

Workaround for singletons:

In your module add the following code at the top:

if(global._didimport_MyModuleName) {
throw("MyModuleName already imported - check if all filenames have equal case");
}

global._didimport_MyModuleName =true;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants