fix: ensure extension installs happen in the right place
and not up the filesystem from the appium home dir
just because someone happens to have a package.json
or a node_modules dir up there somewhere
MODIFY
lib/cli/npm.js
lib/cli/npm.js
import path from 'path';
import semver from 'semver';
import { exec } from 'teen_process';
-import { mkdirp, util, system } from 'appium-support';
+import { fs, mkdirp, util, system } from 'appium-support';
const INSTALL_LOCKFILE = '.appium.install.lock';
const LINK_LOCKFILE = '.appium.link.lock';
@@ -20,6 +20,14 @@ export default class NPM {
// ensure the directory we want to install inside of exists
await mkdirp(cwd);
+ // not only this, this directory needs a 'package.json' inside of it, otherwise, if any
+ // directory in the filesystem tree ABOVE cwd happens to have a package.json or a node_modules
+ // dir in it, NPM will install the module up there instead (silly NPM)
+ const dummyPkgJson = path.resolve(cwd, 'package.json');
+ if (!await fs.exists(dummyPkgJson)) {
+ await fs.writeFile(dummyPkgJson, '{}');
+ }
+
// make sure we perform the current operation in cwd
execOpts = {...execOpts, cwd};

fix: ensure extension installs happen in the right place
and not up the filesystem from the appium home dir
just because someone happens to have a package.json
or a node_modules dir up there somewhere