chore(appium): use new mkdirp
fix some types, mocks
rename `HASHFILE_RELATIVE_PATH` to `PKG_HASHFILE_RELATIVE_PATH`; hopefully that's less opaque
fixed broken junk in `commands-yml/parse.js` which will conflict with so idk
MODIFY
packages/appium/commands-yml/parse.js
packages/appium/commands-yml/parse.js
import path from 'path';
import yaml from 'yaml-js';
-import { fs, mkdirp, util } from 'appium-support';
+import { fs, util } from '@appium/support';
import validate from 'validate.js';
import Handlebars from 'handlebars';
import _ from 'lodash';
@@ -8,8 +8,6 @@ import { asyncify } from 'asyncbox';
import { validator, CLIENT_URL_TYPES } from './validator';
import url from 'url';
import log from 'fancy-log';
-import findRoot from 'find-root';
-
// What range of platforms do the driver's support
const platformRanges = {
@@ -31,7 +29,7 @@ const appiumRanges = {
mac: ['1.6.4'],
};
-const rootFolder = findRoot(__dirname);
+const rootFolder = fs.findRoot(__dirname);
// Create Handlebars helper that shows a version range
Handlebars.registerHelper('versions', function versionHelper (object, name, driverName) {
@@ -207,7 +205,7 @@ async function generateCommands () {
const markdownPath = `${relativeFilename.substring(0, relativeFilename.length - ext.length)}.md`;
const outfile = path.resolve(rootFolder, 'docs', 'en', markdownPath);
log(` Writing to: ${outfile}`);
- await mkdirp(path.dirname(outfile));
+ await fs.mkdirp(path.dirname(outfile));
await fs.writeFile(outfile, markdown, 'utf8');
fileCount++;

MODIFY
packages/appium/lib/config.js
packages/appium/lib/config.js
/* eslint-disable no-console */
import _ from 'lodash';
-import { mkdirp, system, fs } from '@appium/support';
+import { system, fs } from '@appium/support';
import axios from 'axios';
import { exec } from 'teen_process';
import logger from './logger';
@@ -288,7 +288,7 @@ function showConfig (nonDefaultPreConfigParsedArgs, configResult, defaults, pars
*/
async function validateTmpDir (tmpDir) {
try {
- await mkdirp(tmpDir);
+ await fs.mkdirp(tmpDir);
} catch (e) {
throw new Error(`We could not ensure that the temp dir you specified ` +
`(${tmpDir}) exists. Please make sure it's writeable.`);

MODIFY
packages/appium/lib/constants.js
packages/appium/lib/constants.js
@@ -66,7 +66,7 @@ export const CACHE_DIR_RELATIVE_PATH = path.join(
/**
* Relative path to hashfile (from `APPIUM_HOME`) of consuming project's `package.json` (if it exists)
*/
-export const HASHFILE_RELATIVE_PATH = path.join(
+export const PKG_HASHFILE_RELATIVE_PATH = path.join(
CACHE_DIR_RELATIVE_PATH,
'package.hash',
);

MODIFY
packages/appium/lib/extension/manifest.js
packages/appium/lib/extension/manifest.js
* Module containing {@link Manifest} which handles reading & writing of extension config files.
*/
-import { env, fs, mkdirp } from '@appium/support';
+import { env, fs } from '@appium/support';
import _ from 'lodash';
import path from 'path';
import YAML from 'yaml';
@@ -394,7 +394,7 @@ export class Manifest {
this._writing = (async () => {
await this._setManifestPath();
try {
- await mkdirp(path.dirname(this._manifestPath));
+ await fs.mkdirp(path.dirname(this._manifestPath));
} catch (err) {
throw new Error(
`Appium could not create the directory for the manifest file: ${path.dirname(

MODIFY
packages/appium/lib/extension/package-changed.js
packages/appium/lib/extension/package-changed.js
// @ts-check
-import { mkdirp } from '@appium/support';
+import { fs } from '@appium/support';
import { isPackageChanged } from 'package-changed';
import path from 'path';
-import { HASHFILE_RELATIVE_PATH } from '../constants';
+import { PKG_HASHFILE_RELATIVE_PATH } from '../constants';
import log from '../logger';
/**
@@ -16,7 +16,7 @@ import log from '../logger';
* @returns {Promise<boolean>} `true` if `package.json` `appiumHome` changed
*/
export async function packageDidChange (appiumHome) {
- const hashFilename = path.join(appiumHome, HASHFILE_RELATIVE_PATH);
+ const hashFilename = path.join(appiumHome, PKG_HASHFILE_RELATIVE_PATH);
// XXX: the types in `package-changed` seem to be wrong.
@@ -33,7 +33,7 @@ export async function packageDidChange (appiumHome) {
const hashFilenameDir = path.dirname(hashFilename);
log.debug(`Creating hash file directory: ${hashFilenameDir}`);
try {
- await mkdirp(hashFilenameDir);
+ await fs.mkdirp(hashFilenameDir);
} catch (err) {
throw new Error(
`Appium could not create the directory for hash file: ${hashFilenameDir}. Original error: ${err.message}`,
@@ -43,7 +43,7 @@ export async function packageDidChange (appiumHome) {
try {
({isChanged, writeHash, oldHash, hash} = await isPackageChanged({
cwd: appiumHome,
- hashFilename: HASHFILE_RELATIVE_PATH,
+ hashFilename: PKG_HASHFILE_RELATIVE_PATH,
}));
} catch {
return true;

MODIFY
packages/appium/test/cli/cli-e2e-specs.js
packages/appium/test/cli/cli-e2e-specs.js
// @ts-check
-import { npm, env, fs, mkdirp, tempDir, util } from '@appium/support';
+import { npm, env, fs, tempDir, util } from '@appium/support';
import path from 'path';
import resolveFrom from 'resolve-from';
import YAML from 'yaml';
@@ -10,7 +10,7 @@ import {
EXT_SUBCOMMAND_LIST as LIST,
EXT_SUBCOMMAND_RUN as RUN,
EXT_SUBCOMMAND_UNINSTALL as UNINSTALL,
- HASHFILE_RELATIVE_PATH,
+ PKG_HASHFILE_RELATIVE_PATH,
KNOWN_DRIVERS,
PLUGIN_TYPE
} from '../../lib/constants';
@@ -59,7 +59,7 @@ describe('CLI behavior', function () {
before(async function () {
appiumHome = await tempDir.openDir();
- hashPath = path.join(appiumHome, HASHFILE_RELATIVE_PATH);
+ hashPath = path.join(appiumHome, PKG_HASHFILE_RELATIVE_PATH);
manifestPath = path.join(appiumHome, MANIFEST_RELATIVE_PATH);
appiumHomePkgPath = path.join(appiumHome, 'package.json');
runJson = runAppiumJson(appiumHome);
@@ -197,7 +197,7 @@ describe('CLI behavior', function () {
async function clear () {
await fs.rimraf(appiumHome);
- await mkdirp(appiumHome);
+ await fs.mkdirp(appiumHome);
}
describe('Driver CLI', function () {

MODIFY
packages/appium/test/extension/mocks.js
packages/appium/test/extension/mocks.js
@@ -28,10 +28,10 @@ export function initMocks (sandbox = createSandbox()) {
.returns({next: sandbox.stub().resolves({done: true})}),
})
),
- },
- mkdirp: /** @type {MockAppiumSupport['mkdirp']} */ (
+ mkdirp: /** @type {MockAppiumSupportFs['mkdirp']} */ (
sandbox.stub().resolves()
),
+ },
env: {
resolveAppiumHome:
/** @type {MockAppiumSupportEnv['resolveAppiumHome']} */ (
@@ -111,7 +111,6 @@ export function initMocks (sandbox = createSandbox()) {
/**
* Mock of package `@appium/support`
* @typedef {Object} MockAppiumSupport
- * @property {sinon.SinonStub<[string], Promise<void>>} mkdirp
* @property {MockAppiumSupportLogger} logger
* @property {MockAppiumSupportFs} fs
* @property {MockAppiumSupportEnv} env
@@ -126,9 +125,10 @@ export function initMocks (sandbox = createSandbox()) {
/**
* Mock of package `@appium/support`'s `fs` module
* @typedef {Object} MockAppiumSupportFs
- * @property {sinon.SinonStubbedMember<import('fs/promises')['readFile']>} readFile
- * @property {sinon.SinonStubbedMember<import('fs/promises')['writeFile']>} writeFile
- * @property {sinon.SinonStubbedMember<import('klaw')>} walk
+ * @property {sinon.SinonStubbedMember<import('@appium/support/lib/fs')['fs']['readFile']>} readFile
+ * @property {sinon.SinonStubbedMember<import('@appium/support/lib/fs')['fs']['writeFile']>} writeFile
+ * @property {sinon.SinonStubbedMember<import('@appium/support/lib/fs')['fs']['walk']>} walk
+ * @property {sinon.SinonStubbedMember<import('@appium/support/lib/fs')['fs']['mkdirp']>} mkdirp
*/
/**

MODIFY
packages/appium/test/extension/package-changed-specs.js
packages/appium/test/extension/package-changed-specs.js
// @ts-check
import path from 'path';
-import { HASHFILE_RELATIVE_PATH } from '../../lib/constants';
+import { PKG_HASHFILE_RELATIVE_PATH } from '../../lib/constants';
import { rewiremock } from '../helpers';
import { initMocks } from './mocks';
@@ -46,8 +46,8 @@ describe('package-changed', function () {
it('it should attempt to create the parent dir for the hash file', async function () {
await packageDidChange('/some/path');
- expect(MockAppiumSupport.mkdirp).to.have.been.calledWith(
- path.dirname(path.join('/some/path', HASHFILE_RELATIVE_PATH)),
+ expect(MockAppiumSupport.fs.mkdirp).to.have.been.calledWith(
+ path.dirname(path.join('/some/path', PKG_HASHFILE_RELATIVE_PATH)),
);
});
@@ -55,13 +55,13 @@ describe('package-changed', function () {
await packageDidChange('/some/path');
expect(MockPackageChanged.isPackageChanged).to.have.been.calledWith({
cwd: '/some/path',
- hashFilename: HASHFILE_RELATIVE_PATH,
+ hashFilename: PKG_HASHFILE_RELATIVE_PATH,
});
});
describe('when it cannot create the parent dir', function () {
it('should reject', async function () {
- MockAppiumSupport.mkdirp.rejects(new Error('some error'));
+ MockAppiumSupport.fs.mkdirp.rejects(new Error('some error'));
await expect(packageDidChange('/some/path')).to.be.rejectedWith(
Error,
/could not create the directory/i,

MODIFY
packages/support/lib/fs.js
packages/support/lib/fs.js
@@ -26,7 +26,6 @@ const findRootCached = _.memoize(pkgDir.sync);
const fs = {
async hasAccess (path) {
try {
- // as of recent-ish node versions, `R_OK` moved into the `constants` property of `fs`
await fs.access(path, _fs.constants.R_OK);
} catch (err) {
return false;

chore(appium): use new mkdirp

- fix some types, mocks
- rename `HASHFILE_RELATIVE_PATH` to `PKG_HASHFILE_RELATIVE_PATH`; hopefully that's less opaque
- fixed broken junk in `commands-yml/parse.js` which will conflict with #16459 so idk