Skip to content

Commit af66838

Browse files
potapovDimdiemol
andauthored
remove useless package, change io public api import to more common approach (#10037)
Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
1 parent 1f745a0 commit af66838

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

javascript/node/selenium-webdriver/io/index.js

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
const fs = require('fs')
2121
const path = require('path')
22-
const rimraf = require('rimraf')
2322
const tmp = require('tmp')
2423

2524
/**
@@ -52,24 +51,16 @@ function checkedCall(fn) {
5251
* @return {!Promise} A promise to be resolved when the operation has
5352
* completed.
5453
*/
55-
exports.rmDir = function (dirPath) {
54+
function rmDir(dirPath) {
5655
return new Promise(function (fulfill, reject) {
57-
var numAttempts = 0
58-
attemptRm()
59-
function attemptRm() {
60-
numAttempts += 1
61-
rimraf(dirPath, function (err) {
62-
if (err) {
63-
if (err.code && err.code === 'ENOTEMPTY' && numAttempts < 2) {
64-
attemptRm()
65-
return
66-
}
67-
reject(err)
68-
} else {
69-
fulfill()
70-
}
71-
})
72-
}
56+
fs.rm(dirPath, { recursive: true, maxRetries: 2 }, function (err) {
57+
if (err && err.code === 'ENOENT') {
58+
fulfill()
59+
} else if (err) {
60+
reject(err)
61+
}
62+
fulfill()
63+
})
7364
})
7465
}
7566

@@ -79,7 +70,7 @@ exports.rmDir = function (dirPath) {
7970
* @param {string} dst The destination file.
8071
* @return {!Promise<string>} A promise for the copied file's path.
8172
*/
82-
exports.copy = function (src, dst) {
73+
function copy(src, dst) {
8374
return new Promise(function (fulfill, reject) {
8475
const rs = fs.createReadStream(src)
8576
rs.on('error', reject)
@@ -102,7 +93,7 @@ exports.copy = function (src, dst) {
10293
* @return {!Promise<string>} A promise for the destination
10394
* directory's path once all files have been copied.
10495
*/
105-
exports.copyDir = function (src, dst, opt_exclude) {
96+
function copyDir(src, dst, opt_exclude) {
10697
let predicate = opt_exclude
10798
if (opt_exclude && typeof opt_exclude !== 'function') {
10899
predicate = function (p) {
@@ -172,9 +163,8 @@ exports.stat = function stat(aPath) {
172163
* @param {string} aPath The path to remove.
173164
* @return {!Promise} A promise for when the file has been removed.
174165
*/
175-
exports.unlink = function (aPath) {
166+
function unlink(aPath) {
176167
return new Promise(function (fulfill, reject) {
177-
// eslint-disable-next-line node/no-deprecated-api
178168
const exists = fs.existsSync(aPath)
179169
if (exists) {
180170
fs.unlink(aPath, function (err) {
@@ -190,7 +180,7 @@ exports.unlink = function (aPath) {
190180
* @return {!Promise<string>} A promise for the path to a temporary directory.
191181
* @see https://www.npmjs.org/package/tmp
192182
*/
193-
exports.tmpDir = function () {
183+
function tmpDir() {
194184
return checkedCall((callback) => tmp.dir({ unsafeCleanup: true }, callback))
195185
}
196186

@@ -199,7 +189,7 @@ exports.tmpDir = function () {
199189
* @return {!Promise<string>} A promise for the path to a temporary file.
200190
* @see https://www.npmjs.org/package/tmp
201191
*/
202-
exports.tmpFile = function (opt_options) {
192+
function tmpFile(opt_options) {
203193
return checkedCall((callback) => {
204194
/** check fixed in v > 0.2.1 if
205195
* (typeof options === 'function') {
@@ -219,7 +209,7 @@ exports.tmpFile = function (opt_options) {
219209
* @return {?string} Path to the located file, or {@code null} if it could
220210
* not be found.
221211
*/
222-
exports.findInPath = function (file, opt_checkCwd) {
212+
function findInPath(file, opt_checkCwd) {
223213
const dirs = []
224214
if (opt_checkCwd) {
225215
dirs.push(process.cwd())
@@ -246,7 +236,7 @@ exports.findInPath = function (file, opt_checkCwd) {
246236
* @return {!Promise<!Buffer>} A promise that will resolve with a buffer of the
247237
* file contents.
248238
*/
249-
exports.read = function (aPath) {
239+
function read(aPath) {
250240
return checkedCall((callback) => fs.readFile(aPath, callback))
251241
}
252242

@@ -258,7 +248,7 @@ exports.read = function (aPath) {
258248
* @return {!Promise} A promise that will resolve when the operation has
259249
* completed.
260250
*/
261-
exports.write = function (aPath, data) {
251+
function write(aPath, data) {
262252
return checkedCall((callback) => fs.writeFile(aPath, data, callback))
263253
}
264254

@@ -269,7 +259,7 @@ exports.write = function (aPath, data) {
269259
* @return {!Promise<string>} A promise that will resolve with the path of the
270260
* created directory.
271261
*/
272-
exports.mkdir = function (aPath) {
262+
function mkdir(aPath) {
273263
return checkedCall((callback) => {
274264
fs.mkdir(aPath, undefined, (err) => {
275265
if (err && err.code !== 'EEXIST') {
@@ -288,7 +278,7 @@ exports.mkdir = function (aPath) {
288278
* @return {!Promise<string>} A promise that will resolve with the path of the
289279
* created directory.
290280
*/
291-
exports.mkdirp = function mkdirp(dir) {
281+
function mkdirp(dir) {
292282
return checkedCall((callback) => {
293283
fs.mkdir(dir, undefined, (err) => {
294284
if (!err) {
@@ -324,7 +314,7 @@ exports.mkdirp = function mkdirp(dir) {
324314
* resolve with a list of entries seen. For each entry, the recorded path
325315
* will be relative to `rootPath`.
326316
*/
327-
exports.walkDir = function (rootPath) {
317+
function walkDir(rootPath) {
328318
const seen = []
329319
return (function walk(dir) {
330320
return checkedCall((callback) => fs.readdir(dir, callback)).then((files) =>
@@ -343,3 +333,17 @@ exports.walkDir = function (rootPath) {
343333
)
344334
})(rootPath).then(() => seen)
345335
}
336+
337+
// PUBLIC API
338+
module.exports.walkDir = walkDir
339+
module.exports.rmDir = rmDir
340+
module.exports.mkdirp = mkdirp
341+
module.exports.mkdir = mkdir
342+
module.exports.write = write
343+
module.exports.read = read
344+
module.exports.findInPath = findInPath
345+
module.exports.tmpFile = tmpFile
346+
module.exports.tmpDir = tmpDir
347+
module.exports.unlink = unlink
348+
module.exports.copy = copy
349+
module.exports.copyDir = copyDir

javascript/node/selenium-webdriver/package-lock.json

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

javascript/node/selenium-webdriver/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
},
2525
"dependencies": {
2626
"jszip": "^3.6.0",
27-
"rimraf": "^3.0.2",
2827
"tmp": "^0.2.1",
2928
"ws": ">=7.4.6"
3029
},

0 commit comments

Comments
 (0)