Documentation
¶
Overview ¶
Package bundle reads a JavaScript bundle in esbuild's output shape - tsup and other tools built on esbuild write the same - where every bundled module opens with a comment line holding the path the bundler resolved it from:
// ../../node_modules/zod/v3/types.js ... // src/tools/run_command.ts
A published package is often only such a bundle: the server's own modules after megabytes of its dependencies. Blanking the modules whose path runs through node_modules leaves the server's own code, which is what a scan of its repository reads too, since that scan skips node_modules directories. Blanking keeps every byte offset and line number: each byte of a dependency module becomes a space and every newline stays, so a finding points at the bundle's real line and any reader of the raw file sees the same text at the same place.
A module marker is only a comment, so a package can put one in front of its own code to have it blanked. The blanked modules are therefore reported as excluded code, like a node_modules directory, and never support a clean verdict.
Index ¶
Constants ¶
const MaxSize = 32 << 20
MaxSize bounds the bundle read whole to look for module markers; a larger file is read only up to the per-file limit, as any other oversized file
Variables ¶
This section is empty.
Functions ¶
func Read ¶
Read reads a file the inventory accepted as a bundle - at most MaxSize bytes - and blanks its node_modules modules. A file that no longer reads as a bundle whose own part fits ownLimit, because it changed after the walk looked at it, comes back as its first ownLimit bytes, the way any oversized file is read, and ok is false so the caller can report the truncation.
Types ¶
type Result ¶
type Result struct {
// Masked is the bundle, the same length as the input, with every byte of a node_modules
// module except newlines turned into a space
Masked []byte
// ThirdParty and Own count the modules blanked and the modules kept
ThirdParty int
Own int
// OwnBytes is how much of the bundle was kept: the modules outside node_modules and anything
// before the first marker (the bundler's helpers, a shebang)
OwnBytes int64
// Packages are the distinct npm packages the blanked modules came from, such as
// "@modelcontextprotocol/sdk" or "zod"
Packages []string
}
Result is a bundle with its dependency modules blanked