pub struct PackageManager<R: Runner = SystemRunner> { /* private fields */ }Expand description
Extension package manager: install, remove, update, list, resolve.
Generic over a Runner so tests can inject command execution. Production
code uses PackageManager (which defaults to SystemRunner).
Implementations§
Source§impl PackageManager<SystemRunner>
impl PackageManager<SystemRunner>
Sourcepub fn new(options: PackageManagerOptions) -> Self
pub fn new(options: PackageManagerOptions) -> Self
Create a manager backed by the real subprocess runner.
Source§impl<R: Runner> PackageManager<R>
impl<R: Runner> PackageManager<R>
Sourcepub fn with_runner(options: PackageManagerOptions, runner: R) -> Self
pub fn with_runner(options: PackageManagerOptions, runner: R) -> Self
Create a manager with an injected runner.
Sourcepub fn with_offline(self, offline: bool) -> Self
pub fn with_offline(self, offline: bool) -> Self
Force offline mode (Some(true)) or online (Some(false)), overriding
PI_OFFLINE. None (the default) reads the env on each call.
Sourcepub fn set_progress_callback(&mut self, callback: Option<ProgressCallback>)
pub fn set_progress_callback(&mut self, callback: Option<ProgressCallback>)
Install a progress callback (replaces any previous one).
Sourcepub fn get_installed_path(
&self,
settings: &SettingsManager,
source: &str,
scope: Scope,
) -> Result<Option<PathBuf>, PackageManagerError>
pub fn get_installed_path( &self, settings: &SettingsManager, source: &str, scope: Scope, ) -> Result<Option<PathBuf>, PackageManagerError>
Absolute install path for source in scope, or None when absent.
§Errors
Returns PackageManagerError::ProjectNotTrusted for project scope
while untrusted, or PackageManagerError::Resolve on path escape.
Sourcepub fn install(
&self,
settings: &SettingsManager,
source: &str,
scope: Scope,
) -> Result<(), PackageManagerError>
pub fn install( &self, settings: &SettingsManager, source: &str, scope: Scope, ) -> Result<(), PackageManagerError>
Install source into scope without recording it in settings.
Local sources only verify the path exists; npm and git run the package
manager / git clone under NETWORK_TIMEOUT_MS.
§Errors
Returns PackageManagerError::ProjectNotTrusted for untrusted project
scope, PackageManagerError::PathNotFound for a missing local path,
or PackageManagerError::Runner on subprocess failure.
Sourcepub fn install_and_persist(
&self,
settings: &mut SettingsManager,
source: &str,
scope: Scope,
) -> Result<(), PackageManagerError>
pub fn install_and_persist( &self, settings: &mut SettingsManager, source: &str, scope: Scope, ) -> Result<(), PackageManagerError>
Install then persist the source into the scope’s packages[].
§Errors
Sourcepub fn remove(
&self,
settings: &SettingsManager,
source: &str,
scope: Scope,
) -> Result<(), PackageManagerError>
pub fn remove( &self, settings: &SettingsManager, source: &str, scope: Scope, ) -> Result<(), PackageManagerError>
Remove source from scope (disk only; settings untouched).
Local sources are a no-op; npm uninstalls and git removes the clone.
§Errors
Returns PackageManagerError::ProjectNotTrusted for untrusted project
scope or PackageManagerError::Runner on subprocess failure.
Sourcepub fn remove_and_persist(
&self,
settings: &mut SettingsManager,
source: &str,
scope: Scope,
) -> Result<bool, PackageManagerError>
pub fn remove_and_persist( &self, settings: &mut SettingsManager, source: &str, scope: Scope, ) -> Result<bool, PackageManagerError>
Remove from disk then drop the source from packages[].
Returns whether the settings array actually changed.
§Errors
Sourcepub fn update_extensions(
&self,
settings: &SettingsManager,
source: Option<&str>,
) -> Result<(), PackageManagerError>
pub fn update_extensions( &self, settings: &SettingsManager, source: Option<&str>, ) -> Result<(), PackageManagerError>
Update one package (Some) or every configured package (None).
Pinned npm versions are skipped (they are fixed). Pinned git refs are reconciled against the configured ref. Offline mode or an empty match set is a no-op. A filter that matches nothing is an error.
§Errors
Returns PackageManagerError::NoMatchingPackage (with a suggestion
when one exists) for an unmatched filter, or PackageManagerError
variants from the underlying install/clone operations.
Sourcepub fn list_configured_packages(
&self,
settings: &SettingsManager,
) -> Result<Vec<ConfiguredPackage>, PackageManagerError>
pub fn list_configured_packages( &self, settings: &SettingsManager, ) -> Result<Vec<ConfiguredPackage>, PackageManagerError>
List every configured package across both scopes with its install path.
§Errors
Returns PackageManagerError only when an install-path lookup hits a
trust or path-escape failure.
Sourcepub fn resolve(
&self,
settings: &SettingsManager,
) -> Result<ResolvedPaths, PackageManagerError>
pub fn resolve( &self, settings: &SettingsManager, ) -> Result<ResolvedPaths, PackageManagerError>
Resolve all configured packages and local resources to concrete paths.
Delegates to PackagePathResolver::resolve so this surface and the
resolve-side discovery never disagree on managed install locations.
Missing installs are skipped (no network install here).
§Errors
Propagates PackageResolveError as PackageManagerError::Resolve.
Sourcepub fn add_source_to_settings(
&self,
settings: &mut SettingsManager,
source: &str,
scope: Scope,
) -> Result<bool, PackageManagerError>
pub fn add_source_to_settings( &self, settings: &mut SettingsManager, source: &str, scope: Scope, ) -> Result<bool, PackageManagerError>
Add (or normalize) source in scope’s packages[].
Returns whether the settings array changed. Adding the same source is
idempotent (returns false); a re-normalized local path returns true.
§Errors
Returns PackageManagerError::ProjectNotTrusted (via the settings
setter) for untrusted project scope.
Sourcepub fn remove_source_from_settings(
&self,
settings: &mut SettingsManager,
source: &str,
scope: Scope,
) -> Result<bool, PackageManagerError>
pub fn remove_source_from_settings( &self, settings: &mut SettingsManager, source: &str, scope: Scope, ) -> Result<bool, PackageManagerError>
Remove source from scope’s packages[].
Returns whether the array changed.
§Errors
Returns PackageManagerError::ProjectNotTrusted for untrusted project
scope.
Auto Trait Implementations§
impl<R = SystemRunner> !Freeze for PackageManager<R>
impl<R = SystemRunner> !RefUnwindSafe for PackageManager<R>
impl<R = SystemRunner> !UnwindSafe for PackageManager<R>
impl<R> Send for PackageManager<R>
impl<R> Sync for PackageManager<R>
impl<R> Unpin for PackageManager<R>where
R: Unpin,
impl<R> UnsafeUnpin for PackageManager<R>where
R: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more