JezK
Edit File: package-compatibility.js
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.check = check; exports.checkOne = checkOne; exports.shouldCheck = shouldCheck; exports.testEngine = testEngine; function _typeof2() { var data = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); _typeof2 = function _typeof2() { return data; }; return data; } function _errors() { var data = require("./errors.js"); _errors = function _errors() { return data; }; return data; } function _map() { var data = _interopRequireDefault(require("./util/map.js")); _map = function _map() { return data; }; return data; } function _misc() { var data = require("./util/misc.js"); _misc = function _misc() { return data; }; return data; } function _yarnVersion() { var data = require("./util/yarn-version.js"); _yarnVersion = function _yarnVersion() { return data; }; return data; } function _semver() { var data = require("./util/semver.js"); _semver = function _semver() { return data; }; return data; } function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } var semver = require('semver'); var VERSIONS = Object.assign({}, process.versions, { yarn: _yarnVersion().version }); function isValid(items, actual) { var isNotWhitelist = true; var isBlacklist = false; var _iterator = _createForOfIteratorHelper(items), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var item = _step.value; // blacklist if (item[0] === '!') { isBlacklist = true; if (actual === item.slice(1)) { return false; } // whitelist } else { isNotWhitelist = false; if (item === actual) { return true; } } } // npm allows blacklists and whitelists to be mixed. Blacklists with // whitelisted items should be treated as whitelists. } catch (err) { _iterator.e(err); } finally { _iterator.f(); } return isBlacklist && isNotWhitelist; } var aliases = (0, _map()["default"])({ iojs: 'node' // we should probably prompt these libraries to fix this }); var ignore = ['npm', // we'll never satisfy this for obvious reasons 'teleport', // a module bundler used by some modules 'rhino', // once a target for older modules 'cordovaDependencies', // http://bit.ly/2tkUePg 'parcel' // used for plugins of the Parcel bundler ]; function testEngine(name, range, versions, looseSemver) { var actual = versions[name]; if (!actual) { return false; } if (!semver.valid(actual, looseSemver)) { return false; } if (semver.satisfies(actual, range, looseSemver)) { return true; } if (name === 'yarn' && (0, _semver().satisfiesWithPrereleases)(actual, range, looseSemver)) { return true; } if (name === 'node' && semver.gt(actual, '1.0.0', looseSemver)) { // WARNING: this is a massive hack and is super gross but necessary for compatibility // some modules have the `engines.node` field set to a caret version below semver major v1 // eg. ^0.12.0. this is problematic as we enforce engines checks and node is now on version >=1 // to allow this pattern we transform the node version to fake ones in the minor range 10-13 var major = semver.major(actual, looseSemver); var fakes = ["0.10.".concat(major), "0.11.".concat(major), "0.12.".concat(major), "0.13.".concat(major)]; for (var _i = 0, _fakes = fakes; _i < _fakes.length; _i++) { var actualFake = _fakes[_i]; if (semver.satisfies(actualFake, range, looseSemver)) { return true; } } } // incompatible version return false; } function isValidArch(archs) { return isValid(archs, process.arch); } function isValidPlatform(platforms) { return isValid(platforms, process.platform); } function checkOne(info, config, ignoreEngines) { var didIgnore = false; var didError = false; var reporter = config.reporter; var human = "".concat(info.name, "@").concat(info.version); var pushError = function pushError(msg) { var ref = info._reference; if (ref && ref.optional) { ref.ignore = true; ref.incompatible = true; if (!didIgnore) { didIgnore = true; } } else { reporter.error("".concat(human, ": ").concat(msg)); didError = true; } }; var os = info.os, cpu = info.cpu, engines = info.engines; if (shouldCheckPlatform(os, config.ignorePlatform) && !isValidPlatform(os)) { pushError(reporter.lang('incompatibleOS', process.platform)); } if (shouldCheckCpu(cpu, config.ignorePlatform) && !isValidArch(cpu)) { pushError(reporter.lang('incompatibleCPU', process.arch)); } if (shouldCheckEngines(engines, ignoreEngines)) { var _iterator2 = _createForOfIteratorHelper((0, _misc().entries)(info.engines)), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var entry = _step2.value; var name = entry[0]; var range = entry[1]; if (aliases[name]) { name = aliases[name]; } if (VERSIONS[name]) { if (!testEngine(name, range, VERSIONS, config.looseSemver)) { pushError(reporter.lang('incompatibleEngine', name, range, VERSIONS[name])); } } else if (ignore.indexOf(name) < 0) { reporter.warn("".concat(human, ": ").concat(reporter.lang('invalidEngine', name))); } } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } } if (didError) { throw new (_errors().MessageError)(reporter.lang('foundIncompatible')); } } function check(infos, config, ignoreEngines) { var _iterator3 = _createForOfIteratorHelper(infos), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var info = _step3.value; checkOne(info, config, ignoreEngines); } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } } function shouldCheckCpu(cpu, ignorePlatform) { return !ignorePlatform && Array.isArray(cpu) && cpu.length > 0; } function shouldCheckPlatform(os, ignorePlatform) { return !ignorePlatform && Array.isArray(os) && os.length > 0; } function shouldCheckEngines(engines, ignoreEngines) { return !ignoreEngines && (0, _typeof2()["default"])(engines) === 'object'; } function shouldCheck(manifest, options) { return shouldCheckCpu(manifest.cpu, options.ignorePlatform) || shouldCheckPlatform(manifest.os, options.ignorePlatform) || shouldCheckEngines(manifest.engines, options.ignoreEngines); } //# sourceMappingURL=package-compatibility.js.map