mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-24 05:05:39 +00:00
* 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>
44 lines
1.0 KiB
JavaScript
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
|
|
};
|