MCPcopy Index your code
hub / github.com/devcontainers/cli / replaceVariables

Function replaceVariables

src/spec-node/dockerfileUtils.ts:158–179  ·  view source on GitHub ↗
(dockerfile: Dockerfile, buildArgs: Record<string, string>, baseImageEnv: Record<string, string>, globalBuildxPlatformArgs: Record<string, string> = {}, str: string, stage: { from?: From; instructions: Instruction[] }, beforeInstructionIndex: number)

Source from the content-addressed store, hash-verified

156}
157
158function 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
181function 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;

Callers 3

findUserStatementFunction · 0.85
findBaseImageFunction · 0.85
findValueFunction · 0.85

Calls 2

findValueFunction · 0.85
getExpressionValueFunction · 0.85

Tested by

no test coverage detected