1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3    return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.getNpmProxy = exports.isYarnOfflineAsync = void 0;
7const child_process_1 = require("child_process");
8const dns_1 = __importDefault(require("dns"));
9const url_1 = __importDefault(require("url"));
10/** Determine if you should use yarn offline or not */
11async function isYarnOfflineAsync() {
12    if (await isUrlAvailableAsync('registry.yarnpkg.com')) {
13        return false;
14    }
15    const proxy = getNpmProxy();
16    if (!proxy) {
17        return true;
18    }
19    const { hostname } = url_1.default.parse(proxy);
20    if (!hostname) {
21        return true;
22    }
23    return !(await isUrlAvailableAsync(hostname));
24}
25exports.isYarnOfflineAsync = isYarnOfflineAsync;
26/** Exposed for testing */
27function getNpmProxy() {
28    if (process.env.https_proxy) {
29        return process.env.https_proxy ?? null;
30    }
31    try {
32        const httpsProxy = (0, child_process_1.execSync)('npm config get https-proxy').toString().trim();
33        return httpsProxy !== 'null' ? httpsProxy : null;
34    }
35    catch {
36        return null;
37    }
38}
39exports.getNpmProxy = getNpmProxy;
40function isUrlAvailableAsync(url) {
41    return new Promise((resolve) => {
42        dns_1.default.lookup(url, (err) => {
43            resolve(!err);
44        });
45    });
46}
47//# sourceMappingURL=yarn.js.map