From 96a0f9b56a5c048739a4d5c372d147ed7c4f241b Mon Sep 17 00:00:00 2001 From: Pascal Duez Date: Tue, 20 Sep 2016 22:51:46 +0200 Subject: [PATCH 1/2] Add the hashPrefix option --- README.md | 1 + package.json | 2 +- src/options_resolvers/hashPrefix.js | 15 +++++++++++++++ src/options_resolvers/index.js | 1 + test/options_resolvers/hashPrefix.spec.js | 13 +++++++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/options_resolvers/hashPrefix.js create mode 100644 test/options_resolvers/hashPrefix.spec.js diff --git a/README.md b/README.md index 0d991c6..73feacb 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ npm install --save-dev babel-plugin-css-modules-transform "generateScopedName": "[name]__[local]___[hash:base64:5]", // in case you don't want to use a function "generateScopedName": "./path/to/module-exporting-a-function.js", // in case you want to use a function "generateScopedName": "npm-module-name", + "hashPrefix": "string", "ignore": "*css", "ignore": "./path/to/module-exporting-a-function-or-regexp.js", "preprocessCss": "./path/to/module-exporting-a-function.js", diff --git a/package.json b/package.json index 38155de..fdbec21 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ }, "homepage": "https://github.com/michalkvasnicak/babel-plugin-css-modules-transform#readme", "dependencies": { - "css-modules-require-hook": "^4.0.2", + "css-modules-require-hook": "^4.0.3", "mkdirp": "^0.5.1" }, "devDependencies": { diff --git a/src/options_resolvers/hashPrefix.js b/src/options_resolvers/hashPrefix.js new file mode 100644 index 0000000..19d5f62 --- /dev/null +++ b/src/options_resolvers/hashPrefix.js @@ -0,0 +1,15 @@ +import { isString } from '../utils'; + +/** + * Resolves hashPrefix option for css-modules-require-hook + * + * @param {*} value + * @returns {String} + */ +export default function hashPrefix(value/* , currentConfig */) { + if (!isString(value)) { + throw new Error(`Configuration 'hashPrefix' is not a string`); + } + + return value; +} diff --git a/src/options_resolvers/index.js b/src/options_resolvers/index.js index 958de2c..3c35a13 100644 --- a/src/options_resolvers/index.js +++ b/src/options_resolvers/index.js @@ -3,6 +3,7 @@ export { default as camelCase } from './camelCase'; export { default as createImportedName } from './createImportedName'; export { default as devMode } from './devMode'; export { default as generateScopedName } from './generateScopedName'; +export { default as hashPrefix } from './hashPrefix'; export { default as ignore } from './ignore'; export { default as mode } from './mode'; export { default as prepend } from './prepend'; diff --git a/test/options_resolvers/hashPrefix.spec.js b/test/options_resolvers/hashPrefix.spec.js new file mode 100644 index 0000000..fdf2974 --- /dev/null +++ b/test/options_resolvers/hashPrefix.spec.js @@ -0,0 +1,13 @@ +import { expect } from 'chai'; + +import hashPrefix from '../../src/options_resolvers/hashPrefix'; + +describe('options_resolvers/hashPrefix', () => { + it('should throw if hashPrefix value is not a string', () => { + expect( + () => hashPrefix(null) + ).to.throw(); + + expect(hashPrefix('hashPrefix')).to.be.equal('hashPrefix'); + }); +}); From a3bd22726c7547dd0c0361dc6c01fbddd1ac3b55 Mon Sep 17 00:00:00 2001 From: Pascal Duez Date: Tue, 20 Sep 2016 23:07:42 +0200 Subject: [PATCH 2/2] Fix a few JSDoc annotations --- src/options_resolvers/mode.js | 2 +- src/options_resolvers/rootDir.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/options_resolvers/mode.js b/src/options_resolvers/mode.js index 02c0953..e0b9c7c 100644 --- a/src/options_resolvers/mode.js +++ b/src/options_resolvers/mode.js @@ -4,7 +4,7 @@ import { isString } from '../utils'; * Resolves mode option for css-modules-require-hook * * @param {*} value - * @returns {boolean} + * @returns {String} */ export default function mode(value/* , currentConfig */) { if (!isString(value)) { diff --git a/src/options_resolvers/rootDir.js b/src/options_resolvers/rootDir.js index 0507a69..65d0b06 100644 --- a/src/options_resolvers/rootDir.js +++ b/src/options_resolvers/rootDir.js @@ -3,10 +3,10 @@ import { statSync } from 'fs'; import { isString } from '../utils'; /** - * Resolves mode option for css-modules-require-hook + * Resolves rootDir option for css-modules-require-hook * * @param {*} value - * @returns {boolean} + * @returns {String} */ export default function rootDir(value/* , currentConfig */) { if (!isString(value)) {