utils

package
v1.3.19-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildNpmUploadFromPackageJSON

func BuildNpmUploadFromPackageJSON(pkgJSON []byte, readme string, file io.ReadCloser) (*npm.PackageUpload, string, string, error)

func ExtractPackageJSONAndReadmeFromTarball added in v1.3.10

func ExtractPackageJSONAndReadmeFromTarball(file io.ReadCloser) ([]byte, string, error)

ExtractPackageJSONAndReadmeFromTarball extracts the root-level package.json and README file from an npm tarball. The readme is optional — if not found, an empty string is returned.

func ResolveFilePath added in v1.3.5

func ResolveFilePath(pattern string, extensions ...string) ([]string, error)

ResolveFilePath resolves a file path pattern (supports glob wildcards and regex). If the pattern contains wildcards/regex, it returns all matching files. If no wildcards, it returns the path as-is after validating it exists. Optional extensions filter can be provided to only include files with specific extensions.

func SetChecksumHeaders added in v1.3.19

func SetChecksumHeaders(h http.Header, c FileChecksums)

SetChecksumHeaders sets X-Checksum-{Md5,Sha1,Sha256,Sha512} headers on h for any non-empty digest in c.

Types

type FileChecksums added in v1.3.19

type FileChecksums struct {
	MD5    string
	SHA1   string
	SHA256 string
	SHA512 string
}

FileChecksums holds hex-encoded digests of a file.

func ChecksumHeadersForFile added in v1.3.19

func ChecksumHeadersForFile(path string) (http.Header, FileChecksums, error)

ChecksumHeadersForFile is a convenience helper that computes file checksums and returns an http.Header pre-populated with X-Checksum-* entries.

func ComputeFileChecksums added in v1.3.19

func ComputeFileChecksums(path string) (FileChecksums, error)

ComputeFileChecksums computes MD5, SHA-1, SHA-256 and SHA-512 of the file at path in a single read pass and returns them hex-encoded.

type MinimalPackageJSON

type MinimalPackageJSON struct {
	Name                 string      `json:"name"`
	Version              string      `json:"version"`
	Description          interface{} `json:"description"`
	Homepage             interface{} `json:"homepage"`
	Keywords             []string    `json:"keywords"`
	Repository           interface{} `json:"repository"`
	Author               interface{} `json:"author"`
	License              interface{} `json:"license"`
	Dependencies         interface{} `json:"dependencies"`
	DevDependencies      interface{} `json:"devDependencies"`
	PeerDependencies     interface{} `json:"peerDependencies"`
	PeerDependenciesMeta interface{} `json:"peerDependenciesMeta"`
	OptionalDependencies interface{} `json:"optionalDependencies"`
	AcceptDependencies   interface{} `json:"acceptDependencies"`
	BundleDependencies   interface{} `json:"bundleDependencies"`
	Bin                  interface{} `json:"bin"`
	Contributors         interface{} `json:"contributors"`
	Bugs                 interface{} `json:"bugs"`
	Engines              interface{} `json:"engines"`
	Deprecated           interface{} `json:"deprecated"`
	Directories          interface{} `json:"directories"`
	Funding              interface{} `json:"funding"`
	CPU                  interface{} `json:"cpu"`
	OS                   interface{} `json:"os"`
	Main                 interface{} `json:"main"`
	Module               interface{} `json:"module"`
	Types                interface{} `json:"types"`
	Typings              interface{} `json:"typings"`
	Exports              interface{} `json:"exports"`
	Imports              interface{} `json:"imports"`
	Files                interface{} `json:"files"`
	Workspaces           interface{} `json:"workspaces"`
	Scripts              interface{} `json:"scripts"`
	Config               interface{} `json:"config"`
	PublishConfig        interface{} `json:"publishConfig"`
	SideEffects          interface{} `json:"sideEffects"`
	HasShrinkwrap        interface{} `json:"_hasShrinkwrap"`
	HasInstallScript     interface{} `json:"hasInstallScript"`
	NodeVersion          interface{} `json:"_nodeVersion"`
	NpmUser              interface{} `json:"_npmUser"`
	NpmVersion           interface{} `json:"_npmVersion"`
}

MinimalPackageJSON represents the subset of fields from package.json we care about. Fields use interface{} to match PackageMetadataVersion and avoid parse failures when package.json contains unexpected types (e.g. description as array, dependency values as objects for workspace/override references).

Jump to

Keyboard shortcuts

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