Files
bruno/packages/bruno-cli/src/runner/interpolate-string.js
lohit ab9bcbe5ed feat/rename collectionVariables variable name to runtimeVariables (#2638)
* pr review changes

* collection root object in export json

* import environment updates

* tests run execution order fix for collection runs

* updated validations

* collectionVariables -> runtimeVariables

* removed husky, adjusted indentation

---------

Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
2024-07-17 17:21:03 +05:30

44 lines
1.0 KiB
JavaScript

const { forOwn, cloneDeep } = require('lodash');
const { interpolate } = require('@usebruno/common');
const interpolateString = (str, { envVars, runtimeVariables, processEnvVars }) => {
if (!str || !str.length || typeof str !== 'string') {
return str;
}
processEnvVars = processEnvVars || {};
runtimeVariables = runtimeVariables || {};
// we clone envVars because we don't want to modify the original object
envVars = envVars ? cloneDeep(envVars) : {};
// envVars can inturn have values as {{process.env.VAR_NAME}}
// so we need to interpolate envVars first with processEnvVars
forOwn(envVars, (value, key) => {
envVars[key] = interpolate(value, {
process: {
env: {
...processEnvVars
}
}
});
});
// runtimeVariables take precedence over envVars
const combinedVars = {
...envVars,
...runtimeVariables,
process: {
env: {
...processEnvVars
}
}
};
return interpolate(str, combinedVars);
};
module.exports = {
interpolateString
};