Absolute resourcePath used in getCSSModuleLocalIdent
Created by: vg-stan
I recently upgraded to create-react-app 2.1.8 and noticed the hashes used in css modules classnames are different in different build environments. I did some debugging and saw that 'react-dev-utils/getCSSModuleLocalIdent' uses 'context.resourcePath + localName' for the hash generation and that context.resourcePath was an absolute path. The original discussion (https://github.com/facebook/create-react-app/pull/3965) indicated we wanted the full path for uniqueness and that we also wanted to preserve keep the classnames deterministic for automated testing. It seems like trimming the context.resourcePath of context.rootContext would preserve uniqueness within the project and allow users to write tests against the classnames locally and have it work on different machines regardless of the project path.
Example of the issue, the classnames for css modules in the below two repo locations will hash to different values in the current code: /Users/person1/projectrepo/ /Users/person2/projectrepo/
If in getCSSModuleLocalIdent we change the code to something like the below, the hashes will be the same
const hash = loaderUtils.getHashDigest(
context.resourcePath.replace(context.rootContext, "") + localName
'md5',
'base64',
5
);
I'd be happy to submit a PR if this makes sense and I didn't miss something obvious. Thank you!