Variable ADMIN_EXTEND_JSConst
ADMIN_EXTEND_JS: "(function () {\n\tconst out = document.getElementById('installed');\n\t// the module a composer package provides is its name after the vendor prefix, so drupal/pathauto\n\t// enables as pathauto, which is what /enable takes\n\tfunction machineName(pkg) {\n\t\treturn String(pkg).split('/').pop().replace(/-/g, '_');\n\t}\n\tasync function ask(url) {\n\t\tconst res = await fetch(url, { credentials: 'same-origin' });\n\t\tconst body = await res.json().catch(() => ({}));\n\t\tif (!res.ok) throw new Error(body.refused || body.error || 'HTTP ' + res.status);\n\t\treturn body;\n\t}\n\tasync function install(name, force) {\n\t\tout.textContent = 'Installing ' + name + '...';\n\t\ttry {\n\t\t\tconst body = await ask(\n\t\t\t\t'/install?module=' + encodeURIComponent(name) + (force ? '&force=1' : '')\n\t\t\t);\n\t\t\t// installPackage() reports `files`; this read `stored`, which it has never returned, so\n\t\t\t// every successful install said \"0 files\"\n\t\t\tout.textContent =\n\t\t\t\t'Installed ' + name + ': ' + (body.files || 0) + ' files. Now enable it.';\n\t\t\tconst b = document.querySelector('[data-enable=\"' + name + '\"]');\n\t\t\tif (b) b.disabled = false;\n\t\t} catch (e) {\n\t\t\tout.textContent = 'Refused: ' + e.message;\n\t\t}\n\t}\n\tasync function enable(name) {\n\t\tconst machine = machineName(name);\n\t\tout.textContent = 'Enabling ' + machine + '...';\n\t\ttry {\n\t\t\t// `retry` means the object dropped a resident interpreter and needs a new invocation\n\t\t\t// before it can boot a fresh one. Repeated here rather than shown, because it is\n\t\t\t// bookkeeping the operator did not ask about\n\t\t\tlet body = await ask('/enable?module=' + encodeURIComponent(machine));\n\t\t\tfor (let i = 0; i < 2 && body.retry; i++) {\n\t\t\t\tawait new Promise((r) => setTimeout(r, 2000));\n\t\t\t\tbody = await ask('/enable?module=' + encodeURIComponent(machine));\n\t\t\t}\n\t\t\t// `nowEnabled` is what ENABLE_MODULE reads back out of core.extension. This read\n\t\t\t// `enabled`, which only ENABLE_VERIFY sets and only to a module name, so a successful\n\t\t\t// enable rendered \"Not enabled: unknown\"\n\t\t\tif (!body.nowEnabled) {\n\t\t\t\tout.textContent =\n\t\t\t\t\t'Not enabled: ' +\n\t\t\t\t\t(body.error || body.throwMessage || body.readbackError || 'unknown');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout.textContent = 'Enabled ' + machine + '.';\n\t\t\t// the object hands back this cue and the page dropped it, so a UI enable left the\n\t\t\t// requeued pages asleep until the next alarm happened along\n\t\t\tif (body.armFill) {\n\t\t\t\tout.textContent = 'Enabled ' + machine + '. Waking the fill chain...';\n\t\t\t\ttry {\n\t\t\t\t\tawait ask('/armfill');\n\t\t\t\t\tout.textContent = 'Enabled ' + machine + '. Pages are regenerating.';\n\t\t\t\t} catch (e) {\n\t\t\t\t\tout.textContent =\n\t\t\t\t\t\t'Enabled ' + machine + ', but the fill chain did not wake: ' + e.message;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tout.textContent = 'Refused: ' + e.message;\n\t\t}\n\t}\n\tfor (const b of document.querySelectorAll('[data-install]')) {\n\t\tb.addEventListener('click', () => install(b.dataset.install, b.dataset.force === '1'));\n\t}\n\tfor (const b of document.querySelectorAll('[data-enable]')) {\n\t\tb.addEventListener('click', () => enable(b.dataset.enable));\n\t}\n})();\n"