babel-loader 8.0.1 → 8.0.5

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,24 +1,25 @@
1
- > This readme is for babel-loader v8 + Babel v7
1
+ > This README is for babel-loader v8 + Babel v7
2
2
  > Check the [7.x branch](https://github.com/babel/babel-loader/tree/7.x) for docs with Babel v6
3
3
 
4
4
  [![NPM Status](https://img.shields.io/npm/v/babel-loader.svg?style=flat)](https://www.npmjs.com/package/babel-loader)
5
5
  [![Build Status](https://travis-ci.org/babel/babel-loader.svg?branch=master)](https://travis-ci.org/babel/babel-loader)
6
- [![Build Status](https://ci.appveyor.com/api/projects/status/vgtpr2i5bykgyuqo/branch/master?svg=true)](https://ci.appveyor.com/project/danez/babel-loader/branch/master)
6
+ [![Build Status](https://ci.appveyor.com/api/projects/status/77y5mk6amwqt0q88/branch/master?svg=true)](https://ci.appveyor.com/project/babel/babel-loader/branch/master)
7
7
  [![codecov](https://codecov.io/gh/babel/babel-loader/branch/master/graph/badge.svg)](https://codecov.io/gh/babel/babel-loader)
8
8
 
9
9
  <div align="center">
10
- <a href="https://github.com/babel/babel/">
11
- <img width="200" height="200" src="https://rawgit.com/babel/logo/master/babel.svg">
10
+ <a href="https://github.com/babel/babel">
11
+ <img src="https://rawgit.com/babel/logo/master/babel.svg" alt="Babel logo" width="200" height="200">
12
12
  </a>
13
13
  <a href="https://github.com/webpack/webpack">
14
- <img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg">
14
+ <img src="https://webpack.js.org/assets/icon-square-big.svg" alt="webpack logo" width="200" height="200">
15
15
  </a>
16
- <h1>Babel Loader</h1>
17
16
  </div>
18
17
 
18
+ <h1 align="center">Babel Loader</h1>
19
+
19
20
  This package allows transpiling JavaScript files using [Babel](https://github.com/babel/babel) and [webpack](https://github.com/webpack/webpack).
20
21
 
21
- __Notes:__ Issues with the output should be reported on the babel [issue tracker](https://github.com/babel/babel/issues).
22
+ **Note**: Issues with the output should be reported on the Babel [Issues](https://github.com/babel/babel/issues) tracker.
22
23
 
23
24
  <h2 align="center">Install</h2>
24
25
 
@@ -36,7 +37,7 @@ npm install -D babel-loader@7 babel-core babel-preset-env webpack
36
37
 
37
38
  <h2 align="center">Usage</h2>
38
39
 
39
- [Documentation: Using loaders](https://webpack.js.org/loaders/)
40
+ webpack documentation: [Loaders](https://webpack.js.org/loaders/)
40
41
 
41
42
  Within your webpack configuration object, you'll need to add the babel-loader to the list of modules, like so:
42
43
 
@@ -44,7 +45,7 @@ Within your webpack configuration object, you'll need to add the babel-loader to
44
45
  module: {
45
46
  rules: [
46
47
  {
47
- test: /\.js$/,
48
+ test: /\.m?js$/,
48
49
  exclude: /(node_modules|bower_components)/,
49
50
  use: {
50
51
  loader: 'babel-loader',
@@ -59,22 +60,21 @@ module: {
59
60
 
60
61
  ### Options
61
62
 
62
- See the `babel` [options](https://babeljs.io/docs/usage/api/#options).
63
-
63
+ See the `babel` [options](https://babeljs.io/docs/en/options).
64
64
 
65
- You can pass options to the loader by using the [options property](https://webpack.js.org/configuration/module/#rule-options-rule-query):
65
+ You can pass options to the loader by using the [`options`](https://webpack.js.org/configuration/module/#rule-options-rule-query) property:
66
66
 
67
67
  ```javascript
68
68
  module: {
69
69
  rules: [
70
70
  {
71
- test: /\.js$/,
71
+ test: /\.m?js$/,
72
72
  exclude: /(node_modules|bower_components)/,
73
73
  use: {
74
74
  loader: 'babel-loader',
75
75
  options: {
76
76
  presets: ['@babel/preset-env'],
77
- plugins: [require('@babel/plugin-proposal-object-rest-spread')]
77
+ plugins: ['@babel/plugin-proposal-object-rest-spread']
78
78
  }
79
79
  }
80
80
  }
@@ -84,45 +84,42 @@ module: {
84
84
 
85
85
  This loader also supports the following loader-specific option:
86
86
 
87
- * `cacheDirectory`: Default `false`. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is blank (`loader: 'babel-loader?cacheDirectory'`) or `true` (`loader: babel-loader?cacheDirectory=true`) the loader will use the default cache directory in `node_modules/.cache/babel-loader` or fallback to the default OS temporary file directory if no `node_modules` folder could be found in any root directory.
87
+ * `cacheDirectory`: Default `false`. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is blank (`loader: 'babel-loader?cacheDirectory'`) or `true` (`loader: 'babel-loader?cacheDirectory=true'`), the loader will use the default cache directory in `node_modules/.cache/babel-loader` or fallback to the default OS temporary file directory if no `node_modules` folder could be found in any root directory.
88
+
89
+ * `cacheIdentifier`: Default is a string composed by the `babel-core`'s version, the `babel-loader`'s version, the contents of `.babelrc` file if it exists, and the value of the environment variable `BABEL_ENV` with a fallback to the `NODE_ENV` environment variable. This can be set to a custom value to force cache busting if the identifier changes.
88
90
 
89
- * `cacheIdentifier`: Default is a string composed by the babel-core's version, the babel-loader's version, the contents of .babelrc file if it exists and the value of the environment variable `BABEL_ENV` with a fallback to the `NODE_ENV` environment variable. This can be set to a custom value to force cache busting if the identifier changes.
91
+ * `cacheCompression`: Default `true`. When set, each Babel transform output will be compressed with Gzip. If you want to opt-out of cache compression, set it to `false` -- your project may benefit from this if it transpiles thousands of files.
90
92
 
91
- __Note:__ The `sourceMap` option is ignored, instead sourceMaps are automatically enabled when webpack is configured to use them (via the `devtool` config option).
93
+ * `customize`: Default `null`. The path of a module that exports a `custom` callback [like the one that you'd pass to `.custom()`](#customized-loader). Since you already have to make a new file to use this, it is recommended that you instead use `.custom` to create a wrapper loader. Only use this is you _must_ continue using `babel-loader` directly, but still want to customize.
92
94
 
93
95
  ## Troubleshooting
94
96
 
95
97
  ### babel-loader is slow!
96
98
 
97
- Make sure you are transforming as few files as possible. Because you are probably
98
- matching `/\.js$/`, you might be transforming the `node_modules` folder or other unwanted
99
- source.
99
+ Make sure you are transforming as few files as possible. Because you are probably matching `/\.m?js$/`, you might be transforming the `node_modules` folder or other unwanted source.
100
100
 
101
101
  To exclude `node_modules`, see the `exclude` option in the `loaders` config as documented above.
102
102
 
103
- You can also speed up babel-loader by as much as 2x by using the `cacheDirectory` option.
104
- This will cache transformations to the filesystem.
103
+ You can also speed up babel-loader by as much as 2x by using the `cacheDirectory` option. This will cache transformations to the filesystem.
105
104
 
106
- ### babel is injecting helpers into each file and bloating my code!
105
+ ### Babel is injecting helpers into each file and bloating my code!
107
106
 
108
- babel uses very small helpers for common functions such as `_extend`. By default
109
- this will be added to every file that requires it.
107
+ Babel uses very small helpers for common functions such as `_extend`. By default, this will be added to every file that requires it.
110
108
 
111
- You can instead require the babel runtime as a separate module to avoid the duplication.
109
+ You can instead require the Babel runtime as a separate module to avoid the duplication.
112
110
 
113
- The following configuration disables automatic per-file runtime injection in babel, instead
114
- requiring `babel-plugin-transform-runtime` and making all helper references use it.
111
+ The following configuration disables automatic per-file runtime injection in Babel, requiring `babel-plugin-transform-runtime` instead and making all helper references use it.
115
112
 
116
113
  See the [docs](https://babeljs.io/docs/plugins/transform-runtime/) for more information.
117
114
 
118
- **NOTE:** You must run `npm install @babel/plugin-transform-runtime --save-dev` to include this in your project and `babel-runtime` itself as a dependency with `npm install @babel/runtime --save`.
115
+ **NOTE**: You must run `npm install -D @babel/plugin-transform-runtime` to include this in your project and `babel-runtime` itself as a dependency with `npm install @babel/runtime`.
119
116
 
120
117
  ```javascript
121
118
  rules: [
122
- // the 'transform-runtime' plugin tells babel to require the runtime
123
- // instead of inlining it.
119
+ // the 'transform-runtime' plugin tells Babel to
120
+ // require the runtime instead of inlining it.
124
121
  {
125
- test: /\.js$/,
122
+ test: /\.m?js$/,
126
123
  exclude: /(node_modules|bower_components)/,
127
124
  use: {
128
125
  loader: 'babel-loader',
@@ -135,9 +132,9 @@ rules: [
135
132
  ]
136
133
  ```
137
134
 
138
- #### **NOTE:** transform-runtime & custom polyfills (e.g. Promise library)
135
+ #### **NOTE**: transform-runtime & custom polyfills (e.g. Promise library)
139
136
 
140
- Since [babel-plugin-transform-runtime](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime) includes a polyfill that includes a custom [regenerator runtime](https://github.com/facebook/regenerator/blob/master/packages/regenerator-runtime/runtime.js) and [core.js](https://github.com/zloirock/core-js), the following usual shimming method using `webpack.ProvidePlugin` will not work:
137
+ Since [babel-plugin-transform-runtime](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime) includes a polyfill that includes a custom [regenerator-runtime](https://github.com/facebook/regenerator/blob/master/packages/regenerator-runtime/runtime.js) and [core-js](https://github.com/zloirock/core-js), the following usual shimming method using `webpack.ProvidePlugin` will not work:
141
138
 
142
139
  ```javascript
143
140
  // ...
@@ -181,23 +178,23 @@ require('@babel/runtime/core-js/promise').default = require('bluebird');
181
178
  require('./app');
182
179
  ```
183
180
 
184
- ### The node API for `babel` has been moved to `babel-core`.
181
+ ### The Node.js API for `babel` has been moved to `babel-core`.
185
182
 
186
- If you receive this message it means that you have the npm package `babel` installed and use the short notation of the loader in the webpack config (which is not valid anymore as of webpack 2.x):
187
- ```js
183
+ If you receive this message, it means that you have the npm package `babel` installed and are using the short notation of the loader in the webpack config (which is not valid anymore as of webpack 2.x):
184
+ ```javascript
188
185
  {
189
- test: /\.js$/,
186
+ test: /\.m?js$/,
190
187
  loader: 'babel',
191
188
  }
192
189
  ```
193
190
 
194
- Webpack then tries to load the `babel` package instead of the `babel-loader`.
191
+ webpack then tries to load the `babel` package instead of the `babel-loader`.
195
192
 
196
- To fix this you should uninstall the npm package `babel` as it is deprecated in babel v6. (instead install `babel-cli` or `babel-core`)
193
+ To fix this, you should uninstall the npm package `babel`, as it is deprecated in Babel v6. (Instead, install `babel-cli` or `babel-core`.)
197
194
  In the case one of your dependencies is installing `babel` and you cannot uninstall it yourself, use the complete name of the loader in the webpack config:
198
- ```js
195
+ ```javascript
199
196
  {
200
- test: /\.js$/,
197
+ test: /\.m?js$/,
201
198
  loader: 'babel-loader',
202
199
  }
203
200
  ```
@@ -211,9 +208,14 @@ of Babel's configuration for each file that it processes.
211
208
  `babel` so that tooling can ensure that it using exactly the same `@babel/core`
212
209
  instance as the loader itself.
213
210
 
211
+ In cases where you want to customize without actually having a file to call `.custom`, you
212
+ may also pass the `customize` option with a string pointing at a file that exports
213
+ your `custom` callback function.
214
+
214
215
  ### Example
215
216
 
216
217
  ```js
218
+ // Export from "./my-custom-loader.js" or whatever you want.
217
219
  module.exports = require("babel-loader").custom(babel => {
218
220
  function myPlugin() {
219
221
  return {
@@ -233,7 +235,7 @@ module.exports = require("babel-loader").custom(babel => {
233
235
  };
234
236
  },
235
237
 
236
- // Passed Babel's 'PartialConfig' object.
238
+ // Passed Babel's 'PartialConfig' object.
237
239
  config(cfg) {
238
240
  if (cfg.hasFilesystemConfig()) {
239
241
  // Use the normal config
@@ -261,6 +263,20 @@ module.exports = require("babel-loader").custom(babel => {
261
263
  });
262
264
  ```
263
265
 
266
+ ```js
267
+ // And in your Webpack config
268
+ module.exports = {
269
+ // ..
270
+ module: {
271
+ rules: [{
272
+ // ...
273
+ loader: path.join(__dirname, 'my-custom-loader.js'),
274
+ // ...
275
+ }]
276
+ }
277
+ };
278
+ ```
279
+
264
280
  ### `customOptions(options: Object): { custom: Object, loader: Object }`
265
281
 
266
282
  Given the loader's options, split custom options out of `babel-loader`'s
@@ -278,4 +294,5 @@ be passed to `babel.transform`.
278
294
  Given Babel's result object, allow loaders to make additional tweaks to it.
279
295
 
280
296
 
281
- ## [License](https://couto.mit-license.org/)
297
+ ## License
298
+ [MIT](https://couto.mit-license.org/)
package/lib/cache.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
 
3
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(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); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
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); }); }; }
4
6
 
5
7
  /**
6
8
  * Filesystem Cache
@@ -46,13 +48,13 @@ const mkdirp = promisify(mkdirpOrig);
46
48
  const read =
47
49
  /*#__PURE__*/
48
50
  function () {
49
- var _ref = _asyncToGenerator(function* (filename) {
50
- const data = yield readFile(filename);
51
- const content = yield gunzip(data);
52
- return JSON.parse(content);
51
+ var _ref = _asyncToGenerator(function* (filename, compress) {
52
+ const data = yield readFile(filename + (compress ? ".gz" : ""));
53
+ const content = compress ? yield gunzip(data) : data;
54
+ return JSON.parse(content.toString());
53
55
  });
54
56
 
55
- return function read(_x) {
57
+ return function read(_x, _x2) {
56
58
  return _ref.apply(this, arguments);
57
59
  };
58
60
  }();
@@ -68,13 +70,13 @@ function () {
68
70
  const write =
69
71
  /*#__PURE__*/
70
72
  function () {
71
- var _ref2 = _asyncToGenerator(function* (filename, result) {
73
+ var _ref2 = _asyncToGenerator(function* (filename, compress, result) {
72
74
  const content = JSON.stringify(result);
73
- const data = yield gzip(content);
74
- return yield writeFile(filename, data);
75
+ const data = compress ? yield gzip(content) : content;
76
+ return yield writeFile(filename + (compress ? ".gz" : ""), data);
75
77
  });
76
78
 
77
- return function write(_x2, _x3) {
79
+ return function write(_x3, _x4, _x5) {
78
80
  return _ref2.apply(this, arguments);
79
81
  };
80
82
  }();
@@ -96,7 +98,7 @@ const filename = function (source, identifier, options) {
96
98
  identifier
97
99
  });
98
100
  hash.update(contents);
99
- return hash.digest("hex") + ".json.gz";
101
+ return hash.digest("hex") + ".json";
100
102
  };
101
103
  /**
102
104
  * Handle the cache
@@ -114,14 +116,15 @@ function () {
114
116
  source,
115
117
  options = {},
116
118
  cacheIdentifier,
117
- cacheDirectory
119
+ cacheDirectory,
120
+ cacheCompression
118
121
  } = params;
119
122
  const file = path.join(directory, filename(source, cacheIdentifier, options));
120
123
 
121
124
  try {
122
125
  // No errors mean that the file was previously cached
123
126
  // we just need to return it
124
- return yield read(file);
127
+ return yield read(file, cacheCompression);
125
128
  } catch (err) {}
126
129
 
127
130
  const fallback = typeof cacheDirectory !== "string" && directory !== os.tmpdir(); // Make sure the directory exists.
@@ -141,7 +144,7 @@ function () {
141
144
  const result = yield transform(source, options);
142
145
 
143
146
  try {
144
- yield write(file, result);
147
+ yield write(file, cacheCompression, result);
145
148
  } catch (err) {
146
149
  if (fallback) {
147
150
  // Fallback to tmpdir if node_modules folder not writable
@@ -154,7 +157,7 @@ function () {
154
157
  return result;
155
158
  });
156
159
 
157
- return function handleCache(_x4, _x5) {
160
+ return function handleCache(_x6, _x7) {
158
161
  return _ref3.apply(this, arguments);
159
162
  };
160
163
  }();
@@ -176,6 +179,7 @@ function () {
176
179
  * cache({
177
180
  * directory: '.tmp/cache',
178
181
  * identifier: 'babel-loader-cachefile',
182
+ * cacheCompression: false,
179
183
  * source: *source code from file*,
180
184
  * options: {
181
185
  * experimental: true,
@@ -212,7 +216,7 @@ function () {
212
216
  return yield handleCache(directory, params);
213
217
  });
214
218
 
215
- return function (_x6) {
219
+ return function (_x8) {
216
220
  return _ref4.apply(this, arguments);
217
221
  };
218
222
  }();
package/lib/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
 
3
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(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); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
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); }); }; }
4
6
 
5
7
  let babel;
6
8
 
@@ -26,7 +28,9 @@ const cache = require("./cache");
26
28
 
27
29
  const transform = require("./transform");
28
30
 
29
- const relative = require("./utils/relative");
31
+ const injectCaller = require("./injectCaller");
32
+
33
+ const path = require("path");
30
34
 
31
35
  const loaderUtils = require("loader-utils");
32
36
 
@@ -56,10 +60,38 @@ function _loader() {
56
60
  _loader = _asyncToGenerator(function* (source, inputSourceMap, overrides) {
57
61
  const filename = this.resourcePath;
58
62
  let loaderOptions = loaderUtils.getOptions(this) || {};
63
+
64
+ if (loaderOptions.customize != null) {
65
+ if (typeof loaderOptions.customize !== "string") {
66
+ throw new Error("Customized loaders must be implemented as standalone modules.");
67
+ }
68
+
69
+ if (!path.isAbsolute(loaderOptions.customize)) {
70
+ 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.");
71
+ }
72
+
73
+ if (overrides) {
74
+ throw new Error("babel-loader's 'customize' option is not available when already " + "using a customized babel-loader wrapper.");
75
+ }
76
+
77
+ let override = require(loaderOptions.customize);
78
+
79
+ if (override.__esModule) override = override.default;
80
+
81
+ if (typeof override !== "function") {
82
+ throw new Error("Custom overrides must be functions.");
83
+ }
84
+
85
+ overrides = override(babel);
86
+ }
87
+
59
88
  let customOptions;
60
89
 
61
90
  if (overrides && overrides.customOptions) {
62
- const result = yield overrides.customOptions.call(this, loaderOptions);
91
+ const result = yield overrides.customOptions.call(this, loaderOptions, {
92
+ source,
93
+ map: inputSourceMap
94
+ });
63
95
  customOptions = result.custom;
64
96
  loaderOptions = result.loader;
65
97
  } // Deprecation handling
@@ -71,31 +103,41 @@ function _loader() {
71
103
 
72
104
  if (typeof loaderOptions.babelrc === "string") {
73
105
  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");
74
- } // Set babel-loader's default options.
106
+ } // Standardize on 'sourceMaps' as the key passed through to Webpack, so that
107
+ // users may safely use either one alongside our default use of
108
+ // 'this.sourceMap' below without getting error about conflicting aliases.
75
109
 
76
110
 
77
- const {
78
- sourceRoot = process.cwd(),
79
- sourceMap = this.sourceMap,
80
- sourceFileName = relative(sourceRoot, filename)
81
- } = loaderOptions;
111
+ if (Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMap") && !Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMaps")) {
112
+ loaderOptions = Object.assign({}, loaderOptions, {
113
+ sourceMaps: loaderOptions.sourceMap
114
+ });
115
+ delete loaderOptions.sourceMap;
116
+ }
117
+
82
118
  const programmaticOptions = Object.assign({}, loaderOptions, {
83
119
  filename,
84
120
  inputSourceMap: inputSourceMap || undefined,
85
- sourceRoot,
86
- sourceMap,
87
- sourceFileName
121
+ // Set the default sourcemap behavior based on Webpack's mapping flag,
122
+ // but allow users to override if they want.
123
+ sourceMaps: loaderOptions.sourceMaps === undefined ? this.sourceMap : loaderOptions.sourceMaps,
124
+ // Ensure that Webpack will get a full absolute path in the sourcemap
125
+ // so that it can properly map the module back to its internal cached
126
+ // modules.
127
+ sourceFileName: filename
88
128
  }); // Remove loader related options
89
129
 
130
+ delete programmaticOptions.customize;
90
131
  delete programmaticOptions.cacheDirectory;
91
132
  delete programmaticOptions.cacheIdentifier;
133
+ delete programmaticOptions.cacheCompression;
92
134
  delete programmaticOptions.metadataSubscribers;
93
135
 
94
136
  if (!babel.loadPartialConfig) {
95
137
  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`);
96
138
  }
97
139
 
98
- const config = babel.loadPartialConfig(programmaticOptions);
140
+ const config = babel.loadPartialConfig(injectCaller(programmaticOptions));
99
141
 
100
142
  if (config) {
101
143
  let options = config.options;
@@ -103,10 +145,21 @@ function _loader() {
103
145
  if (overrides && overrides.config) {
104
146
  options = yield overrides.config.call(this, config, {
105
147
  source,
148
+ map: inputSourceMap,
106
149
  customOptions
107
150
  });
108
151
  }
109
152
 
153
+ if (options.sourceMaps === "inline") {
154
+ // Babel has this weird behavior where if you set "inline", we
155
+ // inline the sourcemap, and set 'result.map = null'. This results
156
+ // in bad behavior from Babel since the maps get put into the code,
157
+ // which Webpack does not expect, and because the map we return to
158
+ // Webpack is null, which is also bad. To avoid that, we override the
159
+ // behavior here so "inline" just behaves like 'true'.
160
+ options.sourceMaps = true;
161
+ }
162
+
110
163
  const {
111
164
  cacheDirectory = null,
112
165
  cacheIdentifier = JSON.stringify({
@@ -114,6 +167,7 @@ function _loader() {
114
167
  "@babel/core": transform.version,
115
168
  "@babel/loader": pkg.version
116
169
  }),
170
+ cacheCompression = true,
117
171
  metadataSubscribers = []
118
172
  } = loaderOptions;
119
173
  let result;
@@ -124,7 +178,8 @@ function _loader() {
124
178
  options,
125
179
  transform,
126
180
  cacheDirectory,
127
- cacheIdentifier
181
+ cacheIdentifier,
182
+ cacheCompression
128
183
  });
129
184
  } else {
130
185
  result = yield transform(source, options);
@@ -140,6 +195,7 @@ function _loader() {
140
195
  if (overrides && overrides.result) {
141
196
  result = yield overrides.result.call(this, result, {
142
197
  source,
198
+ map: inputSourceMap,
143
199
  customOptions,
144
200
  config,
145
201
  options
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ const babel = require("@babel/core");
4
+
5
+ module.exports = function injectCaller(opts) {
6
+ if (!supportsCallerOption()) return opts;
7
+ return Object.assign({}, opts, {
8
+ caller: Object.assign({
9
+ name: "babel-loader",
10
+ // Webpack >= 2 supports ESM and dynamic import.
11
+ supportsStaticESM: true,
12
+ supportsDynamicImport: true
13
+ }, opts.caller)
14
+ });
15
+ }; // TODO: We can remove this eventually, I'm just adding it so that people have
16
+ // a little time to migrate to the newer RCs of @babel/core without getting
17
+ // hard-to-diagnose errors about unknown 'caller' options.
18
+
19
+
20
+ let supportsCallerOptionFlag = undefined;
21
+
22
+ function supportsCallerOption() {
23
+ if (supportsCallerOptionFlag === undefined) {
24
+ try {
25
+ // Rather than try to match the Babel version, we just see if it throws
26
+ // when passed a 'caller' flag, and use that to decide if it is supported.
27
+ babel.loadPartialConfig({
28
+ caller: undefined,
29
+ babelrc: false,
30
+ configFile: false
31
+ });
32
+ supportsCallerOptionFlag = true;
33
+ } catch (err) {
34
+ supportsCallerOptionFlag = false;
35
+ }
36
+ }
37
+
38
+ return supportsCallerOptionFlag;
39
+ }
package/lib/transform.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
 
3
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(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); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
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); }); }; }
4
6
 
5
7
  const babel = require("@babel/core");
6
8
 
@@ -17,7 +19,7 @@ function () {
17
19
  let result;
18
20
 
19
21
  try {
20
- result = yield transform(source, injectCaller(options));
22
+ result = yield transform(source, options);
21
23
  } catch (err) {
22
24
  throw err.message && err.codeFrame ? new LoaderError(err) : err;
23
25
  }
@@ -54,40 +56,4 @@ function () {
54
56
  };
55
57
  }();
56
58
 
57
- module.exports.version = babel.version;
58
-
59
- function injectCaller(opts) {
60
- if (!supportsCallerOption()) return opts;
61
- return Object.assign({}, opts, {
62
- caller: Object.assign({
63
- name: "babel-loader",
64
- // Webpack >= 2 supports ESM and dynamic import.
65
- supportsStaticESM: true,
66
- supportsDynamicImport: true
67
- }, opts.caller)
68
- });
69
- } // TODO: We can remove this eventually, I'm just adding it so that people have
70
- // a little time to migrate to the newer RCs of @babel/core without getting
71
- // hard-to-diagnose errors about unknown 'caller' options.
72
-
73
-
74
- let supportsCallerOptionFlag = undefined;
75
-
76
- function supportsCallerOption() {
77
- if (supportsCallerOptionFlag === undefined) {
78
- try {
79
- // Rather than try to match the Babel version, we just see if it throws
80
- // when passed a 'caller' flag, and use that to decide if it is supported.
81
- babel.loadPartialConfig({
82
- caller: undefined,
83
- babelrc: false,
84
- configFile: false
85
- });
86
- supportsCallerOptionFlag = true;
87
- } catch (err) {
88
- supportsCallerOptionFlag = false;
89
- }
90
- }
91
-
92
- return supportsCallerOptionFlag;
93
- }
59
+ module.exports.version = babel.version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-loader",
3
- "version": "8.0.1",
3
+ "version": "8.0.5",
4
4
  "description": "babel module loader for webpack",
5
5
  "files": [
6
6
  "lib"
@@ -10,7 +10,7 @@
10
10
  "node": ">= 6.9"
11
11
  },
12
12
  "dependencies": {
13
- "find-cache-dir": "^1.0.0",
13
+ "find-cache-dir": "^2.0.0",
14
14
  "loader-utils": "^1.0.2",
15
15
  "mkdirp": "^0.5.1",
16
16
  "util.promisify": "^1.0.0"
@@ -20,25 +20,26 @@
20
20
  "webpack": ">=2"
21
21
  },
22
22
  "devDependencies": {
23
- "@babel/cli": "^7.0.0-beta.41",
24
- "@babel/core": "^7.0.0-beta.41",
25
- "@babel/preset-env": "^7.0.0-beta.41",
26
- "ava": "0.25.0",
27
- "babel-eslint": "^8.0.0",
28
- "babel-plugin-istanbul": "^4.0.0",
29
- "babel-plugin-react-intl": "^2.1.3",
30
- "cross-env": "^5.0.0",
31
- "eslint": "^4.1.0",
32
- "eslint-config-babel": "^7.0.0",
33
- "eslint-plugin-flowtype": "^2.25.0",
34
- "eslint-plugin-prettier": "^2.1.2",
35
- "husky": "^0.14.0",
36
- "lint-staged": "^7.1.0",
37
- "nyc": "^11.0.1",
38
- "prettier": "^1.2.2",
23
+ "@babel/cli": "^7.2.0",
24
+ "@babel/core": "^7.2.0",
25
+ "@babel/preset-env": "^7.2.0",
26
+ "ava": "1.0.1",
27
+ "babel-eslint": "^10.0.1",
28
+ "babel-plugin-istanbul": "^5.1.0",
29
+ "babel-plugin-react-intl": "^3.0.1",
30
+ "cross-env": "^5.2.0",
31
+ "eslint": "^5.9.0",
32
+ "eslint-config-babel": "^8.0.2",
33
+ "eslint-config-prettier": "^3.3.0",
34
+ "eslint-plugin-flowtype": "^3.2.0",
35
+ "eslint-plugin-prettier": "^3.0.0",
36
+ "husky": "^1.2.0",
37
+ "lint-staged": "^8.1.0",
38
+ "nyc": "^13.1.0",
39
+ "prettier": "^1.15.3",
39
40
  "react": "^16.0.0",
40
41
  "react-intl": "^2.1.2",
41
- "react-intl-webpack-plugin": "^0.0.3",
42
+ "react-intl-webpack-plugin": "^0.3.0",
42
43
  "rimraf": "^2.4.3",
43
44
  "webpack": "^4.0.0"
44
45
  },
@@ -89,7 +90,7 @@
89
90
  "!test/fixtures/**/*",
90
91
  "!test/helpers/**/*"
91
92
  ],
92
- "source": [
93
+ "sources": [
93
94
  "src/**/*.js"
94
95
  ]
95
96
  },
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- const path = require("path");
4
-
5
- module.exports = function relative(root, file) {
6
- const rootPath = root.replace(/\\/g, "/").split("/")[1];
7
- const filePath = file.replace(/\\/g, "/").split("/")[1]; // If the file is in a completely different root folder
8
- // use the absolute path of the file
9
-
10
- if (rootPath && rootPath !== filePath) {
11
- return file;
12
- }
13
-
14
- return path.relative(root, file);
15
- };