* Patches Resize Observer polyfill by wrapping its body into `install` * function. * This gives us an option to control when and how the polyfill is installed. * The polyfill can only be installed on the root context.
()
| 80 | * The polyfill can only be installed on the root context. |
| 81 | */ |
| 82 | function patchResizeObserver() { |
| 83 | // Copies intersection-observer into a new file that has an export. |
| 84 | const patchedName = |
| 85 | 'node_modules/resize-observer-polyfill/ResizeObserver.install.js'; |
| 86 | let file = fs |
| 87 | .readFileSync( |
| 88 | 'node_modules/resize-observer-polyfill/dist/ResizeObserver.js' |
| 89 | ) |
| 90 | .toString(); |
| 91 | |
| 92 | // Wrap the contents inside the install function. |
| 93 | file = `export function installResizeObserver(global) {\n${file}\n}\n` |
| 94 | // For some reason Closure fails on this three lines. Babel is fine. |
| 95 | .replace( |
| 96 | "typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :", |
| 97 | '' |
| 98 | ) |
| 99 | .replace( |
| 100 | "typeof define === 'function' && define.amd ? define(factory) :", |
| 101 | '' |
| 102 | ) |
| 103 | .replace('}(this, (function () {', '}(global, (function () {'); |
| 104 | writeIfUpdated(patchedName, file); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Patches Shadow DOM polyfill by wrapping its body into `install` |
no test coverage detected