@node-cli/bundlecheck 1.5.1 → 1.6.1
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 +106 -82
- package/dist/bundlecheck.js +7 -3
- package/dist/bundlecheck.js.map +1 -1
- package/dist/bundler.d.ts +4 -0
- package/dist/bundler.js +18 -6
- package/dist/bundler.js.map +1 -1
- package/dist/defaults.d.ts +25 -0
- package/dist/defaults.js +56 -1
- package/dist/defaults.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/dist/parse.d.ts +1 -0
- package/dist/parse.js +16 -1
- package/dist/parse.js.map +1 -1
- package/dist/trend.d.ts +4 -0
- package/dist/trend.js +3 -2
- package/dist/trend.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -95,19 +95,20 @@ bundlecheck lodash "debounce,throttle"
|
|
|
95
95
|
|
|
96
96
|
### Options
|
|
97
97
|
|
|
98
|
-
| Flag | Short
|
|
99
|
-
| ------------------- |
|
|
100
|
-
| `--help` | `-h`
|
|
101
|
-
| `--version` | `-v`
|
|
102
|
-
| `--versions` | `-V`
|
|
103
|
-
| `--trend [N]` | `-t [N]`
|
|
104
|
-
| `--boring` | `-b`
|
|
105
|
-
| `--gzipLevel <n>` | `-g <n>`
|
|
106
|
-
| `--external <pkgs>` | `-e <pkgs>`
|
|
107
|
-
| `--noExternal` | `-n`
|
|
108
|
-
| `--registry <url>` | `-r <url>`
|
|
109
|
-
| `--platform <name>` | `-p <name>`
|
|
110
|
-
| `--force` | `-f`
|
|
98
|
+
| Flag | Short | Description |
|
|
99
|
+
| ------------------- | ------------- | ------------------------------------------------------------ |
|
|
100
|
+
| `--help` | `-h` | Display help instructions |
|
|
101
|
+
| `--version` | `-v` | Output the current version |
|
|
102
|
+
| `--versions` | `-V` | Choose from available package versions interactively |
|
|
103
|
+
| `--trend [N]` | `-t [N]` | Show bundle size trend for N versions (default: 5) |
|
|
104
|
+
| `--boring` | `-b` | Do not use color output |
|
|
105
|
+
| `--gzipLevel <n>` | `-g <n>` | Gzip compression level (1-9, default: 5) |
|
|
106
|
+
| `--external <pkgs>` | `-e <pkgs>` | Comma-separated additional packages to mark as external |
|
|
107
|
+
| `--noExternal` | `-n` | Do not mark any packages as external |
|
|
108
|
+
| `--registry <url>` | `-r <url>` | Custom npm registry URL (default: registry.npmjs.org) |
|
|
109
|
+
| `--platform <name>` | `-p <name>` | Target platform: `auto` (default), `browser`, or `node` |
|
|
110
|
+
| `--force` | `-f` | Bypass cache and force re-fetch/re-calculation |
|
|
111
|
+
| `--target <target>` | `-T <target>` | esbuild target (e.g., "es2022", "es2020"). Default: "es2022" |
|
|
111
112
|
|
|
112
113
|
### Examples
|
|
113
114
|
|
|
@@ -151,6 +152,9 @@ bundlecheck express # auto-detects "node" from package.json engines
|
|
|
151
152
|
|
|
152
153
|
# Bypass cache and force re-fetch
|
|
153
154
|
bundlecheck lodash --force
|
|
155
|
+
|
|
156
|
+
# Use a specific esbuild target (default: es2022)
|
|
157
|
+
bundlecheck lodash --target es2020
|
|
154
158
|
```
|
|
155
159
|
|
|
156
160
|
## Programmatic Usage (Library API)
|
|
@@ -166,11 +170,16 @@ npm install @node-cli/bundlecheck
|
|
|
166
170
|
### Basic Usage
|
|
167
171
|
|
|
168
172
|
```js
|
|
169
|
-
import {
|
|
173
|
+
import {
|
|
174
|
+
getBundleStats,
|
|
175
|
+
getBundleTrend,
|
|
176
|
+
getPackageVersions,
|
|
177
|
+
getPackageExports
|
|
178
|
+
} from "@node-cli/bundlecheck";
|
|
170
179
|
|
|
171
180
|
// Get bundle stats for a single package
|
|
172
181
|
const stats = await getBundleStats({
|
|
173
|
-
package: "@mantine/core@7.0.0"
|
|
182
|
+
package: "@mantine/core@7.0.0"
|
|
174
183
|
});
|
|
175
184
|
console.log(stats);
|
|
176
185
|
// {
|
|
@@ -191,14 +200,14 @@ console.log(stats);
|
|
|
191
200
|
// Check specific exports (tree-shaking)
|
|
192
201
|
const buttonStats = await getBundleStats({
|
|
193
202
|
package: "@mantine/core",
|
|
194
|
-
exports: ["Button", "Input"]
|
|
203
|
+
exports: ["Button", "Input"]
|
|
195
204
|
});
|
|
196
205
|
console.log(buttonStats.gzipSizeFormatted); // "12.3 kB"
|
|
197
206
|
|
|
198
207
|
// Get bundle size trend across versions
|
|
199
208
|
const trend = await getBundleTrend({
|
|
200
209
|
package: "@mantine/core",
|
|
201
|
-
versionCount: 5
|
|
210
|
+
versionCount: 5
|
|
202
211
|
});
|
|
203
212
|
console.log(trend);
|
|
204
213
|
// {
|
|
@@ -222,17 +231,17 @@ console.log(trend);
|
|
|
222
231
|
|
|
223
232
|
// Get available versions for a package
|
|
224
233
|
const versions = await getPackageVersions({
|
|
225
|
-
package: "@mantine/core"
|
|
234
|
+
package: "@mantine/core"
|
|
226
235
|
});
|
|
227
236
|
console.log(versions.tags.latest); // "7.0.0"
|
|
228
237
|
console.log(versions.versions.slice(0, 5)); // ["7.0.0", "6.0.21", "6.0.20", ...]
|
|
229
238
|
|
|
230
239
|
// Get named exports from a package
|
|
231
240
|
const exports = await getPackageExports({
|
|
232
|
-
package: "date-fns@3.6.0"
|
|
241
|
+
package: "date-fns@3.6.0"
|
|
233
242
|
});
|
|
234
243
|
console.log(`Found ${exports.count} exports`);
|
|
235
|
-
console.log(exports.exports.slice(0, 5).map(e => e.name)); // ["add", "addBusinessDays", "addDays", ...]
|
|
244
|
+
console.log(exports.exports.slice(0, 5).map((e) => e.name)); // ["add", "addBusinessDays", "addDays", ...]
|
|
236
245
|
```
|
|
237
246
|
|
|
238
247
|
### API Reference
|
|
@@ -243,34 +252,35 @@ Get bundle size statistics for a single package.
|
|
|
243
252
|
|
|
244
253
|
**Options:**
|
|
245
254
|
|
|
246
|
-
| Option | Type
|
|
247
|
-
| ------------ |
|
|
248
|
-
| `package` | `string`
|
|
249
|
-
| `exports` | `string[]`
|
|
250
|
-
| `external` | `string[]`
|
|
251
|
-
| `noExternal` | `boolean`
|
|
252
|
-
| `gzipLevel` | `number`
|
|
253
|
-
| `registry` | `string`
|
|
254
|
-
| `platform` | `"browser" \| "node" \| "auto"` | `"auto"`
|
|
255
|
-
| `force` | `boolean`
|
|
255
|
+
| Option | Type | Default | Description |
|
|
256
|
+
| ------------ | ------------------------------- | ----------- | ---------------------------------------------------------- |
|
|
257
|
+
| `package` | `string` | (required) | Package name with optional version (e.g., `lodash@4.17.0`) |
|
|
258
|
+
| `exports` | `string[]` | `undefined` | Specific exports to measure (tree-shaking) |
|
|
259
|
+
| `external` | `string[]` | `undefined` | Additional packages to mark as external |
|
|
260
|
+
| `noExternal` | `boolean` | `false` | Bundle everything (no externals, even react/react-dom) |
|
|
261
|
+
| `gzipLevel` | `number` | `5` | Gzip compression level (1-9) |
|
|
262
|
+
| `registry` | `string` | `undefined` | Custom npm registry URL |
|
|
263
|
+
| `platform` | `"browser" \| "node" \| "auto"` | `"auto"` | Target platform |
|
|
264
|
+
| `force` | `boolean` | `false` | Bypass cache |
|
|
265
|
+
| `target` | `string` | `"es2022"` | esbuild target (e.g., "es2022", "es2020") |
|
|
256
266
|
|
|
257
267
|
**Returns:** `Promise<BundleStats>`
|
|
258
268
|
|
|
259
269
|
```ts
|
|
260
270
|
type BundleStats = {
|
|
261
|
-
packageName: string;
|
|
262
|
-
packageVersion: string;
|
|
263
|
-
exports: string[];
|
|
264
|
-
rawSize: number;
|
|
265
|
-
gzipSize: number | null;
|
|
266
|
-
gzipLevel: number;
|
|
267
|
-
externals: string[];
|
|
268
|
-
dependencies: string[];
|
|
271
|
+
packageName: string; // Display name (may include subpath)
|
|
272
|
+
packageVersion: string; // Resolved version
|
|
273
|
+
exports: string[]; // Exports analyzed
|
|
274
|
+
rawSize: number; // Raw size in bytes
|
|
275
|
+
gzipSize: number | null; // Gzip size in bytes (null for node platform)
|
|
276
|
+
gzipLevel: number; // Compression level used
|
|
277
|
+
externals: string[]; // External packages
|
|
278
|
+
dependencies: string[]; // Package dependencies
|
|
269
279
|
platform: "browser" | "node";
|
|
270
|
-
rawSizeFormatted: string;
|
|
280
|
+
rawSizeFormatted: string; // Human-readable (e.g., "45.2 kB")
|
|
271
281
|
gzipSizeFormatted: string | null;
|
|
272
|
-
fromCache: boolean;
|
|
273
|
-
namedExportCount: number;
|
|
282
|
+
fromCache: boolean; // Whether result was from cache
|
|
283
|
+
namedExportCount: number; // Total named exports in package
|
|
274
284
|
};
|
|
275
285
|
```
|
|
276
286
|
|
|
@@ -280,25 +290,26 @@ Get bundle size trend across multiple versions.
|
|
|
280
290
|
|
|
281
291
|
**Options:**
|
|
282
292
|
|
|
283
|
-
| Option | Type
|
|
284
|
-
| -------------- |
|
|
285
|
-
| `package` | `string`
|
|
286
|
-
| `versionCount` | `number`
|
|
287
|
-
| `exports` | `string[]`
|
|
288
|
-
| `external` | `string[]`
|
|
289
|
-
| `noExternal` | `boolean`
|
|
290
|
-
| `gzipLevel` | `number`
|
|
291
|
-
| `registry` | `string`
|
|
292
|
-
| `platform` | `"browser" \| "node" \| "auto"` | `"auto"`
|
|
293
|
-
| `force` | `boolean`
|
|
293
|
+
| Option | Type | Default | Description |
|
|
294
|
+
| -------------- | ------------------------------- | ----------- | --------------------------------------------- |
|
|
295
|
+
| `package` | `string` | (required) | Package name (version ignored if provided) |
|
|
296
|
+
| `versionCount` | `number` | `5` | Number of versions to analyze |
|
|
297
|
+
| `exports` | `string[]` | `undefined` | Specific exports to measure |
|
|
298
|
+
| `external` | `string[]` | `undefined` | Additional packages to mark as external |
|
|
299
|
+
| `noExternal` | `boolean` | `false` | Bundle everything including default externals |
|
|
300
|
+
| `gzipLevel` | `number` | `5` | Gzip compression level (1-9) |
|
|
301
|
+
| `registry` | `string` | `undefined` | Custom npm registry URL |
|
|
302
|
+
| `platform` | `"browser" \| "node" \| "auto"` | `"auto"` | Target platform |
|
|
303
|
+
| `force` | `boolean` | `false` | Bypass cache |
|
|
304
|
+
| `target` | `string` | `"es2022"` | esbuild target (e.g., "es2022", "es2020") |
|
|
294
305
|
|
|
295
306
|
**Returns:** `Promise<BundleTrend>`
|
|
296
307
|
|
|
297
308
|
```ts
|
|
298
309
|
type BundleTrend = {
|
|
299
310
|
packageName: string;
|
|
300
|
-
versions: TrendVersionResult[];
|
|
301
|
-
change: TrendChange | null;
|
|
311
|
+
versions: TrendVersionResult[]; // Results for each version (newest first)
|
|
312
|
+
change: TrendChange | null; // Change between oldest and newest
|
|
302
313
|
};
|
|
303
314
|
|
|
304
315
|
type TrendVersionResult = {
|
|
@@ -312,11 +323,11 @@ type TrendVersionResult = {
|
|
|
312
323
|
type TrendChange = {
|
|
313
324
|
fromVersion: string;
|
|
314
325
|
toVersion: string;
|
|
315
|
-
rawDiff: number;
|
|
316
|
-
rawPercent: number | null;
|
|
317
|
-
rawDiffFormatted: string;
|
|
326
|
+
rawDiff: number; // Positive = increase, negative = decrease
|
|
327
|
+
rawPercent: number | null; // null if oldest size was 0
|
|
328
|
+
rawDiffFormatted: string; // e.g., "+5.2 kB" or "-1.3 kB"
|
|
318
329
|
gzipDiff: number | null;
|
|
319
|
-
gzipPercent: number | null;
|
|
330
|
+
gzipPercent: number | null; // null if not applicable or oldest size was 0
|
|
320
331
|
gzipDiffFormatted: string | null;
|
|
321
332
|
};
|
|
322
333
|
```
|
|
@@ -327,17 +338,17 @@ Get available versions for an npm package.
|
|
|
327
338
|
|
|
328
339
|
**Options:**
|
|
329
340
|
|
|
330
|
-
| Option | Type | Default
|
|
331
|
-
| ---------- | -------- |
|
|
332
|
-
| `package` | `string` | (required)
|
|
333
|
-
| `registry` | `string` | `undefined
|
|
341
|
+
| Option | Type | Default | Description |
|
|
342
|
+
| ---------- | -------- | ----------- | ----------------------- |
|
|
343
|
+
| `package` | `string` | (required) | Package name |
|
|
344
|
+
| `registry` | `string` | `undefined` | Custom npm registry URL |
|
|
334
345
|
|
|
335
346
|
**Returns:** `Promise<PackageVersions>`
|
|
336
347
|
|
|
337
348
|
```ts
|
|
338
349
|
type PackageVersions = {
|
|
339
|
-
versions: string[];
|
|
340
|
-
tags: Record<string, string>;
|
|
350
|
+
versions: string[]; // All versions (newest first)
|
|
351
|
+
tags: Record<string, string>; // Dist tags (e.g., { latest: "7.0.0" })
|
|
341
352
|
};
|
|
342
353
|
```
|
|
343
354
|
|
|
@@ -347,26 +358,33 @@ Get the named exports of an npm package by analyzing its TypeScript declarations
|
|
|
347
358
|
|
|
348
359
|
**Options:**
|
|
349
360
|
|
|
350
|
-
| Option | Type | Default
|
|
351
|
-
| ---------- | -------- |
|
|
352
|
-
| `package` | `string` | (required)
|
|
353
|
-
| `registry` | `string` | `undefined
|
|
361
|
+
| Option | Type | Default | Description |
|
|
362
|
+
| ---------- | -------- | ----------- | ---------------------------------- |
|
|
363
|
+
| `package` | `string` | (required) | Package name with optional version |
|
|
364
|
+
| `registry` | `string` | `undefined` | Custom npm registry URL |
|
|
354
365
|
|
|
355
366
|
**Returns:** `Promise<PackageExports>`
|
|
356
367
|
|
|
357
368
|
```ts
|
|
358
369
|
type PackageExports = {
|
|
359
|
-
packageName: string;
|
|
360
|
-
packageVersion: string;
|
|
361
|
-
exports: PackageExport[];
|
|
362
|
-
count: number;
|
|
370
|
+
packageName: string; // Package name
|
|
371
|
+
packageVersion: string; // Resolved version
|
|
372
|
+
exports: PackageExport[]; // All named exports (including types)
|
|
373
|
+
count: number; // Total count (including types)
|
|
363
374
|
runtimeExports: PackageExport[]; // Runtime exports only (no types/interfaces)
|
|
364
|
-
runtimeCount: number;
|
|
375
|
+
runtimeCount: number; // Count of runtime exports
|
|
365
376
|
};
|
|
366
377
|
|
|
367
378
|
type PackageExport = {
|
|
368
|
-
name: string;
|
|
369
|
-
kind:
|
|
379
|
+
name: string; // Export name (e.g., "Button")
|
|
380
|
+
kind:
|
|
381
|
+
| "function"
|
|
382
|
+
| "class"
|
|
383
|
+
| "const"
|
|
384
|
+
| "type"
|
|
385
|
+
| "interface"
|
|
386
|
+
| "enum"
|
|
387
|
+
| "unknown";
|
|
370
388
|
};
|
|
371
389
|
```
|
|
372
390
|
|
|
@@ -374,10 +392,10 @@ type PackageExport = {
|
|
|
374
392
|
|
|
375
393
|
```js
|
|
376
394
|
const result = await getPackageExports({
|
|
377
|
-
package: "@mantine/core"
|
|
395
|
+
package: "@mantine/core"
|
|
378
396
|
});
|
|
379
397
|
|
|
380
|
-
console.log(result.count);
|
|
398
|
+
console.log(result.count); // 1056 (all exports including types)
|
|
381
399
|
console.log(result.runtimeCount); // 365 (only importable exports)
|
|
382
400
|
console.log(result.runtimeExports[0]); // { name: "Accordion", kind: "unknown" }
|
|
383
401
|
```
|
|
@@ -385,11 +403,16 @@ console.log(result.runtimeExports[0]); // { name: "Accordion", kind: "unknown" }
|
|
|
385
403
|
### Utility Functions
|
|
386
404
|
|
|
387
405
|
```js
|
|
388
|
-
import {
|
|
406
|
+
import {
|
|
407
|
+
formatBytes,
|
|
408
|
+
parsePackageSpecifier,
|
|
409
|
+
clearCache,
|
|
410
|
+
getCacheCount
|
|
411
|
+
} from "@node-cli/bundlecheck";
|
|
389
412
|
|
|
390
413
|
// Format bytes to human-readable string
|
|
391
|
-
formatBytes(1024);
|
|
392
|
-
formatBytes(1536);
|
|
414
|
+
formatBytes(1024); // "1 kB"
|
|
415
|
+
formatBytes(1536); // "1.5 kB"
|
|
393
416
|
|
|
394
417
|
// Parse a package specifier
|
|
395
418
|
parsePackageSpecifier("@scope/name@1.0.0");
|
|
@@ -399,8 +422,8 @@ parsePackageSpecifier("@scope/name/subpath@2.0.0");
|
|
|
399
422
|
// { name: "@scope/name", version: "2.0.0", subpath: "subpath" }
|
|
400
423
|
|
|
401
424
|
// Cache management
|
|
402
|
-
getCacheCount();
|
|
403
|
-
clearCache();
|
|
425
|
+
getCacheCount(); // Returns number of cached entries
|
|
426
|
+
clearCache(); // Clears all cached results
|
|
404
427
|
```
|
|
405
428
|
|
|
406
429
|
## How It Works
|
|
@@ -423,6 +446,7 @@ The `--platform` flag controls how the bundle is built:
|
|
|
423
446
|
- **`node`**: Builds for Node.js environments (also accepts aliases: `server`, `nodejs`, `backend`)
|
|
424
447
|
|
|
425
448
|
When targeting **node** platform:
|
|
449
|
+
|
|
426
450
|
- Gzip size is not calculated (shows "N/A") since server-side code isn't typically served compressed over HTTP
|
|
427
451
|
- The bundle is optimized for Node.js built-ins
|
|
428
452
|
|
package/dist/bundlecheck.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import kleur from "kleur";
|
|
4
4
|
import { checkBundleSize, formatBytes, getExternals, parsePackageSpecifier } from "./bundler.js";
|
|
5
5
|
import { getCachedResult, normalizeCacheKey, setCachedResult } from "./cache.js";
|
|
6
|
-
import { normalizePlatform, TREND_VERSION_COUNT } from "./defaults.js";
|
|
6
|
+
import { normalizePlatform, normalizeTarget, TREND_VERSION_COUNT } from "./defaults.js";
|
|
7
7
|
import { config } from "./parse.js";
|
|
8
8
|
import { analyzeTrend, renderTrendGraph, selectTrendVersions } from "./trend.js";
|
|
9
9
|
import { fetchPackageVersions, promptForVersion } from "./versions.js";
|
|
@@ -65,6 +65,8 @@ async function main() {
|
|
|
65
65
|
}
|
|
66
66
|
// Normalize platform from flag (handles aliases like "web" → "browser").
|
|
67
67
|
const platform = normalizePlatform(flags?.platform);
|
|
68
|
+
// Normalize target (e.g., lowercase).
|
|
69
|
+
const target = normalizeTarget(flags?.target);
|
|
68
70
|
/**
|
|
69
71
|
* If --trend flag is set, show bundle size trend across versions --trend alone
|
|
70
72
|
* uses default (5), --trend N uses N versions.
|
|
@@ -99,7 +101,8 @@ async function main() {
|
|
|
99
101
|
boring: flags?.boring,
|
|
100
102
|
registry: flags?.registry,
|
|
101
103
|
platform,
|
|
102
|
-
force: flags?.force
|
|
104
|
+
force: flags?.force,
|
|
105
|
+
target
|
|
103
106
|
});
|
|
104
107
|
if (results.length === 0) {
|
|
105
108
|
log.error("Failed to analyze any versions");
|
|
@@ -187,7 +190,8 @@ async function main() {
|
|
|
187
190
|
noExternal: flags?.noExternal,
|
|
188
191
|
gzipLevel: flags?.gzipLevel,
|
|
189
192
|
registry: flags?.registry,
|
|
190
|
-
platform
|
|
193
|
+
platform,
|
|
194
|
+
target
|
|
191
195
|
});
|
|
192
196
|
// Store result in cache.
|
|
193
197
|
setCachedResult(cacheKey, result);
|
package/dist/bundlecheck.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundlecheck.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/* istanbul ignore file */\n\nimport { Logger } from \"@node-cli/logger\";\nimport kleur from \"kleur\";\nimport {\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 { config } from \"./parse.js\";\nimport {\n\tanalyzeTrend,\n\trenderTrendGraph,\n\tselectTrendVersions,\n} from \"./trend.js\";\nimport { fetchPackageVersions, promptForVersion } from \"./versions.js\";\n\nconst flags = config.flags;\nconst parameters = config.parameters;\n\n// Disable kleur colors when --boring flag is set.\nkleur.enabled = !flags?.boring;\n\nconst log = new Logger({\n\tboring: flags?.boring,\n});\n\n/**\n * Display bundle result in a formatted box.\n */\nfunction displayResult(\n\tresult: {\n\t\tpackageName: string;\n\t\tpackageVersion: string;\n\t\texports: string[];\n\t\trawSize: number;\n\t\tgzipSize: number | null;\n\t\tgzipLevel: number;\n\t\texternals: string[];\n\t\tdependencies: string[];\n\t\tplatform: \"browser\" | \"node\";\n\t\tnamedExportCount: number;\n\t},\n\tisAutoDetected: boolean,\n): void {\n\tconst blue = kleur.blue;\n\tconst green = kleur.green;\n\n\tconst platformLabel = result.platform === \"node\" ? \"node\" : \"browser\";\n\tconst platformNote = isAutoDetected ? \" (auto-detected)\" : \"\";\n\n\t// Format exports display.\n\tlet exportsDisplay: string;\n\tif (result.exports.length > 0) {\n\t\texportsDisplay = `{ ${result.exports.join(\", \")} }`;\n\t} else if (result.namedExportCount > 0) {\n\t\texportsDisplay = `${result.namedExportCount} named exports (entire package)`;\n\t} else {\n\t\texportsDisplay = \"* (entire package)\";\n\t}\n\n\tlog.printBox(\n\t\t[\n\t\t\t`${blue(\"Package:\")} ${result.packageName} (${blue(\"version:\")} ${result.packageVersion})`,\n\t\t\t`${blue(\"Exports:\")} ${exportsDisplay}`,\n\t\t\t\"\",\n\t\t\t`${blue(\"Raw size:\")} ${formatBytes(result.rawSize)}`,\n\t\t\tresult.gzipSize !== null\n\t\t\t\t? `${blue(\"Gzip size:\")} ${formatBytes(result.gzipSize)} (level ${result.gzipLevel})`\n\t\t\t\t: `${blue(\"Gzip size:\")} N/A (not applicable for node platform)`,\n\t\t\t\"\",\n\t\t\tresult.externals.length > 0\n\t\t\t\t? `${blue(\"Externals:\")} ${result.externals.join(\", \")}`\n\t\t\t\t: `${blue(\"Externals:\")} ${green(\"none\")}`,\n\t\t\tresult.dependencies.length > 0\n\t\t\t\t? `${blue(\"Dependencies:\")} ${result.dependencies.join(\", \")}`\n\t\t\t\t: `${blue(\"Dependencies:\")} ${green(\"none\")}`,\n\t\t\t`${blue(\"Platform:\")} ${platformLabel}${platformNote}`,\n\t\t],\n\t\t{\n\t\t\tborderStyle: \"round\",\n\t\t\talign: \"left\",\n\t\t},\n\t);\n}\n\nasync function main() {\n\tlet packageName = parameters?.[\"0\"];\n\n\tif (!packageName) {\n\t\tlog.error(\"Package name is required\");\n\t\tconfig.showHelp?.();\n\t\tprocess.exit(1);\n\t}\n\n\t// Parse additional externals if provided (comma-separated).\n\tlet additionalExternals: string[] | undefined;\n\tif (flags?.external) {\n\t\tadditionalExternals = flags.external\n\t\t\t.split(\",\")\n\t\t\t.map((e) => e.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\t// Parse exports if provided (comma-separated).\n\tlet exports: string[] | undefined;\n\tconst exportsArg = parameters?.[\"1\"];\n\tif (exportsArg) {\n\t\texports = exportsArg\n\t\t\t.split(\",\")\n\t\t\t.map((e) => e.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\t// Normalize platform from flag (handles aliases like \"web\" → \"browser\").\n\tconst platform = normalizePlatform(flags?.platform);\n\n\t/**\n\t * If --trend flag is set, show bundle size trend across versions --trend alone\n\t * uses default (5), --trend N uses N versions.\n\t */\n\tconst trendValue = flags?.trend;\n\tif (trendValue !== undefined) {\n\t\tconst parsedCount = Number.parseInt(trendValue, 10);\n\t\tconst versionCount =\n\t\t\t!Number.isNaN(parsedCount) && parsedCount > 0\n\t\t\t\t? parsedCount\n\t\t\t\t: TREND_VERSION_COUNT;\n\n\t\ttry {\n\t\t\tconst { name, subpath } = parsePackageSpecifier(packageName);\n\t\t\t// Construct the full package path including subpath if present.\n\t\t\tconst fullPackagePath = subpath ? `${name}/${subpath}` : name;\n\n\t\t\tlog.info(`\\nFetching available versions for ${name}...`);\n\n\t\t\tconst { versions } = await fetchPackageVersions({\n\t\t\t\tpackageName,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\n\t\t\tif (versions.length === 0) {\n\t\t\t\tlog.error(\"No versions found for this package\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\t// Select versions for trend.\n\t\t\tconst trendVersions = selectTrendVersions(versions, versionCount);\n\n\t\t\tlog.info(\n\t\t\t\t`Analyzing ${trendVersions.length} versions: ${trendVersions.join(\", \")}`,\n\t\t\t);\n\t\t\tlog.info(\"\");\n\n\t\t\tconst results = await analyzeTrend({\n\t\t\t\tpackageName: fullPackagePath,\n\t\t\t\tversions: trendVersions,\n\t\t\t\texports,\n\t\t\t\tadditionalExternals,\n\t\t\t\tnoExternal: flags?.noExternal,\n\t\t\t\tgzipLevel: flags?.gzipLevel,\n\t\t\t\tboring: flags?.boring,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t\tplatform,\n\t\t\t\tforce: flags?.force,\n\t\t\t});\n\n\t\t\tif (results.length === 0) {\n\t\t\t\tlog.error(\"Failed to analyze any versions\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\t// Render and display the trend graph.\n\t\t\tconst graphLines = renderTrendGraph(\n\t\t\t\tfullPackagePath,\n\t\t\t\tresults,\n\t\t\t\tflags?.boring,\n\t\t\t);\n\t\t\tfor (const line of graphLines) {\n\t\t\t\tlog.log(line);\n\t\t\t}\n\n\t\t\tprocess.exit(0);\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlog.error(`Failed to analyze trend: ${errorMessage}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\t// If --versions flag is set, fetch and prompt for version selection.\n\tif (flags?.versions) {\n\t\ttry {\n\t\t\tconst { name, subpath } = parsePackageSpecifier(packageName);\n\t\t\tlog.info(`\\nFetching available versions for ${name}...`);\n\n\t\t\tconst { versions, tags } = await fetchPackageVersions({\n\t\t\t\tpackageName,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\n\t\t\tif (versions.length === 0) {\n\t\t\t\tlog.error(\"No versions found for this package\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tconst selectedVersion = await promptForVersion(name, versions, tags);\n\t\t\t// Rebuild specifier preserving any subpath.\n\t\t\tpackageName = subpath\n\t\t\t\t? `${name}/${subpath}@${selectedVersion}`\n\t\t\t\t: `${name}@${selectedVersion}`;\n\t\t\tlog.info(`\\nSelected: ${packageName}`);\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlog.error(`Failed to fetch versions: ${errorMessage}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tlog.info(`\\nAnalyzing bundle size for: ${packageName}`);\n\tif (exports && exports.length > 0) {\n\t\tlog.info(`Exports: { ${exports.join(\", \")} }`);\n\t}\n\n\ttry {\n\t\t// Parse package specifier to get name and version.\n\t\tconst { name: baseName, version: requestedVersion } =\n\t\t\tparsePackageSpecifier(packageName);\n\n\t\t// Resolve \"latest\" to actual version for cache key.\n\t\tlet resolvedVersion = requestedVersion;\n\t\tif (requestedVersion === \"latest\") {\n\t\t\tconst { tags } = await fetchPackageVersions({\n\t\t\t\tpackageName: baseName,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\t\t\tresolvedVersion = tags.latest || requestedVersion;\n\t\t}\n\n\t\t// Compute externals for cache key (same logic as bundler).\n\t\tconst externals = getExternals(\n\t\t\tbaseName,\n\t\t\tadditionalExternals,\n\t\t\tflags?.noExternal,\n\t\t);\n\n\t\t/**\n\t\t * Build cache key.\n\t\t * NOTE: platform can be undefined (auto-detect), which is stored as \"auto\" in cache.\n\t\t */\n\t\tconst cacheKey = normalizeCacheKey({\n\t\t\tpackageName: baseName,\n\t\t\tversion: resolvedVersion,\n\t\t\texports,\n\t\t\tplatform,\n\t\t\tgzipLevel: flags?.gzipLevel ?? 5,\n\t\t\texternals,\n\t\t\tnoExternal: flags?.noExternal ?? false,\n\t\t});\n\n\t\t// Check cache (unless --force flag is set).\n\t\tif (!flags?.force) {\n\t\t\tconst cached = getCachedResult(cacheKey);\n\t\t\tif (cached) {\n\t\t\t\tlog.info(\"NOTE: Using cached results\\n\");\n\t\t\t\tdisplayResult(cached, platform === undefined);\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t}\n\n\t\tlog.info(\"Please wait, installing and bundling...\\n\");\n\n\t\tconst result = await checkBundleSize({\n\t\t\tpackageName,\n\t\t\texports,\n\t\t\tadditionalExternals,\n\t\t\tnoExternal: flags?.noExternal,\n\t\t\tgzipLevel: flags?.gzipLevel,\n\t\t\tregistry: flags?.registry,\n\t\t\tplatform,\n\t\t});\n\n\t\t// Store result in cache.\n\t\tsetCachedResult(cacheKey, result);\n\n\t\tdisplayResult(result, platform === undefined);\n\n\t\tprocess.exit(0);\n\t} catch (error) {\n\t\tconst errorMessage = error instanceof Error ? error.message : String(error);\n\t\tlog.error(`Failed to analyze bundle size: ${errorMessage}`);\n\t\tprocess.exit(1);\n\t}\n}\n\nmain();\n"],"names":["Logger","kleur","checkBundleSize","formatBytes","getExternals","parsePackageSpecifier","getCachedResult","normalizeCacheKey","setCachedResult","normalizePlatform","TREND_VERSION_COUNT","config","analyzeTrend","renderTrendGraph","selectTrendVersions","fetchPackageVersions","promptForVersion","flags","parameters","enabled","boring","log","displayResult","result","isAutoDetected","blue","green","platformLabel","platform","platformNote","exportsDisplay","exports","length","join","namedExportCount","printBox","packageName","packageVersion","rawSize","gzipSize","gzipLevel","externals","dependencies","borderStyle","align","main","error","showHelp","process","exit","additionalExternals","external","split","map","e","trim","filter","Boolean","exportsArg","trendValue","trend","undefined","parsedCount","Number","parseInt","versionCount","isNaN","name","subpath","fullPackagePath","info","versions","registry","trendVersions","results","noExternal","force","graphLines","line","errorMessage","Error","message","String","tags","selectedVersion","baseName","version","requestedVersion","resolvedVersion","latest","cacheKey","cached"],"mappings":";AAEA,wBAAwB,GAExB,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,WAAW,QAAQ;AAC1B,SACCC,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,MAAM,QAAQ,aAAa;AACpC,SACCC,YAAY,EACZC,gBAAgB,EAChBC,mBAAmB,QACb,aAAa;AACpB,SAASC,oBAAoB,EAAEC,gBAAgB,QAAQ,gBAAgB;AAEvE,MAAMC,QAAQN,OAAOM,KAAK;AAC1B,MAAMC,aAAaP,OAAOO,UAAU;AAEpC,kDAAkD;AAClDjB,MAAMkB,OAAO,GAAG,CAACF,OAAOG;AAExB,MAAMC,MAAM,IAAIrB,OAAO;IACtBoB,QAAQH,OAAOG;AAChB;AAEA;;CAEC,GACD,SAASE,cACRC,MAWC,EACDC,cAAuB;IAEvB,MAAM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AClC6B,aAAaiD;YACbC,SAASE;YACTzD;YACAH;YACAY,WAAWvB,OAAOuB,aAAa;YAC/BC;YACAkC,YAAY1D,OAAO0D,cAAc;QAClC;QAEA,4CAA4C;QAC5C,IAAI,CAAC1D,OAAO2D,OAAO;YAClB,MAAMe,SAASrF,gBAAgBoF;YAC/B,IAAIC,QAAQ;gBACXtE,IAAIiD,IAAI,CAAC;gBACThD,cAAcqE,QAAQ/D,aAAaiC;gBACnCb,QAAQC,IAAI,CAAC;YACd;QACD;QAEA5B,IAAIiD,IAAI,CAAC;QAET,MAAM/C,SAAS,MAAMrB,gBAAgB;YACpCkC;YACAL;YACAmB;YACAyB,YAAY1D,OAAO0D;YACnBnC,WAAWvB,OAAOuB;YAClBgC,UAAUvD,OAAOuD;YACjB5C;QACD;QAEA,yBAAyB;QACzBpB,gBAAgBkF,UAAUnE;QAE1BD,cAAcC,QAAQK,aAAaiC;QAEnCb,QAAQC,IAAI,CAAC;IACd,EAAE,OAAOH,OAAO;QACf,MAAMiC,eAAejC,iBAAiBkC,QAAQlC,MAAMmC,OAAO,GAAGC,OAAOpC;QACrEzB,IAAIyB,KAAK,CAAC,CAAC,+BAA+B,EAAEiC,cAAc;QAC1D/B,QAAQC,IAAI,CAAC;IACd;AACD;AAEAJ"}
|
|
1
|
+
{"version":3,"sources":["../src/bundlecheck.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/* istanbul ignore file */\n\nimport { Logger } from \"@node-cli/logger\";\nimport kleur from \"kleur\";\nimport {\n\tcheckBundleSize,\n\tformatBytes,\n\tgetExternals,\n\tparsePackageSpecifier,\n} from \"./bundler.js\";\nimport {\n\tgetCachedResult,\n\tnormalizeCacheKey,\n\tsetCachedResult,\n} from \"./cache.js\";\nimport {\n\tnormalizePlatform,\n\tnormalizeTarget,\n\tTREND_VERSION_COUNT,\n} from \"./defaults.js\";\nimport { config } from \"./parse.js\";\nimport {\n\tanalyzeTrend,\n\trenderTrendGraph,\n\tselectTrendVersions,\n} from \"./trend.js\";\nimport { fetchPackageVersions, promptForVersion } from \"./versions.js\";\n\nconst flags = config.flags;\nconst parameters = config.parameters;\n\n// Disable kleur colors when --boring flag is set.\nkleur.enabled = !flags?.boring;\n\nconst log = new Logger({\n\tboring: flags?.boring,\n});\n\n/**\n * Display bundle result in a formatted box.\n */\nfunction displayResult(\n\tresult: {\n\t\tpackageName: string;\n\t\tpackageVersion: string;\n\t\texports: string[];\n\t\trawSize: number;\n\t\tgzipSize: number | null;\n\t\tgzipLevel: number;\n\t\texternals: string[];\n\t\tdependencies: string[];\n\t\tplatform: \"browser\" | \"node\";\n\t\tnamedExportCount: number;\n\t},\n\tisAutoDetected: boolean,\n): void {\n\tconst blue = kleur.blue;\n\tconst green = kleur.green;\n\n\tconst platformLabel = result.platform === \"node\" ? \"node\" : \"browser\";\n\tconst platformNote = isAutoDetected ? \" (auto-detected)\" : \"\";\n\n\t// Format exports display.\n\tlet exportsDisplay: string;\n\tif (result.exports.length > 0) {\n\t\texportsDisplay = `{ ${result.exports.join(\", \")} }`;\n\t} else if (result.namedExportCount > 0) {\n\t\texportsDisplay = `${result.namedExportCount} named exports (entire package)`;\n\t} else {\n\t\texportsDisplay = \"* (entire package)\";\n\t}\n\n\tlog.printBox(\n\t\t[\n\t\t\t`${blue(\"Package:\")} ${result.packageName} (${blue(\"version:\")} ${result.packageVersion})`,\n\t\t\t`${blue(\"Exports:\")} ${exportsDisplay}`,\n\t\t\t\"\",\n\t\t\t`${blue(\"Raw size:\")} ${formatBytes(result.rawSize)}`,\n\t\t\tresult.gzipSize !== null\n\t\t\t\t? `${blue(\"Gzip size:\")} ${formatBytes(result.gzipSize)} (level ${result.gzipLevel})`\n\t\t\t\t: `${blue(\"Gzip size:\")} N/A (not applicable for node platform)`,\n\t\t\t\"\",\n\t\t\tresult.externals.length > 0\n\t\t\t\t? `${blue(\"Externals:\")} ${result.externals.join(\", \")}`\n\t\t\t\t: `${blue(\"Externals:\")} ${green(\"none\")}`,\n\t\t\tresult.dependencies.length > 0\n\t\t\t\t? `${blue(\"Dependencies:\")} ${result.dependencies.join(\", \")}`\n\t\t\t\t: `${blue(\"Dependencies:\")} ${green(\"none\")}`,\n\t\t\t`${blue(\"Platform:\")} ${platformLabel}${platformNote}`,\n\t\t],\n\t\t{\n\t\t\tborderStyle: \"round\",\n\t\t\talign: \"left\",\n\t\t},\n\t);\n}\n\nasync function main() {\n\tlet packageName = parameters?.[\"0\"];\n\n\tif (!packageName) {\n\t\tlog.error(\"Package name is required\");\n\t\tconfig.showHelp?.();\n\t\tprocess.exit(1);\n\t}\n\n\t// Parse additional externals if provided (comma-separated).\n\tlet additionalExternals: string[] | undefined;\n\tif (flags?.external) {\n\t\tadditionalExternals = flags.external\n\t\t\t.split(\",\")\n\t\t\t.map((e) => e.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\t// Parse exports if provided (comma-separated).\n\tlet exports: string[] | undefined;\n\tconst exportsArg = parameters?.[\"1\"];\n\tif (exportsArg) {\n\t\texports = exportsArg\n\t\t\t.split(\",\")\n\t\t\t.map((e) => e.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\t// Normalize platform from flag (handles aliases like \"web\" → \"browser\").\n\tconst platform = normalizePlatform(flags?.platform);\n\n\t// Normalize target (e.g., lowercase).\n\tconst target = normalizeTarget(flags?.target);\n\n\t/**\n\t * If --trend flag is set, show bundle size trend across versions --trend alone\n\t * uses default (5), --trend N uses N versions.\n\t */\n\tconst trendValue = flags?.trend;\n\tif (trendValue !== undefined) {\n\t\tconst parsedCount = Number.parseInt(trendValue, 10);\n\t\tconst versionCount =\n\t\t\t!Number.isNaN(parsedCount) && parsedCount > 0\n\t\t\t\t? parsedCount\n\t\t\t\t: TREND_VERSION_COUNT;\n\n\t\ttry {\n\t\t\tconst { name, subpath } = parsePackageSpecifier(packageName);\n\t\t\t// Construct the full package path including subpath if present.\n\t\t\tconst fullPackagePath = subpath ? `${name}/${subpath}` : name;\n\n\t\t\tlog.info(`\\nFetching available versions for ${name}...`);\n\n\t\t\tconst { versions } = await fetchPackageVersions({\n\t\t\t\tpackageName,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\n\t\t\tif (versions.length === 0) {\n\t\t\t\tlog.error(\"No versions found for this package\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\t// Select versions for trend.\n\t\t\tconst trendVersions = selectTrendVersions(versions, versionCount);\n\n\t\t\tlog.info(\n\t\t\t\t`Analyzing ${trendVersions.length} versions: ${trendVersions.join(\", \")}`,\n\t\t\t);\n\t\t\tlog.info(\"\");\n\n\t\t\tconst results = await analyzeTrend({\n\t\t\t\tpackageName: fullPackagePath,\n\t\t\t\tversions: trendVersions,\n\t\t\t\texports,\n\t\t\t\tadditionalExternals,\n\t\t\t\tnoExternal: flags?.noExternal,\n\t\t\t\tgzipLevel: flags?.gzipLevel,\n\t\t\t\tboring: flags?.boring,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t\tplatform,\n\t\t\t\tforce: flags?.force,\n\t\t\t\ttarget,\n\t\t\t});\n\n\t\t\tif (results.length === 0) {\n\t\t\t\tlog.error(\"Failed to analyze any versions\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\t// Render and display the trend graph.\n\t\t\tconst graphLines = renderTrendGraph(\n\t\t\t\tfullPackagePath,\n\t\t\t\tresults,\n\t\t\t\tflags?.boring,\n\t\t\t);\n\t\t\tfor (const line of graphLines) {\n\t\t\t\tlog.log(line);\n\t\t\t}\n\n\t\t\tprocess.exit(0);\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlog.error(`Failed to analyze trend: ${errorMessage}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\t// If --versions flag is set, fetch and prompt for version selection.\n\tif (flags?.versions) {\n\t\ttry {\n\t\t\tconst { name, subpath } = parsePackageSpecifier(packageName);\n\t\t\tlog.info(`\\nFetching available versions for ${name}...`);\n\n\t\t\tconst { versions, tags } = await fetchPackageVersions({\n\t\t\t\tpackageName,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\n\t\t\tif (versions.length === 0) {\n\t\t\t\tlog.error(\"No versions found for this package\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tconst selectedVersion = await promptForVersion(name, versions, tags);\n\t\t\t// Rebuild specifier preserving any subpath.\n\t\t\tpackageName = subpath\n\t\t\t\t? `${name}/${subpath}@${selectedVersion}`\n\t\t\t\t: `${name}@${selectedVersion}`;\n\t\t\tlog.info(`\\nSelected: ${packageName}`);\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlog.error(`Failed to fetch versions: ${errorMessage}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tlog.info(`\\nAnalyzing bundle size for: ${packageName}`);\n\tif (exports && exports.length > 0) {\n\t\tlog.info(`Exports: { ${exports.join(\", \")} }`);\n\t}\n\n\ttry {\n\t\t// Parse package specifier to get name and version.\n\t\tconst { name: baseName, version: requestedVersion } =\n\t\t\tparsePackageSpecifier(packageName);\n\n\t\t// Resolve \"latest\" to actual version for cache key.\n\t\tlet resolvedVersion = requestedVersion;\n\t\tif (requestedVersion === \"latest\") {\n\t\t\tconst { tags } = await fetchPackageVersions({\n\t\t\t\tpackageName: baseName,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\t\t\tresolvedVersion = tags.latest || requestedVersion;\n\t\t}\n\n\t\t// Compute externals for cache key (same logic as bundler).\n\t\tconst externals = getExternals(\n\t\t\tbaseName,\n\t\t\tadditionalExternals,\n\t\t\tflags?.noExternal,\n\t\t);\n\n\t\t/**\n\t\t * Build cache key.\n\t\t * NOTE: platform can be undefined (auto-detect), which is stored as \"auto\" in cache.\n\t\t */\n\t\tconst cacheKey = normalizeCacheKey({\n\t\t\tpackageName: baseName,\n\t\t\tversion: resolvedVersion,\n\t\t\texports,\n\t\t\tplatform,\n\t\t\tgzipLevel: flags?.gzipLevel ?? 5,\n\t\t\texternals,\n\t\t\tnoExternal: flags?.noExternal ?? false,\n\t\t});\n\n\t\t// Check cache (unless --force flag is set).\n\t\tif (!flags?.force) {\n\t\t\tconst cached = getCachedResult(cacheKey);\n\t\t\tif (cached) {\n\t\t\t\tlog.info(\"NOTE: Using cached results\\n\");\n\t\t\t\tdisplayResult(cached, platform === undefined);\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t}\n\n\t\tlog.info(\"Please wait, installing and bundling...\\n\");\n\n\t\tconst result = await checkBundleSize({\n\t\t\tpackageName,\n\t\t\texports,\n\t\t\tadditionalExternals,\n\t\t\tnoExternal: flags?.noExternal,\n\t\t\tgzipLevel: flags?.gzipLevel,\n\t\t\tregistry: flags?.registry,\n\t\t\tplatform,\n\t\t\ttarget,\n\t\t});\n\n\t\t// Store result in cache.\n\t\tsetCachedResult(cacheKey, result);\n\n\t\tdisplayResult(result, platform === undefined);\n\n\t\tprocess.exit(0);\n\t} catch (error) {\n\t\tconst errorMessage = error instanceof Error ? error.message : String(error);\n\t\tlog.error(`Failed to analyze bundle size: ${errorMessage}`);\n\t\tprocess.exit(1);\n\t}\n}\n\nmain();\n"],"names":["Logger","kleur","checkBundleSize","formatBytes","getExternals","parsePackageSpecifier","getCachedResult","normalizeCacheKey","setCachedResult","normalizePlatform","normalizeTarget","TREND_VERSION_COUNT","config","analyzeTrend","renderTrendGraph","selectTrendVersions","fetchPackageVersions","promptForVersion","flags","parameters","enabled","boring","log","displayResult","result","isAutoDetected","blue","green","platformLabel","platform","platformNote","exportsDisplay","exports","length","join","namedExportCount","printBox","packageName","packageVersion","rawSize","gzipSize","gzipLevel","externals","dependencies","borderStyle","align","main","error","showHelp","process","exit","additionalExternals","external","split","map","e","trim","filter","Boolean","exportsArg","target","trendValue","trend","undefined","parsedCount","Number","parseInt","versionCount","isNaN","name","subpath","fullPackagePath","info","versions","registry","trendVersions","results","noExternal","force","graphLines","line","errorMessage","Error","message","String","tags","selectedVersion","baseName","version","requestedVersion","resolvedVersion","latest","cacheKey","cached"],"mappings":";AAEA,wBAAwB,GAExB,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,WAAW,QAAQ;AAC1B,SACCC,eAAe,EACfC,WAAW,EACXC,YAAY,EACZC,qBAAqB,QACf,eAAe;AACtB,SACCC,eAAe,EACfC,iBAAiB,EACjBC,eAAe,QACT,aAAa;AACpB,SACCC,iBAAiB,EACjBC,eAAe,EACfC,mBAAmB,QACb,gBAAgB;AACvB,SAASC,MAAM,QAAQ,aAAa;AACpC,SACCC,YAAY,EACZC,gBAAgB,EAChBC,mBAAmB,QACb,aAAa;AACpB,SAASC,oBAAoB,EAAEC,gBAAgB,QAAQ,gBAAgB;AAEvE,MAAMC,QAAQN,OAAOM,KAAK;AAC1B,MAAMC,aAAaP,OAAOO,UAAU;AAEpC,kDAAkD;AAClDlB,MAAMmB,OAAO,GAAG,CAACF,OAAOG;AAExB,MAAMC,MAAM,IAAItB,OAAO;IACtBqB,QAAQH,OAAOG;AAChB;AAEA;;CAEC,GACD,SAASE,cACRC,MAWC,EACDC,cAAuB;IAEvB,MAAMC,OAAOzB,MAAMyB,IAAI;IACvB,MAAMC,QAAQ1B,MAAM0B,KAAK;IAEzB,MAAMC,gBAAgBJ,OAAOK,QAAQ,KAAK,SAAS,SAAS;IAC5D,MAAMC,eAAeL,iBAAiB,qBAAqB;IAE3D,0BAA0B;IAC1B,IAAIM;IACJ,IAAIP,OAAOQ,OAAO,CAACC,MAAM,GAAG,GAAG;QAC9BF,iBAAiB,CAAC,EAAE,EAAEP,OAAOQ,OAAO,CAACE,IAAI,CAAC,MAAM,EAAE,CAAC;IACpD,OAAO,IAAIV,OAAOW,gBAAgB,GAAG,GAAG;QACvCJ,iBAAiB,GAAGP,OAAOW,gBAAgB,CAAC,+BAA+B,CAAC;IAC7E,OAAO;QACNJ,iBAAiB;IAClB;IAEAT,IAAIc,QAAQ,CACX;QACC,GAAGV,KAAK,YA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ClBiC,UAAUxD,OAAOwD;YACjB7C;YACA+B;QACD;QAEA,yBAAyB;QACzBpD,gBAAgBoF,UAAUpE;QAE1BD,cAAcC,QAAQK,aAAakC;QAEnCd,QAAQC,IAAI,CAAC;IACd,EAAE,OAAOH,OAAO;QACf,MAAMkC,eAAelC,iBAAiBmC,QAAQnC,MAAMoC,OAAO,GAAGC,OAAOrC;QACrEzB,IAAIyB,KAAK,CAAC,CAAC,+BAA+B,EAAEkC,cAAc;QAC1DhC,QAAQC,IAAI,CAAC;IACd;AACD;AAEAJ"}
|
package/dist/bundler.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ export type BundleOptions = {
|
|
|
23
23
|
* Target platform. If undefined, auto-detects from package.json engines.
|
|
24
24
|
*/
|
|
25
25
|
platform?: "browser" | "node";
|
|
26
|
+
/**
|
|
27
|
+
* esbuild target (e.g., "es2022", "es2020"). Defaults to "es2022".
|
|
28
|
+
*/
|
|
29
|
+
target?: string;
|
|
26
30
|
};
|
|
27
31
|
export type BundleResult = {
|
|
28
32
|
packageName: string;
|
package/dist/bundler.js
CHANGED
|
@@ -5,7 +5,7 @@ import path from "node:path";
|
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
import zlib from "node:zlib";
|
|
7
7
|
import * as esbuild from "esbuild";
|
|
8
|
-
import { DEFAULT_EXTERNALS, EXTERNAL_SUBPATHS } from "./defaults.js";
|
|
8
|
+
import { BROWSER_FRAMEWORK_DEPS, DEFAULT_EXTERNALS, DEFAULT_TARGET, EXTERNAL_SUBPATHS } from "./defaults.js";
|
|
9
9
|
import { getNamedExports } from "./exports.js";
|
|
10
10
|
const gzipAsync = promisify(zlib.gzip);
|
|
11
11
|
/**
|
|
@@ -446,7 +446,7 @@ let usePnpm = null;
|
|
|
446
446
|
/**
|
|
447
447
|
* Check the bundle size of an npm package.
|
|
448
448
|
*/ export async function checkBundleSize(options) {
|
|
449
|
-
const { packageName: packageSpecifier, exports, additionalExternals, noExternal, gzipLevel = 5, registry, platform: explicitPlatform } = options;
|
|
449
|
+
const { packageName: packageSpecifier, exports, additionalExternals, noExternal, gzipLevel = 5, registry, platform: explicitPlatform, target = DEFAULT_TARGET } = options;
|
|
450
450
|
// Parse the package specifier to extract name, version, and subpath.
|
|
451
451
|
const { name: packageName, version: requestedVersion, subpath } = parsePackageSpecifier(packageSpecifier);
|
|
452
452
|
const tmpDir = createTempDir();
|
|
@@ -479,8 +479,20 @@ let usePnpm = null;
|
|
|
479
479
|
if (explicitPlatform) {
|
|
480
480
|
platform = explicitPlatform;
|
|
481
481
|
} else if (pkgInfo.engines?.node && !pkgInfo.engines?.browser) {
|
|
482
|
-
|
|
483
|
-
|
|
482
|
+
/**
|
|
483
|
+
* Package specifies node engine without browser - potentially a Node.js
|
|
484
|
+
* package. However, many browser packages also specify engines.node for
|
|
485
|
+
* build tooling or SSR compatibility (e.g., @clerk/clerk-react). Check
|
|
486
|
+
* if the package has browser-framework dependencies which indicate it's
|
|
487
|
+
* a browser package despite having engines.node.
|
|
488
|
+
*/ const allDepNames = [
|
|
489
|
+
...Object.keys(pkgInfo.dependencies),
|
|
490
|
+
...Object.keys(pkgInfo.peerDependencies)
|
|
491
|
+
];
|
|
492
|
+
const hasBrowserFrameworkDep = allDepNames.some((dep)=>BROWSER_FRAMEWORK_DEPS.includes(dep));
|
|
493
|
+
if (!hasBrowserFrameworkDep) {
|
|
494
|
+
platform = "node";
|
|
495
|
+
}
|
|
484
496
|
}
|
|
485
497
|
// Collect all dependency names (prod + peer).
|
|
486
498
|
const allDependencies = [
|
|
@@ -559,7 +571,7 @@ let usePnpm = null;
|
|
|
559
571
|
write: false,
|
|
560
572
|
format: "esm",
|
|
561
573
|
platform,
|
|
562
|
-
target
|
|
574
|
+
target,
|
|
563
575
|
minify: true,
|
|
564
576
|
treeShaking: true,
|
|
565
577
|
external: esbuildExternals,
|
|
@@ -595,7 +607,7 @@ let usePnpm = null;
|
|
|
595
607
|
write: false,
|
|
596
608
|
format: "esm",
|
|
597
609
|
platform,
|
|
598
|
-
target
|
|
610
|
+
target,
|
|
599
611
|
minify: true,
|
|
600
612
|
treeShaking: true,
|
|
601
613
|
external: esbuildExternals,
|