pkgmgr

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package pkgmgr 管理节点包管理器偏好(npm/pnpm/yarn,经 corepack 激活)与多 registry 配置(FR-306)。配置落托管 .npmrc(NPM_CONFIG_USERCONFIG 指向,不污染用户 ~/.npmrc), 供 FR-307 全局包管理 / FR-308 bot-worker 依赖装全局复用。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	PM                string
	CorepackAvailable bool
	PMVersion         string
	Registries        []Registry
	NodeBin           string
}

Config 节点 PM 配置读取结果。

type GlobalPackage

type GlobalPackage struct {
	Name    string
	Version string
	Latest  string // outdated 探测到的最新版(空=已最新/探测失败)
}

GlobalPackage 托管全局目录下的一个已装包(FR-307)。

type Manager

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

Manager 管理托管 .npmrc 与 corepack 激活。runtimesRoot=<数据根>/opt/runtimes(含 nodejs-* 与 .npmrc)。

func NewManager

func NewManager(runtimesRoot string) *Manager

NewManager 创建包管理器。runtimesRoot 为 <数据根>/opt/runtimes。

func (*Manager) Get

func (m *Manager) Get(pm string) Config

Get 读取当前 PM 配置:探测 corepack 可用性、PM 版本、回读托管 .npmrc registry。 pm 为期望偏好(来自 CP DB,Worker 不持久化偏好,仅落 .npmrc 与激活 shim)。

func (*Manager) GlobalDir

func (m *Manager) GlobalDir() string

GlobalDir 返回节点级受控包项目根(FR-307,见 ADR-072)。

func (*Manager) InstallGlobal

func (m *Manager) InstallGlobal(ctx context.Context, pm, name, version string, onLine func(string)) error

InstallGlobal 安装/升级一个全局包(version 空=latest);onLine 逐行回调 PM 输出(任务日志)。

func (*Manager) ListGlobal

func (m *Manager) ListGlobal(ctx context.Context, pm string) ([]GlobalPackage, error)

ListGlobal 列出节点受控项目已装包,并 best-effort 标注可更新版本(FR-307)。

func (*Manager) NpmrcPath

func (m *Manager) NpmrcPath() string

NpmrcPath 返回托管 .npmrc 路径(FR-307 全局包操作以此作 NPM_CONFIG_USERCONFIG)。

func (*Manager) RemoveGlobal

func (m *Manager) RemoveGlobal(ctx context.Context, pm, name string) error

RemoveGlobal 卸载一个全局包(FR-307)。

func (*Manager) Set

func (m *Manager) Set(ctx context.Context, pm string, regs []Registry) (string, error)

Set 应用 PM 偏好(pnpm/yarn 经 corepack enable 激活)并写托管 .npmrc。返回激活后的 PM 版本。

func (*Manager) SetRunner

func (m *Manager) SetRunner(r runner)

SetRunner 注入命令执行器(仅测试)。

type Registry

type Registry struct {
	Name  string
	URL   string
	Scope string
	Token string
}

Registry 单条 registry 配置(scope 空=默认源)。

Jump to

Keyboard shortcuts

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