Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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,7 @@
{
"type": "patch",
"comment": "fix: bump workspace-tools and add options to collectLocalReport api",
"packageName": "@fluentui/bundle-size",
"email": "[email protected]",
"dependentChangeType": "patch"
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@
"json-schema": "0.4.0",
"json-stable-stringify-without-jsonify": "1.0.1",
"just-scripts": "1.8.2",
"lage": "1.7.4",
"lerna": "^3.21.0",
"lage": "1.8.8",
"lerna": "5.5.2",
"lint-staged": "10.2.10",
"loader-utils": "2.0.0",
"markdown-table": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/bundle-size/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"pretty-bytes": "^5.6.0",
"terser": "^5.5.1",
"webpack": "^5.21.2",
"workspace-tools": "^0.16.2",
"workspace-tools": "^0.27.0",
"ci-info": "^3.2.0",
"node-fetch": "^2.6.1",
"yargs": "^13.3.2"
Expand Down
13 changes: 9 additions & 4 deletions packages/bundle-size/src/utils/collectLocalReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@ async function readReportForPackage(reportFile) {
}
}

const collectLocalReportDefaultOptions = {
root: /** @type {string | undefined} */ (undefined),
reportFilesGlob: 'packages/**/dist/bundle-size/bundle-size.json',
};
/**
* Collects all reports for packages to a single one.
*
* @param {Partial<typeof collectLocalReportDefaultOptions>} options
* @return {Promise<BundleSizeReport>}
*/
async function collectLocalReport() {
/** @type {string[]} */
const reportFiles = glob.sync('packages/**/dist/bundle-size/bundle-size.json', {
cwd: /** @type {string} */ (findGitRoot(process.cwd())),
async function collectLocalReport(options = {}) {
const { reportFilesGlob, root = findGitRoot(process.cwd()) } = { ...collectLocalReportDefaultOptions, ...options };
const reportFiles = glob.sync(reportFilesGlob, {
cwd: root,
});

const reports = await Promise.all(reportFiles.map(readReportForPackage));
Expand Down
16 changes: 5 additions & 11 deletions packages/bundle-size/src/utils/collectLocalReport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ jest.mock('glob', () => ({

const collectLocalReport = require('./collectLocalReport');

/**
* @return {string}
*/
function mkPackagesDir() {
const projectDir = tmp.dirSync({ prefix: 'collectLocalReport', unsafeCleanup: true });
const packagesDir = tmp.dirSync({ dir: projectDir.name, name: 'packages', unsafeCleanup: true });
Expand All @@ -28,10 +25,7 @@ function mkPackagesDir() {
const spy = jest.spyOn(process, 'cwd');
spy.mockReturnValue(projectDir.name);

// is required as root directory is determined based on Git project
tmp.dirSync({ dir: projectDir.name, name: '.git', unsafeCleanup: true });

return packagesDir.name;
return { packagesDir: packagesDir.name, rootDir: projectDir.name };
}

/**
Expand All @@ -53,7 +47,7 @@ describe('collectLocalReport', () => {
});

it('aggregates all local reports to a single one', async () => {
const packagesDir = mkPackagesDir();
const { packagesDir, rootDir } = mkPackagesDir();

const reportAPath = mkReportDir(tmp.dirSync({ dir: packagesDir, name: 'package-a', unsafeCleanup: true }).name);
const reportBPath = mkReportDir(tmp.dirSync({ dir: packagesDir, name: 'package-b', unsafeCleanup: true }).name);
Expand All @@ -75,7 +69,7 @@ describe('collectLocalReport', () => {
await fs.writeFile(reportBPath, JSON.stringify(reportB));
await fs.writeFile(reportCPath, JSON.stringify(reportC));

expect(await collectLocalReport()).toMatchInlineSnapshot(`
expect(await collectLocalReport({ root: rootDir })).toMatchInlineSnapshot(`
Array [
Object {
"gzippedSize": 50,
Expand Down Expand Up @@ -110,7 +104,7 @@ describe('collectLocalReport', () => {
});

it('throws an error if a report file contains invalid JSON', async () => {
const packagesDir = mkPackagesDir();
const { packagesDir, rootDir } = mkPackagesDir();

const reportAPath = mkReportDir(tmp.dirSync({ dir: packagesDir, name: 'package-a', unsafeCleanup: true }).name);
const reportBPath = mkReportDir(tmp.dirSync({ dir: packagesDir, name: 'package-b', unsafeCleanup: true }).name);
Expand All @@ -127,6 +121,6 @@ describe('collectLocalReport', () => {
await fs.writeFile(reportBPath, JSON.stringify(reportB));
await fs.writeFile(reportCPath, JSON.stringify(reportC));

await expect(collectLocalReport()).rejects.toThrow(/Failed to read JSON/);
await expect(collectLocalReport({ root: rootDir })).rejects.toThrow(/Failed to read JSON/);
});
});
10 changes: 5 additions & 5 deletions packages/bundle-size/src/utils/readConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ describe('prepareFixture', () => {
it('should read config from package', async () => {
await setup(`module.exports = { webpack: (config) => { config.foo = 'bar'; return config; } }`);

const config = await readConfig();
const config = await readConfig(true);

expect(config.webpack({})).toEqual({ foo: 'bar' });
});

it('should return default webpack config if no config file defined', async () => {
const config = await readConfig();
const config = await readConfig(true);

expect(config.webpack({})).toEqual({});
});
Expand All @@ -49,9 +49,9 @@ describe('prepareFixture', () => {
process.env.NODE_ENV = 'nottest';

await setup(`module.exports = { webpack: (config) => config }`);
const firstConfig = await readConfig();
const firstConfig = await readConfig(true);
await setup(`module.exports = { webpack: (config) => { config.foo = 'bar'; return config; } }`);
const config = await readConfig();
const config = await readConfig(true);

expect(firstConfig).toBe(config);
expect(config.webpack({})).toEqual({});
Expand All @@ -61,7 +61,7 @@ describe('prepareFixture', () => {

it.each([1, 2, 3])('should cache config for %i layers of nesting', async nesting => {
await setup(`module.exports = { webpack: (config) => { config.foo = 'bar'; return config; } }`, nesting);
const config = await readConfig();
const config = await readConfig(true);

expect(config.webpack({})).toEqual({ foo: 'bar' });
});
Expand Down
Loading