From 7e628d2ce0d83b7d86e8a4997ba21ada14a82661 Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Wed, 13 Nov 2024 11:17:24 +0100 Subject: [PATCH] [FEATURE] Switch from "rimraf" to native "fs.rm" --- lib/build/ProjectBuilder.js | 4 ++-- lib/ui5Framework/maven/Installer.js | 8 +++---- lib/ui5Framework/npm/Installer.js | 6 ++--- lib/utils/fs.js | 5 ++++ package-lock.json | 9 ++++++- package.json | 4 ++-- test/lib/ui5framework/maven/Installer.js | 7 +++--- test/lib/ui5framework/npm/Installer.js | 30 ++++++++++-------------- 8 files changed, 40 insertions(+), 33 deletions(-) diff --git a/lib/build/ProjectBuilder.js b/lib/build/ProjectBuilder.js index fe39870d9..af1804b6a 100644 --- a/lib/build/ProjectBuilder.js +++ b/lib/build/ProjectBuilder.js @@ -1,4 +1,4 @@ -import {rimraf} from "rimraf"; +import {rmrf} from "../utils/fs.js"; import * as resourceFactory from "@ui5/fs/resourceFactory"; import BuildLogger from "@ui5/logger/internal/loggers/Build"; import composeProjectList from "./helpers/composeProjectList.js"; @@ -233,7 +233,7 @@ class ProjectBuilder { if (cleanDest) { this.#log.info(`Cleaning target directory...`); - await rimraf(destPath); + await rmrf(destPath); } const startTime = process.hrtime(); try { diff --git a/lib/ui5Framework/maven/Installer.js b/lib/ui5Framework/maven/Installer.js index 6a85b7ccb..08811dcb3 100644 --- a/lib/ui5Framework/maven/Installer.js +++ b/lib/ui5Framework/maven/Installer.js @@ -7,7 +7,7 @@ import {promisify} from "node:util"; import Registry from "./Registry.js"; import AbstractInstaller from "../AbstractInstaller.js"; import CacheMode from "./CacheMode.js"; -import {rimraf} from "rimraf"; +import {rmrf} from "../../utils/fs.js"; const stat = promisify(fs.stat); const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); @@ -275,7 +275,7 @@ class Installer extends AbstractInstaller { if (pkgName) { const packageDir = this._getTargetDirForPackage(pkgName, revision); log.verbose(`Removing directory ${packageDir}...`); - await rimraf(packageDir); + await rmrf(packageDir); } } } @@ -326,7 +326,7 @@ class Installer extends AbstractInstaller { // Check whether staging dir already exists and remove it if (await this._pathExists(stagingDir)) { log.verbose(`Removing stale staging directory at ${stagingDir}...`); - await rimraf(stagingDir); + await rmrf(stagingDir); } await mkdirp(stagingDir); @@ -345,7 +345,7 @@ class Installer extends AbstractInstaller { // Check whether target dir already exists and remove it if (await this._pathExists(targetDir)) { log.verbose(`Removing existing target directory at ${targetDir}...`); - await rimraf(targetDir); + await rmrf(targetDir); } // Do not create target dir itself to prevent EPERM error in following rename operation diff --git a/lib/ui5Framework/npm/Installer.js b/lib/ui5Framework/npm/Installer.js index da3c7bf27..7a6564c1d 100644 --- a/lib/ui5Framework/npm/Installer.js +++ b/lib/ui5Framework/npm/Installer.js @@ -4,7 +4,7 @@ import fs from "graceful-fs"; import {promisify} from "node:util"; import Registry from "./Registry.js"; import AbstractInstaller from "../AbstractInstaller.js"; -import {rimraf} from "rimraf"; +import {rmrf} from "../../utils/fs.js"; const stat = promisify(fs.stat); const readFile = promisify(fs.readFile); const rename = promisify(fs.rename); @@ -99,7 +99,7 @@ class Installer extends AbstractInstaller { // Check whether staging dir already exists and remove it if (await this._pathExists(stagingDir)) { log.verbose(`Removing existing staging directory at ${stagingDir}...`); - await rimraf(stagingDir); + await rmrf(stagingDir); } // Check whether target dir already exists and remove it. @@ -108,7 +108,7 @@ class Installer extends AbstractInstaller { // directory so that the rename operation won't have any no trouble. if (await this._pathExists(targetDir)) { log.verbose(`Removing existing target directory at ${targetDir}...`); - await rimraf(targetDir); + await rmrf(targetDir); } log.verbose(`Installing ${pkgName} in version ${version} to ${stagingDir}...`); diff --git a/lib/utils/fs.js b/lib/utils/fs.js index a7a930aa3..a8852509b 100644 --- a/lib/utils/fs.js +++ b/lib/utils/fs.js @@ -1,7 +1,12 @@ import fs from "graceful-fs"; import {promisify} from "node:util"; const mkdir = promisify(fs.mkdir); +const rm = promisify(fs.rm); export async function mkdirp(dirPath) { return mkdir(dirPath, {recursive: true}); } + +export async function rmrf(dirPath) { + return rm(dirPath, {recursive: true, force: true}); +} diff --git a/package-lock.json b/package-lock.json index 04f377ccf..496400846 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,6 @@ "read-package-up": "^11.0.0", "read-pkg": "^9.0.1", "resolve": "^1.22.8", - "rimraf": "^6.0.1", "semver": "^7.6.3", "xml2js": "^0.6.2", "yesno": "^0.4.0" @@ -54,6 +53,7 @@ "jsdoc": "^4.0.4", "nyc": "^17.1.0", "open-cli": "^8.0.0", + "rimraf": "^6.0.1", "sinon": "^19.0.2", "tap-xunit": "^2.4.1" }, @@ -7347,6 +7347,8 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-6.0.1.tgz", "integrity": "sha512-9dkvaxAsk/xNXSJzMgFqqMCuFgt2+KsOFek3TMLfo8NCPfWpBmqwyNn5Y+NX56QUYfCtsyhF3ayiboEoUmJk/A==", + "dev": true, + "license": "ISC", "dependencies": { "glob": "^11.0.0", "package-json-from-dist": "^1.0.0" @@ -7365,6 +7367,7 @@ "version": "11.0.0", "resolved": "https://registry.npmjs.org/glob/-/glob-11.0.0.tgz", "integrity": "sha512-9UiX/Bl6J2yaBbxKoEBRm4Cipxgok8kQYcOPEhScPwebu2I0HoQOuYdIO6S3hLuWoZgpDpwQZMzTFxgpkyT76g==", + "dev": true, "dependencies": { "foreground-child": "^3.1.0", "jackspeak": "^4.0.1", @@ -7387,6 +7390,7 @@ "version": "4.0.2", "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.2.tgz", "integrity": "sha512-bZsjR/iRjl1Nk1UkjGpAzLNfQtzuijhn2g+pbZb98HQ1Gk8vM9hfbxeMBP+M2/UUdwj0RqGG3mlvk2MsAqwvEw==", + "dev": true, "dependencies": { "@isaacs/cliui": "^8.0.2" }, @@ -7401,6 +7405,7 @@ "version": "11.0.2", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.0.2.tgz", "integrity": "sha512-123qHRfJBmo2jXDbo/a5YOQrJoHF/GNQTLzQ5+IdK5pWpceK17yRc6ozlWd25FxvGKQbIUs91fDFkXmDHTKcyA==", + "dev": true, "engines": { "node": "20 || >=22" } @@ -7409,6 +7414,7 @@ "version": "10.0.1", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.1.tgz", "integrity": "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==", + "dev": true, "dependencies": { "brace-expansion": "^2.0.1" }, @@ -7423,6 +7429,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-2.0.0.tgz", "integrity": "sha512-ypGJsmGtdXUOeM5u93TyeIEfEhM6s+ljAhrk5vAvSx8uyY/02OvrZnA0YNGUrPXfpJMgI1ODd3nwz8Npx4O4cg==", + "dev": true, "dependencies": { "lru-cache": "^11.0.0", "minipass": "^7.1.2" diff --git a/package.json b/package.json index a25d4a1af..440aa4bd0 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "version": "git-chglog --sort semver --next-tag v$npm_package_version -o CHANGELOG.md v4.0.0.. && git add CHANGELOG.md", "prepublishOnly": "git push --follow-tags", "release-note": "git-chglog --sort semver -c .chglog/release-config.yml v$npm_package_version", - "depcheck": "depcheck --ignores @ui5/project,docdash,@istanbuljs/esm-loader-hook" + "depcheck": "depcheck --ignores @ui5/project,docdash,@istanbuljs/esm-loader-hook,rimraf" }, "files": [ "CHANGELOG.md", @@ -138,7 +138,6 @@ "read-package-up": "^11.0.0", "read-pkg": "^9.0.1", "resolve": "^1.22.8", - "rimraf": "^6.0.1", "semver": "^7.6.3", "xml2js": "^0.6.2", "yesno": "^0.4.0" @@ -173,6 +172,7 @@ "jsdoc": "^4.0.4", "nyc": "^17.1.0", "open-cli": "^8.0.0", + "rimraf": "^6.0.1", "sinon": "^19.0.2", "tap-xunit": "^2.4.1" } diff --git a/test/lib/ui5framework/maven/Installer.js b/test/lib/ui5framework/maven/Installer.js index 044f04cb5..86b00754c 100644 --- a/test/lib/ui5framework/maven/Installer.js +++ b/test/lib/ui5framework/maven/Installer.js @@ -3,11 +3,10 @@ import sinon from "sinon"; import esmock from "esmock"; import path from "node:path"; import fs from "graceful-fs"; -import {rimraf} from "rimraf"; test.beforeEach(async (t) => { t.context.mkdirpStub = sinon.stub().resolves(); - t.context.rimrafStub = sinon.stub().resolves(); + t.context.rmrfStub = sinon.stub().resolves(); t.context.readFileStub = sinon.stub(); t.context.writeFileStub = sinon.stub(); t.context.renameStub = sinon.stub().returns(); @@ -20,7 +19,6 @@ test.beforeEach(async (t) => { t.context.promisifyStub.withArgs(fs.rename).callsFake(() => t.context.renameStub); t.context.promisifyStub.withArgs(fs.rm).callsFake(() => t.context.rmStub); t.context.promisifyStub.withArgs(fs.stat).callsFake(() => t.context.statStub); - t.context.promisifyStub.withArgs(rimraf).callsFake(() => t.context.rimrafStub); t.context.lockStub = sinon.stub(); t.context.unlockStub = sinon.stub(); @@ -39,7 +37,8 @@ test.beforeEach(async (t) => { t.context.AbstractInstaller = await esmock.p("../../../../lib/ui5Framework/AbstractInstaller.js", { "../../../../lib/utils/fs.js": { - mkdirp: t.context.mkdirpStub + mkdirp: t.context.mkdirpStub, + rmrf: t.context.rmrfStub }, "lockfile": { lock: t.context.lockStub, diff --git a/test/lib/ui5framework/npm/Installer.js b/test/lib/ui5framework/npm/Installer.js index 1020e45cd..c06b36ae3 100644 --- a/test/lib/ui5framework/npm/Installer.js +++ b/test/lib/ui5framework/npm/Installer.js @@ -7,7 +7,7 @@ const __dirname = import.meta.dirname; test.beforeEach(async (t) => { t.context.mkdirpStub = sinon.stub().resolves(); - t.context.rimrafStub = sinon.stub().resolves(); + t.context.rmrfStub = sinon.stub().resolves(); t.context.lockStub = sinon.stub(); t.context.unlockStub = sinon.stub(); @@ -16,10 +16,8 @@ test.beforeEach(async (t) => { t.context.AbstractResolver = await esmock.p("../../../../lib/ui5Framework/AbstractInstaller.js", { "../../../../lib/utils/fs.js": { - mkdirp: t.context.mkdirpStub - }, - "rimraf": { - rimraf: t.context.rimrafStub + mkdirp: t.context.mkdirpStub, + rmrf: t.context.rmrfStub }, "lockfile": { lock: t.context.lockStub, @@ -29,10 +27,8 @@ test.beforeEach(async (t) => { t.context.Installer = await esmock.p("../../../../lib/ui5Framework/npm/Installer.js", { "../../../../lib/ui5Framework/AbstractInstaller.js": t.context.AbstractResolver, "../../../../lib/utils/fs.js": { - mkdirp: t.context.mkdirpStub - }, - "rimraf": { - rimraf: t.context.rimrafStub + mkdirp: t.context.mkdirpStub, + rmrf: t.context.rmrfStub }, "graceful-fs": { rename: t.context.renameStub, @@ -512,7 +508,7 @@ test.serial("Installer: installPackage with new package", async (t) => { "_packageJsonExists should be called with the correct arguments"); t.is(pathExistsStub.getCall(1).args[0], targetDir, "_packageJsonExists should be called with the correct arguments"); - t.is(t.context.rimrafStub.callCount, 0, "rimraf should never be called"); + t.is(t.context.rmrfStub.callCount, 0, "rmrf should never be called"); t.is(extractPackageStub.callCount, 1, "_extractPackage should be called once"); @@ -577,7 +573,7 @@ test.serial("Installer: installPackage with already installed package", async (t t.is(t.context.unlockStub.callCount, 0, "unlock should never be called"); t.is(getStagingDirForPackageStub.callCount, 0, "_getStagingDirForPackage should never be called"); t.is(pathExistsStub.callCount, 0, "_pathExists should never be called"); - t.is(t.context.rimrafStub.callCount, 0, "rimraf should never be called"); + t.is(t.context.rmrfStub.callCount, 0, "rmrf should never be called"); t.is(extractPackageStub.callCount, 0, "_extractPackage should never be called"); t.is(t.context.mkdirpStub.callCount, 0, "mkdirp should never be called"); t.is(t.context.renameStub.callCount, 0, "fs.rename should never be called"); @@ -633,7 +629,7 @@ test.serial("Installer: installPackage with install already in progress", async t.is(t.context.lockStub.callCount, 1, "lock should be called once"); t.is(t.context.unlockStub.callCount, 1, "unlock should be called once"); - t.is(t.context.rimrafStub.callCount, 0, "rimraf should never be called"); + t.is(t.context.rmrfStub.callCount, 0, "rmrf should never be called"); t.is(t.context.mkdirpStub.callCount, 1, "mkdirp should be called once"); t.is(t.context.mkdirpStub.getCall(0).args[0], path.join("/", "ui5Data", "framework", "locks"), @@ -709,11 +705,11 @@ test.serial("Installer: installPackage with new package and existing target and t.is(pathExistsStub.getCall(1).args[0], targetDir, "_packageJsonExists should be called with the correct arguments"); - t.is(t.context.rimrafStub.callCount, 2, "rimraf should be called twice"); - t.is(t.context.rimrafStub.getCall(0).args[0], "staging-dir-path", - "rimraf should be called with the correct arguments"); - t.is(t.context.rimrafStub.getCall(1).args[0], targetDir, - "rimraf should be called with the correct arguments"); + t.is(t.context.rmrfStub.callCount, 2, "rmrf should be called twice"); + t.is(t.context.rmrfStub.getCall(0).args[0], "staging-dir-path", + "rmrf should be called with the correct arguments"); + t.is(t.context.rmrfStub.getCall(1).args[0], targetDir, + "rmrf should be called with the correct arguments"); t.is(extractPackageStub.callCount, 1, "_extractPackage should be called once");