Skip to content

Commit 17e3e61

Browse files
authored
include firestore memory builds and sub modules in the size report (#2798)
* include firestore memory builds and sub modules in size report * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers
1 parent faa9fc6 commit 17e3e61

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

scripts/report_binary_size.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
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+
118
const { resolve } = require('path');
219
const fs = require('fs');
320
const { execSync } = require('child_process');
@@ -19,6 +36,7 @@ function generateReportForCDNScripts() {
1936
const special_files = [
2037
'firebase-performance-standalone.es2017.js',
2138
'firebase-performance-standalone.js',
39+
'firebase-firestore.memory.js',
2240
'firebase.js'
2341
];
2442

@@ -58,12 +76,22 @@ function generateReportForNPMPackages() {
5876
);
5977

6078
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);
6291

6392
for (const field of fields) {
6493
if (packageJson[field]) {
65-
const filePath = `${package.location}/${packageJson[field]}`;
66-
94+
const filePath = `${path}/${packageJson[field]}`;
6795
const rawCode = fs.readFileSync(filePath, 'utf-8');
6896

6997
// remove comments and whitespaces, then get size
@@ -84,6 +112,22 @@ function generateReportForNPMPackages() {
84112
return reports;
85113
}
86114

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+
87131
function makeReportObject(sdk, type, value) {
88132
return {
89133
sdk,

0 commit comments

Comments
 (0)