diff --git a/packages/yarnpkg-core/package.json b/packages/yarnpkg-core/package.json index 050fa417ee38..0b345166b77b 100644 --- a/packages/yarnpkg-core/package.json +++ b/packages/yarnpkg-core/package.json @@ -1,6 +1,6 @@ { "name": "@yarnpkg/core", - "version": "4.1.3", + "version": "4.1.4", "license": "BSD-2-Clause", "main": "./sources/index.ts", "exports": { diff --git a/packages/yarnpkg-core/sources/miscUtils.ts b/packages/yarnpkg-core/sources/miscUtils.ts index 98dcf1f1015c..29b05fd35247 100644 --- a/packages/yarnpkg-core/sources/miscUtils.ts +++ b/packages/yarnpkg-core/sources/miscUtils.ts @@ -467,26 +467,31 @@ export function buildIgnorePattern(ignorePatterns: Array) { }).join(`|`); } -export function replaceEnvVariables(value: string, {env}: {env: {[key: string]: string | undefined}}) { - const regex = /\${(?[\d\w_]+)(?:)?(?:-(?[^}]*))?}/g; +export function replaceEnvVariables(value: string, { env }: { env: { [key: string]: string | undefined } }) { + const regex = /\${(?[\w_]+)(?::(?[^}]*))?}/g; return value.replace(regex, (...args) => { - const {variableName, colon, fallback} = args[args.length - 1]; + const { variableName, fallback } = args[args.length - 1]; - const variableExist = Object.hasOwn(env, variableName); const variableValue = env[variableName]; - if (variableValue) + // If the variable exists, return its value + if (variableValue !== undefined) { return variableValue; - if (variableExist && !colon) - return variableValue; - if (fallback != null) + } + + // If the variable does not exist but a fallback is provided, return the fallback + if (fallback != null) { return fallback; + } + // Throw an error if the variable does not exist and no fallback is provided throw new UsageError(`Environment variable not found (${variableName})`); }); } + + export function parseBoolean(value: unknown): boolean { switch (value) { case `true`: