Skip to content

Commit 1998257

Browse files
committed
[DEPENDENCY] Switch from "rimraf" to native "fs.rm" (#780)
1 parent aeb1372 commit 1998257

File tree

8 files changed

+40
-33
lines changed

8 files changed

+40
-33
lines changed

lib/build/ProjectBuilder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {rimraf} from "rimraf";
1+
import {rmrf} from "../utils/fs.js";
22
import * as resourceFactory from "@ui5/fs/resourceFactory";
33
import BuildLogger from "@ui5/logger/internal/loggers/Build";
44
import composeProjectList from "./helpers/composeProjectList.js";
@@ -233,7 +233,7 @@ class ProjectBuilder {
233233

234234
if (cleanDest) {
235235
this.#log.info(`Cleaning target directory...`);
236-
await rimraf(destPath);
236+
await rmrf(destPath);
237237
}
238238
const startTime = process.hrtime();
239239
try {

lib/ui5Framework/maven/Installer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {promisify} from "node:util";
77
import Registry from "./Registry.js";
88
import AbstractInstaller from "../AbstractInstaller.js";
99
import CacheMode from "./CacheMode.js";
10-
import {rimraf} from "rimraf";
10+
import {rmrf} from "../../utils/fs.js";
1111
const stat = promisify(fs.stat);
1212
const readFile = promisify(fs.readFile);
1313
const writeFile = promisify(fs.writeFile);
@@ -275,7 +275,7 @@ class Installer extends AbstractInstaller {
275275
if (pkgName) {
276276
const packageDir = this._getTargetDirForPackage(pkgName, revision);
277277
log.verbose(`Removing directory ${packageDir}...`);
278-
await rimraf(packageDir);
278+
await rmrf(packageDir);
279279
}
280280
}
281281
}
@@ -326,7 +326,7 @@ class Installer extends AbstractInstaller {
326326
// Check whether staging dir already exists and remove it
327327
if (await this._pathExists(stagingDir)) {
328328
log.verbose(`Removing stale staging directory at ${stagingDir}...`);
329-
await rimraf(stagingDir);
329+
await rmrf(stagingDir);
330330
}
331331

332332
await mkdirp(stagingDir);
@@ -345,7 +345,7 @@ class Installer extends AbstractInstaller {
345345
// Check whether target dir already exists and remove it
346346
if (await this._pathExists(targetDir)) {
347347
log.verbose(`Removing existing target directory at ${targetDir}...`);
348-
await rimraf(targetDir);
348+
await rmrf(targetDir);
349349
}
350350

351351
// Do not create target dir itself to prevent EPERM error in following rename operation

lib/ui5Framework/npm/Installer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs from "graceful-fs";
44
import {promisify} from "node:util";
55
import Registry from "./Registry.js";
66
import AbstractInstaller from "../AbstractInstaller.js";
7-
import {rimraf} from "rimraf";
7+
import {rmrf} from "../../utils/fs.js";
88
const stat = promisify(fs.stat);
99
const readFile = promisify(fs.readFile);
1010
const rename = promisify(fs.rename);
@@ -99,7 +99,7 @@ class Installer extends AbstractInstaller {
9999
// Check whether staging dir already exists and remove it
100100
if (await this._pathExists(stagingDir)) {
101101
log.verbose(`Removing existing staging directory at ${stagingDir}...`);
102-
await rimraf(stagingDir);
102+
await rmrf(stagingDir);
103103
}
104104

105105
// Check whether target dir already exists and remove it.
@@ -108,7 +108,7 @@ class Installer extends AbstractInstaller {
108108
// directory so that the rename operation won't have any no trouble.
109109
if (await this._pathExists(targetDir)) {
110110
log.verbose(`Removing existing target directory at ${targetDir}...`);
111-
await rimraf(targetDir);
111+
await rmrf(targetDir);
112112
}
113113

114114
log.verbose(`Installing ${pkgName} in version ${version} to ${stagingDir}...`);

lib/utils/fs.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import fs from "graceful-fs";
22
import {promisify} from "node:util";
33
const mkdir = promisify(fs.mkdir);
4+
const rm = promisify(fs.rm);
45

56
export async function mkdirp(dirPath) {
67
return mkdir(dirPath, {recursive: true});
78
}
9+
10+
export async function rmrf(dirPath) {
11+
return rm(dirPath, {recursive: true, force: true});
12+
}

package-lock.json

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"version": "git-chglog --sort semver --next-tag v$npm_package_version -o CHANGELOG.md v4.0.0.. && git add CHANGELOG.md",
5555
"prepublishOnly": "git push --follow-tags",
5656
"release-note": "git-chglog --sort semver -c .chglog/release-config.yml v$npm_package_version",
57-
"depcheck": "depcheck --ignores @ui5/project,docdash,@istanbuljs/esm-loader-hook"
57+
"depcheck": "depcheck --ignores @ui5/project,docdash,@istanbuljs/esm-loader-hook,rimraf"
5858
},
5959
"files": [
6060
"CHANGELOG.md",
@@ -138,7 +138,6 @@
138138
"read-package-up": "^11.0.0",
139139
"read-pkg": "^9.0.1",
140140
"resolve": "^1.22.8",
141-
"rimraf": "^6.0.1",
142141
"semver": "^7.6.3",
143142
"xml2js": "^0.6.2",
144143
"yesno": "^0.4.0"
@@ -173,6 +172,7 @@
173172
"jsdoc": "^4.0.4",
174173
"nyc": "^17.1.0",
175174
"open-cli": "^8.0.0",
175+
"rimraf": "^6.0.1",
176176
"sinon": "^19.0.2",
177177
"tap-xunit": "^2.4.1"
178178
}

test/lib/ui5framework/maven/Installer.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import sinon from "sinon";
33
import esmock from "esmock";
44
import path from "node:path";
55
import fs from "graceful-fs";
6-
import {rimraf} from "rimraf";
76

87
test.beforeEach(async (t) => {
98
t.context.mkdirpStub = sinon.stub().resolves();
10-
t.context.rimrafStub = sinon.stub().resolves();
9+
t.context.rmrfStub = sinon.stub().resolves();
1110
t.context.readFileStub = sinon.stub();
1211
t.context.writeFileStub = sinon.stub();
1312
t.context.renameStub = sinon.stub().returns();
@@ -20,7 +19,6 @@ test.beforeEach(async (t) => {
2019
t.context.promisifyStub.withArgs(fs.rename).callsFake(() => t.context.renameStub);
2120
t.context.promisifyStub.withArgs(fs.rm).callsFake(() => t.context.rmStub);
2221
t.context.promisifyStub.withArgs(fs.stat).callsFake(() => t.context.statStub);
23-
t.context.promisifyStub.withArgs(rimraf).callsFake(() => t.context.rimrafStub);
2422

2523
t.context.lockStub = sinon.stub();
2624
t.context.unlockStub = sinon.stub();
@@ -39,7 +37,8 @@ test.beforeEach(async (t) => {
3937

4038
t.context.AbstractInstaller = await esmock.p("../../../../lib/ui5Framework/AbstractInstaller.js", {
4139
"../../../../lib/utils/fs.js": {
42-
mkdirp: t.context.mkdirpStub
40+
mkdirp: t.context.mkdirpStub,
41+
rmrf: t.context.rmrfStub
4342
},
4443
"lockfile": {
4544
lock: t.context.lockStub,

test/lib/ui5framework/npm/Installer.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const __dirname = import.meta.dirname;
77

88
test.beforeEach(async (t) => {
99
t.context.mkdirpStub = sinon.stub().resolves();
10-
t.context.rimrafStub = sinon.stub().resolves();
10+
t.context.rmrfStub = sinon.stub().resolves();
1111

1212
t.context.lockStub = sinon.stub();
1313
t.context.unlockStub = sinon.stub();
@@ -16,10 +16,8 @@ test.beforeEach(async (t) => {
1616

1717
t.context.AbstractResolver = await esmock.p("../../../../lib/ui5Framework/AbstractInstaller.js", {
1818
"../../../../lib/utils/fs.js": {
19-
mkdirp: t.context.mkdirpStub
20-
},
21-
"rimraf": {
22-
rimraf: t.context.rimrafStub
19+
mkdirp: t.context.mkdirpStub,
20+
rmrf: t.context.rmrfStub
2321
},
2422
"lockfile": {
2523
lock: t.context.lockStub,
@@ -29,10 +27,8 @@ test.beforeEach(async (t) => {
2927
t.context.Installer = await esmock.p("../../../../lib/ui5Framework/npm/Installer.js", {
3028
"../../../../lib/ui5Framework/AbstractInstaller.js": t.context.AbstractResolver,
3129
"../../../../lib/utils/fs.js": {
32-
mkdirp: t.context.mkdirpStub
33-
},
34-
"rimraf": {
35-
rimraf: t.context.rimrafStub
30+
mkdirp: t.context.mkdirpStub,
31+
rmrf: t.context.rmrfStub
3632
},
3733
"graceful-fs": {
3834
rename: t.context.renameStub,
@@ -512,7 +508,7 @@ test.serial("Installer: installPackage with new package", async (t) => {
512508
"_packageJsonExists should be called with the correct arguments");
513509
t.is(pathExistsStub.getCall(1).args[0], targetDir,
514510
"_packageJsonExists should be called with the correct arguments");
515-
t.is(t.context.rimrafStub.callCount, 0, "rimraf should never be called");
511+
t.is(t.context.rmrfStub.callCount, 0, "rmrf should never be called");
516512

517513
t.is(extractPackageStub.callCount, 1, "_extractPackage should be called once");
518514

@@ -577,7 +573,7 @@ test.serial("Installer: installPackage with already installed package", async (t
577573
t.is(t.context.unlockStub.callCount, 0, "unlock should never be called");
578574
t.is(getStagingDirForPackageStub.callCount, 0, "_getStagingDirForPackage should never be called");
579575
t.is(pathExistsStub.callCount, 0, "_pathExists should never be called");
580-
t.is(t.context.rimrafStub.callCount, 0, "rimraf should never be called");
576+
t.is(t.context.rmrfStub.callCount, 0, "rmrf should never be called");
581577
t.is(extractPackageStub.callCount, 0, "_extractPackage should never be called");
582578
t.is(t.context.mkdirpStub.callCount, 0, "mkdirp should never be called");
583579
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
633629
t.is(t.context.lockStub.callCount, 1, "lock should be called once");
634630
t.is(t.context.unlockStub.callCount, 1, "unlock should be called once");
635631

636-
t.is(t.context.rimrafStub.callCount, 0, "rimraf should never be called");
632+
t.is(t.context.rmrfStub.callCount, 0, "rmrf should never be called");
637633

638634
t.is(t.context.mkdirpStub.callCount, 1, "mkdirp should be called once");
639635
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
709705
t.is(pathExistsStub.getCall(1).args[0], targetDir,
710706
"_packageJsonExists should be called with the correct arguments");
711707

712-
t.is(t.context.rimrafStub.callCount, 2, "rimraf should be called twice");
713-
t.is(t.context.rimrafStub.getCall(0).args[0], "staging-dir-path",
714-
"rimraf should be called with the correct arguments");
715-
t.is(t.context.rimrafStub.getCall(1).args[0], targetDir,
716-
"rimraf should be called with the correct arguments");
708+
t.is(t.context.rmrfStub.callCount, 2, "rmrf should be called twice");
709+
t.is(t.context.rmrfStub.getCall(0).args[0], "staging-dir-path",
710+
"rmrf should be called with the correct arguments");
711+
t.is(t.context.rmrfStub.getCall(1).args[0], targetDir,
712+
"rmrf should be called with the correct arguments");
717713

718714
t.is(extractPackageStub.callCount, 1, "_extractPackage should be called once");
719715

0 commit comments

Comments
 (0)