Skip to content

Commit

Permalink
fix(appium): correctly handle git/github install types (fix appium#20781
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps authored Nov 29, 2024
1 parent 59a8442 commit 522f05d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions packages/appium/lib/cli/extension-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class ExtensionCliCommand {
installType,
pkgName: /** @type {string} */ (packageName),
};
probableExtName = installSpec;
probableExtName = /** @type {string} */ (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
Expand All @@ -321,7 +321,7 @@ class ExtensionCliCommand {
installType,
pkgName: /** @type {string} */ (packageName),
};
probableExtName = installSpec;
probableExtName = /** @type {string} */ (packageName);
} else {
let pkgName, pkgVer;
if (installType === INSTALL_TYPE_LOCAL) {
Expand Down Expand Up @@ -439,13 +439,15 @@ class ExtensionCliCommand {
* @returns {Promise<ExtInstallReceipt<ExtType>>}
*/
async installViaNpm({installSpec, pkgName, pkgVer, installType}) {
const npmSpec = `${pkgName}${pkgVer ? '@' + pkgVer : ''}`;
const specMsg = npmSpec === installSpec ? '' : ` using NPM install spec '${npmSpec}'`;
const msg = `Installing '${installSpec}'${specMsg}`;
const msg = `Installing '${installSpec}'`;

// the string used for installation is either <name>@<ver> in the case of a standard NPM
// package, or whatever the user sent in otherwise.
const installStr = installType === INSTALL_TYPE_NPM ? `${pkgName}${pkgVer ? `@${pkgVer}` : ''}` : installSpec;
try {
const {pkg, path} = await spinWith(this.isJsonOutput, msg, async () => {
const {pkg, installPath: path} = await npm.installPackage(this.config.appiumHome, pkgName, {
pkgVer,
const {pkg, installPath: path} = await npm.installPackage(this.config.appiumHome, installStr, {
pkgName,
installType,
});
this.validatePackageJson(pkg, installSpec);
Expand Down
8 changes: 4 additions & 4 deletions packages/support/lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ export class NPM {
/**
* Installs a package w/ `npm`
* @param {string} cwd
* @param {string} pkgName
* @param {string} installStr - as in "npm install <installStr>"
* @param {InstallPackageOpts} opts
* @returns {Promise<NpmInstallReceipt>}
*/
async installPackage(cwd, pkgName, {pkgVer, installType} = {}) {
async installPackage(cwd, installStr, {pkgName, installType}) {
/** @type {any} */
let dummyPkgJson;
const dummyPkgPath = path.join(cwd, 'package.json');
Expand All @@ -225,7 +225,7 @@ export class NPM {
}

const cmd = installType === 'local' ? 'link' : 'install';
const res = await this.exec(cmd, [...installOpts, pkgVer ? `${pkgName}@${pkgVer}` : pkgName], {
const res = await this.exec(cmd, [...installOpts, installStr], {
cwd,
json: true,
lockFile: this._getInstallLockfilePath(cwd),
Expand Down Expand Up @@ -287,8 +287,8 @@ export const npm = new NPM();
/**
* Options for {@link NPM.installPackage}
* @typedef InstallPackageOpts
* @property {string} pkgName - the name of the package to install
* @property {import('type-fest').LiteralUnion<'local', string>} [installType] - whether to install from a local path or from npm
* @property {string} [pkgVer] - the version of the package to install
*/

/**
Expand Down

0 comments on commit 522f05d

Please sign in to comment.