index.js 2.5 KB

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