puppeteer-finder
Version:
Find a executable Chrome / Edge / Firefox in your system
62 lines • 3.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
const path_1 = require("path");
const utils_1 = require("./utils");
const suffixes = [
'/Contents/MacOS/Google Chrome Canary',
'/Contents/MacOS/Google Chrome Dev',
'/Contents/MacOS/Google Chrome',
'/Contents/MacOS/Chromium',
'/Contents/MacOS/Microsoft Edge Canary',
'/Contents/MacOS/Microsoft Edge Dev',
'/Contents/MacOS/Microsoft Edge',
];
const LSREGISTER = '/System/Library/Frameworks/CoreServices.framework' +
'/Versions/A/Frameworks/LaunchServices.framework' +
'/Versions/A/Support/lsregister';
function darwin() {
const installations = [];
(0, child_process_1.execSync)([
`${LSREGISTER} -dump`,
`grep -E -i -o '/.+(((google chrome)|(microsoft edge))( (dev|canary))?|chromium)\\.app(\\s|$)'`,
`grep -E -v 'Caches|TimeMachine|Temporary|/Volumes|\\.Trash'`,
].join(' | '))
.toString()
.split(utils_1.newLineRegex)
.forEach((inst) => {
suffixes.forEach(suffix => {
const execPath = (0, path_1.join)(inst.trim(), suffix);
if ((0, utils_1.canAccess)(execPath)) {
installations.push(execPath);
}
});
});
// Retains one per line to maintain readability.
const priorities = [
{ regex: new RegExp(`^${process.env.HOME}/Applications/.*Microsoft Edge.app`), weight: 46 },
{ regex: new RegExp(`^${process.env.HOME}/Applications/.*Microsoft Edge Dev.app`), weight: 47 },
{ regex: new RegExp(`^${process.env.HOME}/Applications/.*Microsoft Edge Canary.app`), weight: 48 },
{ regex: new RegExp(`^${process.env.HOME}/Applications/.*Chromium.app`), weight: 49 },
{ regex: new RegExp(`^${process.env.HOME}/Applications/.*Chrome.app`), weight: 50 },
{ regex: new RegExp(`^${process.env.HOME}/Applications/.*Chrome Dev.app`), weight: 51 },
{ regex: new RegExp(`^${process.env.HOME}/Applications/.*Chrome Canary.app`), weight: 52 },
{ regex: /^\/Applications\/.*Microsoft Edge.app/, weight: 96 },
{ regex: /^\/Applications\/.*Microsoft Edge Dev.app/, weight: 97 },
{ regex: /^\/Applications\/.*Microsoft Edge Canary.app/, weight: 98 },
{ regex: /^\/Applications\/.*Chromium.app/, weight: 99 },
{ regex: /^\/Applications\/.*Chrome.app/, weight: 100 },
{ regex: /^\/Applications\/.*Chrome Dev.app/, weight: 101 },
{ regex: /^\/Applications\/.*Chrome Canary.app/, weight: 102 },
{ regex: /^\/Volumes\/.*Microsoft Edge.app/, weight: -6 },
{ regex: /^\/Volumes\/.*Microsoft Edge Dev.app/, weight: -5 },
{ regex: /^\/Volumes\/.*Microsoft Edge Canary.app/, weight: -4 },
{ regex: /^\/Volumes\/.*Chromium.app/, weight: -3 },
{ regex: /^\/Volumes\/.*Chrome.app/, weight: -2 },
{ regex: /^\/Volumes\/.*Chrome Dev.app/, weight: -1 },
{ regex: /^\/Volumes\/.*Chrome Canary.app/, weight: 0 },
];
return (0, utils_1.sort)(installations, priorities);
}
exports.default = darwin;
//# sourceMappingURL=darwin.js.map