From fd00998a342cf077fa2a4b97ac0e4fa7153b6ed0 Mon Sep 17 00:00:00 2001 From: "taeyoung.hong" Date: Tue, 5 Dec 2023 19:01:12 +0900 Subject: [PATCH 1/7] apply own hash on css-module-ident --- css-module-ident.js | 17 ++++++++++++++++- index.js | 1 + npm-shrinkwrap.json | 14 ++++++++++++++ package.json | 3 ++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/css-module-ident.js b/css-module-ident.js index 9ab95ef..5e718c5 100644 --- a/css-module-ident.js +++ b/css-module-ident.js @@ -1,5 +1,6 @@ const fs = require('fs'); const path = require('path'); +const loaderUtils = require('loader-utils'); const app = require('./option-parser'); const packageRoot = require('./package-root'); @@ -24,5 +25,19 @@ module.exports = function (context, localIdentName, localName) { } const fileMatch = rel.match(fileIdentPattern); const identFile = (fileMatch && (fileMatch[1] || fileMatch[2])) || 'unknown'; - return identFile.replace(/[/\\]+/g, '_') + '_' + localName; + + // Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique. + let hash = ''; + if (process.env.SIMPLE_CSS_IDENT === 'true') { + hash = + '__' + + loaderUtils.getHashDigest( + path.posix.relative(context.rootContext, context.resourcePath) + localName, + 'md5', + 'base64url', + 5 + ); + } + + return identFile.replace(/[/\\]+/g, '_') + '_' + localName + hash; }; diff --git a/index.js b/index.js index acb88a2..06e90da 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,7 @@ const exportOnDemand = obj => { exportOnDemand({ configHelper: () => require('./config-helper'), cssModuleIdent: () => require('./css-module-ident'), + cssModuleIdentWithHash: () => require('./css-module-ident-with-hash'), mixins: () => require('./mixins'), optionParser: () => require('./option-parser'), packageRoot: () => require('./package-root') diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 850a85a..da657c3 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -18,6 +18,7 @@ "find-cache-dir": "^5.0.0", "graceful-fs": "^4.2.11", "import-fresh": "^3.3.0", + "loader-utils": "^3.2.1", "mock-require": "^3.0.3", "resolve": "^1.22.8", "tapable": "^2.2.1", @@ -18791,6 +18792,14 @@ "node": ">=6.11.5" } }, + "node_modules/loader-utils": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-3.2.1.tgz", + "integrity": "sha512-ZvFw1KWS3GVyYBYb7qkmRM/WwL2TQQBxgCK62rlvm4WpVQ23Nb4tYjApUlfjrEGvOs7KHEsmyUn75OHZrJMWPw==", + "engines": { + "node": ">= 12.13.0" + } + }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -34256,6 +34265,11 @@ "integrity": "sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==", "dev": true }, + "loader-utils": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-3.2.1.tgz", + "integrity": "sha512-ZvFw1KWS3GVyYBYb7qkmRM/WwL2TQQBxgCK62rlvm4WpVQ23Nb4tYjApUlfjrEGvOs7KHEsmyUn75OHZrJMWPw==" + }, "locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", diff --git a/package.json b/package.json index b1b06aa..de7f1f7 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "find-cache-dir": "^5.0.0", "graceful-fs": "^4.2.11", "import-fresh": "^3.3.0", + "loader-utils": "^3.2.1", "mock-require": "^3.0.3", "resolve": "^1.22.8", "tapable": "^2.2.1", @@ -74,4 +75,4 @@ "react": "^18.2.0", "webpack": "^5.89.0" } -} \ No newline at end of file +} From c55b59dc88691b70d5f4e7aabbf69c086228c899 Mon Sep 17 00:00:00 2001 From: "taeyoung.hong" Date: Tue, 5 Dec 2023 19:14:36 +0900 Subject: [PATCH 2/7] update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86ca99c..6e31ea3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# unreleased + +* `css-module-ident`: Added own hash constructor function. + # 6.0.2 (September 27, 2023) * `VerboseLogPlugin`: From d685d1e219e7990b07ffded3f4111e5eea92c443 Mon Sep 17 00:00:00 2001 From: "taeyoung.hong" Date: Tue, 5 Dec 2023 19:15:07 +0900 Subject: [PATCH 3/7] fix lint error --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 06e90da..acb88a2 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,6 @@ const exportOnDemand = obj => { exportOnDemand({ configHelper: () => require('./config-helper'), cssModuleIdent: () => require('./css-module-ident'), - cssModuleIdentWithHash: () => require('./css-module-ident-with-hash'), mixins: () => require('./mixins'), optionParser: () => require('./option-parser'), packageRoot: () => require('./package-root') From 593724c4809f7650409430ac053b1404571a217d Mon Sep 17 00:00:00 2001 From: "taeyoung.hong" Date: Wed, 6 Dec 2023 10:06:20 +0900 Subject: [PATCH 4/7] Fix the statement to generate hash --- css-module-ident.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css-module-ident.js b/css-module-ident.js index 5e718c5..46a1aff 100644 --- a/css-module-ident.js +++ b/css-module-ident.js @@ -28,7 +28,7 @@ module.exports = function (context, localIdentName, localName) { // Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique. let hash = ''; - if (process.env.SIMPLE_CSS_IDENT === 'true') { + if (process.env.SIMPLE_CSS_IDENT !== 'true') { hash = '__' + loaderUtils.getHashDigest( From f5c7f64cdf97ce88126f9c8585ed03089bdb04eb Mon Sep 17 00:00:00 2001 From: "taeyoung.hong" <35059065+hong6316@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:04:14 +0900 Subject: [PATCH 5/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e31ea3..735365a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # unreleased -* `css-module-ident`: Added own hash constructor function. +* `css-module-ident`: Added own hash generate function. # 6.0.2 (September 27, 2023) From 8a6ffa1c61cb120aa1935fb95ec85cea1de85ab2 Mon Sep 17 00:00:00 2001 From: "taeyoung.hong" Date: Fri, 29 Dec 2023 16:49:48 +0900 Subject: [PATCH 6/7] use base62 --- css-module-ident.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css-module-ident.js b/css-module-ident.js index 46a1aff..3a53d03 100644 --- a/css-module-ident.js +++ b/css-module-ident.js @@ -34,7 +34,7 @@ module.exports = function (context, localIdentName, localName) { loaderUtils.getHashDigest( path.posix.relative(context.rootContext, context.resourcePath) + localName, 'md5', - 'base64url', + 'base62', 5 ); } From 1972991d3a1de1a6d9d4d0ffa2dbfb7cd550671d Mon Sep 17 00:00:00 2001 From: "taeyoung.hong" Date: Fri, 29 Dec 2023 17:28:15 +0900 Subject: [PATCH 7/7] fix lint error --- option-parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/option-parser.js b/option-parser.js index 3a1c558..8e2ecb5 100644 --- a/option-parser.js +++ b/option-parser.js @@ -168,7 +168,7 @@ const config = { ? fontGenerator : [path.join(pkg.path, fontGenerator), path.join(pkg.path, 'node_modules', fontGenerator)].find( fs.existsSync - )); + )); // Override theme's accent LESS variable value if desired. Private option; may be removed in future. // When used, creates a LESS variable override map, overriding '@moon-accent' and/or '@-accent'