Skip to content

[localization-plugin] Include webpack compilation in stats callback #4854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/webpack5-localization-plugin",
"comment": "Include webpack compilation in localizationStats callback.",
"type": "minor"
}
],
"packageName": "@rushstack/webpack5-localization-plugin"
}
3 changes: 2 additions & 1 deletion common/reviews/api/webpack5-localization-plugin.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/// <reference types="node" />

import type { Chunk } from 'webpack';
import type { Compilation } from 'webpack';
import type { Compiler } from 'webpack';
import { ILocalizationFile } from '@rushstack/localization-utilities';
import type { IPseudolocaleOptions } from '@rushstack/localization-utilities';
Expand Down Expand Up @@ -77,7 +78,7 @@ export interface ILocalizationStatsEntrypoint {

// @public
export interface ILocalizationStatsOptions {
callback?: (stats: ILocalizationStats) => void;
callback?: (stats: ILocalizationStats, compilation: Compilation) => void;
dropPath?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ export class LocalizationPlugin implements WebpackPluginInstance {

if (callback) {
try {
callback(localizationStats);
callback(localizationStats, compilation);
} catch (e) {
/* swallow errors from the callback */
}
Expand Down
6 changes: 3 additions & 3 deletions webpack/webpack5-localization-plugin/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import type { LoaderContext } from 'webpack';
import type { LoaderContext, Compilation } from 'webpack';
import type { IPseudolocaleOptions } from '@rushstack/localization-utilities';

/**
Expand Down Expand Up @@ -97,9 +97,9 @@ export interface ILocalizationStatsOptions {

/**
* This option is used to specify a callback to be called with the stats data that would be
* dropped at `localizationStats.dropPath` after compilation completes.
* dropped at `localizationStats.dropPath` after compilation completes, and the compilation instance.
*/
callback?: (stats: ILocalizationStats) => void;
callback?: (stats: ILocalizationStats, compilation: Compilation) => void;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async function testLocalizedNoAsyncInner(minimize: boolean): Promise<void> {
'/'
);

let compilationInStats: webpack.Compilation | undefined;
const resJsonLoader: string = resolve(__dirname, '../loaders/resjson-loader.js');
const options: ILocalizationPluginOptions = {
localizedData: {
Expand All @@ -53,7 +54,10 @@ async function testLocalizedNoAsyncInner(minimize: boolean): Promise<void> {
}
},
localizationStats: {
dropPath: 'localization-stats.json'
dropPath: 'localization-stats.json',
callback: (stats, compilation) => {
compilationInStats = compilation;
}
},
realContentHash: true
};
Expand Down Expand Up @@ -109,6 +113,9 @@ async function testLocalizedNoAsyncInner(minimize: boolean): Promise<void> {

expect(errors).toHaveLength(0);
expect(warnings).toHaveLength(0);

expect(compilationInStats).toBeDefined();
expect(compilationInStats).toBeInstanceOf(webpack.Compilation);
}

describe(LocalizationPlugin.name, () => {
Expand Down
Loading