@node-cli/bundlecheck 1.6.0 → 1.6.2

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 CHANGED
@@ -95,20 +95,20 @@ bundlecheck lodash "debounce,throttle"
95
95
 
96
96
  ### Options
97
97
 
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" |
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" |
112
112
 
113
113
  ### Examples
114
114
 
@@ -170,11 +170,16 @@ npm install @node-cli/bundlecheck
170
170
  ### Basic Usage
171
171
 
172
172
  ```js
173
- import { getBundleStats, getBundleTrend, getPackageVersions, getPackageExports } from "@node-cli/bundlecheck";
173
+ import {
174
+ getBundleStats,
175
+ getBundleTrend,
176
+ getPackageVersions,
177
+ getPackageExports
178
+ } from "@node-cli/bundlecheck";
174
179
 
175
180
  // Get bundle stats for a single package
176
181
  const stats = await getBundleStats({
177
- package: "@mantine/core@7.0.0",
182
+ package: "@mantine/core@7.0.0"
178
183
  });
179
184
  console.log(stats);
180
185
  // {
@@ -195,14 +200,14 @@ console.log(stats);
195
200
  // Check specific exports (tree-shaking)
196
201
  const buttonStats = await getBundleStats({
197
202
  package: "@mantine/core",
198
- exports: ["Button", "Input"],
203
+ exports: ["Button", "Input"]
199
204
  });
200
205
  console.log(buttonStats.gzipSizeFormatted); // "12.3 kB"
201
206
 
202
207
  // Get bundle size trend across versions
203
208
  const trend = await getBundleTrend({
204
209
  package: "@mantine/core",
205
- versionCount: 5,
210
+ versionCount: 5
206
211
  });
207
212
  console.log(trend);
208
213
  // {
@@ -226,17 +231,17 @@ console.log(trend);
226
231
 
227
232
  // Get available versions for a package
228
233
  const versions = await getPackageVersions({
229
- package: "@mantine/core",
234
+ package: "@mantine/core"
230
235
  });
231
236
  console.log(versions.tags.latest); // "7.0.0"
232
237
  console.log(versions.versions.slice(0, 5)); // ["7.0.0", "6.0.21", "6.0.20", ...]
233
238
 
234
239
  // Get named exports from a package
235
240
  const exports = await getPackageExports({
236
- package: "date-fns@3.6.0",
241
+ package: "date-fns@3.6.0"
237
242
  });
238
243
  console.log(`Found ${exports.count} exports`);
239
- 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", ...]
240
245
  ```
241
246
 
242
247
  ### API Reference
@@ -247,35 +252,35 @@ Get bundle size statistics for a single package.
247
252
 
248
253
  **Options:**
249
254
 
250
- | Option | Type | Default | Description |
251
- | ------------ | ----------------------------- | ---------- | -------------------------------------------------------- |
252
- | `package` | `string` | (required) | Package name with optional version (e.g., `lodash@4.17.0`) |
253
- | `exports` | `string[]` | `undefined`| Specific exports to measure (tree-shaking) |
254
- | `external` | `string[]` | `undefined`| Additional packages to mark as external |
255
- | `noExternal` | `boolean` | `false` | Bundle everything (no externals, even react/react-dom) |
256
- | `gzipLevel` | `number` | `5` | Gzip compression level (1-9) |
257
- | `registry` | `string` | `undefined`| Custom npm registry URL |
258
- | `platform` | `"browser" \| "node" \| "auto"` | `"auto"` | Target platform |
259
- | `force` | `boolean` | `false` | Bypass cache |
260
- | `target` | `string` | `"es2022"` | esbuild target (e.g., "es2022", "es2020") |
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") |
261
266
 
262
267
  **Returns:** `Promise<BundleStats>`
263
268
 
264
269
  ```ts
265
270
  type BundleStats = {
266
- packageName: string; // Display name (may include subpath)
267
- packageVersion: string; // Resolved version
268
- exports: string[]; // Exports analyzed
269
- rawSize: number; // Raw size in bytes
270
- gzipSize: number | null; // Gzip size in bytes (null for node platform)
271
- gzipLevel: number; // Compression level used
272
- externals: string[]; // External packages
273
- dependencies: string[]; // Package dependencies
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
274
279
  platform: "browser" | "node";
275
- rawSizeFormatted: string; // Human-readable (e.g., "45.2 kB")
280
+ rawSizeFormatted: string; // Human-readable (e.g., "45.2 kB")
276
281
  gzipSizeFormatted: string | null;
277
- fromCache: boolean; // Whether result was from cache
278
- namedExportCount: number; // Total named exports in package
282
+ fromCache: boolean; // Whether result was from cache
283
+ namedExportCount: number; // Total named exports in package
279
284
  };
280
285
  ```
281
286
 
@@ -285,26 +290,26 @@ Get bundle size trend across multiple versions.
285
290
 
286
291
  **Options:**
287
292
 
288
- | Option | Type | Default | Description |
289
- | -------------- | ----------------------------- | ---------- | -------------------------------------------------------- |
290
- | `package` | `string` | (required) | Package name (version ignored if provided) |
291
- | `versionCount` | `number` | `5` | Number of versions to analyze |
292
- | `exports` | `string[]` | `undefined`| Specific exports to measure |
293
- | `external` | `string[]` | `undefined`| Additional packages to mark as external |
294
- | `noExternal` | `boolean` | `false` | Bundle everything including default externals |
295
- | `gzipLevel` | `number` | `5` | Gzip compression level (1-9) |
296
- | `registry` | `string` | `undefined`| Custom npm registry URL |
297
- | `platform` | `"browser" \| "node" \| "auto"` | `"auto"` | Target platform |
298
- | `force` | `boolean` | `false` | Bypass cache |
299
- | `target` | `string` | `"es2022"` | esbuild target (e.g., "es2022", "es2020") |
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") |
300
305
 
301
306
  **Returns:** `Promise<BundleTrend>`
302
307
 
303
308
  ```ts
304
309
  type BundleTrend = {
305
310
  packageName: string;
306
- versions: TrendVersionResult[]; // Results for each version (newest first)
307
- change: TrendChange | null; // Change between oldest and newest
311
+ versions: TrendVersionResult[]; // Results for each version (newest first)
312
+ change: TrendChange | null; // Change between oldest and newest
308
313
  };
309
314
 
310
315
  type TrendVersionResult = {
@@ -318,11 +323,11 @@ type TrendVersionResult = {
318
323
  type TrendChange = {
319
324
  fromVersion: string;
320
325
  toVersion: string;
321
- rawDiff: number; // Positive = increase, negative = decrease
322
- rawPercent: number | null; // null if oldest size was 0
323
- rawDiffFormatted: string; // e.g., "+5.2 kB" or "-1.3 kB"
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"
324
329
  gzipDiff: number | null;
325
- gzipPercent: number | null; // null if not applicable or oldest size was 0
330
+ gzipPercent: number | null; // null if not applicable or oldest size was 0
326
331
  gzipDiffFormatted: string | null;
327
332
  };
328
333
  ```
@@ -333,17 +338,17 @@ Get available versions for an npm package.
333
338
 
334
339
  **Options:**
335
340
 
336
- | Option | Type | Default | Description |
337
- | ---------- | -------- | ---------- | ---------------------------- |
338
- | `package` | `string` | (required) | Package name |
339
- | `registry` | `string` | `undefined`| Custom npm registry URL |
341
+ | Option | Type | Default | Description |
342
+ | ---------- | -------- | ----------- | ----------------------- |
343
+ | `package` | `string` | (required) | Package name |
344
+ | `registry` | `string` | `undefined` | Custom npm registry URL |
340
345
 
341
346
  **Returns:** `Promise<PackageVersions>`
342
347
 
343
348
  ```ts
344
349
  type PackageVersions = {
345
- versions: string[]; // All versions (newest first)
346
- tags: Record<string, string>; // Dist tags (e.g., { latest: "7.0.0" })
350
+ versions: string[]; // All versions (newest first)
351
+ tags: Record<string, string>; // Dist tags (e.g., { latest: "7.0.0" })
347
352
  };
348
353
  ```
349
354
 
@@ -353,26 +358,33 @@ Get the named exports of an npm package by analyzing its TypeScript declarations
353
358
 
354
359
  **Options:**
355
360
 
356
- | Option | Type | Default | Description |
357
- | ---------- | -------- | ---------- | ------------------------------------------------ |
358
- | `package` | `string` | (required) | Package name with optional version |
359
- | `registry` | `string` | `undefined`| Custom npm registry URL |
361
+ | Option | Type | Default | Description |
362
+ | ---------- | -------- | ----------- | ---------------------------------- |
363
+ | `package` | `string` | (required) | Package name with optional version |
364
+ | `registry` | `string` | `undefined` | Custom npm registry URL |
360
365
 
361
366
  **Returns:** `Promise<PackageExports>`
362
367
 
363
368
  ```ts
364
369
  type PackageExports = {
365
- packageName: string; // Package name
366
- packageVersion: string; // Resolved version
367
- exports: PackageExport[]; // All named exports (including types)
368
- count: number; // Total count (including types)
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)
369
374
  runtimeExports: PackageExport[]; // Runtime exports only (no types/interfaces)
370
- runtimeCount: number; // Count of runtime exports
375
+ runtimeCount: number; // Count of runtime exports
371
376
  };
372
377
 
373
378
  type PackageExport = {
374
- name: string; // Export name (e.g., "Button")
375
- kind: "function" | "class" | "const" | "type" | "interface" | "enum" | "unknown";
379
+ name: string; // Export name (e.g., "Button")
380
+ kind:
381
+ | "function"
382
+ | "class"
383
+ | "const"
384
+ | "type"
385
+ | "interface"
386
+ | "enum"
387
+ | "unknown";
376
388
  };
377
389
  ```
378
390
 
