Thanks to visit codestin.com
Credit goes to github.com

Skip to content

CLI binary requires network access even when @holistics/cli-core is already cached #15

@khoaanguyenn

Description

@khoaanguyenn

Description

The CLI binary always calls getLatestVersion() (which fetches from https://registry.npmjs.org/@holistics/cli-core) before checking the local cache. This means the binary cannot run offline, even if @holistics/cli-core is already downloaded and cached at ~/.cache/holistics/.

Problem

In src/downloader.ts:

export async function ensureModule(pkg: string, version?: string) {
  if (!version) version = await getLatestVersion(pkg); // ← always hits npm
  const modulePath = getModulePath(pkg, version);
  // ...
}

Since index.ts calls loadModule('@holistics/cli-core') without a version, getLatestVersion() is always invoked. If the network is unavailable, the binary crashes with ConnectionRefused — even though the package is already cached locally.

Impact

This makes it impossible to use the holistics CLI in network-restricted environments such as:

  • Docker containers running with --network none
  • Air-gapped CI/CD environments
  • Pre-baked Docker images where @holistics/cli-core is downloaded at build time but unavailable at runtime
  • Production environments where outbound connections to npm registry are not whitelisted

Suggested fix

Two changes to ensureModule in src/downloader.ts:

  1. Support a HOLISTICS_CLI_CORE_VERSION env var — if set, skip the npm call entirely and use the specified version from cache
  2. Offline fallback — if getLatestVersion() fails (network error), scan the cache directory for any previously downloaded version instead of crashing

This would allow:

# Pin version explicitly (no network call at all)
HOLISTICS_CLI_CORE_VERSION=0.6.13 holistics --version

# Or just work offline if cache exists
holistics --version  # falls back to cached version when npm is unreachable

Steps to reproduce

# 1. Run once to populate cache
holistics --version

# 2. Verify cache exists
ls ~/.cache/holistics/@holistics/[email protected]/

# 3. Run without network — crashes
docker run --network none <image-with-holistics> holistics --version
# error: Unable to connect. Is the computer able to access the url?
#   path: "https://registry.npmjs.org/@holistics/cli-core"
#   code: "ConnectionRefused"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions