diff --git a/package-lock.json b/package-lock.json index f7a63df358..1bcfd6c63d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,7 +31,6 @@ "react": "18.2.0", "react-dom": "18.2.0", "regenerator-runtime": "0.14.1", - "rimraf": "5.0.5", "semver": "7.5.4", "typescript": "5.3.3", "vitest": "^1.6.0", diff --git a/package.json b/package.json index 1f1895bf0e..eeaee82444 100644 --- a/package.json +++ b/package.json @@ -154,11 +154,11 @@ "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", "check:demo": "npm run check:demo:types && npm run lint:demo", "check:demo:types": "tsc --noEmit --project demo/", - "clean:build": "rimraf dist", + "clean:build": "scripts/remove_dir.mjs dist", "check:types": "tsc --noEmit --project .", "check:types:unit_tests": "tsc --noEmit --project ./tsconfig.unit-tests.json", "check:types:watch": "tsc --noEmit --watch --project .", - "clean:wasm": "rimraf dist/mpd-parser.wasm && rimraf ./src/parsers/manifest/dash/wasm-parser/target", + "clean:wasm": "scripts/remove_dir.mjs dist/mpd-parser.wasm && scripts/remove_dir.mjs ./src/parsers/manifest/dash/wasm-parser/target", "demo": "node ./scripts/build_demo.mjs --production-mode", "demo:min": "node ./scripts/build_demo.mjs --production-mode --minify", "demo:watch": "node ./scripts/build_demo.mjs --watch --production-mode", @@ -215,7 +215,6 @@ "react": "18.2.0", "react-dom": "18.2.0", "regenerator-runtime": "0.14.1", - "rimraf": "5.0.5", "semver": "7.5.4", "typescript": "5.3.3", "vitest": "^1.6.0", diff --git a/scripts/generate_build.mjs b/scripts/generate_build.mjs index 968dbdd263..ba528662c2 100755 --- a/scripts/generate_build.mjs +++ b/scripts/generate_build.mjs @@ -22,9 +22,9 @@ import { spawn } from "child_process"; import * as fs from "fs"; import * as path from "path"; import { fileURLToPath, pathToFileURL } from "url"; -import { rimraf } from "rimraf"; import generateEmbeds from "./generate_embeds.mjs"; import runBundler from "./run_bundler.mjs"; +import removeDir from "./remove_dir.mjs"; const currentDirectory = path.dirname(fileURLToPath(import.meta.url)); @@ -112,7 +112,7 @@ async function removePreviousBuildArtefacts() { await Promise.all( BUILD_ARTEFACTS_TO_REMOVE.map((name) => { const relativePath = path.join(ROOT_DIR, name); - return removeFile(relativePath); + return removeDir(relativePath); }), ); } @@ -146,14 +146,6 @@ async function compile(devMode) { ]); } -/** - * @param {string} fileName - * @returns {Promise} - */ -function removeFile(fileName) { - return rimraf(fileName); -} - /** * @param {string} command * @param {Array.} args diff --git a/scripts/remove_dir.mjs b/scripts/remove_dir.mjs new file mode 100755 index 0000000000..4ac9d84d6a --- /dev/null +++ b/scripts/remove_dir.mjs @@ -0,0 +1,27 @@ +#!/usr/bin/env node +import { pathToFileURL } from "url"; +import * as fs from "fs"; + +// If true, this script is called directly +if (import.meta.url === pathToFileURL(process.argv[1]).href) { + for (const dir of process.argv.slice(2)) { + removeDir(dir).catch((err) => { + console.error(`ERROR: Failed to remove "${dir}"`, err); + }); + } +} + +/** + * @param {string} fileName + * @returns {Promise} + */ +export default function removeDir(fileName) { + return new Promise((res, rej) => { + fs.rm(fileName, { recursive: true, force: true }, (err) => { + if (err) { + rej(err); + } + res(); + }); + }); +} diff --git a/tests/performance/run.mjs b/tests/performance/run.mjs index 4216333638..db74c91931 100644 --- a/tests/performance/run.mjs +++ b/tests/performance/run.mjs @@ -6,10 +6,10 @@ import esbuild from "esbuild"; import * as fs from "fs/promises"; import { createServer } from "http"; import * as path from "path"; -import { rimraf } from "rimraf"; import { fileURLToPath } from "url"; import launchStaticServer from "../../scripts/launch_static_server.mjs"; import getHumanReadableHours from "../../scripts/utils/get_human_readable_hours.mjs"; +import removeDir from "../../scripts/remove_dir.mjs"; import { createContentServer } from "../contents/server.mjs"; const currentDirectory = path.dirname(fileURLToPath(import.meta.url)); @@ -214,7 +214,7 @@ async function prepareLastRxPlayerTests() { * @returns {Promise} */ async function linkCurrentRxPlayer() { - await removeFile(path.join(currentDirectory, "node_modules")); + await removeDir(path.join(currentDirectory, "node_modules")); await fs.mkdir(path.join(currentDirectory, "node_modules")); await spawnProc( "npm run build", @@ -770,14 +770,6 @@ function createBundle(options) { }); } -/** - * @param {string} fileName - * @returns {Promise} - */ -function removeFile(fileName) { - return rimraf(fileName); -} - /** * @param {string} command * @param {Array.} args