@node-cli/bundlecheck 1.4.0 → 1.5.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 +58 -7
- package/dist/bundlecheck.js +10 -1
- package/dist/bundlecheck.js.map +1 -1
- package/dist/bundler.d.ts +19 -2
- package/dist/bundler.js +179 -30
- package/dist/bundler.js.map +1 -1
- package/dist/cache.js +29 -6
- package/dist/cache.js.map +1 -1
- package/dist/defaults.d.ts +10 -0
- package/dist/defaults.js +18 -1
- package/dist/defaults.js.map +1 -1
- package/dist/exports-installer.d.ts +19 -0
- package/dist/exports-installer.js +115 -0
- package/dist/exports-installer.js.map +1 -0
- package/dist/exports.d.ts +43 -0
- package/dist/exports.js +330 -0
- package/dist/exports.js.map +1 -0
- package/dist/index.d.ts +398 -3
- package/dist/index.js +64 -7
- package/dist/index.js.map +1 -1
- package/dist/parse.js +2 -2
- package/dist/parse.js.map +1 -1
- package/package.json +3 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,400 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @node-cli/bundlecheck - Library API
|
|
3
|
+
*
|
|
4
|
+
* Programmatic interface for analyzing npm package bundle sizes.
|
|
5
|
+
*
|
|
3
6
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
/**
|
|
8
|
+
* =============================================================================
|
|
9
|
+
* Types
|
|
10
|
+
* =============================================================================
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Options for getting bundle stats of a single package.
|
|
14
|
+
*/
|
|
15
|
+
export type GetBundleStatsOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* Package name with optional version (e.g., "@mantine/core" or
|
|
18
|
+
* "@mantine/core@7.0.0").
|
|
19
|
+
*/
|
|
20
|
+
package: string;
|
|
21
|
+
/**
|
|
22
|
+
* Specific exports to measure (e.g., ["Button", "Input"]).
|
|
23
|
+
*/
|
|
24
|
+
exports?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Additional packages to mark as external (not bundled).
|
|
27
|
+
*/
|
|
28
|
+
external?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Bundle everything including dependencies that would normally be external.
|
|
31
|
+
*/
|
|
32
|
+
noExternal?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Gzip compression level (1-9, default 5).
|
|
35
|
+
*/
|
|
36
|
+
gzipLevel?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Custom npm registry URL.
|
|
39
|
+
*/
|
|
40
|
+
registry?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Target platform: "browser", "node", or "auto" (default: "auto" - auto-detect
|
|
43
|
+
* from package.json).
|
|
44
|
+
*/
|
|
45
|
+
platform?: "browser" | "node" | "auto";
|
|
46
|
+
/**
|
|
47
|
+
* Bypass cache and force re-analysis.
|
|
48
|
+
*/
|
|
49
|
+
force?: boolean;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Result from getBundleStats.
|
|
53
|
+
*/
|
|
54
|
+
export type BundleStats = {
|
|
55
|
+
/**
|
|
56
|
+
* Display name of the package (may include subpath).
|
|
57
|
+
*/
|
|
58
|
+
packageName: string;
|
|
59
|
+
/**
|
|
60
|
+
* Resolved package version.
|
|
61
|
+
*/
|
|
62
|
+
packageVersion: string;
|
|
63
|
+
/**
|
|
64
|
+
* Exports that were analyzed.
|
|
65
|
+
*/
|
|
66
|
+
exports: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Raw (minified) bundle size in bytes.
|
|
69
|
+
*/
|
|
70
|
+
rawSize: number;
|
|
71
|
+
/**
|
|
72
|
+
* Gzipped bundle size in bytes (null for node platform).
|
|
73
|
+
*/
|
|
74
|
+
gzipSize: number | null;
|
|
75
|
+
/**
|
|
76
|
+
* Gzip compression level used.
|
|
77
|
+
*/
|
|
78
|
+
gzipLevel: number;
|
|
79
|
+
/**
|
|
80
|
+
* Packages marked as external (not included in bundle).
|
|
81
|
+
*/
|
|
82
|
+
externals: string[];
|
|
83
|
+
/**
|
|
84
|
+
* Package dependencies.
|
|
85
|
+
*/
|
|
86
|
+
dependencies: string[];
|
|
87
|
+
/**
|
|
88
|
+
* Target platform used for bundling.
|
|
89
|
+
*/
|
|
90
|
+
platform: "browser" | "node";
|
|
91
|
+
/**
|
|
92
|
+
* Human-readable raw size (e.g., "45.2 kB").
|
|
93
|
+
*/
|
|
94
|
+
rawSizeFormatted: string;
|
|
95
|
+
/**
|
|
96
|
+
* Human-readable gzip size (e.g., "12.3 kB") or null.
|
|
97
|
+
*/
|
|
98
|
+
gzipSizeFormatted: string | null;
|
|
99
|
+
/**
|
|
100
|
+
* Whether the result was retrieved from cache.
|
|
101
|
+
*/
|
|
102
|
+
fromCache: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Total number of named exports in the package (when analyzing entire
|
|
105
|
+
* package).
|
|
106
|
+
*/
|
|
107
|
+
namedExportCount: number;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Options for getting bundle size trend across versions.
|
|
111
|
+
*/
|
|
112
|
+
export type GetBundleTrendOptions = {
|
|
113
|
+
/**
|
|
114
|
+
* Package name (e.g., "@mantine/core") - version is ignored if provided.
|
|
115
|
+
*/
|
|
116
|
+
package: string;
|
|
117
|
+
/**
|
|
118
|
+
* Number of versions to analyze (default 5).
|
|
119
|
+
*/
|
|
120
|
+
versionCount?: number;
|
|
121
|
+
/**
|
|
122
|
+
* Specific exports to measure (e.g., ["Button", "Input"]).
|
|
123
|
+
*/
|
|
124
|
+
exports?: string[];
|
|
125
|
+
/**
|
|
126
|
+
* Additional packages to mark as external (not bundled).
|
|
127
|
+
*/
|
|
128
|
+
external?: string[];
|
|
129
|
+
/**
|
|
130
|
+
* Bundle everything including dependencies that would normally be external.
|
|
131
|
+
*/
|
|
132
|
+
noExternal?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Gzip compression level (1-9, default 5).
|
|
135
|
+
*/
|
|
136
|
+
gzipLevel?: number;
|
|
137
|
+
/**
|
|
138
|
+
* Custom npm registry URL.
|
|
139
|
+
*/
|
|
140
|
+
registry?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Target platform: "browser", "node", or "auto" (default: "auto" - auto-detect
|
|
143
|
+
* from package.json).
|
|
144
|
+
*/
|
|
145
|
+
platform?: "browser" | "node" | "auto";
|
|
146
|
+
/**
|
|
147
|
+
* Bypass cache and force re-analysis.
|
|
148
|
+
*/
|
|
149
|
+
force?: boolean;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Single version result in trend analysis.
|
|
153
|
+
*/
|
|
154
|
+
export type TrendVersionResult = {
|
|
155
|
+
/**
|
|
156
|
+
* Package version.
|
|
157
|
+
*/
|
|
158
|
+
version: string;
|
|
159
|
+
/**
|
|
160
|
+
* Raw (minified) bundle size in bytes.
|
|
161
|
+
*/
|
|
162
|
+
rawSize: number;
|
|
163
|
+
/**
|
|
164
|
+
* Gzipped bundle size in bytes (null for node platform).
|
|
165
|
+
*/
|
|
166
|
+
gzipSize: number | null;
|
|
167
|
+
/**
|
|
168
|
+
* Human-readable raw size (e.g., "45.2 kB").
|
|
169
|
+
*/
|
|
170
|
+
rawSizeFormatted: string;
|
|
171
|
+
/**
|
|
172
|
+
* Human-readable gzip size (e.g., "12.3 kB") or null.
|
|
173
|
+
*/
|
|
174
|
+
gzipSizeFormatted: string | null;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Size change information between oldest and newest versions.
|
|
178
|
+
*/
|
|
179
|
+
export type TrendChange = {
|
|
180
|
+
/**
|
|
181
|
+
* Oldest version analyzed.
|
|
182
|
+
*/
|
|
183
|
+
fromVersion: string;
|
|
184
|
+
/**
|
|
185
|
+
* Newest version analyzed.
|
|
186
|
+
*/
|
|
187
|
+
toVersion: string;
|
|
188
|
+
/**
|
|
189
|
+
* Raw size difference in bytes (positive = increase, negative = decrease).
|
|
190
|
+
*/
|
|
191
|
+
rawDiff: number;
|
|
192
|
+
/**
|
|
193
|
+
* Raw size percentage change (null if oldest size was 0).
|
|
194
|
+
*/
|
|
195
|
+
rawPercent: number | null;
|
|
196
|
+
/**
|
|
197
|
+
* Human-readable raw size change (e.g., "+5.2 kB" or "-1.3 kB").
|
|
198
|
+
*/
|
|
199
|
+
rawDiffFormatted: string;
|
|
200
|
+
/**
|
|
201
|
+
* Gzip size difference in bytes (null if not applicable).
|
|
202
|
+
*/
|
|
203
|
+
gzipDiff: number | null;
|
|
204
|
+
/**
|
|
205
|
+
* Gzip size percentage change (null if not applicable or oldest size was 0).
|
|
206
|
+
*/
|
|
207
|
+
gzipPercent: number | null;
|
|
208
|
+
/**
|
|
209
|
+
* Human-readable gzip size change (e.g., "+1.5 kB" or "-0.8 kB") or null.
|
|
210
|
+
*/
|
|
211
|
+
gzipDiffFormatted: string | null;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Result from getBundleTrend.
|
|
215
|
+
*/
|
|
216
|
+
export type BundleTrend = {
|
|
217
|
+
/**
|
|
218
|
+
* Package name.
|
|
219
|
+
*/
|
|
220
|
+
packageName: string;
|
|
221
|
+
/**
|
|
222
|
+
* Results for each version analyzed (newest first).
|
|
223
|
+
*/
|
|
224
|
+
versions: TrendVersionResult[];
|
|
225
|
+
/**
|
|
226
|
+
* Size change between oldest and newest versions (null if only one version).
|
|
227
|
+
*/
|
|
228
|
+
change: TrendChange | null;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Options for fetching package versions.
|
|
232
|
+
*/
|
|
233
|
+
export type GetPackageVersionsOptions = {
|
|
234
|
+
/**
|
|
235
|
+
* Package name (e.g., "@mantine/core").
|
|
236
|
+
*/
|
|
237
|
+
package: string;
|
|
238
|
+
/**
|
|
239
|
+
* Custom npm registry URL.
|
|
240
|
+
*/
|
|
241
|
+
registry?: string;
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Result from getPackageVersions.
|
|
245
|
+
*/
|
|
246
|
+
export type PackageVersions = {
|
|
247
|
+
/**
|
|
248
|
+
* All available versions (sorted newest first).
|
|
249
|
+
*/
|
|
250
|
+
versions: string[];
|
|
251
|
+
/**
|
|
252
|
+
* Distribution tags (e.g., { latest: "7.0.0", next: "8.0.0-beta.1" }).
|
|
253
|
+
*/
|
|
254
|
+
tags: Record<string, string>;
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* =============================================================================
|
|
258
|
+
* Library Functions
|
|
259
|
+
* =============================================================================
|
|
260
|
+
*/
|
|
261
|
+
/**
|
|
262
|
+
* Get bundle size statistics for an npm package.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```js
|
|
266
|
+
* import { getBundleStats } from "@node-cli/bundlecheck";
|
|
267
|
+
*
|
|
268
|
+
* const stats = await getBundleStats({
|
|
269
|
+
* package: "@mantine/core@7.0.0",
|
|
270
|
+
* exports: ["Button", "Input"],
|
|
271
|
+
* });
|
|
272
|
+
*
|
|
273
|
+
* console.log(stats.gzipSizeFormatted); // "12.3 kB"
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
*/
|
|
277
|
+
export declare function getBundleStats(options: GetBundleStatsOptions): Promise<BundleStats>;
|
|
278
|
+
/**
|
|
279
|
+
* Get bundle size trend across multiple versions of a package.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```js
|
|
283
|
+
* import { getBundleTrend } from "@node-cli/bundlecheck";
|
|
284
|
+
*
|
|
285
|
+
* const trend = await getBundleTrend({
|
|
286
|
+
* package: "@mantine/core",
|
|
287
|
+
* versionCount: 5,
|
|
288
|
+
* });
|
|
289
|
+
*
|
|
290
|
+
* console.log(trend.change?.rawDiffFormatted); // "+5.2 kB"
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
*/
|
|
294
|
+
export declare function getBundleTrend(options: GetBundleTrendOptions): Promise<BundleTrend>;
|
|
295
|
+
/**
|
|
296
|
+
* Get available versions for an npm package.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```js
|
|
300
|
+
* import { getPackageVersions } from "@node-cli/bundlecheck";
|
|
301
|
+
*
|
|
302
|
+
* const { versions, tags } = await getPackageVersions({
|
|
303
|
+
* package: "@mantine/core",
|
|
304
|
+
* });
|
|
305
|
+
*
|
|
306
|
+
* console.log(tags.latest); // "7.0.0"
|
|
307
|
+
* ```
|
|
308
|
+
*
|
|
309
|
+
*/
|
|
310
|
+
export declare function getPackageVersions(options: GetPackageVersionsOptions): Promise<PackageVersions>;
|
|
311
|
+
/**
|
|
312
|
+
* Options for getting package exports.
|
|
313
|
+
*/
|
|
314
|
+
export type GetPackageExportsOptions = {
|
|
315
|
+
/**
|
|
316
|
+
* Package name with optional version (e.g., "@mantine/core" or
|
|
317
|
+
* "@mantine/core@7.0.0").
|
|
318
|
+
*/
|
|
319
|
+
package: string;
|
|
320
|
+
/**
|
|
321
|
+
* Custom npm registry URL.
|
|
322
|
+
*/
|
|
323
|
+
registry?: string;
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* A named export from a package.
|
|
327
|
+
*/
|
|
328
|
+
export type PackageExport = {
|
|
329
|
+
/**
|
|
330
|
+
* The export name (e.g., "Button", "useState").
|
|
331
|
+
*/
|
|
332
|
+
name: string;
|
|
333
|
+
/**
|
|
334
|
+
* The type of export.
|
|
335
|
+
*/
|
|
336
|
+
kind: "function" | "class" | "const" | "type" | "interface" | "enum" | "unknown";
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* Result from getPackageExports.
|
|
340
|
+
*/
|
|
341
|
+
export type PackageExports = {
|
|
342
|
+
/**
|
|
343
|
+
* Package name.
|
|
344
|
+
*/
|
|
345
|
+
packageName: string;
|
|
346
|
+
/**
|
|
347
|
+
* Resolved package version.
|
|
348
|
+
*/
|
|
349
|
+
packageVersion: string;
|
|
350
|
+
/**
|
|
351
|
+
* Array of all named exports found in the package (including types).
|
|
352
|
+
*/
|
|
353
|
+
exports: PackageExport[];
|
|
354
|
+
/**
|
|
355
|
+
* Total count of all named exports (including types).
|
|
356
|
+
*/
|
|
357
|
+
count: number;
|
|
358
|
+
/**
|
|
359
|
+
* Array of runtime exports only (excluding types and interfaces). These are
|
|
360
|
+
* the exports that can actually be imported at runtime.
|
|
361
|
+
*/
|
|
362
|
+
runtimeExports: PackageExport[];
|
|
363
|
+
/**
|
|
364
|
+
* Count of runtime exports only (functions, classes, const, enums).
|
|
365
|
+
*/
|
|
366
|
+
runtimeCount: number;
|
|
367
|
+
};
|
|
368
|
+
/**
|
|
369
|
+
* Get the named exports of an npm package by analyzing its type definitions.
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```js
|
|
373
|
+
* import { getPackageExports } from "@node-cli/bundlecheck";
|
|
374
|
+
*
|
|
375
|
+
* const { exports, count } = await getPackageExports({
|
|
376
|
+
* package: "@mantine/core@7.0.0",
|
|
377
|
+
* });
|
|
378
|
+
*
|
|
379
|
+
* console.log(`Found ${count} exports`);
|
|
380
|
+
* console.log(exports.map(e => e.name)); // ["Accordion", "ActionIcon", "Alert", ...]
|
|
381
|
+
* ```
|
|
382
|
+
*
|
|
383
|
+
*/
|
|
384
|
+
export declare function getPackageExports(options: GetPackageExportsOptions): Promise<PackageExports>;
|
|
385
|
+
/**
|
|
386
|
+
* =============================================================================
|
|
387
|
+
* Re-exports for advanced usage
|
|
388
|
+
* =============================================================================
|
|
389
|
+
*/
|
|
390
|
+
/**
|
|
391
|
+
* - Format bytes to human-readable string (e.g., 1024 → "1 kB").
|
|
392
|
+
* - Parse a package specifier (e.g., "@scope/name@1.0.0" → { name, version,
|
|
393
|
+
* subpath }).
|
|
394
|
+
*/
|
|
395
|
+
export { formatBytes, parsePackageSpecifier } from "./bundler.js";
|
|
396
|
+
/**
|
|
397
|
+
* - Clear the bundle cache.
|
|
398
|
+
* - Get the number of cached entries.
|
|
399
|
+
*/
|
|
400
|
+
export { clearCache, getCacheCount } from "./cache.js";
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Programmatic interface for analyzing npm package bundle sizes.
|
|
5
5
|
*
|
|
6
|
-
*/ import { checkBundleSize, formatBytes,
|
|
6
|
+
*/ import { checkBundleSize, formatBytes, parsePackageSpecifier } from "./bundler.js";
|
|
7
7
|
import { getCachedResult, normalizeCacheKey, setCachedResult } from "./cache.js";
|
|
8
8
|
import { normalizePlatform, TREND_VERSION_COUNT } from "./defaults.js";
|
|
9
9
|
import { analyzeTrend, selectTrendVersions } from "./trend.js";
|
|
@@ -42,16 +42,18 @@ import { fetchPackageVersions as fetchVersions } from "./versions.js";
|
|
|
42
42
|
});
|
|
43
43
|
resolvedVersion = tags.latest || requestedVersion;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Build cache key.
|
|
47
|
+
* NOTE: We use additionalExternals here, not computed externals, because the default externals (react, react-dom) are determined at bundle time based on the package's dependencies.
|
|
48
|
+
* The cache key captures the user's intent (additionalExternals + noExternal
|
|
49
|
+
* flag), and the actual externals are stored in the cached result.
|
|
50
|
+
*/ const cacheKey = normalizeCacheKey({
|
|
49
51
|
packageName: baseName,
|
|
50
52
|
version: resolvedVersion,
|
|
51
53
|
exports: exportsList,
|
|
52
54
|
platform,
|
|
53
55
|
gzipLevel,
|
|
54
|
-
externals,
|
|
56
|
+
externals: additionalExternals || [],
|
|
55
57
|
noExternal: noExternal ?? false
|
|
56
58
|
});
|
|
57
59
|
// Check cache (unless force is set).
|
|
@@ -190,6 +192,60 @@ import { fetchPackageVersions as fetchVersions } from "./versions.js";
|
|
|
190
192
|
tags: result.tags
|
|
191
193
|
};
|
|
192
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Get the named exports of an npm package by analyzing its type definitions.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```js
|
|
200
|
+
* import { getPackageExports } from "@node-cli/bundlecheck";
|
|
201
|
+
*
|
|
202
|
+
* const { exports, count } = await getPackageExports({
|
|
203
|
+
* package: "@mantine/core@7.0.0",
|
|
204
|
+
* });
|
|
205
|
+
*
|
|
206
|
+
* console.log(`Found ${count} exports`);
|
|
207
|
+
* console.log(exports.map(e => e.name)); // ["Accordion", "ActionIcon", "Alert", ...]
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
*/ export async function getPackageExports(options) {
|
|
211
|
+
const { package: packageName, registry } = options;
|
|
212
|
+
/**
|
|
213
|
+
* Import the install utilities from bundler (we'll use a minimal bundle
|
|
214
|
+
* check).
|
|
215
|
+
*/ const { name: baseName, version: requestedVersion } = parsePackageSpecifier(packageName);
|
|
216
|
+
// Resolve "latest" to actual version.
|
|
217
|
+
let resolvedVersion = requestedVersion;
|
|
218
|
+
if (requestedVersion === "latest") {
|
|
219
|
+
const { tags } = await fetchVersions({
|
|
220
|
+
packageName: baseName,
|
|
221
|
+
registry
|
|
222
|
+
});
|
|
223
|
+
resolvedVersion = tags.latest || requestedVersion;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Use a minimal bundle check to install the package and get exports We'll
|
|
227
|
+
* leverage the existing infrastructure.
|
|
228
|
+
*/ const { installPackage } = await import("./exports-installer.js");
|
|
229
|
+
const { version, exports, runtimeExports } = await installPackage({
|
|
230
|
+
packageName: baseName,
|
|
231
|
+
version: resolvedVersion,
|
|
232
|
+
registry
|
|
233
|
+
});
|
|
234
|
+
return {
|
|
235
|
+
packageName: baseName,
|
|
236
|
+
packageVersion: version,
|
|
237
|
+
exports: exports.map((e)=>({
|
|
238
|
+
name: e.name,
|
|
239
|
+
kind: e.kind
|
|
240
|
+
})),
|
|
241
|
+
count: exports.length,
|
|
242
|
+
runtimeExports: runtimeExports.map((e)=>({
|
|
243
|
+
name: e.name,
|
|
244
|
+
kind: e.kind
|
|
245
|
+
})),
|
|
246
|
+
runtimeCount: runtimeExports.length
|
|
247
|
+
};
|
|
248
|
+
}
|
|
193
249
|
/**
|
|
194
250
|
* =============================================================================
|
|
195
251
|
* Re-exports for advanced usage
|
|
@@ -222,7 +278,8 @@ import { fetchPackageVersions as fetchVersions } from "./versions.js";
|
|
|
222
278
|
platform: result.platform,
|
|
223
279
|
rawSizeFormatted: formatBytes(result.rawSize),
|
|
224
280
|
gzipSizeFormatted: result.gzipSize !== null ? formatBytes(result.gzipSize) : null,
|
|
225
|
-
fromCache
|
|
281
|
+
fromCache,
|
|
282
|
+
namedExportCount: result.namedExportCount
|
|
226
283
|
};
|
|
227
284
|
}
|
|
228
285
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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;;;;;;;;;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IACD;IAEA,OAAO;QACNqB,UAAUL,OAAOK,QAAQ;QACzBX,MAAMM,OAAON,IAAI;IAClB;AACD;AAEA;;;;CAIC,GAED;;;;CAIC,GACD,SAAShC,WAAW,EAAEE,qBAAqB,QAAQ,eAAe;AAClE;;;CAGC,GACD,SAASuE,UAAU,EAAEC,aAAa,QAAQ,aAAa;AAEvD;;;;CAIC,GAED;;CAEC,GACD,SAASrC,kBACRC,MAAoB,EACpBqC,SAAkB;IAElB,OAAO;QACN5D,aAAauB,OAAOvB,WAAW;QAC/B6D,gBAAgBtC,OAAOsC,cAAc;QACrC5D,SAASsB,OAAOtB,OAAO;QACvBoC,SAASd,OAAOc,OAAO;QACvBC,UAAUf,OAAOe,QAAQ;QACzBhC,WAAWiB,OAAOjB,SAAS;QAC3Ba,WAAWI,OAAOJ,SAAS;QAC3B2C,cAAcvC,OAAOuC,YAAY;QACjCtD,UAAUe,OAAOf,QAAQ;QACzB+B,kBAAkBtD,YAAYsC,OAAOc,OAAO;QAC5CG,mBACCjB,OAAOe,QAAQ,KAAK,OAAOrD,YAAYsC,OAAOe,QAAQ,IAAI;QAC3DsB;IACD;AACD"}
|
|
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\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 type { NamedExport } from \"./exports.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 dependencies that would normally be external.\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\t/**\n\t * Total number of named exports in the package (when analyzing entire\n\t * package).\n\t */\n\tnamedExportCount: number;\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 dependencies that would normally be external.\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/**\n\t * Build cache key.\n\t * NOTE: We use additionalExternals here, not computed externals, because the default externals (react, react-dom) are determined at bundle time based on the package's dependencies.\n\t * The cache key captures the user's intent (additionalExternals + noExternal\n\t * flag), and the actual externals are stored in the cached result.\n\t */\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: additionalExternals || [],\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 * Options for getting package exports.\n */\nexport type GetPackageExportsOptions = {\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 * Custom npm registry URL.\n\t */\n\tregistry?: string;\n};\n\n/**\n * A named export from a package.\n */\nexport type PackageExport = {\n\t/**\n\t * The export name (e.g., \"Button\", \"useState\").\n\t */\n\tname: string;\n\t/**\n\t * The type of export.\n\t */\n\tkind:\n\t\t| \"function\"\n\t\t| \"class\"\n\t\t| \"const\"\n\t\t| \"type\"\n\t\t| \"interface\"\n\t\t| \"enum\"\n\t\t| \"unknown\";\n};\n\n/**\n * Result from getPackageExports.\n */\nexport type PackageExports = {\n\t/**\n\t * Package name.\n\t */\n\tpackageName: string;\n\t/**\n\t * Resolved package version.\n\t */\n\tpackageVersion: string;\n\t/**\n\t * Array of all named exports found in the package (including types).\n\t */\n\texports: PackageExport[];\n\t/**\n\t * Total count of all named exports (including types).\n\t */\n\tcount: number;\n\t/**\n\t * Array of runtime exports only (excluding types and interfaces). These are\n\t * the exports that can actually be imported at runtime.\n\t */\n\truntimeExports: PackageExport[];\n\t/**\n\t * Count of runtime exports only (functions, classes, const, enums).\n\t */\n\truntimeCount: number;\n};\n\n/**\n * Get the named exports of an npm package by analyzing its type definitions.\n *\n * @example\n * ```js\n * import { getPackageExports } from \"@node-cli/bundlecheck\";\n *\n * const { exports, count } = await getPackageExports({\n * package: \"@mantine/core@7.0.0\",\n * });\n *\n * console.log(`Found ${count} exports`);\n * console.log(exports.map(e => e.name)); // [\"Accordion\", \"ActionIcon\", \"Alert\", ...]\n * ```\n *\n */\nexport async function getPackageExports(\n\toptions: GetPackageExportsOptions,\n): Promise<PackageExports> {\n\tconst { package: packageName, registry } = options;\n\n\t/**\n\t * Import the install utilities from bundler (we'll use a minimal bundle\n\t * check).\n\t */\n\tconst { name: baseName, version: requestedVersion } =\n\t\tparsePackageSpecifier(packageName);\n\n\t// Resolve \"latest\" to actual version.\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/**\n\t * Use a minimal bundle check to install the package and get exports We'll\n\t * leverage the existing infrastructure.\n\t */\n\tconst { installPackage } = await import(\"./exports-installer.js\");\n\n\tconst { version, exports, runtimeExports } = await installPackage({\n\t\tpackageName: baseName,\n\t\tversion: resolvedVersion,\n\t\tregistry,\n\t});\n\n\treturn {\n\t\tpackageName: baseName,\n\t\tpackageVersion: version,\n\t\texports: exports.map((e: NamedExport) => ({\n\t\t\tname: e.name,\n\t\t\tkind: e.kind,\n\t\t})),\n\t\tcount: exports.length,\n\t\truntimeExports: runtimeExports.map((e: NamedExport) => ({\n\t\t\tname: e.name,\n\t\t\tkind: e.kind,\n\t\t})),\n\t\truntimeCount: runtimeExports.length,\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\tnamedExportCount: result.namedExportCount,\n\t};\n}\n"],"names":["checkBundleSize","formatBytes","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","cacheKey","externals","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","getPackageExports","installPackage","runtimeExports","packageVersion","e","kind","count","runtimeCount","clearCache","getCacheCount","fromCache","dependencies","namedExportCount"],"mappings":"AAAA;;;;;CAKC,GAED,SAECA,eAAe,EACfC,WAAW,EACXC,qBAAqB,QACf,eAAe;AACtB,SACCC,eAAe,EACfC,iBAAiB,EACjBC,eAAe,QACT,aAAa;AACpB,SAASC,iBAAiB,EAAEC,mBAAmB,QAAQ,gBAAgB;AAEvE,SAASC,YAAY,EAAEC,mBAAmB,QAAQ,aAAa;AAC/D,SAASC,wBAAwBC,aAAa,QAAQ,gBAAgB;AAoQtE;;;;CAIC,GAED;;;;;;;;;;;;;;;CAeC,GACD,OAAO,eAAeC,eACrBC,OAA8B;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OAAOsC,cAAc;QACrC5D,SAASsB,OAAOtB,OAAO;QACvBoC,SAASd,OAAOc,OAAO;QACvBC,UAAUf,OAAOe,QAAQ;QACzBhC,WAAWiB,OAAOjB,SAAS;QAC3Bc,WAAWG,OAAOH,SAAS;QAC3BiD,cAAc9C,OAAO8C,YAAY;QACjC7D,UAAUe,OAAOf,QAAQ;QACzB+B,kBAAkBrD,YAAYqC,OAAOc,OAAO;QAC5CG,mBACCjB,OAAOe,QAAQ,KAAK,OAAOpD,YAAYqC,OAAOe,QAAQ,IAAI;QAC3D8B;QACAE,kBAAkB/C,OAAO+C,gBAAgB;IAC1C;AACD"}
|
package/dist/parse.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* istanbul ignore file */ import { parser } from "@node-cli/parser";
|
|
2
|
-
import {
|
|
2
|
+
import { defaultFlags, isValidPlatform } from "./defaults.js";
|
|
3
3
|
export const config = parser({
|
|
4
4
|
meta: import.meta,
|
|
5
5
|
examples: [
|
|
@@ -66,7 +66,7 @@ export const config = parser({
|
|
|
66
66
|
external: {
|
|
67
67
|
shortFlag: "e",
|
|
68
68
|
default: defaultFlags.external,
|
|
69
|
-
description:
|
|
69
|
+
description: "Comma-separated additional externals (react, react-dom auto-external when in package deps)",
|
|
70
70
|
type: "string"
|
|
71
71
|
},
|
|
72
72
|
noExternal: {
|