1 | "use strict";
|
---|
2 |
|
---|
3 | const babel = require("@babel/core");
|
---|
4 |
|
---|
5 | module.exports = function injectCaller(opts, target) {
|
---|
6 | if (!supportsCallerOption()) return opts;
|
---|
7 | return Object.assign({}, opts, {
|
---|
8 | caller: Object.assign({
|
---|
9 | name: "babel-loader",
|
---|
10 | // Provide plugins with insight into webpack target.
|
---|
11 | // https://github.com/babel/babel-loader/issues/787
|
---|
12 | target,
|
---|
13 | // Webpack >= 2 supports ESM and dynamic import.
|
---|
14 | supportsStaticESM: true,
|
---|
15 | supportsDynamicImport: true,
|
---|
16 | // Webpack 5 supports TLA behind a flag. We enable it by default
|
---|
17 | // for Babel, and then webpack will throw an error if the experimental
|
---|
18 | // flag isn't enabled.
|
---|
19 | supportsTopLevelAwait: true
|
---|
20 | }, opts.caller)
|
---|
21 | });
|
---|
22 | }; // TODO: We can remove this eventually, I'm just adding it so that people have
|
---|
23 | // a little time to migrate to the newer RCs of @babel/core without getting
|
---|
24 | // hard-to-diagnose errors about unknown 'caller' options.
|
---|
25 |
|
---|
26 |
|
---|
27 | let supportsCallerOptionFlag = undefined;
|
---|
28 |
|
---|
29 | function supportsCallerOption() {
|
---|
30 | if (supportsCallerOptionFlag === undefined) {
|
---|
31 | try {
|
---|
32 | // Rather than try to match the Babel version, we just see if it throws
|
---|
33 | // when passed a 'caller' flag, and use that to decide if it is supported.
|
---|
34 | babel.loadPartialConfig({
|
---|
35 | caller: undefined,
|
---|
36 | babelrc: false,
|
---|
37 | configFile: false
|
---|
38 | });
|
---|
39 | supportsCallerOptionFlag = true;
|
---|
40 | } catch (err) {
|
---|
41 | supportsCallerOptionFlag = false;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | return supportsCallerOptionFlag;
|
---|
46 | } |
---|