(groups: Group[])
| 47 | } |
| 48 | |
| 49 | export async function rewriteCurrentScript(groups: Group[]): Promise<void> { |
| 50 | const current = getCurrentScript() |
| 51 | if (!current) { |
| 52 | return |
| 53 | } |
| 54 | |
| 55 | const src = current.src |
| 56 | |
| 57 | try { |
| 58 | const response = await fetch(src) |
| 59 | const original = await response.text() |
| 60 | const { content: rewritten, changed } = applyGroups(original, groups) |
| 61 | |
| 62 | if (changed) { |
| 63 | logger.log(`Rewrote script: ${src}`) |
| 64 | } |
| 65 | |
| 66 | const content = patchFigmaDelete(rewritten) |
| 67 | withCurrentScript(current, () => { |
| 68 | new Function(content)() |
| 69 | }) |
| 70 | } catch (error) { |
| 71 | logger.error(error) |
| 72 | replaceScript(current, `${src}?fallback`) |
| 73 | } |
| 74 | } |
no test coverage detected