web_pkg

package
v0.51.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyPkgID is returned if the package ID is empty.
	ErrEmptyPkgID = errors.New("package id cannot be empty")
	// ErrInvalidPkgID is returned if the package id is invalid.
	ErrInvalidPkgID = errors.New("package id is invalid")
)
View Source
var PkgNameRe = regexp.MustCompile(`^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$`)

PkgNameRe is a regex that can be used to check for valid package names. https://github.com/dword-design/package-name-regex/blob/2899905/src/index.js

Functions

func CheckStripWebPkgIdPrefix

func CheckStripWebPkgIdPrefix(pkgPath string) (pkgID, pkgSubPath string, err error)

CheckStripWebPkgIdPrefix checks and strips a web pkg id prefix from a path.

Returns the web pkg id and the pkg path split.

func ResolveWebPkgEntrypoints

func ResolveWebPkgEntrypoints(
	pkgRoot string,
	entrypoints []WebPkgEntrypointConfig,
) ([]string, error)

ResolveWebPkgEntrypoints resolves the entry points for a web package into file paths relative to pkgRoot.

For project-local packages (no package.json with exports):

  • Uses configured entrypoints, or defaults to ["."].
  • "." resolves to the root index file.
  • "./foo" resolves to foo.ts, foo.tsx, foo/index.ts, etc.

For node_modules packages (has package.json with exports or main):

  • Uses configured entrypoints if set.
  • Otherwise reads package.json exports field to discover entry points.
  • Falls back to main field or index.js.

func SortWebPkgRefs

func SortWebPkgRefs(refs []*WebPkgRef)

SortWebPkgRefs sorts the list of refs by web pkg id.

func ValidateWebPkgId

func ValidateWebPkgId(id string) error

ValidateWebPkgId validates a web package identifier. Follows the npm package name validation scheme.

Types

type LookupWebPkg

type LookupWebPkg interface {
	// Directive indicates LookupWebPkg is a directive.
	directive.Directive

	// LookupWebPkgID is the web package ID to lookup.
	// E.x.: "react" or "react-dom" or "@myorg/mypkg".
	// Cannot be empty.
	LookupWebPkgID() string
}

LookupWebPkg is a directive to lookup a WebPkg.

func NewLookupWebPkg

func NewLookupWebPkg(webPkgID string) LookupWebPkg

NewLookupWebPkg constructs a new LookupWebPkg directive.

type LookupWebPkgValue

type LookupWebPkgValue = WebPkg

LookupWebPkgValue is the result of LookupWebPkg.

func ExLookupWebPkg

func ExLookupWebPkg(
	ctx context.Context,
	b bus.Bus,
	returnIfIdle bool,
	webPkgID string,
) (LookupWebPkgValue, directive.Instance, directive.Reference, error)

ExLookupWebPkg looks up a web pkg by id.

type WebPkg

type WebPkg interface {
	// GetId returns the web package identifier.
	GetId() string
	// GetInfo returns the WebPkgInfo for the WebPkg.
	GetInfo(ctx context.Context) (*WebPkgInfo, error)
	// GetWebPkgFsHandle returns an fs handle which can be used to access the WebPkg fs.
	// Remember to release the handle when done.
	GetWebPkgFsHandle(ctx context.Context) (*unixfs.FSHandle, error)
}

WebPkg is a service serving files for a web package (abbreviated pkg). The web package ID is equivalent to the npm package ID (i.e. "@myorg/mypkg").

type WebPkgEntrypointConfig

type WebPkgEntrypointConfig struct {
	// Path is the subpath export specifier (e.g. ".", "./object").
	Path string
}

WebPkgEntrypointConfig is the subset of entrypoint config needed for resolution. Avoids importing web/bundler proto types to prevent import cycles.

type WebPkgInfo

type WebPkgInfo struct {

	// Id is the web package identifier.
	// Usually matches the npm package name.
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// contains filtered or unexported fields
}

WebPkgInfo is information about a WebPkg.

func (*WebPkgInfo) CloneMessageVT

func (m *WebPkgInfo) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*WebPkgInfo) CloneVT

func (m *WebPkgInfo) CloneVT() *WebPkgInfo

func (*WebPkgInfo) EqualMessageVT

