Skip to content

Commit ea43e1f

Browse files
Merge pull request #18 from holistics/feat/cli-core-version-env
feat: allow pinning @holistics/cli-core version via HOLISTICS_CLI_CORE_VERSION env
2 parents 8473788 + ca4ad43 commit ea43e1f

6 files changed

Lines changed: 29 additions & 13 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v0.2.0
2+
- Support `HOLISTICS_CLI_CORE_VERSION` env to run a specific `@holistics/cli-core` version (defaults to latest)
3+
14
# v0.1.1
25
- Update dependency for security fixes
36

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ The Holistics CLI is built as a lightweight NodeJS wrapper around the `@holistic
1818
1. Package Management
1919
- On startup, it automatically downloads the latest version of `@holistics/cli-core` from the npm registry
2020
- The package is cached locally in `.cache/holistics` for future use
21+
- To run a specific version instead of the latest, set the `HOLISTICS_CLI_CORE_VERSION` environment variable:
22+
```bash
23+
HOLISTICS_CLI_CORE_VERSION=1.2.3 holistics --help
24+
```
2125

2226
2. Command Execution
2327
- Once the core package is loaded, it invokes the `@holistics/cli-core` for the actual command execution

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@holistics/cli-ts",
33
"type": "module",
4-
"version": "0.1.1",
4+
"version": "0.2.0",
55
"scripts": {
66
"cli": "tsx src/index.ts"
77
},

‎src/downloader.ts‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writeFile, mkdir, stat } from "fs/promises";
1+
import { writeFile, mkdir, stat, rm } from "fs/promises";
22
import { fetch } from "undici";
33
import { extract } from "tar";
44
import { join } from "path";
@@ -13,14 +13,20 @@ async function downloadAndExtract(pkg: string, version: string) {
1313
? `https://registry.npmjs.org/${pkg.replace("/", "%2F")}/-/${pkg.split("/")[1]}-${encodeURIComponent(version)}.tgz`
1414
: `https://registry.npmjs.org/${pkg}/-/${pkg}-${version}.tgz`;
1515

16-
console.log(`Downloading version ${pkg}@${version}...`);
17-
const response = await fetch(tarballUrl);
18-
if (!response.ok) throw new Error(`Failed to download package: ${response.statusText}`);
19-
20-
const tarball = await response.arrayBuffer();
21-
await writeFile(join(modulePath, "package.tgz"), new Uint8Array(tarball)); // Now safe
22-
23-
await extract({ file: join(modulePath, "package.tgz"), cwd: modulePath, strip: 1 });
16+
try {
17+
console.log(`Downloading version ${pkg}@${version}...`);
18+
const response = await fetch(tarballUrl);
19+
if (!response.ok) throw new Error(`Failed to download package ${pkg}@${version}: ${response.statusText}`);
20+
21+
const tarball = await response.arrayBuffer();
22+
await writeFile(join(modulePath, "package.tgz"), new Uint8Array(tarball)); // Now safe
23+
24+
await extract({ file: join(modulePath, "package.tgz"), cwd: modulePath, strip: 1 });
25+
} catch (err) {
26+
// Remove the partial download so the next run doesn't treat it as cached
27+
await rm(modulePath, { recursive: true, force: true });
28+
throw err;
29+
}
2430
}
2531

2632
async function getLatestVersion(pkg: string): Promise<string> {

‎src/index.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { Command } from 'commander';
33

44
const program = new Command();
55

6-
const clicore = await loadModule('@holistics/cli-core');
6+
// Pin a specific @holistics/cli-core version via env, otherwise use the latest
7+
const cliCoreVersion = process.env.HOLISTICS_CLI_CORE_VERSION?.trim() || undefined;
8+
9+
const clicore = await loadModule('@holistics/cli-core', cliCoreVersion);
710
clicore.registerCommands(program);
811

912
program.parse(process.argv);

0 commit comments

Comments
 (0)