get-modules-list-for-target-version.js 584 B

123456789101112131415161718
  1. 'use strict';
  2. const { compare, intersection, semver } = require('./helpers');
  3. const modulesByVersions = require('./modules-by-versions');
  4. const modules = require('./modules');
  5. module.exports = function (raw) {
  6. const corejs = semver(raw);
  7. if (corejs.major !== 3) {
  8. throw RangeError('This version of `core-js-compat` works only with `core-js@3`.');
  9. }
  10. const result = [];
  11. for (const version of Object.keys(modulesByVersions)) {
  12. if (compare(version, '<=', corejs)) {
  13. result.push(...modulesByVersions[version]);
  14. }
  15. }
  16. return intersection(result, modules);
  17. };