Files
_hublib-web/packages/video-player/scripts/apply-videojs-patch.mjs

46 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

import { readFileSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const originalSnippet = ` const originalAbort = request.abort;
request.abort = function () {
request.aborted = true;
return originalAbort.apply(request, arguments);
};`;
const patchedSnippet = ` // const originalAbort = request.abort;
// request.abort = function () {
// request.aborted = true;
// return originalAbort.apply(request, arguments);
// };`;
function run() {
const packageJsonPath = require.resolve("video.js/package.json");
const videoEsPath = join(dirname(packageJsonPath), "dist", "video.es.js");
const source = readFileSync(videoEsPath, "utf8");
if (source.includes(patchedSnippet)) {
console.log("[video-player] video.js patch already applied");
return;
}
if (!source.includes(originalSnippet)) {
throw new Error(
"[video-player] Cannot apply video.js patch: target snippet not found. Expected video.js 8.23.4 source."
);
}
const patched = source.replace(originalSnippet, patchedSnippet);
writeFileSync(videoEsPath, patched, "utf8");
console.log("[video-player] Applied video.js patch");
}
try {
run();
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exit(1);
}