@node-cli/bundlecheck 1.2.0 → 1.4.0
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.
- package/README.md +287 -11
- package/dist/bundlecheck.js +82 -32
- package/dist/bundlecheck.js.map +1 -1
- package/dist/bundler.d.ts +17 -4
- package/dist/bundler.js +113 -91
- package/dist/bundler.js.map +1 -1
- package/dist/cache.d.ts +62 -0
- package/dist/cache.js +196 -0
- package/dist/cache.js.map +1 -0
- package/dist/defaults.d.ts +13 -0
- package/dist/defaults.js +65 -1
- package/dist/defaults.js.map +1 -1
- package/dist/index.d.ts +1 -6
- package/dist/index.js +229 -0
- package/dist/index.js.map +1 -0
- package/dist/parse.d.ts +2 -0
- package/dist/parse.js +26 -1
- package/dist/parse.js.map +1 -1
- package/dist/trend.d.ts +17 -6
- package/dist/trend.js +95 -45
- package/dist/trend.js.map +1 -1
- package/dist/versions.d.ts +1 -1
- package/dist/versions.js +12 -10
- package/dist/versions.js.map +1 -1
- package/package.json +6 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @node-cli/bundlecheck - Library API
|
|
3
|
+
*
|
|
4
|
+
* Programmatic interface for analyzing npm package bundle sizes.
|
|
5
|
+
*
|
|
6
|
+
*/ import { checkBundleSize, formatBytes, getExternals, parsePackageSpecifier } from "./bundler.js";
|
|
7
|
+
import { getCachedResult, normalizeCacheKey, setCachedResult } from "./cache.js";
|
|
8
|
+
import { normalizePlatform, TREND_VERSION_COUNT } from "./defaults.js";
|
|
9
|
+
import { analyzeTrend, selectTrendVersions } from "./trend.js";
|
|
10
|
+
import { fetchPackageVersions as fetchVersions } from "./versions.js";
|
|
11
|
+
/**
|
|
12
|
+
* =============================================================================
|
|
13
|
+
* Library Functions
|
|
14
|
+
* =============================================================================
|
|
15
|
+
*/ /**
|
|
16
|
+
* Get bundle size statistics for an npm package.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```js
|
|
20
|
+
* import { getBundleStats } from "@node-cli/bundlecheck";
|
|
21
|
+
*
|
|
22
|
+
* const stats = await getBundleStats({
|
|
23
|
+
* package: "@mantine/core@7.0.0",
|
|
24
|
+
* exports: ["Button", "Input"],
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* console.log(stats.gzipSizeFormatted); // "12.3 kB"
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
*/ export async function getBundleStats(options) {
|
|
31
|
+
const { package: packageName, exports: exportsList, external: additionalExternals, noExternal, gzipLevel = 5, registry, platform: platformOption = "auto", force = false } = options;
|
|
32
|
+
// Normalize platform.
|
|
33
|
+
const platform = normalizePlatform(platformOption === "auto" ? undefined : platformOption);
|
|
34
|
+
// Parse package specifier.
|
|
35
|
+
const { name: baseName, version: requestedVersion } = parsePackageSpecifier(packageName);
|
|
36
|
+
// Resolve "latest" to actual version for cache key.
|
|
37
|
+
let resolvedVersion = requestedVersion;
|
|
38
|
+
if (requestedVersion === "latest") {
|
|
39
|
+
const { tags } = await fetchVersions({
|
|
40
|
+
packageName: baseName,
|
|
41
|
+
registry
|
|
42
|
+
});
|
|
43
|
+
resolvedVersion = tags.latest || requestedVersion;
|
|
44
|
+
}
|
|
45
|
+
// Compute externals for cache key.
|
|
46
|
+
const externals = getExternals(baseName, additionalExternals, noExternal);
|
|
47
|
+
// Build cache key.
|
|
48
|
+
const cacheKey = normalizeCacheKey({
|
|
49
|
+
packageName: baseName,
|
|
50
|
+
version: resolvedVersion,
|
|
51
|
+
exports: exportsList,
|
|
52
|
+
platform,
|
|
53
|
+
gzipLevel,
|
|
54
|
+
externals,
|
|
55
|
+
noExternal: noExternal ?? false
|
|
56
|
+
});
|
|
57
|
+
// Check cache (unless force is set).
|
|
58
|
+
if (!force) {
|
|
59
|
+
const cached = getCachedResult(cacheKey);
|
|
60
|
+
if (cached) {
|
|
61
|
+
return formatBundleStats(cached, true);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Perform the analysis.
|
|
65
|
+
const result = await checkBundleSize({
|
|
66
|
+
packageName,
|
|
67
|
+
exports: exportsList,
|
|
68
|
+
additionalExternals,
|
|
69
|
+
noExternal,
|
|
70
|
+
gzipLevel,
|
|
71
|
+
registry,
|
|
72
|
+
platform
|
|
73
|
+
});
|
|
74
|
+
// Store in cache.
|
|
75
|
+
setCachedResult(cacheKey, result);
|
|
76
|
+
return formatBundleStats(result, false);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get bundle size trend across multiple versions of a package.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```js
|
|
83
|
+
* import { getBundleTrend } from "@node-cli/bundlecheck";
|
|
84
|
+
*
|
|
85
|
+
* const trend = await getBundleTrend({
|
|
86
|
+
* package: "@mantine/core",
|
|
87
|
+
* versionCount: 5,
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* console.log(trend.change?.rawDiffFormatted); // "+5.2 kB"
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
*/ export async function getBundleTrend(options) {
|
|
94
|
+
const { package: packageName, versionCount = TREND_VERSION_COUNT, exports: exportsList, external: additionalExternals, noExternal, gzipLevel, registry, platform: platformOption = "auto", force = false } = options;
|
|
95
|
+
// Normalize platform.
|
|
96
|
+
const platform = normalizePlatform(platformOption === "auto" ? undefined : platformOption);
|
|
97
|
+
// Parse package name (ignore version if provided).
|
|
98
|
+
const { name: baseName, subpath } = parsePackageSpecifier(packageName);
|
|
99
|
+
const fullPackagePath = subpath ? `${baseName}/${subpath}` : baseName;
|
|
100
|
+
// Fetch available versions.
|
|
101
|
+
const { versions } = await fetchVersions({
|
|
102
|
+
packageName: baseName,
|
|
103
|
+
registry
|
|
104
|
+
});
|
|
105
|
+
if (versions.length === 0) {
|
|
106
|
+
throw new Error(`No versions found for package: ${baseName}`);
|
|
107
|
+
}
|
|
108
|
+
// Select versions for trend.
|
|
109
|
+
const trendVersions = selectTrendVersions(versions, versionCount);
|
|
110
|
+
// Analyze all versions (silently - no console output).
|
|
111
|
+
const results = await analyzeTrend({
|
|
112
|
+
packageName: fullPackagePath,
|
|
113
|
+
versions: trendVersions,
|
|
114
|
+
exports: exportsList,
|
|
115
|
+
additionalExternals,
|
|
116
|
+
noExternal,
|
|
117
|
+
gzipLevel,
|
|
118
|
+
boring: true,
|
|
119
|
+
registry,
|
|
120
|
+
platform,
|
|
121
|
+
force
|
|
122
|
+
});
|
|
123
|
+
if (results.length === 0) {
|
|
124
|
+
throw new Error(`Failed to analyze any versions for package: ${baseName}`);
|
|
125
|
+
}
|
|
126
|
+
// Format results.
|
|
127
|
+
const formattedVersions = results.map((r)=>({
|
|
128
|
+
version: r.version,
|
|
129
|
+
rawSize: r.rawSize,
|
|
130
|
+
gzipSize: r.gzipSize,
|
|
131
|
+
rawSizeFormatted: formatBytes(r.rawSize),
|
|
132
|
+
gzipSizeFormatted: r.gzipSize !== null ? formatBytes(r.gzipSize) : null
|
|
133
|
+
}));
|
|
134
|
+
// Calculate change between oldest and newest.
|
|
135
|
+
let change = null;
|
|
136
|
+
if (results.length > 1) {
|
|
137
|
+
const newest = results[0];
|
|
138
|
+
const oldest = results[results.length - 1];
|
|
139
|
+
const rawDiff = newest.rawSize - oldest.rawSize;
|
|
140
|
+
// Handle division by zero: if oldest size is 0, percent is null.
|
|
141
|
+
const rawPercent = oldest.rawSize === 0 ? null : rawDiff / oldest.rawSize * 100;
|
|
142
|
+
let gzipDiff = null;
|
|
143
|
+
let gzipPercent = null;
|
|
144
|
+
let gzipDiffFormatted = null;
|
|
145
|
+
if (newest.gzipSize !== null && oldest.gzipSize !== null) {
|
|
146
|
+
gzipDiff = newest.gzipSize - oldest.gzipSize;
|
|
147
|
+
// Handle division by zero: if oldest size is 0, percent is null.
|
|
148
|
+
gzipPercent = oldest.gzipSize === 0 ? null : gzipDiff / oldest.gzipSize * 100;
|
|
149
|
+
gzipDiffFormatted = gzipDiff >= 0 ? `+${formatBytes(gzipDiff)}` : `-${formatBytes(Math.abs(gzipDiff))}`;
|
|
150
|
+
}
|
|
151
|
+
change = {
|
|
152
|
+
fromVersion: oldest.version,
|
|
153
|
+
toVersion: newest.version,
|
|
154
|
+
rawDiff,
|
|
155
|
+
rawPercent: rawPercent !== null ? Number.parseFloat(rawPercent.toFixed(1)) : null,
|
|
156
|
+
rawDiffFormatted: rawDiff >= 0 ? `+${formatBytes(rawDiff)}` : `-${formatBytes(Math.abs(rawDiff))}`,
|
|
157
|
+
gzipDiff,
|
|
158
|
+
gzipPercent: gzipPercent !== null ? Number.parseFloat(gzipPercent.toFixed(1)) : null,
|
|
159
|
+
gzipDiffFormatted
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
packageName: fullPackagePath,
|
|
164
|
+
versions: formattedVersions,
|
|
165
|
+
change
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get available versions for an npm package.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```js
|
|
173
|
+
* import { getPackageVersions } from "@node-cli/bundlecheck";
|
|
174
|
+
*
|
|
175
|
+
* const { versions, tags } = await getPackageVersions({
|
|
176
|
+
* package: "@mantine/core",
|
|
177
|
+
* });
|
|
178
|
+
*
|
|
179
|
+
* console.log(tags.latest); // "7.0.0"
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
*/ export async function getPackageVersions(options) {
|
|
183
|
+
const { package: packageName, registry } = options;
|
|
184
|
+
const result = await fetchVersions({
|
|
185
|
+
packageName,
|
|
186
|
+
registry
|
|
187
|
+
});
|
|
188
|
+
return {
|
|
189
|
+
versions: result.versions,
|
|
190
|
+
tags: result.tags
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* =============================================================================
|
|
195
|
+
* Re-exports for advanced usage
|
|
196
|
+
* =============================================================================
|
|
197
|
+
*/ /**
|
|
198
|
+
* - Format bytes to human-readable string (e.g., 1024 → "1 kB").
|
|
199
|
+
* - Parse a package specifier (e.g., "@scope/name@1.0.0" → { name, version,
|
|
200
|
+
* subpath }).
|
|
201
|
+
*/ export { formatBytes, parsePackageSpecifier } from "./bundler.js";
|
|
202
|
+
/**
|
|
203
|
+
* - Clear the bundle cache.
|
|
204
|
+
* - Get the number of cached entries.
|
|
205
|
+
*/ export { clearCache, getCacheCount } from "./cache.js";
|
|
206
|
+
/**
|
|
207
|
+
* =============================================================================
|
|
208
|
+
* Internal Helpers
|
|
209
|
+
* =============================================================================
|
|
210
|
+
*/ /**
|
|
211
|
+
* Format a BundleResult into a BundleStats object.
|
|
212
|
+
*/ function formatBundleStats(result, fromCache) {
|
|
213
|
+
return {
|
|
214
|
+
packageName: result.packageName,
|
|
215
|
+
packageVersion: result.packageVersion,
|
|
216
|
+
exports: result.exports,
|
|
217
|
+
rawSize: result.rawSize,
|
|
218
|
+
gzipSize: result.gzipSize,
|
|
219
|
+
gzipLevel: result.gzipLevel,
|
|
220
|
+
externals: result.externals,
|
|
221
|
+
dependencies: result.dependencies,
|
|
222
|
+
platform: result.platform,
|
|
223
|
+
rawSizeFormatted: formatBytes(result.rawSize),
|
|
224
|
+
gzipSizeFormatted: result.gzipSize !== null ? formatBytes(result.gzipSize) : null,
|
|
225
|
+
fromCache
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @node-cli/bundlecheck - Library API\n *\n * Programmatic interface for analyzing npm package bundle sizes.\n *\n */\n\nimport {\n\ttype BundleResult,\n\tcheckBundleSize,\n\tformatBytes,\n\tgetExternals,\n\tparsePackageSpecifier,\n} from \"./bundler.js\";\nimport {\n\tgetCachedResult,\n\tnormalizeCacheKey,\n\tsetCachedResult,\n} from \"./cache.js\";\nimport { normalizePlatform, TREND_VERSION_COUNT } from \"./defaults.js\";\nimport { analyzeTrend, selectTrendVersions } from \"./trend.js\";\nimport { fetchPackageVersions as fetchVersions } from \"./versions.js\";\n\n/**\n * =============================================================================\n * Types\n * =============================================================================\n */\n\n/**\n * Options for getting bundle stats of a single package.\n */\nexport type GetBundleStatsOptions = {\n\t/**\n\t * Package name with optional version (e.g., \"@mantine/core\" or\n\t * \"@mantine/core@7.0.0\").\n\t */\n\tpackage: string;\n\t/**\n\t * Specific exports to measure (e.g., [\"Button\", \"Input\"]).\n\t */\n\texports?: string[];\n\t/**\n\t * Additional packages to mark as external (not bundled).\n\t */\n\texternal?: string[];\n\t/**\n\t * Bundle everything including default externals (react, react-dom).\n\t */\n\tnoExternal?: boolean;\n\t/**\n\t * Gzip compression level (1-9, default 5).\n\t */\n\tgzipLevel?: number;\n\t/**\n\t * Custom npm registry URL.\n\t */\n\tregistry?: string;\n\t/**\n\t * Target platform: \"browser\", \"node\", or \"auto\" (default: \"auto\" - auto-detect\n\t * from package.json).\n\t */\n\tplatform?: \"browser\" | \"node\" | \"auto\";\n\t/**\n\t * Bypass cache and force re-analysis.\n\t */\n\tforce?: boolean;\n};\n\n/**\n * Result from getBundleStats.\n */\nexport type BundleStats = {\n\t/**\n\t * Display name of the package (may include subpath).\n\t */\n\tpackageName: string;\n\t/**\n\t * Resolved package version.\n\t */\n\tpackageVersion: string;\n\t/**\n\t * Exports that were analyzed.\n\t */\n\texports: string[];\n\t/**\n\t * Raw (minified) bundle size in bytes.\n\t */\n\trawSize: number;\n\t/**\n\t * Gzipped bundle size in bytes (null for node platform).\n\t */\n\tgzipSize: number | null;\n\t/**\n\t * Gzip compression level used.\n\t */\n\tgzipLevel: number;\n\t/**\n\t * Packages marked as external (not included in bundle).\n\t */\n\texternals: string[];\n\t/**\n\t * Package dependencies.\n\t */\n\tdependencies: string[];\n\t/**\n\t * Target platform used for bundling.\n\t */\n\tplatform: \"browser\" | \"node\";\n\t/**\n\t * Human-readable raw size (e.g., \"45.2 kB\").\n\t */\n\trawSizeFormatted: string;\n\t/**\n\t * Human-readable gzip size (e.g., \"12.3 kB\") or null.\n\t */\n\tgzipSizeFormatted: string | null;\n\t/**\n\t * Whether the result was retrieved from cache.\n\t */\n\tfromCache: boolean;\n};\n\n/**\n * Options for getting bundle size trend across versions.\n */\nexport type GetBundleTrendOptions = {\n\t/**\n\t * Package name (e.g., \"@mantine/core\") - version is ignored if provided.\n\t */\n\tpackage: string;\n\t/**\n\t * Number of versions to analyze (default 5).\n\t */\n\tversionCount?: number;\n\t/**\n\t * Specific exports to measure (e.g., [\"Button\", \"Input\"]).\n\t */\n\texports?: string[];\n\t/**\n\t * Additional packages to mark as external (not bundled).\n\t */\n\texternal?: string[];\n\t/**\n\t * Bundle everything including default externals (react, react-dom).\n\t */\n\tnoExternal?: boolean;\n\t/**\n\t * Gzip compression level (1-9, default 5).\n\t */\n\tgzipLevel?: number;\n\t/**\n\t * Custom npm registry URL.\n\t */\n\tregistry?: string;\n\t/**\n\t * Target platform: \"browser\", \"node\", or \"auto\" (default: \"auto\" - auto-detect\n\t * from package.json).\n\t */\n\tplatform?: \"browser\" | \"node\" | \"auto\";\n\t/**\n\t * Bypass cache and force re-analysis.\n\t */\n\tforce?: boolean;\n};\n\n/**\n * Single version result in trend analysis.\n */\nexport type TrendVersionResult = {\n\t/**\n\t * Package version.\n\t */\n\tversion: string;\n\t/**\n\t * Raw (minified) bundle size in bytes.\n\t */\n\trawSize: number;\n\t/**\n\t * Gzipped bundle size in bytes (null for node platform).\n\t */\n\tgzipSize: number | null;\n\t/**\n\t * Human-readable raw size (e.g., \"45.2 kB\").\n\t */\n\trawSizeFormatted: string;\n\t/**\n\t * Human-readable gzip size (e.g., \"12.3 kB\") or null.\n\t */\n\tgzipSizeFormatted: string | null;\n};\n\n/**\n * Size change information between oldest and newest versions.\n */\nexport type TrendChange = {\n\t/**\n\t * Oldest version analyzed.\n\t */\n\tfromVersion: string;\n\t/**\n\t * Newest version analyzed.\n\t */\n\ttoVersion: string;\n\t/**\n\t * Raw size difference in bytes (positive = increase, negative = decrease).\n\t */\n\trawDiff: number;\n\t/**\n\t * Raw size percentage change (null if oldest size was 0).\n\t */\n\trawPercent: number | null;\n\t/**\n\t * Human-readable raw size change (e.g., \"+5.2 kB\" or \"-1.3 kB\").\n\t */\n\trawDiffFormatted: string;\n\t/**\n\t * Gzip size difference in bytes (null if not applicable).\n\t */\n\tgzipDiff: number | null;\n\t/**\n\t * Gzip size percentage change (null if not applicable or oldest size was 0).\n\t */\n\tgzipPercent: number | null;\n\t/**\n\t * Human-readable gzip size change (e.g., \"+1.5 kB\" or \"-0.8 kB\") or null.\n\t */\n\tgzipDiffFormatted: string | null;\n};\n\n/**\n * Result from getBundleTrend.\n */\nexport type BundleTrend = {\n\t/**\n\t * Package name.\n\t */\n\tpackageName: string;\n\t/**\n\t * Results for each version analyzed (newest first).\n\t */\n\tversions: TrendVersionResult[];\n\t/**\n\t * Size change between oldest and newest versions (null if only one version).\n\t */\n\tchange: TrendChange | null;\n};\n\n/**\n * Options for fetching package versions.\n */\nexport type GetPackageVersionsOptions = {\n\t/**\n\t * Package name (e.g., \"@mantine/core\").\n\t */\n\tpackage: string;\n\t/**\n\t * Custom npm registry URL.\n\t */\n\tregistry?: string;\n};\n\n/**\n * Result from getPackageVersions.\n */\nexport type PackageVersions = {\n\t/**\n\t * All available versions (sorted newest first).\n\t */\n\tversions: string[];\n\t/**\n\t * Distribution tags (e.g., { latest: \"7.0.0\", next: \"8.0.0-beta.1\" }).\n\t */\n\ttags: Record<string, string>;\n};\n\n/**\n * =============================================================================\n * Library Functions\n * =============================================================================\n */\n\n/**\n * Get bundle size statistics for an npm package.\n *\n * @example\n * ```js\n * import { getBundleStats } from \"@node-cli/bundlecheck\";\n *\n * const stats = await getBundleStats({\n * package: \"@mantine/core@7.0.0\",\n * exports: [\"Button\", \"Input\"],\n * });\n *\n * console.log(stats.gzipSizeFormatted); // \"12.3 kB\"\n * ```\n *\n */\nexport async function getBundleStats(\n\toptions: GetBundleStatsOptions,\n): Promise<BundleStats> {\n\tconst {\n\t\tpackage: packageName,\n\t\texports: exportsList,\n\t\texternal: additionalExternals,\n\t\tnoExternal,\n\t\tgzipLevel = 5,\n\t\tregistry,\n\t\tplatform: platformOption = \"auto\",\n\t\tforce = false,\n\t} = options;\n\n\t// Normalize platform.\n\tconst platform = normalizePlatform(\n\t\tplatformOption === \"auto\" ? undefined : platformOption,\n\t);\n\n\t// Parse package specifier.\n\tconst { name: baseName, version: requestedVersion } =\n\t\tparsePackageSpecifier(packageName);\n\n\t// Resolve \"latest\" to actual version for cache key.\n\tlet resolvedVersion = requestedVersion;\n\tif (requestedVersion === \"latest\") {\n\t\tconst { tags } = await fetchVersions({\n\t\t\tpackageName: baseName,\n\t\t\tregistry,\n\t\t});\n\t\tresolvedVersion = tags.latest || requestedVersion;\n\t}\n\n\t// Compute externals for cache key.\n\tconst externals = getExternals(baseName, additionalExternals, noExternal);\n\n\t// Build cache key.\n\tconst cacheKey = normalizeCacheKey({\n\t\tpackageName: baseName,\n\t\tversion: resolvedVersion,\n\t\texports: exportsList,\n\t\tplatform,\n\t\tgzipLevel,\n\t\texternals,\n\t\tnoExternal: noExternal ?? false,\n\t});\n\n\t// Check cache (unless force is set).\n\tif (!force) {\n\t\tconst cached = getCachedResult(cacheKey);\n\t\tif (cached) {\n\t\t\treturn formatBundleStats(cached, true);\n\t\t}\n\t}\n\n\t// Perform the analysis.\n\tconst result = await checkBundleSize({\n\t\tpackageName,\n\t\texports: exportsList,\n\t\tadditionalExternals,\n\t\tnoExternal,\n\t\tgzipLevel,\n\t\tregistry,\n\t\tplatform,\n\t});\n\n\t// Store in cache.\n\tsetCachedResult(cacheKey, result);\n\n\treturn formatBundleStats(result, false);\n}\n\n/**\n * Get bundle size trend across multiple versions of a package.\n *\n * @example\n * ```js\n * import { getBundleTrend } from \"@node-cli/bundlecheck\";\n *\n * const trend = await getBundleTrend({\n * package: \"@mantine/core\",\n * versionCount: 5,\n * });\n *\n * console.log(trend.change?.rawDiffFormatted); // \"+5.2 kB\"\n * ```\n *\n */\nexport async function getBundleTrend(\n\toptions: GetBundleTrendOptions,\n): Promise<BundleTrend> {\n\tconst {\n\t\tpackage: packageName,\n\t\tversionCount = TREND_VERSION_COUNT,\n\t\texports: exportsList,\n\t\texternal: additionalExternals,\n\t\tnoExternal,\n\t\tgzipLevel,\n\t\tregistry,\n\t\tplatform: platformOption = \"auto\",\n\t\tforce = false,\n\t} = options;\n\n\t// Normalize platform.\n\tconst platform = normalizePlatform(\n\t\tplatformOption === \"auto\" ? undefined : platformOption,\n\t);\n\n\t// Parse package name (ignore version if provided).\n\tconst { name: baseName, subpath } = parsePackageSpecifier(packageName);\n\tconst fullPackagePath = subpath ? `${baseName}/${subpath}` : baseName;\n\n\t// Fetch available versions.\n\tconst { versions } = await fetchVersions({\n\t\tpackageName: baseName,\n\t\tregistry,\n\t});\n\n\tif (versions.length === 0) {\n\t\tthrow new Error(`No versions found for package: ${baseName}`);\n\t}\n\n\t// Select versions for trend.\n\tconst trendVersions = selectTrendVersions(versions, versionCount);\n\n\t// Analyze all versions (silently - no console output).\n\tconst results = await analyzeTrend({\n\t\tpackageName: fullPackagePath,\n\t\tversions: trendVersions,\n\t\texports: exportsList,\n\t\tadditionalExternals,\n\t\tnoExternal,\n\t\tgzipLevel,\n\t\tboring: true, // Suppress logging\n\t\tregistry,\n\t\tplatform,\n\t\tforce,\n\t});\n\n\tif (results.length === 0) {\n\t\tthrow new Error(`Failed to analyze any versions for package: ${baseName}`);\n\t}\n\n\t// Format results.\n\tconst formattedVersions: TrendVersionResult[] = results.map((r) => ({\n\t\tversion: r.version,\n\t\trawSize: r.rawSize,\n\t\tgzipSize: r.gzipSize,\n\t\trawSizeFormatted: formatBytes(r.rawSize),\n\t\tgzipSizeFormatted: r.gzipSize !== null ? formatBytes(r.gzipSize) : null,\n\t}));\n\n\t// Calculate change between oldest and newest.\n\tlet change: TrendChange | null = null;\n\tif (results.length > 1) {\n\t\tconst newest = results[0];\n\t\tconst oldest = results[results.length - 1];\n\n\t\tconst rawDiff = newest.rawSize - oldest.rawSize;\n\t\t// Handle division by zero: if oldest size is 0, percent is null.\n\t\tconst rawPercent =\n\t\t\toldest.rawSize === 0 ? null : (rawDiff / oldest.rawSize) * 100;\n\n\t\tlet gzipDiff: number | null = null;\n\t\tlet gzipPercent: number | null = null;\n\t\tlet gzipDiffFormatted: string | null = null;\n\n\t\tif (newest.gzipSize !== null && oldest.gzipSize !== null) {\n\t\t\tgzipDiff = newest.gzipSize - oldest.gzipSize;\n\t\t\t// Handle division by zero: if oldest size is 0, percent is null.\n\t\t\tgzipPercent =\n\t\t\t\toldest.gzipSize === 0 ? null : (gzipDiff / oldest.gzipSize) * 100;\n\t\t\tgzipDiffFormatted =\n\t\t\t\tgzipDiff >= 0\n\t\t\t\t\t? `+${formatBytes(gzipDiff)}`\n\t\t\t\t\t: `-${formatBytes(Math.abs(gzipDiff))}`;\n\t\t}\n\n\t\tchange = {\n\t\t\tfromVersion: oldest.version,\n\t\t\ttoVersion: newest.version,\n\t\t\trawDiff,\n\t\t\trawPercent:\n\t\t\t\trawPercent !== null ? Number.parseFloat(rawPercent.toFixed(1)) : null,\n\t\t\trawDiffFormatted:\n\t\t\t\trawDiff >= 0\n\t\t\t\t\t? `+${formatBytes(rawDiff)}`\n\t\t\t\t\t: `-${formatBytes(Math.abs(rawDiff))}`,\n\t\t\tgzipDiff,\n\t\t\tgzipPercent:\n\t\t\t\tgzipPercent !== null ? Number.parseFloat(gzipPercent.toFixed(1)) : null,\n\t\t\tgzipDiffFormatted,\n\t\t};\n\t}\n\n\treturn {\n\t\tpackageName: fullPackagePath,\n\t\tversions: formattedVersions,\n\t\tchange,\n\t};\n}\n\n/**\n * Get available versions for an npm package.\n *\n * @example\n * ```js\n * import { getPackageVersions } from \"@node-cli/bundlecheck\";\n *\n * const { versions, tags } = await getPackageVersions({\n * package: \"@mantine/core\",\n * });\n *\n * console.log(tags.latest); // \"7.0.0\"\n * ```\n *\n */\nexport async function getPackageVersions(\n\toptions: GetPackageVersionsOptions,\n): Promise<PackageVersions> {\n\tconst { package: packageName, registry } = options;\n\n\tconst result = await fetchVersions({\n\t\tpackageName,\n\t\tregistry,\n\t});\n\n\treturn {\n\t\tversions: result.versions,\n\t\ttags: result.tags,\n\t};\n}\n\n/**\n * =============================================================================\n * Re-exports for advanced usage\n * =============================================================================\n */\n\n/**\n * - Format bytes to human-readable string (e.g., 1024 → \"1 kB\").\n * - Parse a package specifier (e.g., \"@scope/name@1.0.0\" → { name, version,\n * subpath }).\n */\nexport { formatBytes, parsePackageSpecifier } from \"./bundler.js\";\n/**\n * - Clear the bundle cache.\n * - Get the number of cached entries.\n */\nexport { clearCache, getCacheCount } from \"./cache.js\";\n\n/**\n * =============================================================================\n * Internal Helpers\n * =============================================================================\n */\n\n/**\n * Format a BundleResult into a BundleStats object.\n */\nfunction formatBundleStats(\n\tresult: BundleResult,\n\tfromCache: boolean,\n): BundleStats {\n\treturn {\n\t\tpackageName: result.packageName,\n\t\tpackageVersion: result.packageVersion,\n\t\texports: result.exports,\n\t\trawSize: result.rawSize,\n\t\tgzipSize: result.gzipSize,\n\t\tgzipLevel: result.gzipLevel,\n\t\texternals: result.externals,\n\t\tdependencies: result.dependencies,\n\t\tplatform: result.platform,\n\t\trawSizeFormatted: formatBytes(result.rawSize),\n\t\tgzipSizeFormatted:\n\t\t\tresult.gzipSize !== null ? formatBytes(result.gzipSize) : null,\n\t\tfromCache,\n\t};\n}\n"],"names":["checkBundleSize","formatBytes","getExternals","parsePackageSpecifier","getCachedResult","normalizeCacheKey","setCachedResult","normalizePlatform","TREND_VERSION_COUNT","analyzeTrend","selectTrendVersions","fetchPackageVersions","fetchVersions","getBundleStats","options","package","packageName","exports","exportsList","external","additionalExternals","noExternal","gzipLevel","registry","platform","platformOption","force","undefined","name","baseName","version","requestedVersion","resolvedVersion","tags","latest","externals","cacheKey","cached","formatBundleStats","result","getBundleTrend","versionCount","subpath","fullPackagePath","versions","length","Error","trendVersions","results","boring","formattedVersions","map","r","rawSize","gzipSize","rawSizeFormatted","gzipSizeFormatted","change","newest","oldest","rawDiff","rawPercent","gzipDiff","gzipPercent","gzipDiffFormatted","Math","abs","fromVersion","toVersion","Number","parseFloat","toFixed","rawDiffFormatted","getPackageVersions","clearCache","getCacheCount","fromCache","packageVersion","dependencies"],"mappings":"AAAA;;;;;CAKC,GAED,SAECA,eAAe,EACfC,WAAW,EACXC,YAAY,EACZC,qBAAqB,QACf,eAAe;AACtB,SACCC,eAAe,EACfC,iBAAiB,EACjBC,eAAe,QACT,aAAa;AACpB,SAASC,iBAAiB,EAAEC,mBAAmB,QAAQ,gBAAgB;AACvE,SAASC,YAAY,EAAEC,mBAAmB,QAAQ,aAAa;AAC/D,SAASC,wBAAwBC,aAAa,QAAQ,gBAAgB;AA+PtE;;;;CAIC,GAED;;;;;;;;;;;;;;;CAeC,GACD,OAAO,eAAeC,eACrBC,OAA8B;IAE9B,MAAM,EACLC,SAASC,WAAW,EACpBC,SAASC,WAAW,EACpBC,UAAUC,mBAAmB,EAC7BC,UAAU,EACVC,YAAY,CAAC,EACbC,QAAQ,EACRC,UAAUC,iBAAiB,MAAM,EACjCC,QAAQ,KAAK,EACb,GAAGZ;IAEJ,sBAAsB;IACtB,MAAMU,WAAWjB,kBAChBkB,mBAAmB,SAASE,YAAYF;IAGzC,2BAA2B;IAC3B,MAAM,EAAEG,MAAMC,QAAQ,EAAEC,SAASC,gBAAgB,EAAE,GAClD5B,sBAAsBa;IAEvB,oDAAoD;IACpD,IAAIgB,kBAAkBD;IACtB,IAAIA,qBAAqB,UAAU;QAClC,MAAM,EAAEE,IAAI,EAAE,GAAG,MAAMrB,cAAc;YACpCI,aAAaa;YACbN;QACD;QACAS,kBAAkBC,KAAKC,MAAM,IAAIH;IAClC;IAEA,mCAAmC;IACnC,MAAMI,YAAYjC,aAAa2B,UAAUT,qBAAqBC;IAE9D,mBAAmB;IACnB,MAAMe,WAAW/B,kBAAkB;QAClCW,aAAaa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DsB;IACD;AACD"}
|
package/dist/parse.d.ts
CHANGED
package/dist/parse.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* istanbul ignore file */ import { parser } from "@node-cli/parser";
|
|
2
|
-
import { DEFAULT_EXTERNALS, defaultFlags } from "./defaults.js";
|
|
2
|
+
import { DEFAULT_EXTERNALS, defaultFlags, isValidPlatform } from "./defaults.js";
|
|
3
3
|
export const config = parser({
|
|
4
4
|
meta: import.meta,
|
|
5
5
|
examples: [
|
|
@@ -46,6 +46,14 @@ export const config = parser({
|
|
|
46
46
|
{
|
|
47
47
|
command: "bundlecheck lodash --registry https://registry.example.com",
|
|
48
48
|
comment: "## Use a custom npm registry"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
command: "bundlecheck express --platform node",
|
|
52
|
+
comment: "## Check bundle size for Node.js platform (aliases: server, nodejs, backend)"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
command: "bundlecheck lodash --force",
|
|
56
|
+
comment: "## Bypass cache and force re-fetch/re-calculation"
|
|
49
57
|
}
|
|
50
58
|
],
|
|
51
59
|
flags: {
|
|
@@ -99,6 +107,18 @@ export const config = parser({
|
|
|
99
107
|
default: defaultFlags.registry,
|
|
100
108
|
description: "Custom npm registry URL (default: https://registry.npmjs.org)",
|
|
101
109
|
type: "string"
|
|
110
|
+
},
|
|
111
|
+
platform: {
|
|
112
|
+
shortFlag: "p",
|
|
113
|
+
default: defaultFlags.platform,
|
|
114
|
+
description: 'Target platform: "auto" (default, detects from engines), "browser" or "node"',
|
|
115
|
+
type: "string"
|
|
116
|
+
},
|
|
117
|
+
force: {
|
|
118
|
+
shortFlag: "f",
|
|
119
|
+
default: defaultFlags.force,
|
|
120
|
+
description: "Bypass cache and force re-fetch/re-calculation",
|
|
121
|
+
type: "boolean"
|
|
102
122
|
}
|
|
103
123
|
},
|
|
104
124
|
parameters: {
|
|
@@ -119,6 +139,11 @@ export const config = parser({
|
|
|
119
139
|
exit: 1,
|
|
120
140
|
message: ()=>"Error: Gzip level must be between 1 and 9",
|
|
121
141
|
test: (flags)=>flags.gzipLevel !== undefined && (flags.gzipLevel < 1 || flags.gzipLevel > 9)
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
exit: 1,
|
|
145
|
+
message: ()=>'Error: Invalid platform. Use "browser" (or web, desktop, client) or "node" (or server, nodejs, backend)',
|
|
146
|
+
test: (flags)=>!isValidPlatform(flags.platform)
|
|
122
147
|
}
|
|
123
148
|
],
|
|
124
149
|
usage: true,
|
package/dist/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["/* istanbul ignore file */\nimport { parser } from \"@node-cli/parser\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["/* istanbul ignore file */\nimport { parser } from \"@node-cli/parser\";\nimport {\n\tDEFAULT_EXTERNALS,\n\tdefaultFlags,\n\tisValidPlatform,\n} from \"./defaults.js\";\n\nexport type Flags = {\n\tboring?: boolean;\n\thelp?: boolean;\n\tversion?: boolean;\n\tversions?: boolean;\n\ttrend?: string;\n\tgzipLevel?: number;\n\texternal?: string;\n\tnoExternal?: boolean;\n\tregistry?: string;\n\tplatform?: string;\n\tforce?: boolean;\n};\n\nexport type Parameters = {\n\t[\"0\"]?: string; // package name\n\t[\"1\"]?: string; // exports (comma-separated)\n};\n\nexport type Configuration = {\n\tflags?: Flags;\n\tparameters?: Parameters;\n\tusage?: boolean;\n\tshowHelp?: () => void;\n};\n\nexport const config: Configuration = parser({\n\tmeta: import.meta,\n\texamples: [\n\t\t{\n\t\t\tcommand: \"bundlecheck lodash\",\n\t\t\tcomment: \"## Check the bundle size of the entire lodash package\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"bundlecheck lodash@4.17.0\",\n\t\t\tcomment: \"## Check a specific version of a package\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"bundlecheck @mantine/core\",\n\t\t\tcomment: \"## Check the bundle size of the entire @mantine/core package\",\n\t\t},\n\t\t{\n\t\t\tcommand: 'bundlecheck @mantine/core \"ScrollArea,Button\"',\n\t\t\tcomment:\n\t\t\t\t\"## Check the bundle size of specific exports from @mantine/core\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"bundlecheck react --no-external\",\n\t\t\tcomment:\n\t\t\t\t\"## Check the bundle size of react itself (not marked as external)\",\n\t\t},\n\t\t{\n\t\t\tcommand: 'bundlecheck some-pkg --external \"vue,svelte\"',\n\t\t\tcomment: \"## Add vue and svelte as additional external dependencies\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"bundlecheck lodash --gzip-level 6\",\n\t\t\tcomment: \"## Use a different gzip compression level (1-9)\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"bundlecheck lodash --versions\",\n\t\t\tcomment: \"## Choose from available versions interactively\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"bundlecheck lodash --trend\",\n\t\t\tcomment: \"## Show bundle size trend (default: 5 versions)\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"bundlecheck lodash --trend 3\",\n\t\t\tcomment: \"## Show bundle size trend for 3 versions\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"bundlecheck lodash --registry https://registry.example.com\",\n\t\t\tcomment: \"## Use a custom npm registry\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"bundlecheck express --platform node\",\n\t\t\tcomment:\n\t\t\t\t\"## Check bundle size for Node.js platform (aliases: server, nodejs, backend)\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"bundlecheck lodash --force\",\n\t\t\tcomment: \"## Bypass cache and force re-fetch/re-calculation\",\n\t\t},\n\t],\n\tflags: {\n\t\tgzipLevel: {\n\t\t\tshortFlag: \"g\",\n\t\t\tdefault: defaultFlags.gzipLevel,\n\t\t\tdescription: \"Gzip compression level (1-9, default: 5)\",\n\t\t\ttype: \"number\",\n\t\t},\n\t\texternal: {\n\t\t\tshortFlag: \"e\",\n\t\t\tdefault: defaultFlags.external,\n\t\t\tdescription: `Comma-separated additional externals (default externals: ${DEFAULT_EXTERNALS.join(\", \")})`,\n\t\t\ttype: \"string\",\n\t\t},\n\t\tnoExternal: {\n\t\t\tshortFlag: \"n\",\n\t\t\tdefault: defaultFlags.noExternal,\n\t\t\tdescription:\n\t\t\t\t\"Do not mark any packages as external (useful for checking react/react-dom themselves)\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tboring: {\n\t\t\tshortFlag: \"b\",\n\t\t\tdefault: defaultFlags.boring,\n\t\t\tdescription: \"Do not use color output\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\thelp: {\n\t\t\tshortFlag: \"h\",\n\t\t\tdescription: \"Display help instructions\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tversion: {\n\t\t\tshortFlag: \"v\",\n\t\t\tdescription: \"Output the current version\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tversions: {\n\t\t\tshortFlag: \"V\",\n\t\t\tdefault: defaultFlags.versions,\n\t\t\tdescription: \"Choose from available package versions interactively\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\ttrend: {\n\t\t\tshortFlag: \"t\",\n\t\t\tdescription: \"Show bundle size trend for N recent versions (default: 5)\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\tregistry: {\n\t\t\tshortFlag: \"r\",\n\t\t\tdefault: defaultFlags.registry,\n\t\t\tdescription:\n\t\t\t\t\"Custom npm registry URL (default: https://registry.npmjs.org)\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\tplatform: {\n\t\t\tshortFlag: \"p\",\n\t\t\tdefault: defaultFlags.platform,\n\t\t\tdescription:\n\t\t\t\t'Target platform: \"auto\" (default, detects from engines), \"browser\" or \"node\"',\n\t\t\ttype: \"string\",\n\t\t},\n\t\tforce: {\n\t\t\tshortFlag: \"f\",\n\t\t\tdefault: defaultFlags.force,\n\t\t\tdescription: \"Bypass cache and force re-fetch/re-calculation\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t},\n\tparameters: {\n\t\tpackage: {\n\t\t\tdescription: \"The npm package to check (e.g., lodash, @mantine/core)\",\n\t\t},\n\t\texports: {\n\t\t\tdescription:\n\t\t\t\t'Comma-separated list of exports to check (e.g., \"ScrollArea,Button\")',\n\t\t},\n\t},\n\trestrictions: [\n\t\t{\n\t\t\texit: 1,\n\t\t\tmessage: () => \"Error: Package name is required\",\n\t\t\ttest: (flags, parameters) => !parameters?.[\"0\"],\n\t\t},\n\t\t{\n\t\t\texit: 1,\n\t\t\tmessage: () => \"Error: Gzip level must be between 1 and 9\",\n\t\t\ttest: (flags) =>\n\t\t\t\tflags.gzipLevel !== undefined &&\n\t\t\t\t(flags.gzipLevel < 1 || flags.gzipLevel > 9),\n\t\t},\n\t\t{\n\t\t\texit: 1,\n\t\t\tmessage: () =>\n\t\t\t\t'Error: Invalid platform. Use \"browser\" (or web, desktop, client) or \"node\" (or server, nodejs, backend)',\n\t\t\ttest: (flags) => !isValidPlatform(flags.platform),\n\t\t},\n\t],\n\tusage: true,\n\tdefaultFlags,\n});\n"],"names":["parser","DEFAULT_EXTERNALS","defaultFlags","isValidPlatform","config","meta","examples","command","comment","flags","gzipLevel","shortFlag","default","description","type","external","join","noExternal","boring","help","version","versions","trend","registry","platform","force","parameters","package","exports","restrictions","exit","message","test","undefined","usage"],"mappings":"AAAA,wBAAwB,GACxB,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SACCC,iBAAiB,EACjBC,YAAY,EACZC,eAAe,QACT,gBAAgB;AA4BvB,OAAO,MAAMC,SAAwBJ,OAAO;IAC3CK,MAAM;IACNC,UAAU;QACT;YACCC,SAAS;YACTC,SAAS;QACV;QACA;YACCD,SAAS;YACTC,SAAS;QACV;QACA;YACCD,SAAS;YACTC,SAAS;QACV;QACA;YACCD,SAAS;YACTC,SACC;QACF;QACA;YACCD,SAAS;YACTC,SACC;QACF;QACA;YACCD,SAAS;YACTC,SAAS;QACV;QACA;YACCD,SAAS;YACTC,SAAS;QACV;QACA;YAC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OAAOiB,aAAe,CAACA,YAAY,CAAC,IAAI;QAChD;QACA;YACCI,MAAM;YACNC,SAAS,IAAM;YACfC,MAAM,CAACvB,QACNA,MAAMC,SAAS,KAAKuB,aACnBxB,CAAAA,MAAMC,SAAS,GAAG,KAAKD,MAAMC,SAAS,GAAG,CAAA;QAC5C;QACA;YACCoB,MAAM;YACNC,SAAS,IACR;YACDC,MAAM,CAACvB,QAAU,CAACN,gBAAgBM,MAAMe,QAAQ;QACjD;KACA;IACDU,OAAO;IACPhC;AACD,GAAG"}
|
package/dist/trend.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export type TrendResult = {
|
|
2
2
|
version: string;
|
|
3
3
|
rawSize: number;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Gzip size in bytes, or null for node platform.
|
|
6
|
+
*/
|
|
7
|
+
gzipSize: number | null;
|
|
5
8
|
};
|
|
6
9
|
export type TrendOptions = {
|
|
7
10
|
packageName: string;
|
|
@@ -12,18 +15,26 @@ export type TrendOptions = {
|
|
|
12
15
|
gzipLevel?: number;
|
|
13
16
|
boring?: boolean;
|
|
14
17
|
registry?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Target platform. If undefined, auto-detects from package.json engines.
|
|
20
|
+
*/
|
|
21
|
+
platform?: "browser" | "node";
|
|
22
|
+
/**
|
|
23
|
+
* Bypass cache and force re-fetch/re-calculation.
|
|
24
|
+
*/
|
|
25
|
+
force?: boolean;
|
|
15
26
|
};
|
|
16
27
|
/**
|
|
17
|
-
* Select versions for trend analysis
|
|
18
|
-
*
|
|
19
|
-
*
|
|
28
|
+
* Select versions for trend analysis Returns the most recent stable versions
|
|
29
|
+
* (newest first) Filters out prerelease versions (canary, alpha, beta, rc,
|
|
30
|
+
* etc.)
|
|
20
31
|
*/
|
|
21
32
|
export declare function selectTrendVersions(allVersions: string[], count?: number): string[];
|
|
22
33
|
/**
|
|
23
|
-
* Analyze bundle size trend across multiple versions
|
|
34
|
+
* Analyze bundle size trend across multiple versions.
|
|
24
35
|
*/
|
|
25
36
|
export declare function analyzeTrend(options: TrendOptions): Promise<TrendResult[]>;
|
|
26
37
|
/**
|
|
27
|
-
* Render a bar graph showing bundle size trend
|
|
38
|
+
* Render a bar graph showing bundle size trend.
|
|
28
39
|
*/
|
|
29
40
|
export declare function renderTrendGraph(packageName: string, results: TrendResult[], boring?: boolean): string[];
|