-
Notifications
You must be signed in to change notification settings - Fork 771
Expand file tree
/
Copy pathmonosize.config.mjs
More file actions
56 lines (48 loc) · 2 KB
/
monosize.config.mjs
File metadata and controls
56 lines (48 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// @ts-check
import { join } from 'node:path';
import { writeFileSync } from 'node:fs';
import webpackBundler from 'monosize-bundler-webpack';
/** @type {import('monosize').MonoSizeConfig} */
const config = {
repository: 'https://github.com/microsoft/fluentui-system-icons',
storage: createLocalStorage(),
bundler: webpackBundler((config) => {
return config;
}),
};
export default config;
/**
* Creates a local storage adapter for Monosize.
* This adapter reads and writes bundle size reports to a local JSON file.
* It is used to store the bundle size reports locally for the package.
* TODO: needs to be reworked to leverage GHA artifacts because pushing from CI to protected branch is not allowed.
* @returns {import('monosize').StorageAdapter}
*/
function createLocalStorage() {
const storageFileName = 'monosize.baseline.json';
return {
getRemoteReport: async (branch) => {
const url = `https://raw.githubusercontent.com/microsoft/fluentui-system-icons/${branch}/${storageFileName}`;
const emptyReport = { commitSHA: 'initial', remoteReport: [] };
try {
const response = await fetch(url);
if (!response.ok) {
console.log(`Failed to fetch baseline from "${url}": ${response.statusText}`);
return emptyReport;
}
/** @type {{branch: string; commitSHA: string; report: import('monosize').BundleSizeReport}}} */
const data = await response.json();
return { commitSHA: data.commitSHA, remoteReport: data.report };
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
console.log(`Error fetching baseline: ${message}`);
return emptyReport;
}
},
uploadReportToRemote: async (branch, commitSHA, localReport) => {
const storageData = { branch, commitSHA, report: localReport };
const storedReportPath = join(import.meta.dirname, storageFileName);
writeFileSync(storedReportPath, JSON.stringify(storageData, null, 2), 'utf-8');
},
};
}