diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index ad34b7f1..30853530 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -8,6 +8,7 @@ const ini = require("ini"); import { Secret } from "../secret"; import { Environment, ProjectConfig } from "./project-config"; import { Endpoint, RootConfig } from "./root-config"; +import { container } from "../../cli.mjs"; export { Endpoint, Environment, ProjectConfig, RootConfig }; @@ -381,7 +382,8 @@ const readFile = (fileName: string) => { }; export const getRootConfigPath = () => { - return path.join(os.homedir(), ".fauna-shell"); + const homedir = container.resolve("homedir"); + return path.join(homedir.toString(), ".fauna-shell"); }; export const getProjectConfigPath = (start?: string): string | undefined => { diff --git a/src/lib/file-util.mjs b/src/lib/file-util.mjs index 1902d47d..b1ecd300 100644 --- a/src/lib/file-util.mjs +++ b/src/lib/file-util.mjs @@ -1,7 +1,7 @@ //@ts-check import fs from "node:fs"; -import os from "node:os"; +import path from "node:path"; import { container } from "../cli.mjs"; @@ -105,7 +105,10 @@ export class Credentials { constructor(filename = "") { this.logger = container.resolve("logger"); this.filename = filename; - this.credsDir = `${os.homedir()}/.fauna/credentials`; + + const homedir = container.resolve("homedir"); + this.credsDir = path.join(homedir.toString(),".fauna/credentials"); + if (!dirExists(this.credsDir)) { fs.mkdirSync(this.credsDir, { recursive: true }); } diff --git a/test/authNZ.mjs b/test/authNZ.mjs index 4ded6bb3..6a62d4a5 100644 --- a/test/authNZ.mjs +++ b/test/authNZ.mjs @@ -1,3 +1,6 @@ +//@ts-check +import path from "node:path"; + import * as awilix from "awilix"; import { expect } from "chai"; import { beforeEach } from "mocha"; @@ -28,9 +31,13 @@ describe.skip("authNZMiddleware", function () { }; beforeEach(() => { + const __dirname = import.meta.dirname; + const homedir = path.join(__dirname, "./test-homedir"); + container = setupContainer(); container.register({ accountClient: awilix.asFunction(mockAccountClient).scoped(), + homedir: awilix.asFunction(() => homedir).scoped(), }); fetch = container.resolve("fetch"); }); diff --git a/test/login.mjs b/test/login.mjs index d6ecc35e..1eb16094 100644 --- a/test/login.mjs +++ b/test/login.mjs @@ -1,4 +1,5 @@ //@ts-check +import path from "node:path"; import * as awilix from "awilix"; import { expect } from "chai"; @@ -60,12 +61,17 @@ describe("login", function () { getToken: stub().resolves({ accessToken: "access-token" }), }; }; + beforeEach(() => { + const __dirname = import.meta.dirname; + const homedir = path.join(__dirname, "./test-homedir"); + container = setupContainer(); container.register({ oauthClient: awilix.asFunction(mockOAuth).scoped(), accountClient: awilix.asFunction(mockAccountClient).scoped(), accountCreds: awilix.asClass(AccountKey).scoped(), + homedir: awilix.asFunction(() => homedir).scoped(), }); fs = container.resolve("fs"); });