Skip to content

Commit

Permalink
feat(fetch-engine): only print error message for nixos if applicable (#…
Browse files Browse the repository at this point in the history
…20138)

Previously on nixos, an error message regarding not available
precompiled engine files was always printed. With this change, the error
message is only shown if the engine files were not configured correctly
via environment variables.

Fixes: #17900
  • Loading branch information
Gerschtli committed Jul 28, 2023
1 parent 7854a5f commit d9ed477
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/fetch-engine/src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { BinaryType } from './BinaryType'
import { chmodPlusX } from './chmodPlusX'
import { cleanupCache } from './cleanupCache'
import { downloadZip } from './downloadZip'
import { getBinaryEnvVarPath } from './env'
import { allEngineEnvVarsSet, getBinaryEnvVarPath } from './env'
import { getHash } from './getHash'
import { getBar } from './log'
import { getCacheDir, getDownloadUrl, overwriteFile } from './utils'
Expand Down Expand Up @@ -70,8 +70,12 @@ export async function download(options: DownloadOptions): Promise<BinaryPaths> {
const platform = await getPlatform()
const os = await getos()

if (os.targetDistro && ['nixos'].includes(os.targetDistro)) {
console.error(`${yellow('Warning')} Precompiled engine files are not available for ${os.targetDistro}.`)
if (os.targetDistro && ['nixos'].includes(os.targetDistro) && !allEngineEnvVarsSet(Object.keys(options.binaries))) {
console.error(
`${yellow('Warning')} Precompiled engine files are not available for ${
os.targetDistro
}, please provide the paths via environment variables, see https://pris.ly/d/custom-engines`,
)
} else if (['freebsd11', 'freebsd12', 'freebsd13', 'openbsd', 'netbsd'].includes(platform)) {
console.error(
`${yellow(
Expand Down
10 changes: 10 additions & 0 deletions packages/fetch-engine/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@ function getEnvVarToUse(binaryType: BinaryType): string {

return envVar
}

export function allEngineEnvVarsSet(binaries: string[]): boolean {
for (const binaryType of binaries) {
if (!getBinaryEnvVarPath(binaryType as BinaryType)) {
return false
}
}

return true
}

0 comments on commit d9ed477

Please sign in to comment.