JezK
Edit File: rc.js
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.findRc = findRc; function _toConsumableArray2() { var data = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); _toConsumableArray2 = function _toConsumableArray2() { return data; }; return data; } function _fs() { var data = require("fs"); _fs = function _fs() { return data; }; return data; } function path() { var data = _interopRequireWildcard(require("path")); path = function path() { return data; }; return data; } function _constants() { var data = require("../constants"); _constants = function _constants() { return data; }; return data; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var etc = '/etc'; var isWin = process.platform === 'win32'; var home = isWin ? process.env.USERPROFILE : process.env.HOME; function getRcPaths(name, cwd) { var configPaths = []; function pushConfigPath() { for (var _len = arguments.length, segments = new Array(_len), _key = 0; _key < _len; _key++) { segments[_key] = arguments[_key]; } configPaths.push(path().join.apply(path(), segments)); if (segments[segments.length - 1] === ".".concat(name, "rc")) { configPaths.push(path().join.apply(path(), (0, _toConsumableArray2()["default"])(segments.slice(0, -1)).concat([".".concat(name, "rc.yml")]))); } } function unshiftConfigPath() { for (var _len2 = arguments.length, segments = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { segments[_key2] = arguments[_key2]; } if (segments[segments.length - 1] === ".".concat(name, "rc")) { configPaths.unshift(path().join.apply(path(), (0, _toConsumableArray2()["default"])(segments.slice(0, -1)).concat([".".concat(name, "rc.yml")]))); } configPaths.unshift(path().join.apply(path(), segments)); } if (!isWin) { pushConfigPath(etc, name, 'config'); pushConfigPath(etc, "".concat(name, "rc")); } if (home) { pushConfigPath(_constants().CONFIG_DIRECTORY); pushConfigPath(home, '.config', name, 'config'); pushConfigPath(home, '.config', name); pushConfigPath(home, ".".concat(name), 'config'); pushConfigPath(home, ".".concat(name, "rc")); } // add .yarnrc locations relative to the cwd while (true) { unshiftConfigPath(cwd, ".".concat(name, "rc")); var upperCwd = path().dirname(cwd); if (upperCwd === cwd) { // we've reached the root break; } else { // continue since there's still more directories to search cwd = upperCwd; } } var envVariable = "".concat(name, "_config").toUpperCase(); if (process.env[envVariable]) { pushConfigPath(process.env[envVariable]); } return configPaths; } function parseRcPaths(paths, parser) { return Object.assign.apply(Object, [{}].concat((0, _toConsumableArray2()["default"])(paths.map(function (path) { try { return parser((0, _fs().readFileSync)(path).toString(), path); } catch (error) { if (error.code === 'ENOENT' || error.code === 'EISDIR') { return {}; } else { throw error; } } })))); } function findRc(name, cwd, parser) { return parseRcPaths(getRcPaths(name, cwd), parser); } //# sourceMappingURL=rc.js.map