From b4355179af276b4a91143cd3b816e2a65b678acd Mon Sep 17 00:00:00 2001 From: Andris Silis Date: Tue, 13 Jun 2017 14:48:15 +0300 Subject: [PATCH] Use imported file path as style map key --- src/index.js | 4 ++-- .../expected.js | 2 +- .../expected.js | 2 +- .../expected.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index b1cbea5..4152ace 100644 --- a/src/index.js +++ b/src/index.js @@ -144,8 +144,8 @@ export default ({ let styleImportName: string; if (path.node.specifiers.length === 0) { - // eslint-disable-next-line no-process-env - styleImportName = process.env.NODE_ENV === 'test' ? 'random-test' : 'random-' + Math.random(); + // use imported file path as import name + styleImportName = path.node.source.value; } else if (path.node.specifiers.length === 1) { styleImportName = path.node.specifiers[0].local.name; } else { diff --git a/test/fixtures/react-css-modules/merges the resolved styleName with the existing className values/expected.js b/test/fixtures/react-css-modules/merges the resolved styleName with the existing className values/expected.js index e9bbd3d..36fbc35 100644 --- a/test/fixtures/react-css-modules/merges the resolved styleName with the existing className values/expected.js +++ b/test/fixtures/react-css-modules/merges the resolved styleName with the existing className values/expected.js @@ -2,7 +2,7 @@ import _getClassName from 'babel-plugin-react-css-modules/dist/browser/getClassN import './bar.css'; const _styleModuleImportMap = { - 'random-test': { + './bar.css': { 'a': 'bar__a' } }; diff --git a/test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName (with already existing className)/expected.js b/test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName (with already existing className)/expected.js index e9f288f..587fbff 100644 --- a/test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName (with already existing className)/expected.js +++ b/test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName (with already existing className)/expected.js @@ -6,7 +6,7 @@ const _styleModuleImportMap = { 'bar': { 'a-b': 'bar__a-b' }, - 'random-test': { + './foo.css': { 'a-b': 'foo__a-b' } }; diff --git a/test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName/expected.js b/test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName/expected.js index 336e388..891c016 100644 --- a/test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName/expected.js +++ b/test/fixtures/react-css-modules/uses getClassName to resolve non-literal styleName/expected.js @@ -6,7 +6,7 @@ const _styleModuleImportMap = { 'bar': { 'a-b': 'bar__a-b' }, - 'random-test': { + './foo.css': { 'a-b': 'foo__a-b' } };