@@ -5,8 +5,6 @@ const traverse = require('@babel/traverse').default;
5
5
const execa = require ( 'execa' ) ;
6
6
7
7
const main = ( ) => {
8
- const sizeLimitConfig = [ ] ;
9
-
10
8
// Get all the components name exported from the bundle and add them to the size-limit configuration
11
9
const fileContent = fs . readFileSync (
12
10
path . resolve ( __dirname , '../build/lib/web/production/components/index.js' ) ,
@@ -18,71 +16,74 @@ const main = () => {
18
16
sourceType : 'module' ,
19
17
} ) ;
20
18
21
- const componentNameList = [ ] ;
19
+ const sizes = [ ] ;
20
+ const excludedComponents = [
21
+ 'useTheme' ,
22
+ 'BladeProvider' ,
23
+ 'announce' ,
24
+ 'clearAnnouncer' ,
25
+ 'destroyAnnouncer' ,
26
+ 'getTextProps' ,
27
+ 'screenReaderStyles' ,
28
+ 'useActionListContext' ,
29
+ ] ;
22
30
23
31
// Traverse the AST to get the component names
24
32
traverse ( ast , {
25
33
// Get the component name from the export statement
26
34
ExportSpecifier : ( { node } ) => {
27
35
const componentName = node . exported . name ;
28
36
// We don't want to add Icon components to the size-limit configuration
29
- // We don't want to add the same component name twice, so we'll check if it's already added
30
- if ( ! ( componentName . includes ( 'Icon' ) || componentNameList . includes ( componentName ) ) ) {
31
- componentNameList . push ( componentName ) ;
32
- sizeLimitConfig . push ( {
33
- name : componentName ,
34
- path : './build/lib/web/production/components/index.js' ,
35
- import : `{ ${ componentName } }` ,
36
- // Set high limit for the component size so that it doesn't fail the size-limit check
37
- limit : '200 kb' ,
38
- running : false ,
39
- gzip : true ,
40
- } ) ;
37
+ if ( ! ( componentName . includes ( 'Icon' ) || excludedComponents . includes ( componentName ) ) ) {
38
+ console . log ( '🚀 Analyzing: ' , componentName ) ;
39
+
40
+ fs . writeFileSync (
41
+ path . resolve ( __dirname , '../.size-limit.json' ) ,
42
+ JSON . stringify (
43
+ [
44
+ {
45
+ name : componentName ,
46
+ path : './build/lib/web/production/components/index.js' ,
47
+ import : `{ ${ componentName } }` ,
48
+ // Set high limit for the component size so that it doesn't fail the size-limit check
49
+ limit : '200 kb' ,
50
+ running : false ,
51
+ gzip : true ,
52
+ } ,
53
+ ] ,
54
+ null ,
55
+ 2 ,
56
+ ) ,
57
+ ) ;
58
+
59
+ const { stdout } = execa . commandSync ( 'yarn size-limit --json' ) ;
60
+
61
+ const jsonLikeString = stdout
62
+ . split ( '\n' ) // remove new line chars => []
63
+ . map ( ( item ) => item . trim ( ) ) // remove whitespace
64
+ . filter ( ( item ) => item !== '' ) // filter empty array items
65
+ . join ( '' ) ;
66
+
67
+ sizes . push (
68
+ JSON . parse (
69
+ jsonLikeString . substring ( jsonLikeString . indexOf ( '[' ) + 1 , jsonLikeString . indexOf ( ']' ) ) ,
70
+ ) ,
71
+ ) ;
41
72
}
42
73
} ,
43
74
} ) ;
44
75
45
- // All components import
46
- sizeLimitConfig . unshift ( {
47
- name : '*' ,
48
- path : './build/lib/web/production/components/index.js' ,
49
- import : '*' ,
50
- limit : '200 kb' ,
51
- running : false ,
52
- gzip : true ,
53
- } ) ;
54
-
55
- fs . writeFileSync (
56
- path . resolve ( __dirname , '../.size-limit.json' ) ,
57
- JSON . stringify ( sizeLimitConfig , null , 2 ) ,
76
+ const story = fs . readFileSync (
77
+ path . resolve ( __dirname , '../docs/utils/bundleSizeReport.stories.mdx' ) ,
78
+ 'utf-8' ,
58
79
) ;
59
80
60
- // Run the size-limit command
61
- try {
62
- const { stdout } = execa . commandSync ( 'yarn size-limit --json' ) ;
63
-
64
- const jsonLikeString = stdout
65
- . split ( '\n' ) // remove new line chars => []
66
- . map ( ( item ) => item . trim ( ) ) // remove whitespace
67
- . filter ( ( item ) => item !== '' ) // filter empty array items
68
- . join ( '' ) ;
81
+ const updatedStory = story . replace ( / B U N D L E _ S I Z E _ D A T A / g, JSON . stringify ( sizes ) ) ;
69
82
70
- const sizes = JSON . parse (
71
- jsonLikeString . substring ( jsonLikeString . indexOf ( '[' ) , jsonLikeString . indexOf ( ']' ) + 1 ) ,
72
- ) ;
73
-
74
- const story = fs . readFileSync (
75
- path . resolve ( __dirname , '../docs/utils/bundleSizeReport.stories.mdx' ) ,
76
- 'utf-8' ,
77
- ) ;
78
- const updatedStory = story . replace ( / B U N D L E _ S I Z E _ D A T A / g, JSON . stringify ( sizes ) ) ;
79
- fs . writeFileSync (
80
- path . resolve ( __dirname , '../docs/utils/bundleSizeReport.stories.mdx' ) ,
81
- updatedStory ,
82
- ) ;
83
- } catch ( error ) {
84
- throw new Error ( error ) ;
85
- }
83
+ fs . writeFileSync (
84
+ path . resolve ( __dirname , '../docs/utils/bundleSizeReport.stories.mdx' ) ,
85
+ updatedStory ,
86
+ ) ;
86
87
} ;
87
88
88
89
main ( ) ;
0 commit comments