/
githubmirror
/
grafana
Обзор
Документация
Войти
/
githubmirror
/
grafana
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
scripts/rspack/plugins/FeatureFlaggedSriPlugin.ts
33 строки
1 KB
Jack Westbrook
Frontend: add custom rspack plugins (#129968)
05 авг 2026, 13:39
Не верифицирован
05 авг 2026, 13:39
0408c03
Код
Авторство
О чём код?
import { type Compiler } from '@rspack/core'; const PLUGIN_NAME = 'FeatureFlaggedSRIPlugin'; const LOAD_SCRIPT_RUNTIME_MODULE_NAME = 'load_script'; // Match on both script.integrity and script.crossOrigin. const SRI_ATTRIBUTES_REGEX = /(?<indent>[ \t]*)(?<sriAttributes>script\.integrity = .+;\r?\n[ \t]*script\.crossOrigin = .+;)/; export default class FeatureFlaggedSRIPlugin { apply(compiler: Compiler): void { const logger = compiler.getInfrastructureLogger(PLUGIN_NAME); compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module) => { if (module.name !== LOAD_SCRIPT_RUNTIME_MODULE_NAME || !module.source) { return; } const source = module.source.source.toString(); if (!SRI_ATTRIBUTES_REGEX.test(source)) { return; } logger.log('FeatureFlaggedSRIPlugin: Wrapping SRI checks in feature flag'); const wrapped = source.replace( SRI_ATTRIBUTES_REGEX, '$<indent>if (window.__grafanaAssetSriChecksEnabled) {\n$<indent>$<sriAttributes>\n$<indent>}' ); module.source.source = Buffer.from(wrapped, 'utf-8'); }); }); } }