10000 Fix an issue with split chunks not being marked as localized. · rbuckton/rushstack@0186908 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0186908

Browse files
committed
Fix an issue with split chunks not being marked as localized.
1 parent d788452 commit 0186908

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

webpack/localization-plugin/src/LocalizationPlugin.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -239,36 +239,14 @@ export class LocalizationPlugin implements Webpack.Plugin {
239239
return;
240240
}
241241

242-
// First pass - see if the chunk directly contains any loc modules
243242
for (const chunk of chunks) {
244-
let chunkHasAnyLocModules: boolean = false;
245-
if (!chunkHasAnyLocModules) {
246-
for (const module of chunk.getModules()) {
247-
if (EntityMarker.getMark(module)) {
248-
chunkHasAnyLocModules = true;
249-
break;
250-
}
251-
}
252-
}
253-
254-
EntityMarker.markEntity(chunk, chunkHasAnyLocModules);
255-
}
256-
257-
// Second pass - see if the chunk loads any localized chunks
258-
for (const chunk of chunks) {
259-
let localizedChunk: boolean = EntityMarker.getMark(chunk);
260-
if (
261-
!localizedChunk &&
262-
Array.from(chunk.getAllAsyncChunks()).some((asyncChunk) => EntityMarker.getMark(asyncChunk))
263-
) {
264-
localizedChunk = true;
265-
EntityMarker.markEntity(chunk, true);
266-
}
243+
// See if the chunk contains any localized modules or loads any localized chunks
244+
const localizedChunk: boolean = this._chunkHasLocalizedModules(chunk);
267245

246+
// Change the chunk's name to include either the locale name or the locale name for chunks without strings
268247
const replacementValue: string = localizedChunk
269248
? Constants.LOCALE_NAME_PLACEHOLDER
270249
: this._noStringsLocaleName;
271-
EntityMarker.markEntity(chunk, localizedChunk);
272250
if (chunk.hasRuntime()) {
273251
chunk.filenameTemplate = (compilation.options.output!.filename as string).replace(
274252
Constants.LOCALE_FILENAME_PLACEHOLDER_REGEX,
@@ -314,7 +292,7 @@ export class LocalizationPlugin implements Webpack.Plugin {
314292
}
315293
}
316294

317-
if (EntityMarker.getMark(chunk)) {
295+
if (this._chunkHasLocalizedModules(chunk)) {
318296
processChunkJsFile((chunkFilename) => {
319297
if (chunkFilename.indexOf(Constants.LOCALE_NAME_PLACEHOLDER) === -1) {
320298
throw new Error(`Asset ${chunkFilename} is expected to be localized, but is missing a locale placeholder`);
@@ -655,4 +633,31 @@ export class LocalizationPlugin implements Webpack.Plugin {
655633
suffix: suffix
656634
};
657635
}
636+
637+
private _chunkHasLocalizedModules(chunk: Webpack.compilation.Chunk): boolean {
638+
if (EntityMarker.getMark(chunk) === undefined) {
639+
let chunkHasAnyLocModules: boolean = false;
640+
if (!chunkHasAnyLocModules) {
641+
for (const module of chunk.getModules()) {
642+
if (EntityMarker.getMark(module)) {
643+
chunkHasAnyLocModules = true;
644+
break;
645+
}
646+
}
647+
}
648+
649+
if (!chunkHasAnyLocModules) {
650+
for (const asyncChunk of chunk.getAllAsyncChunks()) {
651+
if (this._chunkHasLocalizedModules(asyncChunk)) {
652+
chunkHasAnyLocModules = true;
653+
break;
654+
}
655+
}
656+
}
657+
658+
EntityMarker.markEntity(chunk, chunkHasAnyLocModules);
659+
}
660+
661+
return EntityMarker.getMark(chunk)!;
662+
}
658663
}

webpack/localization-plugin/src/utilities/EntityMarker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class EntityMarker {
1111
module[LABEL] = value;
1212
}
1313

14-
public static getMark<TModule>(module: TModule): boolean {
15-
return !!module[LABEL];
14+
public static getMark<TModule>(module: TModule): boolean | undefined {
15+
return module[LABEL];
1616
}
1717
}

0 commit comments

Comments
 (0)
0