From 135ad33f7ca79fb1be539892bb53d6cb54a504c5 Mon Sep 17 00:00:00 2001 From: David Michon Date: Mon, 23 Sep 2024 21:19:56 +0000 Subject: [PATCH] [webpack-localization-plugin] Fix circular reference in assetInfo.related --- .../webpack-loc-related-loop_2024-09-23-21-19.json | 10 ++++++++++ .../src/AssetProcessor.ts | 11 ++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 common/changes/@rushstack/webpack5-localization-plugin/webpack-loc-related-loop_2024-09-23-21-19.json diff --git a/common/changes/@rushstack/webpack5-localization-plugin/webpack-loc-related-loop_2024-09-23-21-19.json b/common/changes/@rushstack/webpack5-localization-plugin/webpack-loc-related-loop_2024-09-23-21-19.json new file mode 100644 index 00000000000..af0a3a03622 --- /dev/null +++ b/common/changes/@rushstack/webpack5-localization-plugin/webpack-loc-related-loop_2024-09-23-21-19.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/webpack5-localization-plugin", + "comment": "Fix circular references between localized assets' \"related\" properties. This caused emitting of the webpack stats object to fail.", + "type": "patch" + } + ], + "packageName": "@rushstack/webpack5-localization-plugin" +} \ No newline at end of file diff --git a/webpack/webpack5-localization-plugin/src/AssetProcessor.ts b/webpack/webpack5-localization-plugin/src/AssetProcessor.ts index efc93e56fb0..9a52310e145 100644 --- a/webpack/webpack5-localization-plugin/src/AssetProcessor.ts +++ b/webpack/webpack5-localization-plugin/src/AssetProcessor.ts @@ -117,8 +117,6 @@ export function processLocalizedAsset(options: IProcessLocalizedAssetOptions): R const fileName: string = compilation.getAssetPath(filenameTemplate, data); - originInfo.related[locale] = fileName; - const info: AssetInfo = { ...originInfo, locale @@ -130,8 +128,15 @@ export function processLocalizedAsset(options: IProcessLocalizedAssetOptions): R // If file already exists if (originName === fileName) { // This helper throws if the asset doesn't already exist - compilation.updateAsset(fileName, wrapped, info); + // Use the function form so that the object identity of `related` is preserved. + // Since we already read the original info, we don't need fancy merge logic. + compilation.updateAsset(fileName, wrapped, () => info); } else { + // If A.related points to B, B.related can't point to A or the stats emitter explodes + // So just strip the related object for the localized assets + info.related = undefined; + // We omit the `related` property that does a self-reference. + originInfo.related[locale] = fileName; // This helper throws if the asset already exists compilation.emitAsset(fileName, wrapped, info); }