You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

4 years ago
  1. "use strict";
  2. const babel = require("@babel/core");
  3. module.exports = function injectCaller(opts) {
  4. if (!supportsCallerOption()) return opts;
  5. return Object.assign({}, opts, {
  6. caller: Object.assign({
  7. name: "babel-loader",
  8. // Webpack >= 2 supports ESM and dynamic import.
  9. supportsStaticESM: true,
  10. supportsDynamicImport: true
  11. }, opts.caller)
  12. });
  13. }; // TODO: We can remove this eventually, I'm just adding it so that people have
  14. // a little time to migrate to the newer RCs of @babel/core without getting
  15. // hard-to-diagnose errors about unknown 'caller' options.
  16. let supportsCallerOptionFlag = undefined;
  17. function supportsCallerOption() {
  18. if (supportsCallerOptionFlag === undefined) {
  19. try {
  20. // Rather than try to match the Babel version, we just see if it throws
  21. // when passed a 'caller' flag, and use that to decide if it is supported.
  22. babel.loadPartialConfig({
  23. caller: undefined,
  24. babelrc: false,
  25. configFile: false
  26. });
  27. supportsCallerOptionFlag = true;
  28. } catch (err) {
  29. supportsCallerOptionFlag = false;
  30. }
  31. }
  32. return supportsCallerOptionFlag;
  33. }