From bc83a2151f23ee2a15b7271b9829ec7904b420dc Mon Sep 17 00:00:00 2001 From: Phil Edwards Date: Mon, 20 May 2024 19:09:35 -0400 Subject: [PATCH] Patch webpack t() plugin to allow t('String ' + /*\n*/ 'concatenation') Fixes a problem where if you concatenate string literals inside a t() call, the t-string would be excluded, without any error message, from `extracted-strings.json` If you run the webpack build after this patch, you'll see about 9 translation strings in the output that were missing before. (This commit also removes the previous patch on 6.0.0 and upgrades webpack-extract-translation-keys-plugin to 6.1.0 where that patch was merged upstream.) --- package-lock.json | 14 ++++++------ package.json | 2 +- ...xtract-translation-keys-plugin+6.0.0.patch | 19 ---------------- ...xtract-translation-keys-plugin+6.1.0.patch | 22 +++++++++++++++++++ 4 files changed, 30 insertions(+), 27 deletions(-) delete mode 100644 patches/webpack-extract-translation-keys-plugin+6.0.0.patch create mode 100644 patches/webpack-extract-translation-keys-plugin+6.1.0.patch diff --git a/package-lock.json b/package-lock.json index 5149c8673e..0fdaec00ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -163,7 +163,7 @@ "webpack-cli": "^4.9.2", "webpack-dev-middleware": "^5.3.1", "webpack-dev-server": "^4.8.1", - "webpack-extract-translation-keys-plugin": "^6.0.0" + "webpack-extract-translation-keys-plugin": "^6.1.0" }, "engines": { "node": "16.15.0", @@ -28124,9 +28124,9 @@ } }, "node_modules/webpack-extract-translation-keys-plugin": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/webpack-extract-translation-keys-plugin/-/webpack-extract-translation-keys-plugin-6.0.0.tgz", - "integrity": "sha512-QjW1wrXkplsGZP5hysOYPL7CsjhXBUMQ7O1i73nQkMft0uWfggdeH79JKWvTN66VZYZuM4CS80dGwl2E+BpoLw==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/webpack-extract-translation-keys-plugin/-/webpack-extract-translation-keys-plugin-6.1.0.tgz", + "integrity": "sha512-W6F/VAPqFG05Iloy2t2UTa84nkJQC/IuPmMQNYXe0ic85Xeu01WpUOkrpnb4kGRcsKxHAVC95VCsL8uvH94oRQ==", "dev": true, "peerDependencies": { "webpack": "^5.0.0" @@ -48279,9 +48279,9 @@ } }, "webpack-extract-translation-keys-plugin": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/webpack-extract-translation-keys-plugin/-/webpack-extract-translation-keys-plugin-6.0.0.tgz", - "integrity": "sha512-QjW1wrXkplsGZP5hysOYPL7CsjhXBUMQ7O1i73nQkMft0uWfggdeH79JKWvTN66VZYZuM4CS80dGwl2E+BpoLw==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/webpack-extract-translation-keys-plugin/-/webpack-extract-translation-keys-plugin-6.1.0.tgz", + "integrity": "sha512-W6F/VAPqFG05Iloy2t2UTa84nkJQC/IuPmMQNYXe0ic85Xeu01WpUOkrpnb4kGRcsKxHAVC95VCsL8uvH94oRQ==", "dev": true, "requires": {} }, diff --git a/package.json b/package.json index dca9c12207..c1954f726c 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,7 @@ "webpack-cli": "^4.9.2", "webpack-dev-middleware": "^5.3.1", "webpack-dev-server": "^4.8.1", - "webpack-extract-translation-keys-plugin": "^6.0.0" + "webpack-extract-translation-keys-plugin": "^6.1.0" }, "overrides": { "reflux": { diff --git a/patches/webpack-extract-translation-keys-plugin+6.0.0.patch b/patches/webpack-extract-translation-keys-plugin+6.0.0.patch deleted file mode 100644 index 7b04937a54..0000000000 --- a/patches/webpack-extract-translation-keys-plugin+6.0.0.patch +++ /dev/null @@ -1,19 +0,0 @@ -diff --git a/node_modules/webpack-extract-translation-keys-plugin/index.js b/node_modules/webpack-extract-translation-keys-plugin/index.js -index 7dba8ea..d066e7e 100644 ---- a/node_modules/webpack-extract-translation-keys-plugin/index.js -+++ b/node_modules/webpack-extract-translation-keys-plugin/index.js -@@ -25,12 +25,12 @@ const KeyGenerator = require('./key-generator'); - - // resolve entry for given module, we try to exit early with rawRequest in case of multiple modules issuing request - function resolveEntry(module, reverseEntryPoints) { -+ const moduleGraph = module.parser.state.compilation.moduleGraph; - let issuer = module; - if (reverseEntryPoints[issuer.rawRequest]) { - return issuer.rawRequest; - } -- while (issuer.issuer) { -- issuer = issuer.issuer; -+ while (issuer = moduleGraph.getIssuer(issuer)) { - if (reverseEntryPoints[issuer.rawRequest]) { - return issuer.rawRequest; - } diff --git a/patches/webpack-extract-translation-keys-plugin+6.1.0.patch b/patches/webpack-extract-translation-keys-plugin+6.1.0.patch new file mode 100644 index 0000000000..1431420747 --- /dev/null +++ b/patches/webpack-extract-translation-keys-plugin+6.1.0.patch @@ -0,0 +1,22 @@ +diff --git a/node_modules/webpack-extract-translation-keys-plugin/index.js b/node_modules/webpack-extract-translation-keys-plugin/index.js +index 50da46c..962c104 100644 +--- a/node_modules/webpack-extract-translation-keys-plugin/index.js ++++ b/node_modules/webpack-extract-translation-keys-plugin/index.js +@@ -115,7 +115,7 @@ ExtractTranslationPlugin.prototype.apply = function(compiler) { + } + + key = parser.evaluateExpression(expr.arguments[0]); +- if (!key.isString()) { ++ if (key.string === undefined) { + parser.state.module.errors.push( + new DynamicTranslationKeyError( + parser.state.module, +@@ -127,7 +127,7 @@ ExtractTranslationPlugin.prototype.apply = function(compiler) { + + key = key.string; + +- let value = expr.arguments[0].value; ++ let value = key; + + const entry = + reverseEntryPoints[