refactor: Reuse walkDir implementation from appium-support module
MODIFY
lib/basedriver/helpers.js
lib/basedriver/helpers.js
@@ -234,18 +234,6 @@ async function downloadApp (app, targetPath) {
return targetPath;
}
-async function walkDir (dir) {
- const result = [];
- for (const name of await fs.readdir(dir)) {
- const currentPath = path.join(dir, name);
- result.push(currentPath);
- if ((await fs.stat(currentPath)).isDirectory()) {
- result.push(...(await walkDir(currentPath)));
- }
- }
- return result;
-}
-
async function unzipApp (zipPath, dstRoot, supportedAppExtensions) {
await zip.assertValidZip(zipPath);
@@ -257,7 +245,8 @@ async function unzipApp (zipPath, dstRoot, supportedAppExtensions) {
try {
logger.debug(`Unzipping '${zipPath}'`);
await zip.extractAllTo(zipPath, tmpRoot);
- const allExtractedItems = await walkDir(tmpRoot);
+ const allExtractedItems = [];
+ await fs.walkDir(tmpRoot, true, (itemPath) => void allExtractedItems.push(itemPath));
logger.debug(`Extracted ${allExtractedItems.length} item(s) from '${zipPath}'`);
const isSupportedAppItem = (relativePath) => supportedAppExtensions.includes(path.extname(relativePath))
|| _.some(supportedAppExtensions, (x) => relativePath.includes(`${x}${path.sep}`));
@@ -273,7 +262,9 @@ async function unzipApp (zipPath, dstRoot, supportedAppExtensions) {
await fs.rimraf(itemPath);
}
});
- const allBundleItems = (await walkDir(tmpRoot))
+ let allBundleItems = [];
+ await fs.walkDir(tmpRoot, true, (itemPath) => void allBundleItems.push(itemPath));
+ allBundleItems = allBundleItems
.map((itemPath) => path.relative(tmpRoot, itemPath))
.filter((relativePath) => isSupportedAppItem(relativePath))
// Get the top level match

MODIFY
package.json
package.json
],
"dependencies": {
"@babel/runtime": "^7.0.0",
- "appium-support": "^2.24.0",
+ "appium-support": "^2.33.1",
"async-lock": "^1.0.0",
"asyncbox": "^2.3.1",
"bluebird": "^3.5.3",

refactor: Reuse walkDir implementation from appium-support module (#361)