diff --git a/_scripts/patch-shaka-player-loader.js b/_scripts/patch-shaka-player-loader.js new file mode 100644 index 0000000000000..c65fec616b56b --- /dev/null +++ b/_scripts/patch-shaka-player-loader.js @@ -0,0 +1,8 @@ +/** + * fixes shaka-player referencing the Roboto font on google fonts in its CSS + * by updating the CSS to point to the local Roboto font + * @param {string} source + */ +module.exports = function (source) { + return source.replace(/@font-face{font-family:Roboto;[^}]+}/, '') +} diff --git a/_scripts/patchShaka.mjs b/_scripts/patchShaka.mjs deleted file mode 100644 index 27e95c9689219..0000000000000 --- a/_scripts/patchShaka.mjs +++ /dev/null @@ -1,33 +0,0 @@ -// This script fixes shaka-player referencing the Roboto font on google fonts in its CSS -// by updating the CSS to point to the local Roboto font -// this script only makes changes if they are needed, so running it multiple times doesn't cause any problems - -import { closeSync, ftruncateSync, openSync, readFileSync, writeSync } from 'fs' -import { resolve } from 'path' - -const SHAKA_DIST_DIR = resolve(import.meta.dirname, '../node_modules/shaka-player/dist') - -function removeRobotoFont() { - let cssFileHandle - try { - cssFileHandle = openSync(`${SHAKA_DIST_DIR}/controls.css`, 'r+') - - let cssContents = readFileSync(cssFileHandle, 'utf-8') - - const beforeReplacement = cssContents.length - cssContents = cssContents.replace(/@font-face{font-family:Roboto;[^}]+}/, '') - - if (cssContents.length !== beforeReplacement) { - ftruncateSync(cssFileHandle) - writeSync(cssFileHandle, cssContents, 0, 'utf-8') - - console.log('Removed shaka-player Roboto font, so it uses ours') - } - } finally { - if (cssFileHandle !== undefined) { - closeSync(cssFileHandle) - } - } -} - -removeRobotoFont() diff --git a/_scripts/webpack.renderer.config.js b/_scripts/webpack.renderer.config.js index b55a52a633291..b8ae34a8abe03 100644 --- a/_scripts/webpack.renderer.config.js +++ b/_scripts/webpack.renderer.config.js @@ -93,6 +93,12 @@ const config = { } } ], + rules: [ + { + resource: path.resolve(__dirname, '../node_modules/shaka-player/dist/controls.css'), + use: path.join(__dirname, 'patch-shaka-player-loader.js') + } + ], }, { test: /\.(png|jpe?g|gif|tif?f|bmp|webp|svg)(\?.*)?$/, diff --git a/_scripts/webpack.web.config.js b/_scripts/webpack.web.config.js index bb685b2275f8a..022f0532f23d8 100644 --- a/_scripts/webpack.web.config.js +++ b/_scripts/webpack.web.config.js @@ -83,6 +83,12 @@ const config = { } } ], + rules: [ + { + resource: path.resolve(__dirname, '../node_modules/shaka-player/dist/controls.css'), + use: path.join(__dirname, 'patch-shaka-player-loader.js') + } + ], }, { test: /\.html$/, diff --git a/package.json b/package.json index b5c80371a7698..7ae2ba368174d 100644 --- a/package.json +++ b/package.json @@ -19,20 +19,17 @@ "url": "https://github.com/FreeTubeApp/FreeTube/issues" }, "scripts": { - "build": "run-s patch-shaka pack build-release", - "build:arm64": "run-s patch-shaka pack build-release:arm64", - "build:arm32": "run-s patch-shaka pack build-release:arm32", + "build": "run-s pack build-release", + "build:arm64": "run-s pack build-release:arm64", + "build:arm32": "run-s pack build-release:arm32", "build-release": "node _scripts/build.mjs", "build-release:arm64": "node _scripts/build.mjs arm64", "build-release:arm32": "node _scripts/build.mjs arm32", "clean": "node _scripts/clean.mjs", - "debug": "run-s patch-shaka debug-runner", - "debug-runner": "node _scripts/dev-runner.js --remote-debug", - "dev": "run-s patch-shaka dev-runner", + "debug": "node _scripts/dev-runner.js --remote-debug", + "dev": "node _scripts/dev-runner.js", "dev:web": "node _scripts/dev-runner.js --web", - "dev-runner": "node _scripts/dev-runner.js", "get-instances": "node _scripts/getInstances.js", - "patch-shaka": "node _scripts/patchShaka.mjs", "get-regions": "node _scripts/getRegions.mjs", "lint-all": "run-p lint lint-json", "lint": "run-p eslint-lint lint-style", @@ -49,7 +46,6 @@ "pack:preload": "webpack --mode=production --node-env=production --config _scripts/webpack.preload.config.js", "pack:web": "webpack --mode=production --node-env=production --config _scripts/webpack.web.config.js", "pack:botGuardScript": "webpack --config _scripts/webpack.botGuardScript.config.js", - "postinstall": "yarn run --silent patch-shaka", "checkforbadtemplates": "node _scripts/findMissingTemplates.mjs", "ci": "yarn install --silent --frozen-lockfile --network-concurrency 1" },