Skip to content
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

Fix webpack baseline writing #4187

Merged
merged 3 commits into from
Jan 24, 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
2 changes: 1 addition & 1 deletion packages/cli-utils/src/baseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const getBaselineRelativePath = (
filepath = '',
): string => {
const absoluteFilepath = getBaselinePath(outputPath, outputDir, filepath);
return path.relative(path.join(outputPath, outputDir), absoluteFilepath);
return path.relative(outputPath, absoluteFilepath);
};

export async function readBaseline(baselineFilepath: string): Promise<object> {
Expand Down
8 changes: 6 additions & 2 deletions packages/cli-utils/src/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ export const generateReports = async (
baselineStats = filter(baselineStatsData);

if (!options.silent) {
logger.info(`${TEXT.BASELINE_READING} ${baselinePath}`);
logger.info(`${TEXT.BASELINE_READING} ${baselinePath}.`);
}
} catch (err) {
logger.warn(TEXT.BASELINE_MISSING);
logger.warn(`${TEXT.BASELINE_READING} ${baselinePath}. ${TEXT.BASELINE_MISSING}`);
}
}

Expand Down Expand Up @@ -150,6 +150,10 @@ export const generateReports = async (
source: JSON.stringify(data),
filepath: baselineAbsolutePath,
};

if (!options.silent) {
logger.info(`${TEXT.BASELINE_WRITING} ${baselinePath}`);
}
}

const info = getReportInfo(report);
Expand Down
1 change: 1 addition & 0 deletions packages/cli-utils/src/text.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const BASELINE_MISSING = 'Baseline stats file is missing, see "baseline" option.';
export const BASELINE_READING = 'Reading baseline data from';
export const BASELINE_WRITING = 'Writing baseline data to';

export const CLI_NO_COMPARE_MODE = 'Not in compare mode (see --compare).';
export const CLI_MULTIPLE_STATS = 'Multiple stat files already set.';
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-plugin/src/__tests__/webpack-plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('webpack plugin', () => {
/* eslint-disable no-console */
expect(console.warn).not.toBeCalledWith('Missing baseline stats, see "baseline" option.');
expect(console.info).toBeCalledWith(
'Reading baseline data from ../node_modules/.cache/bundle-stats/baseline.json',
'Reading baseline data from ../node_modules/.cache/bundle-stats/baseline.json.',
);
expect(console.info).toBeCalledWith('Bundle Size — 27B (+35%).');
/* eslint-enable no-console */
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('webpack plugin', () => {

/* eslint-disable no-console */
expect(console.warn).not.toBeCalledWith('Missing baseline stats, see "baseline" option.');
expect(console.info).toBeCalledWith('Reading baseline data from custom-baseline.json');
expect(console.info).toBeCalledWith('Reading baseline data from custom-baseline.json.');
expect(console.info).toBeCalledWith('Bundle Size — 27B (+8%).');
/* eslint-enable no-console */

Expand Down
14 changes: 7 additions & 7 deletions packages/webpack-plugin/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ declare namespace BundleStatsWebpackPlugin {
builtAt?: Boolean;
}

interface Options extends ReportOptions {
interface Options extends Omit<ReportOptions, 'baselineFilepath', 'outDir'> {
/**
* Compare the current build stats with the saved baseline
*
* Custom baseline file path relative to webpack output directory (output.path)
* Default: `node_modules/.cache/bundle-stats/baseline.json`
*/
baseline?: boolean;
baselineFilepath?: string;

/**
* Custom baseline file path
* Default: node_modules/.cache/bundle-stats/baseline.json
* Output directory relative to webpack output directory (output.path)
* Default: `''`.
*/
baselineFilepath?: string;
outDir?: string;

/**
* webpack stats options
Expand Down