Skip to content

Commit

Permalink
[INTERNAL] Use native fs.mkdir instead of mkdirp
Browse files Browse the repository at this point in the history
The recursive option is available since Node v10.12, which makes the
use of thirdparty packages obsolete for most use cases.
  • Loading branch information
matz3 committed Dec 2, 2022
1 parent f0b2cb0 commit 1e2951d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions lib/ui5Framework/npm/Installer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from "node:path";
import mkdirp from "mkdirp";
import fs from "graceful-fs";
import {promisify} from "node:util";
import Registry from "./Registry.js";
Expand All @@ -8,6 +7,7 @@ const rimraf = promisify(_rimraf);
const stat = promisify(fs.stat);
const readFile = promisify(fs.readFile);
const rename = promisify(fs.rename);
const mkdir = promisify(fs.mkdir);
import logger from "@ui5/logger";
const log = logger.getLogger("ui5Framework:npm:Installer");

Expand Down Expand Up @@ -100,7 +100,7 @@ class Installer {

// Do not create target dir itself to prevent EPERM error in following rename operation
// (https://github.com/SAP/ui5-tooling/issues/487)
await mkdirp(path.dirname(targetDir));
await mkdir(path.dirname(targetDir), {recursive: true});
log.verbose(`Promoting staging directory from ${stagingDir} to ${targetDir}...`);
await rename(stagingDir, targetDir);
} else {
Expand Down Expand Up @@ -139,7 +139,7 @@ class Installer {
const lock = promisify(lockfile.lock);
const unlock = promisify(lockfile.unlock);
const lockPath = this._getLockPath({pkgName, version});
await mkdirp(this._lockDir);
await mkdir(this._lockDir, {recursive: true});
log.verbose("Locking " + lockPath);
await lock(lockPath, {
wait: 10000,
Expand Down
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.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
"js-yaml": "^4.1.0",
"libnpmconfig": "^1.2.1",
"lockfile": "^1.0.4",
"mkdirp": "^1.0.4",
"pacote": "^15.0.6",
"pretty-hrtime": "^1.0.3",
"read-pkg": "^7.1.0",
Expand Down
4 changes: 2 additions & 2 deletions test/lib/graph/helpers/ui5Framework.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ test.beforeEach(async (t) => {

t.context.Installer = await esmock.p("../../../../lib/ui5Framework/npm/Installer.js", {
"@ui5/logger": ui5Logger,
"mkdirp": sinon.stub().resolves(),
"graceful-fs": {
rename: sinon.stub().yieldsAsync()
rename: sinon.stub().yieldsAsync(),
mkdir: sinon.stub().yieldsAsync()
},
"lockfile": {
lock: sinon.stub().yieldsAsync(),
Expand Down
42 changes: 22 additions & 20 deletions test/lib/ui5framework/npm/Installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import {fileURLToPath} from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));

test.beforeEach(async (t) => {
t.context.mkdirpStub = sinon.stub().resolves();
t.context.rimrafStub = sinon.stub().yieldsAsync();

t.context.lockStub = sinon.stub();
t.context.unlockStub = sinon.stub();
t.context.renameStub = sinon.stub().yieldsAsync();
t.context.statStub = sinon.stub().yieldsAsync();
t.context.mkdirStub = sinon.stub().yieldsAsync();

t.context.Installer = await esmock.p("../../../../lib/ui5Framework/npm/Installer.js", {
"mkdirp": t.context.mkdirpStub,
"rimraf": t.context.rimrafStub,
"lockfile": {
lock: t.context.lockStub,
unlock: t.context.unlockStub
},
"graceful-fs": {
rename: t.context.renameStub,
stat: t.context.statStub
stat: t.context.statStub,
mkdir: t.context.mkdirStub
}
});
});
Expand Down Expand Up @@ -299,9 +299,11 @@ test.serial("Installer: _synchronize", async (t) => {
t.deepEqual(getLockPathStub.getCall(0).args, [{pkgName: "@openui5/sap.ui.lib1", version: "1.2.3"}],
"_getLockPath should be called with expected args");

t.is(t.context.mkdirpStub.callCount, 1, "_mkdirp should be called once");
t.deepEqual(t.context.mkdirpStub.getCall(0).args, [path.join("/ui5Home/", "framework", "locks")],
"_mkdirp should be called with expected args");
t.is(t.context.mkdirStub.callCount, 1, "mkdir should be called once");
t.is(t.context.mkdirStub.getCall(0).args[0], path.join("/ui5Home/", "framework", "locks"),
"mkdir should be called with expected path");
t.deepEqual(t.context.mkdirStub.getCall(0).args[1], {recursive: true},
"mkdir should be called with expected options");

t.is(t.context.lockStub.callCount, 1, "lock should be called once");
t.is(t.context.lockStub.getCall(0).args[0], "/locks/lockfile.lock",
Expand Down Expand Up @@ -498,11 +500,11 @@ test.serial("Installer: installPackage with new package", async (t) => {

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

t.is(t.context.mkdirpStub.callCount, 2, "mkdirp should be called twice");
t.is(t.context.mkdirpStub.getCall(0).args[0], path.join("/", "ui5Home", "framework", "locks"),
"mkdirp should be called with the correct arguments on first call");
t.is(t.context.mkdirpStub.getCall(1).args[0], path.join("my", "package"),
"mkdirp should be called with the correct arguments on second call");
t.is(t.context.mkdirStub.callCount, 2, "mkdir should be called twice");
t.is(t.context.mkdirStub.getCall(0).args[0], path.join("/", "ui5Home", "framework", "locks"),
"mkdir should be called with the correct arguments on first call");
t.is(t.context.mkdirStub.getCall(1).args[0], path.join("my", "package"),
"mkdir should be called with the correct arguments on second call");

t.is(t.context.renameStub.callCount, 1, "fs.rename should be called once");
t.is(t.context.renameStub.getCall(0).args[0], "staging-dir-path",
Expand Down Expand Up @@ -561,7 +563,7 @@ test.serial("Installer: installPackage with already installed package", async (t
t.is(pathExistsStub.callCount, 0, "_pathExists should never be called");
t.is(t.context.rimrafStub.callCount, 0, "rimraf 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.mkdirStub.callCount, 0, "mkdir should never be called");
t.is(t.context.renameStub.callCount, 0, "fs.rename should never be called");
});

Expand Down Expand Up @@ -619,9 +621,9 @@ test.serial("Installer: installPackage with install already in progress", async

t.is(t.context.rimrafStub.callCount, 0, "rimraf 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("/", "ui5Home", "framework", "locks"),
"mkdirp should be called with the correct arguments");
t.is(t.context.mkdirStub.callCount, 1, "mkdir should be called once");
t.is(t.context.mkdirStub.getCall(0).args[0], path.join("/", "ui5Home", "framework", "locks"),
"mkdir should be called with the correct arguments");

t.is(getStagingDirForPackageStub.callCount, 0, "_getStagingDirForPackage should never be called");
t.is(pathExistsStub.callCount, 0, "_pathExists should never be called");
Expand Down Expand Up @@ -703,11 +705,11 @@ test.serial("Installer: installPackage with new package and existing target and

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

t.is(t.context.mkdirpStub.callCount, 2, "mkdirp should be called twice");
t.is(t.context.mkdirpStub.getCall(0).args[0], path.join("/", "ui5Home", "framework", "locks"),
"mkdirp should be called with the correct arguments on first call");
t.is(t.context.mkdirpStub.getCall(1).args[0], path.join("my", "package"),
"mkdirp should be called with the correct arguments on second call");
t.is(t.context.mkdirStub.callCount, 2, "mkdir should be called twice");
t.is(t.context.mkdirStub.getCall(0).args[0], path.join("/", "ui5Home", "framework", "locks"),
"mkdir should be called with the correct arguments on first call");
t.is(t.context.mkdirStub.getCall(1).args[0], path.join("my", "package"),
"mkdir should be called with the correct arguments on second call");

t.is(t.context.renameStub.callCount, 1, "fs.rename should be called once");
t.is(t.context.renameStub.getCall(0).args[0], "staging-dir-path",
Expand Down

0 comments on commit 1e2951d

Please sign in to comment.