@node-cli/bundlecheck 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -11
- package/dist/bundlecheck.js +69 -21
- package/dist/bundlecheck.js.map +1 -1
- package/dist/bundler.d.ts +10 -1
- package/dist/bundler.js +26 -12
- package/dist/bundler.js.map +1 -1
- package/dist/cache.d.ts +59 -0
- package/dist/cache.js +192 -0
- package/dist/cache.js.map +1 -0
- package/dist/defaults.d.ts +13 -0
- package/dist/defaults.js +65 -1
- package/dist/defaults.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/parse.d.ts +2 -0
- package/dist/parse.js +26 -1
- package/dist/parse.js.map +1 -1
- package/dist/trend.d.ts +6 -1
- package/dist/trend.js +69 -25
- package/dist/trend.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -13,8 +13,10 @@ A CLI tool to check the bundle size of npm packages, similar to [bundlephobia.co
|
|
|
13
13
|
- Support for checking specific exports (tree-shaking)
|
|
14
14
|
- Automatic externalization of React and React-DOM
|
|
15
15
|
- Raw and gzip sizes with configurable compression level
|
|
16
|
+
- **Platform support**: target `browser` (default) or `node` with smart auto-detection
|
|
16
17
|
- Custom npm registry support (for private registries)
|
|
17
18
|
- Fast bundling using esbuild (with pnpm support)
|
|
19
|
+
- **Local caching** for faster repeated lookups (SQLite-based, max 100 entries)
|
|
18
20
|
|
|
19
21
|
## Installation
|
|
20
22
|
|
|
@@ -92,17 +94,19 @@ bundlecheck lodash "debounce,throttle"
|
|
|
92
94
|
|
|
93
95
|
### Options
|
|
94
96
|
|
|
95
|
-
| Flag | Short | Description
|
|
96
|
-
| ------------------- | ----------- |
|
|
97
|
-
| `--help` | `-h` | Display help instructions
|
|
98
|
-
| `--version` | `-v` | Output the current version
|
|
99
|
-
| `--versions` | `-V` | Choose from available package versions interactively
|
|
100
|
-
| `--trend [N]` | `-t [N]` | Show bundle size trend for N versions (default: 5)
|
|
101
|
-
| `--boring` | `-b` | Do not use color output
|
|
102
|
-
| `--gzipLevel <n>` | `-g <n>` | Gzip compression level (1-9, default: 5)
|
|
103
|
-
| `--external <pkgs>` | `-e <pkgs>` | Comma-separated additional packages to mark as external
|
|
104
|
-
| `--noExternal` | `-n` | Do not mark any packages as external
|
|
105
|
-
| `--registry <url>` | `-r <url>` | Custom npm registry URL (default: registry.npmjs.org)
|
|
97
|
+
| Flag | Short | Description |
|
|
98
|
+
| ------------------- | ----------- | ---------------------------------------------------------------- |
|
|
99
|
+
| `--help` | `-h` | Display help instructions |
|
|
100
|
+
| `--version` | `-v` | Output the current version |
|
|
101
|
+
| `--versions` | `-V` | Choose from available package versions interactively |
|
|
102
|
+
| `--trend [N]` | `-t [N]` | Show bundle size trend for N versions (default: 5) |
|
|
103
|
+
| `--boring` | `-b` | Do not use color output |
|
|
104
|
+
| `--gzipLevel <n>` | `-g <n>` | Gzip compression level (1-9, default: 5) |
|
|
105
|
+
| `--external <pkgs>` | `-e <pkgs>` | Comma-separated additional packages to mark as external |
|
|
106
|
+
| `--noExternal` | `-n` | Do not mark any packages as external |
|
|
107
|
+
| `--registry <url>` | `-r <url>` | Custom npm registry URL (default: registry.npmjs.org) |
|
|
108
|
+
| `--platform <name>` | `-p <name>` | Target platform: `auto` (default), `browser`, or `node` |
|
|
109
|
+
| `--force` | `-f` | Bypass cache and force re-fetch/re-calculation |
|
|
106
110
|
|
|
107
111
|
### Examples
|
|
108
112
|
|
|
@@ -137,6 +141,15 @@ bundlecheck lodash --trend 3
|
|
|
137
141
|
|
|
138
142
|
# Use a custom npm registry
|
|
139
143
|
bundlecheck @myorg/private-pkg --registry https://npm.mycompany.com
|
|
144
|
+
|
|
145
|
+
# Check a Node.js package (explicit platform)
|
|
146
|
+
bundlecheck express --platform node
|
|
147
|
+
|
|
148
|
+
# Auto-detect platform (default behavior)
|
|
149
|
+
bundlecheck express # auto-detects "node" from package.json engines
|
|
150
|
+
|
|
151
|
+
# Bypass cache and force re-fetch
|
|
152
|
+
bundlecheck lodash --force
|
|
140
153
|
```
|
|
141
154
|
|
|
142
155
|
## How It Works
|
|
@@ -148,6 +161,27 @@ bundlecheck @myorg/private-pkg --registry https://npm.mycompany.com
|
|
|
148
161
|
5. Reports raw and gzip sizes
|
|
149
162
|
6. Cleans up temporary files
|
|
150
163
|
|
|
164
|
+
## Platform Support
|
|
165
|
+
|
|
166
|
+
The `--platform` flag controls how the bundle is built:
|
|
167
|
+
|
|
168
|
+
- **`auto`** (default): Automatically detects the platform from the package's `engines` field. If the package specifies `engines.node` without `engines.browser`, it uses `node`; otherwise defaults to `browser`.
|
|
169
|
+
- **`browser`**: Builds for browser environments (also accepts aliases: `web`, `desktop`, `client`)
|
|
170
|
+
- **`node`**: Builds for Node.js environments (also accepts aliases: `server`, `nodejs`, `backend`)
|
|
171
|
+
|
|
172
|
+
When targeting **node** platform:
|
|
173
|
+
- Gzip size is not calculated (shows "N/A") since server-side code isn't typically served compressed over HTTP
|
|
174
|
+
- The bundle is optimized for Node.js built-ins
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Auto-detect (recommended for most cases)
|
|
178
|
+
bundlecheck express # detects "node" from engines.node
|
|
179
|
+
|
|
180
|
+
# Explicit platform
|
|
181
|
+
bundlecheck lodash --platform browser
|
|
182
|
+
bundlecheck fastify -p server # "server" is an alias for "node"
|
|
183
|
+
```
|
|
184
|
+
|
|
151
185
|
## Default Externals
|
|
152
186
|
|
|
153
187
|
By default, `react` and `react-dom` are marked as external (not included in the bundle size) since most React-based packages expect these as peer dependencies. This matches how these packages would typically be used in a real application.
|
|
@@ -169,6 +203,46 @@ bundlecheck my-local-pkg --registry http://localhost:4873
|
|
|
169
203
|
|
|
170
204
|
Note: If the registry requires authentication, ensure your npm/pnpm is configured with the appropriate credentials (via `.npmrc` or environment variables).
|
|
171
205
|
|
|
206
|
+
## Cache
|
|
207
|
+
|
|
208
|
+
Bundle size results are cached locally to speed up repeated lookups. The cache is stored in `~/.bundlecheck/cache.db` using SQLite.
|
|
209
|
+
|
|
210
|
+
### How it works
|
|
211
|
+
|
|
212
|
+
- Results are cached based on: package name, version, exports, platform, gzip level, and externals configuration
|
|
213
|
+
- The cache holds up to **100 entries** (least recently used entries are evicted first)
|
|
214
|
+
- When you check a package, the CLI first looks for a cached result with matching parameters
|
|
215
|
+
|
|
216
|
+
### Smart version matching
|
|
217
|
+
|
|
218
|
+
The cache uses **resolved versions**, not the requested specifier. This means:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
bundlecheck @mantine/core # Resolves "latest" to e.g. 8.0.0, caches as 8.0.0
|
|
222
|
+
bundlecheck @mantine/core@8.0.0 # Cache hit! Same resolved version
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
This also works with `--trend`: if you previously checked `@mantine/core` (which resolved to v8.0.0), running `--trend` will use the cached result for v8.0.0 and only fetch the other versions.
|
|
226
|
+
|
|
227
|
+
### Bypassing the cache
|
|
228
|
+
|
|
229
|
+
Use the `--force` flag to skip the cache and re-fetch/re-calculate:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
bundlecheck lodash --force # Always fetches fresh data
|
|
233
|
+
bundlecheck lodash -f # Short form
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Cache location
|
|
237
|
+
|
|
238
|
+
The cache database is stored at:
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
~/.bundlecheck/cache.db
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
To clear the cache, simply delete this file or the `~/.bundlecheck` directory.
|
|
245
|
+
|
|
172
246
|
## License
|
|
173
247
|
|
|
174
248
|
MIT - see [LICENSE](./LICENSE) for details.
|
package/dist/bundlecheck.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* istanbul ignore file */ import { Logger } from "@node-cli/logger";
|
|
3
3
|
import kleur from "kleur";
|
|
4
|
-
import { checkBundleSize, formatBytes, parsePackageSpecifier } from "./bundler.js";
|
|
5
|
-
import {
|
|
4
|
+
import { checkBundleSize, formatBytes, getExternals, parsePackageSpecifier } from "./bundler.js";
|
|
5
|
+
import { getCachedResult, normalizeCacheKey, setCachedResult } from "./cache.js";
|
|
6
|
+
import { normalizePlatform, TREND_VERSION_COUNT } from "./defaults.js";
|
|
6
7
|
import { config } from "./parse.js";
|
|
7
8
|
import { analyzeTrend, renderTrendGraph, selectTrendVersions } from "./trend.js";
|
|
8
9
|
import { fetchPackageVersions, promptForVersion } from "./versions.js";
|
|
@@ -13,6 +14,28 @@ kleur.enabled = !flags?.boring;
|
|
|
13
14
|
const log = new Logger({
|
|
14
15
|
boring: flags?.boring
|
|
15
16
|
});
|
|
17
|
+
/**
|
|
18
|
+
* Display bundle result in a formatted box
|
|
19
|
+
*/ function displayResult(result, isAutoDetected) {
|
|
20
|
+
const blue = kleur.blue;
|
|
21
|
+
const green = kleur.green;
|
|
22
|
+
const platformLabel = result.platform === "node" ? "node" : "browser";
|
|
23
|
+
const platformNote = isAutoDetected ? " (auto-detected)" : "";
|
|
24
|
+
log.printBox([
|
|
25
|
+
`${blue("Package:")} ${result.packageName} (${blue("version:")} ${result.packageVersion})`,
|
|
26
|
+
result.exports.length > 0 ? `${blue("Exports:")} { ${result.exports.join(", ")} }` : `${blue("Exports:")} * (entire package)`,
|
|
27
|
+
"",
|
|
28
|
+
`${blue("Raw size:")} ${formatBytes(result.rawSize)}`,
|
|
29
|
+
result.gzipSize !== null ? `${blue("Gzip size:")} ${formatBytes(result.gzipSize)} (level ${result.gzipLevel})` : `${blue("Gzip size:")} N/A (not applicable for node platform)`,
|
|
30
|
+
"",
|
|
31
|
+
result.externals.length > 0 ? `${blue("Externals:")} ${result.externals.join(", ")}` : `${blue("Externals:")} ${green("none")}`,
|
|
32
|
+
result.dependencies.length > 0 ? `${blue("Dependencies:")} ${result.dependencies.join(", ")}` : `${blue("Dependencies:")} ${green("none")}`,
|
|
33
|
+
`${blue("Platform:")} ${platformLabel}${platformNote}`
|
|
34
|
+
], {
|
|
35
|
+
borderStyle: "round",
|
|
36
|
+
align: "left"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
16
39
|
async function main() {
|
|
17
40
|
let packageName = parameters?.["0"];
|
|
18
41
|
if (!packageName) {
|
|
@@ -31,6 +54,8 @@ async function main() {
|
|
|
31
54
|
if (exportsArg) {
|
|
32
55
|
exports = exportsArg.split(",").map((e)=>e.trim()).filter(Boolean);
|
|
33
56
|
}
|
|
57
|
+
// Normalize platform from flag (handles aliases like "web" → "browser")
|
|
58
|
+
const platform = normalizePlatform(flags?.platform);
|
|
34
59
|
// If --trend flag is set, show bundle size trend across versions
|
|
35
60
|
// --trend alone uses default (5), --trend N uses N versions
|
|
36
61
|
const trendValue = flags?.trend;
|
|
@@ -62,7 +87,9 @@ async function main() {
|
|
|
62
87
|
noExternal: flags?.noExternal,
|
|
63
88
|
gzipLevel: flags?.gzipLevel,
|
|
64
89
|
boring: flags?.boring,
|
|
65
|
-
registry: flags?.registry
|
|
90
|
+
registry: flags?.registry,
|
|
91
|
+
platform,
|
|
92
|
+
force: flags?.force
|
|
66
93
|
});
|
|
67
94
|
if (results.length === 0) {
|
|
68
95
|
log.error("Failed to analyze any versions");
|
|
@@ -107,32 +134,53 @@ async function main() {
|
|
|
107
134
|
if (exports && exports.length > 0) {
|
|
108
135
|
log.info(`Exports: { ${exports.join(", ")} }`);
|
|
109
136
|
}
|
|
110
|
-
log.info("Please wait, installing and bundling...\n");
|
|
111
137
|
try {
|
|
138
|
+
// Parse package specifier to get name and version
|
|
139
|
+
const { name: baseName, version: requestedVersion } = parsePackageSpecifier(packageName);
|
|
140
|
+
// Resolve "latest" to actual version for cache key
|
|
141
|
+
let resolvedVersion = requestedVersion;
|
|
142
|
+
if (requestedVersion === "latest") {
|
|
143
|
+
const { tags } = await fetchPackageVersions({
|
|
144
|
+
packageName: baseName,
|
|
145
|
+
registry: flags?.registry
|
|
146
|
+
});
|
|
147
|
+
resolvedVersion = tags.latest || requestedVersion;
|
|
148
|
+
}
|
|
149
|
+
// Compute externals for cache key (same logic as bundler)
|
|
150
|
+
const externals = getExternals(baseName, additionalExternals, flags?.noExternal);
|
|
151
|
+
// Build cache key
|
|
152
|
+
// Note: platform can be undefined (auto-detect), which is stored as "auto" in cache
|
|
153
|
+
const cacheKey = normalizeCacheKey({
|
|
154
|
+
packageName: baseName,
|
|
155
|
+
version: resolvedVersion,
|
|
156
|
+
exports,
|
|
157
|
+
platform,
|
|
158
|
+
gzipLevel: flags?.gzipLevel ?? 5,
|
|
159
|
+
externals,
|
|
160
|
+
noExternal: flags?.noExternal ?? false
|
|
161
|
+
});
|
|
162
|
+
// Check cache (unless --force flag is set)
|
|
163
|
+
if (!flags?.force) {
|
|
164
|
+
const cached = getCachedResult(cacheKey);
|
|
165
|
+
if (cached) {
|
|
166
|
+
log.info("NOTE: Using cached results\n");
|
|
167
|
+
displayResult(cached, platform === undefined);
|
|
168
|
+
process.exit(0);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
log.info("Please wait, installing and bundling...\n");
|
|
112
172
|
const result = await checkBundleSize({
|
|
113
173
|
packageName,
|
|
114
174
|
exports,
|
|
115
175
|
additionalExternals,
|
|
116
176
|
noExternal: flags?.noExternal,
|
|
117
177
|
gzipLevel: flags?.gzipLevel,
|
|
118
|
-
registry: flags?.registry
|
|
119
|
-
|
|
120
|
-
const blue = kleur.blue;
|
|
121
|
-
const green = kleur.green;
|
|
122
|
-
// Display results
|
|
123
|
-
log.printBox([
|
|
124
|
-
`${blue("Package:")} ${result.packageName} (${blue("version:")} ${result.packageVersion})`,
|
|
125
|
-
result.exports.length > 0 ? `${blue("Exports:")} { ${result.exports.join(", ")} }` : `${blue("Exports:")} * (entire package)`,
|
|
126
|
-
"",
|
|
127
|
-
`${blue("Raw size:")} ${formatBytes(result.rawSize)}`,
|
|
128
|
-
`${blue("Gzip size:")} ${formatBytes(result.gzipSize)} (level ${result.gzipLevel})`,
|
|
129
|
-
"",
|
|
130
|
-
result.externals.length > 0 ? `${blue("Externals:")} ${result.externals.join(", ")}` : `${blue("Externals:")} ${green("none")}`,
|
|
131
|
-
result.dependencies.length > 0 ? `${blue("Dependencies:")} ${result.dependencies.join(", ")}` : `${blue("Dependencies:")} ${green("none")}`
|
|
132
|
-
], {
|
|
133
|
-
borderStyle: "round",
|
|
134
|
-
align: "left"
|
|
178
|
+
registry: flags?.registry,
|
|
179
|
+
platform
|
|
135
180
|
});
|
|
181
|
+
// Store result in cache
|
|
182
|
+
setCachedResult(cacheKey, result);
|
|
183
|
+
displayResult(result, platform === undefined);
|
|
136
184
|
process.exit(0);
|
|
137
185
|
} catch (error) {
|
|
138
186
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
package/dist/bundlecheck.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundlecheck.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/* istanbul ignore file */\n\nimport { Logger } from \"@node-cli/logger\";\nimport kleur from \"kleur\";\nimport {\n\tcheckBundleSize,\n\tformatBytes,\n\tparsePackageSpecifier,\n} from \"./bundler.js\";\nimport { TREND_VERSION_COUNT } from \"./defaults.js\";\nimport { config } from \"./parse.js\";\nimport {\n\tanalyzeTrend,\n\trenderTrendGraph,\n\tselectTrendVersions,\n} from \"./trend.js\";\nimport { fetchPackageVersions, promptForVersion } from \"./versions.js\";\n\nconst flags = config.flags;\nconst parameters = config.parameters;\n\n// Disable kleur colors when --boring flag is set\nkleur.enabled = !flags?.boring;\n\nconst log = new Logger({\n\tboring: flags?.boring,\n});\n\nasync function main() {\n\tlet packageName = parameters?.[\"0\"];\n\n\tif (!packageName) {\n\t\tlog.error(\"Package name is required\");\n\t\tconfig.showHelp?.();\n\t\tprocess.exit(1);\n\t}\n\n\t// Parse additional externals if provided (comma-separated)\n\tlet additionalExternals: string[] | undefined;\n\tif (flags?.external) {\n\t\tadditionalExternals = flags.external\n\t\t\t.split(\",\")\n\t\t\t.map((e) => e.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\t// Parse exports if provided (comma-separated)\n\tlet exports: string[] | undefined;\n\tconst exportsArg = parameters?.[\"1\"];\n\tif (exportsArg) {\n\t\texports = exportsArg\n\t\t\t.split(\",\")\n\t\t\t.map((e) => e.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\t// If --trend flag is set, show bundle size trend across versions\n\t// --trend alone uses default (5), --trend N uses N versions\n\tconst trendValue = flags?.trend;\n\tif (trendValue !== undefined) {\n\t\tconst parsedCount = Number.parseInt(trendValue, 10);\n\t\tconst versionCount =\n\t\t\t!Number.isNaN(parsedCount) && parsedCount > 0\n\t\t\t\t? parsedCount\n\t\t\t\t: TREND_VERSION_COUNT;\n\n\t\ttry {\n\t\t\tconst { name, subpath } = parsePackageSpecifier(packageName);\n\t\t\t// Construct the full package path including subpath if present\n\t\t\tconst fullPackagePath = subpath ? `${name}/${subpath}` : name;\n\n\t\t\tlog.info(`\\nFetching available versions for ${name}...`);\n\n\t\t\tconst { versions } = await fetchPackageVersions({\n\t\t\t\tpackageName,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\n\t\t\tif (versions.length === 0) {\n\t\t\t\tlog.error(\"No versions found for this package\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\t// Select versions for trend\n\t\t\tconst trendVersions = selectTrendVersions(versions, versionCount);\n\n\t\t\tlog.info(\n\t\t\t\t`Analyzing ${trendVersions.length} versions: ${trendVersions.join(\", \")}`,\n\t\t\t);\n\t\t\tlog.info(\"\");\n\n\t\t\tconst results = await analyzeTrend({\n\t\t\t\tpackageName: fullPackagePath,\n\t\t\t\tversions: trendVersions,\n\t\t\t\texports,\n\t\t\t\tadditionalExternals,\n\t\t\t\tnoExternal: flags?.noExternal,\n\t\t\t\tgzipLevel: flags?.gzipLevel,\n\t\t\t\tboring: flags?.boring,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\n\t\t\tif (results.length === 0) {\n\t\t\t\tlog.error(\"Failed to analyze any versions\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\t// Render and display the trend graph\n\t\t\tconst graphLines = renderTrendGraph(\n\t\t\t\tfullPackagePath,\n\t\t\t\tresults,\n\t\t\t\tflags?.boring,\n\t\t\t);\n\t\t\tfor (const line of graphLines) {\n\t\t\t\tlog.log(line);\n\t\t\t}\n\n\t\t\tprocess.exit(0);\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlog.error(`Failed to analyze trend: ${errorMessage}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\t// If --versions flag is set, fetch and prompt for version selection\n\tif (flags?.versions) {\n\t\ttry {\n\t\t\tconst { name, subpath } = parsePackageSpecifier(packageName);\n\t\t\tlog.info(`\\nFetching available versions for ${name}...`);\n\n\t\t\tconst { versions, tags } = await fetchPackageVersions({\n\t\t\t\tpackageName,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\n\t\t\tif (versions.length === 0) {\n\t\t\t\tlog.error(\"No versions found for this package\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tconst selectedVersion = await promptForVersion(name, versions, tags);\n\t\t\t// Rebuild specifier preserving any subpath\n\t\t\tpackageName = subpath\n\t\t\t\t? `${name}/${subpath}@${selectedVersion}`\n\t\t\t\t: `${name}@${selectedVersion}`;\n\t\t\tlog.info(`\\nSelected: ${packageName}`);\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlog.error(`Failed to fetch versions: ${errorMessage}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tlog.info(`\\nAnalyzing bundle size for: ${packageName}`);\n\tif (exports && exports.length > 0) {\n\t\tlog.info(`Exports: { ${exports.join(\", \")} }`);\n\t}\n\tlog.info(\"Please wait, installing and bundling...\\n\");\n\n\ttry {\n\t\tconst result = await checkBundleSize({\n\t\t\tpackageName,\n\t\t\texports,\n\t\t\tadditionalExternals,\n\t\t\tnoExternal: flags?.noExternal,\n\t\t\tgzipLevel: flags?.gzipLevel,\n\t\t\tregistry: flags?.registry,\n\t\t});\n\n\t\tconst blue = kleur.blue;\n\t\tconst green = kleur.green;\n\n\t\t// Display results\n\t\tlog.printBox(\n\t\t\t[\n\t\t\t\t`${blue(\"Package:\")} ${result.packageName} (${blue(\"version:\")} ${result.packageVersion})`,\n\t\t\t\tresult.exports.length > 0\n\t\t\t\t\t? `${blue(\"Exports:\")} { ${result.exports.join(\", \")} }`\n\t\t\t\t\t: `${blue(\"Exports:\")} * (entire package)`,\n\t\t\t\t\"\",\n\t\t\t\t`${blue(\"Raw size:\")} ${formatBytes(result.rawSize)}`,\n\t\t\t\t`${blue(\"Gzip size:\")} ${formatBytes(result.gzipSize)} (level ${result.gzipLevel})`,\n\t\t\t\t\"\",\n\t\t\t\tresult.externals.length > 0\n\t\t\t\t\t? `${blue(\"Externals:\")} ${result.externals.join(\", \")}`\n\t\t\t\t\t: `${blue(\"Externals:\")} ${green(\"none\")}`,\n\t\t\t\tresult.dependencies.length > 0\n\t\t\t\t\t? `${blue(\"Dependencies:\")} ${result.dependencies.join(\", \")}`\n\t\t\t\t\t: `${blue(\"Dependencies:\")} ${green(\"none\")}`,\n\t\t\t],\n\t\t\t{\n\t\t\t\tborderStyle: \"round\",\n\t\t\t\talign: \"left\",\n\t\t\t},\n\t\t);\n\n\t\tprocess.exit(0);\n\t} catch (error) {\n\t\tconst errorMessage = error instanceof Error ? error.message : String(error);\n\t\tlog.error(`Failed to analyze bundle size: ${errorMessage}`);\n\t\tprocess.exit(1);\n\t}\n}\n\nmain();\n"],"names":["Logger","kleur","checkBundleSize","formatBytes","parsePackageSpecifier","TREND_VERSION_COUNT","config","analyzeTrend","renderTrendGraph","selectTrendVersions","fetchPackageVersions","promptForVersion","flags","parameters","enabled","boring","log","main","packageName","error","showHelp","process","exit","additionalExternals","external","split","map","e","trim","filter","Boolean","exports","exportsArg","trendValue","trend","undefined","parsedCount","Number","parseInt","versionCount","isNaN","name","subpath","fullPackagePath","info","versions","registry","length","trendVersions","join","results","noExternal","gzipLevel","graphLines","line","errorMessage","Error","message","String","tags","selectedVersion","result","blue","green","printBox","packageVersion","rawSize","gzipSize","externals","dependencies","borderStyle","align"],"mappings":";AAEA,wBAAwB,GAExB,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,WAAW,QAAQ;AAC1B,SACCC,eAAe,EACfC,WAAW,EACXC,qBAAqB,QACf,eAAe;AACtB,SAASC,mBAAmB,QAAQ,gBAAgB;AACpD,SAASC,MAAM,QAAQ,aAAa;AACpC,SACCC,YAAY,EACZC,gBAAgB,EAChBC,mBAAmB,QACb,aAAa;AACpB,SAASC,oBAAoB,EAAEC,gBAAgB,QAAQ,gBAAgB;AAEvE,MAAMC,QAAQN,OAAOM,KAAK;AAC1B,MAAMC,aAAaP,OAAOO,UAAU;AAEpC,iDAAiD;AACjDZ,MAAMa,OAAO,GAAG,CAACF,OAAOG;AAExB,MAAMC,MAAM,IAAIhB,OAAO;IACtBe,QAAQH,OAAOG;AAChB;AAEA,eAAeE;IACd,IAAIC,cAAcL,YAAY,CAAC,IAAI;IAEnC,IAAI,CAACK,aAAa;QACjBF,IAAIG,KAAK,CAAC;QACVb,OAAOc,QAAQ;QACfC,QAAQC,IAAI,CAAC;IACd;IAEA,2DAA2D;IAC3D,IAAIC;IACJ,IAAIX,OAAOY,UAAU;QACpBD,sBAAsBX,MAAMY,QAAQ,CAClCC,KAAK,CAAC,KACNC,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,IACjBC,MAAM,CAACC;IACV;IAEA,8CAA8C;IAC9C,IAAIC;IACJ,MAAMC,aAAanB,YAAY,CAAC,IAAI;IACpC,IAAImB,YAAY;QACfD,UAAUC,WACRP,KAAK,CAAC,KACNC,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,IACjBC,MAAM,CAAC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ACd,EAAE,OAAOH,OAAO;QACf,MAAMoC,eAAepC,iBAAiBqC,QAAQrC,MAAMsC,OAAO,GAAGC,OAAOvC;QACrEH,IAAIG,KAAK,CAAC,CAAC,+BAA+B,EAAEoC,cAAc;QAC1DlC,QAAQC,IAAI,CAAC;IACd;AACD;AAEAL"}
|
|
1
|
+
{"version":3,"sources":["../src/bundlecheck.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/* istanbul ignore file */\n\nimport { Logger } from \"@node-cli/logger\";\nimport kleur from \"kleur\";\nimport {\n\tcheckBundleSize,\n\tformatBytes,\n\tgetExternals,\n\tparsePackageSpecifier,\n} from \"./bundler.js\";\nimport {\n\tgetCachedResult,\n\tnormalizeCacheKey,\n\tsetCachedResult,\n} from \"./cache.js\";\nimport { normalizePlatform, TREND_VERSION_COUNT } from \"./defaults.js\";\nimport { config } from \"./parse.js\";\nimport {\n\tanalyzeTrend,\n\trenderTrendGraph,\n\tselectTrendVersions,\n} from \"./trend.js\";\nimport { fetchPackageVersions, promptForVersion } from \"./versions.js\";\n\nconst flags = config.flags;\nconst parameters = config.parameters;\n\n// Disable kleur colors when --boring flag is set\nkleur.enabled = !flags?.boring;\n\nconst log = new Logger({\n\tboring: flags?.boring,\n});\n\n/**\n * Display bundle result in a formatted box\n */\nfunction displayResult(\n\tresult: {\n\t\tpackageName: string;\n\t\tpackageVersion: string;\n\t\texports: string[];\n\t\trawSize: number;\n\t\tgzipSize: number | null;\n\t\tgzipLevel: number;\n\t\texternals: string[];\n\t\tdependencies: string[];\n\t\tplatform: \"browser\" | \"node\";\n\t},\n\tisAutoDetected: boolean,\n): void {\n\tconst blue = kleur.blue;\n\tconst green = kleur.green;\n\n\tconst platformLabel = result.platform === \"node\" ? \"node\" : \"browser\";\n\tconst platformNote = isAutoDetected ? \" (auto-detected)\" : \"\";\n\n\tlog.printBox(\n\t\t[\n\t\t\t`${blue(\"Package:\")} ${result.packageName} (${blue(\"version:\")} ${result.packageVersion})`,\n\t\t\tresult.exports.length > 0\n\t\t\t\t? `${blue(\"Exports:\")} { ${result.exports.join(\", \")} }`\n\t\t\t\t: `${blue(\"Exports:\")} * (entire package)`,\n\t\t\t\"\",\n\t\t\t`${blue(\"Raw size:\")} ${formatBytes(result.rawSize)}`,\n\t\t\tresult.gzipSize !== null\n\t\t\t\t? `${blue(\"Gzip size:\")} ${formatBytes(result.gzipSize)} (level ${result.gzipLevel})`\n\t\t\t\t: `${blue(\"Gzip size:\")} N/A (not applicable for node platform)`,\n\t\t\t\"\",\n\t\t\tresult.externals.length > 0\n\t\t\t\t? `${blue(\"Externals:\")} ${result.externals.join(\", \")}`\n\t\t\t\t: `${blue(\"Externals:\")} ${green(\"none\")}`,\n\t\t\tresult.dependencies.length > 0\n\t\t\t\t? `${blue(\"Dependencies:\")} ${result.dependencies.join(\", \")}`\n\t\t\t\t: `${blue(\"Dependencies:\")} ${green(\"none\")}`,\n\t\t\t`${blue(\"Platform:\")} ${platformLabel}${platformNote}`,\n\t\t],\n\t\t{\n\t\t\tborderStyle: \"round\",\n\t\t\talign: \"left\",\n\t\t},\n\t);\n}\n\nasync function main() {\n\tlet packageName = parameters?.[\"0\"];\n\n\tif (!packageName) {\n\t\tlog.error(\"Package name is required\");\n\t\tconfig.showHelp?.();\n\t\tprocess.exit(1);\n\t}\n\n\t// Parse additional externals if provided (comma-separated)\n\tlet additionalExternals: string[] | undefined;\n\tif (flags?.external) {\n\t\tadditionalExternals = flags.external\n\t\t\t.split(\",\")\n\t\t\t.map((e) => e.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\t// Parse exports if provided (comma-separated)\n\tlet exports: string[] | undefined;\n\tconst exportsArg = parameters?.[\"1\"];\n\tif (exportsArg) {\n\t\texports = exportsArg\n\t\t\t.split(\",\")\n\t\t\t.map((e) => e.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\t// Normalize platform from flag (handles aliases like \"web\" → \"browser\")\n\tconst platform = normalizePlatform(flags?.platform);\n\n\t// If --trend flag is set, show bundle size trend across versions\n\t// --trend alone uses default (5), --trend N uses N versions\n\tconst trendValue = flags?.trend;\n\tif (trendValue !== undefined) {\n\t\tconst parsedCount = Number.parseInt(trendValue, 10);\n\t\tconst versionCount =\n\t\t\t!Number.isNaN(parsedCount) && parsedCount > 0\n\t\t\t\t? parsedCount\n\t\t\t\t: TREND_VERSION_COUNT;\n\n\t\ttry {\n\t\t\tconst { name, subpath } = parsePackageSpecifier(packageName);\n\t\t\t// Construct the full package path including subpath if present\n\t\t\tconst fullPackagePath = subpath ? `${name}/${subpath}` : name;\n\n\t\t\tlog.info(`\\nFetching available versions for ${name}...`);\n\n\t\t\tconst { versions } = await fetchPackageVersions({\n\t\t\t\tpackageName,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\n\t\t\tif (versions.length === 0) {\n\t\t\t\tlog.error(\"No versions found for this package\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\t// Select versions for trend\n\t\t\tconst trendVersions = selectTrendVersions(versions, versionCount);\n\n\t\t\tlog.info(\n\t\t\t\t`Analyzing ${trendVersions.length} versions: ${trendVersions.join(\", \")}`,\n\t\t\t);\n\t\t\tlog.info(\"\");\n\n\t\t\tconst results = await analyzeTrend({\n\t\t\t\tpackageName: fullPackagePath,\n\t\t\t\tversions: trendVersions,\n\t\t\t\texports,\n\t\t\t\tadditionalExternals,\n\t\t\t\tnoExternal: flags?.noExternal,\n\t\t\t\tgzipLevel: flags?.gzipLevel,\n\t\t\t\tboring: flags?.boring,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t\tplatform,\n\t\t\t\tforce: flags?.force,\n\t\t\t});\n\n\t\t\tif (results.length === 0) {\n\t\t\t\tlog.error(\"Failed to analyze any versions\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\t// Render and display the trend graph\n\t\t\tconst graphLines = renderTrendGraph(\n\t\t\t\tfullPackagePath,\n\t\t\t\tresults,\n\t\t\t\tflags?.boring,\n\t\t\t);\n\t\t\tfor (const line of graphLines) {\n\t\t\t\tlog.log(line);\n\t\t\t}\n\n\t\t\tprocess.exit(0);\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlog.error(`Failed to analyze trend: ${errorMessage}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\t// If --versions flag is set, fetch and prompt for version selection\n\tif (flags?.versions) {\n\t\ttry {\n\t\t\tconst { name, subpath } = parsePackageSpecifier(packageName);\n\t\t\tlog.info(`\\nFetching available versions for ${name}...`);\n\n\t\t\tconst { versions, tags } = await fetchPackageVersions({\n\t\t\t\tpackageName,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\n\t\t\tif (versions.length === 0) {\n\t\t\t\tlog.error(\"No versions found for this package\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tconst selectedVersion = await promptForVersion(name, versions, tags);\n\t\t\t// Rebuild specifier preserving any subpath\n\t\t\tpackageName = subpath\n\t\t\t\t? `${name}/${subpath}@${selectedVersion}`\n\t\t\t\t: `${name}@${selectedVersion}`;\n\t\t\tlog.info(`\\nSelected: ${packageName}`);\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlog.error(`Failed to fetch versions: ${errorMessage}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tlog.info(`\\nAnalyzing bundle size for: ${packageName}`);\n\tif (exports && exports.length > 0) {\n\t\tlog.info(`Exports: { ${exports.join(\", \")} }`);\n\t}\n\n\ttry {\n\t\t// Parse package specifier to get name and version\n\t\tconst { name: baseName, version: requestedVersion } =\n\t\t\tparsePackageSpecifier(packageName);\n\n\t\t// Resolve \"latest\" to actual version for cache key\n\t\tlet resolvedVersion = requestedVersion;\n\t\tif (requestedVersion === \"latest\") {\n\t\t\tconst { tags } = await fetchPackageVersions({\n\t\t\t\tpackageName: baseName,\n\t\t\t\tregistry: flags?.registry,\n\t\t\t});\n\t\t\tresolvedVersion = tags.latest || requestedVersion;\n\t\t}\n\n\t\t// Compute externals for cache key (same logic as bundler)\n\t\tconst externals = getExternals(\n\t\t\tbaseName,\n\t\t\tadditionalExternals,\n\t\t\tflags?.noExternal,\n\t\t);\n\n\t\t// Build cache key\n\t\t// Note: platform can be undefined (auto-detect), which is stored as \"auto\" in cache\n\t\tconst cacheKey = normalizeCacheKey({\n\t\t\tpackageName: baseName,\n\t\t\tversion: resolvedVersion,\n\t\t\texports,\n\t\t\tplatform,\n\t\t\tgzipLevel: flags?.gzipLevel ?? 5,\n\t\t\texternals,\n\t\t\tnoExternal: flags?.noExternal ?? false,\n\t\t});\n\n\t\t// Check cache (unless --force flag is set)\n\t\tif (!flags?.force) {\n\t\t\tconst cached = getCachedResult(cacheKey);\n\t\t\tif (cached) {\n\t\t\t\tlog.info(\"NOTE: Using cached results\\n\");\n\t\t\t\tdisplayResult(cached, platform === undefined);\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t}\n\n\t\tlog.info(\"Please wait, installing and bundling...\\n\");\n\n\t\tconst result = await checkBundleSize({\n\t\t\tpackageName,\n\t\t\texports,\n\t\t\tadditionalExternals,\n\t\t\tnoExternal: flags?.noExternal,\n\t\t\tgzipLevel: flags?.gzipLevel,\n\t\t\tregistry: flags?.registry,\n\t\t\tplatform,\n\t\t});\n\n\t\t// Store result in cache\n\t\tsetCachedResult(cacheKey, result);\n\n\t\tdisplayResult(result, platform === undefined);\n\n\t\tprocess.exit(0);\n\t} catch (error) {\n\t\tconst errorMessage = error instanceof Error ? error.message : String(error);\n\t\tlog.error(`Failed to analyze bundle size: ${errorMessage}`);\n\t\tprocess.exit(1);\n\t}\n}\n\nmain();\n"],"names":["Logger","kleur","checkBundleSize","formatBytes","getExternals","parsePackageSpecifier","getCachedResult","normalizeCacheKey","setCachedResult","normalizePlatform","TREND_VERSION_COUNT","config","analyzeTrend","renderTrendGraph","selectTrendVersions","fetchPackageVersions","promptForVersion","flags","parameters","enabled","boring","log","displayResult","result","isAutoDetected","blue","green","platformLabel","platform","platformNote","printBox","packageName","packageVersion","exports","length","join","rawSize","gzipSize","gzipLevel","externals","dependencies","borderStyle","align","main","error","showHelp","process","exit","additionalExternals","external","split","map","e","trim","filter","Boolean","exportsArg","trendValue","trend","undefined","parsedCount","Number","parseInt","versionCount","isNaN","name","subpath","fullPackagePath","info","versions","registry","trendVersions","results","noExternal","force","graphLines","line","errorMessage","Error","message","String","tags","selectedVersion","baseName","version","requestedVersion","resolvedVersion","latest","cacheKey","cached"],"mappings":";AAEA,wBAAwB,GAExB,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,WAAW,QAAQ;AAC1B,SACCC,eAAe,EACfC,WAAW,EACXC,YAAY,EACZC,qBAAqB,QACf,eAAe;AACtB,SACCC,eAAe,EACfC,iBAAiB,EACjBC,eAAe,QACT,aAAa;AACpB,SAASC,iBAAiB,EAAEC,mBAAmB,QAAQ,gBAAgB;AACvE,SAASC,MAAM,QAAQ,aAAa;AACpC,SACCC,YAAY,EACZC,gBAAgB,EAChBC,mBAAmB,QACb,aAAa;AACpB,SAASC,oBAAoB,EAAEC,gBAAgB,QAAQ,gBAAgB;AAEvE,MAAMC,QAAQN,OAAOM,KAAK;AAC1B,MAAMC,aAAaP,OAAOO,UAAU;AAEpC,iDAAiD;AACjDjB,MAAMkB,OAAO,GAAG,CAACF,OAAOG;AAExB,MAAMC,MAAM,IAAIrB,OAAO;IACtBoB,QAAQH,OAAOG;AAChB;AAEA;;CAEC,GACD,SAASE,cACRC,MAUC,EACDC,cAAuB;IAEvB,MAAMC,OAAOxB,MAAMwB,IAAI;IACvB,MAAMC,QAAQzB,MAAMyB,KAAK;IAEzB,MAAMC,gBAAgBJ,OAAOK,QAAQ,KAAK,SAAS,SAAS;IAC5D,MAAMC,eAAeL,iBAAiB,qBAAqB;IAE3DH,IAAIS,QAAQ,CACX;QACC,GAAGL,KAAK,YAAY,CAAC,EAAEF,OAAOQ,WAAW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YACAE;YACAe;YACAyB,YAAYxD,OAAOwD;YACnBnC,WAAWrB,OAAOqB;YAClBgC,UAAUrD,OAAOqD;YACjB1C;QACD;QAEA,wBAAwB;QACxBpB,gBAAgBgF,UAAUjE;QAE1BD,cAAcC,QAAQK,aAAa+B;QAEnCb,QAAQC,IAAI,CAAC;IACd,EAAE,OAAOH,OAAO;QACf,MAAMiC,eAAejC,iBAAiBkC,QAAQlC,MAAMmC,OAAO,GAAGC,OAAOpC;QACrEvB,IAAIuB,KAAK,CAAC,CAAC,+BAA+B,EAAEiC,cAAc;QAC1D/B,QAAQC,IAAI,CAAC;IACd;AACD;AAEAJ"}
|
package/dist/bundler.d.ts
CHANGED
|
@@ -19,16 +19,20 @@ export type BundleOptions = {
|
|
|
19
19
|
noExternal?: boolean;
|
|
20
20
|
gzipLevel?: number;
|
|
21
21
|
registry?: string;
|
|
22
|
+
/** Target platform. If undefined, auto-detects from package.json engines */
|
|
23
|
+
platform?: "browser" | "node";
|
|
22
24
|
};
|
|
23
25
|
export type BundleResult = {
|
|
24
26
|
packageName: string;
|
|
25
27
|
packageVersion: string;
|
|
26
28
|
exports: string[];
|
|
27
29
|
rawSize: number;
|
|
28
|
-
|
|
30
|
+
/** Gzip size in bytes, or null for node platform (gzip not applicable) */
|
|
31
|
+
gzipSize: number | null;
|
|
29
32
|
gzipLevel: number;
|
|
30
33
|
externals: string[];
|
|
31
34
|
dependencies: string[];
|
|
35
|
+
platform: "browser" | "node";
|
|
32
36
|
};
|
|
33
37
|
/**
|
|
34
38
|
* Format bytes to human-readable string
|
|
@@ -41,6 +45,10 @@ export type EntryContentOptions = {
|
|
|
41
45
|
allSubpaths?: string[];
|
|
42
46
|
exportToSubpath?: Map<string, string>;
|
|
43
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Get externals list based on options
|
|
50
|
+
*/
|
|
51
|
+
export declare function getExternals(packageName: string, externals?: string[], noExternal?: boolean): string[];
|
|
44
52
|
export type PackageExports = Record<string, string | {
|
|
45
53
|
import?: string;
|
|
46
54
|
types?: string;
|
|
@@ -51,6 +59,7 @@ export type PackageInfo = {
|
|
|
51
59
|
peerDependencies: Record<string, string>;
|
|
52
60
|
exports: PackageExports | null;
|
|
53
61
|
hasMainEntry: boolean;
|
|
62
|
+
engines: Record<string, string> | null;
|
|
54
63
|
};
|
|
55
64
|
/**
|
|
56
65
|
* Check the bundle size of an npm package
|
package/dist/bundler.js
CHANGED
|
@@ -208,7 +208,7 @@ let usePnpm = null;
|
|
|
208
208
|
}
|
|
209
209
|
/**
|
|
210
210
|
* Get externals list based on options
|
|
211
|
-
*/ function getExternals(packageName, externals, noExternal) {
|
|
211
|
+
*/ export function getExternals(packageName, externals, noExternal) {
|
|
212
212
|
if (noExternal) {
|
|
213
213
|
return [];
|
|
214
214
|
}
|
|
@@ -248,7 +248,8 @@ let usePnpm = null;
|
|
|
248
248
|
dependencies: pkgJson.dependencies || {},
|
|
249
249
|
peerDependencies: pkgJson.peerDependencies || {},
|
|
250
250
|
exports: pkgJson.exports || null,
|
|
251
|
-
hasMainEntry
|
|
251
|
+
hasMainEntry,
|
|
252
|
+
engines: pkgJson.engines || null
|
|
252
253
|
};
|
|
253
254
|
}
|
|
254
255
|
} catch {
|
|
@@ -259,7 +260,8 @@ let usePnpm = null;
|
|
|
259
260
|
dependencies: {},
|
|
260
261
|
peerDependencies: {},
|
|
261
262
|
exports: null,
|
|
262
|
-
hasMainEntry: true
|
|
263
|
+
hasMainEntry: true,
|
|
264
|
+
engines: null
|
|
263
265
|
};
|
|
264
266
|
}
|
|
265
267
|
/**
|
|
@@ -354,7 +356,7 @@ let usePnpm = null;
|
|
|
354
356
|
/**
|
|
355
357
|
* Check the bundle size of an npm package
|
|
356
358
|
*/ export async function checkBundleSize(options) {
|
|
357
|
-
const { packageName: packageSpecifier, exports, additionalExternals, noExternal, gzipLevel = 5, registry } = options;
|
|
359
|
+
const { packageName: packageSpecifier, exports, additionalExternals, noExternal, gzipLevel = 5, registry, platform: explicitPlatform } = options;
|
|
358
360
|
// Parse the package specifier to extract name, version, and subpath
|
|
359
361
|
const { name: packageName, version: requestedVersion, subpath } = parsePackageSpecifier(packageSpecifier);
|
|
360
362
|
const tmpDir = createTempDir();
|
|
@@ -375,9 +377,17 @@ let usePnpm = null;
|
|
|
375
377
|
cwd: tmpDir,
|
|
376
378
|
stdio: "pipe"
|
|
377
379
|
});
|
|
378
|
-
// Get package info (version, dependencies, peer dependencies, exports)
|
|
380
|
+
// Get package info (version, dependencies, peer dependencies, exports, engines)
|
|
379
381
|
const pkgInfo = getPackageInfo(tmpDir, packageName);
|
|
380
382
|
const peerDepKeys = Object.keys(pkgInfo.peerDependencies);
|
|
383
|
+
// Determine platform: use explicit value if provided, otherwise auto-detect from engines
|
|
384
|
+
let platform = "browser";
|
|
385
|
+
if (explicitPlatform) {
|
|
386
|
+
platform = explicitPlatform;
|
|
387
|
+
} else if (pkgInfo.engines?.node && !pkgInfo.engines?.browser) {
|
|
388
|
+
// Package specifies node engine without browser - likely a Node.js package
|
|
389
|
+
platform = "node";
|
|
390
|
+
}
|
|
381
391
|
// Collect all dependency names (prod + peer)
|
|
382
392
|
const allDependencies = [
|
|
383
393
|
...new Set([
|
|
@@ -439,7 +449,7 @@ let usePnpm = null;
|
|
|
439
449
|
bundle: true,
|
|
440
450
|
write: false,
|
|
441
451
|
format: "esm",
|
|
442
|
-
platform
|
|
452
|
+
platform,
|
|
443
453
|
target: "es2020",
|
|
444
454
|
minify: true,
|
|
445
455
|
treeShaking: true,
|
|
@@ -449,11 +459,14 @@ let usePnpm = null;
|
|
|
449
459
|
// Get raw size
|
|
450
460
|
const bundleContent = result.outputFiles[0].contents;
|
|
451
461
|
const rawSize = bundleContent.length;
|
|
452
|
-
// Gzip the bundle
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
462
|
+
// Gzip the bundle (only for browser platform - not relevant for Node.js)
|
|
463
|
+
let gzipSize = null;
|
|
464
|
+
if (platform === "browser") {
|
|
465
|
+
const gzipped = await gzipAsync(Buffer.from(bundleContent), {
|
|
466
|
+
level: gzipLevel
|
|
467
|
+
});
|
|
468
|
+
gzipSize = gzipped.length;
|
|
469
|
+
}
|
|
457
470
|
// Determine the display name
|
|
458
471
|
let displayName = packageName;
|
|
459
472
|
if (resolvedSubpath) {
|
|
@@ -473,7 +486,8 @@ let usePnpm = null;
|
|
|
473
486
|
gzipSize,
|
|
474
487
|
gzipLevel,
|
|
475
488
|
externals,
|
|
476
|
-
dependencies: allDependencies
|
|
489
|
+
dependencies: allDependencies,
|
|
490
|
+
platform
|
|
477
491
|
};
|
|
478
492
|
} finally{
|
|
479
493
|
cleanupTempDir(tmpDir);
|
package/dist/bundler.js.map
CHANGED
|
@@ -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 { DEFAULT_EXTERNALS } from \"./defaults.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// Now workingSpec is like @scope/name or @scope/name/subpath\n\t\t// Split by / and check if there are more than 2 parts\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};\n\nexport type BundleResult = {\n\tpackageName: string;\n\tpackageVersion: string;\n\texports: string[];\n\trawSize: number;\n\tgzipSize: number;\n\tgzipLevel: number;\n\texternals: string[];\n\tdependencies: string[];\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 * Get externals list based on options\n */\nfunction getExternals(\n\tpackageName: string,\n\texternals?: string[],\n\tnoExternal?: boolean,\n): string[] {\n\tif (noExternal) {\n\t\treturn [];\n\t}\n\n\t// Start with default externals (react, react-dom)\n\tlet result = [...DEFAULT_EXTERNALS];\n\n\t// If checking react or react-dom themselves, don't mark them as external\n\tif (packageName === \"react\") {\n\t\tresult = result.filter((e) => e !== \"react\");\n\t} else if (packageName === \"react-dom\") {\n\t\tresult = result.filter((e) => e !== \"react-dom\");\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\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};\n\n/**\n * Get version, dependencies, peer dependencies, and exports from an installed 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};\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};\n}\n\n/**\n * Extract subpath export names from package exports field\n * Returns array of 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\n * Reads type definition 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} = 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// Get package info (version, dependencies, peer dependencies, exports)\n\t\tconst pkgInfo = getPackageInfo(tmpDir, packageName);\n\t\tconst peerDepKeys = Object.keys(pkgInfo.peerDependencies);\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// Determine if we need to use all subpath exports or find the right subpath(s)\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// Get externals\n\t\tconst externals = getExternals(\n\t\t\tpackageName,\n\t\t\tadditionalExternals,\n\t\t\tnoExternal,\n\t\t);\n\n\t\t// Bundle with esbuild\n\t\tconst result = await esbuild.build({\n\t\t\tentryPoints: [entryFile],\n\t\t\tbundle: true,\n\t\t\twrite: false,\n\t\t\tformat: \"esm\",\n\t\t\tplatform: \"browser\",\n\t\t\ttarget: \"es2020\",\n\t\t\tminify: true,\n\t\t\ttreeShaking: true,\n\t\t\texternal: externals,\n\t\t\tmetafile: true,\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\n\t\tconst gzipped = await gzipAsync(Buffer.from(bundleContent), {\n\t\t\tlevel: gzipLevel,\n\t\t});\n\t\tconst gzipSize = gzipped.length;\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\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};\n\t} finally {\n\t\tcleanupTempDir(tmpDir);\n\t}\n}\n"],"names":["execSync","fs","os","path","promisify","zlib","esbuild","DEFAULT_EXTERNALS","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","getExternals","externals","noExternal","result","filter","e","Set","getPackageInfo","pkgJsonPath","existsSync","pkgJson","JSON","parse","readFileSync","hasMainEntry","Boolean","main","module","dependencies","peerDependencies","getSubpathExports","subpaths","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","requestedVersion","packageJson","type","writeFileSync","stringify","installCmd","cwd","pkgInfo","peerDepKeys","allDependencies","sort","dep","resolvedSubpath","mapping","entryContent","entryFile","build","entryPoints","bundle","write","format","platform","target","minify","treeShaking","external","metafile","bundleContent","outputFiles","contents","rawSize","gzipped","Buffer","from","level","gzipSize","displayName","uniqueSubpaths","packageVersion"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,qBAAqB;AAC9C,OAAOC,QAAQ,UAAU;AACzB,OAAOC,QA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AAG1G,YAAY,EAAE,EAAE2G,eAAelJ,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9D;QAEA,OAAO;YACNuC,aAAa0G;YACbE,gBAAgB/B,QAAQ/H,OAAO;YAC/BmD,SAASA,WAAW,EAAE;YACtBmG;YACAK;YACApC;YACA/C;YACAiB,cAAcwC;QACf;IACD,SAAU;QACTjG,eAAeN;IAChB;AACD"}
|
|
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 { DEFAULT_EXTERNALS } from \"./defaults.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// Now workingSpec is like @scope/name or @scope/name/subpath\n\t\t// Split by / and check if there are more than 2 parts\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/** Target platform. If undefined, auto-detects from package.json engines */\n\tplatform?: \"browser\" | \"node\";\n};\n\nexport type BundleResult = {\n\tpackageName: string;\n\tpackageVersion: string;\n\texports: string[];\n\trawSize: number;\n\t/** Gzip size in bytes, or null for node platform (gzip not applicable) */\n\tgzipSize: number | null;\n\tgzipLevel: number;\n\texternals: string[];\n\tdependencies: string[];\n\tplatform: \"browser\" | \"node\";\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 * Get externals list based on options\n */\nexport function getExternals(\n\tpackageName: string,\n\texternals?: string[],\n\tnoExternal?: boolean,\n): string[] {\n\tif (noExternal) {\n\t\treturn [];\n\t}\n\n\t// Start with default externals (react, react-dom)\n\tlet result = [...DEFAULT_EXTERNALS];\n\n\t// If checking react or react-dom themselves, don't mark them as external\n\tif (packageName === \"react\") {\n\t\tresult = result.filter((e) => e !== \"react\");\n\t} else if (packageName === \"react-dom\") {\n\t\tresult = result.filter((e) => e !== \"react-dom\");\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\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 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\n * Returns array of 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\n * Reads type definition 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} = 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// Get package info (version, dependencies, peer dependencies, exports, engines)\n\t\tconst pkgInfo = getPackageInfo(tmpDir, packageName);\n\t\tconst peerDepKeys = Object.keys(pkgInfo.peerDependencies);\n\n\t\t// Determine platform: use explicit value if provided, otherwise auto-detect from engines\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// Determine if we need to use all subpath exports or find the right subpath(s)\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// Get externals\n\t\tconst externals = getExternals(\n\t\t\tpackageName,\n\t\t\tadditionalExternals,\n\t\t\tnoExternal,\n\t\t);\n\n\t\t// Bundle with esbuild\n\t\tconst result = await esbuild.build({\n\t\t\tentryPoints: [entryFile],\n\t\t\tbundle: true,\n\t\t\twrite: false,\n\t\t\tformat: \"esm\",\n\t\t\tplatform,\n\t\t\ttarget: \"es2020\",\n\t\t\tminify: true,\n\t\t\ttreeShaking: true,\n\t\t\texternal: externals,\n\t\t\tmetafile: true,\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\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};\n\t} finally {\n\t\tcleanupTempDir(tmpDir);\n\t}\n}\n"],"names":["execSync","fs","os","path","promisify","zlib","esbuild","DEFAULT_EXTERNALS","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","getExternals","externals","noExternal","result","filter","e","Set","getPackageInfo","pkgJsonPath","existsSync","pkgJson","JSON","parse","readFileSync","hasMainEntry","Boolean","main","module","dependencies","peerDependencies","engines","getSubpathExports","subpaths","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","requestedVersion","packageJson","type","writeFileSync","stringify","installCmd","cwd","pkgInfo","peerDepKeys","node","browser","allDependencies","sort","dep","resolvedSubpath","mapping","entryContent","entryFile","build","entryPoints","bundle","write","format","target","minify","treeShaking","external","metafile","bundleContent","outputFiles","contents","rawSize","gzipSize","gzipped","Buffer","from","level","displayName","uniqueSubpaths","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,SAASC,iBAAiB,QAAQ,gBAAgB;AAElD,MAAMC,YAAYJ,UAAUC,KAAKI,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,iDAAiD;QACjD,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,6DAA6D;QAC7D,sDAAsD;QACtD,MAAMG,QAAQN,YAAYO,KAAK,CAAC;QAChC,IAAID,MAAME,MAAM,GAAG,GAAG;YACrB,wCAAwC;YACxC,MAAMC,OAAO,GAAGH,KAAK,CAAC,EAAE,CAAC,CAAC,EAAEA,KAAK,CAAC,EAAE,EAAE;YACtC,MAAMI,UAAUJ,MAAMK,KAAK,CAAC,GAAGC,IAAI,CAAC;YACpC,OAAO;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