func (this *WebPkgInfo) EqualMessageVT(thatMsg any) bool

func (*WebPkgInfo) EqualVT

func (this *WebPkgInfo) EqualVT(that *WebPkgInfo) bool

func (*WebPkgInfo) GetId

func (x *WebPkgInfo) GetId() string

func (*WebPkgInfo) MarshalJSON

func (x *WebPkgInfo) MarshalJSON() ([]byte, error)

MarshalJSON marshals the WebPkgInfo to JSON.

func (*WebPkgInfo) MarshalProtoJSON

func (x *WebPkgInfo) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the WebPkgInfo message to JSON.

func (*WebPkgInfo) MarshalProtoText

func (x *WebPkgInfo) MarshalProtoText() string

func (*WebPkgInfo) MarshalToSizedBufferVT

func (m *WebPkgInfo) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*WebPkgInfo) MarshalToVT

func (m *WebPkgInfo) MarshalToVT(dAtA []byte) (int, error)

func (*WebPkgInfo) MarshalVT

func (m *WebPkgInfo) MarshalVT() (dAtA []byte, err error)

func (*WebPkgInfo) ProtoMessage

func (*WebPkgInfo) ProtoMessage()

func (*WebPkgInfo) Reset

func (x *WebPkgInfo) Reset()

func (*WebPkgInfo) SizeVT

func (m *WebPkgInfo) SizeVT() (n int)

func (*WebPkgInfo) String

func (x *WebPkgInfo) String() string

func (*WebPkgInfo) UnmarshalJSON

func (x *WebPkgInfo) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the WebPkgInfo from JSON.

func (*WebPkgInfo) UnmarshalProtoJSON

func (x *WebPkgInfo) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the WebPkgInfo message from JSON.

func (*WebPkgInfo) UnmarshalVT

func (m *WebPkgInfo) UnmarshalVT(dAtA []byte) error

type WebPkgRef

type WebPkgRef struct {

	// WebPkgId is the web pkg identifier.
	WebPkgId string `protobuf:"bytes,1,opt,name=web_pkg_id,json=webPkgId,proto3" json:"webPkgId,omitempty"`
	// WebPkgRoot is the path to the web pkg root dir relative to project root.
	WebPkgRoot string `protobuf:"bytes,2,opt,name=web_pkg_root,json=webPkgRoot,proto3" json:"webPkgRoot,omitempty"`
	// Imports is the list of paths that were imported from the web pkg.
	Imports []string `protobuf:"bytes,3,rep,name=imports,proto3" json:"imports,omitempty"`
	// CrossRefs is the list of other web pkgs that this pkg imports.
	// NOTE: this is not filled unless ResolveWebPkgRefsEsbuild is called.
	CrossRefs []string `protobuf:"bytes,4,rep,name=cross_refs,json=crossRefs,proto3" json:"crossRefs,omitempty"`
	// contains filtered or unexported fields
}

WebPkgRef contains information about references to a web pkg.

func FindWebPkgRef

func FindWebPkgRef(sl []*WebPkgRef, webPkgID string) (*WebPkgRef, int)

FindWebPkgRef finds the web pkg ref with the given web pkg id.

Returns the index or -1 if not found.

func ResolveWebPkgRefsFromConfig

func ResolveWebPkgRefsFromConfig(
	codeRootPath string,
	pkgConfigs []WebPkgResolveConfig,
	viteRefs []*WebPkgRef,
	excludedIDs map[string]struct{},
) ([]*WebPkgRef, error)

ResolveWebPkgRefsFromConfig builds WebPkgRef entries from config and Vite-discovered roots. Entry points are resolved from config (entrypoints field or package.json exports) rather than regex-discovered subpaths.

viteRefs provides package roots discovered by the Vite plugin during the main build. These are used to determine the filesystem root for each package. Packages not found in viteRefs are resolved via node_modules.

configEntrypoints maps web pkg ID to its entrypoint configs (from WebPkgRefConfig.Entrypoints). Pass nil for packages that should use defaults.

func (*WebPkgRef) CloneMessageVT

func (m *WebPkgRef) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*WebPkgRef) CloneVT

func (m *WebPkgRef) CloneVT() *WebPkgRef

func (*WebPkgRef) EqualMessageVT

