(dockerfile: Dockerfile, buildArgs: Record<string, string>, baseImageEnv: Record<string, string>, globalBuildxPlatformArgs: Record<string, string> = {}, str: string, stage: { from?: From; instructions: Instruction[] }, beforeInstructionIndex: number)
| 156 | } |
| 157 | |
| 158 | function replaceVariables(dockerfile: Dockerfile, buildArgs: Record<string, string>, baseImageEnv: Record<string, string>, globalBuildxPlatformArgs: Record<string, string> = {}, str: string, stage: { from?: From; instructions: Instruction[] }, beforeInstructionIndex: number) { |
| 159 | return [...str.matchAll(argumentExpression)] |
| 160 | .map(match => { |
| 161 | const variable = match.groups!.variable; |
| 162 | const isVarExp = match.groups!.isVarExp ? true : false; |
| 163 | let value = findValue(dockerfile, buildArgs, baseImageEnv, globalBuildxPlatformArgs, variable, stage, beforeInstructionIndex) || ''; |
| 164 | if (isVarExp) { |
| 165 | // Handle replacing variable expressions (${var:+word}) if they exist |
| 166 | const option = match.groups!.option; |
| 167 | const word = match.groups!.word; |
| 168 | const isSet = value !== ''; |
| 169 | value = getExpressionValue(option, isSet, word, value); |
| 170 | } |
| 171 | |
| 172 | return { |
| 173 | begin: match.index!, |
| 174 | end: match.index! + match[0].length, |
| 175 | value, |
| 176 | }; |
| 177 | }).reverse() |
| 178 | .reduce((str, { begin, end, value }) => str.substring(0, begin) + value + str.substring(end), str); |
| 179 | } |
| 180 | |
| 181 | function findValue(dockerfile: Dockerfile, buildArgs: Record<string, string>, baseImageEnv: Record<string, string>, globalBuildxPlatformArgs: Record<string, string> = {}, variable: string, stage: { from?: From; instructions: Instruction[] }, beforeInstructionIndex: number): string | undefined { |
| 182 | let considerArg = true; |
no test coverage detected