babel-loader 7.0.0-alpha.3 โ†’ 7.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
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
+
3
13
  ## v6.4.0
4
14
 
5
15
  ### ๐Ÿš€ New Feature
@@ -32,7 +42,7 @@ Allow to override BABEL_ENV/NODE_ENV at loader-level. Useful for isomorphic appl
32
42
 
33
43
  ### ๐Ÿ’… Polish
34
44
 
35
- - 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
36
46
 
37
47
  ## v6.2.10
38
48
 
package/README.md CHANGED
@@ -19,6 +19,12 @@ __Notes:__ Issues with the output should be reported on the babel [issue tracker
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,11 +4,12 @@ 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.
@@ -47,7 +48,7 @@ var transpile = function transpile(source, options) {
47
48
  try {
48
49
  result = babel.transform(source, options);
49
50
  } catch (error) {
50
- if (forceEnv) process.env.BABEL_ENV = tmpEnv;
51
+ if (forceEnv) restoreBabelEnv(tmpEnv);
51
52
  if (error.message && error.codeFrame) {
52
53
  var message = error.message;
53
54
  var name = void 0;
@@ -73,7 +74,7 @@ var transpile = function transpile(source, options) {
73
74
  map.sourcesContent = [source];
74
75
  }
75
76
 
76
- if (forceEnv) process.env.BABEL_ENV = tmpEnv;
77
+ if (forceEnv) restoreBabelEnv(tmpEnv);
77
78
 
78
79
  return {
79
80
  code: code,
@@ -82,6 +83,14 @@ var transpile = function transpile(source, options) {
82
83
  };
83
84
  };
84
85
 
86
+ function restoreBabelEnv(prevValue) {
87
+ if (prevValue === undefined) {
88
+ delete process.env.BABEL_ENV;
89
+ } else {
90
+ process.env.BABEL_ENV = prevValue;
91
+ }
92
+ }
93
+
85
94
  function passMetadata(s, context, metadata) {
86
95
  if (context[s]) {
87
96
  context[s](metadata);
@@ -97,6 +106,16 @@ module.exports = function (source, inputSourceMap) {
97
106
 
98
107
  // Handle options
99
108
  var loaderOptions = loaderUtils.getOptions(this) || {};
109
+ var fileSystem = this.fs ? this.fs : fs;
110
+ var babelrcPath = null;
111
+ if (loaderOptions.babelrc !== false) {
112
+ babelrcPath = exists(fileSystem, loaderOptions.babelrc) ? loaderOptions.babelrc : resolveRc(fileSystem, path.dirname(filename));
113
+ }
114
+
115
+ if (babelrcPath) {
116
+ this.addDependency(babelrcPath);
117
+ }
118
+
100
119
  var defaultOptions = {
101
120
  metadataSubscribers: [],
102
121
  inputSourceMap: inputSourceMap,
@@ -105,7 +124,7 @@ module.exports = function (source, inputSourceMap) {
105
124
  cacheIdentifier: JSON.stringify({
106
125
  "babel-loader": pkg.version,
107
126
  "babel-core": babel.version,
108
- babelrc: exists(loaderOptions.babelrc) ? read(loaderOptions.babelrc) : resolveRc(path.dirname(filename)),
127
+ babelrc: babelrcPath ? read(fileSystem, babelrcPath) : null,
109
128
  env: loaderOptions.forceEnv || process.env.BABEL_ENV || process.env.NODE_ENV || "development"
110
129
  })
111
130
  };
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,11 @@
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 (e) {}
16
9
 
17
- if (!filename) {
18
- return false;
19
- }
20
-
21
- cache[filename] = cache[filename] || fs.existsSync(filename);
22
-
23
- return cache[filename];
24
- };
10
+ return exists;
25
11
  };
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-alpha.3",
3
+ "version": "7.1.1",
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.19.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
  }