Skip to content

include firestore memory builds and sub modules in the size report #2798

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
merged 3 commits into from
Mar 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions scripts/report_binary_size.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const { resolve } = require('path');
const fs = require('fs');
const { execSync } = require('child_process');
Expand All @@ -19,6 +36,7 @@ function generateReportForCDNScripts() {
const special_files = [
'firebase-performance-standalone.es2017.js',
'firebase-performance-standalone.js',
'firebase-firestore.memory.js',
'firebase.js'
];

Expand Down Expand Up @@ -58,12 +76,22 @@ function generateReportForNPMPackages() {
);

for (const package of packageInfo) {
const packageJson = require(`${package.location}/package.json`);
// we traverse the dir in order to include binaries for submodules, e.g. @firebase/firestore/memory
// Currently we only traverse 1 level deep because we don't have any submodule deeper than that.
traverseDirs(package.location, collectBinarySize, 0, 1);
}

function collectBinarySize(path) {
const packageJsonPath = `${path}/package.json`;
if (!fs.existsSync(packageJsonPath)) {
return;
}

const packageJson = require(packageJsonPath);

for (const field of fields) {
if (packageJson[field]) {
const filePath = `${package.location}/${packageJson[field]}`;

const filePath = `${path}/${packageJson[field]}`;
const rawCode = fs.readFileSync(filePath, 'utf-8');

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

function traverseDirs(path, executor, level, levelLimit) {
if (level > levelLimit) {
return;
}

executor(path);

for (const name of fs.readdirSync(path)) {
const p = `${path}/${name}`;

if (fs.lstatSync(p).isDirectory()) {
traverseDirs(p, executor, level + 1, levelLimit);
}
}
}

function makeReportObject(sdk, type, value) {
return {
sdk,
Expand Down