Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ decodo scrape https://example.com --full --format ndjson
| Variable | Description |
| --- | --- |
| `DECODO_AUTH_TOKEN` | Basic auth token (overrides saved config, below `--token`) |
| `DECODO_CONFIG_HOME` | Override config directory (default: OS-specific `env-paths` location) |
| `DECODO_CONFIG_HOME` | Override config directory (default: `$XDG_CONFIG_HOME/decodo`, else `~/.config/decodo`) |

## Exit codes

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@decodo/cli",
"version": "0.1.7",
"version": "0.1.8",
"description": "Official CLI for the Decodo APIs",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -38,8 +38,7 @@
"packageManager": "pnpm@10.33.3",
"dependencies": {
"@decodo/sdk-ts": "^2.1.2",
"commander": "^14.0.0",
"env-paths": "^3.0.0"
"commander": "^14.0.0"
},
"devDependencies": {
"@biomejs/biome": "2.4.15",
Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/platform/services/paths.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import envPaths from "env-paths";
import { homedir } from "node:os";
import { join } from "node:path";

export function getConfigDir(): string {
const override = process.env.DECODO_CONFIG_HOME;
Expand All @@ -7,5 +8,11 @@ export function getConfigDir(): string {
return override;
}

return envPaths("decodo", { suffix: "" }).config;
const xdgConfigHome = process.env.XDG_CONFIG_HOME;

if (xdgConfigHome) {
return join(xdgConfigHome, "decodo");
}

return join(homedir(), ".config", "decodo");
}
43 changes: 43 additions & 0 deletions tests/platform/services/paths.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { homedir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";

describe("getConfigDir", () => {
afterEach(() => {
vi.unstubAllEnvs();
vi.resetModules();
});

it("returns ~/.config/decodo when no override is set", async () => {
vi.stubEnv("DECODO_CONFIG_HOME", undefined);
vi.stubEnv("XDG_CONFIG_HOME", undefined);

const { getConfigDir } = await import(
"../../../src/platform/services/paths.js"
);

expect(getConfigDir()).toBe(join(homedir(), ".config", "decodo"));
});

it("honors XDG_CONFIG_HOME when set and no override", async () => {
vi.stubEnv("DECODO_CONFIG_HOME", undefined);
vi.stubEnv("XDG_CONFIG_HOME", "/xdg-config");

const { getConfigDir } = await import(
"../../../src/platform/services/paths.js"
);

expect(getConfigDir()).toBe(join("/xdg-config", "decodo"));
});

it("returns DECODO_CONFIG_HOME when set (precedence over XDG)", async () => {
vi.stubEnv("DECODO_CONFIG_HOME", "/custom/config");
vi.stubEnv("XDG_CONFIG_HOME", "/xdg-config");

const { getConfigDir } = await import(
"../../../src/platform/services/paths.js"
);

expect(getConfigDir()).toBe("/custom/config");
});
});
Loading