-
Notifications
You must be signed in to change notification settings - Fork 928
Add bundle definitions and its measurement script. #5706
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
Changes from 2 commits
1a12d6e
78f614c
e9c4b79
b1057f6
a46d695
a6ce26c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* @license | ||
* Copyright 2021 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. | ||
*/ | ||
|
||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as tmp from 'tmp'; | ||
|
||
import { Bundler, Mode, run as runBundleAnalysis } from './bundle-analysis'; | ||
import { Report } from '../../scripts/size_report/report_binary_size'; | ||
|
||
export async function generateReportForBundles(version?: string) { | ||
const definitionDir = `${__dirname}/bundle-definitions`; | ||
const outputDir = tmp.dirSync().name; | ||
console.log(`Bundle definitions are located at "${definitionDir}".`); | ||
console.log(`Analysis output are located at "${outputDir}".`); | ||
|
||
const bundles = fs.readdirSync(definitionDir); | ||
const results: Report[] = []; | ||
for (const bundle of bundles) { | ||
const product = path.basename(bundle, '.json'); | ||
const output = `${outputDir}/${product}.analysis.json`; | ||
if (version) { | ||
overwriteVersion(definitionDir, bundle, outputDir, version); | ||
} | ||
const option = { | ||
input: version ? `${outputDir}/${bundle}` : `${definitionDir}/${bundle}`, | ||
bundler: Bundler.Rollup, | ||
mode: version ? Mode.Npm : Mode.Local, | ||
output: output, | ||
debug: true | ||
}; | ||
console.log(`Running for bundle "${bundle}" with mode "${option.mode}".`); | ||
await runBundleAnalysis(option); | ||
const measurements = parseAnalysisOutput(product, output); | ||
results.push(...measurements); | ||
} | ||
console.log(results); | ||
return results; | ||
} | ||
|
||
function overwriteVersion( | ||
definitionDir: string, | ||
bundle: string, | ||
temp: string, | ||
version: string | ||
) { | ||
const definitions = JSON.parse( | ||
fs.readFileSync(`${definitionDir}/${bundle}`, { encoding: 'utf-8' }) | ||
); | ||
for (const definition of definitions) { | ||
const dependencies = definition.dependencies; | ||
for (const dependency of dependencies) { | ||
dependency.versionOrTag = version; | ||
} | ||
} | ||
fs.writeFileSync(`${temp}/${bundle}`, JSON.stringify(definitions, null, 2), { | ||
encoding: 'utf-8' | ||
}); | ||
} | ||
|
||
function parseAnalysisOutput(product: string, output: string) { | ||
const analyses = JSON.parse(fs.readFileSync(output, { encoding: 'utf-8' })); | ||
const results: Report[] = []; | ||
for (const analysis of analyses) { | ||
const sdk = 'bundle'; | ||
const value = analysis.results[0].size; | ||
const type = `${product} (${analysis.name})`; | ||
results.push({ sdk, type, value }); | ||
} | ||
return results; | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[ | ||
{ | ||
"name": "logEvent", | ||
"dependencies": [ | ||
{ | ||
"packageName": "firebase", | ||
"versionOrTag": "exp", | ||
Feiyang1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"imports": [ | ||
{ | ||
"path": "app", | ||
"imports": [ | ||
"initializeApp" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"packageName": "firebase", | ||
"versionOrTag": "exp", | ||
"imports": [ | ||
{ | ||
"path": "analytics", | ||
"imports": [ | ||
"getAnalytics", | ||
"logEvent" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
[ | ||
{ | ||
"name": "ReCaptchaV3Provider", | ||
"dependencies": [ | ||
{ | ||
"packageName": "firebase", | ||
"versionOrTag": "exp", | ||
"imports": [ | ||
{ | ||
"path": "app", | ||
"imports": [ | ||
"initializeApp" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"packageName": "firebase", | ||
"versionOrTag": "exp", | ||
"imports": [ | ||
{ | ||
"path": "app-check", | ||
"imports": [ | ||
"initializeAppCheck", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did these used to include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it was there before. I got confused this morning when reading the code sample for App Check Enterprise, which doesn't reference Anyway, I have added it back both in the bundle definition doc and the json files in this pull request. Please take a look. Thanks! |
||
"ReCaptchaV3Provider", | ||
"getToken" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "ReCaptchaEnterpriseProvider", | ||
"dependencies": [ | ||
{ | ||
"packageName": "firebase", | ||
"versionOrTag": "exp", | ||
"imports": [ | ||
{ | ||
"path": "app", | ||
"imports": [ | ||
"initializeApp" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"packageName": "firebase", | ||
"versionOrTag": "exp", | ||
"imports": [ | ||
{ | ||
"path": "app-check", | ||
"imports": [ | ||
"initializeAppCheck", | ||
"ReCaptchaEnterpriseProvider", | ||
"getToken" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "CustomProvider", | ||
"dependencies": [ | ||
{ | ||
"packageName": "firebase", | ||
"versionOrTag": "exp", | ||
"imports": [ | ||
{ | ||
"path": "app", | ||
"imports": [ | ||
"initializeApp" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"packageName": "firebase", | ||
"versionOrTag": "exp", | ||
"imports": [ | ||
{ | ||
"path": "app-check", | ||
"imports": [ | ||
"initializeAppCheck", | ||
"CustomProvider", | ||
"getToken" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does bundle mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name we put here will be appear as the name of a new section under "affected sdks" in a PR report. For example, there is another section named "bundle" in the report above in this PR [1]. We can put whatever name we want here.
[1] #5706 (comment)
I suppose it is a limitation of the metric backend at the moment. When the API for receiving size measurements was first designed, the backend only recognizes http requests with a json body strictly in this format:
Writing a new API in the backend and deploying a new version of the service to GCP can be some work, therefore I'm reusing the API for bundle measurements here, although the semantic of the API doesn't make any sense in the context of "bundle-analysis". What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine. It would be great if you can copy your comment here to the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comment in the code to explain the rationale here.