babel-loader 7.0.0-beta.1 โ†’ 7.1.2

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,9 @@
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
+
3
7
  ## v6.4.1
4
8
 
5
9
  ### ๐Ÿ› Bug Fix
@@ -38,7 +42,7 @@ Allow to override BABEL_ENV/NODE_ENV at loader-level. Useful for isomorphic appl
38
42
 
39
43
  ### ๐Ÿ’… Polish
40
44
 
41
- - Improve FS caching to do less sync calls which improves performance slightly (#375) @akx
45
+ - Improve FS caching to do less sync calls which improves performance slightly (#375) @akx
42
46
 
43
47
  ## v6.2.10
44
48
 
package/README.md CHANGED
@@ -15,10 +15,16 @@
15
15
 
16
16
  This package allows transpiling JavaScript files using [Babel](https://github.com/babel/babel) and [webpack](https://github.com/webpack/webpack).
17
17
 
18
- __Notes:__ Issues with the output should be reported on the babel [issue tracker](https://github.com/babel/babel/issues);
18
+ __Notes:__ Issues with the output should be reported on the babel [issue tracker](https://github.com/babel/babel/issues).
19
19
 
20
20
  <h2 align="center">Install</h2>
21
21
 
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)
25
+ >
26
+ > webpack 3.x | babel-loader >= 7.1
27
+
22
28
  ```bash
23
29
  yarn add babel-loader babel-core babel-preset-env webpack --dev
24
30
  ```
@@ -56,6 +62,7 @@ module: {
56
62
 
57
63
  See the `babel` [options](https://babeljs.io/docs/usage/api/#options).
58
64
 
65
+
59
66
  You can pass options to the loader by using the [options property](https://webpack.js.org/configuration/module/#rule-options-rule-query):
60
67
 
61
68
  ```javascript
package/lib/fs-cache.js CHANGED
@@ -28,16 +28,12 @@ var defaultCacheDirectory = null; // Lazily instantiated when needed
28
28
  */
29
29
  var read = function read(filename, callback) {
30
30
  return fs.readFile(filename, function (err, data) {
31
- if (err) {
32
- return callback(err);
33
- }
31
+ if (err) return callback(err);
34
32
 
35
33
  return zlib.gunzip(data, function (err, content) {
36
- var result = {};
34
+ if (err) return callback(err);
37
35
 
38
- if (err) {
39
- return callback(err);
40
- }
36
+ var result = {};
41
37
 
42
38
  try {
43
39
  result = JSON.parse(content);
@@ -62,9 +58,7 @@ var write = function write(filename, result, callback) {
62
58
  var content = JSON.stringify(result);
63
59
 
64
60
  return zlib.gzip(content, function (err, data) {
65
- if (err) {
66
- return callback(err);
67
- }
61
+ if (err) return callback(err);
68
62
 
69
63
  return fs.writeFile(filename, data, callback);
70
64
  });
package/lib/index.js CHANGED
@@ -4,23 +4,25 @@ var babel = require("babel-core");
4
4
  var loaderUtils = require("loader-utils");
5
5
  var path = require("path");
6
6
  var cache = require("./fs-cache.js");
7
- var exists = require("./utils/exists")();
7
+ var exists = require("./utils/exists");
8
8
  var relative = require("./utils/relative");
9
- var read = require("./utils/read")();
9
+ var read = require("./utils/read");
10
10
  var resolveRc = require("./resolve-rc.js");
11
11
  var pkg = require("../package.json");
12
+ var fs = require("fs");
12
13
 
13
14
  /**
14
15
  * Error thrown by Babel formatted to conform to Webpack reporting.
15
16
  */
16
17
  function BabelLoaderError(name, message, codeFrame, hideStack, error) {
17
18
  Error.call(this);
18
- Error.captureStackTrace(this, BabelLoaderError);
19
19
 
20
20
  this.name = "BabelLoaderError";
21
21
  this.message = formatMessage(name, message, codeFrame);
22
22
  this.hideStack = hideStack;
23
23
  this.error = error;
24
+
25
+ Error.captureStackTrace(this, BabelLoaderError);
24
26
  }
25
27
 
26
28
  BabelLoaderError.prototype = Object.create(Error.prototype);
@@ -105,6 +107,16 @@ module.exports = function (source, inputSourceMap) {
105
107
 
106
108
  // Handle options
107
109
  var loaderOptions = loaderUtils.getOptions(this) || {};
110
+ var fileSystem = this.fs ? this.fs : fs;
111
+ var babelrcPath = null;
112
+ if (loaderOptions.babelrc !== false) {
113
+ babelrcPath = typeof loaderOptions.babelrc === "string" && exists(fileSystem, loaderOptions.babelrc) ? loaderOptions.babelrc : resolveRc(fileSystem, path.dirname(filename));
114
+ }
115
+
116
+ if (babelrcPath) {
117
+ this.addDependency(babelrcPath);
118
+ }
119
+
108
120
  var defaultOptions = {
109
121
  metadataSubscribers: [],
110
122
  inputSourceMap: inputSourceMap,
@@ -113,7 +125,7 @@ module.exports = function (source, inputSourceMap) {
113
125
  cacheIdentifier: JSON.stringify({
114
126
  "babel-loader": pkg.version,
115
127
  "babel-core": babel.version,
116
- babelrc: exists(loaderOptions.babelrc) ? read(loaderOptions.babelrc) : resolveRc(path.dirname(filename)),
128
+ babelrc: babelrcPath ? read(fileSystem, babelrcPath) : null,
117
129
  env: loaderOptions.forceEnv || process.env.BABEL_ENV || process.env.NODE_ENV || "development"
118
130
  })
119
131
  };
package/lib/resolve-rc.js CHANGED
@@ -1,38 +1,26 @@
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
- */
11
3
  var path = require("path");
12
- var exists = require("./utils/exists")({});
13
- var read = require("./utils/read")({});
4
+ var exists = require("./utils/exists");
14
5
 
15
- var cache = {};
6
+ module.exports = function find(fileSystem, start) {
7
+ var _arr = [".babelrc", ".babelrc.js", "package.json"];
16
8
 
17
- var find = function find(start, rel) {
18
- var file = path.join(start, rel);
9
+ for (var _i = 0; _i < _arr.length; _i++) {
10
+ var fileName = _arr[_i];
11
+ var file = path.join(start, fileName);
19
12
 
20
- if (exists(file)) {
21
- return read(file);
13
+ if (exists(fileSystem, file)) {
14
+ if (fileName !== "package.json" || typeof require(file).babel === "object") {
15
+ return file;
16
+ }
17
+ }
22
18
  }
23
19
 
24
20
  var up = path.dirname(start);
25
- if (up !== start) {
26
- // Reached root
27
- return find(up, rel);
28
- }
29
- };
30
21
 
31
- module.exports = function (loc, rel) {
32
- rel = rel || ".babelrc";
33
- var cacheKey = `${loc}/${rel}`;
34
- if (!(cacheKey in cache)) {
35
- cache[cacheKey] = find(loc, rel);
22
+ // Reached root
23
+ if (up !== start) {
24
+ return find(fileSystem, up);
36
25
  }
37
- return cache[cacheKey];
38
26
  };
@@ -1,25 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var fs = require("fs");
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
- */
12
- module.exports = function (cache) {
13
- cache = cache || {};
3
+ module.exports = function (fileSystem, filename) {
4
+ var exists = false;
14
5
 
15
- return function (filename) {
6
+ try {
7
+ exists = fileSystem.statSync(filename).isFile();
8
+ } catch (err) {
9
+ if (err.code !== "ENOENT") throw err;
10
+ }
16
11
 
17
- if (!filename) {
18
- return false;
19
- }
20
-
21
- cache[filename] = cache[filename] || fs.existsSync(filename);
22
-
23
- return cache[filename];
24
- };
12
+ return exists;
25
13
  };
package/lib/utils/read.js CHANGED
@@ -1,25 +1,14 @@
1
1
  "use strict";
2
2
 
3
- var fs = require("fs");
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
- */
12
- module.exports = function (cache) {
13
- cache = cache || {};
3
+ var path = require("path");
14
4
 
15
- return function (filename) {
5
+ module.exports = function readBabelConfig(fileSystem, filename) {
6
+ if (path.basename(filename) === "package.json") {
7
+ var pkg = require(filename);
16
8
 
17
- if (!filename) {
18
- throw new Error("filename must be a string");
19
- }
9
+ return JSON.stringify(pkg.babel);
10
+ }
20
11
 
21
- cache[filename] = cache[filename] || fs.readFileSync(filename, "utf8");
22
-
23
- return cache[filename];
24
- };
12
+ // Webpack `fs` return Buffer
13
+ return fileSystem.readFileSync(filename).toString("utf8");
25
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-loader",
3
- "version": "7.0.0-beta.1",
3
+ "version": "7.1.2",
4
4
  "description": "babel module loader for webpack",
5
5
  "files": [
6
6
  "lib"
@@ -10,16 +10,16 @@
10
10
  "node": ">=4"
11
11
  },
12
12
  "dependencies": {
13
- "find-cache-dir": "^0.1.1",
13
+ "find-cache-dir": "^1.0.0",
14
14
  "loader-utils": "^1.0.2",
15
15
  "mkdirp": "^0.5.1"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "babel-core": "6 || 7 || ^7.0.0-alpha || ^7.0.0-beta || ^7.0.0-rc",
19
- "webpack": "2"
19
+ "webpack": "2 || 3"
20
20
  },
21
21
  "devDependencies": {
22
- "ava": "^0.18.0",
22
+ "ava": "^0.22.0",
23
23
  "babel-cli": "^6.18.0",
24
24
  "babel-core": "^6.0.0",
25
25
  "babel-eslint": "^7.1.0",
@@ -27,27 +27,30 @@
27
27
  "babel-plugin-react-intl": "^2.1.3",
28
28
  "babel-preset-env": "^1.2.0",
29
29
  "babel-register": "^6.18.0",
30
- "codecov": "^1.0.1",
31
- "cross-env": "^3.1.4",
32
- "eslint": "^3.8.1",
33
- "eslint-config-babel": "^6.0.0",
30
+ "cross-env": "^5.0.0",
31
+ "eslint": "^4.1.0",
32
+ "eslint-config-babel": "^7.0.0",
34
33
  "eslint-plugin-flowtype": "^2.25.0",
35
- "nyc": "^10.0.0",
34
+ "eslint-plugin-prettier": "^2.1.2",
35
+ "husky": "^0.14.0",
36
+ "lint-staged": "^4.0.0",
37
+ "nyc": "^11.0.1",
38
+ "prettier": "^1.2.2",
36
39
  "react": "^15.1.0",
37
40
  "react-intl": "^2.1.2",
38
41
  "react-intl-webpack-plugin": "^0.0.3",
39
42
  "rimraf": "^2.4.3",
40
- "webpack": "^2.2.0"
43
+ "webpack": "^3.0.0"
41
44
  },
42
45
  "scripts": {
43
46
  "clean": "rimraf lib/",
44
47
  "build": "babel src/ --out-dir lib/",
45
- "coverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json",
48
+ "format": "prettier --write --trailing-comma all \"src/**/*.js\" \"test/**/*.test.js\" \"test/helpers/*.js\" && prettier --write --trailing-comma es5 \"scripts/*.js\"",
46
49
  "lint": "eslint src test",
47
- "preversion": "yarn run test",
50
+ "precommit": "lint-staged",
48
51
  "prepublish": "yarn run clean && yarn run build",
52
+ "preversion": "yarn run test",
49
53
  "test": "yarn run lint && cross-env BABEL_ENV=test yarn run build && yarn run test-only",
50
- "test-ci": "cross-env BABEL_ENV=test yarn run build && yarn run test-only",
51
54
  "test-only": "nyc ava"
52
55
  },
53
56
  "repository": {
@@ -73,6 +76,10 @@
73
76
  "include": [
74
77
  "src/**/*.js"
75
78
  ],
79
+ "reporter": [
80
+ "text",
81
+ "json"
82
+ ],
76
83
  "require": [
77
84
  "babel-register"
78
85
  ],
@@ -89,5 +96,27 @@
89
96
  "src/**/*.js"
90
97
  ],
91
98
  "babel": "inherit"
99
+ },
100
+ "lint-staged": {
101
+ "scripts/*.js": [
102
+ "prettier --trailing-comma es5 --write",
103
+ "git add"
104
+ ],
105
+ "src/**/*.js": [
106
+ "prettier --trailing-comma all --write",
107
+ "git add"
108
+ ],
109
+ "test/**/*.test.js": [
110
+ "prettier --trailing-comma all --write",
111
+ "git add"
112
+ ],
113
+ "test/helpers/*.js": [
114
+ "prettier --trailing-comma all --write",
115
+ "git add"
116
+ ],
117
+ "package.json": [
118
+ "node ./scripts/yarn-install.js",
119
+ "git add yarn.lock"
120
+ ]
92
121
  }
93
122
  }