Skip to content

Commit ab2fe0e

Browse files
andris-silisgajus
authored andcommitted
feat: use imported file path as style map key (#101)
1 parent d221d7c commit ab2fe0e

File tree

4 files changed

+5
-5
lines changed
  • src
  • test/fixtures/react-css-modules
    • merges the resolved styleName with the existing className values
    • uses getClassName to resolve non-literal styleName
    • uses getClassName to resolve non-literal styleName (with already existing className)

4 files changed

+5
-5
lines changed

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ export default ({
144144
let styleImportName: string;
145145

146146
if (path.node.specifiers.length === 0) {
147-
// eslint-disable-next-line no-process-env
148-
styleImportName = process.env.NODE_ENV === 'test' ? 'random-test' : 'random-' + Math.random();
147+
// use imported file path as import name
148+
styleImportName = path.node.source.value;
149149
} else if (path.node.specifiers.length === 1) {
150150
styleImportName = path.node.specifiers[0].local.name;
151151
} else {

test/fixtures/react-css-modules/merges the resolved styleName with the existing className values/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _getClassName from 'babel-plugin-react-css-modules/dist/browser/getClassN
22
import './bar.css';
33

44
const _styleModuleImportMap = {
5-
'random-test': {
5+
'./bar.css': {
66
'a': 'bar__a'
77
}
88
};

test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName (with already existing className)/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const _styleModuleImportMap = {
66
'bar': {
77
'a-b': 'bar__a-b'
88
},
9-
'random-test': {
9+
'./foo.css': {
1010
'a-b': 'foo__a-b'
1111
}
1212
};

test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const _styleModuleImportMap = {
66
'bar': {
77
'a-b': 'bar__a-b'
88
},
9-
'random-test': {
9+
'./foo.css': {
1010
'a-b': 'foo__a-b'
1111
}
1212
};

0 commit comments

Comments
 (0)