From 84f0dec84d305e18ce3b75409b2f7a6ba0d78764 Mon Sep 17 00:00:00 2001 From: Thomas Langewouters Date: Wed, 18 Jan 2023 09:50:03 +0100 Subject: [PATCH] Add a resolveEnvVars option to .zap package.pathRelativity This allows variables like $CHIP_ROOT to be used, which is needed when the chip codebase is a submodule of the repository the zap file is in. Throw an error when any variable used fails resolving. --- src-electron/util/util.js | 10 ++++++++++ src-shared/db-enum.js | 1 + 2 files changed, 11 insertions(+) diff --git a/src-electron/util/util.js b/src-electron/util/util.js index 7343547ef6..5e4c24b7c9 100644 --- a/src-electron/util/util.js +++ b/src-electron/util/util.js @@ -444,6 +444,16 @@ function createAbsolutePath(relativePath, relativity, zapFilePath) { return path.join(os.homedir(), relativePath) case dbEnum.pathRelativity.relativeToZap: return path.join(path.dirname(zapFilePath), relativePath) + case dbEnum.pathRelativity.resolveEnvVars: + for (let key in process.env) { + if (Object.prototype.hasOwnProperty.call(process.env, key)) { + relativePath = relativePath.replaceAll('$' + key, process.env[key]) + relativePath = relativePath.replaceAll('${' + key + '}', process.env[key]) + } + } + if (relativePath.indexOf('$') !== -1) { + throw new Error('resolveEnvVars: unable to resolve environment variables completely: ' + relativePath) + } } return relativePath } diff --git a/src-shared/db-enum.js b/src-shared/db-enum.js index b7461d24cc..ca30efbe87 100644 --- a/src-shared/db-enum.js +++ b/src-shared/db-enum.js @@ -84,6 +84,7 @@ exports.pathRelativity = { relativeToZap: 'relativeToZap', relativeToUserHome: 'relativeToHome', absolute: 'absolute', + resolveEnvVars: 'resolveEnvVars', } exports.wsCategory = {