Skip to content

Package Managers

Matthew Layton edited this page Nov 11, 2026 · 1 revision

Package managers

The packageManagers contribution point (plugin API 1.25.0; searchExactName from 1.27.0) and the package-manager protocol (1.1). Epic #907. Core reads no package manifest of its own: everything the Packages panel shows comes from a plugin. For what a user installs, see Packages.

What a package-manager plugin is

A program Studio starts once per session and talks to over newline-delimited JSON on standard streams, the same transport as version control and hosting. One request per line in, one response per line out, correlated by id. Requests are independent, so answer them as they arrive: a folder with hundreds of packages must not hold up a search.

It serves one ecosystem (npm, NuGet, PyPI, …) and answers four kinds of question about a folder:

Operation Answers Capability
load The folder's projects, what each declares, the installed and latest versions, and a verdict always
sources The registries the folder can search (names only: they reach the renderer) sources
search A page of one source's packages; an empty query browses search
install / update / remove / restore The command that would do it, never the doing each its own

Qualifiers on search:

  • searchRequiresQuery: the registry needs text, as npm's does.
  • prerelease: it can filter prereleases, as NuGet's can.
  • searchExactName (protocol 1.1): the registry has no search, so a query is looked up as one exact name, as with PyPI and the Go module proxy.

The panel draws itself from these: Prereleases appears only with prerelease, and an exact-name source says so in its search field rather than pretending to search.

The protocol is defined in src/shared/api/package-manager-protocol.ts. Each first-party plugin under plugins/ (npm, nuget, pypi, cargo, go-modules, maven, vcpkg, conan) carries its own copy, as every plugin does: the protocol, not shared TypeScript, is the contract.

The manifest

"contributes": {
  "packageManagers": [
    {
      "id": "onixlabs.cargo",
      "displayName": "Cargo",
      "ecosystem": "cargo",
      "priority": 100,
      "markers": ["Cargo.toml"],
      "capabilities": ["sources", "search", "install", "update", "remove", "restore"],
      "command": { "kind": "node" },
      "entryPoint": "node_modules/@onixlabs/cargo/main.js"
    }
  ]
}
  • markers are file names, with * allowed (*.csproj, requirements*.txt). Studio scans the folder three levels deep, skipping hidden directories and generated ones (node_modules, bin, obj, dist, build, out, target, vendor). Every plugin whose marker it finds applies: a folder can hold an npm package and a .NET solution side by side, and the panel shows both.
  • priority orders plugins that apply to one folder, highest first.
  • capabilities are a promise, because the panel draws its controls before any process has started. The handshake confirms them, and Studio offers only what both say.
  • The Plugin Manager lists these plugins under Package Managers, and the setup wizard offers the ones matching the ecosystems the user picks.

The handshake

Studio's first request is initialize with { "protocol": "1.1" }. Answer with { protocol, capabilities, toolVersion, problem? }. A different major version is refused. A newer minor is fine, because minors only add.

Writes: the plugin never runs anything

install, update, remove and restore answer with a PackageCommand: { executable, args[], cwd, title }. Studio runs it in a visible terminal, where the user can read it, stop it and see its output, then reads the folder again when it ends. Studio refuses:

  • a project outside the folder the request named;
  • a command whose cwd is outside that folder, or that is malformed;
  • any operation the plugin did not both declare and confirm.

Arguments are an array, so a package name can't become a second command. Still refuse a name or version that begins with - or could otherwise be read as an option. Offer only what the tool can do: Maven has no "add a dependency" command, so the Maven plugin offers restore only. When one project can't take a write its siblings can, answer ok: false in the user's terms.

Credentials

The same rule as code hosting:

  1. The tool's own configuration first, read by the plugin: .npmrc, nuget.config, pip.conf, .cargo/credentials.toml, ~/.m2/settings.xml. Core reads none of them.
  2. A token the user saved in Studio, in Settings › Workspaces › Package Managers. Ask for it mid-request, and only when the configuration holds none: { "request": "credential", "callId": 1, "registry": "https://…" } on stdout. Studio answers on stdin with { "answer": "credential", "callId": 1, "token": "…" | null }. It hands over a token only if it was saved for this plugin and this https registry.

⛔ The rules a plugin keeps:

  • Never send a credential over plain http, except to loopback.
  • Never ask for a token for the public registry.
  • Never let a project-level file redirect a credential the user configured to another host, and never interpolate environment variables into a credential sent to a host the project chose (#1361, #1365).
  • A plugin's environment is cut down to an allow-list, so ${NPM_TOKEN} in a config file usually resolves to nothing. Treat that as "no credential". Which registry variables the allow-list should pass (GOPRIVATE, CARGO_HOME, PIP_INDEX_URL, …) is #1423.

Trust

Studio asks a plugin about a folder only once the user has said they trust it, because a project's configuration decides which registry is contacted and what is sent to it. A repository is asked about by version control. Any other folder is trusted from the Packages panel's empty state. Both record the same decision.

The model

load answers a PackageManagerModel (declared in src/shared/api/package-management.ts), { ecosystem, root, projects[] }. Each project is { name, manifestPath, packages[] }, and each package is { name, requested, installed, latest, status, scope }:

  • status is current, outdated or unknown. Use unknown when the latest version could not be resolved (offline, a private feed with no credential, a path or git dependency). Never guess.
  • scope is one of production, development, peer or optional. Map the ecosystem's own scopes onto these. For example, Maven test becomes development and provided becomes peer; Cargo's dev and build dependencies become development.

Testing a plugin

  • Unit specs sit beside the source (plugins/<name>/src/*.spec.ts) and run in Studio's unit suite.
  • A contract spec in src/shared/electron/package-managers/<name>-plugin.contract.spec.ts starts the built plugin as a real process, speaks to it with core's own client, and points it at a fake registry on loopback with a scratch HOME. ⛔ Never a real registry in a spec.
  • To try it in the app, sideload it: put the built dist/ under <userData>/plugins/<id>/.

Releasing

Like every npm-tarball plugin: tag plugin-<name>-v<version> (see Plugins). Repinning touches four files: the lockfile, plugin.json's sha256, the curated index's copy, and the index revision. Pin last.

Clone this wiki locally