Skip to content

Commit

Permalink
Add a resolveEnvVars option to .zap package.pathRelativity (project-c…
Browse files Browse the repository at this point in the history
…hip#891)

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.
  • Loading branch information
q-thla authored Jan 23, 2023
1 parent 33d2bae commit 7f47fc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src-electron/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src-shared/db-enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ exports.pathRelativity = {
relativeToZap: 'relativeToZap',
relativeToUserHome: 'relativeToHome',
absolute: 'absolute',
resolveEnvVars: 'resolveEnvVars',
}

exports.wsCategory = {
Expand Down

0 comments on commit 7f47fc1

Please sign in to comment.