(path, src, dest)
| 5 | const patched = {}; |
| 6 | |
| 7 | const replace = (path, src, dest) => { |
| 8 | if (Array.isArray(path)) { |
| 9 | path.forEach(path => replace(path, src, dest)); |
| 10 | return; |
| 11 | } |
| 12 | try { |
| 13 | if (!path.startsWith("types/")) |
| 14 | path = "types/" + path; |
| 15 | |
| 16 | const before = patched[path] ?? |
| 17 | (cache[path] ??= fs.readFileSync("./" + path, { encoding: 'utf-8' })); |
| 18 | const after = before.replaceAll(src, dest); |
| 19 | |
| 20 | if (after !== before) |
| 21 | patched[path] = after; |
| 22 | else |
| 23 | console.error(`A patch failed in ${path}:\n -${src}\n +${dest}`); |
| 24 | } catch (err) { |
| 25 | console.error(err); |
| 26 | } |
| 27 | }; |
| 28 | |
| 29 | // TODO: Handle this better in the docs instead of patching |
| 30 | replace( |
no outgoing calls
no test coverage detected