babel-loader 8.0.0-beta.3 → 8.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/README.md +6 -6
- package/lib/cache.js +12 -12
- package/lib/transform.js +50 -5
- package/package.json +2 -2
package/README.md
CHANGED
@@ -22,16 +22,16 @@ __Notes:__ Issues with the output should be reported on the babel [issue tracker
|
|
22
22
|
|
23
23
|
<h2 align="center">Install</h2>
|
24
24
|
|
25
|
-
> webpack
|
25
|
+
> webpack 4.x | babel-loader 8.x | babel 7.x
|
26
26
|
|
27
27
|
```bash
|
28
|
-
npm install
|
28
|
+
npm install babel-loader @babel/core @babel/preset-env webpack
|
29
29
|
```
|
30
30
|
|
31
|
-
> webpack
|
31
|
+
> webpack 4.x | babel-loader 7.x | babel 6.x
|
32
32
|
|
33
33
|
```bash
|
34
|
-
npm install babel-loader babel-core babel-preset-env webpack
|
34
|
+
npm install babel-loader@7 babel-core babel-preset-env webpack
|
35
35
|
```
|
36
36
|
|
37
37
|
<h2 align="center">Usage</h2>
|
@@ -116,7 +116,7 @@ You can instead require the babel runtime as a separate module to avoid the dupl
|
|
116
116
|
The following configuration disables automatic per-file runtime injection in babel, instead
|
117
117
|
requiring `babel-plugin-transform-runtime` and making all helper references use it.
|
118
118
|
|
119
|
-
See the [docs](
|
119
|
+
See the [docs](https://babeljs.io/docs/plugins/transform-runtime/) for more information.
|
120
120
|
|
121
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`.
|
122
122
|
|
@@ -281,4 +281,4 @@ be passed to `babel.transform`.
|
|
281
281
|
Given Babel's result object, allow loaders to make additional tweaks to it.
|
282
282
|
|
283
283
|
|
284
|
-
## [License](
|
284
|
+
## [License](https://couto.mit-license.org/)
|
package/lib/cache.js
CHANGED
@@ -89,14 +89,14 @@ function () {
|
|
89
89
|
|
90
90
|
|
91
91
|
const filename = function (source, identifier, options) {
|
92
|
-
const hash = crypto.createHash("
|
92
|
+
const hash = crypto.createHash("md4");
|
93
93
|
const contents = JSON.stringify({
|
94
94
|
source,
|
95
95
|
options,
|
96
96
|
identifier
|
97
97
|
});
|
98
|
-
hash.
|
99
|
-
return hash.
|
98
|
+
hash.update(contents);
|
99
|
+
return hash.digest("hex") + ".json.gz";
|
100
100
|
};
|
101
101
|
/**
|
102
102
|
* Handle the cache
|
@@ -116,6 +116,14 @@ function () {
|
|
116
116
|
cacheIdentifier,
|
117
117
|
cacheDirectory
|
118
118
|
} = params;
|
119
|
+
const file = path.join(directory, filename(source, cacheIdentifier, options));
|
120
|
+
|
121
|
+
try {
|
122
|
+
// No errors mean that the file was previously cached
|
123
|
+
// we just need to return it
|
124
|
+
return yield read(file);
|
125
|
+
} catch (err) {}
|
126
|
+
|
119
127
|
const fallback = typeof cacheDirectory !== "string" && directory !== os.tmpdir(); // Make sure the directory exists.
|
120
128
|
|
121
129
|
try {
|
@@ -126,15 +134,7 @@ function () {
|
|
126
134
|
}
|
127
135
|
|
128
136
|
throw err;
|
129
|
-
}
|
130
|
-
|
131
|
-
const file = path.join(directory, filename(source, cacheIdentifier, options));
|
132
|
-
|
133
|
-
try {
|
134
|
-
// No errors mean that the file was previously cached
|
135
|
-
// we just need to return it
|
136
|
-
return yield read(file);
|
137
|
-
} catch (err) {} // Otherwise just transform the file
|
137
|
+
} // Otherwise just transform the file
|
138
138
|
// return it to the user asap and write it in cache
|
139
139
|
|
140
140
|
|
package/lib/transform.js
CHANGED
@@ -17,16 +17,23 @@ function () {
|
|
17
17
|
let result;
|
18
18
|
|
19
19
|
try {
|
20
|
-
result = yield transform(source, options);
|
20
|
+
result = yield transform(source, injectCaller(options));
|
21
21
|
} catch (err) {
|
22
22
|
throw err.message && err.codeFrame ? new LoaderError(err) : err;
|
23
23
|
}
|
24
24
|
|
25
|
-
if (!result) return null;
|
25
|
+
if (!result) return null; // We don't return the full result here because some entries are not
|
26
|
+
// really serializable. For a full list of properties see here:
|
27
|
+
// https://github.com/babel/babel/blob/master/packages/babel-core/src/transformation/index.js
|
28
|
+
// For discussion on this topic see here:
|
29
|
+
// https://github.com/babel/babel-loader/pull/629
|
30
|
+
|
26
31
|
const {
|
32
|
+
ast,
|
27
33
|
code,
|
28
34
|
map,
|
29
|
-
metadata
|
35
|
+
metadata,
|
36
|
+
sourceType
|
30
37
|
} = result;
|
31
38
|
|
32
39
|
if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
|
@@ -34,9 +41,11 @@ function () {
|
|
34
41
|
}
|
35
42
|
|
36
43
|
return {
|
44
|
+
ast,
|
37
45
|
code,
|
38
46
|
map,
|
39
|
-
metadata
|
47
|
+
metadata,
|
48
|
+
sourceType
|
40
49
|
};
|
41
50
|
});
|
42
51
|
|
@@ -45,4 +54,40 @@ function () {
|
|
45
54
|
};
|
46
55
|
}();
|
47
56
|
|
48
|
-
module.exports.version = babel.version;
|
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
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "babel-loader",
|
3
|
-
"version": "8.0.0
|
3
|
+
"version": "8.0.0",
|
4
4
|
"description": "babel module loader for webpack",
|
5
5
|
"files": [
|
6
6
|
"lib"
|
@@ -16,7 +16,7 @@
|
|
16
16
|
"util.promisify": "^1.0.0"
|
17
17
|
},
|
18
18
|
"peerDependencies": {
|
19
|
-
"@babel/core": "^7.0.0
|
19
|
+
"@babel/core": "^7.0.0",
|
20
20
|
"webpack": ">=2"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|