@bilt/build-with-configuration
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "@bilt/build-with-configuration", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
@@ -32,3 +32,4 @@ "main": "src/build-with-configuration.js", | ||
"@bilt/scripting-commons": "^1.2.1", | ||
"camelcase": "^6.0.0", | ||
"@types/node": "^13.11.1", | ||
"constant-case": "^3.0.3", | ||
"debug": "^4.1.1" | ||
@@ -43,4 +44,5 @@ }, | ||
"mocha": "^7.1.1", | ||
"prettier": "^2.0.4" | ||
"prettier": "^2.0.4", | ||
"testdouble": "^3.13.1" | ||
} | ||
} |
@@ -9,3 +9,3 @@ 'use strict' | ||
function arrayify(possibleArray) { | ||
if (possibleArray == null) return undefined | ||
if (possibleArray == null) return [] | ||
if (Array.isArray(possibleArray)) return possibleArray | ||
@@ -12,0 +12,0 @@ return [possibleArray] |
@@ -12,11 +12,3 @@ 'use strict' | ||
async function* executeJob(jobConfiguration, phase, directoryToExecuteIn, buildOptions) { | ||
if (phase === 'before' && jobConfiguration[phase]) { | ||
yield* await executePhase(jobConfiguration.steps[phase], directoryToExecuteIn, buildOptions) | ||
} | ||
if (phase === 'after' && jobConfiguration[phase]) { | ||
yield* await executePhase(jobConfiguration.steps[phase], directoryToExecuteIn, buildOptions) | ||
} | ||
if (phase === 'during' && jobConfiguration[phase]) { | ||
yield* await executePhase(jobConfiguration.steps[phase], directoryToExecuteIn, buildOptions) | ||
} | ||
yield* executePhase(jobConfiguration.steps[phase], directoryToExecuteIn, buildOptions) | ||
} | ||
@@ -41,3 +33,3 @@ | ||
for (const parameterOption of stepInfo(step).parameterOptions) { | ||
enableOptions.push(parameterOption) | ||
parameterOptions.push(parameterOption) | ||
} | ||
@@ -44,0 +36,0 @@ } |
'use strict' | ||
const {compileFunction} = require('vm') | ||
const camelcase = require('camelcase') | ||
const {constantCase} = require('constant-case') | ||
const {sh} = require('@bilt/scripting-commons') | ||
@@ -30,3 +30,3 @@ const {arrayify} = require('./arrayify') | ||
* @param {string} cwd | ||
* @param {{[x: string]: boolean|string}} | ||
* @param {{[x: string]: boolean|string}} buildOptions | ||
* @returns {Promise<void>} | ||
@@ -46,4 +46,5 @@ */ | ||
/** | ||
* @param {string} condition | ||
* @param {import('./types').BooleanValueOrFunctionText} condition | ||
* @param {string} cwd | ||
* @returns {Promise<boolean>} | ||
*/ | ||
@@ -60,3 +61,3 @@ async function executeCondition(condition, cwd) { | ||
* @param {string} command | ||
* @param {{ [s: string]: any; } | ArrayLike<any>} env | ||
* @param {import('./types').EnvVars} env | ||
* @param {string} cwd | ||
@@ -78,13 +79,19 @@ * @param {any} buildOptions | ||
await sh(command, {env: envVars, cwd}) | ||
await sh(command, {env: {...process.env, ...envVars}, cwd}) | ||
} | ||
/** | ||
* @param {string} functionAsText | ||
* @param {any|{function: string}} functionAsText | ||
* @param {{ directory: string; }} optionsParameter | ||
*/ | ||
async function executeFunction(functionAsText, optionsParameter) { | ||
return await compileFunction(` | ||
return (${functionAsText})(options) | ||
`)(optionsParameter) | ||
if (typeof functionAsText === 'object') | ||
return await compileFunction( | ||
` | ||
return (${functionAsText.function})(options) | ||
`, | ||
['options'], | ||
)(optionsParameter) | ||
return functionAsText | ||
} | ||
@@ -100,3 +107,3 @@ | ||
if (value !== false) { | ||
ret[`BILT_OPTION_${camelcase(option).toUpperCase()}`] = value.toString() | ||
ret[`BILT_OPTION_${constantCase(option)}`] = value.toString() | ||
} | ||
@@ -127,9 +134,13 @@ } | ||
if (step.condition != null && typeof step.condition !== 'string') { | ||
if ( | ||
step.condition != null && | ||
typeof step.condition !== 'string' && | ||
(typeof step.condition !== 'object' || typeof step.condition.function !== 'string') | ||
) { | ||
throw new Error( | ||
`"name" property of step #${i} in phase ${phaseName} of job ${jobId} must to be a string in ${configPath}`, | ||
`"condition" property of step #${i} in phase ${phaseName} of job ${jobId} must to be a boolean or a function text in ${configPath}`, | ||
) | ||
} | ||
if (step.env != null && typeof step.env !== 'string') { | ||
if (step.env != null && typeof step.env !== 'object') { | ||
throw new Error( | ||
@@ -139,2 +150,17 @@ `"env" property of step #${i} in phase ${phaseName} of job ${jobId} must to be an object in ${configPath}`, | ||
} | ||
for (const [envVar, value] of Object.entries(step.env || {})) { | ||
if (typeof envVar !== 'string') { | ||
throw new Error( | ||
`"env" name ${envVar} of step #${i} in phase ${phaseName} of job ${jobId} must be a string in ${configPath}`, | ||
) | ||
} | ||
if ( | ||
typeof value !== 'string' && | ||
(typeof value !== 'object' || typeof value.function !== 'string') | ||
) { | ||
throw new Error( | ||
`"env" value ${envVar} of step #${i} in phase ${phaseName} of job ${jobId} must be a string or a function text in ${configPath}`, | ||
) | ||
} | ||
} | ||
@@ -141,0 +167,0 @@ if ( |
@@ -26,7 +26,7 @@ 'use strict' | ||
* name: string | ||
* enableOption?: string|string[] | ||
* parameterOption?: string|string[] | ||
* run: string | ||
* condition?: string | ||
* condition?: BooleanValueOrFunctionText | ||
* env?: EnvVars | ||
* enableOption?: string|string[] | ||
* parameterOption?: string|string[] | ||
* }} Step | ||
@@ -36,6 +36,9 @@ */ | ||
/**@typedef {{ | ||
* [varName: string]: boolean|number|string | ||
* [varName: string]: StringValueOrFunctionText | ||
* }} EnvVars | ||
*/ | ||
/**@typedef {string|{function: string}} StringValueOrFunctionText */ | ||
/**@typedef {boolean|{function: string}} BooleanValueOrFunctionText */ | ||
module.exports = 'this module contains only type definitions' |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
11653
320
4
8
2
+ Added@types/node@^13.11.1
+ Addedconstant-case@^3.0.3
+ Added@types/node@13.13.52(transitive)
+ Addedconstant-case@3.0.4(transitive)
+ Addedlower-case@2.0.2(transitive)
+ Addedno-case@3.0.4(transitive)
+ Addedtslib@2.8.1(transitive)
+ Addedupper-case@2.0.2(transitive)
- Removedcamelcase@^6.0.0
- Removedcamelcase@6.3.0(transitive)