func (this *WebPkgRef) EqualMessageVT(thatMsg any) bool

func (*WebPkgRef) EqualVT

func (this *WebPkgRef) EqualVT(that *WebPkgRef) bool

func (*WebPkgRef) GetCrossRefs

func (x *WebPkgRef) GetCrossRefs() []string

func (*WebPkgRef) GetImports

func (x *WebPkgRef) GetImports() []string

func (*WebPkgRef) GetWebPkgId

func (x *WebPkgRef) GetWebPkgId() string

func (*WebPkgRef) GetWebPkgRoot

func (x *WebPkgRef) GetWebPkgRoot() string

func (*WebPkgRef) MarshalJSON

func (x *WebPkgRef) MarshalJSON() ([]byte, error)

MarshalJSON marshals the WebPkgRef to JSON.

func (*WebPkgRef) MarshalProtoJSON

func (x *WebPkgRef) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the WebPkgRef message to JSON.

func (*WebPkgRef) MarshalProtoText

func (x *WebPkgRef) MarshalProtoText() string

func (*WebPkgRef) MarshalToSizedBufferVT

func (m *WebPkgRef) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*WebPkgRef) MarshalToVT

func (m *WebPkgRef) MarshalToVT(dAtA []byte) (int, error)

func (*WebPkgRef) MarshalVT

func (m *WebPkgRef) MarshalVT() (dAtA []byte, err error)

func (*WebPkgRef) ProtoMessage

func (*WebPkgRef) ProtoMessage()

func (*WebPkgRef) Reset

func (x *WebPkgRef) Reset()

func (*WebPkgRef) SizeVT

func (m *WebPkgRef) SizeVT() (n int)

func (*WebPkgRef) String

func (x *WebPkgRef) String() string

func (*WebPkgRef) UnmarshalJSON

func (x *WebPkgRef) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the WebPkgRef from JSON.

func (*WebPkgRef) UnmarshalProtoJSON

func (x *WebPkgRef) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the WebPkgRef message from JSON.

func (*WebPkgRef) UnmarshalVT

func (m *WebPkgRef) UnmarshalVT(dAtA []byte) error

type WebPkgRefSlice

type WebPkgRefSlice []*WebPkgRef

WebPkgRefSlice is a slice of WebPkgRef.

func (WebPkgRefSlice) AppendWebPkgRef

func (sl WebPkgRefSlice) AppendWebPkgRef(webPkgID, webPkgRoot, importPath string) (WebPkgRefSlice, bool)

AppendWebPkgRef appends a web pkg ref to the slice. Merges with any existing definition for that web pkg id.

Returns true if any changes were made.

func (WebPkgRefSlice) AppendWebPkgRefValue added in v0.51.2

func (sl WebPkgRefSlice) AppendWebPkgRefValue(add *WebPkgRef) (WebPkgRefSlice, bool)

AppendWebPkgRefValue appends a web pkg ref value to the slice. Merges roots, imports, and cross refs with any existing definition.

Returns true if any changes were made.

func (WebPkgRefSlice) AppendWebPkgRoot added in v0.51.2

func (sl WebPkgRefSlice) AppendWebPkgRoot(webPkgID, webPkgRoot string) (WebPkgRefSlice, bool)

AppendWebPkgRoot appends a web pkg root to the slice. Merges with any existing definition for that web pkg id.

Returns true if any changes were made.

func (WebPkgRefSlice) FilterExcluded

func (sl WebPkgRefSlice) FilterExcluded(excludedIDs map[string]struct{}) WebPkgRefSlice

FilterExcluded returns a new slice with web pkg refs whose IDs are NOT in the excluded set.

func (WebPkgRefSlice) ToWebPkgIDList

func (sl WebPkgRefSlice) ToWebPkgIDList() []string

ToWebPkgIDList returns a sorted, deduplicated list of web pkg ids from the slice.

type WebPkgResolveConfig

type WebPkgResolveConfig struct {
	ID          string
	Exclude     bool
	Entrypoints []WebPkgEntrypointConfig
}

WebPkgResolveConfig holds the config needed to resolve a web package. Avoids importing web/bundler proto types to prevent import cycles.

Jump to

Keyboard shortcuts

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