MCPcopy Index your code
hub / github.com/ampproject/amphtml / patchResizeObserver

Function patchResizeObserver

build-system/common/update-packages.js:82–105  ·  view source on GitHub ↗

* 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.

()

Source from the content-addressed store, hash-verified

80 * The polyfill can only be installed on the root context.
81 */
82function 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`

Callers 1

updatePackagesFunction · 0.85

Calls 3

writeIfUpdatedFunction · 0.85
toStringMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected