fix: just write config instead of testing for config dir access
MODIFY
lib/driver-cli.js
lib/driver-cli.js
@@ -57,15 +57,15 @@ class DriverCommand {
const lsMsg = `Listing ${showInstalled ? 'installed' : 'available'} drivers`;
const installedNames = Object.keys(this.config.installedDrivers);
const knownNames = Object.keys(KNOWN_DRIVERS);
- const drivers = [...installedNames, ...knownNames].reduce((drivers, name) => {
- if (!drivers[name]) {
+ const drivers = [...installedNames, ...knownNames].reduce((acc, name) => {
+ if (!acc[name]) {
if (installedNames.includes(name)) {
- drivers[name] = {...this.config.installedDrivers[name], installed: true};
+ acc[name] = {...this.config.installedDrivers[name], installed: true};
} else if (!showInstalled) {
- drivers[name] = {pkgName: KNOWN_DRIVERS[name], installed: false};
+ acc[name] = {pkgName: KNOWN_DRIVERS[name], installed: false};
}
}
- return drivers;
+ return acc;
}, {});
// if we want to show whether updates are available, put that behind a spinner

MODIFY
lib/driver-config.js
lib/driver-config.js
@@ -22,7 +22,10 @@ const INSTALL_TYPES = [
export default class DriverConfig {
- constructor (appiumHome, logFn = log.error) {
+ constructor (appiumHome, logFn = null) {
+ if (logFn === null) {
+ logFn = log.error.bind(log);
+ }
this.appiumHome = appiumHome;
this.configFile = path.resolve(this.appiumHome, CONFIG_FILE_NAME);
this.installedDrivers = {};
@@ -47,9 +50,10 @@ export default class DriverConfig {
`readable. Specific error: ${err.message}`);
}
- // if appium home exists but the dir is not readable/writable, fs.access will error
+ // if the config file doesn't exist, try to write an empty one, to make
+ // sure we actually have write privileges, and complain if we don't
try {
- await fs.access(this.appiumHome);
+ await this.write();
} catch {
throw new Error(`Appium could not read or write from the Appium Home directory ` +
`(${this.appiumHome}). Please ensure it is writable.`);

fix: just write config instead of testing for config dir access