Skip to content

Commit 82ed063

Browse files
authored
[code-infra] Add bundle size monitor (#17754)
1 parent cfeb654 commit 82ed063

File tree

14 files changed

+2055
-391
lines changed

14 files changed

+2055
-391
lines changed

.circleci/config.yml

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,38 @@ jobs:
307307
command: pnpm test:e2e-website
308308
environment:
309309
PLAYWRIGHT_TEST_BASE_URL: << parameters.e2e-base-url >>
310+
311+
test_package:
312+
<<: *default-job
313+
steps:
314+
- checkout
315+
- install_js:
316+
react-version: << parameters.react-version >>
317+
318+
- run:
319+
name: prepare danger on PRs
320+
command: pnpm danger ci
321+
environment:
322+
DANGER_COMMAND: prepareBundleSizeReport
323+
324+
- run:
325+
name: Build packages
326+
command: pnpm release:build
327+
328+
- run:
329+
name: create and upload a size snapshot
330+
command: |
331+
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID_ARTIFACTS
332+
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY_ARTIFACTS
333+
export AWS_REGION=$AWS_REGION_ARTIFACTS
334+
pnpm size:snapshot
335+
336+
- run:
337+
name: Run danger on PRs
338+
command: pnpm danger ci --fail-on-errors
339+
environment:
340+
DANGER_COMMAND: reportBundleSize
341+
310342
test_regressions:
311343
<<: *default-job
312344
steps:
@@ -320,14 +352,7 @@ jobs:
320352
- run:
321353
name: Upload screenshots to Argos CI
322354
command: pnpm test:argos
323-
run_danger:
324-
<<: *default-job
325-
steps:
326-
- checkout
327-
- install_js
328-
- run:
329-
name: Run danger on PRs
330-
command: pnpm danger ci --fail-on-errors
355+
331356
workflows:
332357
pipeline:
333358
when:
@@ -349,7 +374,7 @@ workflows:
349374
<<: *default-context
350375
- test_regressions:
351376
<<: *default-context
352-
- run_danger:
377+
- test_package:
353378
<<: *default-context
354379
e2e-website:
355380
when:

.eslintrc.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,6 @@ module.exports = {
223223
'packages/x-data-grid-premium/**/*{.tsx,.ts,.js}',
224224
'docs/src/pages/**/*.tsx',
225225
],
226-
excludedFiles: [
227-
'packages/x-data-grid/src/themeAugmentation/index.js', // TypeScript ignores JS files with the same name as the TS file
228-
'packages/x-data-grid-pro/src/themeAugmentation/index.js',
229-
'packages/x-data-grid-premium/src/themeAugmentation/index.js',
230-
],
231226
rules: {
232227
'material-ui/no-direct-state-access': 'error',
233228
},

dangerfile.js

Lines changed: 6 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,7 @@
1-
const { danger, markdown } = require('danger');
1+
// eslint-disable-next-line import/no-unresolved
2+
const tsx = require('tsx/cjs/api');
23

3-
function addDeployPreviewUrls() {
4-
/**
5-
* The incoming docsPath from danger does not start with `/`
6-
* e.g. ['docs/data/data-grid/editing/editing.md']
7-
*/
8-
function formatFileToLink(docsPath) {
9-
const url = docsPath.replace('docs/data', 'x').replace(/\/[^/]+\.md$/, '/');
10-
11-
return url
12-
.replace('data-grid/', 'react-data-grid/')
13-
.replace('date-pickers/', 'react-date-pickers/')
14-
.replace('charts/', 'react-charts/')
15-
.replace('scheduler/', 'react-scheduler/')
16-
.replace('tree-view/', 'react-tree-view/')
17-
.replace(/\/[^/]+\.md$/, '/');
18-
}
19-
20-
const netlifyPreview = `https://deploy-preview-${danger.github.pr.number}--material-ui-x.netlify.app/`;
21-
22-
const files = [...danger.git.created_files, ...danger.git.modified_files];
23-
24-
// limit to the first 5 docs
25-
const docs = files
26-
.filter((file) => file.startsWith('docs/data') && file.endsWith('.md'))
27-
.slice(0, 5);
28-
29-
markdown(`**Deploy preview:** <a href="${netlifyPreview}">${netlifyPreview}</a>`);
30-
31-
if (docs.length) {
32-
markdown(`
33-
34-
**Updated pages:**
35-
36-
${docs
37-
.map((docsPath) => {
38-
const formattedUrl = formatFileToLink(docsPath);
39-
return `- [${docsPath}](${netlifyPreview}${formattedUrl})`;
40-
})
41-
.join('\n')}
42-
`);
43-
}
44-
}
45-
46-
function addL10nHelpMessage() {
47-
const isAddingLocale = danger.git.created_files.some((file) => file.includes('/src/locales/'));
48-
const isUpdatingLocale = danger.git.modified_files.some((file) => file.includes('/src/locales/'));
49-
50-
if (!isAddingLocale && !isUpdatingLocale) {
51-
return;
52-
}
53-
markdown(
54-
[
55-
'## Localization writing tips :writing_hand:',
56-
'',
57-
'Seems you are updating localization :earth_africa: files.',
58-
'',
59-
'Thank you for contributing to the localization! :tada: To make your PR perfect, here is a list of elements to check: :heavy_check_mark:',
60-
'- [ ] Verify if the PR title respects the release format. Here are two examples (depending if you update or add a locale file)',
61-
' > [l10n] Improve Swedish (sv-SE) locale',
62-
' > [l10n] Add Danish (da-DK) locale',
63-
'- [ ] Update the documentation of supported locales by running `pnpm l10n`',
64-
...(isAddingLocale
65-
? [
66-
'- [ ] Verify that you have added an export line in `src/locales/index.ts` for the new locale.',
67-
'- [ ] Run `pnpm docs:api` which should add your new translation to the list of exported interfaces.',
68-
]
69-
: []),
70-
'- [ ] Clean files with `pnpm prettier`.',
71-
'',
72-
].join('\n'),
73-
);
74-
}
75-
76-
async function run() {
77-
addL10nHelpMessage();
78-
addDeployPreviewUrls();
79-
}
80-
81-
run().catch((error) => {
82-
console.error(error);
83-
process.exit(1);
84-
});
4+
// danger uses babelify under the hood. The implementation is buggy and fails on our
5+
// custom plugins in our codebase. We'll just disable it and do our own compilation.
6+
// Danger must always be run with envirnonent variable `DANGER_DISABLE_TRANSPILATION="true"`.
7+
tsx.require('./scripts/dangerfileContent', __filename);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"prettier:all": "prettier --write . --ignore-path .eslintignore",
3131
"prettier:check": "prettier --check . --ignore-path .eslintignore",
3232
"proptypes": "tsx ./docs/scripts/generateProptypes.ts",
33-
"size:snapshot": "node --max-old-space-size=2048 ./scripts/sizeSnapshot/create",
33+
"size:snapshot": "pnpm -F ./test/bundle-size check",
3434
"size:why": "pnpm size:snapshot --analyze --accurateBundles",
3535
"test": "pnpm test:unit:jsdom",
3636
"test:jsdom": "pnpm test:unit:jsdom",
@@ -87,6 +87,7 @@
8787
"@mui/icons-material": "^7.0.2",
8888
"@mui/internal-babel-plugin-display-name": "github:mui/mui-public#master&path:./packages/babel-plugin-display-name",
8989
"@mui/internal-babel-plugin-resolve-imports": "^2.0.2",
90+
"@mui/internal-bundle-size-checker": "^1.0.3",
9091
"@mui/internal-markdown": "^2.0.5",
9192
"@mui/internal-test-utils": "^2.0.8",
9293
"@mui/material": "^7.0.2",

packages/x-data-grid-premium/src/themeAugmentation/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/x-data-grid-pro/src/themeAugmentation/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)