Skip to content

Commit

Permalink
Remove reliance on the rimraf dependency
Browse files Browse the repository at this point in the history
We often have to work on debugging applications. In most of those cases,
we call `npm-link` or `yarn-link` to link our local version of the
RxPlayer to a given application.

Sadly it turns out that some of those applications have complex and
poorly-configured package installation and build steps, which leads to
many errors as we try to produce a build.

An issue I was having right now, is linked to a peculiar way packages
can be installed in one application at Canal+, leading in some cases to
issues with how the `rimraf` package is imported.

I grew tired of this issue. Considering that the `rimraf` dependency
for our simple usage seems to be very easy to replace with a few line of
Node.js (fs.rm fills what we want to do and seems to even be relied on
by `rimraf` on the simple cases we're exploiting), I decided to do just
that - so there's less possibility for dependency-importing issues to
occur.
  • Loading branch information
peaBerberian committed Jul 31, 2024
1 parent c7c2c60 commit 54fba9d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 2 additions & 10 deletions scripts/generate_build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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);
}),
);
}
Expand Down Expand Up @@ -146,14 +146,6 @@ async function compile(devMode) {
]);
}

/**
* @param {string} fileName
* @returns {Promise}
*/
function removeFile(fileName) {
return rimraf(fileName);
}

/**
* @param {string} command
* @param {Array.<string>} args
Expand Down
27 changes: 27 additions & 0 deletions scripts/remove_dir.mjs
Original file line number Diff line number Diff line change
@@ -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();
});
});
}
12 changes: 2 additions & 10 deletions tests/performance/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -770,14 +770,6 @@ function createBundle(options) {
});
}

/**
* @param {string} fileName
* @returns {Promise}
*/
function removeFile(fileName) {
return rimraf(fileName);
}

/**
* @param {string} command
* @param {Array.<string>} args
Expand Down

0 comments on commit 54fba9d

Please sign in to comment.