| 175 | } |
| 176 | |
| 177 | function extractInlineSource(text) { |
| 178 | const matches = Array.from( |
| 179 | text.matchAll( |
| 180 | /\/\/# sourceMappingURL=data:application\/json(?:;charset=[^;,]+)?;base64,([A-Za-z0-9+/=]+)\s*$/gm, |
| 181 | ), |
| 182 | ) |
| 183 | const encoded = matches.at(-1)?.[1] |
| 184 | if (!encoded) { |
| 185 | return null |
| 186 | } |
| 187 | |
| 188 | try { |
| 189 | const decoded = Buffer.from(encoded, 'base64').toString('utf8') |
| 190 | const map = JSON.parse(decoded) |
| 191 | if (!Array.isArray(map.sourcesContent) || map.sourcesContent.length === 0) { |
| 192 | return null |
| 193 | } |
| 194 | |
| 195 | const content = |
| 196 | typeof map.sourcesContent[0] === 'string' ? map.sourcesContent[0] : null |
| 197 | if (!content) { |
| 198 | return null |
| 199 | } |
| 200 | |
| 201 | return { |
| 202 | content, |
| 203 | sourceName: Array.isArray(map.sources) ? map.sources[0] ?? null : null, |
| 204 | } |
| 205 | } catch { |
| 206 | return null |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | function collectDependencyRoots(sourceText, dependencyRoots) { |
| 211 | const patterns = [ |