packagejson

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DependencyFields

type DependencyFields struct {
	Dependencies         Expected[map[string]string] `json:"dependencies"`
	DevDependencies      Expected[map[string]string] `json:"devDependencies"`
	PeerDependencies     Expected[map[string]string] `json:"peerDependencies"`
	OptionalDependencies Expected[map[string]string] `json:"optionalDependencies"`
}

func (*DependencyFields) GetRuntimeDependencyNames

func (df *DependencyFields) GetRuntimeDependencyNames() *collections.Set[string]

func (*DependencyFields) HasDependency

func (df *DependencyFields) HasDependency(name string) bool

HasDependency returns true if the package.json has a dependency with the given name under any of the dependency fields (dependencies, devDependencies, peerDependencies, optionalDependencies).

func (*DependencyFields) RangeDependencies

func (df *DependencyFields) RangeDependencies(f func(name, version, dependencyField string) bool)

type Expected

type Expected[T any] struct {
	Null  bool
	Valid bool
	Value T
	// contains filtered or unexported fields
}

func ExpectedOf

func ExpectedOf[T any](value T) Expected[T]

func (*Expected[T]) ActualJSONType

func (e *Expected[T]) ActualJSONType() string

func (*Expected[T]) ExpectedJSONType

func (e *Expected[T]) ExpectedJSONType() string

func (*Expected[T]) GetValue

func (e *Expected[T]) GetValue() (value T, ok bool)

func (*Expected[T]) IsPresent

func (e *Expected[T]) IsPresent() bool

func (*Expected[T]) IsValid

func (e *Expected[T]) IsValid() bool

func (*Expected[T]) UnmarshalJSON

func (e *Expected[T]) UnmarshalJSON(data []byte) error

type ExportsOrImports

type ExportsOrImports struct {
	JSONValue
	// contains filtered or unexported fields
}

func (ExportsOrImports) AsArray

func (e ExportsOrImports) AsArray() []ExportsOrImports

func (ExportsOrImports) AsObject

func (ExportsOrImports) IsConditions

func (e ExportsOrImports) IsConditions() bool

func (ExportsOrImports) IsImports

func (e ExportsOrImports) IsImports() bool

func (ExportsOrImports) IsSubpaths

func (e ExportsOrImports) IsSubpaths() bool

func (*ExportsOrImports) UnmarshalJSONFrom

func (e *ExportsOrImports) UnmarshalJSONFrom(dec *json.Decoder) error

type Fields

type Fields struct {
	HeaderFields
	PathFields
	DependencyFields
}

func Parse

func Parse(data []byte) (Fields, error)

type HeaderFields

type HeaderFields struct {
	Name    Expected[string] `json:"name"`
	Version Expected[string] `json:"version"`
	Type    Expected[string] `json:"type"`
}

type InfoCache

type InfoCache struct {
	// contains filtered or unexported fields
}

func NewInfoCache

func NewInfoCache(currentDirectory string, useCaseSensitiveFileNames bool) *InfoCache

func (*InfoCache) Get

func (p *InfoCache) Get(packageJsonPath string) *InfoCacheEntry

func (*InfoCache) Range added in v0.22.0

func (p *InfoCache) Range(f func(key tspath.Path, value *InfoCacheEntry) bool)

func (*InfoCache) Set

func (p *InfoCache) Set(packageJsonPath string, info *InfoCacheEntry) *InfoCacheEntry

type InfoCacheEntry

type InfoCacheEntry struct {
	PackageDirectory string
	DirectoryExists  bool
	Contents         *PackageJson
}

func (*InfoCacheEntry) Exists

func (p *InfoCacheEntry) Exists() bool

func (*InfoCacheEntry) GetContents

func (p *InfoCacheEntry) GetContents() *PackageJson

func (*InfoCacheEntry) GetDirectory

func (p *InfoCacheEntry) GetDirectory() string

func (*InfoCacheEntry) WithPackageDirectory added in v0.22.0

func (p *InfoCacheEntry) WithPackageDirectory(packageDirectory string) *InfoCacheEntry

WithPackageDirectory returns an entry whose PackageDirectory matches the caller's value. The package.json info cache is keyed by the canonical path of the package.json file, but multiple callers may look up the same package.json using directory paths that differ only by a trailing separator (e.g. "node_modules/preact/compat" vs "node_modules/preact/compat/"). Because the cache uses first-writer-wins semantics, a later caller may receive an entry whose PackageDirectory doesn't match its own candidate path. Downstream code compares the candidate against PackageDirectory, so we must return a corrected shallow copy when they diverge. See https://github.com/microsoft/TypeScript/pull/50740.

type JSONValue

type JSONValue struct {
	Type  JSONValueType
	Value any
}

func (JSONValue) AsArray

func (v JSONValue) AsArray() []JSONValue

func (JSONValue) AsObject

func (JSONValue) AsString

func (v JSONValue) AsString() string

func (*JSONValue) IsFalsy

func (v *JSONValue) IsFalsy() bool

func (*JSONValue) IsPresent

func (v *JSONValue) IsPresent() bool

func (*JSONValue) UnmarshalJSONFrom

func (v *JSONValue) UnmarshalJSONFrom(dec *json.Decoder) error

type JSONValueType

type JSONValueType int8
const (
	JSONValueTypeNotPresent JSONValueType = iota
	JSONValueTypeNull
	JSONValueTypeString
	JSONValueTypeNumber
	JSONValueTypeBoolean
	JSONValueTypeArray
	JSONValueTypeObject
)

func (JSONValueType) String

func (t JSONValueType) String() string

type PackageJson

type PackageJson struct {
	Fields
	Parseable bool
	// contains filtered or unexported fields
}

func (*PackageJson) GetVersionPaths

func (p *PackageJson) GetVersionPaths(trace func(m *diagnostics.Message, args ...any)) VersionPaths

type PathFields

type PathFields struct {
	TSConfig      Expected[string] `json:"tsconfig"`
	Main          Expected[string] `json:"main"`
	Types         Expected[string] `json:"types"`
	Typings       Expected[string] `json:"typings"`
	TypesVersions JSONValue        `json:"typesVersions"`
	Imports       ExportsOrImports `json:"imports"`
	Exports       ExportsOrImports `json:"exports"`
}

type TypeValidatedField

type TypeValidatedField interface {
	IsPresent() bool
	IsValid() bool
	ExpectedJSONType() string
	ActualJSONType() string
}

type VersionPaths

type VersionPaths struct {
	Version string
	// contains filtered or unexported fields
}

func (*VersionPaths) Exists

func (v *VersionPaths) Exists() bool

func (*VersionPaths) GetPaths

func (v *VersionPaths) GetPaths() *collections.OrderedMap[string, []string]

Jump to

Keyboard shortcuts

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