1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
1
18
const { resolve } = require ( 'path' ) ;
2
19
const fs = require ( 'fs' ) ;
3
20
const { execSync } = require ( 'child_process' ) ;
@@ -19,6 +36,7 @@ function generateReportForCDNScripts() {
19
36
const special_files = [
20
37
'firebase-performance-standalone.es2017.js' ,
21
38
'firebase-performance-standalone.js' ,
39
+ 'firebase-firestore.memory.js' ,
22
40
'firebase.js'
23
41
] ;
24
42
@@ -58,12 +76,22 @@ function generateReportForNPMPackages() {
58
76
) ;
59
77
60
78
for ( const package of packageInfo ) {
61
- const packageJson = require ( `${ package . location } /package.json` ) ;
79
+ // we traverse the dir in order to include binaries for submodules, e.g. @firebase/firestore/memory
80
+ // Currently we only traverse 1 level deep because we don't have any submodule deeper than that.
81
+ traverseDirs ( package . location , collectBinarySize , 0 , 1 ) ;
82
+ }
83
+
84
+ function collectBinarySize ( path ) {
85
+ const packageJsonPath = `${ path } /package.json` ;
86
+ if ( ! fs . existsSync ( packageJsonPath ) ) {
87
+ return ;
88
+ }
89
+
90
+ const packageJson = require ( packageJsonPath ) ;
62
91
63
92
for ( const field of fields ) {
64
93
if ( packageJson [ field ] ) {
65
- const filePath = `${ package . location } /${ packageJson [ field ] } ` ;
66
-
94
+ const filePath = `${ path } /${ packageJson [ field ] } ` ;
67
95
const rawCode = fs . readFileSync ( filePath , 'utf-8' ) ;
68
96
69
97
// remove comments and whitespaces, then get size
@@ -84,6 +112,22 @@ function generateReportForNPMPackages() {
84
112
return reports ;
85
113
}
86
114
115
+ function traverseDirs ( path , executor , level , levelLimit ) {
116
+ if ( level > levelLimit ) {
117
+ return ;
118
+ }
119
+
120
+ executor ( path ) ;
121
+
122
+ for ( const name of fs . readdirSync ( path ) ) {
123
+ const p = `${ path } /${ name } ` ;
124
+
125
+ if ( fs . lstatSync ( p ) . isDirectory ( ) ) {
126
+ traverseDirs ( p , executor , level + 1 , levelLimit ) ;
127
+ }
128
+ }
129
+ }
130
+
87
131
function makeReportObject ( sdk , type , value ) {
88
132
return {
89
133
sdk,
0 commit comments