feat: Перенести патч videojs в библиотеку

This commit is contained in:
2026-03-04 18:06:13 +03:00
parent 915c56351b
commit 028ce21c4c
2 changed files with 49 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
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);
}