babel-loader 8.2.5 → 9.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- > This README is for babel-loader v8 + Babel v7
1
+ > This README is for babel-loader v8/v9 with Babel v7
2
2
  > If you are using legacy Babel v6, see the [7.x branch](https://github.com/babel/babel-loader/tree/7.x) docs
3
3
 
4
4
  [![NPM Status](https://img.shields.io/npm/v/babel-loader.svg?style=flat)](https://www.npmjs.com/package/babel-loader)
@@ -21,7 +21,11 @@ This package allows transpiling JavaScript files using [Babel](https://github.co
21
21
 
22
22
  <h2 align="center">Install</h2>
23
23
 
24
- > webpack `4.x || 5.x` | babel-loader 8.x | babel 7.x
24
+ > | babel-loader | supported webpack versions | supported Babel versions | supported Node.js versions |
25
+ > |:-:|:-:|:-:|:-:|
26
+ > | 8.x | 4.x or 5.x | 7.x | >= 8.9 |
27
+ > | 9.x | 5.x | ^7.12.0 | >= 14.15.0 |
28
+
25
29
 
26
30
  ```bash
27
31
  npm install -D babel-loader @babel/core @babel/preset-env webpack
package/lib/Error.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  const STRIP_FILENAME_RE = /^[^:]+: /;
4
-
5
4
  const format = err => {
6
5
  if (err instanceof SyntaxError) {
7
6
  err.name = "SyntaxError";
@@ -12,10 +11,8 @@ const format = err => {
12
11
  err.message = err.message.replace(STRIP_FILENAME_RE, "");
13
12
  err.hideStack = true;
14
13
  }
15
-
16
14
  return err;
17
15
  };
18
-
19
16
  class LoaderError extends Error {
20
17
  constructor(err) {
21
18
  super();
@@ -30,7 +27,5 @@ class LoaderError extends Error {
30
27
  this.hideStack = hideStack;
31
28
  Error.captureStackTrace(this, this.constructor);
32
29
  }
33
-
34
30
  }
35
-
36
31
  module.exports = LoaderError;
package/lib/cache.js CHANGED
@@ -1,9 +1,5 @@
1
1
  "use strict";
2
2
 
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
7
3
  /**
8
4
  * Filesystem Cache
9
5
  *
@@ -13,40 +9,32 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
13
9
  * @see https://github.com/babel/babel-loader/issues/34
14
10
  * @see https://github.com/babel/babel-loader/pull/41
15
11
  */
16
- const fs = require("fs");
17
-
18
12
  const os = require("os");
19
-
20
13
  const path = require("path");
21
-
22
14
  const zlib = require("zlib");
23
-
24
15
  const crypto = require("crypto");
25
-
26
16
  const findCacheDir = require("find-cache-dir");
27
-
28
17
  const {
29
18
  promisify
30
19
  } = require("util");
31
-
32
- const transform = require("./transform"); // Lazily instantiated when needed
33
-
34
-
20
+ const {
21
+ readFile,
22
+ writeFile,
23
+ mkdir
24
+ } = require("fs/promises");
25
+ const transform = require("./transform");
26
+ // Lazily instantiated when needed
35
27
  let defaultCacheDirectory = null;
36
- let hashType = "md4"; // use md5 hashing if md4 is not available
37
-
28
+ let hashType = "sha256";
29
+ // use md5 hashing if sha256 is not available
38
30
  try {
39
31
  crypto.createHash(hashType);
40
32
  } catch (err) {
41
33
  hashType = "md5";
42
34
  }
43
-
44
- const readFile = promisify(fs.readFile);
45
- const writeFile = promisify(fs.writeFile);
46
35
  const gunzip = promisify(zlib.gunzip);
47
36
  const gzip = promisify(zlib.gzip);
48
37
 
49
- const makeDir = require("make-dir");
50
38
  /**
51
39
  * Read the contents from the compressed file.
52
40
  *
@@ -54,19 +42,12 @@ const makeDir = require("make-dir");
54
42
  * @params {String} filename
55
43
  * @params {Boolean} compress
56
44
  */
45
+ const read = async function (filename, compress) {
46
+ const data = await readFile(filename + (compress ? ".gz" : ""));
47
+ const content = compress ? await gunzip(data) : data;
48
+ return JSON.parse(content.toString());
49
+ };
57
50
 
58
-
59
- const read = /*#__PURE__*/function () {
60
- var _ref = _asyncToGenerator(function* (filename, compress) {
61
- const data = yield readFile(filename + (compress ? ".gz" : ""));
62
- const content = compress ? yield gunzip(data) : data;
63
- return JSON.parse(content.toString());
64
- });
65
-
66
- return function read(_x, _x2) {
67
- return _ref.apply(this, arguments);
68
- };
69
- }();
70
51
  /**
71
52
  * Write contents into a compressed file.
72
53
  *
@@ -75,19 +56,12 @@ const read = /*#__PURE__*/function () {
75
56
  * @params {Boolean} compress
76
57
  * @params {String} result
77
58
  */
59
+ const write = async function (filename, compress, result) {
60
+ const content = JSON.stringify(result);
61
+ const data = compress ? await gzip(content) : content;
62
+ return await writeFile(filename + (compress ? ".gz" : ""), data);
63
+ };
78
64
 
79
-
80
- const write = /*#__PURE__*/function () {
81
- var _ref2 = _asyncToGenerator(function* (filename, compress, result) {
82
- const content = JSON.stringify(result);
83
- const data = compress ? yield gzip(content) : content;
84
- return yield writeFile(filename + (compress ? ".gz" : ""), data);
85
- });
86
-
87
- return function write(_x3, _x4, _x5) {
88
- return _ref2.apply(this, arguments);
89
- };
90
- }();
91
65
  /**
92
66
  * Build the filename for the cached file
93
67
  *
@@ -96,8 +70,6 @@ const write = /*#__PURE__*/function () {
96
70
  *
97
71
  * @return {String}
98
72
  */
99
-
100
-
101
73
  const filename = function (source, identifier, options) {
102
74
  const hash = crypto.createHash(hashType);
103
75
  const contents = JSON.stringify({
@@ -108,65 +80,57 @@ const filename = function (source, identifier, options) {
108
80
  hash.update(contents);
109
81
  return hash.digest("hex") + ".json";
110
82
  };
83
+
111
84
  /**
112
85
  * Handle the cache
113
86
  *
114
87
  * @params {String} directory
115
88
  * @params {Object} params
116
89
  */
117
-
118
-
119
- const handleCache = /*#__PURE__*/function () {
120
- var _ref3 = _asyncToGenerator(function* (directory, params) {
121
- const {
122
- source,
123
- options = {},
124
- cacheIdentifier,
125
- cacheDirectory,
126
- cacheCompression
127
- } = params;
128
- const file = path.join(directory, filename(source, cacheIdentifier, options));
129
-
130
- try {
131
- // No errors mean that the file was previously cached
132
- // we just need to return it
133
- return yield read(file, cacheCompression);
134
- } catch (err) {}
135
-
136
- const fallback = typeof cacheDirectory !== "string" && directory !== os.tmpdir(); // Make sure the directory exists.
137
-
138
- try {
139
- yield makeDir(directory);
140
- } catch (err) {
141
- if (fallback) {
142
- return handleCache(os.tmpdir(), params);
143
- }
144
-
145
- throw err;
146
- } // Otherwise just transform the file
147
- // return it to the user asap and write it in cache
148
-
149
-
150
- const result = yield transform(source, options);
151
-
152
- try {
153
- yield write(file, cacheCompression, result);
154
- } catch (err) {
155
- if (fallback) {
156
- // Fallback to tmpdir if node_modules folder not writable
157
- return handleCache(os.tmpdir(), params);
158
- }
159
-
160
- throw err;
90
+ const handleCache = async function (directory, params) {
91
+ const {
92
+ source,
93
+ options = {},
94
+ cacheIdentifier,
95
+ cacheDirectory,
96
+ cacheCompression
97
+ } = params;
98
+ const file = path.join(directory, filename(source, cacheIdentifier, options));
99
+ try {
100
+ // No errors mean that the file was previously cached
101
+ // we just need to return it
102
+ return await read(file, cacheCompression);
103
+ } catch (err) {}
104
+ const fallback = typeof cacheDirectory !== "string" && directory !== os.tmpdir();
105
+
106
+ // Make sure the directory exists.
107
+ try {
108
+ // overwrite directory if exists
109
+ await mkdir(directory, {
110
+ recursive: true
111
+ });
112
+ } catch (err) {
113
+ if (fallback) {
114
+ return handleCache(os.tmpdir(), params);
161
115
  }
116
+ throw err;
117
+ }
118
+
119
+ // Otherwise just transform the file
120
+ // return it to the user asap and write it in cache
121
+ const result = await transform(source, options);
122
+ try {
123
+ await write(file, cacheCompression, result);
124
+ } catch (err) {
125
+ if (fallback) {
126
+ // Fallback to tmpdir if node_modules folder not writable
127
+ return handleCache(os.tmpdir(), params);
128
+ }
129
+ throw err;
130
+ }
131
+ return result;
132
+ };
162
133
 
163
- return result;
164
- });
165
-
166
- return function handleCache(_x6, _x7) {
167
- return _ref3.apply(this, arguments);
168
- };
169
- }();
170
134
  /**
171
135
  * Retrieve file from cache, or create a new one for future reads
172
136
  *
@@ -192,27 +156,17 @@ const handleCache = /*#__PURE__*/function () {
192
156
  * });
193
157
  */
194
158
 
195
-
196
- module.exports = /*#__PURE__*/function () {
197
- var _ref4 = _asyncToGenerator(function* (params) {
198
- let directory;
199
-
200
- if (typeof params.cacheDirectory === "string") {
201
- directory = params.cacheDirectory;
202
- } else {
203
- if (defaultCacheDirectory === null) {
204
- defaultCacheDirectory = findCacheDir({
205
- name: "babel-loader"
206
- }) || os.tmpdir();
207
- }
208
-
209
- directory = defaultCacheDirectory;
159
+ module.exports = async function (params) {
160
+ let directory;
161
+ if (typeof params.cacheDirectory === "string") {
162
+ directory = params.cacheDirectory;
163
+ } else {
164
+ if (defaultCacheDirectory === null) {
165
+ defaultCacheDirectory = findCacheDir({
166
+ name: "babel-loader"
167
+ }) || os.tmpdir();
210
168
  }
211
-
212
- return yield handleCache(directory, params);
213
- });
214
-
215
- return function (_x8) {
216
- return _ref4.apply(this, arguments);
217
- };
218
- }();
169
+ directory = defaultCacheDirectory;
170
+ }
171
+ return await handleCache(directory, params);
172
+ };
package/lib/index.js CHANGED
@@ -1,56 +1,38 @@
1
1
  "use strict";
2
2
 
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
7
3
  let babel;
8
-
9
4
  try {
10
5
  babel = require("@babel/core");
11
6
  } catch (err) {
12
7
  if (err.code === "MODULE_NOT_FOUND") {
13
- err.message += "\n babel-loader@8 requires Babel 7.x (the package '@babel/core'). " + "If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'.";
8
+ err.message += "\n babel-loader@9 requires Babel 7.12+ (the package '@babel/core'). " + "If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'.";
14
9
  }
15
-
16
10
  throw err;
17
- } // Since we've got the reverse bridge package at @babel/core@6.x, give
18
- // people useful feedback if they try to use it alongside babel-loader.
19
-
11
+ }
20
12
 
13
+ // Since we've got the reverse bridge package at @babel/core@6.x, give
14
+ // people useful feedback if they try to use it alongside babel-loader.
21
15
  if (/^6\./.test(babel.version)) {
22
- throw new Error("\n babel-loader@8 will not work with the '@babel/core@6' bridge package. " + "If you want to use Babel 6.x, install 'babel-loader@7'.");
16
+ throw new Error("\n babel-loader@9 will not work with the '@babel/core@6' bridge package. " + "If you want to use Babel 6.x, install 'babel-loader@7'.");
23
17
  }
24
-
25
18
  const {
26
19
  version
27
20
  } = require("../package.json");
28
-
29
21
  const cache = require("./cache");
30
-
31
22
  const transform = require("./transform");
32
-
33
23
  const injectCaller = require("./injectCaller");
34
-
35
24
  const schema = require("./schema");
36
-
37
25
  const {
38
26
  isAbsolute
39
27
  } = require("path");
40
-
41
- const loaderUtils = require("loader-utils");
42
-
43
- const validateOptions = require("schema-utils");
44
-
28
+ const validateOptions = require("schema-utils").validate;
45
29
  function subscribe(subscriber, metadata, context) {
46
30
  if (context[subscriber]) {
47
31
  context[subscriber](metadata);
48
32
  }
49
33
  }
50
-
51
34
  module.exports = makeLoader();
52
35
  module.exports.custom = makeLoader;
53
-
54
36
  function makeLoader(callback) {
55
37
  const overrides = callback ? callback(babel) : undefined;
56
38
  return function (source, inputSourceMap) {
@@ -59,188 +41,138 @@ function makeLoader(callback) {
59
41
  loader.call(this, source, inputSourceMap, overrides).then(args => callback(null, ...args), err => callback(err));
60
42
  };
61
43
  }
62
-
63
- function loader(_x, _x2, _x3) {
64
- return _loader.apply(this, arguments);
65
- }
66
-
67
- function _loader() {
68
- _loader = _asyncToGenerator(function* (source, inputSourceMap, overrides) {
69
- const filename = this.resourcePath;
70
- let loaderOptions = loaderUtils.getOptions(this);
71
- validateOptions(schema, loaderOptions, {
72
- name: "Babel loader"
73
- });
74
-
75
- if (loaderOptions.customize != null) {
76
- if (typeof loaderOptions.customize !== "string") {
77
- throw new Error("Customized loaders must be implemented as standalone modules.");
78
- }
79
-
80
- if (!isAbsolute(loaderOptions.customize)) {
81
- throw new Error("Customized loaders must be passed as absolute paths, since " + "babel-loader has no way to know what they would be relative to.");
82
- }
83
-
84
- if (overrides) {
85
- throw new Error("babel-loader's 'customize' option is not available when already " + "using a customized babel-loader wrapper.");
86
- }
87
-
88
- let override = require(loaderOptions.customize);
89
-
90
- if (override.__esModule) override = override.default;
91
-
92
- if (typeof override !== "function") {
93
- throw new Error("Custom overrides must be functions.");
94
- }
95
-
96
- overrides = override(babel);
44
+ async function loader(source, inputSourceMap, overrides) {
45
+ const filename = this.resourcePath;
46
+ let loaderOptions = this.getOptions();
47
+ validateOptions(schema, loaderOptions, {
48
+ name: "Babel loader"
49
+ });
50
+ if (loaderOptions.customize != null) {
51
+ if (typeof loaderOptions.customize !== "string") {
52
+ throw new Error("Customized loaders must be implemented as standalone modules.");
53
+ }
54
+ if (!isAbsolute(loaderOptions.customize)) {
55
+ throw new Error("Customized loaders must be passed as absolute paths, since " + "babel-loader has no way to know what they would be relative to.");
97
56
  }
57
+ if (overrides) {
58
+ throw new Error("babel-loader's 'customize' option is not available when already " + "using a customized babel-loader wrapper.");
59
+ }
60
+ let override = require(loaderOptions.customize);
61
+ if (override.__esModule) override = override.default;
62
+ if (typeof override !== "function") {
63
+ throw new Error("Custom overrides must be functions.");
64
+ }
65
+ overrides = override(babel);
66
+ }
67
+ let customOptions;
68
+ if (overrides && overrides.customOptions) {
69
+ const result = await overrides.customOptions.call(this, loaderOptions, {
70
+ source,
71
+ map: inputSourceMap
72
+ });
73
+ customOptions = result.custom;
74
+ loaderOptions = result.loader;
75
+ }
98
76
 
99
- let customOptions;
77
+ // Deprecation handling
78
+ if ("forceEnv" in loaderOptions) {
79
+ console.warn("The option `forceEnv` has been removed in favor of `envName` in Babel 7.");
80
+ }
81
+ if (typeof loaderOptions.babelrc === "string") {
82
+ console.warn("The option `babelrc` should not be set to a string anymore in the babel-loader config. " + "Please update your configuration and set `babelrc` to true or false.\n" + "If you want to specify a specific babel config file to inherit config from " + "please use the `extends` option.\nFor more information about this options see " + "https://babeljs.io/docs/core-packages/#options");
83
+ }
100
84
 
101
- if (overrides && overrides.customOptions) {
102
- const result = yield overrides.customOptions.call(this, loaderOptions, {
85
+ // Standardize on 'sourceMaps' as the key passed through to Webpack, so that
86
+ // users may safely use either one alongside our default use of
87
+ // 'this.sourceMap' below without getting error about conflicting aliases.
88
+ if (Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMap") && !Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMaps")) {
89
+ loaderOptions = Object.assign({}, loaderOptions, {
90
+ sourceMaps: loaderOptions.sourceMap
91
+ });
92
+ delete loaderOptions.sourceMap;
93
+ }
94
+ const programmaticOptions = Object.assign({}, loaderOptions, {
95
+ filename,
96
+ inputSourceMap: inputSourceMap || loaderOptions.inputSourceMap,
97
+ // Set the default sourcemap behavior based on Webpack's mapping flag,
98
+ // but allow users to override if they want.
99
+ sourceMaps: loaderOptions.sourceMaps === undefined ? this.sourceMap : loaderOptions.sourceMaps,
100
+ // Ensure that Webpack will get a full absolute path in the sourcemap
101
+ // so that it can properly map the module back to its internal cached
102
+ // modules.
103
+ sourceFileName: filename
104
+ });
105
+ // Remove loader related options
106
+ delete programmaticOptions.customize;
107
+ delete programmaticOptions.cacheDirectory;
108
+ delete programmaticOptions.cacheIdentifier;
109
+ delete programmaticOptions.cacheCompression;
110
+ delete programmaticOptions.metadataSubscribers;
111
+ const config = await babel.loadPartialConfigAsync(injectCaller(programmaticOptions, this.target));
112
+ if (config) {
113
+ let options = config.options;
114
+ if (overrides && overrides.config) {
115
+ options = await overrides.config.call(this, config, {
103
116
  source,
104
- map: inputSourceMap
117
+ map: inputSourceMap,
118
+ customOptions
105
119
  });
106
- customOptions = result.custom;
107
- loaderOptions = result.loader;
108
- } // Deprecation handling
109
-
110
-
111
- if ("forceEnv" in loaderOptions) {
112
- console.warn("The option `forceEnv` has been removed in favor of `envName` in Babel 7.");
113
120
  }
114
-
115
- if (typeof loaderOptions.babelrc === "string") {
116
- console.warn("The option `babelrc` should not be set to a string anymore in the babel-loader config. " + "Please update your configuration and set `babelrc` to true or false.\n" + "If you want to specify a specific babel config file to inherit config from " + "please use the `extends` option.\nFor more information about this options see " + "https://babeljs.io/docs/core-packages/#options");
117
- } // Standardize on 'sourceMaps' as the key passed through to Webpack, so that
118
- // users may safely use either one alongside our default use of
119
- // 'this.sourceMap' below without getting error about conflicting aliases.
120
-
121
-
122
- if (Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMap") && !Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMaps")) {
123
- loaderOptions = Object.assign({}, loaderOptions, {
124
- sourceMaps: loaderOptions.sourceMap
125
- });
126
- delete loaderOptions.sourceMap;
121
+ if (options.sourceMaps === "inline") {
122
+ // Babel has this weird behavior where if you set "inline", we
123
+ // inline the sourcemap, and set 'result.map = null'. This results
124
+ // in bad behavior from Babel since the maps get put into the code,
125
+ // which Webpack does not expect, and because the map we return to
126
+ // Webpack is null, which is also bad. To avoid that, we override the
127
+ // behavior here so "inline" just behaves like 'true'.
128
+ options.sourceMaps = true;
127
129
  }
128
-
129
- const programmaticOptions = Object.assign({}, loaderOptions, {
130
- filename,
131
- inputSourceMap: inputSourceMap || loaderOptions.inputSourceMap,
132
- // Set the default sourcemap behavior based on Webpack's mapping flag,
133
- // but allow users to override if they want.
134
- sourceMaps: loaderOptions.sourceMaps === undefined ? this.sourceMap : loaderOptions.sourceMaps,
135
- // Ensure that Webpack will get a full absolute path in the sourcemap
136
- // so that it can properly map the module back to its internal cached
137
- // modules.
138
- sourceFileName: filename
139
- }); // Remove loader related options
140
-
141
- delete programmaticOptions.customize;
142
- delete programmaticOptions.cacheDirectory;
143
- delete programmaticOptions.cacheIdentifier;
144
- delete programmaticOptions.cacheCompression;
145
- delete programmaticOptions.metadataSubscribers;
146
-
147
- if (!babel.loadPartialConfig) {
148
- throw new Error(`babel-loader ^8.0.0-beta.3 requires @babel/core@7.0.0-beta.41, but ` + `you appear to be using "${babel.version}". Either update your ` + `@babel/core version, or pin you babel-loader version to 8.0.0-beta.2`);
149
- } // babel.loadPartialConfigAsync is available in v7.8.0+
150
-
151
-
152
130
  const {
153
- loadPartialConfigAsync = babel.loadPartialConfig
154
- } = babel;
155
- const config = yield loadPartialConfigAsync(injectCaller(programmaticOptions, this.target));
156
-
157
- if (config) {
158
- let options = config.options;
159
-
160
- if (overrides && overrides.config) {
161
- options = yield overrides.config.call(this, config, {
131
+ cacheDirectory = null,
132
+ cacheIdentifier = JSON.stringify({
133
+ options,
134
+ "@babel/core": transform.version,
135
+ "@babel/loader": version
136
+ }),
137
+ cacheCompression = true,
138
+ metadataSubscribers = []
139
+ } = loaderOptions;
140
+ let result;
141
+ if (cacheDirectory) {
142
+ result = await cache({
143
+ source,
144
+ options,
145
+ transform,
146
+ cacheDirectory,
147
+ cacheIdentifier,
148
+ cacheCompression
149
+ });
150
+ } else {
151
+ result = await transform(source, options);
152
+ }
153
+ config.files.forEach(configFile => this.addDependency(configFile));
154
+ if (result) {
155
+ if (overrides && overrides.result) {
156
+ result = await overrides.result.call(this, result, {
162
157
  source,
163
158
  map: inputSourceMap,
164
- customOptions
159
+ customOptions,
160
+ config,
161
+ options
165
162
  });
166
163
  }
167
-
168
- if (options.sourceMaps === "inline") {
169
- // Babel has this weird behavior where if you set "inline", we
170
- // inline the sourcemap, and set 'result.map = null'. This results
171
- // in bad behavior from Babel since the maps get put into the code,
172
- // which Webpack does not expect, and because the map we return to
173
- // Webpack is null, which is also bad. To avoid that, we override the
174
- // behavior here so "inline" just behaves like 'true'.
175
- options.sourceMaps = true;
176
- }
177
-
178
164
  const {
179
- cacheDirectory = null,
180
- cacheIdentifier = JSON.stringify({
181
- options,
182
- "@babel/core": transform.version,
183
- "@babel/loader": version
184
- }),
185
- cacheCompression = true,
186
- metadataSubscribers = []
187
- } = loaderOptions;
188
- let result;
189
-
190
- if (cacheDirectory) {
191
- result = yield cache({
192
- source,
193
- options,
194
- transform,
195
- cacheDirectory,
196
- cacheIdentifier,
197
- cacheCompression
198
- });
199
- } else {
200
- result = yield transform(source, options);
201
- } // Availabe since Babel 7.12
202
- // https://github.com/babel/babel/pull/11907
203
-
204
-
205
- if (config.files) {
206
- config.files.forEach(configFile => this.addDependency(configFile));
207
- } else {
208
- // .babelrc.json
209
- if (typeof config.babelrc === "string") {
210
- this.addDependency(config.babelrc);
211
- } // babel.config.js
212
-
213
-
214
- if (config.config) {
215
- this.addDependency(config.config);
216
- }
217
- }
218
-
219
- if (result) {
220
- if (overrides && overrides.result) {
221
- result = yield overrides.result.call(this, result, {
222
- source,
223
- map: inputSourceMap,
224
- customOptions,
225
- config,
226
- options
227
- });
228
- }
229
-
230
- const {
231
- code,
232
- map,
233
- metadata
234
- } = result;
235
- metadataSubscribers.forEach(subscriber => {
236
- subscribe(subscriber, metadata, this);
237
- });
238
- return [code, map];
239
- }
240
- } // If the file was ignored, pass through the original content.
241
-
165
+ code,
166
+ map,
167
+ metadata
168
+ } = result;
169
+ metadataSubscribers.forEach(subscriber => {
170
+ subscribe(subscriber, metadata, this);
171
+ });
172
+ return [code, map];
173
+ }
174
+ }
242
175
 
243
- return [source, inputSourceMap];
244
- });
245
- return _loader.apply(this, arguments);
176
+ // If the file was ignored, pass through the original content.
177
+ return [source, inputSourceMap];
246
178
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  const babel = require("@babel/core");
4
-
5
4
  module.exports = function injectCaller(opts, target) {
6
5
  if (!supportsCallerOption()) return opts;
7
6
  return Object.assign({}, opts, {
@@ -19,13 +18,12 @@ module.exports = function injectCaller(opts, target) {
19
18
  supportsTopLevelAwait: true
20
19
  }, opts.caller)
21
20
  });
22
- }; // TODO: We can remove this eventually, I'm just adding it so that people have
21
+ };
22
+
23
+ // TODO: We can remove this eventually, I'm just adding it so that people have
23
24
  // a little time to migrate to the newer RCs of @babel/core without getting
24
25
  // hard-to-diagnose errors about unknown 'caller' options.
25
-
26
-
27
26
  let supportsCallerOptionFlag = undefined;
28
-
29
27
  function supportsCallerOption() {
30
28
  if (supportsCallerOptionFlag === undefined) {
31
29
  try {
@@ -41,6 +39,5 @@ function supportsCallerOption() {
41
39
  supportsCallerOptionFlag = false;
42
40
  }
43
41
  }
44
-
45
42
  return supportsCallerOptionFlag;
46
43
  }
package/lib/transform.js CHANGED
@@ -1,59 +1,41 @@
1
1
  "use strict";
2
2
 
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
7
3
  const babel = require("@babel/core");
8
-
9
4
  const {
10
5
  promisify
11
6
  } = require("util");
12
-
13
7
  const LoaderError = require("./Error");
14
-
15
8
  const transform = promisify(babel.transform);
16
-
17
- module.exports = /*#__PURE__*/function () {
18
- var _ref = _asyncToGenerator(function* (source, options) {
19
- let result;
20
-
21
- try {
22
- result = yield transform(source, options);
23
- } catch (err) {
24
- throw err.message && err.codeFrame ? new LoaderError(err) : err;
25
- }
26
-
27
- if (!result) return null; // We don't return the full result here because some entries are not
28
- // really serializable. For a full list of properties see here:
29
- // https://github.com/babel/babel/blob/main/packages/babel-core/src/transformation/index.js
30
- // For discussion on this topic see here:
31
- // https://github.com/babel/babel-loader/pull/629
32
-
33
- const {
34
- ast,
35
- code,
36
- map,
37
- metadata,
38
- sourceType
39
- } = result;
40
-
41
- if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
42
- map.sourcesContent = [source];
43
- }
44
-
45
- return {
46
- ast,
47
- code,
48
- map,
49
- metadata,
50
- sourceType
51
- };
52
- });
53
-
54
- return function (_x, _x2) {
55
- return _ref.apply(this, arguments);
9
+ module.exports = async function (source, options) {
10
+ let result;
11
+ try {
12
+ result = await transform(source, options);
13
+ } catch (err) {
14
+ throw err.message && err.codeFrame ? new LoaderError(err) : err;
15
+ }
16
+ if (!result) return null;
17
+
18
+ // We don't return the full result here because some entries are not
19
+ // really serializable. For a full list of properties see here:
20
+ // https://github.com/babel/babel/blob/main/packages/babel-core/src/transformation/index.js
21
+ // For discussion on this topic see here:
22
+ // https://github.com/babel/babel-loader/pull/629
23
+ const {
24
+ ast,
25
+ code,
26
+ map,
27
+ metadata,
28
+ sourceType
29
+ } = result;
30
+ if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
31
+ map.sourcesContent = [source];
32
+ }
33
+ return {
34
+ ast,
35
+ code,
36
+ map,
37
+ metadata,
38
+ sourceType
56
39
  };
57
- }();
58
-
40
+ };
59
41
  module.exports.version = babel.version;
package/package.json CHANGED
@@ -1,33 +1,31 @@
1
1
  {
2
2
  "name": "babel-loader",
3
- "version": "8.2.5",
3
+ "version": "9.0.1",
4
4
  "description": "babel module loader for webpack",
5
5
  "files": [
6
6
  "lib"
7
7
  ],
8
8
  "main": "lib/index.js",
9
9
  "engines": {
10
- "node": ">= 8.9"
10
+ "node": ">= 14.15.0"
11
11
  },
12
12
  "dependencies": {
13
- "find-cache-dir": "^3.3.1",
14
- "loader-utils": "^2.0.0",
15
- "make-dir": "^3.1.0",
16
- "schema-utils": "^2.6.5"
13
+ "find-cache-dir": "^3.3.2",
14
+ "schema-utils": "^4.0.0"
17
15
  },
18
16
  "peerDependencies": {
19
- "@babel/core": "^7.0.0",
20
- "webpack": ">=2"
17
+ "@babel/core": "^7.12.0",
18
+ "webpack": ">=5"
21
19
  },
22
20
  "devDependencies": {
23
21
  "@ava/babel": "^1.0.1",
24
- "@babel/cli": "^7.12.1",
25
- "@babel/core": "^7.12.3",
26
- "@babel/preset-env": "^7.12.1",
22
+ "@babel/cli": "^7.19.3",
23
+ "@babel/core": "^7.19.6",
24
+ "@babel/preset-env": "^7.19.4",
27
25
  "ava": "^3.13.0",
28
- "babel-eslint": "^10.0.1",
29
- "babel-plugin-istanbul": "^6.0.0",
30
- "babel-plugin-react-intl": "^8.2.15",
26
+ "babel-eslint": "^10.1.0",
27
+ "babel-plugin-istanbul": "^6.1.1",
28
+ "babel-plugin-react-intl": "^8.2.25",
31
29
  "cross-env": "^7.0.2",
32
30
  "eslint": "^7.13.0",
33
31
  "eslint-config-babel": "^9.0.0",
@@ -120,5 +118,8 @@
120
118
  "node ./scripts/yarn-install.js",
121
119
  "git add yarn.lock"
122
120
  ]
121
+ },
122
+ "resolutions": {
123
+ "nyc/node-preload": "0.2.0"
123
124
  }
124
125
  }