Skip to content

Commit

Permalink
fix(api): fixed env issue in MacOS executable
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury4GL committed Jan 15, 2024
1 parent 4f1763d commit 73d965d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
16 changes: 8 additions & 8 deletions api/package-lock.json

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

2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"adm-zip": "^0.5.9",
"axios": "0.27.2",
"csrf": "^3.1.0",
"dotenv": "^10.0.0",
"dotenv": "^16.0.1",
"http-headers-validation": "^0.0.1",
"jest": "^27.0.6",
"mongodb-memory-server": "8.11.4",
Expand Down
32 changes: 30 additions & 2 deletions api/src/utils/setProcessVariables.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import path from 'path'
import { createFolder, getAbsolutePath, getRealPath } from '@sasjs/utils'

import {
createFolder,
getAbsolutePath,
getRealPath,
fileExists
} from '@sasjs/utils'
import dotenv from 'dotenv'
import { connectDB, getDesktopFields, ModeType, RunTimeType, SECRETS } from '.'

export const setProcessVariables = async () => {
const { execPath } = process

// Check if execPath ends with 'api-macos' to determine executable for MacOS.
// This is needed to fix picking .env file issue in MacOS executable.
if (execPath) {
const envPathSplitted = execPath.split(path.sep)

if (envPathSplitted.pop() === 'api-macos') {
const envPath = path.join(envPathSplitted.join(path.sep), '.env')

// Override environment variables from envPath if file exists
if (await fileExists(envPath)) {
dotenv.config({ path: envPath, override: true })
}
}
}

const { MODE, RUN_TIMES } = process.env

if (MODE === ModeType.Server) {
Expand All @@ -21,6 +43,7 @@ export const setProcessVariables = async () => {
if (process.env.NODE_ENV === 'test') {
process.sasjsRoot = path.join(process.cwd(), 'sasjs_root')
process.driveLoc = path.join(process.cwd(), 'sasjs_root', 'drive')

return
}

Expand All @@ -41,14 +64,17 @@ export const setProcessVariables = async () => {

const { SASJS_ROOT } = process.env
const absPath = getAbsolutePath(SASJS_ROOT ?? 'sasjs_root', process.cwd())

await createFolder(absPath)

process.sasjsRoot = getRealPath(absPath)

const { DRIVE_LOCATION } = process.env
const absDrivePath = getAbsolutePath(
DRIVE_LOCATION ?? path.join(process.sasjsRoot, 'drive'),
process.cwd()
)

await createFolder(absDrivePath)
process.driveLoc = getRealPath(absDrivePath)

Expand All @@ -57,7 +83,9 @@ export const setProcessVariables = async () => {
LOG_LOCATION ?? path.join(process.sasjsRoot, 'logs'),
process.cwd()
)

await createFolder(absLogsPath)

process.logsLoc = getRealPath(absLogsPath)

process.logsUUID = 'SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784'
Expand Down

0 comments on commit 73d965d

Please sign in to comment.