-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinit.js
More file actions
55 lines (46 loc) · 1.89 KB
/
Copy pathinit.js
File metadata and controls
55 lines (46 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const dotenv = require('dotenv')
const path = require('node:path')
// Load .env file from project root if it exists
// Use process.cwd() to ensure we're loading from the project root, not test directory
// Set override: true to ensure project .env takes precedence over any existing env vars
const envPath = path.resolve(process.cwd(), '.env')
const fs = require('node:fs')
// Only clear and reload if .env file exists
if (fs.existsSync(envPath)) {
// Store original values as fallback
const originalToken = process.env.HMD_API_ACCESS_TOKEN
const originalEndpoint = process.env.HMD_API_ENDPOINT_URL
// Clear existing env vars to ensure .env file values are used
if (process.env.HMD_API_ACCESS_TOKEN && !process.env.FORCE_ENV_OVERRIDE) {
delete process.env.HMD_API_ACCESS_TOKEN
}
if (process.env.HMD_API_ENDPOINT_URL && !process.env.FORCE_ENV_OVERRIDE) {
delete process.env.HMD_API_ENDPOINT_URL
}
// Load from .env file
dotenv.config({override: true, path: envPath})
// If .env file didn't load the token, restore the original (if it existed)
if (!process.env.HMD_API_ACCESS_TOKEN && originalToken) {
process.env.HMD_API_ACCESS_TOKEN = originalToken
}
if (!process.env.HMD_API_ENDPOINT_URL && originalEndpoint) {
process.env.HMD_API_ENDPOINT_URL = originalEndpoint
}
} else {
// If .env doesn't exist, try default dotenv.config() to load from any location
dotenv.config({override: true})
}
process.env.TS_NODE_PROJECT = path.resolve('test/tsconfig.json')
process.env.NODE_ENV = 'development'
// Initialize oclif config for @oclif/test
try {
const {Config} = require('@oclif/config')
const config = Config.load()
globalThis.oclif = globalThis.oclif || {}
globalThis.oclif.config = config
globalThis.oclif.columns = 80
} catch {
// If oclif config can't be loaded, set minimal globals
globalThis.oclif = globalThis.oclif || {}
globalThis.oclif.columns = 80
}