index.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. let clonedApi;
  26. for (const name of Object.keys(apiPolyfills)) {
  27. if (api[name]) continue;
  28. clonedApi != null ? clonedApi : clonedApi = copyApiObject(api);
  29. clonedApi[name] = apiPolyfills[name](clonedApi);
  30. }
  31. return builder(clonedApi != null ? clonedApi : api, options || {}, dirname);
  32. };
  33. }
  34. const declarePreset = exports.declarePreset = declare;
  35. function copyApiObject(api) {
  36. let proto = null;
  37. if (typeof api.version === "string" && /^7\./.test(api.version)) {
  38. proto = Object.getPrototypeOf(api);
  39. if (proto && (!hasOwnProperty.call(proto, "version") || !hasOwnProperty.call(proto, "transform") || !hasOwnProperty.call(proto, "template") || !hasOwnProperty.call(proto, "types"))) {
  40. proto = null;
  41. }
  42. }
  43. return Object.assign({}, proto, api);
  44. }
  45. function throwVersionError(range, version) {
  46. if (typeof range === "number") {
  47. if (!Number.isInteger(range)) {
  48. throw new Error("Expected string or integer value.");
  49. }
  50. range = `^${range}.0.0-0`;
  51. }
  52. if (typeof range !== "string") {
  53. throw new Error("Expected string or integer value.");
  54. }
  55. const limit = Error.stackTraceLimit;
  56. if (typeof limit === "number" && limit < 25) {
  57. Error.stackTraceLimit = 25;
  58. }
  59. let err;
  60. if (version.slice(0, 2) === "7.") {
  61. err = new Error(`Requires Babel "^7.0.0-beta.41", but was loaded with "${version}". ` + `You'll need to update your @babel/core version.`);
  62. } else {
  63. 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.`);
  64. }
  65. if (typeof limit === "number") {
  66. Error.stackTraceLimit = limit;
  67. }
  68. throw Object.assign(err, {
  69. code: "BABEL_VERSION_UNSUPPORTED",
  70. version,
  71. range
  72. });
  73. }
  74. //# sourceMappingURL=index.js.map