diff --git a/.github/workflows/test.js.yml b/.github/workflows/test.js.yml index 3ff38ca..8fabe69 100644 --- a/.github/workflows/test.js.yml +++ b/.github/workflows/test.js.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - node-version: [10.x, 12.x, 14.x, 15.x] + node-version: [16.x, 18.x, 19.x, 20.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ runs-on: ${{ matrix.os }} diff --git a/.gitignore b/.gitignore index 013eddc..5de664d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build/ npm-debug.log index.es5.js undefined.json +.idea/ diff --git a/README.md b/README.md index 2059f3c..ad25065 100644 --- a/README.md +++ b/README.md @@ -191,17 +191,19 @@ postcss([ ### localsConvention -Type: `String | (originalClassName: string, generatedClassName: string, inputFile: string) => className: string` +Type: `String | (originalClassName: string, generatedClassName: string, inputFile: string) => className: (string|string[])` Default: `null` Style of exported classnames, the keys in your json. | Name | Type | Description | -| :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- | +|:---------------------:| :--------: |:-------------------------------------------------------------------------------------------------| | **`'camelCase'`** | `{String}` | Class names will be camelized, the original class name will not to be removed from the locals | | **`'camelCaseOnly'`** | `{String}` | Class names will be camelized, the original class name will be removed from the locals | | **`'dashes'`** | `{String}` | Only dashes in class names will be camelized | | **`'dashesOnly'`** | `{String}` | Dashes in class names will be camelized, the original class name will be removed from the locals | +| **`'all'`** | `{String}` | Apply camelCase, dashes, and the orignional naming convention | +| **`'none'`** | `{String}` | Only use the orignional naming convention with out locals | In lieu of a string, a custom function can generate the exported class names. diff --git a/package-lock.json b/package-lock.json index b447596..2937933 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "postcss-modules", - "version": "6.0.0", + "version": "6.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "postcss-modules", - "version": "6.0.0", + "version": "6.0.1", "license": "MIT", "dependencies": { "generic-names": "^4.0.0", @@ -4228,7 +4228,8 @@ "node_modules/colorette": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.1.tgz", - "integrity": "sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==" + "integrity": "sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==", + "dev": true }, "node_modules/combined-stream": { "version": "1.0.8", @@ -8920,6 +8921,7 @@ "version": "3.1.20", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.20.tgz", "integrity": "sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==", + "dev": true, "bin": { "nanoid": "bin/nanoid.cjs" }, @@ -9600,6 +9602,7 @@ "version": "8.2.4", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.2.4.tgz", "integrity": "sha512-kRFftRoExRVXZlwUuay9iC824qmXPcQQVzAjbCCgjpXnkdMCJYBu2gTwAaFBzv8ewND6O8xFb3aELmEkh9zTzg==", + "dev": true, "dependencies": { "colorette": "^1.2.1", "nanoid": "^3.1.20", @@ -9691,6 +9694,7 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -11800,20 +11804,6 @@ "is-typedarray": "^1.0.0" } }, - "node_modules/typescript": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz", - "integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==", - "dev": true, - "peer": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", @@ -14785,8 +14775,7 @@ "version": "5.3.1", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz", "integrity": "sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==", - "dev": true, - "requires": {} + "dev": true }, "acorn-walk": { "version": "7.2.0", @@ -15453,7 +15442,8 @@ "colorette": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.1.tgz", - "integrity": "sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==" + "integrity": "sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==", + "dev": true }, "combined-stream": { "version": "1.0.8", @@ -16821,8 +16811,7 @@ "icss-utils": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/icss-utils/-/icss-utils-5.1.0.tgz", - "integrity": "sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==", - "requires": {} + "integrity": "sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==" }, "ignore": { "version": "4.0.6", @@ -17878,8 +17867,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/jest-pnp-resolver/-/jest-pnp-resolver-1.2.1.tgz", "integrity": "sha512-pgFw2tm54fzgYvc/OHrnysABEObZCUNFnhjoRjaVOCN8NYc032/gVjPaHD4Aq6ApkSieWtfKAFQtmDKAmhupnQ==", - "dev": true, - "requires": {} + "dev": true }, "jest-regex-util": { "version": "26.0.0", @@ -19051,7 +19039,8 @@ "nanoid": { "version": "3.1.20", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.20.tgz", - "integrity": "sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==" + "integrity": "sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==", + "dev": true }, "nanomatch": { "version": "1.2.13", @@ -19578,6 +19567,7 @@ "version": "8.2.4", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.2.4.tgz", "integrity": "sha512-kRFftRoExRVXZlwUuay9iC824qmXPcQQVzAjbCCgjpXnkdMCJYBu2gTwAaFBzv8ewND6O8xFb3aELmEkh9zTzg==", + "dev": true, "requires": { "colorette": "^1.2.1", "nanoid": "^3.1.20", @@ -19587,15 +19577,15 @@ "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true } } }, "postcss-modules-extract-imports": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/postcss-modules-extract-imports/-/postcss-modules-extract-imports-3.0.0.tgz", - "integrity": "sha512-bdHleFnP3kZ4NYDhuGlVK+CMrQ/pqUm8bx/oGL93K6gVwiclvX5x0n76fYMKuIGKzlABOy13zsvqjb0f92TEXw==", - "requires": {} + "integrity": "sha512-bdHleFnP3kZ4NYDhuGlVK+CMrQ/pqUm8bx/oGL93K6gVwiclvX5x0n76fYMKuIGKzlABOy13zsvqjb0f92TEXw==" }, "postcss-modules-local-by-default": { "version": "4.0.0", @@ -21314,13 +21304,6 @@ "is-typedarray": "^1.0.0" } }, - "typescript": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz", - "integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==", - "dev": true, - "peer": true - }, "unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", @@ -21666,8 +21649,7 @@ "version": "7.3.0", "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz", "integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==", - "dev": true, - "requires": {} + "dev": true }, "xml-name-validator": { "version": "3.0.0", diff --git a/package.json b/package.json index ef7896d..3570a04 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-modules", - "version": "6.0.0", + "version": "6.0.1", "description": "PostCSS plugin to use CSS Modules everywhere", "main": "build/index.js", "types": "index.d.ts", diff --git a/src/localsConvention.js b/src/localsConvention.js index 91c9e30..a6ba263 100644 --- a/src/localsConvention.js +++ b/src/localsConvention.js @@ -10,12 +10,31 @@ export function makeLocalsConventionReducer(localsConvention, inputFile) { return (tokens, [className, value]) => { if (isFunc) { const convention = localsConvention(className, value, inputFile); + + if (Array.isArray(convention)) { + + convention.forEach(convention => tokens[convention] = value); + + return tokens; + + } + tokens[convention] = value; return tokens; } switch (localsConvention) { + case "none": + tokens[className] = value; + break; + + case "all": + tokens[className] = value; + tokens[camelCase(className)] = value; + tokens[dashesCamelCase(className)] = value; + break; + case "camelCase": tokens[className] = value; tokens[camelCase(className)] = value;