@@ -380,10 +392,10 @@ type PackageExport = {
380
392
 
381
393
  ```js
382
394
  const result = await getPackageExports({
383
- package: "@mantine/core",
395
+ package: "@mantine/core"
384
396
  });
385
397
 
386
- console.log(result.count); // 1056 (all exports including types)
398
+ console.log(result.count); // 1056 (all exports including types)
387
399
  console.log(result.runtimeCount); // 365 (only importable exports)
388
400
  console.log(result.runtimeExports[0]); // { name: "Accordion", kind: "unknown" }
389
401
  ```
@@ -391,11 +403,16 @@ console.log(result.runtimeExports[0]); // { name: "Accordion", kind: "unknown" }
391
403
  ### Utility Functions
392
404
 
393
405
  ```js
394
- import { formatBytes, parsePackageSpecifier, clearCache, getCacheCount } from "@node-cli/bundlecheck";
406
+ import {
407
+ formatBytes,
408
+ parsePackageSpecifier,
409
+ clearCache,
410
+ getCacheCount
411
+ } from "@node-cli/bundlecheck";
395
412
 
396
413
  // Format bytes to human-readable string
397
- formatBytes(1024); // "1 kB"
398
- formatBytes(1536); // "1.5 kB"
414
+ formatBytes(1024); // "1 kB"
415
+ formatBytes(1536); // "1.5 kB"
399
416
 
400
417
  // Parse a package specifier
401
418
  parsePackageSpecifier("@scope/name@1.0.0");
@@ -405,8 +422,8 @@ parsePackageSpecifier("@scope/name/subpath@2.0.0");
405
422
  // { name: "@scope/name", version: "2.0.0", subpath: "subpath" }
406
423
 
407
424
  // Cache management
408
- getCacheCount(); // Returns number of cached entries
409
- clearCache(); // Clears all cached results
425
+ getCacheCount(); // Returns number of cached entries
426
+ clearCache(); // Clears all cached results
410
427
  ```
411
428
 
412
429
  ## How It Works
@@ -429,6 +446,7 @@ The `--platform` flag controls how the bundle is built:
429
446
  - **`node`**: Builds for Node.js environments (also accepts aliases: `server`, `nodejs`, `backend`)
430
447
 
431
448
  When targeting **node** platform:
449
+
432
450
  - Gzip size is not calculated (shows "N/A") since server-side code isn't typically served compressed over HTTP
433
451
  - The bundle is optimized for Node.js built-ins
434
452
 
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, DEFAULT_TARGET, 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
  /**
@@ -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
- // Package specifies node engine without browser - likely a Node.js package.
483
- platform = "node";
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 = [
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/bundler.ts"],"sourcesContent":["import { execSync } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { promisify } from \"node:util\";\nimport zlib from \"node:zlib\";\nimport * as esbuild from \"esbuild\";\nimport {\n\tDEFAULT_EXTERNALS,\n\tDEFAULT_TARGET,\n\tEXTERNAL_SUBPATHS,\n} from \"./defaults.js\";\nimport { getNamedExports } from \"./exports.js\";\n\nconst gzipAsync = promisify(zlib.gzip);\n\n/**\n * Escape special regex characters in a string.\n */\nfunction escapeRegExp(str: string): string {\n\treturn str.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nexport type ParsedPackage = {\n\tname: string;\n\tversion: string;\n\tsubpath?: string;\n};\n\n/**\n * Parse a package specifier to extract name, version, and subpath.\n * Handles:\n * - @scope/package@1.0.0\n * - @scope/package/subpath@1.0.0\n * - @scope/package/subpath\n * - package/subpath@1.0.0\n */\nexport function parsePackageSpecifier(specifier: string): ParsedPackage {\n\tlet workingSpec = specifier;\n\tlet version = \"latest\";\n\n\t// Handle scoped packages (@scope/name...)\n\tif (workingSpec.startsWith(\"@\")) {\n\t\t// Find the second @ which would separate version.\n\t\tconst secondAtIndex = workingSpec.indexOf(\"@\", 1);\n\t\tif (secondAtIndex !== -1) {\n\t\t\tversion = workingSpec.substring(secondAtIndex + 1);\n\t\t\tworkingSpec = workingSpec.substring(0, secondAtIndex);\n\t\t}\n\n\t\t/**\n\t\t * Now workingSpec is like @scope/name or @scope/name/subpath Split by / and\n\t\t * check if there are more than 2 parts.\n\t\t */\n\t\tconst parts = workingSpec.split(\"/\");\n\t\tif (parts.length > 2) {\n\t\t\t// Has subpath: @scope/name/subpath/more.\n\t\t\tconst name = `${parts[0]}/${parts[1]}`;\n\t\t\tconst subpath = parts.slice(2).join(\"/\");\n\t\t\treturn { name, version, subpath };\n\t\t}\n\t\t// No subpath: @scope/name.\n\t\treturn { name: workingSpec, version };\n\t}\n\n\t// Handle non-scoped packages (name@version or name/subpath@version).\n\tconst atIndex = workingSpec.indexOf(\"@\");\n\tif (atIndex !== -1) {\n\t\tversion = workingSpec.substring(atIndex + 1);\n\t\tworkingSpec = workingSpec.substring(0, atIndex);\n\t}\n\n\t// Check for subpath in non-scoped packages.\n\tconst slashIndex = workingSpec.indexOf(\"/\");\n\tif (slashIndex !== -1) {\n\t\tconst name = workingSpec.substring(0, slashIndex);\n\t\tconst subpath = workingSpec.substring(slashIndex + 1);\n\t\treturn { name, version, subpath };\n\t}\n\n\treturn { name: workingSpec, version };\n}\n\nexport type BundleOptions = {\n\tpackageName: string;\n\texports?: string[];\n\tadditionalExternals?: string[];\n\tnoExternal?: boolean;\n\tgzipLevel?: number;\n\tregistry?: string;\n\t/**\n\t * Target platform. If undefined, auto-detects from package.json engines.\n\t */\n\tplatform?: \"browser\" | \"node\";\n\t/**\n\t * esbuild target (e.g., \"es2022\", \"es2020\"). Defaults to \"es2022\".\n\t */\n\ttarget?: string;\n};\n\nexport type BundleResult = {\n\tpackageName: string;\n\tpackageVersion: string;\n\texports: string[];\n\trawSize: number;\n\t/**\n\t * Gzip size in bytes, or null for node platform (gzip not applicable).\n\t */\n\tgzipSize: number | null;\n\tgzipLevel: number;\n\texternals: string[];\n\tdependencies: string[];\n\tplatform: \"browser\" | \"node\";\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 * Format bytes to human-readable string.\n */\nexport function formatBytes(bytes: number): string {\n\tif (bytes === 0) {\n\t\treturn \"0 B\";\n\t}\n\tconst k = 1024;\n\tconst sizes = [\"B\", \"kB\", \"MB\", \"GB\"];\n\tconst i = Math.floor(Math.log(bytes) / Math.log(k));\n\treturn `${Number.parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`;\n}\n\n/**\n * Create a temporary directory for bundling.\n */\nfunction createTempDir(): string {\n\tconst tmpDir = path.join(os.tmpdir(), `bundlecheck-${Date.now()}`);\n\tfs.mkdirSync(tmpDir, { recursive: true });\n\treturn tmpDir;\n}\n\n/**\n * Clean up temporary directory.\n */\nfunction cleanupTempDir(tmpDir: string): void {\n\ttry {\n\t\tfs.rmSync(tmpDir, { recursive: true, force: true });\n\t} catch {\n\t\t// Ignore cleanup errors.\n\t}\n}\n\n/**\n * Check if pnpm is available.\n */\nfunction isPnpmAvailable(): boolean {\n\ttry {\n\t\texecSync(\"pnpm --version\", { stdio: \"pipe\" });\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n// Cache the result of pnpm availability check.\nlet usePnpm: boolean | null = null;\n\n/**\n * Validate and sanitize a registry URL to prevent command injection.\n * @param registry - The registry URL to validate\n * @returns The sanitized URL or undefined if invalid\n * @throws Error if the URL is invalid or contains potentially malicious characters\n */\nfunction validateRegistryUrl(registry: string): string {\n\t// Parse as URL to validate format.\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(registry);\n\t} catch {\n\t\tthrow new Error(\n\t\t\t`Invalid registry URL: ${registry}. Must be a valid URL (e.g., https://registry.example.com)`,\n\t\t);\n\t}\n\n\t// Only allow http and https protocols.\n\tif (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n\t\tthrow new Error(\n\t\t\t`Invalid registry URL protocol: ${url.protocol}. Only http: and https: are allowed`,\n\t\t);\n\t}\n\n\t// Return the sanitized URL (URL constructor normalizes it).\n\treturn url.toString();\n}\n\n/**\n * Get the install command (pnpm preferred, npm fallback).\n * @param registry - Optional custom npm registry URL\n */\nfunction getInstallCommand(registry?: string): string {\n\tif (usePnpm === null) {\n\t\tusePnpm = isPnpmAvailable();\n\t}\n\n\tlet registryArg = \"\";\n\tif (registry) {\n\t\t// Validate and sanitize the registry URL to prevent command injection.\n\t\tconst sanitizedRegistry = validateRegistryUrl(registry);\n\t\t// Quote the URL to handle any special characters safely.\n\t\tregistryArg = ` --registry \"${sanitizedRegistry}\"`;\n\t}\n\n\tif (usePnpm) {\n\t\treturn `pnpm install --ignore-scripts --no-frozen-lockfile${registryArg}`;\n\t}\n\treturn `npm install --legacy-peer-deps --ignore-scripts${registryArg}`;\n}\n\nexport type EntryContentOptions = {\n\tpackageName: string;\n\tsubpath?: string;\n\texports?: string[];\n\tallSubpaths?: string[];\n\texportToSubpath?: Map<string, string>;\n};\n\n/**\n * Generate the entry file content based on package, subpath, and exports.\n */\nfunction generateEntryContent(options: EntryContentOptions): string {\n\tconst { packageName, subpath, exports, allSubpaths, exportToSubpath } =\n\t\toptions;\n\n\t// If we have exports mapped to different subpaths.\n\tif (exportToSubpath && exportToSubpath.size > 0) {\n\t\t// Group exports by subpath.\n\t\tconst subpathToExports = new Map<string, string[]>();\n\t\tfor (const [exportName, sp] of exportToSubpath) {\n\t\t\tconst existing = subpathToExports.get(sp) || [];\n\t\t\texisting.push(exportName);\n\t\t\tsubpathToExports.set(sp, existing);\n\t\t}\n\n\t\t// Generate imports for each subpath.\n\t\tconst lines: string[] = [];\n\t\tconst allExportNames: string[] = [];\n\n\t\tfor (const [sp, exportNames] of subpathToExports) {\n\t\t\tconst importPath = `${packageName}/${sp}`;\n\t\t\tconst names = exportNames.join(\", \");\n\t\t\tlines.push(`import { ${names} } from \"${importPath}\";`);\n\t\t\tallExportNames.push(...exportNames);\n\t\t}\n\n\t\tlines.push(`export { ${allExportNames.join(\", \")} };`);\n\t\treturn lines.join(\"\\n\") + \"\\n\";\n\t}\n\n\t// If we have specific exports to import.\n\tif (exports && exports.length > 0) {\n\t\t// Determine the import path.\n\t\tconst importPath = subpath ? `${packageName}/${subpath}` : packageName;\n\t\tconst importNames = exports.join(\", \");\n\t\treturn `import { ${importNames} } from \"${importPath}\";\\nexport { ${importNames} };\\n`;\n\t}\n\n\t// If we have a specific subpath (but no specific exports).\n\tif (subpath) {\n\t\tconst importPath = `${packageName}/${subpath}`;\n\t\treturn `import * as pkg from \"${importPath}\";\\nexport default pkg;\\n`;\n\t}\n\n\t// If package has subpath exports only (no main entry), import all subpaths.\n\tif (allSubpaths && allSubpaths.length > 0) {\n\t\tconst imports = allSubpaths\n\t\t\t.map(\n\t\t\t\t(sp, i) =>\n\t\t\t\t\t`import * as sub${i} from \"${packageName}/${sp}\";\\nexport { sub${i} };`,\n\t\t\t)\n\t\t\t.join(\"\\n\");\n\t\treturn imports + \"\\n\";\n\t}\n\n\t// Default: import everything from main entry.\n\treturn `import * as pkg from \"${packageName}\";\\nexport default pkg;\\n`;\n}\n\n/**\n * Check if an error is an esbuild BuildFailure. BuildFailure has an `errors`\n * array with structured error objects.\n */\nfunction isEsbuildBuildFailure(\n\terror: unknown,\n): error is { errors: Array<{ text: string; location?: unknown }> } {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"errors\" in error &&\n\t\tArray.isArray((error as { errors: unknown }).errors)\n\t);\n}\n\n/**\n * Extract unresolved module paths from an esbuild BuildFailure error. Returns\n * an object indicating which react-related modules failed to resolve.\n *\n * Uses esbuild's structured error objects (errors array) for reliable parsing.\n * Falls back to string matching if the error format is unexpected.\n *\n * Tested against esbuild 0.27.x error format.\n *\n */\nfunction parseUnresolvedModules(error: unknown): {\n\thasUnresolvedReact: boolean;\n\thasUnresolvedReactDom: boolean;\n} {\n\tconst result = { hasUnresolvedReact: false, hasUnresolvedReactDom: false };\n\n\t/**\n\t * Pattern to extract module path from \"Could not resolve X\" errors. Matches:\n\t * Could not resolve \"module-name\" or Could not resolve 'module-name'.\n\t */\n\tconst resolveErrorPattern = /Could not resolve [\"']([^\"']+)[\"']/;\n\n\tif (isEsbuildBuildFailure(error)) {\n\t\t// Use structured error objects from esbuild BuildFailure.\n\t\tfor (const err of error.errors) {\n\t\t\tconst match = resolveErrorPattern.exec(err.text);\n\t\t\tif (match) {\n\t\t\t\tconst modulePath = match[1];\n\t\t\t\t// Check if it's a react or react-dom import (including subpaths).\n\t\t\t\tif (modulePath === \"react\" || modulePath.startsWith(\"react/\")) {\n\t\t\t\t\tresult.hasUnresolvedReact = true;\n\t\t\t\t}\n\t\t\t\tif (modulePath === \"react-dom\" || modulePath.startsWith(\"react-dom/\")) {\n\t\t\t\t\tresult.hasUnresolvedReactDom = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\t// Fallback: parse error message string (less reliable).\n\t\tconst errorMessage = String(error);\n\t\tconst matches = errorMessage.matchAll(\n\t\t\t/Could not resolve [\"']([^\"']+)[\"']/g,\n\t\t);\n\t\tfor (const match of matches) {\n\t\t\tconst modulePath = match[1];\n\t\t\tif (modulePath === \"react\" || modulePath.startsWith(\"react/\")) {\n\t\t\t\tresult.hasUnresolvedReact = true;\n\t\t\t}\n\t\t\tif (modulePath === \"react-dom\" || modulePath.startsWith(\"react-dom/\")) {\n\t\t\t\tresult.hasUnresolvedReactDom = true;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Get externals list based on options and package dependencies. react and\n * react-dom are only marked as external if they are declared in the package's\n * dependencies or peerDependencies.\n *\n * Returns the base package names (e.g., [\"react\", \"react-dom\"]) for display\n * purposes.\n *\n */\nexport function getExternals(\n\tpackageName: string,\n\texternals?: string[],\n\tnoExternal?: boolean,\n\tpackageDependencies?: string[],\n): string[] {\n\tif (noExternal) {\n\t\treturn [];\n\t}\n\n\t/**\n\t * Start with empty result - we'll only add react/react-dom if they're in\n\t * package deps.\n\t */\n\tlet result: string[] = [];\n\n\t/**\n\t * Only include react/react-dom if they're in the package's dependencies or\n\t * peerDependencies.\n\t */\n\tif (packageDependencies && packageDependencies.length > 0) {\n\t\tfor (const dep of DEFAULT_EXTERNALS) {\n\t\t\t// Don't mark as external if we're checking the package itself.\n\t\t\tif (dep === packageName) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (packageDependencies.includes(dep)) {\n\t\t\t\tresult.push(dep);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Add any additional externals.\n\tif (externals && externals.length > 0) {\n\t\tresult = [...new Set([...result, ...externals])];\n\t}\n\n\treturn result;\n}\n\n/**\n * Expand externals to include subpaths for esbuild. For example, \"react\"\n * expands to [\"react\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"]. This is\n * needed because esbuild doesn't automatically externalize subpaths.\n */\nexport function expandExternalsForEsbuild(externals: string[]): string[] {\n\tconst expanded: string[] = [];\n\n\tfor (const ext of externals) {\n\t\texpanded.push(ext);\n\t\t// Add subpaths if this is a known package with subpath exports.\n\t\tconst subpaths = EXTERNAL_SUBPATHS[ext];\n\t\tif (subpaths) {\n\t\t\texpanded.push(...subpaths);\n\t\t}\n\t}\n\n\treturn [...new Set(expanded)];\n}\n\nexport type PackageExports = Record<\n\tstring,\n\tstring | { import?: string; types?: string }\n>;\n\nexport type PackageInfo = {\n\tversion: string;\n\tdependencies: Record<string, string>;\n\tpeerDependencies: Record<string, string>;\n\texports: PackageExports | null;\n\thasMainEntry: boolean;\n\tengines: Record<string, string> | null;\n};\n\n/**\n * Get version, dependencies, peer dependencies, and exports from an installed\n * package.\n */\nfunction getPackageInfo(tmpDir: string, packageName: string): PackageInfo {\n\ttry {\n\t\t// Handle scoped packages - the package name in node_modules.\n\t\tconst pkgJsonPath = path.join(\n\t\t\ttmpDir,\n\t\t\t\"node_modules\",\n\t\t\tpackageName,\n\t\t\t\"package.json\",\n\t\t);\n\t\tif (fs.existsSync(pkgJsonPath)) {\n\t\t\tconst pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf-8\"));\n\n\t\t\t// Check if package has a main entry point.\n\t\t\tconst hasMainEntry = Boolean(\n\t\t\t\tpkgJson.main ||\n\t\t\t\t\tpkgJson.module ||\n\t\t\t\t\tpkgJson.exports?.[\".\"] ||\n\t\t\t\t\tpkgJson.exports?.[\"./index\"] ||\n\t\t\t\t\t(!pkgJson.exports && !pkgJson.main && !pkgJson.module),\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tversion: pkgJson.version || \"unknown\",\n\t\t\t\tdependencies: pkgJson.dependencies || {},\n\t\t\t\tpeerDependencies: pkgJson.peerDependencies || {},\n\t\t\t\texports: pkgJson.exports || null,\n\t\t\t\thasMainEntry,\n\t\t\t\tengines: pkgJson.engines || null,\n\t\t\t};\n\t\t}\n\t} catch {\n\t\t// Ignore errors reading package info.\n\t}\n\treturn {\n\t\tversion: \"unknown\",\n\t\tdependencies: {},\n\t\tpeerDependencies: {},\n\t\texports: null,\n\t\thasMainEntry: true,\n\t\tengines: null,\n\t};\n}\n\n/**\n * Extract subpath export names from package exports field Returns array of\n * subpaths like [\"header\", \"body\", \"datagrid\"].\n */\nfunction getSubpathExports(exports: PackageExports | null): string[] {\n\tif (!exports) {\n\t\treturn [];\n\t}\n\n\tconst subpaths: string[] = [];\n\tfor (const key of Object.keys(exports)) {\n\t\t// Skip the main entry point and package.json.\n\t\tif (key === \".\" || key === \"./package.json\") {\n\t\t\tcontinue;\n\t\t}\n\t\t// Remove leading \"./\" to get subpath name.\n\t\tif (key.startsWith(\"./\")) {\n\t\t\tsubpaths.push(key.substring(2));\n\t\t}\n\t}\n\treturn subpaths;\n}\n\n/**\n * Result of finding subpaths for exports.\n */\ntype SubpathMapping = {\n\t// Single subpath if all exports are from the same subpath.\n\tsingleSubpath?: string;\n\t// Map of export name to subpath for multiple subpaths.\n\texportToSubpath?: Map<string, string>;\n};\n\n/**\n * Find which subpath(s) export the given component names Reads type definition\n * files or JS files to find the exports.\n */\nfunction findSubpathsForExports(\n\ttmpDir: string,\n\tpackageName: string,\n\texports: PackageExports,\n\tcomponentNames: string[],\n): SubpathMapping {\n\tconst packageDir = path.join(tmpDir, \"node_modules\", packageName);\n\tconst exportToSubpath = new Map<string, string>();\n\n\tfor (const [subpathKey, subpathValue] of Object.entries(exports)) {\n\t\t// Skip main entry and package.json.\n\t\tif (subpathKey === \".\" || subpathKey === \"./package.json\") {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Get the types or import path.\n\t\tlet filePath: string | undefined;\n\t\tif (typeof subpathValue === \"object\" && subpathValue !== null) {\n\t\t\t// Prefer types file for more accurate export detection.\n\t\t\tfilePath = subpathValue.types || subpathValue.import;\n\t\t} else if (typeof subpathValue === \"string\") {\n\t\t\tfilePath = subpathValue;\n\t\t}\n\n\t\tif (!filePath) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Resolve the file path.\n\t\tconst fullPath = path.join(packageDir, filePath);\n\n\t\ttry {\n\t\t\tif (fs.existsSync(fullPath)) {\n\t\t\t\tconst content = fs.readFileSync(fullPath, \"utf-8\");\n\t\t\t\tconst subpath = subpathKey.startsWith(\"./\")\n\t\t\t\t\t? subpathKey.substring(2)\n\t\t\t\t\t: subpathKey;\n\n\t\t\t\t// Check each component name.\n\t\t\t\tfor (const name of componentNames) {\n\t\t\t\t\t// Skip if already found.\n\t\t\t\t\tif (exportToSubpath.has(name)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Escape regex special characters in the name to prevent injection.\n\t\t\t\t\tconst escapedName = escapeRegExp(name);\n\n\t\t\t\t\t// Look for various export patterns.\n\t\t\t\t\tconst patterns = [\n\t\t\t\t\t\tnew RegExp(`export\\\\s*\\\\{[^}]*\\\\b${escapedName}\\\\b[^}]*\\\\}`, \"m\"),\n\t\t\t\t\t\tnew RegExp(\n\t\t\t\t\t\t\t`export\\\\s+declare\\\\s+(?:const|function|class)\\\\s+${escapedName}\\\\b`,\n\t\t\t\t\t\t\t\"m\",\n\t\t\t\t\t\t),\n\t\t\t\t\t\tnew RegExp(\n\t\t\t\t\t\t\t`export\\\\s+(?:const|function|class)\\\\s+${escapedName}\\\\b`,\n\t\t\t\t\t\t\t\"m\",\n\t\t\t\t\t\t),\n\t\t\t\t\t];\n\n\t\t\t\t\tif (patterns.some((pattern) => pattern.test(content))) {\n\t\t\t\t\t\texportToSubpath.set(name, subpath);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore read errors, continue to next subpath.\n\t\t}\n\t}\n\n\t// Check if all exports were found.\n\tif (exportToSubpath.size !== componentNames.length) {\n\t\treturn {}; // Not all exports found\n\t}\n\n\t// Check if all exports are from the same subpath.\n\tconst subpaths = new Set(exportToSubpath.values());\n\tif (subpaths.size === 1) {\n\t\treturn { singleSubpath: [...subpaths][0] };\n\t}\n\n\t// Multiple subpaths needed.\n\treturn { exportToSubpath };\n}\n\n/**\n * Check the bundle size of an npm package.\n */\nexport async function checkBundleSize(\n\toptions: BundleOptions,\n): Promise<BundleResult> {\n\tconst {\n\t\tpackageName: packageSpecifier,\n\t\texports,\n\t\tadditionalExternals,\n\t\tnoExternal,\n\t\tgzipLevel = 5,\n\t\tregistry,\n\t\tplatform: explicitPlatform,\n\t\ttarget = DEFAULT_TARGET,\n\t} = options;\n\n\t// Parse the package specifier to extract name, version, and subpath.\n\tconst {\n\t\tname: packageName,\n\t\tversion: requestedVersion,\n\t\tsubpath,\n\t} = parsePackageSpecifier(packageSpecifier);\n\n\tconst tmpDir = createTempDir();\n\n\ttry {\n\t\t// Create initial package.json.\n\t\tconst packageJson: {\n\t\t\tname: string;\n\t\t\tversion: string;\n\t\t\ttype: string;\n\t\t\tdependencies: Record<string, string>;\n\t\t} = {\n\t\t\tname: \"bundlecheck-temp\",\n\t\t\tversion: \"1.0.0\",\n\t\t\ttype: \"module\",\n\t\t\tdependencies: {\n\t\t\t\t[packageName]: requestedVersion,\n\t\t\t},\n\t\t};\n\n\t\tfs.writeFileSync(\n\t\t\tpath.join(tmpDir, \"package.json\"),\n\t\t\tJSON.stringify(packageJson, null, 2),\n\t\t);\n\n\t\t// Install the main package (try pnpm first, fallback to npm).\n\t\tconst installCmd = getInstallCommand(registry);\n\t\texecSync(installCmd, {\n\t\t\tcwd: tmpDir,\n\t\t\tstdio: \"pipe\",\n\t\t});\n\n\t\t/**\n\t\t * Get package info (version, dependencies, peer dependencies, exports,\n\t\t * engines).\n\t\t */\n\t\tconst pkgInfo = getPackageInfo(tmpDir, packageName);\n\t\tconst peerDepKeys = Object.keys(pkgInfo.peerDependencies);\n\n\t\t/**\n\t\t * Determine platform: use explicit value if provided, otherwise auto-detect\n\t\t * from engines.\n\t\t */\n\t\tlet platform: \"browser\" | \"node\" = \"browser\";\n\t\tif (explicitPlatform) {\n\t\t\tplatform = explicitPlatform;\n\t\t} else if (pkgInfo.engines?.node && !pkgInfo.engines?.browser) {\n\t\t\t// Package specifies node engine without browser - likely a Node.js package.\n\t\t\tplatform = \"node\";\n\t\t}\n\n\t\t// Collect all dependency names (prod + peer).\n\t\tconst allDependencies = [\n\t\t\t...new Set([...Object.keys(pkgInfo.dependencies), ...peerDepKeys]),\n\t\t].sort();\n\n\t\tif (peerDepKeys.length > 0) {\n\t\t\t// Add peer dependencies to package.json.\n\t\t\tfor (const dep of peerDepKeys) {\n\t\t\t\t// Use the version range from peer dependencies.\n\t\t\t\tpackageJson.dependencies[dep] = pkgInfo.peerDependencies[dep];\n\t\t\t}\n\n\t\t\t// Update package.json and reinstall.\n\t\t\tfs.writeFileSync(\n\t\t\t\tpath.join(tmpDir, \"package.json\"),\n\t\t\t\tJSON.stringify(packageJson, null, 2),\n\t\t\t);\n\n\t\t\texecSync(installCmd, {\n\t\t\t\tcwd: tmpDir,\n\t\t\t\tstdio: \"pipe\",\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Determine if we need to use all subpath exports or find the right\n\t\t * subpath(s).\n\t\t */\n\t\tlet allSubpaths: string[] | undefined;\n\t\tlet resolvedSubpath = subpath;\n\t\tlet exportToSubpath: Map<string, string> | undefined;\n\n\t\tif (!subpath && !pkgInfo.hasMainEntry && pkgInfo.exports) {\n\t\t\tif (exports && exports.length > 0) {\n\t\t\t\t// User specified exports but no subpath - try to find the right subpath(s).\n\t\t\t\tconst mapping = findSubpathsForExports(\n\t\t\t\t\ttmpDir,\n\t\t\t\t\tpackageName,\n\t\t\t\t\tpkgInfo.exports,\n\t\t\t\t\texports,\n\t\t\t\t);\n\n\t\t\t\tif (mapping.singleSubpath) {\n\t\t\t\t\t// All exports from the same subpath.\n\t\t\t\t\tresolvedSubpath = mapping.singleSubpath;\n\t\t\t\t} else if (mapping.exportToSubpath) {\n\t\t\t\t\t// Exports from multiple subpaths.\n\t\t\t\t\texportToSubpath = mapping.exportToSubpath;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If still no subpath resolved and no mapping, bundle all subpaths.\n\t\t\tif (!resolvedSubpath && !exportToSubpath) {\n\t\t\t\tallSubpaths = getSubpathExports(pkgInfo.exports);\n\t\t\t}\n\t\t}\n\n\t\t// Create entry file with appropriate content.\n\t\tconst entryContent = generateEntryContent({\n\t\t\tpackageName,\n\t\t\tsubpath: resolvedSubpath,\n\t\t\texports,\n\t\t\tallSubpaths,\n\t\t\texportToSubpath,\n\t\t});\n\t\tconst entryFile = path.join(tmpDir, \"entry.js\");\n\t\tfs.writeFileSync(entryFile, entryContent);\n\n\t\t/**\n\t\t * Get externals based on package dependencies. Only include react/react-dom\n\t\t * if they're in the package's dependencies or peerDependencies.\n\t\t */\n\t\tlet externals = getExternals(\n\t\t\tpackageName,\n\t\t\tadditionalExternals,\n\t\t\tnoExternal,\n\t\t\tallDependencies,\n\t\t);\n\n\t\t/**\n\t\t * Expand externals to include subpaths for esbuild.\n\t\t * e.g., \"react\" -> [\"react\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"]\n\t\t */\n\t\tlet esbuildExternals = expandExternalsForEsbuild(externals);\n\n\t\t/**\n\t\t * Bundle with esbuild. We use a two-phase approach:\n\t\t * 1. First attempt with logLevel: \"silent\" to suppress errors\n\t\t * 2. If it fails due to unresolved react imports, auto-add react to externals and retry\n\t\t * This handles packages that don't properly declare react as a peer\n\t\t * dependency.\n\t\t */\n\t\tlet result: esbuild.BuildResult<{ write: false; metafile: true }>;\n\t\ttry {\n\t\t\tresult = await esbuild.build({\n\t\t\t\tentryPoints: [entryFile],\n\t\t\t\tbundle: true,\n\t\t\t\twrite: false,\n\t\t\t\tformat: \"esm\",\n\t\t\t\tplatform,\n\t\t\t\ttarget,\n\t\t\t\tminify: true,\n\t\t\t\ttreeShaking: true,\n\t\t\t\texternal: esbuildExternals,\n\t\t\t\tmetafile: true,\n\t\t\t\tlogLevel: \"silent\", // Suppress errors on first attempt (will retry if needed)\n\t\t\t});\n\t\t} catch (error) {\n\t\t\t/**\n\t\t\t * Parse unresolved module errors using esbuild's structured error format.\n\t\t\t * This handles packages that don't properly declare react as a peer\n\t\t\t * dependency.\n\t\t\t */\n\t\t\tconst { hasUnresolvedReact, hasUnresolvedReactDom } =\n\t\t\t\tparseUnresolvedModules(error);\n\n\t\t\tif (!noExternal && (hasUnresolvedReact || hasUnresolvedReactDom)) {\n\t\t\t\t// Auto-add react and/or react-dom to externals and retry.\n\t\t\t\tconst autoExternals: string[] = [];\n\t\t\t\tif (hasUnresolvedReact && !externals.includes(\"react\")) {\n\t\t\t\t\tautoExternals.push(\"react\");\n\t\t\t\t}\n\t\t\t\tif (hasUnresolvedReactDom && !externals.includes(\"react-dom\")) {\n\t\t\t\t\tautoExternals.push(\"react-dom\");\n\t\t\t\t}\n\n\t\t\t\tif (autoExternals.length > 0) {\n\t\t\t\t\texternals = [...externals, ...autoExternals];\n\t\t\t\t\tesbuildExternals = expandExternalsForEsbuild(externals);\n\n\t\t\t\t\tresult = await esbuild.build({\n\t\t\t\t\t\tentryPoints: [entryFile],\n\t\t\t\t\t\tbundle: true,\n\t\t\t\t\t\twrite: false,\n\t\t\t\t\t\tformat: \"esm\",\n\t\t\t\t\t\tplatform,\n\t\t\t\t\t\ttarget,\n\t\t\t\t\t\tminify: true,\n\t\t\t\t\t\ttreeShaking: true,\n\t\t\t\t\t\texternal: esbuildExternals,\n\t\t\t\t\t\tmetafile: true,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\t// Get raw size.\n\t\tconst bundleContent = result.outputFiles[0].contents;\n\t\tconst rawSize = bundleContent.length;\n\n\t\t// Gzip the bundle (only for browser platform - not relevant for Node.js).\n\t\tlet gzipSize: number | null = null;\n\t\tif (platform === \"browser\") {\n\t\t\tconst gzipped = await gzipAsync(Buffer.from(bundleContent), {\n\t\t\t\tlevel: gzipLevel,\n\t\t\t});\n\t\t\tgzipSize = gzipped.length;\n\t\t}\n\n\t\t// Determine the display name.\n\t\tlet displayName = packageName;\n\t\tif (resolvedSubpath) {\n\t\t\tdisplayName = `${packageName}/${resolvedSubpath}`;\n\t\t} else if (exportToSubpath && exportToSubpath.size > 0) {\n\t\t\t// Multiple subpaths - show them all.\n\t\t\tconst uniqueSubpaths = [...new Set(exportToSubpath.values())].sort();\n\t\t\tdisplayName = `${packageName}/{${uniqueSubpaths.join(\", \")}}`;\n\t\t}\n\n\t\t/**\n\t\t * Get named export count from the package's type definitions. Use\n\t\t * runtimeCount to exclude type-only exports (types, interfaces).\n\t\t */\n\t\tconst { runtimeCount: namedExportCount } = getNamedExports(\n\t\t\ttmpDir,\n\t\t\tpackageName,\n\t\t);\n\n\t\treturn {\n\t\t\tpackageName: displayName,\n\t\t\tpackageVersion: pkgInfo.version,\n\t\t\texports: exports || [],\n\t\t\trawSize,\n\t\t\tgzipSize,\n\t\t\tgzipLevel,\n\t\t\texternals,\n\t\t\tdependencies: allDependencies,\n\t\t\tplatform,\n\t\t\tnamedExportCount,\n\t\t};\n\t} finally {\n\t\tcleanupTempDir(tmpDir);\n\t}\n}\n"],"names":["execSync","fs","os","path","promisify","zlib","esbuild","DEFAULT_EXTERNALS","DEFAULT_TARGET","EXTERNAL_SUBPATHS","getNamedExports","gzipAsync","gzip","escapeRegExp","str","replace","parsePackageSpecifier","specifier","workingSpec","version","startsWith","secondAtIndex","indexOf","substring","parts","split","length","name","subpath","slice","join","atIndex","slashIndex","formatBytes","bytes","k","sizes","i","Math","floor","log","Number","parseFloat","toFixed","createTempDir","tmpDir","tmpdir","Date","now","mkdirSync","recursive","cleanupTempDir","rmSync","force","isPnpmAvailable","stdio","usePnpm","validateRegistryUrl","registry","url","URL","Error","protocol","toString","getInstallCommand","registryArg","sanitizedRegistry","generateEntryContent","options","packageName","exports","allSubpaths","exportToSubpath","size","subpathToExports","Map","exportName","sp","existing","get","push","set","lines","allExportNames","exportNames","importPath","names","importNames","imports","map","isEsbuildBuildFailure","error","Array","isArray","errors","parseUnresolvedModules","result","hasUnresolvedReact","hasUnresolvedReactDom","resolveErrorPattern","err","match","exec","text","modulePath","errorMessage","String","matches","matchAll","getExternals","externals","noExternal","packageDependencies","dep","includes","Set","expandExternalsForEsbuild","expanded","ext","subpaths","getPackageInfo","pkgJsonPath","existsSync","pkgJson","JSON","parse","readFileSync","hasMainEntry","Boolean","main","module","dependencies","peerDependencies","engines","getSubpathExports","key","Object","keys","findSubpathsForExports","componentNames","packageDir","subpathKey","subpathValue","entries","filePath","types","import","fullPath","content","has","escapedName","patterns","RegExp","some","pattern","test","values","singleSubpath","checkBundleSize","packageSpecifier","additionalExternals","gzipLevel","platform","explicitPlatform","target","requestedVersion","packageJson","type","writeFileSync","stringify","installCmd","cwd","pkgInfo","peerDepKeys","node","browser","allDependencies","sort","resolvedSubpath","mapping","entryContent","entryFile","esbuildExternals","build","entryPoints","bundle","write","format","minify","treeShaking","external","metafile","logLevel","autoExternals","bundleContent","outputFiles","contents","rawSize","gzipSize","gzipped","Buffer","from","level","displayName","uniqueSubpaths","runtimeCount","namedExportCount","packageVersion"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,qBAAqB;AAC9C,OAAOC,QAAQ,UAAU;AACzB,OAAOC,QAAQ,UAAU;AACzB,OAAOC,UAAU,YAAY;AAC7B,SAASC,SAAS,QAAQ,YAAY;AACtC,OAAOC,UAAU,YAAY;AAC7B,YAAYC,aAAa,UAAU;AACnC,SACCC,iBAAiB,EACjBC,cAAc,EACdC,iBAAiB,QACX,gBAAgB;AACvB,SAASC,eAAe,QAAQ,eAAe;AAE/C,MAAMC,YAAYP,UAAUC,KAAKO,IAAI;AAErC;;CAEC,GACD,SAASC,aAAaC,GAAW;IAChC,OAAOA,IAAIC,OAAO,CAAC,uBAAuB;AAC3C;AAQA;;;;;;;CAOC,GACD,OAAO,SAASC,sBAAsBC,SAAiB;IACtD,IAAIC,cAAcD;IAClB,IAAIE,UAAU;IAEd,0CAA0C;IAC1C,IAAID,YAAYE,UAAU,CAAC,MAAM;QAChC,kDAAkD;QAClD,MAAMC,gBAAgBH,YAAYI,OAAO,CAAC,KAAK;QAC/C,IAAID,kBAAkB,CAAC,GAAG;YACzBF,UAAUD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.ts"],"sourcesContent":["import { execSync } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { promisify } from \"node:util\";\nimport zlib from \"node:zlib\";\nimport * as esbuild from \"esbuild\";\nimport {\n\tBROWSER_FRAMEWORK_DEPS,\n\tDEFAULT_EXTERNALS,\n\tDEFAULT_TARGET,\n\tEXTERNAL_SUBPATHS,\n} from \"./defaults.js\";\nimport { getNamedExports } from \"./exports.js\";\n\nconst gzipAsync = promisify(zlib.gzip);\n\n/**\n * Escape special regex characters in a string.\n */\nfunction escapeRegExp(str: string): string {\n\treturn str.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nexport type ParsedPackage = {\n\tname: string;\n\tversion: string;\n\tsubpath?: string;\n};\n\n/**\n * Parse a package specifier to extract name, version, and subpath.\n * Handles:\n * - @scope/package@1.0.0\n * - @scope/package/subpath@1.0.0\n * - @scope/package/subpath\n * - package/subpath@1.0.0\n */\nexport function parsePackageSpecifier(specifier: string): ParsedPackage {\n\tlet workingSpec = specifier;\n\tlet version = \"latest\";\n\n\t// Handle scoped packages (@scope/name...)\n\tif (workingSpec.startsWith(\"@\")) {\n\t\t// Find the second @ which would separate version.\n\t\tconst secondAtIndex = workingSpec.indexOf(\"@\", 1);\n\t\tif (secondAtIndex !== -1) {\n\t\t\tversion = workingSpec.substring(secondAtIndex + 1);\n\t\t\tworkingSpec = workingSpec.substring(0, secondAtIndex);\n\t\t}\n\n\t\t/**\n\t\t * Now workingSpec is like @scope/name or @scope/name/subpath Split by / and\n\t\t * check if there are more than 2 parts.\n\t\t */\n\t\tconst parts = workingSpec.split(\"/\");\n\t\tif (parts.length > 2) {\n\t\t\t// Has subpath: @scope/name/subpath/more.\n\t\t\tconst name = `${parts[0]}/${parts[1]}`;\n\t\t\tconst subpath = parts.slice(2).join(\"/\");\n\t\t\treturn { name, version, subpath };\n\t\t}\n\t\t// No subpath: @scope/name.\n\t\treturn { name: workingSpec, version };\n\t}\n\n\t// Handle non-scoped packages (name@version or name/subpath@version).\n\tconst atIndex = workingSpec.indexOf(\"@\");\n\tif (atIndex !== -1) {\n\t\tversion = workingSpec.substring(atIndex + 1);\n\t\tworkingSpec = workingSpec.substring(0, atIndex);\n\t}\n\n\t// Check for subpath in non-scoped packages.\n\tconst slashIndex = workingSpec.indexOf(\"/\");\n\tif (slashIndex !== -1) {\n\t\tconst name = workingSpec.substring(0, slashIndex);\n\t\tconst subpath = workingSpec.substring(slashIndex + 1);\n\t\treturn { name, version, subpath };\n\t}\n\n\treturn { name: workingSpec, version };\n}\n\nexport type BundleOptions = {\n\tpackageName: string;\n\texports?: string[];\n\tadditionalExternals?: string[];\n\tnoExternal?: boolean;\n\tgzipLevel?: number;\n\tregistry?: string;\n\t/**\n\t * Target platform. If undefined, auto-detects from package.json engines.\n\t */\n\tplatform?: \"browser\" | \"node\";\n\t/**\n\t * esbuild target (e.g., \"es2022\", \"es2020\"). Defaults to \"es2022\".\n\t */\n\ttarget?: string;\n};\n\nexport type BundleResult = {\n\tpackageName: string;\n\tpackageVersion: string;\n\texports: string[];\n\trawSize: number;\n\t/**\n\t * Gzip size in bytes, or null for node platform (gzip not applicable).\n\t */\n\tgzipSize: number | null;\n\tgzipLevel: number;\n\texternals: string[];\n\tdependencies: string[];\n\tplatform: \"browser\" | \"node\";\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 * Format bytes to human-readable string.\n */\nexport function formatBytes(bytes: number): string {\n\tif (bytes === 0) {\n\t\treturn \"0 B\";\n\t}\n\tconst k = 1024;\n\tconst sizes = [\"B\", \"kB\", \"MB\", \"GB\"];\n\tconst i = Math.floor(Math.log(bytes) / Math.log(k));\n\treturn `${Number.parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`;\n}\n\n/**\n * Create a temporary directory for bundling.\n */\nfunction createTempDir(): string {\n\tconst tmpDir = path.join(os.tmpdir(), `bundlecheck-${Date.now()}`);\n\tfs.mkdirSync(tmpDir, { recursive: true });\n\treturn tmpDir;\n}\n\n/**\n * Clean up temporary directory.\n */\nfunction cleanupTempDir(tmpDir: string): void {\n\ttry {\n\t\tfs.rmSync(tmpDir, { recursive: true, force: true });\n\t} catch {\n\t\t// Ignore cleanup errors.\n\t}\n}\n\n/**\n * Check if pnpm is available.\n */\nfunction isPnpmAvailable(): boolean {\n\ttry {\n\t\texecSync(\"pnpm --version\", { stdio: \"pipe\" });\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n// Cache the result of pnpm availability check.\nlet usePnpm: boolean | null = null;\n\n/**\n * Validate and sanitize a registry URL to prevent command injection.\n * @param registry - The registry URL to validate\n * @returns The sanitized URL or undefined if invalid\n * @throws Error if the URL is invalid or contains potentially malicious characters\n */\nfunction validateRegistryUrl(registry: string): string {\n\t// Parse as URL to validate format.\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(registry);\n\t} catch {\n\t\tthrow new Error(\n\t\t\t`Invalid registry URL: ${registry}. Must be a valid URL (e.g., https://registry.example.com)`,\n\t\t);\n\t}\n\n\t// Only allow http and https protocols.\n\tif (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n\t\tthrow new Error(\n\t\t\t`Invalid registry URL protocol: ${url.protocol}. Only http: and https: are allowed`,\n\t\t);\n\t}\n\n\t// Return the sanitized URL (URL constructor normalizes it).\n\treturn url.toString();\n}\n\n/**\n * Get the install command (pnpm preferred, npm fallback).\n * @param registry - Optional custom npm registry URL\n */\nfunction getInstallCommand(registry?: string): string {\n\tif (usePnpm === null) {\n\t\tusePnpm = isPnpmAvailable();\n\t}\n\n\tlet registryArg = \"\";\n\tif (registry) {\n\t\t// Validate and sanitize the registry URL to prevent command injection.\n\t\tconst sanitizedRegistry = validateRegistryUrl(registry);\n\t\t// Quote the URL to handle any special characters safely.\n\t\tregistryArg = ` --registry \"${sanitizedRegistry}\"`;\n\t}\n\n\tif (usePnpm) {\n\t\treturn `pnpm install --ignore-scripts --no-frozen-lockfile${registryArg}`;\n\t}\n\treturn `npm install --legacy-peer-deps --ignore-scripts${registryArg}`;\n}\n\nexport type EntryContentOptions = {\n\tpackageName: string;\n\tsubpath?: string;\n\texports?: string[];\n\tallSubpaths?: string[];\n\texportToSubpath?: Map<string, string>;\n};\n\n/**\n * Generate the entry file content based on package, subpath, and exports.\n */\nfunction generateEntryContent(options: EntryContentOptions): string {\n\tconst { packageName, subpath, exports, allSubpaths, exportToSubpath } =\n\t\toptions;\n\n\t// If we have exports mapped to different subpaths.\n\tif (exportToSubpath && exportToSubpath.size > 0) {\n\t\t// Group exports by subpath.\n\t\tconst subpathToExports = new Map<string, string[]>();\n\t\tfor (const [exportName, sp] of exportToSubpath) {\n\t\t\tconst existing = subpathToExports.get(sp) || [];\n\t\t\texisting.push(exportName);\n\t\t\tsubpathToExports.set(sp, existing);\n\t\t}\n\n\t\t// Generate imports for each subpath.\n\t\tconst lines: string[] = [];\n\t\tconst allExportNames: string[] = [];\n\n\t\tfor (const [sp, exportNames] of subpathToExports) {\n\t\t\tconst importPath = `${packageName}/${sp}`;\n\t\t\tconst names = exportNames.join(\", \");\n\t\t\tlines.push(`import { ${names} } from \"${importPath}\";`);\n\t\t\tallExportNames.push(...exportNames);\n\t\t}\n\n\t\tlines.push(`export { ${allExportNames.join(\", \")} };`);\n\t\treturn lines.join(\"\\n\") + \"\\n\";\n\t}\n\n\t// If we have specific exports to import.\n\tif (exports && exports.length > 0) {\n\t\t// Determine the import path.\n\t\tconst importPath = subpath ? `${packageName}/${subpath}` : packageName;\n\t\tconst importNames = exports.join(\", \");\n\t\treturn `import { ${importNames} } from \"${importPath}\";\\nexport { ${importNames} };\\n`;\n\t}\n\n\t// If we have a specific subpath (but no specific exports).\n\tif (subpath) {\n\t\tconst importPath = `${packageName}/${subpath}`;\n\t\treturn `import * as pkg from \"${importPath}\";\\nexport default pkg;\\n`;\n\t}\n\n\t// If package has subpath exports only (no main entry), import all subpaths.\n\tif (allSubpaths && allSubpaths.length > 0) {\n\t\tconst imports = allSubpaths\n\t\t\t.map(\n\t\t\t\t(sp, i) =>\n\t\t\t\t\t`import * as sub${i} from \"${packageName}/${sp}\";\\nexport { sub${i} };`,\n\t\t\t)\n\t\t\t.join(\"\\n\");\n\t\treturn imports + \"\\n\";\n\t}\n\n\t// Default: import everything from main entry.\n\treturn `import * as pkg from \"${packageName}\";\\nexport default pkg;\\n`;\n}\n\n/**\n * Check if an error is an esbuild BuildFailure. BuildFailure has an `errors`\n * array with structured error objects.\n */\nfunction isEsbuildBuildFailure(\n\terror: unknown,\n): error is { errors: Array<{ text: string; location?: unknown }> } {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"errors\" in error &&\n\t\tArray.isArray((error as { errors: unknown }).errors)\n\t);\n}\n\n/**\n * Extract unresolved module paths from an esbuild BuildFailure error. Returns\n * an object indicating which react-related modules failed to resolve.\n *\n * Uses esbuild's structured error objects (errors array) for reliable parsing.\n * Falls back to string matching if the error format is unexpected.\n *\n * Tested against esbuild 0.27.x error format.\n *\n */\nfunction parseUnresolvedModules(error: unknown): {\n\thasUnresolvedReact: boolean;\n\thasUnresolvedReactDom: boolean;\n} {\n\tconst result = { hasUnresolvedReact: false, hasUnresolvedReactDom: false };\n\n\t/**\n\t * Pattern to extract module path from \"Could not resolve X\" errors. Matches:\n\t * Could not resolve \"module-name\" or Could not resolve 'module-name'.\n\t */\n\tconst resolveErrorPattern = /Could not resolve [\"']([^\"']+)[\"']/;\n\n\tif (isEsbuildBuildFailure(error)) {\n\t\t// Use structured error objects from esbuild BuildFailure.\n\t\tfor (const err of error.errors) {\n\t\t\tconst match = resolveErrorPattern.exec(err.text);\n\t\t\tif (match) {\n\t\t\t\tconst modulePath = match[1];\n\t\t\t\t// Check if it's a react or react-dom import (including subpaths).\n\t\t\t\tif (modulePath === \"react\" || modulePath.startsWith(\"react/\")) {\n\t\t\t\t\tresult.hasUnresolvedReact = true;\n\t\t\t\t}\n\t\t\t\tif (modulePath === \"react-dom\" || modulePath.startsWith(\"react-dom/\")) {\n\t\t\t\t\tresult.hasUnresolvedReactDom = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\t// Fallback: parse error message string (less reliable).\n\t\tconst errorMessage = String(error);\n\t\tconst matches = errorMessage.matchAll(\n\t\t\t/Could not resolve [\"']([^\"']+)[\"']/g,\n\t\t);\n\t\tfor (const match of matches) {\n\t\t\tconst modulePath = match[1];\n\t\t\tif (modulePath === \"react\" || modulePath.startsWith(\"react/\")) {\n\t\t\t\tresult.hasUnresolvedReact = true;\n\t\t\t}\n\t\t\tif (modulePath === \"react-dom\" || modulePath.startsWith(\"react-dom/\")) {\n\t\t\t\tresult.hasUnresolvedReactDom = true;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Get externals list based on options and package dependencies. react and\n * react-dom are only marked as external if they are declared in the package's\n * dependencies or peerDependencies.\n *\n * Returns the base package names (e.g., [\"react\", \"react-dom\"]) for display\n * purposes.\n *\n */\nexport function getExternals(\n\tpackageName: string,\n\texternals?: string[],\n\tnoExternal?: boolean,\n\tpackageDependencies?: string[],\n): string[] {\n\tif (noExternal) {\n\t\treturn [];\n\t}\n\n\t/**\n\t * Start with empty result - we'll only add react/react-dom if they're in\n\t * package deps.\n\t */\n\tlet result: string[] = [];\n\n\t/**\n\t * Only include react/react-dom if they're in the package's dependencies or\n\t * peerDependencies.\n\t */\n\tif (packageDependencies && packageDependencies.length > 0) {\n\t\tfor (const dep of DEFAULT_EXTERNALS) {\n\t\t\t// Don't mark as external if we're checking the package itself.\n\t\t\tif (dep === packageName) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (packageDependencies.includes(dep)) {\n\t\t\t\tresult.push(dep);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Add any additional externals.\n\tif (externals && externals.length > 0) {\n\t\tresult = [...new Set([...result, ...externals])];\n\t}\n\n\treturn result;\n}\n\n/**\n * Expand externals to include subpaths for esbuild. For example, \"react\"\n * expands to [\"react\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"]. This is\n * needed because esbuild doesn't automatically externalize subpaths.\n */\nexport function expandExternalsForEsbuild(externals: string[]): string[] {\n\tconst expanded: string[] = [];\n\n\tfor (const ext of externals) {\n\t\texpanded.push(ext);\n\t\t// Add subpaths if this is a known package with subpath exports.\n\t\tconst subpaths = EXTERNAL_SUBPATHS[ext];\n\t\tif (subpaths) {\n\t\t\texpanded.push(...subpaths);\n\t\t}\n\t}\n\n\treturn [...new Set(expanded)];\n}\n\nexport type PackageExports = Record<\n\tstring,\n\tstring | { import?: string; types?: string }\n>;\n\nexport type PackageInfo = {\n\tversion: string;\n\tdependencies: Record<string, string>;\n\tpeerDependencies: Record<string, string>;\n\texports: PackageExports | null;\n\thasMainEntry: boolean;\n\tengines: Record<string, string> | null;\n};\n\n/**\n * Get version, dependencies, peer dependencies, and exports from an installed\n * package.\n */\nfunction getPackageInfo(tmpDir: string, packageName: string): PackageInfo {\n\ttry {\n\t\t// Handle scoped packages - the package name in node_modules.\n\t\tconst pkgJsonPath = path.join(\n\t\t\ttmpDir,\n\t\t\t\"node_modules\",\n\t\t\tpackageName,\n\t\t\t\"package.json\",\n\t\t);\n\t\tif (fs.existsSync(pkgJsonPath)) {\n\t\t\tconst pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf-8\"));\n\n\t\t\t// Check if package has a main entry point.\n\t\t\tconst hasMainEntry = Boolean(\n\t\t\t\tpkgJson.main ||\n\t\t\t\t\tpkgJson.module ||\n\t\t\t\t\tpkgJson.exports?.[\".\"] ||\n\t\t\t\t\tpkgJson.exports?.[\"./index\"] ||\n\t\t\t\t\t(!pkgJson.exports && !pkgJson.main && !pkgJson.module),\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tversion: pkgJson.version || \"unknown\",\n\t\t\t\tdependencies: pkgJson.dependencies || {},\n\t\t\t\tpeerDependencies: pkgJson.peerDependencies || {},\n\t\t\t\texports: pkgJson.exports || null,\n\t\t\t\thasMainEntry,\n\t\t\t\tengines: pkgJson.engines || null,\n\t\t\t};\n\t\t}\n\t} catch {\n\t\t// Ignore errors reading package info.\n\t}\n\treturn {\n\t\tversion: \"unknown\",\n\t\tdependencies: {},\n\t\tpeerDependencies: {},\n\t\texports: null,\n\t\thasMainEntry: true,\n\t\tengines: null,\n\t};\n}\n\n/**\n * Extract subpath export names from package exports field Returns array of\n * subpaths like [\"header\", \"body\", \"datagrid\"].\n */\nfunction getSubpathExports(exports: PackageExports | null): string[] {\n\tif (!exports) {\n\t\treturn [];\n\t}\n\n\tconst subpaths: string[] = [];\n\tfor (const key of Object.keys(exports)) {\n\t\t// Skip the main entry point and package.json.\n\t\tif (key === \".\" || key === \"./package.json\") {\n\t\t\tcontinue;\n\t\t}\n\t\t// Remove leading \"./\" to get subpath name.\n\t\tif (key.startsWith(\"./\")) {\n\t\t\tsubpaths.push(key.substring(2));\n\t\t}\n\t}\n\treturn subpaths;\n}\n\n/**\n * Result of finding subpaths for exports.\n */\ntype SubpathMapping = {\n\t// Single subpath if all exports are from the same subpath.\n\tsingleSubpath?: string;\n\t// Map of export name to subpath for multiple subpaths.\n\texportToSubpath?: Map<string, string>;\n};\n\n/**\n * Find which subpath(s) export the given component names Reads type definition\n * files or JS files to find the exports.\n */\nfunction findSubpathsForExports(\n\ttmpDir: string,\n\tpackageName: string,\n\texports: PackageExports,\n\tcomponentNames: string[],\n): SubpathMapping {\n\tconst packageDir = path.join(tmpDir, \"node_modules\", packageName);\n\tconst exportToSubpath = new Map<string, string>();\n\n\tfor (const [subpathKey, subpathValue] of Object.entries(exports)) {\n\t\t// Skip main entry and package.json.\n\t\tif (subpathKey === \".\" || subpathKey === \"./package.json\") {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Get the types or import path.\n\t\tlet filePath: string | undefined;\n\t\tif (typeof subpathValue === \"object\" && subpathValue !== null) {\n\t\t\t// Prefer types file for more accurate export detection.\n\t\t\tfilePath = subpathValue.types || subpathValue.import;\n\t\t} else if (typeof subpathValue === \"string\") {\n\t\t\tfilePath = subpathValue;\n\t\t}\n\n\t\tif (!filePath) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Resolve the file path.\n\t\tconst fullPath = path.join(packageDir, filePath);\n\n\t\ttry {\n\t\t\tif (fs.existsSync(fullPath)) {\n\t\t\t\tconst content = fs.readFileSync(fullPath, \"utf-8\");\n\t\t\t\tconst subpath = subpathKey.startsWith(\"./\")\n\t\t\t\t\t? subpathKey.substring(2)\n\t\t\t\t\t: subpathKey;\n\n\t\t\t\t// Check each component name.\n\t\t\t\tfor (const name of componentNames) {\n\t\t\t\t\t// Skip if already found.\n\t\t\t\t\tif (exportToSubpath.has(name)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Escape regex special characters in the name to prevent injection.\n\t\t\t\t\tconst escapedName = escapeRegExp(name);\n\n\t\t\t\t\t// Look for various export patterns.\n\t\t\t\t\tconst patterns = [\n\t\t\t\t\t\tnew RegExp(`export\\\\s*\\\\{[^}]*\\\\b${escapedName}\\\\b[^}]*\\\\}`, \"m\"),\n\t\t\t\t\t\tnew RegExp(\n\t\t\t\t\t\t\t`export\\\\s+declare\\\\s+(?:const|function|class)\\\\s+${escapedName}\\\\b`,\n\t\t\t\t\t\t\t\"m\",\n\t\t\t\t\t\t),\n\t\t\t\t\t\tnew RegExp(\n\t\t\t\t\t\t\t`export\\\\s+(?:const|function|class)\\\\s+${escapedName}\\\\b`,\n\t\t\t\t\t\t\t\"m\",\n\t\t\t\t\t\t),\n\t\t\t\t\t];\n\n\t\t\t\t\tif (patterns.some((pattern) => pattern.test(content))) {\n\t\t\t\t\t\texportToSubpath.set(name, subpath);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore read errors, continue to next subpath.\n\t\t}\n\t}\n\n\t// Check if all exports were found.\n\tif (exportToSubpath.size !== componentNames.length) {\n\t\treturn {}; // Not all exports found\n\t}\n\n\t// Check if all exports are from the same subpath.\n\tconst subpaths = new Set(exportToSubpath.values());\n\tif (subpaths.size === 1) {\n\t\treturn { singleSubpath: [...subpaths][0] };\n\t}\n\n\t// Multiple subpaths needed.\n\treturn { exportToSubpath };\n}\n\n/**\n * Check the bundle size of an npm package.\n */\nexport async function checkBundleSize(\n\toptions: BundleOptions,\n): Promise<BundleResult> {\n\tconst {\n\t\tpackageName: packageSpecifier,\n\t\texports,\n\t\tadditionalExternals,\n\t\tnoExternal,\n\t\tgzipLevel = 5,\n\t\tregistry,\n\t\tplatform: explicitPlatform,\n\t\ttarget = DEFAULT_TARGET,\n\t} = options;\n\n\t// Parse the package specifier to extract name, version, and subpath.\n\tconst {\n\t\tname: packageName,\n\t\tversion: requestedVersion,\n\t\tsubpath,\n\t} = parsePackageSpecifier(packageSpecifier);\n\n\tconst tmpDir = createTempDir();\n\n\ttry {\n\t\t// Create initial package.json.\n\t\tconst packageJson: {\n\t\t\tname: string;\n\t\t\tversion: string;\n\t\t\ttype: string;\n\t\t\tdependencies: Record<string, string>;\n\t\t} = {\n\t\t\tname: \"bundlecheck-temp\",\n\t\t\tversion: \"1.0.0\",\n\t\t\ttype: \"module\",\n\t\t\tdependencies: {\n\t\t\t\t[packageName]: requestedVersion,\n\t\t\t},\n\t\t};\n\n\t\tfs.writeFileSync(\n\t\t\tpath.join(tmpDir, \"package.json\"),\n\t\t\tJSON.stringify(packageJson, null, 2),\n\t\t);\n\n\t\t// Install the main package (try pnpm first, fallback to npm).\n\t\tconst installCmd = getInstallCommand(registry);\n\t\texecSync(installCmd, {\n\t\t\tcwd: tmpDir,\n\t\t\tstdio: \"pipe\",\n\t\t});\n\n\t\t/**\n\t\t * Get package info (version, dependencies, peer dependencies, exports,\n\t\t * engines).\n\t\t */\n\t\tconst pkgInfo = getPackageInfo(tmpDir, packageName);\n\t\tconst peerDepKeys = Object.keys(pkgInfo.peerDependencies);\n\n\t\t/**\n\t\t * Determine platform: use explicit value if provided, otherwise auto-detect\n\t\t * from engines.\n\t\t */\n\t\tlet platform: \"browser\" | \"node\" = \"browser\";\n\t\tif (explicitPlatform) {\n\t\t\tplatform = explicitPlatform;\n\t\t} else if (pkgInfo.engines?.node && !pkgInfo.engines?.browser) {\n\t\t\t/**\n\t\t\t * Package specifies node engine without browser - potentially a Node.js\n\t\t\t * package. However, many browser packages also specify engines.node for\n\t\t\t * build tooling or SSR compatibility (e.g., @clerk/clerk-react). Check\n\t\t\t * if the package has browser-framework dependencies which indicate it's\n\t\t\t * a browser package despite having engines.node.\n\t\t\t */\n\t\t\tconst allDepNames = [\n\t\t\t\t...Object.keys(pkgInfo.dependencies),\n\t\t\t\t...Object.keys(pkgInfo.peerDependencies),\n\t\t\t];\n\t\t\tconst hasBrowserFrameworkDep = allDepNames.some((dep) =>\n\t\t\t\tBROWSER_FRAMEWORK_DEPS.includes(dep),\n\t\t\t);\n\t\t\tif (!hasBrowserFrameworkDep) {\n\t\t\t\tplatform = \"node\";\n\t\t\t}\n\t\t}\n\n\t\t// Collect all dependency names (prod + peer).\n\t\tconst allDependencies = [\n\t\t\t...new Set([...Object.keys(pkgInfo.dependencies), ...peerDepKeys]),\n\t\t].sort();\n\n\t\tif (peerDepKeys.length > 0) {\n\t\t\t// Add peer dependencies to package.json.\n\t\t\tfor (const dep of peerDepKeys) {\n\t\t\t\t// Use the version range from peer dependencies.\n\t\t\t\tpackageJson.dependencies[dep] = pkgInfo.peerDependencies[dep];\n\t\t\t}\n\n\t\t\t// Update package.json and reinstall.\n\t\t\tfs.writeFileSync(\n\t\t\t\tpath.join(tmpDir, \"package.json\"),\n\t\t\t\tJSON.stringify(packageJson, null, 2),\n\t\t\t);\n\n\t\t\texecSync(installCmd, {\n\t\t\t\tcwd: tmpDir,\n\t\t\t\tstdio: \"pipe\",\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Determine if we need to use all subpath exports or find the right\n\t\t * subpath(s).\n\t\t */\n\t\tlet allSubpaths: string[] | undefined;\n\t\tlet resolvedSubpath = subpath;\n\t\tlet exportToSubpath: Map<string, string> | undefined;\n\n\t\tif (!subpath && !pkgInfo.hasMainEntry && pkgInfo.exports) {\n\t\t\tif (exports && exports.length > 0) {\n\t\t\t\t// User specified exports but no subpath - try to find the right subpath(s).\n\t\t\t\tconst mapping = findSubpathsForExports(\n\t\t\t\t\ttmpDir,\n\t\t\t\t\tpackageName,\n\t\t\t\t\tpkgInfo.exports,\n\t\t\t\t\texports,\n\t\t\t\t);\n\n\t\t\t\tif (mapping.singleSubpath) {\n\t\t\t\t\t// All exports from the same subpath.\n\t\t\t\t\tresolvedSubpath = mapping.singleSubpath;\n\t\t\t\t} else if (mapping.exportToSubpath) {\n\t\t\t\t\t// Exports from multiple subpaths.\n\t\t\t\t\texportToSubpath = mapping.exportToSubpath;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If still no subpath resolved and no mapping, bundle all subpaths.\n\t\t\tif (!resolvedSubpath && !exportToSubpath) {\n\t\t\t\tallSubpaths = getSubpathExports(pkgInfo.exports);\n\t\t\t}\n\t\t}\n\n\t\t// Create entry file with appropriate content.\n\t\tconst entryContent = generateEntryContent({\n\t\t\tpackageName,\n\t\t\tsubpath: resolvedSubpath,\n\t\t\texports,\n\t\t\tallSubpaths,\n\t\t\texportToSubpath,\n\t\t});\n\t\tconst entryFile = path.join(tmpDir, \"entry.js\");\n\t\tfs.writeFileSync(entryFile, entryContent);\n\n\t\t/**\n\t\t * Get externals based on package dependencies. Only include react/react-dom\n\t\t * if they're in the package's dependencies or peerDependencies.\n\t\t */\n\t\tlet externals = getExternals(\n\t\t\tpackageName,\n\t\t\tadditionalExternals,\n\t\t\tnoExternal,\n\t\t\tallDependencies,\n\t\t);\n\n\t\t/**\n\t\t * Expand externals to include subpaths for esbuild.\n\t\t * e.g., \"react\" -> [\"react\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"]\n\t\t */\n\t\tlet esbuildExternals = expandExternalsForEsbuild(externals);\n\n\t\t/**\n\t\t * Bundle with esbuild. We use a two-phase approach:\n\t\t * 1. First attempt with logLevel: \"silent\" to suppress errors\n\t\t * 2. If it fails due to unresolved react imports, auto-add react to externals and retry\n\t\t * This handles packages that don't properly declare react as a peer\n\t\t * dependency.\n\t\t */\n\t\tlet result: esbuild.BuildResult<{ write: false; metafile: true }>;\n\t\ttry {\n\t\t\tresult = await esbuild.build({\n\t\t\t\tentryPoints: [entryFile],\n\t\t\t\tbundle: true,\n\t\t\t\twrite: false,\n\t\t\t\tformat: \"esm\",\n\t\t\t\tplatform,\n\t\t\t\ttarget,\n\t\t\t\tminify: true,\n\t\t\t\ttreeShaking: true,\n\t\t\t\texternal: esbuildExternals,\n\t\t\t\tmetafile: true,\n\t\t\t\tlogLevel: \"silent\", // Suppress errors on first attempt (will retry if needed)\n\t\t\t});\n\t\t} catch (error) {\n\t\t\t/**\n\t\t\t * Parse unresolved module errors using esbuild's structured error format.\n\t\t\t * This handles packages that don't properly declare react as a peer\n\t\t\t * dependency.\n\t\t\t */\n\t\t\tconst { hasUnresolvedReact, hasUnresolvedReactDom } =\n\t\t\t\tparseUnresolvedModules(error);\n\n\t\t\tif (!noExternal && (hasUnresolvedReact || hasUnresolvedReactDom)) {\n\t\t\t\t// Auto-add react and/or react-dom to externals and retry.\n\t\t\t\tconst autoExternals: string[] = [];\n\t\t\t\tif (hasUnresolvedReact && !externals.includes(\"react\")) {\n\t\t\t\t\tautoExternals.push(\"react\");\n\t\t\t\t}\n\t\t\t\tif (hasUnresolvedReactDom && !externals.includes(\"react-dom\")) {\n\t\t\t\t\tautoExternals.push(\"react-dom\");\n\t\t\t\t}\n\n\t\t\t\tif (autoExternals.length > 0) {\n\t\t\t\t\texternals = [...externals, ...autoExternals];\n\t\t\t\t\tesbuildExternals = expandExternalsForEsbuild(externals);\n\n\t\t\t\t\tresult = await esbuild.build({\n\t\t\t\t\t\tentryPoints: [entryFile],\n\t\t\t\t\t\tbundle: true,\n\t\t\t\t\t\twrite: false,\n\t\t\t\t\t\tformat: \"esm\",\n\t\t\t\t\t\tplatform,\n\t\t\t\t\t\ttarget,\n\t\t\t\t\t\tminify: true,\n\t\t\t\t\t\ttreeShaking: true,\n\t\t\t\t\t\texternal: esbuildExternals,\n\t\t\t\t\t\tmetafile: true,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\t// Get raw size.\n\t\tconst bundleContent = result.outputFiles[0].contents;\n\t\tconst rawSize = bundleContent.length;\n\n\t\t// Gzip the bundle (only for browser platform - not relevant for Node.js).\n\t\tlet gzipSize: number | null = null;\n\t\tif (platform === \"browser\") {\n\t\t\tconst gzipped = await gzipAsync(Buffer.from(bundleContent), {\n\t\t\t\tlevel: gzipLevel,\n\t\t\t});\n\t\t\tgzipSize = gzipped.length;\n\t\t}\n\n\t\t// Determine the display name.\n\t\tlet displayName = packageName;\n\t\tif (resolvedSubpath) {\n\t\t\tdisplayName = `${packageName}/${resolvedSubpath}`;\n\t\t} else if (exportToSubpath && exportToSubpath.size > 0) {\n\t\t\t// Multiple subpaths - show them all.\n\t\t\tconst uniqueSubpaths = [...new Set(exportToSubpath.values())].sort();\n\t\t\tdisplayName = `${packageName}/{${uniqueSubpaths.join(\", \")}}`;\n\t\t}\n\n\t\t/**\n\t\t * Get named export count from the package's type definitions. Use\n\t\t * runtimeCount to exclude type-only exports (types, interfaces).\n\t\t */\n\t\tconst { runtimeCount: namedExportCount } = getNamedExports(\n\t\t\ttmpDir,\n\t\t\tpackageName,\n\t\t);\n\n\t\treturn {\n\t\t\tpackageName: displayName,\n\t\t\tpackageVersion: pkgInfo.version,\n\t\t\texports: exports || [],\n\t\t\trawSize,\n\t\t\tgzipSize,\n\t\t\tgzipLevel,\n\t\t\texternals,\n\t\t\tdependencies: allDependencies,\n\t\t\tplatform,\n\t\t\tnamedExportCount,\n\t\t};\n\t} finally {\n\t\tcleanupTempDir(tmpDir);\n\t}\n}\n"],"names":["execSync","fs","os","path","promisify","zlib","esbuild","BROWSER_FRAMEWORK_DEPS","DEFAULT_EXTERNALS","DEFAULT_TARGET","EXTERNAL_SUBPATHS","getNamedExports","gzipAsync","gzip","escapeRegExp","str","replace","parsePackageSpecifier","specifier","workingSpec","version","startsWith","secondAtIndex","indexOf","substring","parts","split","length","name","subpath","slice","join","atIndex","slashIndex","formatBytes","bytes","k","sizes","i","Math","floor","log","Number","parseFloat","toFixed","createTempDir","tmpDir","tmpdir","Date","now","mkdirSync","recursive","cleanupTempDir","rmSync","force","isPnpmAvailable","stdio","usePnpm","validateRegistryUrl","registry","url","URL","Error","protocol","toString","getInstallCommand","registryArg","sanitizedRegistry","generateEntryContent","options","packageName","exports","allSubpaths","exportToSubpath","size","subpathToExports","Map","exportName","sp","existing","get","push","set","lines","allExportNames","exportNames","importPath","names","importNames","imports","map","isEsbuildBuildFailure","error","Array","isArray","errors","parseUnresolvedModules","result","hasUnresolvedReact","hasUnresolvedReactDom","resolveErrorPattern","err","match","exec","text","modulePath","errorMessage","String","matches","matchAll","getExternals","externals","noExternal","packageDependencies","dep","includes","Set","expandExternalsForEsbuild","expanded","ext","subpaths","getPackageInfo","pkgJsonPath","existsSync","pkgJson","JSON","parse","readFileSync","hasMainEntry","Boolean","main","module","dependencies","peerDependencies","engines","getSubpathExports","key","Object","keys","findSubpathsForExports","componentNames","packageDir","subpathKey","subpathValue","entries","filePath","types","import","fullPath","content","has","escapedName","patterns","RegExp","some","pattern","test","values","singleSubpath","checkBundleSize","packageSpecifier","additionalExternals","gzipLevel","platform","explicitPlatform","target","requestedVersion","packageJson","type","writeFileSync","stringify","installCmd","cwd","pkgInfo","peerDepKeys","node","browser","allDepNames","hasBrowserFrameworkDep","allDependencies","sort","resolvedSubpath","mapping","entryContent","entryFile","esbuildExternals","build","entryPoints","bundle","write","format","minify","treeShaking","external","metafile","logLevel","autoExternals","bundleContent","outputFiles","contents","rawSize","gzipSize","gzipped","Buffer","from","level","displayName","uniqueSubpaths","runtimeCount","namedExportCount","packageVersion"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,qBAAqB;AAC9C,OAAOC,QAAQ,UAAU;AACzB,OAAOC,QAAQ,UAAU;AACzB,OAAOC,UAAU,YAAY;AAC7B,SAASC,SAAS,QAAQ,YAAY;AACtC,OAAOC,UAAU,YAAY;AAC7B,YAAYC,aAAa,UAAU;AACnC,SACCC,sBAAsB,EACtBC,iBAAiB,EACjBC,cAAc,EACdC,iBAAiB,QACX,gBAAgB;AACvB,SAASC,eAAe,QAAQ,eAAe;AAE/C,MAAMC,YAAYR,UAAUC,KAAKQ,IAAI;AAErC;;CAEC,GACD,SAASC,aAAaC,GAAW;IAChC,OAAOA,IAAIC,OAAO,CAAC,uBAAuB;AAC3C;AAQA;;;;;;;CAOC,GACD,OAAO,SAASC,sBAAsBC,SAAiB;IACtD,IAAIC,cAAcD;IAClB,IAAIE,UAAU;IAEd,0CAA0C;IAC1C,IAAID,YAAYE,UAAU,CAAC,MAAM;QAChC,kDAAkD;QAClD,MAAMC,gBAAgBH,YAAYI,OAAO,CAAC,KAAK;QAC/C,IAAID,kBAAkB,CAAC,GAAG;YACzBF,UAAUD,YAAYK,SAAS,CAACF,gBAAgB;YAChDH,cAAcA,YAAYK,SAAS,CAAC,GAAGF;QACxC;QAEA;;;GAGC,GACD,MAAMG,QAAQN,YAAYO,KAAK,CAAC;QAChC,IAAID,MAAME,MAAM,GAAG,GAAG;YACrB,yCAAyC;YACzC,MAAMC,OAAO,GAAGH,KAAK,CAAC,EAAE,CAAC,CAAC,EAAEA,KAAK,CAAC,EAAE,EAAE;YACtC,MAAMI,UAAUJ,MAAMK,KAAK,CAAC,GAAGC,IAAI,CAAC;YACpC,OAAO;gBAAEH;gBAAMR;gBAASS;YAAQ;QACjC;QACA,2BAA2B;QAC3B,OAAO;YAAED,MAAMT;YAAaC;QAAQ;IACrC;IAEA,qEAAqE;IACrE,MAAMY,UAAUb,YA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;gBACP;YACD,OAAO;gBACN,MAAMA;YACP;QACD;QAEA,gBAAgB;QAChB,MAAMyG,gBAAgBpG,OAAOqG,WAAW,CAAC,EAAE,CAACC,QAAQ;QACpD,MAAMC,UAAUH,cAAc1K,MAAM;QAEpC,0EAA0E;QAC1E,IAAI8K,WAA0B;QAC9B,IAAItC,aAAa,WAAW;YAC3B,MAAMuC,UAAU,MAAM9L,UAAU+L,OAAOC,IAAI,CAACP,gBAAgB;gBAC3DQ,OAAO3C;YACR;YACAuC,WAAWC,QAAQ/K,MAAM;QAC1B;QAEA,8BAA8B;QAC9B,IAAImL,cAAcxI;QAClB,IAAI+G,iBAAiB;YACpByB,cAAc,GAAGxI,YAAY,CAAC,EAAE+G,iBAAiB;QAClD,OAAO,IAAI5G,mBAAmBA,gBAAgBC,IAAI,GAAG,GAAG;YACvD,qCAAqC;YACrC,MAAMqI,iBAAiB;mBAAI,IAAI3F,IAAI3C,gBAAgBoF,MAAM;aAAI,CAACuB,IAAI;YAClE0B,cAAc,GAAGxI,YAAY,EAAE,EAAEyI,eAAehL,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9D;QAEA;;;GAGC,GACD,MAAM,EAAEiL,cAAcC,gBAAgB,EAAE,GAAGtM,gBAC1CmC,QACAwB;QAGD,OAAO;YACNA,aAAawI;YACbI,gBAAgBrC,QAAQzJ,OAAO;YAC/BmD,SAASA,WAAW,EAAE;YACtBiI;YACAC;YACAvC;YACAnD;YACAqB,cAAc+C;YACdhB;YACA8C;QACD;IACD,SAAU;QACT7J,eAAeN;IAChB;AACD"}
@@ -38,6 +38,13 @@ export declare function isValidTarget(target: string | undefined): boolean;
38
38
  * Normalize target to lowercase.
39
39
  */
40
40
  export declare function normalizeTarget(target: string | undefined): string;
41
+ /**
42
+ * Browser framework packages used for platform auto-detection. If a package has
43
+ * any of these in its dependencies or peerDependencies, it's treated as a
44
+ * browser package even if it specifies engines.node (many browser packages set
45
+ * engines.node for build tooling or SSR compatibility).
46
+ */
47
+ export declare const BROWSER_FRAMEWORK_DEPS: string[];
41
48
  /**
42
49
  * Base packages to auto-detect for externalization. These are checked against
43
50
  * the package's dependencies/peerDependencies.
package/dist/defaults.js CHANGED
@@ -112,6 +112,20 @@ export const TREND_VERSION_COUNT = 5;
112
112
  }
113
113
  return target.toLowerCase().trim();
114
114
  }
115
+ /**
116
+ * Browser framework packages used for platform auto-detection. If a package has
117
+ * any of these in its dependencies or peerDependencies, it's treated as a
118
+ * browser package even if it specifies engines.node (many browser packages set
119
+ * engines.node for build tooling or SSR compatibility).
120
+ */ export const BROWSER_FRAMEWORK_DEPS = [
121
+ "react",
122
+ "react-dom",
123
+ "vue",
124
+ "svelte",
125
+ "@angular/core",
126
+ "preact",
127
+ "solid-js"
128
+ ];
115
129
  /**
116
130
  * Base packages to auto-detect for externalization. These are checked against
117
131
  * the package's dependencies/peerDependencies.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport const defaultFlags = {\n\tboring: false,\n\tgzipLevel: 5,\n\texternal: \"\",\n\tnoExternal: false,\n\tversions: false,\n\tregistry: \"\",\n\tplatform: \"auto\",\n\tforce: false,\n\ttarget: \"es2022\",\n};\n\n/**\n * Normalize platform aliases to canonical esbuild platform values.\n * - \"auto\" → undefined (triggers auto-detection based on package engines)\n * - Browser aliases: \"browser\", \"web\", \"desktop\", \"client\" → \"browser\"\n * - Node aliases: \"node\", \"server\", \"nodejs\", \"backend\" → \"node\"\n */\nexport function normalizePlatform(\n\tplatform: string | undefined,\n): \"browser\" | \"node\" | undefined {\n\tif (!platform) {\n\t\treturn undefined;\n\t}\n\n\tconst normalized = platform.toLowerCase().trim();\n\n\t// Auto-detect from package.json engines.\n\tif (normalized === \"auto\") {\n\t\treturn undefined;\n\t}\n\n\t// Node aliases.\n\tif ([\"node\", \"server\", \"nodejs\", \"backend\"].includes(normalized)) {\n\t\treturn \"node\";\n\t}\n\n\t// Browser aliases.\n\tif ([\"browser\", \"web\", \"desktop\", \"client\"].includes(normalized)) {\n\t\treturn \"browser\";\n\t}\n\n\t// Invalid value - will be caught by validation.\n\treturn normalized as \"browser\" | \"node\";\n}\n\n/**\n * Check if a platform value is valid (either canonical or alias).\n */\nexport function isValidPlatform(platform: string | undefined): boolean {\n\tif (platform === undefined) {\n\t\treturn true;\n\t}\n\n\tconst normalized = platform.toLowerCase().trim();\n\n\t// Empty string after trim is invalid.\n\tif (normalized === \"\") {\n\t\treturn false;\n\t}\n\tconst validValues = [\n\t\t// Auto-detect.\n\t\t\"auto\",\n\t\t// Browser.\n\t\t\"browser\",\n\t\t\"web\",\n\t\t\"desktop\",\n\t\t\"client\",\n\t\t// Node.\n\t\t\"node\",\n\t\t\"server\",\n\t\t\"nodejs\",\n\t\t\"backend\",\n\t];\n\n\treturn validValues.includes(normalized);\n}\n\nexport const TREND_VERSION_COUNT = 5;\n\n/**\n * Default esbuild target for bundling.\n */\nexport const DEFAULT_TARGET = \"es2022\";\n\n/**\n * Valid esbuild target values.\n * Includes ECMAScript versions (es2015-es2024, esnext) and browser/runtime targets.\n */\nexport const VALID_TARGETS = [\n\t\"es2015\",\n\t\"es2016\",\n\t\"es2017\",\n\t\"es2018\",\n\t\"es2019\",\n\t\"es2020\",\n\t\"es2021\",\n\t\"es2022\",\n\t\"es2023\",\n\t\"es2024\",\n\t\"esnext\",\n];\n\n/**\n * Check if a target value is valid.\n */\nexport function isValidTarget(target: string | undefined): boolean {\n\tif (target === undefined) {\n\t\treturn true;\n\t}\n\n\tconst normalized = target.toLowerCase().trim();\n\n\t// Empty string after trim is invalid.\n\tif (normalized === \"\") {\n\t\treturn false;\n\t}\n\n\treturn VALID_TARGETS.includes(normalized);\n}\n\n/**\n * Normalize target to lowercase.\n */\nexport function normalizeTarget(target: string | undefined): string {\n\tif (!target) {\n\t\treturn DEFAULT_TARGET;\n\t}\n\treturn target.toLowerCase().trim();\n}\n\n/**\n * Base packages to auto-detect for externalization. These are checked against\n * the package's dependencies/peerDependencies.\n */\nexport const DEFAULT_EXTERNALS = [\"react\", \"react-dom\"];\n\n/**\n * Subpath externals to add when a base package is detected. When \"react\" is in\n * dependencies, we also need to externalize \"react/jsx-runtime\" etc. because\n * esbuild doesn't automatically externalize subpaths.\n */\nexport const EXTERNAL_SUBPATHS: Record<string, string[]> = {\n\treact: [\"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n\t\"react-dom\": [\"react-dom/client\", \"react-dom/server\"],\n};\n\nexport const DEFAULT_REGISTRY = \"https://registry.npmjs.org\";\n"],"names":["defaultFlags","boring","gzipLevel","external","noExternal","versions","registry","platform","force","target","normalizePlatform","undefined","normalized","toLowerCase","trim","includes","isValidPlatform","validValues","TREND_VERSION_COUNT","DEFAULT_TARGET","VALID_TARGETS","isValidTarget","normalizeTarget","DEFAULT_EXTERNALS","EXTERNAL_SUBPATHS","react","DEFAULT_REGISTRY"],"mappings":"AAAA,wBAAwB,GAExB,OAAO,MAAMA,eAAe;IAC3BC,QAAQ;IACRC,WAAW;IACXC,UAAU;IACVC,YAAY;IACZC,UAAU;IACVC,UAAU;IACVC,UAAU;IACVC,OAAO;IACPC,QAAQ;AACT,EAAE;AAEF;;;;;CAKC,GACD,OAAO,SAASC,kBACfH,QAA4B;IAE5B,IAAI,CAACA,UAAU;QACd,OAAOI;IACR;IAEA,MAAMC,aAAaL,SAASM,WAAW,GAAGC,IAAI;IAE9C,yCAAyC;IACzC,IAAIF,eAAe,QAAQ;QAC1B,OAAOD;IACR;IAEA,gBAAgB;IAChB,IAAI;QAAC;QAAQ;QAAU;QAAU;KAAU,CAACI,QAAQ,CAACH,aAAa;QACjE,OAAO;IACR;IAEA,mBAAmB;IACnB,IAAI;QAAC;QAAW;QAAO;QAAW;KAAS,CAACG,QAAQ,CAACH,aAAa;QACjE,OAAO;IACR;IAEA,gDAAgD;IAChD,OAAOA;AACR;AAEA;;CAEC,GACD,OAAO,SAASI,gBAAgBT,QAA4B;IAC3D,IAAIA,aAAaI,WAAW;QAC3B,OAAO;IACR;IAEA,MAAMC,aAAaL,SAASM,WAAW,GAAGC,IAAI;IAE9C,sCAAsC;IACtC,IAAIF,eAAe,IAAI;QACtB,OAAO;IACR;IACA,MAAMK,cAAc;QACnB,eAAe;QACf;QACA,WAAW;QACX;QACA;QACA;QACA;QACA,QAAQ;QACR;QACA;QACA;QACA;KACA;IAED,OAAOA,YAAYF,QAAQ,CAACH;AAC7B;AAEA,OAAO,MAAMM,sBAAsB,EAAE;AAErC;;CAEC,GACD,OAAO,MAAMC,iBAAiB,SAAS;AAEvC;;;CAGC,GACD,OAAO,MAAMC,gBAAgB;IAC5B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACA,CAAC;AAEF;;CAEC,GACD,OAAO,SAASC,cAAcZ,MAA0B;IACvD,IAAIA,WAAWE,WAAW;QACzB,OAAO;IACR;IAEA,MAAMC,aAAaH,OAAOI,WAAW,GAAGC,IAAI;IAE5C,sCAAsC;IACtC,IAAIF,eAAe,IAAI;QACtB,OAAO;IACR;IAEA,OAAOQ,cAAcL,QAAQ,CAACH;AAC/B;AAEA;;CAEC,GACD,OAAO,SAASU,gBAAgBb,MAA0B;IACzD,IAAI,CAACA,QAAQ;QACZ,OAAOU;IACR;IACA,OAAOV,OAAOI,WAAW,GAAGC,IAAI;AACjC;AAEA;;;CAGC,GACD,OAAO,MAAMS,oBAAoB;IAAC;IAAS;CAAY,CAAC;AAExD;;;;CAIC,GACD,OAAO,MAAMC,oBAA8C;IAC1DC,OAAO;QAAC;QAAqB;KAAwB;IACrD,aAAa;QAAC;QAAoB;KAAmB;AACtD,EAAE;AAEF,OAAO,MAAMC,mBAAmB,6BAA6B"}
1
+ {"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport const defaultFlags = {\n\tboring: false,\n\tgzipLevel: 5,\n\texternal: \"\",\n\tnoExternal: false,\n\tversions: false,\n\tregistry: \"\",\n\tplatform: \"auto\",\n\tforce: false,\n\ttarget: \"es2022\",\n};\n\n/**\n * Normalize platform aliases to canonical esbuild platform values.\n * - \"auto\" → undefined (triggers auto-detection based on package engines)\n * - Browser aliases: \"browser\", \"web\", \"desktop\", \"client\" → \"browser\"\n * - Node aliases: \"node\", \"server\", \"nodejs\", \"backend\" → \"node\"\n */\nexport function normalizePlatform(\n\tplatform: string | undefined,\n): \"browser\" | \"node\" | undefined {\n\tif (!platform) {\n\t\treturn undefined;\n\t}\n\n\tconst normalized = platform.toLowerCase().trim();\n\n\t// Auto-detect from package.json engines.\n\tif (normalized === \"auto\") {\n\t\treturn undefined;\n\t}\n\n\t// Node aliases.\n\tif ([\"node\", \"server\", \"nodejs\", \"backend\"].includes(normalized)) {\n\t\treturn \"node\";\n\t}\n\n\t// Browser aliases.\n\tif ([\"browser\", \"web\", \"desktop\", \"client\"].includes(normalized)) {\n\t\treturn \"browser\";\n\t}\n\n\t// Invalid value - will be caught by validation.\n\treturn normalized as \"browser\" | \"node\";\n}\n\n/**\n * Check if a platform value is valid (either canonical or alias).\n */\nexport function isValidPlatform(platform: string | undefined): boolean {\n\tif (platform === undefined) {\n\t\treturn true;\n\t}\n\n\tconst normalized = platform.toLowerCase().trim();\n\n\t// Empty string after trim is invalid.\n\tif (normalized === \"\") {\n\t\treturn false;\n\t}\n\tconst validValues = [\n\t\t// Auto-detect.\n\t\t\"auto\",\n\t\t// Browser.\n\t\t\"browser\",\n\t\t\"web\",\n\t\t\"desktop\",\n\t\t\"client\",\n\t\t// Node.\n\t\t\"node\",\n\t\t\"server\",\n\t\t\"nodejs\",\n\t\t\"backend\",\n\t];\n\n\treturn validValues.includes(normalized);\n}\n\nexport const TREND_VERSION_COUNT = 5;\n\n/**\n * Default esbuild target for bundling.\n */\nexport const DEFAULT_TARGET = \"es2022\";\n\n/**\n * Valid esbuild target values.\n * Includes ECMAScript versions (es2015-es2024, esnext) and browser/runtime targets.\n */\nexport const VALID_TARGETS = [\n\t\"es2015\",\n\t\"es2016\",\n\t\"es2017\",\n\t\"es2018\",\n\t\"es2019\",\n\t\"es2020\",\n\t\"es2021\",\n\t\"es2022\",\n\t\"es2023\",\n\t\"es2024\",\n\t\"esnext\",\n];\n\n/**\n * Check if a target value is valid.\n */\nexport function isValidTarget(target: string | undefined): boolean {\n\tif (target === undefined) {\n\t\treturn true;\n\t}\n\n\tconst normalized = target.toLowerCase().trim();\n\n\t// Empty string after trim is invalid.\n\tif (normalized === \"\") {\n\t\treturn false;\n\t}\n\n\treturn VALID_TARGETS.includes(normalized);\n}\n\n/**\n * Normalize target to lowercase.\n */\nexport function normalizeTarget(target: string | undefined): string {\n\tif (!target) {\n\t\treturn DEFAULT_TARGET;\n\t}\n\treturn target.toLowerCase().trim();\n}\n\n/**\n * Browser framework packages used for platform auto-detection. If a package has\n * any of these in its dependencies or peerDependencies, it's treated as a\n * browser package even if it specifies engines.node (many browser packages set\n * engines.node for build tooling or SSR compatibility).\n */\nexport const BROWSER_FRAMEWORK_DEPS = [\n\t\"react\",\n\t\"react-dom\",\n\t\"vue\",\n\t\"svelte\",\n\t\"@angular/core\",\n\t\"preact\",\n\t\"solid-js\",\n];\n\n/**\n * Base packages to auto-detect for externalization. These are checked against\n * the package's dependencies/peerDependencies.\n */\nexport const DEFAULT_EXTERNALS = [\"react\", \"react-dom\"];\n\n/**\n * Subpath externals to add when a base package is detected. When \"react\" is in\n * dependencies, we also need to externalize \"react/jsx-runtime\" etc. because\n * esbuild doesn't automatically externalize subpaths.\n */\nexport const EXTERNAL_SUBPATHS: Record<string, string[]> = {\n\treact: [\"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n\t\"react-dom\": [\"react-dom/client\", \"react-dom/server\"],\n};\n\nexport const DEFAULT_REGISTRY = \"https://registry.npmjs.org\";\n"],"names":["defaultFlags","boring","gzipLevel","external","noExternal","versions","registry","platform","force","target","normalizePlatform","undefined","normalized","toLowerCase","trim","includes","isValidPlatform","validValues","TREND_VERSION_COUNT","DEFAULT_TARGET","VALID_TARGETS","isValidTarget","normalizeTarget","BROW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cAAcZ,MAA0B;IACvD,IAAIA,WAAWE,WAAW;QACzB,OAAO;IACR;IAEA,MAAMC,aAAaH,OAAOI,WAAW,GAAGC,IAAI;IAE5C,sCAAsC;IACtC,IAAIF,eAAe,IAAI;QACtB,OAAO;IACR;IAEA,OAAOQ,cAAcL,QAAQ,CAACH;AAC/B;AAEA;;CAEC,GACD,OAAO,SAASU,gBAAgBb,MAA0B;IACzD,IAAI,CAACA,QAAQ;QACZ,OAAOU;IACR;IACA,OAAOV,OAAOI,WAAW,GAAGC,IAAI;AACjC;AAEA;;;;;CAKC,GACD,OAAO,MAAMS,yBAAyB;IACrC;IACA;IACA;IACA;IACA;IACA;IACA;CACA,CAAC;AAEF;;;CAGC,GACD,OAAO,MAAMC,oBAAoB;IAAC;IAAS;CAAY,CAAC;AAExD;;;;CAIC,GACD,OAAO,MAAMC,oBAA8C;IAC1DC,OAAO;QAAC;QAAqB;KAAwB;IACrD,aAAa;QAAC;QAAoB;KAAmB;AACtD,EAAE;AAEF,OAAO,MAAMC,mBAAmB,6BAA6B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-cli/bundlecheck",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "description": "CLI tool to check the bundle size of npm packages (like bundlephobia)",
@@ -33,22 +33,21 @@
33
33
  "watch": "swc --strip-leading-paths --watch --out-dir dist src"
34
34
  },
35
35
  "dependencies": {
36
- "@inquirer/select": "5.0.4",
37
- "@node-cli/logger": "1.3.4",
36
+ "@inquirer/select": "5.0.7",
37
+ "@node-cli/logger": "1.3.5",
38
38
  "@node-cli/parser": "2.4.5",
39
39
  "better-sqlite3": "12.6.2",
40
- "esbuild": "0.27.2",
40
+ "esbuild": "0.27.3",
41
41
  "kleur": "4.1.5",
42
- "semver": "7.7.3"
42
+ "semver": "7.7.4"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
47
  "devDependencies": {
48
- "@node-cli/comments": "0.2.9",
49
48
  "@types/better-sqlite3": "7.6.13",
50
49
  "@vitest/coverage-v8": "4.0.18",
51
50
  "vitest": "4.0.18"
52
51
  },
53
- "gitHead": "bb80931807dd01d5b115de9c867d9cea178573ff"
52
+ "gitHead": "f4ced1b7a42dead360543afef548cb18f358f588"
54
53
  }