Skip to content

Commit

Permalink
Merge pull request #4187 from relative-ci/fix-webpack-baseline-writing
Browse files Browse the repository at this point in the history
Fix webpack baseline writing
  • Loading branch information
vio authored Jan 24, 2024
2 parents f77d19f + 42deefd commit 8fd19f2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
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

0 comments on commit 8fd19f2

Please sign in to comment.