bundle

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Read(r io.Reader, ownLimit int64) (src []byte, packages []string, ok bool, err error)

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

func Split

func Split(src []byte) (Result, bool)

Split finds the modules of a bundle and blanks the ones from node_modules. It reports false when src has no node_modules module marker, so it is not a bundle this package can read.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL