1 Commits

2 changed files with 49 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@hublib-web/video-player", "name": "@hublib-web/video-player",
"version": "0.1.0", "version": "0.1.1",
"description": "Cross-framework video player package for React and Angular", "description": "Cross-framework video player package for React and Angular",
"license": "MIT", "license": "MIT",
"type": "module", "type": "module",
@@ -10,7 +10,8 @@
"sideEffects": true, "sideEffects": true,
"files": [ "files": [
"dist", "dist",
"README.md" "README.md",
"scripts"
], ],
"typesVersions": { "typesVersions": {
"*": { "*": {
@@ -48,6 +49,7 @@
} }
}, },
"scripts": { "scripts": {
"postinstall": "node ./scripts/apply-videojs-patch.mjs",
"build": "yarn clean && node ./scripts/build.mjs", "build": "yarn clean && node ./scripts/build.mjs",
"clean": "rm -rf dist storybook-static", "clean": "rm -rf dist storybook-static",
"typecheck": "tsc -p ./tsconfig.json --noEmit", "typecheck": "tsc -p ./tsconfig.json --noEmit",

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);
}