Skip to content

Commit ce26ee3

Browse files
committed
Code cleanup.
1 parent a2a8b04 commit ce26ee3

3 files changed

Lines changed: 21 additions & 22 deletions

File tree

webpack/localization-plugin/src/LocFilePreprocessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class LocFilePreprocessor {
110110
let indent: string = '';
111111
if (this._options.exportAsDefault) {
112112
outputLines.push(
113-
'interface IStrings {'
113+
'export interface IStrings {'
114114
);
115115

116116
indent = ' ';

webpack/localization-plugin/src/LocalizationPlugin.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,8 @@ export class LocalizationPlugin implements Webpack.Plugin {
161161
}
162162

163163
for (const chunk of chunkGroup.chunks) {
164-
// Clone the chunk files array because we're going to modify it
165-
const chunkFiles: string[] = [...chunk.files];
166-
const chunkFilesSet: Set<string> = new Set(chunkFiles);
167-
for (const chunkFileName of chunkFiles) {
164+
const chunkFilesSet: Set<string> = new Set(chunk.files);
165+
for (const chunkFileName of chunk.files) {
168166
if (
169167
chunkFileName.match(Constants.LOCALE_FILENAME_PLACEHOLDER_REGEX) && // Ensure this is expected to be localized
170168
chunkFileName.endsWith('.js') && // Ensure this is a JS file

webpack/set-webpack-public-path-plugin/src/SetPublicPathPlugin.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,7 @@ export class SetPublicPathPlugin implements Webpack.Plugin {
164164
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation: Webpack.compilation.Compilation) => {
165165
const v4MainTemplate: IV4MainTemplate = compilation.mainTemplate as IV4MainTemplate;
166166
v4MainTemplate.hooks.startup.tap(PLUGIN_NAME, (source: string, chunk: IV4Chunk, hash: string) => {
167-
let assetOrChunkFound: boolean = !!this.options.skipDetection;
168-
169-
if (!assetOrChunkFound) {
170-
for (const chunkGroup of chunk.groupsIterable) {
171-
const children: Webpack.compilation.Chunk[] = chunkGroup.getChildren();
172-
assetOrChunkFound = assetOrChunkFound || (children.length > 0);
173-
}
174-
}
175-
176-
if (!assetOrChunkFound) {
177-
for (const innerModule of chunk.modulesIterable) {
178-
if (innerModule.buildInfo.assets && Object.keys(innerModule.buildInfo.assets).length > 0) {
179-
assetOrChunkFound = true;
180-
}
181-
}
182-
}
183-
167+
const assetOrChunkFound: boolean = !!this.options.skipDetection || this._detectAssetsOrChunks(chunk);
184168
if (assetOrChunkFound) {
185169
return this._getStartupCode({
186170
source,
@@ -247,6 +231,23 @@ export class SetPublicPathPlugin implements Webpack.Plugin {
247231
}
248232
}
249233

234+
private _detectAssetsOrChunks(chunk: IV4Chunk): boolean {
235+
for (const chunkGroup of chunk.groupsIterable) {
236+
const children: Webpack.compilation.Chunk[] = chunkGroup.getChildren();
237+
if (children.length > 0) {
238+
return true;
239+
}
240+
}
241+
242+
for (const innerModule of chunk.modulesIterable) {
243+
if (innerModule.buildInfo.assets && Object.keys(innerModule.buildInfo.assets).length > 0) {
244+
return true;
245+
}
246+
}
247+
248+
return false;
249+
}
250+
250251
private _getStartupCode(options: IStartupCodeOptions): string {
251252
const moduleOptions: IInternalOptions = cloneDeep(this.options);
252253

0 commit comments

Comments
 (0)