index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.declare = declare;
  6. exports.declarePreset = void 0;
  7. const apiPolyfills = {
  8. assertVersion: api => range => {
  9. throwVersionError(range, api.version);
  10. }
  11. };
  12. {
  13. Object.assign(apiPolyfills, {
  14. targets: () => () => {
  15. return {};
  16. },
  17. assumption: () => () => {
  18. return undefined;
  19. },
  20. addExternalDependency: () => () => {}
  21. });
  22. }
  23. function declare(builder) {
  24. return (api, options, dirname) => {
  25. var _clonedApi2;
  26. let clonedApi;
  27. for (const name of Object.keys(apiPolyfills)) {
  28. var _clonedApi;
  29. if (api[name]) continue;
  30. (_clonedApi = clonedApi) != null ? _clonedApi : clonedApi = copyApiObject(api);
  31. clonedApi[name] = apiPolyfills[name](clonedApi);
  32. }
  33. return builder((_clonedApi2 = clonedApi) != null ? _clonedApi2 : api, options || {}, dirname);
  34. };
  35. }
  36. const declarePreset = exports.declarePreset = declare;
  37. function copyApiObject(api) {
  38. let proto = null;
  39. if (typeof api.version === "string" && /^7\./.test(api.version)) {
  40. proto = Object.getPrototypeOf(api);
  41. if (proto && (!hasOwnProperty.call(proto, "version") || !hasOwnProperty.call(proto, "transform") || !hasOwnProperty.call(proto, "template") || !hasOwnProperty.call(proto, "types"))) {
  42. proto = null;
  43. }
  44. }
  45. return Object.assign({}, proto, api);
  46. }
  47. function throwVersionError(range, version) {
  48. if (typeof range === "number") {
  49. if (!Number.isInteger(range)) {
  50. throw new Error("Expected string or integer value.");
  51. }
  52. range = `^${range}.0.0-0`;
  53. }
  54. if (typeof range !== "string") {
  55. throw new Error("Expected string or integer value.");
  56. }
  57. const limit = Error.stackTraceLimit;
  58. if (typeof limit === "number" && limit < 25) {
  59. Error.stackTraceLimit = 25;
  60. }
  61. let err;
  62. if (version.slice(0, 2) === "7.") {
  63. err = new Error(`Requires Babel "^7.0.0-beta.41", but was loaded with "${version}". ` + `You'll need to update your @babel/core version.`);
  64. } else {
  65. err = new Error(`Requires Babel "${range}", but was loaded with "${version}". ` + `If you are sure you have a compatible version of @babel/core, ` + `it is likely that something in your build process is loading the ` + `wrong version. Inspect the stack trace of this error to look for ` + `the first entry that doesn't mention "@babel/core" or "babel-core" ` + `to see what is calling Babel.`);
  66. }
  67. if (typeof limit === "number") {
  68. Error.stackTraceLimit = limit;
  69. }
  70. throw Object.assign(err, {
  71. code: "BABEL_VERSION_UNSUPPORTED",
  72. version,
  73. range
  74. });
  75. }
  76. //# sourceMappingURL=index.js.map