diff --git a/CHANGELOG.md b/CHANGELOG.md index ab33baca1d4..df5a47faac2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,5 @@ ## Unreleased -### Features - -- Add a supplementary `worker.es5.js` file and its corresponding `EMBEDDED_WORKER_ES5` - embed to make the `MULTI_THREAD` experimental feature work on old browser environments - [#1400] - ### Bug fixes - Directfile/compat: On safari mobile in directfile mode, do not stay in an infinite diff --git a/doc/api/Miscellaneous/MultiThreading.md b/doc/api/Miscellaneous/MultiThreading.md index 8f55afe6577..b2d2ec71b28 100644 --- a/doc/api/Miscellaneous/MultiThreading.md +++ b/doc/api/Miscellaneous/MultiThreading.md @@ -383,29 +383,12 @@ if (currentModeInfo === null) { ## Note about ES5 Environment -By default, the Worker file will use es2017 features which should be compatible to a -majority of devices. +The Worker file will use es2017 features which should be compatible to a majority of +devices. However, some older devices might not be compatible with it yet still compatible to the -WebWorker API (and thus the `MULTI_THREAD` feature), yet not with ES2017. For those -platforms, the RxPlayer also provide an ES5 variant of the Worker file: +WebWorker API (and thus the `MULTI_THREAD` feature), yet not with ES2017. -- The easiest way is to just import in your application its "embedded" version, exported - through the `"rx-player/experimental/features/embeds"` path: - - ```js - import { EMBEDDED_WORKER_ES5 } from "rx-player/experimental/features/embeds"; - ``` - - This allows to bypass the need to store and serve separately that file. - - If you would prefer more control and a smaller bundle size, you may instead consider the - other following ways to it as a separate file. - -- With every release note published on GitHub as `worker.es5.js` (you should only use the - file linked to the RxPlayer's version you're using), - -- It is also available as `dist/worker.es5.js` from the root directory of the project - published on npm. As such, it might already be found in your project's directory, for - example in the `node_modules` directory (most probably in `node_modules/rx-player/dist/` - depending on your project). +If you need to provide support for the `MULTI_THREAD` feature on those platforms, we +recommend that you use a transpiler tool on that worker file to make it compatible to ES5. +Examples of transpiler tools are [babel](https://babeljs.io/) and [swc](https://swc.rs/). diff --git a/package-lock.json b/package-lock.json index b761425e772..bd35237d787 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "@babel/preset-env": "7.23.6", "@babel/preset-react": "7.23.3", "@canalplus/readme.doc": "0.5.0", - "@swc/core": "^1.4.11", "@types/chai": "4.3.11", "@types/jest": "29.5.11", "@types/mocha": "10.0.6", @@ -3474,219 +3473,6 @@ "integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==", "dev": true }, - "node_modules/@swc/core": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.4.11.tgz", - "integrity": "sha512-WKEakMZxkVwRdgMN4AMJ9K5nysY8g8npgQPczmjBeNK5In7QEAZAJwnyccrWwJZU0XjVeHn2uj+XbOKdDW17rg==", - "dev": true, - "hasInstallScript": true, - "dependencies": { - "@swc/counter": "^0.1.2", - "@swc/types": "^0.1.5" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/swc" - }, - "optionalDependencies": { - "@swc/core-darwin-arm64": "1.4.11", - "@swc/core-darwin-x64": "1.4.11", - "@swc/core-linux-arm-gnueabihf": "1.4.11", - "@swc/core-linux-arm64-gnu": "1.4.11", - "@swc/core-linux-arm64-musl": "1.4.11", - "@swc/core-linux-x64-gnu": "1.4.11", - "@swc/core-linux-x64-musl": "1.4.11", - "@swc/core-win32-arm64-msvc": "1.4.11", - "@swc/core-win32-ia32-msvc": "1.4.11", - "@swc/core-win32-x64-msvc": "1.4.11" - }, - "peerDependencies": { - "@swc/helpers": "^0.5.0" - }, - "peerDependenciesMeta": { - "@swc/helpers": { - "optional": true - } - } - }, - "node_modules/@swc/core-darwin-arm64": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.4.11.tgz", - "integrity": "sha512-C1j1Qp/IHSelVWdEnT7f0iONWxQz6FAqzjCF2iaL+0vFg4V5f2nlgrueY8vj5pNNzSGhrAlxsMxEIp4dj1MXkg==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-darwin-x64": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.4.11.tgz", - "integrity": "sha512-0TTy3Ni8ncgaMCchSQ7FK8ZXQLlamy0FXmGWbR58c+pVZWYZltYPTmheJUvVcR0H2+gPAymRKyfC0iLszDALjg==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm-gnueabihf": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.4.11.tgz", - "integrity": "sha512-XJLB71uw0rog4DjYAPxFGAuGCBQpgJDlPZZK6MTmZOvI/1t0+DelJ24IjHIxk500YYM26Yv47xPabqFPD7I2zQ==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-gnu": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.4.11.tgz", - "integrity": "sha512-vYQwzJvm/iu052d5Iw27UFALIN5xSrGkPZXxLNMHPySVko2QMNNBv35HLatkEQHbQ3X+VKSW9J9SkdtAvAVRAQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-musl": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.4.11.tgz", - "integrity": "sha512-eV+KduiRYUFjPsvbZuJ9aknQH9Tj0U2/G9oIZSzLx/18WsYi+upzHbgxmIIHJ2VJgfd7nN40RI/hMtxNsUzR/g==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-x64-gnu": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.4.11.tgz", - "integrity": "sha512-WA1iGXZ2HpqM1OR9VCQZJ8sQ1KP2or9O4bO8vWZo6HZJIeoQSo7aa9waaCLRpkZvkng1ct/TF/l6ymqSNFXIzQ==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-x64-musl": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.4.11.tgz", - "integrity": "sha512-UkVJToKf0owwQYRnGvjHAeYVDfeimCEcx0VQSbJoN7Iy0ckRZi7YPlmWJU31xtKvikE2bQWCOVe0qbSDqqcWXA==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-arm64-msvc": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.4.11.tgz", - "integrity": "sha512-35khwkyly7lF5NDSyvIrukBMzxPorgc5iTSDfVO/LvnmN5+fm4lTlrDr4tUfTdOhv3Emy7CsKlsNAeFRJ+Pm+w==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-ia32-msvc": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.4.11.tgz", - "integrity": "sha512-Wx8/6f0ufgQF2pbVPsJ2dAmFLwIOW+xBE5fxnb7VnEbGkTgP1qMDWiiAtD9rtvDSuODG3i1AEmAak/2HAc6i6A==", - "cpu": [ - "ia32" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-x64-msvc": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.4.11.tgz", - "integrity": "sha512-0xRFW6K9UZQH2NVC/0pVB0GJXS45lY24f+6XaPBF1YnMHd8A8GoHl7ugyM5yNUTe2AKhSgk5fJV00EJt/XBtdQ==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/counter": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz", - "integrity": "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==", - "dev": true - }, - "node_modules/@swc/types": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/@swc/types/-/types-0.1.6.tgz", - "integrity": "sha512-/JLo/l2JsT/LRd80C3HfbmVpxOAJ11FO2RCEslFrgzLltoP9j8XIbsyDcfCt2WWyX+CM96rBoNM+IToAkFOugg==", - "dev": true, - "dependencies": { - "@swc/counter": "^0.1.3" - } - }, "node_modules/@tootallnate/once": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", @@ -17381,111 +17167,6 @@ "integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==", "dev": true }, - "@swc/core": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.4.11.tgz", - "integrity": "sha512-WKEakMZxkVwRdgMN4AMJ9K5nysY8g8npgQPczmjBeNK5In7QEAZAJwnyccrWwJZU0XjVeHn2uj+XbOKdDW17rg==", - "dev": true, - "requires": { - "@swc/core-darwin-arm64": "1.4.11", - "@swc/core-darwin-x64": "1.4.11", - "@swc/core-linux-arm-gnueabihf": "1.4.11", - "@swc/core-linux-arm64-gnu": "1.4.11", - "@swc/core-linux-arm64-musl": "1.4.11", - "@swc/core-linux-x64-gnu": "1.4.11", - "@swc/core-linux-x64-musl": "1.4.11", - "@swc/core-win32-arm64-msvc": "1.4.11", - "@swc/core-win32-ia32-msvc": "1.4.11", - "@swc/core-win32-x64-msvc": "1.4.11", - "@swc/counter": "^0.1.2", - "@swc/types": "^0.1.5" - } - }, - "@swc/core-darwin-arm64": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.4.11.tgz", - "integrity": "sha512-C1j1Qp/IHSelVWdEnT7f0iONWxQz6FAqzjCF2iaL+0vFg4V5f2nlgrueY8vj5pNNzSGhrAlxsMxEIp4dj1MXkg==", - "dev": true, - "optional": true - }, - "@swc/core-darwin-x64": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.4.11.tgz", - "integrity": "sha512-0TTy3Ni8ncgaMCchSQ7FK8ZXQLlamy0FXmGWbR58c+pVZWYZltYPTmheJUvVcR0H2+gPAymRKyfC0iLszDALjg==", - "dev": true, - "optional": true - }, - "@swc/core-linux-arm-gnueabihf": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.4.11.tgz", - "integrity": "sha512-XJLB71uw0rog4DjYAPxFGAuGCBQpgJDlPZZK6MTmZOvI/1t0+DelJ24IjHIxk500YYM26Yv47xPabqFPD7I2zQ==", - "dev": true, - "optional": true - }, - "@swc/core-linux-arm64-gnu": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.4.11.tgz", - "integrity": "sha512-vYQwzJvm/iu052d5Iw27UFALIN5xSrGkPZXxLNMHPySVko2QMNNBv35HLatkEQHbQ3X+VKSW9J9SkdtAvAVRAQ==", - "dev": true, - "optional": true - }, - "@swc/core-linux-arm64-musl": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.4.11.tgz", - "integrity": "sha512-eV+KduiRYUFjPsvbZuJ9aknQH9Tj0U2/G9oIZSzLx/18WsYi+upzHbgxmIIHJ2VJgfd7nN40RI/hMtxNsUzR/g==", - "dev": true, - "optional": true - }, - "@swc/core-linux-x64-gnu": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.4.11.tgz", - "integrity": "sha512-WA1iGXZ2HpqM1OR9VCQZJ8sQ1KP2or9O4bO8vWZo6HZJIeoQSo7aa9waaCLRpkZvkng1ct/TF/l6ymqSNFXIzQ==", - "dev": true, - "optional": true - }, - "@swc/core-linux-x64-musl": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.4.11.tgz", - "integrity": "sha512-UkVJToKf0owwQYRnGvjHAeYVDfeimCEcx0VQSbJoN7Iy0ckRZi7YPlmWJU31xtKvikE2bQWCOVe0qbSDqqcWXA==", - "dev": true, - "optional": true - }, - "@swc/core-win32-arm64-msvc": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.4.11.tgz", - "integrity": "sha512-35khwkyly7lF5NDSyvIrukBMzxPorgc5iTSDfVO/LvnmN5+fm4lTlrDr4tUfTdOhv3Emy7CsKlsNAeFRJ+Pm+w==", - "dev": true, - "optional": true - }, - "@swc/core-win32-ia32-msvc": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.4.11.tgz", - "integrity": "sha512-Wx8/6f0ufgQF2pbVPsJ2dAmFLwIOW+xBE5fxnb7VnEbGkTgP1qMDWiiAtD9rtvDSuODG3i1AEmAak/2HAc6i6A==", - "dev": true, - "optional": true - }, - "@swc/core-win32-x64-msvc": { - "version": "1.4.11", - "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.4.11.tgz", - "integrity": "sha512-0xRFW6K9UZQH2NVC/0pVB0GJXS45lY24f+6XaPBF1YnMHd8A8GoHl7ugyM5yNUTe2AKhSgk5fJV00EJt/XBtdQ==", - "dev": true, - "optional": true - }, - "@swc/counter": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz", - "integrity": "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==", - "dev": true - }, - "@swc/types": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/@swc/types/-/types-0.1.6.tgz", - "integrity": "sha512-/JLo/l2JsT/LRd80C3HfbmVpxOAJ11FO2RCEslFrgzLltoP9j8XIbsyDcfCt2WWyX+CM96rBoNM+IToAkFOugg==", - "dev": true, - "requires": { - "@swc/counter": "^0.1.3" - } - }, "@tootallnate/once": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", diff --git a/package.json b/package.json index 170f22d5e09..badf81e42ec 100644 --- a/package.json +++ b/package.json @@ -145,10 +145,10 @@ "build:dev": "./scripts/generate_build.mjs --dev-mode", "build:wasm:debug": "mkdir -p dist && cd ./src/parsers/manifest/dash/wasm-parser && cargo build --target wasm32-unknown-unknown && cp target/wasm32-unknown-unknown/debug/mpd_node_parser.wasm ../../../../../dist/mpd-parser.wasm", "build:wasm:release": "./scripts/build_wasm_release.sh", - "bundle": "./scripts/run_bundler.mjs src/index.ts --production-mode --es5 dist/rx-player.js", - "bundle:min": "./scripts/run_bundler.mjs src/index.ts --production-mode --es5 dist/rx-player.js --minify", - "bundle:min:watch": "./scripts/run_bundler.mjs src/index.ts --production-mode --es5 dist/rx-player.js --minify --watch", - "bundle:watch": "./scripts/run_bundler.mjs src/index.ts --production-mode --es5 dist/rx-player.js -- watch", + "bundle": "./scripts/run_bundler.mjs src/index.ts --production-mode dist/rx-player.js", + "bundle:min": "./scripts/run_bundler.mjs src/index.ts --production-mode dist/rx-player.js --minify", + "bundle:min:watch": "./scripts/run_bundler.mjs src/index.ts --production-mode dist/rx-player.js --minify --watch", + "bundle:watch": "./scripts/run_bundler.mjs src/index.ts --production-mode dist/rx-player.js -- watch", "certificate": "./scripts/generate_certificate", "check": "npm run check:types && npm run lint", "check:all": "npm run check:types && npm run lint && npm run lint:demo && npm run lint:tests && npm run test:unit && npm run test:integration && npm run test:memory && node -r esm ./scripts/check_nodejs_import_compatibility.js", @@ -198,7 +198,6 @@ "@babel/preset-env": "7.23.6", "@babel/preset-react": "7.23.3", "@canalplus/readme.doc": "0.5.0", - "@swc/core": "^1.4.11", "@types/chai": "4.3.11", "@types/jest": "29.5.11", "@types/mocha": "10.0.6", diff --git a/scripts/generate_build.mjs b/scripts/generate_build.mjs index b46d8d9f178..968dbdd2631 100755 --- a/scripts/generate_build.mjs +++ b/scripts/generate_build.mjs @@ -37,7 +37,6 @@ const BUILD_ARTEFACTS_TO_REMOVE = [ const WORKER_IN_FILE = path.join(ROOT_DIR, "src/worker_entry_point.ts"); const WORKER_OUT_FILE = path.join(ROOT_DIR, "dist/worker.js"); -const ES5_WORKER_OUT_FILE = path.join(ROOT_DIR, "dist/worker.es5.js"); // If true, this script is called directly if (import.meta.url === pathToFileURL(process.argv[1]).href) { @@ -87,7 +86,6 @@ async function generateBuild(options = {}) { watch: false, minify: !devMode, outfile: WORKER_OUT_FILE, - es5Outfile: ES5_WORKER_OUT_FILE, production: !devMode, silent: true, }), diff --git a/scripts/generate_embeds.mjs b/scripts/generate_embeds.mjs index d160ed07e99..9405c2b057d 100644 --- a/scripts/generate_embeds.mjs +++ b/scripts/generate_embeds.mjs @@ -50,13 +50,11 @@ import { fileURLToPath, pathToFileURL } from "url"; const currentDir = dirname(fileURLToPath(import.meta.url)); const originalWasmFilePath = join(currentDir, "../dist/mpd-parser.wasm"); const originalWorkerFilePath = join(currentDir, "../dist/worker.js"); -const originalWorkerEs5FilePath = join(currentDir, "../dist/worker.es5.js"); const codeGenDir = join(currentDir, "../src/__GENERATED_CODE"); const indexPath = join(codeGenDir, "./index.ts"); const mpdEmbedPath = join(codeGenDir, "./embedded_dash_wasm.ts"); const workerEmbedPath = join(codeGenDir, "./embedded_worker.ts"); -const workerEs5EmbedPath = join(codeGenDir, "./embedded_worker_es5.ts"); // If true, this script is called directly if (import.meta.url === pathToFileURL(process.argv[1]).href) { @@ -70,12 +68,7 @@ async function generateEmbeds() { if (!fs.existsSync(codeGenDir)) { fs.mkdirSync(codeGenDir); } - await Promise.all([ - writeWebAssemblyEmbed(), - writeWorkerEmbed(), - writeWorkerEs5Embed(), - writeIndexCode(), - ]); + await Promise.all([writeWebAssemblyEmbed(), writeWorkerEmbed(), writeIndexCode()]); } catch (err) { console.log(err); return Promise.reject(err); @@ -105,22 +98,10 @@ export default blob;`; await writeFile(workerEmbedPath, workerEmbedCode); } -async function writeWorkerEs5Embed() { - const workerEs5Data = await readFile(originalWorkerEs5FilePath, "utf-8"); - const workerEs5EmbedCode = - "const blob = new Blob([" + - `"(function(){" + ${JSON.stringify(workerEs5Data)} + "})()"` + - `], { type: "application/javascript" }); -export { blob as EMBEDDED_WORKER_ES5 }; -export default blob;`; - await writeFile(workerEs5EmbedPath, workerEs5EmbedCode); -} - async function writeIndexCode() { // Hardcode the code declaring and exporting the embedded URL: const indexCode = `export { EMBEDDED_DASH_WASM } from "./embedded_dash_wasm"; -export { EMBEDDED_WORKER } from "./embedded_worker"; -export { EMBEDDED_WORKER_ES5 } from "./embedded_worker_es5";`; +export { EMBEDDED_WORKER } from "./embedded_worker";`; await writeFile(indexPath, indexCode); } diff --git a/scripts/run_bundler.mjs b/scripts/run_bundler.mjs index 33a8f8ab7b2..43456733a35 100755 --- a/scripts/run_bundler.mjs +++ b/scripts/run_bundler.mjs @@ -15,7 +15,6 @@ import * as fs from "fs"; import * as path from "path"; import { pathToFileURL } from "url"; import esbuild from "esbuild"; -import swc from "@swc/core"; import getHumanReadableHours from "./utils/get_human_readable_hours.mjs"; // If true, this script is called directly @@ -62,23 +61,6 @@ if (import.meta.url === pathToFileURL(process.argv[1]).href) { } } - let es5Outfile; - { - let outputIndex = args.indexOf("-5"); - if (outputIndex < 0) { - outputIndex = args.indexOf("--es5"); - } - if (outputIndex >= 0) { - const wantedEs5OutputFile = args[outputIndex + 1]; - if (wantedEs5OutputFile === undefined) { - console.error("ERROR: no output file provided for -5/--es5 option\n"); - displayHelp(); - process.exit(1); - } - es5Outfile = path.normalize(wantedEs5OutputFile); - } - } - try { await runBundler(normalizedPath, { watch: shouldWatch, @@ -86,7 +68,6 @@ if (import.meta.url === pathToFileURL(process.argv[1]).href) { production, silent, outfile, - es5Outfile, }); } catch (err) { console.error(`ERROR: ${err}\n`); @@ -107,8 +88,6 @@ if (import.meta.url === pathToFileURL(process.argv[1]).href) { * @param {boolean} [options.watch] - If `true`, the RxPlayer's files involve * will be watched and the code re-built each time one of them changes. * @param {boolean} [options.silent] - If `true`, we won't output logs. - * @param {string} [options.es5Outfile] - If set, an ES5 bundle will also be - * produced at that path. * @param {string} [options.outfile] - Destination of the produced es2017 * bundle. To ignore to skip ES2017 bundle generation. * @returns {Promise} @@ -119,11 +98,10 @@ export default async function runBundler(inputFile, options) { const isDevMode = !options.production; const isSilent = options.silent; const outfile = options.outfile; - const es5Outfile = options.es5Outfile; const globalScope = !!options.globalScope; - if (outfile === undefined && es5Outfile === undefined) { - throw new Error("Neither an output file nor an es5 output file has been provided"); + if (outfile === undefined) { + throw new Error("No output file has been provided"); } const esbuildStepsPlugin = { @@ -131,9 +109,6 @@ export default async function runBundler(inputFile, options) { setup(build) { build.onStart(() => logWarning(`Bundling of ${inputFile} started`)); build.onEnd((result) => { - if (watch && es5Outfile !== undefined) { - buildAndAnnounceEs5Bundle(result?.outputFiles?.[0]?.contents, es5Outfile); - } if (result.errors.length > 0 || result.warnings.length > 0) { const { errors, warnings } = result; logWarning( @@ -174,38 +149,12 @@ export default async function runBundler(inputFile, options) { }); if (watch) { return context.watch(); - } else if (es5Outfile !== undefined) { - await buildAndAnnounceEs5Bundle(context?.outputFiles?.[0]?.contents, es5Outfile); } } catch (err) { logError(`Bundling failed for ${inputFile}:`, err); throw err; } - async function buildAndAnnounceEs5Bundle(inputData, output) { - let input; - if (inputData !== undefined) { - input = new TextDecoder().decode(inputData); - } else if (outfile !== undefined) { - input = await readFile(outfile, "utf-8"); - } else { - throw new Error("Impossible to generate ES5 bundle: ES2017 bundling not performed"); - } - try { - await transpileToEs5({ - input, - outfile: output, - minify, - }); - if (!isSilent) { - logSuccess(`ES5 file updated at ${output}!`); - } - } catch (err) { - logError(`ES5 file build failed at ${output}: ${err}`); - throw err; - } - } - function logSuccess(msg) { if (!isSilent) { console.log(`\x1b[32m[${getHumanReadableHours()}]\x1b[0m`, msg); @@ -225,78 +174,6 @@ export default async function runBundler(inputFile, options) { } } -/** - * Simple promisified `fs.readFile` API. - * @param {string} filePath - * @param {string|null} encoding - * @returns {*} - Read data, the type depends on the `encoding` parameters (see - * `fs.readFile` documentation). - */ -function readFile(filePath, encoding) { - return new Promise((res, rej) => { - fs.readFile(filePath, { encoding }, function (err, data) { - if (err) { - rej(err); - } - res(data); - }); - }); -} - -/** - * Simple promisified `fs.writeFile` API. - * @param {string} filePath - * @param {string} content - * @returns {Promise} - */ -function writeFile(filePath, content) { - return new Promise((res, rej) => { - fs.writeFile(filePath, content, (err) => { - if (err) { - rej(err); - } - res(); - }); - }); -} - -async function transpileToEs5(options) { - const input = options.input; - const outfile = options.outfile; - const minify = options.minify; - const output = await swc.transform(input, { - jsc: { - parser: { - syntax: "ecmascript", - jsx: false, - dynamicImport: false, - privateMethod: false, - functionBind: false, - exportDefaultFrom: false, - exportNamespaceFrom: false, - decorators: false, - decoratorsBeforeExport: false, - topLevelAwait: false, - importMeta: false, - }, - minify: { - compress: { - unused: true, - }, - mangle: true, - }, - transform: null, - target: "es5", - loose: false, - externalHelpers: false, - // Requires v1.2.50 or upper and requires target to be es2016 or upper. - keepClassNames: false, - }, - minify, - }); - await writeFile(outfile, output.code); -} - /** * Display through `console.log` an helping message relative to how to run this * script. @@ -311,8 +188,6 @@ Available options: -m, --minify Minify the built bundle -o , --output Specify an output file for the ES2017 bundle. To ignore to skip ES2017 bundle generation. - -5 , --es5 Perform an ES5-compatible build, should be followed by the corresponding - output filename (e.g. '-5 "dist/rx-player.es5.js"') -p, --production-mode Build all files in production mode (less runtime checks, mostly). -g, --global-scope If set, enable "global scope mode" (the \`__GLOBAL_SCOPE__\` global symbol) on the bundle. diff --git a/tests/integration/scenarios/dash_multi_periods.js b/tests/integration/scenarios/dash_multi_periods.js index de95d24de8e..aaf28f2c5fc 100644 --- a/tests/integration/scenarios/dash_multi_periods.js +++ b/tests/integration/scenarios/dash_multi_periods.js @@ -16,7 +16,7 @@ import { checkAfterSleepWithBackoff } from "../../utils/checkAfterSleepWithBacko describe("DASH non-linear multi-periods content (SegmentTemplate)", function () { launchTestsForContent(manifestInfos); launchTestsForContent(manifestInfos, { multithread: true }); - launchTestsForContent(manifestInfos, { multithread: true, es5Worker: true }); + launchTestsForContent(manifestInfos, { multithread: true }); }); describe("DASH multi-Period with different choices", function () { diff --git a/tests/integration/scenarios/dash_static.js b/tests/integration/scenarios/dash_static.js index a0fe3194279..91357bf5593 100644 --- a/tests/integration/scenarios/dash_static.js +++ b/tests/integration/scenarios/dash_static.js @@ -23,7 +23,6 @@ describe("DASH non-linear content (SegmentTimeline)", function () { launchTestsForContent(segmentTimelineManifestInfos, { multithread: true }); launchTestsForContent(segmentTimelineManifestInfos, { multithread: true, - es5Worker: true, }); }); @@ -32,7 +31,6 @@ describe("DASH non-linear content multi-codecs (SegmentBase)", function () { launchTestsForContent(segmentBaseMultiCodecsInfos, { multithread: true }); launchTestsForContent(segmentBaseMultiCodecsInfos, { multithread: true, - es5Worker: true, }); }); @@ -41,7 +39,6 @@ describe("DASH non-linear content not starting at 0 (SegmentTimeline)", function launchTestsForContent(notStartingAt0ManifestInfos, { multithread: true }); launchTestsForContent(notStartingAt0ManifestInfos, { multithread: true, - es5Worker: true, }); }); @@ -52,7 +49,6 @@ describe("DASH non-linear content with SegmentTemplate inheritance (Period-Adapt }); launchTestsForContent(segmentTemplateInheritancePeriodAS, { multithread: true, - es5Worker: true, }); }); @@ -61,7 +57,6 @@ describe("DASH non-linear content with SegmentTemplate inheritance (AdaptationSe launchTestsForContent(segmentTemplateInheritanceASRep, { multithread: true }); launchTestsForContent(segmentTemplateInheritanceASRep, { multithread: true, - es5Worker: true, }); }); diff --git a/tests/integration/scenarios/idle.js b/tests/integration/scenarios/idle.js index e6c94f76317..28e66603d8f 100644 --- a/tests/integration/scenarios/idle.js +++ b/tests/integration/scenarios/idle.js @@ -3,13 +3,12 @@ import RxPlayer from "../../../dist/es2017"; import { MULTI_THREAD } from "../../../dist/es2017/experimental/features/index.js"; import { EMBEDDED_WORKER, - EMBEDDED_WORKER_ES5, EMBEDDED_DASH_WASM, } from "../../../dist/es2017/__GENERATED_CODE/index.js"; runIdleTests(); runIdleTests({ multithread: true }); -runIdleTests({ multithread: true, es5Worker: true }); +runIdleTests({ multithread: true }); /** * Test every methods at an initial, idle state. @@ -20,10 +19,8 @@ runIdleTests({ multithread: true, es5Worker: true }); * @param {Boolean} [options.multithread] - If `true`, those tests will be run * if the RxPlayer runs in multithread mode. * In any other cases, tests will run in monothread mode. - * @param {Boolean} [options.es5Worker] - If `true`, multithread tests will be - * run in the ES5 version of the WebWorker file. */ -function runIdleTests({ multithread, es5Worker } = {}) { +function runIdleTests({ multithread } = {}) { let title = "initial idle state"; if (multithread === true) { RxPlayer.addFeatures([MULTI_THREAD]); @@ -36,7 +33,7 @@ function runIdleTests({ multithread, es5Worker } = {}) { const player = new RxPlayer(); if (multithread === true) { player.attachWorker({ - workerUrl: es5Worker ? EMBEDDED_WORKER_ES5 : EMBEDDED_WORKER, + workerUrl: EMBEDDED_WORKER, dashWasmUrl: EMBEDDED_DASH_WASM, }); } diff --git a/tests/integration/scenarios/initial_playback.js b/tests/integration/scenarios/initial_playback.js index 72d859a7d36..6d96ea5bbbf 100644 --- a/tests/integration/scenarios/initial_playback.js +++ b/tests/integration/scenarios/initial_playback.js @@ -20,7 +20,6 @@ import { MULTI_THREAD } from "../../../dist/es2017/experimental/features/index.j import { EMBEDDED_WORKER, EMBEDDED_DASH_WASM, - EMBEDDED_WORKER_ES5, } from "../../../dist/es2017/__GENERATED_CODE/index.js"; import { manifestInfos } from "../../contents/DASH_static_SegmentTimeline"; import sleep from "../../utils/sleep.js"; @@ -31,7 +30,7 @@ import { checkAfterSleepWithBackoff } from "../../utils/checkAfterSleepWithBacko runInitialPlaybackTests(); runInitialPlaybackTests({ multithread: true }); -runInitialPlaybackTests({ multithread: true, es5Worker: true }); +runInitialPlaybackTests({ multithread: true }); /** * Test various cases of errors linked to starting playback. @@ -39,10 +38,8 @@ runInitialPlaybackTests({ multithread: true, es5Worker: true }); * @param {Boolean} [options.multithread] - If `true`, those tests will be run * if the RxPlayer runs in multithread mode. * In any other cases, tests will run in monothread mode. - * @param {Boolean} [options.es5Worker] - If `true`, multithread tests will be - * run in the ES5 version of the WebWorker file. */ -function runInitialPlaybackTests({ multithread, es5Worker } = {}) { +function runInitialPlaybackTests({ multithread } = {}) { let title = "basic playback use cases: non-linear DASH SegmentTimeline"; if (multithread === true) { RxPlayer.addFeatures([MULTI_THREAD]); @@ -56,7 +53,7 @@ function runInitialPlaybackTests({ multithread, es5Worker } = {}) { player = new RxPlayer(); if (multithread === true) { player.attachWorker({ - workerUrl: es5Worker ? EMBEDDED_WORKER_ES5 : EMBEDDED_WORKER, + workerUrl: EMBEDDED_WORKER, dashWasmUrl: EMBEDDED_DASH_WASM, }); } diff --git a/tests/integration/scenarios/loadVideo_options.js b/tests/integration/scenarios/loadVideo_options.js index 3853784a271..a43c22a6dfd 100644 --- a/tests/integration/scenarios/loadVideo_options.js +++ b/tests/integration/scenarios/loadVideo_options.js @@ -19,7 +19,6 @@ import RxPlayer from "../../../dist/es2017"; import { MULTI_THREAD } from "../../../dist/es2017/experimental/features/index.js"; import { EMBEDDED_WORKER, - EMBEDDED_WORKER_ES5, EMBEDDED_DASH_WASM, } from "../../../dist/es2017/__GENERATED_CODE/index.js"; import { manifestInfos } from "../../contents/DASH_static_SegmentTimeline"; @@ -38,10 +37,8 @@ runLoadVideoOptionsTests({ multithread: true }); * @param {Boolean} [options.multithread] - If `true`, those tests will be run * if the RxPlayer runs in multithread mode. * In any other cases, tests will run in monothread mode. - * @param {Boolean} [options.es5Worker] - If `true`, multithread tests will be - * run in the ES5 version of the WebWorker file. */ -function runLoadVideoOptionsTests({ multithread, es5Worker } = {}) { +function runLoadVideoOptionsTests({ multithread } = {}) { let title = "loadVideo options"; if (multithread === true) { RxPlayer.addFeatures([MULTI_THREAD]); @@ -55,7 +52,7 @@ function runLoadVideoOptionsTests({ multithread, es5Worker } = {}) { player = new RxPlayer(); if (multithread === true) { player.attachWorker({ - workerUrl: es5Worker ? EMBEDDED_WORKER_ES5 : EMBEDDED_WORKER, + workerUrl: EMBEDDED_WORKER, dashWasmUrl: EMBEDDED_DASH_WASM, }); } diff --git a/tests/integration/utils/launch_tests_for_content.js b/tests/integration/utils/launch_tests_for_content.js index d30347676f6..3abdee2268e 100644 --- a/tests/integration/utils/launch_tests_for_content.js +++ b/tests/integration/utils/launch_tests_for_content.js @@ -4,7 +4,6 @@ import { MULTI_THREAD } from "../../../dist/es2017/experimental/features/index.j import { EMBEDDED_WORKER, EMBEDDED_DASH_WASM, - EMBEDDED_WORKER_ES5, } from "../../../dist/es2017/__GENERATED_CODE/index.js"; import sleep from "../../utils/sleep.js"; import waitForState, { @@ -58,13 +57,8 @@ import { checkAfterSleepWithBackoff } from "../../utils/checkAfterSleepWithBacko * @param {Boolean} [options.multithread] - If `true`, those tests will be run * if the RxPlayer runs in multithread mode. * In any other cases, tests will run in monothread mode. - * @param {Boolean} [options.es5Worker] - If `true`, multithread tests will be - * run in the ES5 version of the WebWorker file. */ -export default function launchTestsForContent( - manifestInfos, - { multithread, es5Worker } = {}, -) { +export default function launchTestsForContent(manifestInfos, { multithread } = {}) { let player; if (multithread === true) { @@ -86,7 +80,7 @@ export default function launchTestsForContent( player = new RxPlayer(); if (multithread === true) { player.attachWorker({ - workerUrl: es5Worker ? EMBEDDED_WORKER_ES5 : EMBEDDED_WORKER, + workerUrl: EMBEDDED_WORKER, dashWasmUrl: EMBEDDED_DASH_WASM, }); }