( content: string, nvmrcVersion: string | undefined, )
| 230 | |
| 231 | /** Synchronizes the Node.js toolchain versions and repositories in MODULE.bazel. */ |
| 232 | export async function syncNodeJs( |
| 233 | content: string, |
| 234 | nvmrcVersion: string | undefined, |
| 235 | ): Promise<string> { |
| 236 | const parts: string[] = []; |
| 237 | let lastIndex = 0; |
| 238 | let startIndex = 0; |
| 239 | |
| 240 | while ((startIndex = content.indexOf('node.toolchain(', startIndex)) !== -1) { |
| 241 | const openParenIndex = startIndex + 'node.toolchain('.length - 1; |
| 242 | const endIndex = findClosedParenIndex(content, openParenIndex); |
| 243 | |
| 244 | if (endIndex === -1) { |
| 245 | break; |
| 246 | } |
| 247 | |
| 248 | parts.push(content.slice(lastIndex, startIndex)); |
| 249 | |
| 250 | const args = content.slice(openParenIndex + 1, endIndex); |
| 251 | const updatedArgs = await processNodeToolchainArgs(args, nvmrcVersion); |
| 252 | parts.push(`node.toolchain(${updatedArgs})`); |
| 253 | |
| 254 | lastIndex = endIndex + 1; |
| 255 | startIndex = lastIndex; |
| 256 | } |
| 257 | |
| 258 | parts.push(content.slice(lastIndex)); |
| 259 | |
| 260 | return parts.join(''); |
| 261 | } |
no test coverage detected