-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(test-bundles): make the bundle-size flow generic to simplify local DX but most importantly CI #28210
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
Hotell
merged 6 commits into
microsoft:master
from
Hotell:hotell/ci/fix-size-auditor-pipelines-v2
Jun 15, 2023
Merged
feat(test-bundles): make the bundle-size flow generic to simplify local DX but most importantly CI #28210
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
888f9b9
feat(test-bundles): make old bundle-size generic enough to simplify C…
Hotell 182b89c
feat(test-bundles): replace jq cryptic script with custom merge script
Hotell 4e02694
ci: make size-auditor jobs valid
Hotell b84a445
fix(test-bundles): rename npm script to not confclit with v9 bundle-size
Hotell d033f08
ci: add back dependsOn for lightrail job
Hotell f9167c2
ci: remove commented scripts from pipeline
Hotell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,35 @@ | ||
| import { preset, task, resolveCwd } from '@fluentui/scripts-tasks'; | ||
| import * as path from 'path'; | ||
| import { preset, task, series } from '@fluentui/scripts-tasks'; | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore - parallel-webpack has no types | ||
| import { run } from 'parallel-webpack'; | ||
|
|
||
| import { bundleSizeCollect } from './scripts/bundle-size-collect'; | ||
| import { mergeBundleSizes } from './scripts/merge-bundlesizes'; | ||
|
|
||
| preset(); | ||
|
|
||
| // This pacakge doesn't currently have any files that are included in the eslint task | ||
| // (it only runs on src, not config files) | ||
| task('code-style', 'prettier'); | ||
|
|
||
| task('bundle-size-collect', () => { | ||
| const packageName = process.env.PACKAGE ?? ''; | ||
| bundleSizeCollect({ packageName }); | ||
| }); | ||
|
|
||
| task('bundle', done => { | ||
| run(resolveCwd('webpack.config.js'), {}, done); | ||
| const configPath = path.join(__dirname, 'webpack.config.js'); | ||
| const options = {}; | ||
| run(configPath, options, done); | ||
| }); | ||
|
|
||
| task('bundle-size-merge', () => { | ||
| const root = path.join(__dirname, 'dist'); | ||
| mergeBundleSizes( | ||
| [path.join(root, 'react/bundlesize.json'), path.join(root, 'react-northstar/bundlesize.json')], | ||
| path.join(root, 'bundlesizes.json'), | ||
| ); | ||
| }); | ||
|
|
||
| task('bundle-size', series('bundle', 'bundle-size-collect')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
|
|
||
| /** | ||
| * | ||
| * collates bundle size information from minified files in apps/test-bundles/dist/<packageName> and writes to apps/test-bundles/dist/<packageName>/bundlesizes.json. | ||
| * | ||
| * It is uploaded as an artifact by the build definition in Azure Dev Ops and used to compare baseline and PR file size information which gets reported by Size Auditor | ||
| */ | ||
| export function bundleSizeCollect(config: { packageName: string; filename?: string }) { | ||
| const { packageName, filename: outputFilename = 'bundlesize.json' } = config; | ||
|
|
||
| if (!packageName) { | ||
| throw new Error('🚨 No packageName provided! Set it via env variable name "PACKAGE"'); | ||
| } | ||
|
|
||
| const distRoot = path.join(__dirname, '../dist', packageName.replace('@fluentui/', '')); | ||
|
|
||
| const sizes: Record<string, number> = {}; | ||
|
|
||
| const items = fs.readdirSync(distRoot); | ||
| items.forEach(item => { | ||
| const file = path.join(distRoot, item); | ||
|
|
||
| const isMinifiedJavascriptFile = item.match(/.min.js$/); | ||
| if (isMinifiedJavascriptFile) { | ||
| sizes[getComponentName(item)] = getFilesizeInBytes(file); | ||
| } | ||
| }); | ||
|
|
||
| fs.writeFileSync(path.join(distRoot, outputFilename), JSON.stringify({ sizes })); | ||
|
|
||
| function getFilesizeInBytes(fileName: string) { | ||
| return fs.statSync(fileName).size; | ||
| } | ||
|
|
||
| function getComponentName(fileName: string) { | ||
| return path.basename(fileName, '.min.js'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import * as fs from 'fs'; | ||
|
|
||
| export function mergeBundleSizes(configPaths: string[], mergeConfigPath: string) { | ||
Hotell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const result: { sizes: { [entryName: string]: number } } = { | ||
| sizes: {}, | ||
| }; | ||
|
|
||
| configPaths.forEach(configPath => { | ||
| const json = JSON.parse(fs.readFileSync(configPath, 'utf-8')); | ||
| Object.assign(result.sizes, json.sizes); | ||
| }); | ||
|
|
||
| fs.writeFileSync(mergeConfigPath, JSON.stringify(result)); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.