How vercel/pkg works
pkg is a CLI that turns a Node.js project into a standalone executable for selected Node versions, platforms, and architectures. Its principal workflow resolves the requested entrypoint and configuration, discovers dependencies and assets, prepares package records, and produces an executable using a target Node binary. The README also documents bytecode generation, compression, and cross-platform builds. Edges reflect the excerpts, source-index references, or README; the prelude’s runtime role is documented only indirectly, so its connection is unverified.
Main entry points: index.ts Packaging Orchestrator · walker.ts Dependency Walker · producer.ts Executable Producer · bin.ts CLI Launcher
Components 16
CLI and Inputs
- CLI Launcher
lib/bin.ts - Packaging Orchestrator
lib/index.ts - CLI Help
lib/help.ts - Path and Snapshot Utilities
lib/common.ts
Dependency Discovery
- Dependency Walker
lib/walker.ts - Source Detector
lib/detector.ts - File Resolver
lib/follow.ts - Record Refiner
lib/refiner.ts
Executable Packaging
- Content Packer
lib/packer.ts - Executable Producer
lib/producer.ts - Bytecode Fabricator
lib/fabricator.ts - Compression Options
lib/compress_type.ts
Packaged Runtime
- Snapshot Runtime Prelude
prelude/bootstrap.js - Runtime Diagnostics
prelude/diagnostic.js
Other components
- CLI User
- Target Node Binary
Connections 14
- CLI User → CLI Launcher: invokes
- CLI Launcher → Packaging Orchestrator: starts
lib/bin.ts - Packaging Orchestrator → CLI Help: loads help
lib/index.ts - Packaging Orchestrator → Dependency Walker: discovers files
lib/index.ts - Dependency Walker → Source Detector: analyzes source
lib/walker.ts - Dependency Walker → File Resolver: resolves paths
lib/walker.ts - Packaging Orchestrator → Record Refiner: refines records
lib/index.ts - Packaging Orchestrator → Content Packer: packs records
lib/index.ts - Packaging Orchestrator → Executable Producer: produces executable
lib/index.ts - Executable Producer → Bytecode Fabricator: generates bytecode
lib/producer.ts - Packaging Orchestrator → Target Node Binary: fetches target
lib/index.ts - Packaging Orchestrator → Compression Options: reads option
lib/index.ts - Executable Producer → Snapshot Runtime Prelude: embeds runtime
- Snapshot Runtime Prelude → Runtime Diagnostics: uses diagnostics