Skip to content

Commit

Permalink
remove mkpath as a dependency (#3679)
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityvi committed Apr 6, 2023
1 parent a647ee7 commit 48f488f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 20 deletions.
47 changes: 44 additions & 3 deletions lib/utils/index.js
@@ -1,6 +1,5 @@
const path = require('path');
const fs = require('fs');
const mkpath = require('mkpath');
const glob = require('glob');
const lodashMerge = require('lodash.merge');
const {By, Capabilities} = require('selenium-webdriver');
Expand Down Expand Up @@ -514,7 +513,7 @@ class Utils {

static createFolder(dirPath) {
return new Promise((resolve, reject) => {
mkpath(dirPath, function(err) {
Utils.mkpath(dirPath, function(err) {
if (err) {
return reject(err);
}
Expand All @@ -533,7 +532,7 @@ class Utils {
const dir = path.resolve(filePath, '..');

return new Promise((resolve, reject) => {
mkpath(dir, function(err) {
Utils.mkpath(dir, function(err) {
if (err) {
reject(err);
} else {
Expand Down Expand Up @@ -641,6 +640,48 @@ class Utils {

return objects;
}

/**
* make all directories in a path, like mkdir -p
*/
static mkpath(dirpath, mode, callback) {
dirpath = path.resolve(dirpath);

if (typeof mode === 'function' || typeof mode === 'undefined') {
callback = mode;
mode = parseInt('0777', 8);

if (!callback) {
callback = function() {};
}
}

fs.stat(dirpath, function (err, stats) {
if (err) {
if (err.code === 'ENOENT') {
Utils.mkpath(path.dirname(dirpath), mode, function (err) {
if (err) {
callback(err);
} else {
fs.mkdir(dirpath, mode, function (err) {
if (!err || err.code === 'EEXIST') {
callback(null);
} else {
callback(err);
}
});
}
});
} else {
callback(err);
}
} else if (stats.isDirectory()) {
callback(null);
} else {
callback(new Error(dirpath + ' exists and is not a directory'));
}
});
}
}

lodashMerge(Utils, {
Expand Down
1 change: 0 additions & 1 deletion lib/utils/screenshots.js
@@ -1,6 +1,5 @@
const path = require('path');
const fs = require('fs');
const mkpath = require('mkpath');
const Defaults = require('../settings/defaults.js');

class Screenshots {
Expand Down
11 changes: 0 additions & 11 deletions 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
Expand Up @@ -34,7 +34,6 @@
"lodash.pick": "4.4.0",
"minimatch": "3.1.2",
"minimist": "1.2.6",
"mkpath": "1.0.0",
"mocha": "9.2.2",
"nightwatch-axe-verbose": "^2.1.0",
"open": "8.4.0",
Expand Down
2 changes: 1 addition & 1 deletion test/src/runner/testReporter.js
@@ -1,12 +1,12 @@
const assert = require('assert');
const path = require('path');
const mockery = require('mockery');
const mkpath = require('mkpath');
const rimraf = require('rimraf');

const common = require('../../common.js');
const {settings} = common;
const {runTests} = common.require('index.js');
const {mkpath} = common.require('utils');
const {readFilePromise, readDirPromise} = require('../../lib/utils.js');

const MockServer = require('../../lib/mockserver.js');
Expand Down
2 changes: 1 addition & 1 deletion test/src/runner/testRunnerHtmlOutput.js
Expand Up @@ -4,10 +4,10 @@ const MockServer = require('../../lib/mockserver.js');
const {settings} = common;
const {runTests} = common.require('index.js');
const {readFilePromise} = require('../../lib/utils.js');
const mkpath = require('mkpath');
const rimraf = require('rimraf');
const assert = require('assert');
const HtmlReporter = common.require('reporter/reporters/html.js');
const {mkpath} = common.require('utils');
const reportObject = require('../../extra/reportObject');

describe('testRunnerHTMLOutput', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/src/runner/testRunnerJsonOutput.js
Expand Up @@ -4,10 +4,10 @@ const assert = require('assert');
const common = require('../../common.js');
const MockServer = require('../../lib/mockserver.js');
const CommandGlobals = require('../../lib/globals/commands.js');
const mkpath = require('mkpath');
const rimraf = require('rimraf');
const {settings} = common;
const {runTests} = common.require('index.js');
const {mkpath} = common.require('utils');

describe('testRunnerJsonOutput', function() {
before(function(done) {
Expand Down
2 changes: 1 addition & 1 deletion test/src/runner/testRunnerJunitOutput.js
Expand Up @@ -7,7 +7,7 @@ const CommandGlobals = require('../../lib/globals/commands.js');
const {settings} = common;
const {runTests} = common.require('index.js');
const {readFilePromise, readDirPromise} = require('../../lib/utils.js');
const mkpath = require('mkpath');
const {mkpath} = common.require('utils');
const rimraf = require('rimraf');

describe('testRunnerJUnitOutput', function() {
Expand Down

0 comments on commit 48f488f

Please sign in to comment.