appium-chromium-driver
Version:
Appium driver for Chromium-based browsers that work with Chromedriver
64 lines • 3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.deployDriverArtifact = deployDriverArtifact;
exports.locateDriverExecutableInDir = locateDriverExecutableInDir;
const support_1 = require("appium/support");
const node_path_1 = __importDefault(require("node:path"));
/**
* Deploy a downloaded driver artifact into the target executable directory.
* @param artifact Driver artifact metadata needed for deployment.
* @param executableDir The base directory where versioned driver folders are stored.
* @param downloadArchive Callback responsible for obtaining the archive file at the provided path.
* @returns The deployed driver executable path.
* @throws Error if deployment fails.
*/
async function deployDriverArtifact(artifact, executableDir, downloadArchive) {
const targetDir = node_path_1.default.join(executableDir, artifact.version);
const targetExecutable = node_path_1.default.join(targetDir, artifact.executableName);
if (await support_1.fs.isExecutable(targetExecutable)) {
return targetExecutable;
}
await support_1.fs.mkdirp(targetDir);
const tmpRoot = await support_1.tempDir.openDir();
const archivePath = node_path_1.default.join(tmpRoot, artifact.archiveName);
try {
await downloadArchive(archivePath);
await support_1.zip.extractAllTo(archivePath, targetDir);
const extractedExecutable = await locateDriverExecutableInDir(targetDir, artifact.executableName);
if (!extractedExecutable) {
throw new Error(`Cannot find '${artifact.executableName}' in '${targetDir}'`);
}
if (process.platform !== 'win32') {
// This might not be necessary, but to be safe.
await support_1.fs.chmod(extractedExecutable, 0o755);
}
if (extractedExecutable !== targetExecutable) {
await support_1.fs.mv(extractedExecutable, targetExecutable, { mkdirp: true, clobber: true });
}
return targetExecutable;
}
finally {
await support_1.fs.rimraf(tmpRoot);
}
}
/**
* Locate the driver executable in the given directory tree.
* @param executableDir The directory to search for the driver executable.
* @param executableName The driver executable file name.
* @returns The path to the driver executable, or null if not found.
*/
async function locateDriverExecutableInDir(executableDir, executableName) {
// TODO: change to check the version instead of file existence as a followup.
// https://github.com/appium/appium-chromium-driver/issues/423
const candidates = await support_1.fs.glob(`**/${executableName}`, {
cwd: executableDir,
absolute: true,
nodir: true,
});
const [match] = candidates.sort((a, b) => a.length - b.length);
return match ?? null;
}
//# sourceMappingURL=deployment.js.map