Add MPAK_HOME env var to make base directory configurable

Open
#71 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
typescript
Domain
cli

Research direction

Read cache.ts, config-manager.ts, and run.ts at the locations listed in the issue, then trace how cache, temporary, and config paths are built. Update the named tests in cache.test.ts, run.test.ts, config-manager.test.ts, and outdated.test.ts to cover the environment override and default path. Done when all listed paths use MPAK_HOME and the tests verify both behaviors.

Written by the indexing model from the issue text.

Description

Problem

The mpak base directory (~/.mpak/) is hardcoded. Runtimes like NimbleBrain that embed mpak want to co-locate bundle cache, config, and temp files under their own state tree (e.g., ~/.nimblebrain/apps/) rather than scattering state across two dotfile directories.

Currently users see:

~/.mpak/cache/         # bundle code
~/.mpak/config.json    # bundle credentials
~/.mpak/tmp/           # download temp files
~/.nimblebrain/data/   # app data

With this change, NimbleBrain sets MPAK_HOME=~/.nimblebrain/apps and everything consolidates:

~/.nimblebrain/
├── apps/cache/        # bundle code (MPAK_HOME/cache)
├── apps/config.json   # bundle credentials
├── data/{app}/        # app data (per-bundle MPAK_WORKSPACE)

Proposal

Add a MPAK_HOME environment variable that overrides the base ~/.mpak/ directory. All subdirectories (cache/, tmp/, config.json) remain relative to the base. Falls back to ~/.mpak/ when unset.

Implementation

Add a shared helper in cache.ts:

export function getMpakHome(): string {
  return process.env.MPAK_HOME || join(homedir(), ".mpak");
}

Update 4 production code locations:

  1. cache.ts:getCacheDir() (line 34) — join(getMpakHome(), "cache") instead of join(homedir(), ".mpak", "cache")
  2. cache.ts:listCachedBundles() (line 119) — same change
  3. cache.ts:downloadAndExtract() (line 227) — temp path uses join(getMpakHome(), "tmp", ...)
  4. config-manager.ts:ConfigManager constructor (line 140) — this.configDir = getMpakHome()
  5. run.ts:getLocalCacheDir() (line 183) — join(getMpakHome(), "cache", "_local", hash)

Update tests in cache.test.ts, run.test.ts, config-manager.test.ts, outdated.test.ts to set/mock MPAK_HOME.

Behavior
MPAK_HOME Base directory
unset ~/.mpak/ (unchanged, backwards compatible)
/path/to/dir /path/to/dir/

Subdirectory layout under the base is unchanged: cache/, cache/_local/, tmp/, config.json.

Context

NimbleBrain recently moved to per-bundle data isolation (MPAK_WORKSPACE set per-bundle). This is the companion change on the code/cache side — letting the runtime own the full directory tree so users have one dotfile directory to reason about.

Dominant language
TypeScript
Stars
14
Forks
13
Avg merge
16m
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NimbleBrainInc/mpak

All issues in NimbleBrainInc/mpak

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.