MCPcopy Index your code
hub / github.com/adobe/react-spectrum / compareBuildAppSize

Function compareBuildAppSize

scripts/compareSize.js:17–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15
16// Compares the example test app build size and the verdaccio published package sizes to the last release
17async function compareBuildAppSize() {
18 // Get the commit before the last publish commit
19 let res = await octokit.search.commits({q: 'Publish repo:adobe/react-spectrum'});
20 let {items} = res.data;
21 let commit = items && items[0]?.parents[0]?.sha;
22
23 if (commit) {
24 // Attempt to pull stats from last publish commit. If they don't exist, pull from a hardcoded commit (fallback until these records are generated for a first publish w/ this script)
25 let lastAppStatUrl = `https://reactspectrum.blob.core.windows.net/reactspectrum/${commit}/verdaccio/rsp-cra-18/publish-stats/${currentAppStatsFile}`;
26 let lastPublishStatUrl = `https://reactspectrum.blob.core.windows.net/reactspectrum/${commit}/verdaccio/rsp-cra-18/publish-stats/${currentPublishStatsFile}`;
27 let lastAppStatPath = path.join(__dirname, '..', lastAppStatsFile);
28 let lastPublishStatPath = path.join(__dirname, '..', lastPublishStatsFile);
29 await download(lastAppStatUrl, lastAppStatPath);
30 await download(lastPublishStatUrl, lastPublishStatPath);
31
32 if (!fs.existsSync(lastAppStatPath)) {
33 // TODO: placeholder until we get some real stats. Hardcoded URL pointing to a commit with actual data
34 await download(
35 `https://reactspectrum.blob.core.windows.net/reactspectrum/2504f8ad927d0d0ad55e7e6db8a22fec16a67b6f/verdaccio/publish-stats/${currentAppStatsFile}`,
36 lastAppStatPath
37 );
38 }
39
40 if (!fs.existsSync(lastPublishStatPath)) {
41 await download(
42 `https://reactspectrum.blob.core.windows.net/reactspectrum/2504f8ad927d0d0ad55e7e6db8a22fec16a67b6f/verdaccio/publish-stats/${currentPublishStatsFile}`,
43 lastPublishStatPath
44 );
45 }
46
47 // Extract the built example app size from the current commit and the last publish commit data
48 let lastAppStats = fs.readFileSync(lastAppStatsFile, 'utf8');
49 let currentAppStats = fs.readFileSync(currentAppStatsFile, 'utf8');
50 let regex = /(.*)\tbuild\/\n$/;
51 let lastAppSize = lastAppStats.match(regex)[1];
52 let currentAppSize = currentAppStats.match(regex)[1];
53 fs.writeFileSync(
54 'size-diff.txt',
55 `Built app size diff from last publish: ${(currentAppSize - lastAppSize).toFixed(2)} kB`
56 );
57
58 let lastPackageStats = JSON.parse(fs.readFileSync(lastPublishStatsFile));
59 let currentPackageStats = JSON.parse(fs.readFileSync(currentPublishStatsFile));
60 let stream = fs.createWriteStream('size-diff.txt', {flags: 'a'});
61 stream.write('\n');
62 stream.write(
63 '\nPublished package size differences from last publish in kB (old, new, diff). Packages with size differences less than .01kB are omitted.'
64 );
65 for (let pkg of Object.keys(currentPackageStats)) {
66 // For each package grab the size from the last and current package stats data
67 let currentSize = pkg in currentPackageStats && currentPackageStats[pkg];
68 let lastSize = pkg in lastPackageStats && lastPackageStats[pkg];
69 if (!lastSize) {
70 lastSize = 0;
71 }
72
73 let diff = (currentSize - lastSize).toFixed(2);
74 if (Math.abs(diff) > 0) {

Callers 1

compareSize.jsFile · 0.85

Calls 3

downloadFunction · 0.85
endMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected