shaka-bundle-size 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/BaselineComparator.d.ts +23 -0
  2. package/dist/BaselineComparator.d.ts.map +1 -0
  3. package/dist/BaselineComparator.js +118 -0
  4. package/dist/BaselineComparator.js.map +1 -0
  5. package/dist/BaselineStorage.d.ts +47 -0
  6. package/dist/BaselineStorage.d.ts.map +1 -0
  7. package/dist/BaselineStorage.js +229 -0
  8. package/dist/BaselineStorage.js.map +1 -0
  9. package/dist/BaselineWriter.d.ts +17 -0
  10. package/dist/BaselineWriter.d.ts.map +1 -0
  11. package/dist/BaselineWriter.js +91 -0
  12. package/dist/BaselineWriter.js.map +1 -0
  13. package/dist/BundleSizeChecker.d.ts +42 -0
  14. package/dist/BundleSizeChecker.d.ts.map +1 -0
  15. package/dist/BundleSizeChecker.js +283 -0
  16. package/dist/BundleSizeChecker.js.map +1 -0
  17. package/dist/ExtendedStatsGenerator.d.ts +20 -0
  18. package/dist/ExtendedStatsGenerator.d.ts.map +1 -0
  19. package/dist/ExtendedStatsGenerator.js +82 -0
  20. package/dist/ExtendedStatsGenerator.js.map +1 -0
  21. package/dist/HtmlDiffGenerator.d.ts +16 -0
  22. package/dist/HtmlDiffGenerator.d.ts.map +1 -0
  23. package/dist/HtmlDiffGenerator.js +170 -0
  24. package/dist/HtmlDiffGenerator.js.map +1 -0
  25. package/dist/RegressionDetector.d.ts +20 -0
  26. package/dist/RegressionDetector.d.ts.map +1 -0
  27. package/dist/RegressionDetector.js +94 -0
  28. package/dist/RegressionDetector.js.map +1 -0
  29. package/dist/Reporter.d.ts +44 -0
  30. package/dist/Reporter.d.ts.map +1 -0
  31. package/dist/Reporter.js +116 -0
  32. package/dist/Reporter.js.map +1 -0
  33. package/dist/SizeCalculator.d.ts +21 -0
  34. package/dist/SizeCalculator.d.ts.map +1 -0
  35. package/dist/SizeCalculator.js +100 -0
  36. package/dist/SizeCalculator.js.map +1 -0
  37. package/dist/SourceMapGenerator.d.ts +22 -0
  38. package/dist/SourceMapGenerator.d.ts.map +1 -0
  39. package/dist/SourceMapGenerator.js +148 -0
  40. package/dist/SourceMapGenerator.js.map +1 -0
  41. package/dist/WebpackStatsReader.d.ts +18 -0
  42. package/dist/WebpackStatsReader.d.ts.map +1 -0
  43. package/dist/WebpackStatsReader.js +106 -0
  44. package/dist/WebpackStatsReader.js.map +1 -0
  45. package/dist/cli.d.ts +3 -0
  46. package/dist/cli.d.ts.map +1 -0
  47. package/dist/cli.js +260 -0
  48. package/dist/cli.js.map +1 -0
  49. package/dist/config.d.ts +91 -0
  50. package/dist/config.d.ts.map +1 -0
  51. package/dist/config.js +216 -0
  52. package/dist/config.js.map +1 -0
  53. package/dist/helpers/colors.d.ts +19 -0
  54. package/dist/helpers/colors.d.ts.map +1 -0
  55. package/dist/helpers/colors.js +21 -0
  56. package/dist/helpers/colors.js.map +1 -0
  57. package/dist/index.d.ts +15 -1
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +56 -2
  60. package/dist/index.js.map +1 -1
  61. package/dist/types.d.ts +408 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/types.js +19 -0
  64. package/dist/types.js.map +1 -0
  65. package/package.json +16 -3
  66. package/templates/diff-template.html +113 -0
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Loads baseline configuration and compares with current build sizes
3
+ * to detect changes and potential regressions.
4
+ */
5
+ import type { BaselineComparatorConfig, BaselineConfig, ComponentSize, BaselineComponent, SizeComparison, ComparisonResult } from './types';
6
+ export declare const UNCATEGORIZED_CHUNKS_NAME = "uncategorized chunks";
7
+ export declare class BaselineComparator {
8
+ private baselineDir;
9
+ private sizeThresholdKb;
10
+ constructor({ baselineDir, sizeThresholdKb }: BaselineComparatorConfig);
11
+ getBaselineFilePath(filename: string): string;
12
+ loadBaselineFile(filename: string): BaselineConfig;
13
+ baselineFileExists(filename: string): boolean;
14
+ findComponentByName<T extends {
15
+ name: string;
16
+ }>(components: T[], name: string): T | undefined;
17
+ compare(actualSizes: ComponentSize[], baseline: BaselineConfig): ComparisonResult;
18
+ createComparison(actual: ComponentSize, expected: BaselineComponent): SizeComparison;
19
+ hasSizeIncrease(comparison: SizeComparison): boolean;
20
+ hasSizeDecrease(comparison: SizeComparison): boolean;
21
+ hasChunksCountIncrease(comparison: SizeComparison): boolean;
22
+ }
23
+ //# sourceMappingURL=BaselineComparator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaselineComparator.d.ts","sourceRoot":"","sources":["../src/BaselineComparator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EACV,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAEhE,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,eAAe,CAAS;gBAEpB,EAAE,WAAW,EAAE,eAAqB,EAAE,EAAE,wBAAwB;IAK5E,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAI7C,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc;IAMlD,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI7C,mBAAmB,CAAC,CAAC,SAAS;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAI7F,OAAO,CAAC,WAAW,EAAE,aAAa,EAAE,EAAE,QAAQ,EAAE,cAAc,GAAG,gBAAgB;IAyCjF,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,iBAAiB,GAAG,cAAc;IAcpF,eAAe,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO;IAIpD,eAAe,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO;IAIpD,sBAAsB,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO;CAG5D"}
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ /**
3
+ * Loads baseline configuration and compares with current build sizes
4
+ * to detect changes and potential regressions.
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.BaselineComparator = exports.UNCATEGORIZED_CHUNKS_NAME = void 0;
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ exports.UNCATEGORIZED_CHUNKS_NAME = 'uncategorized chunks';
44
+ class BaselineComparator {
45
+ constructor({ baselineDir, sizeThresholdKb = 0.1 }) {
46
+ this.baselineDir = baselineDir;
47
+ this.sizeThresholdKb = sizeThresholdKb;
48
+ }
49
+ getBaselineFilePath(filename) {
50
+ return path.join(this.baselineDir, filename);
51
+ }
52
+ loadBaselineFile(filename) {
53
+ const configPath = this.getBaselineFilePath(filename);
54
+ const content = fs.readFileSync(configPath, 'utf8');
55
+ return JSON.parse(content);
56
+ }
57
+ baselineFileExists(filename) {
58
+ return fs.existsSync(this.getBaselineFilePath(filename));
59
+ }
60
+ findComponentByName(components, name) {
61
+ return components.find(c => c.name === name);
62
+ }
63
+ compare(actualSizes, baseline) {
64
+ const expectedSizes = baseline.loadableComponents || [];
65
+ const result = {
66
+ sizeChanges: [],
67
+ newComponents: [],
68
+ removedComponents: [],
69
+ chunksCountIncreases: [],
70
+ };
71
+ // Check for new or changed components
72
+ for (const actual of actualSizes) {
73
+ const expected = this.findComponentByName(expectedSizes, actual.name);
74
+ if (!expected) {
75
+ result.newComponents.push(actual);
76
+ continue;
77
+ }
78
+ const comparison = this.createComparison(actual, expected);
79
+ if (this.hasSizeIncrease(comparison)) {
80
+ result.sizeChanges.push(comparison);
81
+ }
82
+ if (this.hasChunksCountIncrease(comparison)) {
83
+ result.chunksCountIncreases.push(comparison);
84
+ }
85
+ }
86
+ // Check for removed components
87
+ for (const expected of expectedSizes) {
88
+ const actual = this.findComponentByName(actualSizes, expected.name);
89
+ if (!actual) {
90
+ result.removedComponents.push(expected);
91
+ }
92
+ }
93
+ return result;
94
+ }
95
+ createComparison(actual, expected) {
96
+ const actualSizeKb = Number(actual.gzipSizeKb.toFixed(2));
97
+ const expectedSizeKb = Number(expected.gzipSizeKb);
98
+ return {
99
+ name: actual.name,
100
+ actualSizeKb,
101
+ expectedSizeKb,
102
+ sizeDiffKb: actualSizeKb - expectedSizeKb,
103
+ actualChunksCount: actual.chunksCount,
104
+ expectedChunksCount: expected.chunksCount,
105
+ };
106
+ }
107
+ hasSizeIncrease(comparison) {
108
+ return comparison.sizeDiffKb > this.sizeThresholdKb;
109
+ }
110
+ hasSizeDecrease(comparison) {
111
+ return comparison.sizeDiffKb < 0;
112
+ }
113
+ hasChunksCountIncrease(comparison) {
114
+ return comparison.actualChunksCount > comparison.expectedChunksCount;
115
+ }
116
+ }
117
+ exports.BaselineComparator = BaselineComparator;
118
+ //# sourceMappingURL=BaselineComparator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaselineComparator.js","sourceRoot":"","sources":["../src/BaselineComparator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,2CAA6B;AAUhB,QAAA,yBAAyB,GAAG,sBAAsB,CAAC;AAEhE,MAAa,kBAAkB;IAI7B,YAAY,EAAE,WAAW,EAAE,eAAe,GAAG,GAAG,EAA4B;QAC1E,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED,mBAAmB,CAAC,QAAgB;QAClC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED,gBAAgB,CAAC,QAAgB;QAC/B,MAAM,UAAU,GAAG,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QACtD,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAmB,CAAC;IAC/C,CAAC;IAED,kBAAkB,CAAC,QAAgB;QACjC,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,mBAAmB,CAA6B,UAAe,EAAE,IAAY;QAC3E,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,E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C;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,gBAAgB,CAAC,MAAqB,EAAE,QAA2B;QACjE,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1D,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QAEnD,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,YAAY;YACZ,cAAc;YACd,UAAU,EAAE,YAAY,GAAG,cAAc;YACzC,iBAAiB,EAAE,MAAM,CAAC,WAAW;YACrC,mBAAmB,EAAE,QAAQ,CAAC,WAAW;SAC1C,CAAC;IACJ,CAAC;IAED,eAAe,CAAC,UAA0B;QACxC,OAAO,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC;IACtD,CAAC;IAED,eAAe,CAAC,UAA0B;QACxC,OAAO,UAAU,CAAC,UAAU,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,sBAAsB,CAAC,UAA0B;QAC/C,OAAO,UAAU,CAAC,iBAAiB,GAAG,UAAU,CAAC,mBAAmB,CAAC;IACvE,CAAC;CACF;AA7FD,gDA6FC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Handles downloading baselines from S3 storage (finding merge-base with main)
3
+ * and uploading baselines to S3 for the current commit.
4
+ */
5
+ export interface BaselineStorageConfig {
6
+ /** S3 bucket name */
7
+ s3Bucket: string;
8
+ /** S3 key prefix (e.g., 'bundle-size-baselines/') */
9
+ s3Prefix: string;
10
+ /** AWS region (optional, falls back to AWS_REGION env or 'us-east-1'). Use 'auto' for R2. */
11
+ awsRegion?: string;
12
+ /** Custom endpoint URL for S3-compatible services like Cloudflare R2 (e.g., 'https://<account_id>.r2.cloudflarestorage.com') */
13
+ endpoint?: string;
14
+ /** Working directory for current baseline */
15
+ baselineDir: string;
16
+ /** Number of main branch commits to search for baseline */
17
+ mainCommitsToCheck: number;
18
+ /** Name of the main branch (default: 'main') */
19
+ mainBranch?: string;
20
+ }
21
+ export declare class BaselineStorage {
22
+ private s3Client;
23
+ private bucket;
24
+ private prefix;
25
+ private baselineDir;
26
+ private mainCommitsToCheck;
27
+ private mainBranch;
28
+ constructor(config: BaselineStorageConfig);
29
+ getMainBranch(): string;
30
+ getGitMergeBase(): string;
31
+ getRecentMainCommits(mergeBase: string): string[];
32
+ getCurrentCommit(): string;
33
+ getS3KeyForCommit(commit: string): string;
34
+ baselineExistsForCommit(commit: string): Promise<boolean>;
35
+ /** Returns the commit hash that baseline was found for, or null if not found. */
36
+ download(): Promise<string | null>;
37
+ downloadForCommit(commitSha: string): Promise<string | null>;
38
+ upload(): Promise<string>;
39
+ /** Use this when you want to associate the baseline with a specific main branch commit. */
40
+ uploadForCommit(commitSha: string): Promise<string>;
41
+ private downloadFromS3;
42
+ private uploadToS3;
43
+ private deleteS3Prefix;
44
+ private getAllFiles;
45
+ private getContentType;
46
+ }
47
+ //# sourceMappingURL=BaselineStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaselineStorage.d.ts","sourceRoot":"","sources":["../src/BaselineStorage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,MAAM,WAAW,qBAAqB;IACpC,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,QAAQ,EAAE,MAAM,CAAC;IACjB,6FAA6F;IAC7F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gIAAgI;IAChI,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,UAAU,CAAS;gBAEf,MAAM,EAAE,qBAAqB;IAczC,aAAa,IAAI,MAAM;IAIvB,eAAe,IAAI,MAAM;IAKzB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAQjD,gBAAgB,IAAI,MAAM;IAI1B,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAInC,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAkB/D,iFAAiF;IAC3E,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAclC,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAQ5D,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAU/B,2FAA2F;IACrF,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAS3C,cAAc;YAmDd,UAAU;YA0BV,cAAc;IA6B5B,OAAO,CAAC,WAAW;IAgBnB,OAAO,CAAC,cAAc;CAUvB"}
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ /**
3
+ * Handles downloading baselines from S3 storage (finding merge-base with main)
4
+ * and uploading baselines to S3 for the current commit.
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.BaselineStorage = void 0;
41
+ const client_s3_1 = require("@aws-sdk/client-s3");
42
+ const child_process_1 = require("child_process");
43
+ const fs = __importStar(require("fs"));
44
+ const path = __importStar(require("path"));
45
+ const promises_1 = require("stream/promises");
46
+ class BaselineStorage {
47
+ constructor(config) {
48
+ this.bucket = config.s3Bucket;
49
+ this.prefix = config.s3Prefix.endsWith('/') ? config.s3Prefix : `${config.s3Prefix}/`;
50
+ this.baselineDir = config.baselineDir;
51
+ this.mainCommitsToCheck = config.mainCommitsToCheck;
52
+ this.mainBranch = config.mainBranch ?? 'main';
53
+ const endpoint = config.endpoint || process.env.S3_ENDPOINT;
54
+ this.s3Client = new client_s3_1.S3Client({
55
+ region: config.awsRegion || process.env.AWS_REGION || 'auto',
56
+ ...(endpoint && { endpoint }),
57
+ });
58
+ }
59
+ getMainBranch() {
60
+ return this.mainBranch;
61
+ }
62
+ getGitMergeBase() {
63
+ (0, child_process_1.execSync)(`git fetch origin ${this.mainBranch}`, { stdio: 'pipe' });
64
+ return (0, child_process_1.execSync)(`git merge-base origin/${this.mainBranch} HEAD`, { encoding: 'utf8' }).trim();
65
+ }
66
+ getRecentMainCommits(mergeBase) {
67
+ const output = (0, child_process_1.execSync)(`git log -${this.mainCommitsToCheck} --pretty=format:"%H" ${mergeBase}`, { encoding: 'utf8' });
68
+ return output.split('\n').filter(Boolean);
69
+ }
70
+ getCurrentCommit() {
71
+ return (0, child_process_1.execSync)('git rev-parse HEAD', { encoding: 'utf8' }).trim();
72
+ }
73
+ getS3KeyForCommit(commit) {
74
+ return `${this.prefix}${commit}/`;
75
+ }
76
+ async baselineExistsForCommit(commit) {
77
+ const prefix = this.getS3KeyForCommit(commit);
78
+ try {
79
+ const response = await this.s3Client.send(new client_s3_1.ListObjectsV2Command({
80
+ Bucket: this.bucket,
81
+ Prefix: prefix,
82
+ MaxKeys: 1,
83
+ }));
84
+ return (response.Contents?.length ?? 0) > 0;
85
+ }
86
+ catch {
87
+ return false;
88
+ }
89
+ }
90
+ /** Returns the commit hash that baseline was found for, or null if not found. */
91
+ async download() {
92
+ const mergeBase = this.getGitMergeBase();
93
+ const commits = this.getRecentMainCommits(mergeBase);
94
+ for (const commit of commits) {
95
+ if (await this.baselineExistsForCommit(commit)) {
96
+ await this.downloadFromS3(commit);
97
+ return commit;
98
+ }
99
+ }
100
+ return null;
101
+ }
102
+ async downloadForCommit(commitSha) {
103
+ if (await this.baselineExistsForCommit(commitSha)) {
104
+ await this.downloadFromS3(commitSha);
105
+ return commitSha;
106
+ }
107
+ return null;
108
+ }
109
+ async upload() {
110
+ if (!fs.existsSync(this.baselineDir)) {
111
+ throw new Error(`No baseline found at ${this.baselineDir}. Generate stats first.`);
112
+ }
113
+ const commit = this.getCurrentCommit();
114
+ await this.uploadToS3(commit);
115
+ return commit;
116
+ }
117
+ /** Use this when you want to associate the baseline with a specific main branch commit. */
118
+ async uploadForCommit(commitSha) {
119
+ if (!fs.existsSync(this.baselineDir)) {
120
+ throw new Error(`No baseline found at ${this.baselineDir}. Generate stats first.`);
121
+ }
122
+ await this.uploadToS3(commitSha);
123
+ return commitSha;
124
+ }
125
+ async downloadFromS3(commit) {
126
+ const prefix = this.getS3KeyForCommit(commit);
127
+ const listResponse = await this.s3Client.send(new client_s3_1.ListObjectsV2Command({
128
+ Bucket: this.bucket,
129
+ Prefix: prefix,
130
+ }));
131
+ if (!listResponse.Contents || listResponse.Contents.length === 0) {
132
+ throw new Error(`No files found for commit ${commit}`);
133
+ }
134
+ // Clear and recreate local baselineDir
135
+ if (fs.existsSync(this.baselineDir)) {
136
+ fs.rmSync(this.baselineDir, { recursive: true });
137
+ }
138
+ fs.mkdirSync(this.baselineDir, { recursive: true });
139
+ // Download each file
140
+ for (const object of listResponse.Contents) {
141
+ if (!object.Key)
142
+ continue;
143
+ // Extract relative path (remove prefix)
144
+ const relativePath = object.Key.slice(prefix.length);
145
+ if (!relativePath)
146
+ continue; // Skip the "directory" itself
147
+ const localPath = path.join(this.baselineDir, relativePath);
148
+ // Ensure parent directory exists
149
+ const parentDir = path.dirname(localPath);
150
+ if (!fs.existsSync(parentDir)) {
151
+ fs.mkdirSync(parentDir, { recursive: true });
152
+ }
153
+ // Download the file
154
+ const getResponse = await this.s3Client.send(new client_s3_1.GetObjectCommand({
155
+ Bucket: this.bucket,
156
+ Key: object.Key,
157
+ }));
158
+ if (getResponse.Body) {
159
+ const writeStream = fs.createWriteStream(localPath);
160
+ await (0, promises_1.pipeline)(getResponse.Body, writeStream);
161
+ }
162
+ }
163
+ }
164
+ async uploadToS3(commit) {
165
+ const prefix = this.getS3KeyForCommit(commit);
166
+ // Delete existing objects for this commit (if any)
167
+ await this.deleteS3Prefix(prefix);
168
+ // Upload all files from baselineDir
169
+ const files = this.getAllFiles(this.baselineDir);
170
+ for (const filePath of files) {
171
+ const relativePath = path.relative(this.baselineDir, filePath);
172
+ const s3Key = `${prefix}${relativePath}`;
173
+ const fileContent = fs.readFileSync(filePath);
174
+ await this.s3Client.send(new client_s3_1.PutObjectCommand({
175
+ Bucket: this.bucket,
176
+ Key: s3Key,
177
+ Body: fileContent,
178
+ ContentType: this.getContentType(filePath),
179
+ }));
180
+ }
181
+ }
182
+ async deleteS3Prefix(prefix) {
183
+ const listResponse = await this.s3Client.send(new client_s3_1.ListObjectsV2Command({
184
+ Bucket: this.bucket,
185
+ Prefix: prefix,
186
+ }));
187
+ if (!listResponse.Contents || listResponse.Contents.length === 0) {
188
+ return;
189
+ }
190
+ const objectsToDelete = [];
191
+ for (const obj of listResponse.Contents) {
192
+ if (obj.Key) {
193
+ objectsToDelete.push({ Key: obj.Key });
194
+ }
195
+ }
196
+ if (objectsToDelete.length > 0) {
197
+ await this.s3Client.send(new client_s3_1.DeleteObjectsCommand({
198
+ Bucket: this.bucket,
199
+ Delete: { Objects: objectsToDelete },
200
+ }));
201
+ }
202
+ }
203
+ getAllFiles(dir) {
204
+ const files = [];
205
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
206
+ for (const entry of entries) {
207
+ const fullPath = path.join(dir, entry.name);
208
+ if (entry.isDirectory()) {
209
+ files.push(...this.getAllFiles(fullPath));
210
+ }
211
+ else {
212
+ files.push(fullPath);
213
+ }
214
+ }
215
+ return files;
216
+ }
217
+ getContentType(filePath) {
218
+ const ext = path.extname(filePath).toLowerCase();
219
+ const contentTypes = {
220
+ '.json': 'application/json',
221
+ '.js': 'application/javascript',
222
+ '.html': 'text/html',
223
+ '.txt': 'text/plain',
224
+ };
225
+ return contentTypes[ext] || 'application/octet-stream';
226
+ }
227
+ }
228
+ exports.BaselineStorage = BaselineStorage;
229
+ //# sourceMappingURL=BaselineStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaselineStorage.js","sourceRoot":"","sources":["../src/BaselineStorage.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAM4B;AAC5B,iDAAyC;AACzC,uCAAyB;AACzB,2CAA6B;AAE7B,8CAA2C;AAmB3C,MAAa,eAAe;IAQ1B,YAAY,MAA6B;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC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E,kBAAkB;YAC3B,KAAK,EAAE,wBAAwB;YAC/B,OAAO,EAAE,WAAW;YACpB,MAAM,EAAE,YAAY;SACrB,CAAC;QACF,OAAO,YAAY,CAAC,GAAG,CAAC,IAAI,0BAA0B,CAAC;IACzD,CAAC;CACF;AAhPD,0CAgPC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Generates baseline config JSON files from current build sizes.
3
+ * These files serve as the reference for future comparisons.
4
+ */
5
+ import type { BaselineWriterConfig, ComponentSize, BaselineComponent, BaselineConfig } from './types';
6
+ export declare class BaselineWriter {
7
+ private baselineDir;
8
+ constructor({ baselineDir }: BaselineWriterConfig);
9
+ ensureDirectoryExists(): void;
10
+ clearDirectory(): void;
11
+ getFilePath(filename: string): string;
12
+ formatComponents(sizes: ComponentSize[]): BaselineComponent[];
13
+ calculateTotalSize(sizes: ComponentSize[]): string;
14
+ createBaselineConfig(sizes: ComponentSize[]): BaselineConfig;
15
+ writeBaselineFile(filename: string, sizes: ComponentSize[]): string;
16
+ }
17
+ //# sourceMappingURL=BaselineWriter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaselineWriter.d.ts","sourceRoot":"","sources":["../src/BaselineWriter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,qBAAa,cAAc;IACzB,OAAO,CAAC,WAAW,CAAS;gBAEhB,EAAE,WAAW,EAAE,EAAE,oBAAoB;IAIjD,qBAAqB,IAAI,IAAI;IAM7B,cAAc,IAAI,IAAI;IAOtB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIrC,gBAAgB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,iBAAiB,EAAE;IAW7D,kBAAkB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,MAAM;IAKlD,oBAAoB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,cAAc;IAO5D,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,MAAM;CAWpE"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ /**
3
+ * Generates baseline config JSON files from current build sizes.
4
+ * These files serve as the reference for future comparisons.
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.BaselineWriter = void 0;
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ class BaselineWriter {
44
+ constructor({ baselineDir }) {
45
+ this.baselineDir = baselineDir;
46
+ }
47
+ ensureDirectoryExists() {
48
+ if (!fs.existsSync(this.baselineDir)) {
49
+ fs.mkdirSync(this.baselineDir, { recursive: true });
50
+ }
51
+ }
52
+ clearDirectory() {
53
+ if (fs.existsSync(this.baselineDir)) {
54
+ fs.rmSync(this.baselineDir, { recursive: true });
55
+ }
56
+ this.ensureDirectoryExists();
57
+ }
58
+ getFilePath(filename) {
59
+ return path.join(this.baselineDir, filename);
60
+ }
61
+ formatComponents(sizes) {
62
+ return sizes
63
+ .map(size => ({
64
+ name: size.name,
65
+ chunksCount: size.chunksCount,
66
+ brotliSizeKb: size.brotliSizeKb.toFixed(2),
67
+ gzipSizeKb: size.gzipSizeKb.toFixed(2),
68
+ }))
69
+ .sort((a, b) => a.name.localeCompare(b.name));
70
+ }
71
+ calculateTotalSize(sizes) {
72
+ const total = sizes.reduce((sum, size) => sum + size.gzipSizeKb, 0);
73
+ return total.toFixed(2);
74
+ }
75
+ createBaselineConfig(sizes) {
76
+ return {
77
+ loadableComponents: this.formatComponents(sizes),
78
+ totalgzipSizeKb: this.calculateTotalSize(sizes),
79
+ };
80
+ }
81
+ writeBaselineFile(filename, sizes) {
82
+ this.ensureDirectoryExists();
83
+ const config = this.createBaselineConfig(sizes);
84
+ const configPath = this.getFilePath(filename);
85
+ const content = JSON.stringify(config, null, 2) + '\n';
86
+ fs.writeFileSync(configPath, content, 'utf8');
87
+ return configPath;
88
+ }
89
+ }
90
+ exports.BaselineWriter = BaselineWriter;
91
+ //# sourceMappingURL=BaselineWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaselineWriter.js","sourceRoot":"","sources":["../src/BaselineWriter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,2CAA6B;AAQ7B,MAAa,cAAc;IAGzB,YAAY,EAAE,WAAW,EAAwB;QAC/C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,qBAAqB;QACnB,IAAI,CAAC,EAA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IAED,oBAAoB,CAAC,KAAsB;QACzC,OAAO;YACL,kBAAkB,EAAE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;YAChD,eAAe,EAAE,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC;SAChD,CAAC;IACJ,CAAC;IAED,iBAAiB,CAAC,QAAgB,EAAE,KAAsB;QACxD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAE7B,MAAM,MAAM,GAAG,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAChD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAE9C,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;QACvD,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAE9C,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AA1DD,wCA0DC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Coordinates the reading of webpack stats, size calculation, baseline comparison,
3
+ * regression detection, and reporting. This is the main entry point for the library.
4
+ */
5
+ import type { ResolvedConfig } from './config';
6
+ import type { IReporter, ComponentSize, ChunkGroupInfo, CheckResult, UpdateBaselineResult, DiffMetadata } from './types';
7
+ export declare class BundleSizeChecker {
8
+ private statsFile;
9
+ private bundlesDir;
10
+ private baselineDir;
11
+ private baselineFile;
12
+ private ignoredBundles;
13
+ private generateSourceMaps;
14
+ private regressionPolicy;
15
+ private reporter;
16
+ private statsReader;
17
+ private sizeCalculator;
18
+ private baselineComparator;
19
+ private regressionDetector;
20
+ private baselineWriter;
21
+ private sourceMapGenerator;
22
+ private htmlDiffGenerator;
23
+ constructor(config: ResolvedConfig, reporter?: IReporter);
24
+ private validateConfig;
25
+ calculateComponentSizes(namedChunkGroups: ChunkGroupInfo[], uncategorizedChunks: string[]): ComponentSize[];
26
+ private reportRegressions;
27
+ check(): CheckResult;
28
+ updateBaseline(): UpdateBaselineResult;
29
+ generateCurrentStatsTo(outputDir: string): {
30
+ configPath: string;
31
+ sourceMapPath: string | null;
32
+ };
33
+ generateHtmlDiffs(options: {
34
+ controlDir: string;
35
+ currentDir: string;
36
+ outputDir: string;
37
+ metadata?: DiffMetadata;
38
+ }): string[];
39
+ getBaselineDir(): string;
40
+ getBaselineFile(): string;
41
+ }
42
+ //# sourceMappingURL=BundleSizeChecker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BundleSizeChecker.d.ts","sourceRoot":"","sources":["../src/BundleSizeChecker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAEV,SAAS,EACT,aAAa,EACb,cAAc,EAGd,WAAW,EACX,oBAAoB,EACpB,YAAY,EACb,MAAM,SAAS,CAAC;AAwBjB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,cAAc,CAAW;IACjC,OAAO,CAAC,kBAAkB,CAAU;IACpC,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,QAAQ,CAAY;IAE5B,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,iBAAiB,CAAoB;gBAEjC,MAAM,EAAE,cAAc,EAAE,QAAQ,CAAC,EAAE,SAAS;IA8CxD,OAAO,CAAC,cAAc;IAYtB,uBAAuB,CAAC,gBAAgB,EAAE,cAAc,EAAE,EAAE,m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