Files
return-youtube-dislike/webpack.live-build-marker.js
T
Anarios 3657de9b2c Fix Shorts support and add userscript voting
Harden Shorts controls, reaction state, and navigation; share voting logic
with the extension; improve ratio-bar rendering; and add comprehensive Jest,
Playwright, artifact, and live-browser regression coverage.
2026-09-01 23:41:28 +02:00

41 lines
1.1 KiB
JavaScript

const crypto = require("node:crypto");
const LIVE_BUILD_ID_PATTERN = /^[a-f0-9]{32}$/;
function createLiveBuildId(enabled) {
return enabled ? crypto.randomBytes(16).toString("hex") : "";
}
class LiveBuildMarkerPlugin {
constructor(buildId, assetNames) {
if (!LIVE_BUILD_ID_PATTERN.test(buildId)) {
throw new TypeError("A live build marker requires a 32-character hexadecimal build ID.");
}
this.assetNames = assetNames;
this.buildId = buildId;
}
apply(compiler) {
compiler.hooks.thisCompilation.tap("LiveBuildMarkerPlugin", (compilation) => {
compilation.hooks.processAssets.tap(
{
name: "LiveBuildMarkerPlugin",
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
},
() => {
const source = new compiler.webpack.sources.RawSource(`${JSON.stringify({ buildId: this.buildId })}\n`);
for (const assetName of this.assetNames) {
compilation.emitAsset(assetName, source);
}
},
);
});
}
}
module.exports = {
LIVE_BUILD_ID_PATTERN,
LiveBuildMarkerPlugin,
createLiveBuildId,
};