diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5570acb..9b04ff2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,6 +37,6 @@ jobs: unset NPM_CONFIG_USER npm ci - name: Unit tests - run: "npm run test" + run: "npm run test:ci" env: YEPCODE_API_TOKEN: ${{ secrets.TEST_YEPCODE_API_TOKEN }} diff --git a/package-lock.json b/package-lock.json index a5adf7b..c776600 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,9 +8,6 @@ "name": "@yepcode/run", "version": "1.5.0", "license": "See LICENSE file", - "dependencies": { - "dotenv": "^16.4.7" - }, "devDependencies": { "@swc/core": "^1.11.13", "@swc/jest": "^0.2.37", @@ -2190,18 +2187,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/dotenv": { - "version": "16.4.7", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", - "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", - "license": "BSD-2-Clause", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://dotenvx.com" - } - }, "node_modules/electron-to-chromium": { "version": "1.5.124", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.124.tgz", diff --git a/package.json b/package.json index 49aabcc..c7e7149 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "scripts": { "lint": "eslint .", "lint:fix": "eslint . --fix", - "test": "jest --coverage --verbose", + "test": "node --env-file=.env node_modules/.bin/jest --coverage --verbose", + "test:ci": "jest --coverage --verbose", "build": "tsc --project tsconfig.json" }, "devDependencies": { @@ -33,8 +34,5 @@ "jest": "^29.7.0", "typescript": "^5.8.2" }, - "dependencies": { - "dotenv": "^16.4.7" - }, "types": "dist/index.d.ts" } diff --git a/src/api/apiManager.ts b/src/api/apiManager.ts deleted file mode 100644 index e81b149..0000000 --- a/src/api/apiManager.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { YepCodeApi } from "./yepcodeApi"; -import { ConfigManager } from "../utils/configManager"; -import { YepCodeApiConfig } from "./types"; -import crypto from "crypto"; - -export class YepCodeApiManager { - private static instances = new Map(); - - private static _getConfigHash(config: YepCodeApiConfig): string { - const sortedConfig = Object.keys(config) - .sort() - .reduce>((obj, key) => { - obj[key] = config[key as keyof YepCodeApiConfig]; - return obj; - }, {}); - - return crypto - .createHash("sha256") - .update(JSON.stringify(sortedConfig)) - .digest("hex"); - } - - static getInstance(config: YepCodeApiConfig = {}): YepCodeApi { - const mergedConfig = { ...ConfigManager.readYepCodeEnvConfig(), ...config }; - const configHash = this._getConfigHash(mergedConfig); - - if (!this.instances.has(configHash)) { - this.instances.set(configHash, new YepCodeApi(mergedConfig)); - } - - return this.instances.get(configHash)!; - } - - static clearInstances(): void { - this.instances.clear(); - } -} diff --git a/src/utils/configManager.ts b/src/api/configManager.ts similarity index 92% rename from src/utils/configManager.ts rename to src/api/configManager.ts index 7a30cf2..8cb8746 100644 --- a/src/utils/configManager.ts +++ b/src/api/configManager.ts @@ -1,9 +1,7 @@ import { YepCodeApiConfig } from "../api/types"; -import dotenv from "dotenv"; export class ConfigManager { static readYepCodeEnvConfig(): any { - dotenv.config(); const envConfig = Object.entries(process.env) .filter(([key]) => key.startsWith("YEPCODE_")) .reduce((acc, [key, value]) => { diff --git a/src/api/index.ts b/src/api/index.ts index 31d43e2..c3c4d04 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,3 +1,2 @@ -export * from "./apiManager"; export * from "./yepcodeApi"; export * from "./types"; diff --git a/src/api/yepcodeApi.ts b/src/api/yepcodeApi.ts index 38ddb9b..8288743 100644 --- a/src/api/yepcodeApi.ts +++ b/src/api/yepcodeApi.ts @@ -1,3 +1,4 @@ +import { ConfigManager } from "./configManager"; import { YepCodeApiConfig, Process, @@ -65,9 +66,11 @@ export class YepCodeApi { `Global fetch API is not available. Please use Node.js 18+ or provide a global fetch polyfill (current node version: ${process.version})` ); } + const envConfig = ConfigManager.readYepCodeEnvConfig(); const finalConfig = { apiHost: "https://cloud.yepcode.io", timeout: 60000, + ...envConfig, ...config, }; if (!finalConfig.authUrl) { diff --git a/src/env/yepcodeEnv.ts b/src/env/yepcodeEnv.ts index 0fdab75..a01dc16 100644 --- a/src/env/yepcodeEnv.ts +++ b/src/env/yepcodeEnv.ts @@ -1,16 +1,11 @@ -import { - YepCodeApiManager, - YepCodeApi, - YepCodeApiConfig, - TeamVariable, -} from "../api"; +import { YepCodeApi, YepCodeApiConfig, TeamVariable } from "../api"; import { EnvVar } from "../types"; export class YepCodeEnv { private yepCodeApi: YepCodeApi; constructor(config: YepCodeApiConfig = {}) { - this.yepCodeApi = YepCodeApiManager.getInstance(config); + this.yepCodeApi = new YepCodeApi(config); } getTeamId(): string { diff --git a/src/run/yepcodeRun.ts b/src/run/yepcodeRun.ts index d896775..0ab3b25 100644 --- a/src/run/yepcodeRun.ts +++ b/src/run/yepcodeRun.ts @@ -1,5 +1,5 @@ import crypto from "crypto"; -import { YepCodeApi, YepCodeApiError, YepCodeApiManager } from "../api"; +import { YepCodeApi, YepCodeApiError } from "../api"; import { Execution } from "./execution"; import { YepCodeApiConfig } from "../api/types"; import { RunOpts, ExecutionError, Log } from "../types"; @@ -10,7 +10,7 @@ export class YepCodeRun { private PROCESS_NAME_PREFIX: string; constructor(config: YepCodeApiConfig = {}) { - this.yepCodeApi = YepCodeApiManager.getInstance(config); + this.yepCodeApi = new YepCodeApi(config); this.PROCESS_NAME_PREFIX = "yepcode-run-"; } diff --git a/src/storage/yepcodeStorage.ts b/src/storage/yepcodeStorage.ts index 28f2920..4b67e36 100644 --- a/src/storage/yepcodeStorage.ts +++ b/src/storage/yepcodeStorage.ts @@ -1,4 +1,4 @@ -import { YepCodeApi, YepCodeApiManager } from "../api"; +import { YepCodeApi } from "../api"; import { StorageObject, YepCodeApiConfig } from "../api/types"; import { Readable } from "stream"; @@ -6,7 +6,7 @@ export class YepCodeStorage { private api: YepCodeApi; constructor(config: YepCodeApiConfig = {}) { - this.api = YepCodeApiManager.getInstance(config); + this.api = new YepCodeApi(config); } async upload( diff --git a/src/utils/index.ts b/src/utils/index.ts deleted file mode 100644 index 8cffa36..0000000 --- a/src/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./configManager";