Skip to content

Commit e5e9f59

Browse files
arianonTimer
authored andcommitted
Update getCSSModuleLocalIdent to support Sass (#4391)
* Update getCSSModuleLocalIdent to support Sass * Fix Sass/SCSS index module tests Also make them more consistent with the non-index variants.
1 parent 7b2eae1 commit e5e9f59

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

packages/react-dev-utils/getCSSModuleLocalIdent.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ module.exports = function getLocalIdent(
1515
localName,
1616
options
1717
) {
18-
// Use the filename or folder name, based on some uses the index.js / index.module.css project style
19-
const fileNameOrFolder = context.resourcePath.endsWith('index.module.css')
18+
// Use the filename or folder name, based on some uses the index.js / index.module.(css|scss|sass) project style
19+
const fileNameOrFolder = context.resourcePath.match(
20+
/index\.module\.(css|scss|sass)$/
21+
)
2022
? '[folder]'
2123
: '[name]';
2224
// Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique.

packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ describe('Integration', () => {
5050
).to.match(
5151
/.+scss-styles_scssModulesInclusion.+\{background:.+;color:.+}/
5252
);
53+
expect(
54+
doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
55+
).to.match(
56+
/.+assets_scssModulesIndexInclusion.+\{background:.+;color:.+}/
57+
);
5358
});
5459

5560
it('sass inclusion', async () => {
@@ -68,6 +73,11 @@ describe('Integration', () => {
6873
).to.match(
6974
/.+sass-styles_sassModulesInclusion.+\{background:.+;color:.+}/
7075
);
76+
expect(
77+
doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
78+
).to.match(
79+
/.+assets_sassModulesIndexInclusion.+\{background:.+;color:.+}/
80+
);
7181
});
7282

7383
it('graphql files inclusion', async () => {

packages/react-scripts/fixtures/kitchensink/src/features/webpack/SassModulesInclusion.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77

88
import React from 'react';
99
import styles from './assets/sass-styles.module.sass';
10+
import indexStyles from './assets/index.module.sass';
1011

1112
export default () => (
12-
<p className={styles.sassModulesInclusion}>SASS Modules are working!</p>
13+
<div>
14+
<p className={styles.sassModulesInclusion}>SASS Modules are working!</p>
15+
<p className={indexStyles.sassModulesIndexInclusion}>
16+
SASS Modules with index are working!
17+
</p>
18+
</div>
1319
);

packages/react-scripts/fixtures/kitchensink/src/features/webpack/ScssModulesInclusion.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77

88
import React from 'react';
99
import styles from './assets/scss-styles.module.scss';
10+
import indexStyles from './assets/index.module.scss';
1011

1112
export default () => (
12-
<p className={styles.scssModulesInclusion}>SCSS Modules are working!</p>
13+
<div>
14+
<p className={styles.scssModulesInclusion}>SCSS Modules are working!</p>
15+
<p className={indexStyles.scssModulesIndexInclusion}>
16+
SCSS Modules with index are working!
17+
</p>
18+
</div>
1319
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.sassModulesIndexInclusion
2+
background: darkblue
3+
color: lightblue
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.scssModulesIndexInclusion {
2+
background: darkblue;
3+
color: lightblue;
4+
}

0 commit comments

Comments
 (0)