feat: add --package cli arg to plugin/driver install, since in the case of git/github we don't actually know where npm will install it unless we know the package name
MODIFY
lib/cli/args.js
lib/cli/args.js
@@ -374,6 +374,15 @@ function makeInstallArgs (type) {
`${type}s. Possible values: ${JSON.stringify(INSTALL_TYPES)}`,
dest: 'installType'
}],
+ [['--package'], {
+ required: false,
+ defaultValue: null,
+ type: 'string',
+ help: `If installing from Git or GitHub, the package name, as defined in the plugin's ` +
+ `package.json file in the "name" field, cannot be determined automatically, and ` +
+ `should be reported here, otherwise the install will probably fail.`,
+ dest: 'packageName',
+ }],
];
}

MODIFY
lib/cli/driver-command.js
lib/cli/driver-command.js
@@ -12,8 +12,8 @@ export default class DriverCommand extends ExtensionCommand {
this.knownExtensions = KNOWN_DRIVERS;
}
- async install ({driver, installType}) {
- return await super.install({ext: driver, installType});
+ async install ({driver, installType, packageName}) {
+ return await super.install({ext: driver, installType, packageName});
}
async uninstall ({driver}) {

MODIFY
lib/cli/extension-command.js
lib/cli/extension-command.js
@@ -106,12 +106,20 @@ export default class ExtensionCommand {
return exts;
}
- async install ({ext, installType}) {
+ async install ({ext, installType, packageName}) {
log(this.isJsonOutput, `Attempting to find and install ${this.type} '${ext}'`);
let extData;
let installSpec = ext;
+ if (packageName && [INSTALL_TYPE_LOCAL, INSTALL_TYPE_NPM].includes(installType)) {
+ throw new Error(`When using --source=${installType}, cannot also use --package`);
+ }
+
+ if (!packageName && [INSTALL_TYPE_GIT, INSTALL_TYPE_GITHUB].includes(installType)) {
+ throw new Error(`When using --source=${installType}, must also use --package`);
+ }
+
if (installType === INSTALL_TYPE_LOCAL) {
const msg = `Linking ${this.type} from local path`;
const pkgJsonData = await spinWith(this.isJsonOutput, msg, async () => (
@@ -124,12 +132,12 @@ export default class ExtensionCommand {
throw new Error(`Github ${this.type} spec ${installSpec} appeared to be invalid; ` +
'it should be of the form <org>/<repo>');
}
- extData = await this.installViaNpm({ext: installSpec});
+ extData = await this.installViaNpm({ext: installSpec, pkgName: packageName});
} else if (installType === INSTALL_TYPE_GIT) {
// git urls can have '.git' at the end, but this is not necessary and would complicate the
// way we download and name directories, so we can just remove it
installSpec = installSpec.replace(/\.git$/, '');
- extData = await this.installViaNpm({ext: installSpec});
+ extData = await this.installViaNpm({ext: installSpec, pkgName: packageName});
} else {
// at this point we have either an npm package or an appium verified extension
// name. both of which will be installed via npm.
@@ -190,20 +198,19 @@ export default class ExtensionCommand {
}
async installViaNpm ({ext, pkgName, pkgVer}) {
- let installPath = pkgName;
- if (!pkgName) {
- pkgName = ext;
- installPath = path.posix.basename(pkgName);
- }
const npmSpec = `${pkgName}${pkgVer ? '@' + pkgVer : ''}`;
const specMsg = npmSpec === ext ? '' : ` using NPM install spec '${npmSpec}'`;
const msg = `Installing '${ext}'${specMsg}`;
try {
const pkgJsonData = await spinWith(this.isJsonOutput, msg, async () => (
- await this.npm.installPackage(path.resolve(this.config.appiumHome, installPath), pkgName, pkgVer)
+ await this.npm.installPackage({
+ pkgDir: path.resolve(this.config.appiumHome, pkgName),
+ pkgName,
+ pkgVer
+ })
));
const extData = this.getExtensionFields(pkgJsonData);
- extData.installPath = installPath;
+ extData.installPath = pkgName;
return extData;
} catch (err) {
throw new Error(`Encountered an error when installing package: ${err.message}`);

MODIFY
lib/cli/npm.js
lib/cli/npm.js
@@ -107,22 +107,17 @@ export default class NPM {
return safeUpgradeVer;
}
- async installPackage (pkgDir, pkg, ver) {
+ async installPackage ({pkgDir, pkgName, ver}) {
const res = await this.exec('install', [
'--no-save',
'--no-package-lock',
- ver ? `${pkg}@${ver}` : pkg
+ ver ? `${pkgName}@${ver}` : pkgName
], {
cwd: pkgDir,
json: true,
lockFile: INSTALL_LOCKFILE
});
- // eventually we need to know the npm package name so we can get its
- // package.json, but if we're installing from github, we don't know that yet.
- // for now, assume it is the same thing we sent in as pkg
- let pkgName = pkg;
-
if (res.json) {
// we parsed a valid json response, so if we got an error here, return that
// message straightaway

MODIFY
lib/cli/plugin-command.js
lib/cli/plugin-command.js
@@ -12,8 +12,8 @@ export default class PluginCommand extends ExtensionCommand {
this.knownExtensions = KNOWN_PLUGINS;
}
- async install ({plugin, installType}) {
- return await super.install({ext: plugin, installType});
+ async install ({plugin, installType, packageName}) {
+ return await super.install({ext: plugin, installType, packageName});
}
async uninstall ({plugin}) {

feat: add --package cli arg to plugin/driver install, since in the case of git/github we don't actually know where npm will install it unless we know the package name