From 7c73c46e753bf6f9ab8fae0c7a6b47930e4c960b Mon Sep 17 00:00:00 2001 From: Sudo Arash Date: Fri, 20 Sep 2024 23:03:58 +0330 Subject: [PATCH 1/3] Update miscUtils.ts --- packages/yarnpkg-core/sources/miscUtils.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/yarnpkg-core/sources/miscUtils.ts b/packages/yarnpkg-core/sources/miscUtils.ts index 98dcf1f1015c..e191c92201b7 100644 --- a/packages/yarnpkg-core/sources/miscUtils.ts +++ b/packages/yarnpkg-core/sources/miscUtils.ts @@ -467,26 +467,27 @@ 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 (variableValue !== undefined) { return variableValue; - if (variableExist && !colon) - return variableValue; - if (fallback != null) + } + + if (fallback != null) { return fallback; + } throw new UsageError(`Environment variable not found (${variableName})`); }); } + export function parseBoolean(value: unknown): boolean { switch (value) { case `true`: From b9331931d1f8c653d6252362a6fabaced65019f6 Mon Sep 17 00:00:00 2001 From: Sudo Arash Date: Fri, 20 Sep 2024 23:19:49 +0330 Subject: [PATCH 2/3] Fixed the bug of the bug --- packages/yarnpkg-core/sources/miscUtils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/yarnpkg-core/sources/miscUtils.ts b/packages/yarnpkg-core/sources/miscUtils.ts index e191c92201b7..29b05fd35247 100644 --- a/packages/yarnpkg-core/sources/miscUtils.ts +++ b/packages/yarnpkg-core/sources/miscUtils.ts @@ -475,19 +475,23 @@ export function replaceEnvVariables(value: string, { env }: { env: { [key: strin const variableValue = env[variableName]; + // If the variable exists, return its value if (variableValue !== undefined) { return variableValue; } - + + // 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`: From dc76e7381959773ea3a8429b499f7ad4d8562d68 Mon Sep 17 00:00:00 2001 From: Sudo Arash Date: Fri, 20 Sep 2024 23:20:49 +0330 Subject: [PATCH 3/3] Update the version --- packages/yarnpkg-core/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": {