Skip to content

Fix health metrics #5509

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 9 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/messaging/sw/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@firebase/messaging",
"name": "@firebase/messaging-sw",
"description": "",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"module": "../dist/index.sw.esm2017.js",
Expand Down
445 changes: 79 additions & 366 deletions repo-scripts/size-analysis/analysis-helper.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions repo-scripts/size-analysis/bundle-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { bundleWithRollup } from './bundle/rollup';
import { bundleWithWebpack } from './bundle/webpack';
import { calculateContentSize } from './util';
import { minify } from './bundle/minify';
import { extractDeclarations, MemberList } from './analysis-helper';
import { extractAllTopLevelSymbols, MemberList } from './analysis-helper';

interface BundleAnalysisArgs {
input: string;
Expand Down Expand Up @@ -392,7 +392,7 @@ async function analyzeBundleWithBundler(
analysisResult.debugInfo = {
pathToBundle: bundleFilePath,
pathToMinifiedBundle: minifiedBundleFilePath,
dependencies: extractDeclarations(bundleFilePath)
dependencies: extractAllTopLevelSymbols(bundleFilePath)
};
}

Expand Down
4 changes: 2 additions & 2 deletions repo-scripts/size-analysis/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ yargs
type: 'array',
alias: 'im',
desc:
'The name of the module(s) to be analyzed. example: --inputModule "@firebase/functions-exp" "firebase/auth-exp"'
'The name of the module(s) to be analyzed. example: --inputModule "@firebase/functions" "firebase/auth"'
},
inputDtsFile: {
type: 'string',
Expand Down Expand Up @@ -90,4 +90,4 @@ yargs
// eslint-disable-next-line @typescript-eslint/no-explicit-any
argv => runBundleAnalysis(argv as any)
)
.help().argv;
.help().parseSync();
5 changes: 5 additions & 0 deletions repo-scripts/size-analysis/package-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export async function analyzePackageSize(
`${projectRoot}/packages/*`
]);
allModulesLocation = allModulesLocation.filter(path => {
const pkgJsonPath = `${path}/package.json`;
if (!fs.existsSync(pkgJsonPath)){
return false;
}

const json = JSON.parse(
fs.readFileSync(`${path}/package.json`, { encoding: 'utf-8' })
);
Expand Down
2 changes: 1 addition & 1 deletion repo-scripts/size-analysis/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);

const nodeInternals = ['fs', 'path'];
const nodeInternals = ['fs', 'path', 'util'];

export default [
{
Expand Down
57 changes: 27 additions & 30 deletions repo-scripts/size-analysis/test/size-analysis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import { expect } from 'chai';

import {
extractDeclarations,
MemberList,
dedup,
mapSymbolToType,
Expand All @@ -27,8 +26,9 @@ import {
ErrorCode,
writeReportToDirectory,
extractExternalDependencies,
buildMap,
Report
Report,
extractExports,
extractAllTopLevelSymbols
} from '../analysis-helper';

import {
Expand All @@ -39,14 +39,14 @@ import {
import * as fs from 'fs';
import { resolve } from 'path';

describe('extractDeclarations on .d.ts file', () => {
describe('extractExports', () => {
let testModuleDtsFile: string;
let extractedDeclarations: MemberList;
before(() => {
const start = Date.now();
testModuleDtsFile = getTestModuleDtsFilePath();
extractedDeclarations = extractDeclarations(testModuleDtsFile);
console.log('extractDeclarations on .d.ts file took ', Date.now() - start);
extractedDeclarations = extractExports(testModuleDtsFile);
console.log('extractExports took ', Date.now() - start);
});
// export {tar as tarr, tar1 as tarr1} from '..'
it('test export rename', () => {
Expand Down Expand Up @@ -187,42 +187,34 @@ describe('extractDeclarations on .d.ts file', () => {
});

// import * as fs from 'fs'
// import * as tmp from 'tmp'
// export declare const aVar: tmp.FileOptions;
// export { fs as fs1 };
it('test namespace export', () => {
expect(extractedDeclarations.variables).to.include.members(['fs1']);
expect(extractedDeclarations.variables).to.not.include.members(['tmp']);
expect(extractedDeclarations.variables).to.include.members(['aVar']);
expect(extractedDeclarations.unknown).to.include.members(['fs1']);
});
});
describe('extractDeclarations on js bundle file', () => {

describe('extractAllTopLevelSymbols', () => {
let subsetExportsBundleFile: string;
let extractedDeclarations: MemberList;
before(function () {
this.timeout(120000);
const start = Date.now();
const testModuleDtsFile: string = getTestModuleDtsFilePath();
const map: Map<string, string> = buildMap(
extractDeclarations(testModuleDtsFile)
);
subsetExportsBundleFile = getSubsetExportsBundleFilePath();
extractedDeclarations = extractDeclarations(subsetExportsBundleFile, map);
extractedDeclarations = extractAllTopLevelSymbols(subsetExportsBundleFile);
console.log(
'extractDeclarations on js bundle file took ',
Date.now() - start
);
});
it('test variable extractions', () => {
const variablesArray = ['aVar', 'fs1'];
const variablesArray = ['aVar'];
variablesArray.sort();
expect(extractedDeclarations.variables).to.have.members(variablesArray);
expect(extractedDeclarations.variables).to.include.members(variablesArray);
});

it('test functions extractions', () => {
const functionsArray = [
'tar',
'tarr1',
'tar1',
'basicFuncExportEnumDependencies',
'd1',
'd2',
Expand All @@ -236,16 +228,15 @@ describe('extractDeclarations on js bundle file', () => {
it('test enums extractions', () => {
const enumsArray = [
'BasicEnumExport',
'LogLevel2',
'BasicEnumExportBar',
'BasicEnumExportFar'
];
enumsArray.sort();
expect(extractedDeclarations.enums).to.have.members(enumsArray);
expect(extractedDeclarations.variables).to.include.members(enumsArray);
});

it('test classes extractions', () => {
const classesArray = ['Logger1'];
const classesArray = ['BasicClassExport'];
classesArray.sort();
expect(extractedDeclarations.classes).to.have.members(classesArray);
});
Expand All @@ -257,7 +248,8 @@ describe('test dedup helper function', () => {
functions: ['aFunc', 'aFunc', 'bFunc', 'cFunc'],
classes: ['aClass', 'bClass', 'aClass', 'cClass'],
variables: ['aVar', 'bVar', 'cVar', 'aVar'],
enums: ['aEnum', 'bEnum', 'cEnum', 'dEnum']
enums: ['aEnum', 'bEnum', 'cEnum', 'dEnum'],
unknown: []
};
memberList = dedup(memberList);

Expand Down Expand Up @@ -287,7 +279,8 @@ describe('test dedup helper function', () => {
functions: [],
classes: [],
variables: ['aVar', 'bVar', 'cVar', 'aVar'],
enums: []
enums: [],
unknown: []
};
memberList = dedup(memberList);
expect(memberList.functions).to.have.length(0);
Expand All @@ -308,7 +301,8 @@ describe('test replaceAll helper function', () => {
functions: ['aFunc', 'aFunc', 'bFunc', 'cFunc'],
classes: ['aClass', 'bClass', 'aClass', 'cClass'],
variables: ['aVar', 'bVar', 'cVar', 'aVar'],
enums: ['aEnum', 'bEnum', 'cEnum', 'dEnum']
enums: ['aEnum', 'bEnum', 'cEnum', 'dEnum'],
unknown: []
};
const original: string = 'aFunc';
const replaceTo: string = 'replacedFunc';
Expand All @@ -331,7 +325,8 @@ describe('test replaceAll helper function', () => {
functions: ['aFunc', 'aFunc', 'bFunc', 'cFunc'],
classes: ['aClass', 'bClass', 'aClass', 'cClass'],
variables: ['aVar', 'bVar', 'cVar', 'aVar'],
enums: ['aEnum', 'bEnum', 'cEnum', 'dEnum']
enums: ['aEnum', 'bEnum', 'cEnum', 'dEnum'],
unknown: []
};
const replaceTo: string = 'replacedClass';
const original: string = 'bClass';
Expand All @@ -354,7 +349,8 @@ describe('test replaceAll helper function', () => {
functions: ['aFunc', 'aFunc', 'bFunc', 'cFunc'],
classes: ['aClass', 'bClass', 'aClass', 'cClass'],
variables: ['aVar', 'bVar', 'cVar', 'aVar'],
enums: ['aEnum', 'bEnum', 'cEnum', 'dEnum']
enums: ['aEnum', 'bEnum', 'cEnum', 'dEnum'],
unknown: []
};
const replaceTo: string = 'replacedEnum';
const original: string = 'eEnum';
Expand All @@ -377,7 +373,8 @@ describe('test mapSymbolToType helper function', () => {
functions: ['aVar', 'bFunc', 'cFunc'],
classes: ['bClass', 'cClass'],
variables: ['aClass', 'bVar', 'cVar', 'aEnum'],
enums: ['bEnum', 'cEnum', 'dEnum', 'aFunc']
enums: ['bEnum', 'cEnum', 'dEnum', 'aFunc'],
unknown: []
};

const map: Map<string, string> = new Map([
Expand Down
6 changes: 2 additions & 4 deletions repo-scripts/size-analysis/test/test-inputs/subsetExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export {
aVar,
LogLevel2,
Logger1,
tarr1,
fs1,
basicFuncExportEnumDependencies,
basicFuncExportFuncDependenciesBar
basicFuncExportFuncDependenciesBar,
BasicClassExport
} from './index';
2 changes: 1 addition & 1 deletion repo-scripts/size-analysis/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"target": "es5",
"target": "es2017",
"esModuleInterop": true,
"declaration": true,
"strict": true
Expand Down
29 changes: 21 additions & 8 deletions scripts/size_report/report_binary_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@ function generateReportForCDNScripts(): Report[] {
const reports = [];
const firebaseRoot = path.resolve(__dirname, '../../packages/firebase');
const pkgJson = require(`${firebaseRoot}/package.json`);
const compatPkgJson = require(`${firebaseRoot}/compat/package.json`);

const special_files = [
'firebase-performance-standalone.es2017.js',
'firebase-performance-standalone.js',
'firebase-firestore.memory.js',
'firebase.js'
'firebase-performance-standalone-compat.es2017.js',
'firebase-performance-standalone-compat.js',
'firebase-compat.js'
];

const files = [
...special_files.map((file: string) => `${firebaseRoot}/${file}`),
...pkgJson.components.map(
(component: string) => `${firebaseRoot}/firebase-${component}.js`
(component: string) => `${firebaseRoot}/firebase-${component.replace('/', '-')}.js`
),
...compatPkgJson.components.map(
(component: string) => `${firebaseRoot}/firebase-${component}-compat.js`
)
];

Expand All @@ -77,7 +80,16 @@ async function generateReportForNPMPackages(): Promise<Report[]> {
for (const info of packageInfo) {
const packages = await findAllPackages(info.location);
for (const pkg of packages) {
reports.push(...(await collectBinarySize(pkg)));
try {
reports.push(...(await collectBinarySize(pkg)));
} catch (e) {
// log errors and continue to the next package
console.log(
`failed to generate report for ${pkg}.
error: ${e}`
);
}

}
}
return reports;
Expand All @@ -104,11 +116,12 @@ async function collectBinarySize(pkg: string): Promise<Report[]> {
const fields = [
'main',
'module',
'esm2017',
'browser',
'esm5',
'react-native',
'cordova',
'lite',
'lite-esm2017'
'lite-esm5'
];
const json = require(pkg);
for (const field of fields) {
Expand Down
8 changes: 7 additions & 1 deletion scripts/size_report/report_modular_export_binary_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
RequestBody,
RequestEndpoint
} from './size_report_helper';
import { existsSync } from 'fs';
interface ModularExportBinarySizeRequestBody extends RequestBody {
modules: Report[];
}
Expand All @@ -37,7 +38,12 @@ async function generateReport(): Promise<ModularExportBinarySizeRequestBody> {
]);

allModulesLocation = allModulesLocation.filter(path => {
const json = require(`${path}/package.json`);
const pkgJsonPath = `${path}/package.json`;
if (!existsSync(pkgJsonPath)){
return false;
}

const json = require(pkgJsonPath);
return (
json.name.startsWith('@firebase') &&
!json.name.includes('-compat') &&
Expand Down