babel-loader 7.0.0-alpha.1 โ†’ 7.0.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # Changelog
2
2
 
3
+ For changes in version v7.0.0 and up please go to [release](https://github.com/babel/babel-loader/releases)
4
+
5
+ # Old Changelog
6
+
7
+ ## v6.4.1
8
+
9
+ ### ๐Ÿ› Bug Fix
10
+
11
+ - Fixed reset of BABEL_ENV when options.forceEnv is used (#420) @nikopavlica
12
+
13
+ ## v6.4.0
14
+
15
+ ### ๐Ÿš€ New Feature
16
+
17
+ - added metadata passing from babel to webpack, which is currently used by react-intl (#398) @Ognian
18
+
19
+ ## v6.3.2
20
+
21
+ ### ๐Ÿ˜ข Regression
22
+
23
+ - `forceEnv` was interfering with regular environment handling
24
+
25
+ ## v6.3.1
26
+
27
+ ### ๐Ÿ› Bug Fix
28
+
29
+ - The new `forceEnv` options wasn't working as expected (#379) @chrisvasz
30
+
31
+ ## v6.3.0
32
+
33
+ ### ๐Ÿš€ New Feature
34
+
35
+ - Add new config option `forceEnv` (#368) @moimael
36
+
37
+ Allow to override BABEL_ENV/NODE_ENV at loader-level. Useful for isomorphic applications which have separate babel config for client and server.
38
+
39
+ ### ๐Ÿ› Bug Fix
40
+
41
+ - Update loader-utils dependency to ^0.2.16 to fix compatibility with webpack 2 (#371) @leonaves
42
+
43
+ ### ๐Ÿ’… Polish
44
+
45
+ - Improve FS caching to do less sync calls which improves performance slightly (#375) @akx
46
+
3
47
  ## v6.2.10
4
48
 
5
49
  Support for webpack 2.2-rc has been added in this release
package/README.md CHANGED
@@ -1,136 +1,136 @@
1
- # babel-loader
2
1
  [![NPM Status](https://img.shields.io/npm/v/babel-loader.svg?style=flat)](https://www.npmjs.com/package/babel-loader)
3
2
  [![Build Status](https://travis-ci.org/babel/babel-loader.svg?branch=master)](https://travis-ci.org/babel/babel-loader)
4
3
  [![Build Status](https://ci.appveyor.com/api/projects/status/vgtpr2i5bykgyuqo/branch/master?svg=true)](https://ci.appveyor.com/project/danez/babel-loader/branch/master)
5
4
  [![codecov](https://codecov.io/gh/babel/babel-loader/branch/master/graph/badge.svg)](https://codecov.io/gh/babel/babel-loader)
6
- > Babel is a compiler for writing next generation JavaScript.
7
5
 
8
- This package allows transpiling JavaScript files using [Babel](https://github.com/babel/babel) and [webpack](https://github.com/webpack/webpack).
6
+ <div align="center">
7
+ <a href="https://github.com/babel/babel/">
8
+ <img width="200" height="200" src="https://rawgit.com/babel/logo/master/babel.svg">
9
+ </a>
10
+ <a href="https://github.com/webpack/webpack">
11
+ <img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg">
12
+ </a>
13
+ <h1>Babel Loader</h1>
14
+ </div>
9
15
 
10
- __Notes:__ Issues with the output should be reported on the babel [issue tracker](https://github.com/babel/babel/issues);
16
+ This package allows transpiling JavaScript files using [Babel](https://github.com/babel/babel) and [webpack](https://github.com/webpack/webpack).
11
17
 
12
- ## Installation
18
+ __Notes:__ Issues with the output should be reported on the babel [issue tracker](https://github.com/babel/babel/issues);
13
19
 
14
- ```bash
15
- npm install babel-loader babel-core babel-preset-es2015 webpack --save-dev
16
- ```
20
+ <h2 align="center">Install</h2>
17
21
 
18
- or
22
+ > webpack 1.x | babel-loader <= 6.x
23
+ >
24
+ > webpack 2.x |ย babel-loader >= 7.x (recommended) (^6.2.10 will also work, but with deprecation warnings)
19
25
 
20
26
  ```bash
21
- yarn add babel-loader babel-core babel-preset-es2015 webpack --dev
27
+ yarn add babel-loader babel-core babel-preset-env webpack --dev
22
28
  ```
23
29
 
24
- __Note:__ [npm](https://npmjs.com) deprecated [auto-installing of peerDependencies](https://github.com/npm/npm/issues/6565) since npm@3, so required peer dependencies like babel-core and webpack must be listed explicitly in your `package.json`.
30
+ We recommend using yarn, but you can also still use npm:
25
31
 
26
- __Note:__ If you're upgrading from babel 5 to babel 6, please take a look [at this guide](https://medium.com/@malyw/how-to-update-babel-5-x-6-x-d828c230ec53#.yqxukuzdk).
32
+ ```bash
33
+ npm install --save-dev babel-loader babel-core babel-preset-env webpack
34
+ ```
27
35
 
28
- ## Usage
36
+ <h2 align="center">Usage</h2>
29
37
 
30
- [Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
38
+ [Documentation: Using loaders](https://webpack.js.org/loaders/)
31
39
 
32
- Within your webpack configuration object, you'll need to add the babel-loader to the list of modules, like so:
40
+ Within your webpack configuration object, you'll need to add the babel-loader to the list of modules, like so:
33
41
 
34
- ```javascript
42
+ ```javascript
35
43
  module: {
36
- loaders: [
44
+ rules: [
37
45
  {
38
46
  test: /\.js$/,
39
47
  exclude: /(node_modules|bower_components)/,
40
- loader: 'babel-loader',
41
- query: {
42
- presets: ['es2015']
48
+ use: {
49
+ loader: 'babel-loader',
50
+ options: {
51
+ presets: ['env']
52
+ }
43
53
  }
44
54
  }
45
55
  ]
46
56
  }
47
- ```
57
+ ```
48
58
 
49
59
  ### Options
50
60
 
51
- See the `babel` [options](http://babeljs.io/docs/usage/options/).
52
-
53
- You can pass options to the loader by writing them as a [query string](https://github.com/webpack/loader-utils):
61
+ See the `babel` [options](https://babeljs.io/docs/usage/api/#options).
54
62
 
55
- ```javascript
56
- module: {
57
- loaders: [
58
- {
59
- test: /\.js$/,
60
- exclude: /(node_modules|bower_components)/,
61
- loader: 'babel-loader?presets[]=es2015'
62
- }
63
- ]
64
- }
65
- ```
66
63
 
67
- or by using the [query property](https://webpack.github.io/docs/using-loaders.html#query-parameters):
64
+ You can pass options to the loader by using the [options property](https://webpack.js.org/configuration/module/#rule-options-rule-query):
68
65
 
69
- ```javascript
66
+ ```javascript
70
67
  module: {
71
- loaders: [
68
+ rules: [
72
69
  {
73
70
  test: /\.js$/,
74
71
  exclude: /(node_modules|bower_components)/,
75
- loader: 'babel-loader',
76
- query: {
77
- presets: ['es2015']
72
+ use: {
73
+ loader: 'babel-loader',
74
+ options: {
75
+ presets: ['env'],
76
+ plugins: [require('babel-plugin-transform-object-rest-spread')]
77
+ }
78
78
  }
79
79
  }
80
80
  ]
81
81
  }
82
- ```
83
-
84
- This loader also supports the following loader-specific option:
82
+ ```
85
83
 
86
- * `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.
84
+ This loader also supports the following loader-specific option:
87
85
 
88
- * `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.
86
+ * `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.
89
87
 
90
- * `babelrc`: Default `true`. When `false`, will ignore `.babelrc` files (except those referenced by the `extends` option).
88
+ * `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
89
 
92
- * `forceEnv`: Default will resolve BABEL_ENV then NODE_ENV. Allow you to override BABEL_ENV/NODE_ENV at the loader level. Useful for isomorphic applications with different babel configuration for client and server.
90
+ * `forceEnv`: Default will resolve BABEL_ENV then NODE_ENV. Allow you to override BABEL_ENV/NODE_ENV at the loader level. Useful for isomorphic applications with different babel configuration for client and server.
93
91
 
94
- __Note:__ The `sourceMap` option is ignored, instead sourceMaps are automatically enabled when webpack is configured to use them (via the `devtool` config option).
92
+ __Note:__ The `sourceMap` option is ignored, instead sourceMaps are automatically enabled when webpack is configured to use them (via the `devtool` config option).
95
93
 
96
94
  ## Troubleshooting
97
95
 
98
96
  ### babel-loader is slow!
99
97
 
100
- Make sure you are transforming as few files as possible. Because you are probably
101
- matching `/\.js$/`, you might be transforming the `node_modules` folder or other unwanted
102
- source.
98
+ Make sure you are transforming as few files as possible. Because you are probably
99
+ matching `/\.js$/`, you might be transforming the `node_modules` folder or other unwanted
100
+ source.
103
101
 
104
- To exclude `node_modules`, see the `exclude` option in the `loaders` config as documented above.
102
+ To exclude `node_modules`, see the `exclude` option in the `loaders` config as documented above.
105
103
 
106
- You can also speed up babel-loader by as much as 2x by using the `cacheDirectory` option.
107
- This will cache transformations to the filesystem.
104
+ You can also speed up babel-loader by as much as 2x by using the `cacheDirectory` option.
105
+ This will cache transformations to the filesystem.
108
106
 
109
107
  ### babel is injecting helpers into each file and bloating my code!
110
108
 
111
- babel uses very small helpers for common functions such as `_extend`. By default
112
- this will be added to every file that requires it.
109
+ babel uses very small helpers for common functions such as `_extend`. By default
110
+ this will be added to every file that requires it.
113
111
 
114
- You can instead require the babel runtime as a separate module to avoid the duplication.
112
+ You can instead require the babel runtime as a separate module to avoid the duplication.
115
113
 
116
- The following configuration disables automatic per-file runtime injection in babel, instead
117
- requiring `babel-plugin-transform-runtime` and making all helper references use it.
114
+ The following configuration disables automatic per-file runtime injection in babel, instead
115
+ requiring `babel-plugin-transform-runtime` and making all helper references use it.
118
116
 
119
- See the [docs](http://babeljs.io/docs/plugins/transform-runtime/) for more information.
117
+ See the [docs](http://babeljs.io/docs/plugins/transform-runtime/) for more information.
120
118
 
121
- **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`.
119
+ **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`.
122
120
 
123
121
  ```javascript
124
- loaders: [
122
+ rules: [
125
123
  // the 'transform-runtime' plugin tells babel to require the runtime
126
124
  // instead of inlining it.
127
125
  {
128
126
  test: /\.js$/,
129
127
  exclude: /(node_modules|bower_components)/,
130
- loader: 'babel-loader',
131
- query: {
132
- presets: ['es2015'],
133
- plugins: ['transform-runtime']
128
+ use: {
129
+ loader: 'babel-loader',
130
+ options: {
131
+ presets: ['env'],
132
+ plugins: ['transform-runtime']
133
+ }
134
134
  }
135
135
  }
136
136
  ]
package/lib/fs-cache.js CHANGED
@@ -1,5 +1,14 @@
1
1
  "use strict";
2
2
 
3
+ /**
4
+ * Filesystem cache
5
+ *
6
+ * Given a file and a transform function, cache the result into files
7
+ * or retrieve the previously cached files if the given file is already known.
8
+ *
9
+ * @see https://github.com/babel/babel-loader/issues/34
10
+ * @see https://github.com/babel/babel-loader/pull/41
11
+ */
3
12
  var crypto = require("crypto");
4
13
  var mkdirp = require("mkdirp");
5
14
  var findCacheDir = require("find-cache-dir");
@@ -8,19 +17,23 @@ var os = require("os");
8
17
  var path = require("path");
9
18
  var zlib = require("zlib");
10
19
 
11
- var defaultCacheDirectory = null;
20
+ var defaultCacheDirectory = null; // Lazily instantiated when needed
21
+
22
+ /**
23
+ * Read the contents from the compressed file.
24
+ *
25
+ * @async
26
+ * @params {String} filename
27
+ * @params {Function} callback
28
+ */
12
29
  var read = function read(filename, callback) {
13
30
  return fs.readFile(filename, function (err, data) {
14
- if (err) {
15
- return callback(err);
16
- }
31
+ if (err) return callback(err);
17
32
 
18
33
  return zlib.gunzip(data, function (err, content) {
19
- var result = {};
34
+ if (err) return callback(err);
20
35
 
21
- if (err) {
22
- return callback(err);
23
- }
36
+ var result = {};
24
37
 
25
38
  try {
26
39
  result = JSON.parse(content);
@@ -33,18 +46,32 @@ var read = function read(filename, callback) {
33
46
  });
34
47
  };
35
48
 
49
+ /**
50
+ * Write contents into a compressed file.
51
+ *
52
+ * @async
53
+ * @params {String} filename
54
+ * @params {String} result
55
+ * @params {Function} callback
56
+ */
36
57
  var write = function write(filename, result, callback) {
37
58
  var content = JSON.stringify(result);
38
59
 
39
60
  return zlib.gzip(content, function (err, data) {
40
- if (err) {
41
- return callback(err);
42
- }
61
+ if (err) return callback(err);
43
62
 
44
63
  return fs.writeFile(filename, data, callback);
45
64
  });
46
65
  };
47
66
 
67
+ /**
68
+ * Build the filename for the cached file
69
+ *
70
+ * @params {String} source File source code
71
+ * @params {Object} options Options used
72
+ *
73
+ * @return {String}
74
+ */
48
75
  var filename = function filename(source, identifier, options) {
49
76
  var hash = crypto.createHash("SHA1");
50
77
  var contents = JSON.stringify({
@@ -58,6 +85,13 @@ var filename = function filename(source, identifier, options) {
58
85
  return hash.read().toString("hex") + ".json.gz";
59
86
  };
60
87
 
88
+ /**
89
+ * Handle the cache
90
+ *
91
+ * @params {String} directory
92
+ * @params {Object} params
93
+ * @params {Function} callback
94
+ */
61
95
  var handleCache = function handleCache(directory, params, callback) {
62
96
  var source = params.source;
63
97
  var options = params.options || {};
@@ -65,16 +99,21 @@ var handleCache = function handleCache(directory, params, callback) {
65
99
  var identifier = params.identifier;
66
100
  var shouldFallback = typeof params.directory !== "string" && directory !== os.tmpdir();
67
101
 
102
+ // Make sure the directory exists.
68
103
  mkdirp(directory, function (err) {
104
+ // Fallback to tmpdir if node_modules folder not writable
69
105
  if (err) return shouldFallback ? handleCache(os.tmpdir(), params, callback) : callback(err);
70
106
 
71
107
  var file = path.join(directory, filename(source, identifier, options));
72
108
 
73
109
  return read(file, function (err, content) {
74
110
  var result = {};
75
-
111
+ // No errors mean that the file was previously cached
112
+ // we just need to return it
76
113
  if (!err) return callback(null, content);
77
114
 
115
+ // Otherwise just transform the file
116
+ // return it to the user asap and write it in cache
78
117
  try {
79
118
  result = transform(source, options);
80
119
  } catch (error) {
@@ -82,6 +121,7 @@ var handleCache = function handleCache(directory, params, callback) {
82
121
  }
83
122
 
84
123
  return write(file, result, function (err) {
124
+ // Fallback to tmpdir if node_modules folder not writable
85
125
  if (err) return shouldFallback ? handleCache(os.tmpdir(), params, callback) : callback(err);
86
126
 
87
127
  callback(null, result);
@@ -90,6 +130,40 @@ var handleCache = function handleCache(directory, params, callback) {
90
130
  });
91
131
  };
92
132
 
133
+ /**
134
+ * Retrieve file from cache, or create a new one for future reads
135
+ *
136
+ * @async
137
+ * @param {Object} params
138
+ * @param {String} params.directory Directory to store cached files
139
+ * @param {String} params.identifier Unique identifier to bust cache
140
+ * @param {String} params.source Original contents of the file to be cached
141
+ * @param {Object} params.options Options to be given to the transform fn
142
+ * @param {Function} params.transform Function that will transform the
143
+ * original file and whose result will be
144
+ * cached
145
+ *
146
+ * @param {Function<err, result>} callback
147
+ *
148
+ * @example
149
+ *
150
+ * cache({
151
+ * directory: '.tmp/cache',
152
+ * identifier: 'babel-loader-cachefile',
153
+ * source: *source code from file*,
154
+ * options: {
155
+ * experimental: true,
156
+ * runtime: true
157
+ * },
158
+ * transform: function(source, options) {
159
+ * var content = *do what you need with the source*
160
+ * return content;
161
+ * }
162
+ * }, function(err, result) {
163
+ *
164
+ * });
165
+ */
166
+
93
167
  module.exports = function (params, callback) {
94
168
  var directory = void 0;
95
169
 
package/lib/index.js CHANGED
@@ -1,8 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4
-
5
- var assign = require("object-assign");
6
3
  var babel = require("babel-core");
7
4
  var loaderUtils = require("loader-utils");
8
5
  var path = require("path");
@@ -11,8 +8,11 @@ var exists = require("./utils/exists")();
11
8
  var relative = require("./utils/relative");
12
9
  var read = require("./utils/read")();
13
10
  var resolveRc = require("./resolve-rc.js");
14
- var pkg = require("./../package.json");
11
+ var pkg = require("../package.json");
15
12
 
13
+ /**
14
+ * Error thrown by Babel formatted to conform to Webpack reporting.
15
+ */
16
16
  function BabelLoaderError(name, message, codeFrame, hideStack, error) {
17
17
  Error.call(this);
18
18
  Error.captureStackTrace(this, BabelLoaderError);
@@ -33,10 +33,21 @@ var formatMessage = function formatMessage(name, message, codeFrame) {
33
33
  };
34
34
 
35
35
  var transpile = function transpile(source, options) {
36
+ var forceEnv = options.forceEnv;
37
+ var tmpEnv = void 0;
38
+
39
+ delete options.forceEnv;
40
+
41
+ if (forceEnv) {
42
+ tmpEnv = process.env.BABEL_ENV;
43
+ process.env.BABEL_ENV = forceEnv;
44
+ }
45
+
36
46
  var result = void 0;
37
47
  try {
38
48
  result = babel.transform(source, options);
39
49
  } catch (error) {
50
+ if (forceEnv) restoreBabelEnv(tmpEnv);
40
51
  if (error.message && error.codeFrame) {
41
52
  var message = error.message;
42
53
  var name = void 0;
@@ -56,45 +67,60 @@ var transpile = function transpile(source, options) {
56
67
  }
57
68
  var code = result.code;
58
69
  var map = result.map;
70
+ var metadata = result.metadata;
59
71
 
60
72
  if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
61
73
  map.sourcesContent = [source];
62
74
  }
63
75
 
76
+ if (forceEnv) restoreBabelEnv(tmpEnv);
77
+
64
78
  return {
65
79
  code: code,
66
- map: map
80
+ map: map,
81
+ metadata: metadata
67
82
  };
68
83
  };
69
84
 
85
+ function restoreBabelEnv(prevValue) {
86
+ if (prevValue === undefined) {
87
+ delete process.env.BABEL_ENV;
88
+ } else {
89
+ process.env.BABEL_ENV = prevValue;
90
+ }
91
+ }
92
+
93
+ function passMetadata(s, context, metadata) {
94
+ if (context[s]) {
95
+ context[s](metadata);
96
+ }
97
+ }
98
+
70
99
  module.exports = function (source, inputSourceMap) {
71
100
  var _this = this;
72
101
 
73
- var result = {};
74
-
102
+ // Handle filenames (#106)
75
103
  var webpackRemainingChain = loaderUtils.getRemainingRequest(this).split("!");
76
104
  var filename = webpackRemainingChain[webpackRemainingChain.length - 1];
77
105
 
78
- var globalOptions = this.options.babel || {};
79
- var loaderOptions = loaderUtils.parseQuery(this.query);
80
- var userOptions = assign({}, globalOptions, loaderOptions);
106
+ // Handle options
107
+ var loaderOptions = loaderUtils.getOptions(this) || {};
81
108
  var defaultOptions = {
109
+ metadataSubscribers: [],
82
110
  inputSourceMap: inputSourceMap,
83
111
  sourceRoot: process.cwd(),
84
112
  filename: filename,
85
113
  cacheIdentifier: JSON.stringify({
86
114
  "babel-loader": pkg.version,
87
115
  "babel-core": babel.version,
88
- babelrc: exists(userOptions.babelrc) ? read(userOptions.babelrc) : resolveRc(path.dirname(filename)),
89
- env: userOptions.forceEnv || process.env.BABEL_ENV || process.env.NODE_ENV
116
+ babelrc: exists(loaderOptions.babelrc) ? read(loaderOptions.babelrc) : resolveRc(path.dirname(filename)),
117
+ env: loaderOptions.forceEnv || process.env.BABEL_ENV || process.env.NODE_ENV || "development"
90
118
  })
91
119
  };
92
120
 
93
- delete userOptions.forceEnv;
121
+ var options = Object.assign({}, defaultOptions, loaderOptions);
94
122
 
95
- var options = assign({}, defaultOptions, userOptions);
96
-
97
- if (userOptions.sourceMap === undefined) {
123
+ if (loaderOptions.sourceMap === undefined) {
98
124
  options.sourceMap = this.sourceMap;
99
125
  }
100
126
 
@@ -104,34 +130,44 @@ module.exports = function (source, inputSourceMap) {
104
130
 
105
131
  var cacheDirectory = options.cacheDirectory;
106
132
  var cacheIdentifier = options.cacheIdentifier;
133
+ var metadataSubscribers = options.metadataSubscribers;
107
134
 
108
135
  delete options.cacheDirectory;
109
136
  delete options.cacheIdentifier;
110
-
111
- this.cacheable();
137
+ delete options.metadataSubscribers;
112
138
 
113
139
  if (cacheDirectory) {
114
- var _ret = function () {
115
- var callback = _this.async();
116
- return {
117
- v: cache({
118
- directory: cacheDirectory,
119
- identifier: cacheIdentifier,
120
- source: source,
121
- options: options,
122
- transform: transpile
123
- }, function (err, result) {
124
- if (err) {
125
- return callback(err);
126
- }
127
- return callback(null, result.code, result.map);
128
- })
129
- };
130
- }();
131
-
132
- if ((typeof _ret === "undefined" ? "undefined" : _typeof(_ret)) === "object") return _ret.v;
140
+ var callback = this.async();
141
+ return cache({
142
+ directory: cacheDirectory,
143
+ identifier: cacheIdentifier,
144
+ source: source,
145
+ options: options,
146
+ transform: transpile
147
+ }, function (err) {
148
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
149
+ code = _ref.code,
150
+ map = _ref.map,
151
+ metadata = _ref.metadata;
152
+
153
+ if (err) return callback(err);
154
+
155
+ metadataSubscribers.forEach(function (s) {
156
+ return passMetadata(s, _this, metadata);
157
+ });
158
+
159
+ return callback(null, code, map);
160
+ });
133
161
  }
134
162
 
135
- result = transpile(source, options);
136
- this.callback(null, result.code, result.map);
163
+ var _transpile = transpile(source, options),
164
+ code = _transpile.code,
165
+ map = _transpile.map,
166
+ metadata = _transpile.metadata;
167
+
168
+ metadataSubscribers.forEach(function (s) {
169
+ return passMetadata(s, _this, metadata);
170
+ });
171
+
172
+ this.callback(null, code, map);
137
173
  };
package/lib/resolve-rc.js CHANGED
@@ -1,5 +1,13 @@
1
1
  "use strict";
2
2
 
3
+ /**
4
+ * The purpose of this module, is to find the project's .babelrc and
5
+ * use its contents to bust the babel-loader's internal cache whenever an option
6
+ * changes.
7
+ *
8
+ * @see https://github.com/babel/babel-loader/issues/62
9
+ * @see http://git.io/vLEvu
10
+ */
3
11
  var path = require("path");
4
12
  var exists = require("./utils/exists")({});
5
13
  var read = require("./utils/read")({});
@@ -15,13 +23,14 @@ var find = function find(start, rel) {
15
23
 
16
24
  var up = path.dirname(start);
17
25
  if (up !== start) {
26
+ // Reached root
18
27
  return find(up, rel);
19
28
  }
20
29
  };
21
30
 
22
31
  module.exports = function (loc, rel) {
23
32
  rel = rel || ".babelrc";
24
- var cacheKey = loc + "/" + rel;
33
+ var cacheKey = `${loc}/${rel}`;
25
34
  if (!(cacheKey in cache)) {
26
35
  cache[cacheKey] = find(loc, rel);
27
36
  }
@@ -1,17 +1,21 @@
1
1
  "use strict";
2
2
 
3
3
  var fs = require("fs");
4
-
4
+ /**
5
+ * Check if file exists and cache the result
6
+ * return the result in cache
7
+ *
8
+ * @example
9
+ * var exists = require('./helpers/fsExists')({});
10
+ * exists('.babelrc'); // false
11
+ */
5
12
  module.exports = function (cache) {
6
13
  cache = cache || {};
7
14
 
8
15
  return function (filename) {
16
+ if (!filename) return false;
9
17
 
10
- if (!filename) {
11
- return false;
12
- }
13
-
14
- cache[filename] = cache[filename] || fs.existsSync(filename);
18
+ cache[filename] = cache[filename] || fs.existsSync(filename) && fs.statSync(filename).isFile();
15
19
 
16
20
  return cache[filename];
17
21
  };
package/lib/utils/read.js CHANGED
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var fs = require("fs");
4
-
4
+ /**
5
+ * Read the file and cache the result
6
+ * return the result in cache
7
+ *
8
+ * @example
9
+ * var read = require('./helpers/fsExists')({});
10
+ * read('.babelrc'); // file contents...
11
+ */
5
12
  module.exports = function (cache) {
6
13
  cache = cache || {};
7
14
 
8
15
  return function (filename) {
9
-
10
16
  if (!filename) {
11
17
  throw new Error("filename must be a string");
12
18
  }
@@ -6,6 +6,7 @@ module.exports = function relative(sourceRoot, filename) {
6
6
  var rootPath = sourceRoot.replace(/\\/g, "/").split("/")[1];
7
7
  var fileRootPath = filename.replace(/\\/g, "/").split("/")[1];
8
8
 
9
+ // If the file is in a completely different root folder use the absolute path of file.
9
10
  if (rootPath && rootPath !== fileRootPath) {
10
11
  return filename;
11
12
  }
package/package.json CHANGED
@@ -1,48 +1,55 @@
1
1
  {
2
2
  "name": "babel-loader",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0",
4
4
  "description": "babel module loader for webpack",
5
5
  "files": [
6
6
  "lib"
7
7
  ],
8
8
  "main": "lib/index.js",
9
+ "engines": {
10
+ "node": ">=4"
11
+ },
9
12
  "dependencies": {
10
13
  "find-cache-dir": "^0.1.1",
11
- "loader-utils": "^0.2.16",
12
- "mkdirp": "^0.5.1",
13
- "object-assign": "^4.0.1"
14
+ "loader-utils": "^1.0.2",
15
+ "mkdirp": "^0.5.1"
14
16
  },
15
17
  "peerDependencies": {
16
18
  "babel-core": "6 || 7 || ^7.0.0-alpha || ^7.0.0-beta || ^7.0.0-rc",
17
- "webpack": "1 || 2 || ^2.1.0-beta || ^2.2.0-rc"
19
+ "webpack": "2"
18
20
  },
19
21
  "devDependencies": {
20
- "ava": "^0.18.0",
22
+ "ava": "^0.19.0",
21
23
  "babel-cli": "^6.18.0",
22
24
  "babel-core": "^6.0.0",
23
25
  "babel-eslint": "^7.1.0",
24
26
  "babel-plugin-istanbul": "^4.0.0",
25
- "babel-preset-es2015": "^6.0.0",
26
- "babel-preset-latest": "^6.16.0",
27
+ "babel-plugin-react-intl": "^2.1.3",
28
+ "babel-preset-env": "^1.2.0",
27
29
  "babel-register": "^6.18.0",
28
- "codecov": "^1.0.1",
29
- "cross-env": "^3.1.4",
30
+ "cross-env": "^4.0.0",
30
31
  "eslint": "^3.8.1",
31
32
  "eslint-config-babel": "^6.0.0",
32
33
  "eslint-plugin-flowtype": "^2.25.0",
34
+ "husky": "^0.13.2",
35
+ "lint-staged": "^3.3.1",
33
36
  "nyc": "^10.0.0",
37
+ "prettier": "^1.2.2",
38
+ "react": "^15.1.0",
39
+ "react-intl": "^2.1.2",
40
+ "react-intl-webpack-plugin": "^0.0.3",
34
41
  "rimraf": "^2.4.3",
35
- "webpack": "^2.2.0-rc"
42
+ "webpack": "^2.2.0"
36
43
  },
37
44
  "scripts": {
38
45
  "clean": "rimraf lib/",
39
46
  "build": "babel src/ --out-dir lib/",
40
- "coverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json",
47
+ "format": "prettier --write --trailing-comma all \"src/**/*.js\" \"test/*.test.js\" \"test/helpers/*.js\" && prettier --write --trailing-comma es5 \"scripts/*.js\"",
41
48
  "lint": "eslint src test",
42
- "preversion": "yarn test",
43
- "prepublish": "yarn clean && yarn build",
44
- "test": "yarn lint && cross-env BABEL_ENV=test yarn build && yarn test-only",
45
- "test-ci": "cross-env BABEL_ENV=test yarn build && yarn test-only",
49
+ "precommit": "lint-staged",
50
+ "prepublish": "yarn run clean && yarn run build",
51
+ "preversion": "yarn run test",
52
+ "test": "yarn run lint && cross-env BABEL_ENV=test yarn run build && yarn run test-only",
46
53
  "test-only": "nyc ava"
47
54
  },
48
55
  "repository": {
@@ -68,6 +75,10 @@
68
75
  "include": [
69
76
  "src/**/*.js"
70
77
  ],
78
+ "reporter": [
79
+ "text",
80
+ "json"
81
+ ],
71
82
  "require": [
72
83
  "babel-register"
73
84
  ],
@@ -84,5 +95,27 @@
84
95
  "src/**/*.js"
85
96
  ],
86
97
  "babel": "inherit"
98
+ },
99
+ "lint-staged": {
100
+ "scripts/*.js": [
101
+ "prettier --trailing-comma es5 --write",
102
+ "git add"
103
+ ],
104
+ "src/**/*.js": [
105
+ "prettier --trailing-comma all --write",
106
+ "git add"
107
+ ],
108
+ "test/**/*.test.js": [
109
+ "prettier --trailing-comma all --write",
110
+ "git add"
111
+ ],
112
+ "test/helpers/*.js": [
113
+ "prettier --trailing-comma all --write",
114
+ "git add"
115
+ ],
116
+ "package.json": [
117
+ "node ./scripts/yarn-install.js",
118
+ "git add yarn.lock"
119
+ ]
87
120
  }
88
121
  }