Skip to content

Commit

Permalink
refactor: replace mkdirp with fs.mkdir(Sync) (#2217)
Browse files Browse the repository at this point in the history
  • Loading branch information
greshilov committed May 2, 2021
1 parent 84373c4 commit 1b217fd
Show file tree
Hide file tree
Showing 10 changed files with 11,561 additions and 10,371 deletions.
11 changes: 11 additions & 0 deletions .changeset/gentle-parrots-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@verdaccio/config': minor
'@verdaccio/local-storage': minor
'@verdaccio/e2e-ui': minor
---

Some verdaccio modules depend on 'mkdirp' library which provides recursive directory creation functionality.
NodeJS can do this out of the box since v.10.12. The last commit in 'mkdirp' was made in early 2016, and it's mid 2021 now.
Time to stick with a built-in library solution!

- All 'mkdirp' calls are replaced with appropriate 'fs' calls.
1 change: 0 additions & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"js-yaml": "3.14.0",
"lodash": "^4.17.20",
"minimatch": "3.0.4",
"mkdirp": "0.5.5",
"yup": "^0.29.3"
},
"devDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions packages/config/src/config-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fs from 'fs';
import path from 'path';
import Path from 'path';
import _ from 'lodash';
import mkdirp from 'mkdirp';
import buildDebug from 'debug';

import { CHARACTER_ENCODING } from '@verdaccio/commons-api';
Expand Down Expand Up @@ -67,7 +66,7 @@ export function readDefaultConfig(): Buffer {
}

function createConfigFolder(configLocation): void {
mkdirp.sync(Path.dirname(configLocation.path));
fs.mkdirSync(Path.dirname(configLocation.path), { recursive: true });
debug(`Creating default config file in %o`, configLocation?.path);
}

Expand Down
3 changes: 1 addition & 2 deletions packages/core/local-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
"async": "^3.2.0",
"debug": "^4.1.1",
"lodash": "^4.17.20",
"lowdb": "1.0.0",
"mkdirp": "^0.5.5"
"lowdb": "1.0.0"
},
"devDependencies": {
"@types/minimatch": "^3.0.3",
Expand Down
4 changes: 1 addition & 3 deletions packages/core/local-storage/src/local-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import buildDebug from 'debug';

import _ from 'lodash';
import async from 'async';
import mkdirp from 'mkdirp';
import {
Callback,
Config,
Expand Down Expand Up @@ -276,10 +275,9 @@ class LocalDatabase extends TokenActions implements IPluginStorage<{}> {
}
// Uses sync to prevent ugly race condition
try {
// https://www.npmjs.com/package/mkdirp#mkdirpsyncdir-opts
const folderName = Path.dirname(this.path);
debug('creating folder %o', folderName);
mkdirp.sync(folderName);
fs.mkdirSync(folderName, { recursive: true });
debug('sync folder %o created succeed', folderName);
} catch (err) {
debug('sync create folder has failed with error: %o', err);
Expand Down
3 changes: 1 addition & 2 deletions packages/core/local-storage/src/local-fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import path from 'path';
import buildDebug from 'debug';

import _ from 'lodash';
import mkdirp from 'mkdirp';
import { UploadTarball, ReadTarball } from '@verdaccio/streams';
import { unlockFile, readFile } from '@verdaccio/file-locking';
import { Callback, Logger, Package, ILocalPackageManager, IUploadTarball } from '@verdaccio/types';
Expand Down Expand Up @@ -353,7 +352,7 @@ export default class LocalFS implements ILocalFSPackageManager {

createTempFile((err) => {
if (err && err.code === noSuchFile) {
mkdirp(path.dirname(dest), function (err) {
fs.mkdir(path.dirname(dest), { recursive: true }, function (err) {
if (err) {
return cb(err);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/core/local-storage/tests/local-fs.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'path';
import fs from 'fs';

import mkdirp from 'mkdirp';
import rm from 'rmdir-sync';
import { Logger, ILocalPackageManager, Package } from '@verdaccio/types';

Expand Down Expand Up @@ -113,7 +112,7 @@ describe('Local FS test', () => {

describe('removePackage() group', () => {
beforeEach(() => {
mkdirp.sync(path.join(localTempStorage, '_toDelete'));
fs.mkdirSync(path.join(localTempStorage, '_toDelete'), { recursive: true });
});

test('removePackage() success', (done) => {
Expand Down Expand Up @@ -183,7 +182,7 @@ describe('Local FS test', () => {
beforeEach(() => {
const writeTarballFolder: string = path.join(localTempStorage, '_writeTarball');
rm(writeTarballFolder);
mkdirp.sync(writeTarballFolder);
fs.mkdirSync(writeTarballFolder, { recursive: true });
});

test('writeTarball() success', (done) => {
Expand Down

0 comments on commit 1b217fd

Please sign in to comment.