Skip to content

feat: support offline mode with env var version pinning and cache fallback#16

Draft
fauzxan wants to merge 1 commit intoholistics:masterfrom
fauzxan:fix/offline-cache-support
Draft

feat: support offline mode with env var version pinning and cache fallback#16
fauzxan wants to merge 1 commit intoholistics:masterfrom
fauzxan:fix/offline-cache-support

Conversation

@fauzxan
Copy link

@fauzxan fauzxan commented Mar 24, 2026

Summary

Fixes #15 — the CLI binary currently always contacts registry.npmjs.org to resolve the latest @holistics/cli-core version, even when the package is already cached locally. This makes the CLI unusable in network-restricted environments.

This PR adds two mechanisms to ensureModule in src/downloader.ts:

  • HOLISTICS_CLI_CORE_VERSION env var — when set, the npm registry call is skipped entirely and the specified version is loaded directly from cache
  • Offline fallback — when the env var is not set and getLatestVersion() fails due to a network error, the CLI scans ~/.cache/holistics/ for any previously downloaded version (picking the highest) instead of crashing

Changes

src/downloader.ts:

  • Added findCachedVersion() — scans the cache directory for existing {pkg}@{version} entries and returns the highest version found
  • Modified ensureModule() — checks HOLISTICS_CLI_CORE_VERSION env var first, then attempts npm with fallback to cached version on network failure
  • Added readdir import from fs/promises and getCacheDir import from ./cache

Usage

# Pin version explicitly (zero network calls)
HOLISTICS_CLI_CORE_VERSION=0.6.13 holistics dbt upload --file-path manifest.json --data-source my_ds

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

Use case: Pre-baked Docker images

# At build time (network available): download cli-core into cache
RUN holistics --version  # populates ~/.cache/holistics/@holistics/cli-core@x.y.z/

# At runtime (no network): pin the version
ENV HOLISTICS_CLI_CORE_VERSION=0.6.13
RUN holistics dbt upload ...  # works without npm

Test plan

  • Verify holistics --version works normally (no env var, network available)
  • Verify HOLISTICS_CLI_CORE_VERSION=0.6.13 holistics --version works with pre-populated cache and no network
  • Verify offline fallback: run once to populate cache, then disconnect network and run again without env var
  • Verify error is still thrown when offline with no cache and no env var

🤖 Generated with Claude Code

…lback

When HOLISTICS_CLI_CORE_VERSION is set, skip npm registry calls entirely
and use the specified version from cache. When the env var is not set and
npm is unreachable, fall back to the most recent cached version instead
of crashing.

Closes holistics#15

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@fauzxan fauzxan marked this pull request as draft March 24, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant