versionmeta

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package versionmeta resolves installed-tool versions from on-disk metadata — npm package manifests, version-encoded install layouts (<tool>/versions/<v>, Homebrew Cellar/Caskroom), and macOS app bundles — so detectors can avoid launching third-party binaries.

Running `<tool> --version` is the detection path that popped macOS Gatekeeper "could not verify … free of malware" dialogs on customer machines: cursor-agent eagerly dlopens an un-notarized native addon (merkle-tree-napi.darwin-arm64.node) on any invocation. Metadata reads can't trigger that class of problem, so callers try FromBinary first and fall back to exec'ing the binary only when it returns "".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromBinary

func FromBinary(ctx context.Context, exec executor.Executor, binaryPath string) string

FromBinary returns the version of the tool installed at binaryPath, derived purely from filesystem metadata, or "" when no trustworthy source exists. It never executes the target binary; the only subprocess it may spawn is Apple's own PlistBuddy (an OS utility) to read an app-bundle Info.plist.

A "" result is not a failure — it means the caller should fall back to its existing version command. Sources are tried most- to least-authoritative:

  1. npm package manifest: binary resolves into node_modules/<pkg>/, and the manifest's package name matches the tool (rejects e.g. corepack's yarn shim, whose manifest version would be corepack's, not yarn's).
  2. <tool>/versions/<version>/ install layouts (cursor-agent, claude native installer). The directory holding "versions" must match the tool name so runtime-manager layouts (~/.pyenv/versions/3.12.1/bin/poetry) don't misattribute the runtime's version to the tool.
  3. Homebrew Cellar/Caskroom: physical containment in Cellar/<formula>/<v>/ means the formula owns the binary, so <v> is its version (npm-installed binaries under a brew node live in node_modules and are claimed or rejected by rule 1 before this can misfire).
  4. macOS app bundle: CFBundleShortVersionString of the enclosing .app.

func NPMPackageName

func NPMPackageName(exec executor.Executor, binaryPath string) string

NPMPackageName returns the full npm package name (e.g. "@github/copilot") that owns binaryPath, or "" when the binary doesn't resolve into an npm package. Lets detectors verify a tool's identity without executing it.

func NPMShimPackageRoot

func NPMShimPackageRoot(exec executor.Executor, path string) string

NPMShimPackageRoot reads a Windows-style npm shim (`<bin>.cmd`, `<bin>.ps1`, `<bin>.bat`) and returns the install root of the package the shim invokes, by locating the first `node_modules\<...>` reference in the shim body. Returns "" when path isn't a shim, can't be read, or contains no node_modules reference.

npm's Windows shim, generated by cmd-shim, looks like:

"%_prog%" "%dp0%\node_modules\@anthropic-ai\claude-code\cli.js" %*

We extract the node_modules path, resolve it relative to the shim's own directory (cmd-shim's `%dp0%`), and feed the absolute path through NodeModulesPackageRoot.

func NodeModulesPackageRoot

func NodeModulesPackageRoot(path string) string

NodeModulesPackageRoot walks up `path` looking for a `node_modules` directory; if found, returns the package root (one or two levels deeper depending on whether the package is scoped). Returns "" when the path isn't inside a node_modules tree.

Separator-agnostic: handles both `/` and `\` paths regardless of the host OS. The returned path uses the same separator style as the input — Windows paths preserve backslashes, Unix paths preserve forward slashes.

Examples:

/usr/local/lib/node_modules/@anthropic-ai/claude-code/bin/claude.exe
  -> /usr/local/lib/node_modules/@anthropic-ai/claude-code
C:\Users\u\AppData\Roaming\npm\node_modules\@scope\name\cli.js
  -> C:\Users\u\AppData\Roaming\npm\node_modules\@scope\name

Types

This section is empty.

Jump to

Keyboard shortcuts

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