( template: string, replacer: (match: string) => Promise<string> )
| 93 | } |
| 94 | |
| 95 | async function replaceEnvVarsAsync( |
| 96 | template: string, |
| 97 | replacer: (match: string) => Promise<string> |
| 98 | ): Promise<string> { |
| 99 | const pattern = createEnvVarPattern() |
| 100 | let cursor = 0 |
| 101 | let result = '' |
| 102 | for (const match of template.matchAll(pattern)) { |
| 103 | const fullMatch = match[0] |
| 104 | const index = match.index ?? 0 |
| 105 | result += template.slice(cursor, index) |
| 106 | result += await replacer(fullMatch) |
| 107 | cursor = index + fullMatch.length |
| 108 | } |
| 109 | return result + template.slice(cursor) |
| 110 | } |
| 111 | |
| 112 | type ShellQuoteContext = 'single' | 'double' | null |
| 113 | type CodeStringQuoteContext = ShellQuoteContext | 'triple-single' | 'triple-double' | 'template' |
no test coverage detected