babel-loader 8.2.5 → 8.3.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/lib/Error.js +0 -5
- package/lib/cache.js +25 -48
- package/lib/index.js +22 -57
- package/lib/injectCaller.js +3 -6
- package/lib/transform.js +7 -15
- package/package.json +7 -4
package/lib/Error.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
const STRIP_FILENAME_RE = /^[^:]+: /;
|
4
|
-
|
5
4
|
const format = err => {
|
6
5
|
if (err instanceof SyntaxError) {
|
7
6
|
err.name = "SyntaxError";
|
@@ -12,10 +11,8 @@ const format = err => {
|
|
12
11
|
err.message = err.message.replace(STRIP_FILENAME_RE, "");
|
13
12
|
err.hideStack = true;
|
14
13
|
}
|
15
|
-
|
16
14
|
return err;
|
17
15
|
};
|
18
|
-
|
19
16
|
class LoaderError extends Error {
|
20
17
|
constructor(err) {
|
21
18
|
super();
|
@@ -30,7 +27,5 @@ class LoaderError extends Error {
|
|
30
27
|
this.hideStack = hideStack;
|
31
28
|
Error.captureStackTrace(this, this.constructor);
|
32
29
|
}
|
33
|
-
|
34
30
|
}
|
35
|
-
|
36
31
|
module.exports = LoaderError;
|
package/lib/cache.js
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
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
4
|
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); }); }; }
|
6
|
-
|
7
5
|
/**
|
8
6
|
* Filesystem Cache
|
9
7
|
*
|
@@ -14,39 +12,30 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
14
12
|
* @see https://github.com/babel/babel-loader/pull/41
|
15
13
|
*/
|
16
14
|
const fs = require("fs");
|
17
|
-
|
18
15
|
const os = require("os");
|
19
|
-
|
20
16
|
const path = require("path");
|
21
|
-
|
22
17
|
const zlib = require("zlib");
|
23
|
-
|
24
18
|
const crypto = require("crypto");
|
25
|
-
|
26
19
|
const findCacheDir = require("find-cache-dir");
|
27
|
-
|
28
20
|
const {
|
29
21
|
promisify
|
30
22
|
} = require("util");
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
23
|
+
const transform = require("./transform");
|
24
|
+
// Lazily instantiated when needed
|
35
25
|
let defaultCacheDirectory = null;
|
36
|
-
let hashType = "
|
37
|
-
|
26
|
+
let hashType = "sha256";
|
27
|
+
// use md5 hashing if sha256 is not available
|
38
28
|
try {
|
39
29
|
crypto.createHash(hashType);
|
40
30
|
} catch (err) {
|
41
31
|
hashType = "md5";
|
42
32
|
}
|
43
|
-
|
44
33
|
const readFile = promisify(fs.readFile);
|
45
34
|
const writeFile = promisify(fs.writeFile);
|
46
35
|
const gunzip = promisify(zlib.gunzip);
|
47
36
|
const gzip = promisify(zlib.gzip);
|
48
|
-
|
49
37
|
const makeDir = require("make-dir");
|
38
|
+
|
50
39
|
/**
|
51
40
|
* Read the contents from the compressed file.
|
52
41
|
*
|
@@ -54,19 +43,17 @@ const makeDir = require("make-dir");
|
|
54
43
|
* @params {String} filename
|
55
44
|
* @params {Boolean} compress
|
56
45
|
*/
|
57
|
-
|
58
|
-
|
59
46
|
const read = /*#__PURE__*/function () {
|
60
47
|
var _ref = _asyncToGenerator(function* (filename, compress) {
|
61
48
|
const data = yield readFile(filename + (compress ? ".gz" : ""));
|
62
49
|
const content = compress ? yield gunzip(data) : data;
|
63
50
|
return JSON.parse(content.toString());
|
64
51
|
});
|
65
|
-
|
66
52
|
return function read(_x, _x2) {
|
67
53
|
return _ref.apply(this, arguments);
|
68
54
|
};
|
69
55
|
}();
|
56
|
+
|
70
57
|
/**
|
71
58
|
* Write contents into a compressed file.
|
72
59
|
*
|
@@ -75,19 +62,17 @@ const read = /*#__PURE__*/function () {
|
|
75
62
|
* @params {Boolean} compress
|
76
63
|
* @params {String} result
|
77
64
|
*/
|
78
|
-
|
79
|
-
|
80
65
|
const write = /*#__PURE__*/function () {
|
81
66
|
var _ref2 = _asyncToGenerator(function* (filename, compress, result) {
|
82
67
|
const content = JSON.stringify(result);
|
83
68
|
const data = compress ? yield gzip(content) : content;
|
84
69
|
return yield writeFile(filename + (compress ? ".gz" : ""), data);
|
85
70
|
});
|
86
|
-
|
87
71
|
return function write(_x3, _x4, _x5) {
|
88
72
|
return _ref2.apply(this, arguments);
|
89
73
|
};
|
90
74
|
}();
|
75
|
+
|
91
76
|
/**
|
92
77
|
* Build the filename for the cached file
|
93
78
|
*
|
@@ -96,8 +81,6 @@ const write = /*#__PURE__*/function () {
|
|
96
81
|
*
|
97
82
|
* @return {String}
|
98
83
|
*/
|
99
|
-
|
100
|
-
|
101
84
|
const filename = function (source, identifier, options) {
|
102
85
|
const hash = crypto.createHash(hashType);
|
103
86
|
const contents = JSON.stringify({
|
@@ -108,14 +91,13 @@ const filename = function (source, identifier, options) {
|
|
108
91
|
hash.update(contents);
|
109
92
|
return hash.digest("hex") + ".json";
|
110
93
|
};
|
94
|
+
|
111
95
|
/**
|
112
96
|
* Handle the cache
|
113
97
|
*
|
114
98
|
* @params {String} directory
|
115
99
|
* @params {Object} params
|
116
100
|
*/
|
117
|
-
|
118
|
-
|
119
101
|
const handleCache = /*#__PURE__*/function () {
|
120
102
|
var _ref3 = _asyncToGenerator(function* (directory, params) {
|
121
103
|
const {
|
@@ -126,47 +108,47 @@ const handleCache = /*#__PURE__*/function () {
|
|
126
108
|
cacheCompression
|
127
109
|
} = params;
|
128
110
|
const file = path.join(directory, filename(source, cacheIdentifier, options));
|
129
|
-
|
130
111
|
try {
|
131
112
|
// No errors mean that the file was previously cached
|
132
113
|
// we just need to return it
|
133
114
|
return yield read(file, cacheCompression);
|
134
115
|
} catch (err) {}
|
116
|
+
const fallback = typeof cacheDirectory !== "string" && directory !== os.tmpdir();
|
135
117
|
|
136
|
-
|
137
|
-
|
118
|
+
// Make sure the directory exists.
|
138
119
|
try {
|
139
120
|
yield makeDir(directory);
|
140
121
|
} catch (err) {
|
141
122
|
if (fallback) {
|
142
123
|
return handleCache(os.tmpdir(), params);
|
143
124
|
}
|
144
|
-
|
145
125
|
throw err;
|
146
|
-
}
|
147
|
-
// return it to the user asap and write it in cache
|
148
|
-
|
126
|
+
}
|
149
127
|
|
128
|
+
// Otherwise just transform the file
|
129
|
+
// return it to the user asap and write it in cache
|
150
130
|
const result = yield transform(source, options);
|
151
131
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
132
|
+
// Do not cache if there are external dependencies,
|
133
|
+
// since they might change and we cannot control it.
|
134
|
+
if (!result.externalDependencies.length) {
|
135
|
+
try {
|
136
|
+
yield write(file, cacheCompression, result);
|
137
|
+
} catch (err) {
|
138
|
+
if (fallback) {
|
139
|
+
// Fallback to tmpdir if node_modules folder not writable
|
140
|
+
return handleCache(os.tmpdir(), params);
|
141
|
+
}
|
142
|
+
throw err;
|
158
143
|
}
|
159
|
-
|
160
|
-
throw err;
|
161
144
|
}
|
162
|
-
|
163
145
|
return result;
|
164
146
|
});
|
165
|
-
|
166
147
|
return function handleCache(_x6, _x7) {
|
167
148
|
return _ref3.apply(this, arguments);
|
168
149
|
};
|
169
150
|
}();
|
151
|
+
|
170
152
|
/**
|
171
153
|
* Retrieve file from cache, or create a new one for future reads
|
172
154
|
*
|
@@ -192,11 +174,9 @@ const handleCache = /*#__PURE__*/function () {
|
|
192
174
|
* });
|
193
175
|
*/
|
194
176
|
|
195
|
-
|
196
177
|
module.exports = /*#__PURE__*/function () {
|
197
178
|
var _ref4 = _asyncToGenerator(function* (params) {
|
198
179
|
let directory;
|
199
|
-
|
200
180
|
if (typeof params.cacheDirectory === "string") {
|
201
181
|
directory = params.cacheDirectory;
|
202
182
|
} else {
|
@@ -205,13 +185,10 @@ module.exports = /*#__PURE__*/function () {
|
|
205
185
|
name: "babel-loader"
|
206
186
|
}) || os.tmpdir();
|
207
187
|
}
|
208
|
-
|
209
188
|
directory = defaultCacheDirectory;
|
210
189
|
}
|
211
|
-
|
212
190
|
return yield handleCache(directory, params);
|
213
191
|
});
|
214
|
-
|
215
192
|
return function (_x8) {
|
216
193
|
return _ref4.apply(this, arguments);
|
217
194
|
};
|
package/lib/index.js
CHANGED
@@ -1,56 +1,41 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
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
4
|
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); }); }; }
|
6
|
-
|
7
5
|
let babel;
|
8
|
-
|
9
6
|
try {
|
10
7
|
babel = require("@babel/core");
|
11
8
|
} catch (err) {
|
12
9
|
if (err.code === "MODULE_NOT_FOUND") {
|
13
10
|
err.message += "\n babel-loader@8 requires Babel 7.x (the package '@babel/core'). " + "If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'.";
|
14
11
|
}
|
15
|
-
|
16
12
|
throw err;
|
17
|
-
}
|
18
|
-
// people useful feedback if they try to use it alongside babel-loader.
|
19
|
-
|
13
|
+
}
|
20
14
|
|
15
|
+
// Since we've got the reverse bridge package at @babel/core@6.x, give
|
16
|
+
// people useful feedback if they try to use it alongside babel-loader.
|
21
17
|
if (/^6\./.test(babel.version)) {
|
22
18
|
throw new Error("\n babel-loader@8 will not work with the '@babel/core@6' bridge package. " + "If you want to use Babel 6.x, install 'babel-loader@7'.");
|
23
19
|
}
|
24
|
-
|
25
20
|
const {
|
26
21
|
version
|
27
22
|
} = require("../package.json");
|
28
|
-
|
29
23
|
const cache = require("./cache");
|
30
|
-
|
31
24
|
const transform = require("./transform");
|
32
|
-
|
33
25
|
const injectCaller = require("./injectCaller");
|
34
|
-
|
35
26
|
const schema = require("./schema");
|
36
|
-
|
37
27
|
const {
|
38
28
|
isAbsolute
|
39
29
|
} = require("path");
|
40
|
-
|
41
30
|
const loaderUtils = require("loader-utils");
|
42
|
-
|
43
31
|
const validateOptions = require("schema-utils");
|
44
|
-
|
45
32
|
function subscribe(subscriber, metadata, context) {
|
46
33
|
if (context[subscriber]) {
|
47
34
|
context[subscriber](metadata);
|
48
35
|
}
|
49
36
|
}
|
50
|
-
|
51
37
|
module.exports = makeLoader();
|
52
38
|
module.exports.custom = makeLoader;
|
53
|
-
|
54
39
|
function makeLoader(callback) {
|
55
40
|
const overrides = callback ? callback(babel) : undefined;
|
56
41
|
return function (source, inputSourceMap) {
|
@@ -59,11 +44,9 @@ function makeLoader(callback) {
|
|
59
44
|
loader.call(this, source, inputSourceMap, overrides).then(args => callback(null, ...args), err => callback(err));
|
60
45
|
};
|
61
46
|
}
|
62
|
-
|
63
47
|
function loader(_x, _x2, _x3) {
|
64
48
|
return _loader.apply(this, arguments);
|
65
49
|
}
|
66
|
-
|
67
50
|
function _loader() {
|
68
51
|
_loader = _asyncToGenerator(function* (source, inputSourceMap, overrides) {
|
69
52
|
const filename = this.resourcePath;
|
@@ -71,33 +54,24 @@ function _loader() {
|
|
71
54
|
validateOptions(schema, loaderOptions, {
|
72
55
|
name: "Babel loader"
|
73
56
|
});
|
74
|
-
|
75
57
|
if (loaderOptions.customize != null) {
|
76
58
|
if (typeof loaderOptions.customize !== "string") {
|
77
59
|
throw new Error("Customized loaders must be implemented as standalone modules.");
|
78
60
|
}
|
79
|
-
|
80
61
|
if (!isAbsolute(loaderOptions.customize)) {
|
81
62
|
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.");
|
82
63
|
}
|
83
|
-
|
84
64
|
if (overrides) {
|
85
65
|
throw new Error("babel-loader's 'customize' option is not available when already " + "using a customized babel-loader wrapper.");
|
86
66
|
}
|
87
|
-
|
88
67
|
let override = require(loaderOptions.customize);
|
89
|
-
|
90
68
|
if (override.__esModule) override = override.default;
|
91
|
-
|
92
69
|
if (typeof override !== "function") {
|
93
70
|
throw new Error("Custom overrides must be functions.");
|
94
71
|
}
|
95
|
-
|
96
72
|
overrides = override(babel);
|
97
73
|
}
|
98
|
-
|
99
74
|
let customOptions;
|
100
|
-
|
101
75
|
if (overrides && overrides.customOptions) {
|
102
76
|
const result = yield overrides.customOptions.call(this, loaderOptions, {
|
103
77
|
source,
|
@@ -105,27 +79,25 @@ function _loader() {
|
|
105
79
|
});
|
106
80
|
customOptions = result.custom;
|
107
81
|
loaderOptions = result.loader;
|
108
|
-
}
|
109
|
-
|
82
|
+
}
|
110
83
|
|
84
|
+
// Deprecation handling
|
111
85
|
if ("forceEnv" in loaderOptions) {
|
112
86
|
console.warn("The option `forceEnv` has been removed in favor of `envName` in Babel 7.");
|
113
87
|
}
|
114
|
-
|
115
88
|
if (typeof loaderOptions.babelrc === "string") {
|
116
89
|
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");
|
117
|
-
}
|
90
|
+
}
|
91
|
+
|
92
|
+
// Standardize on 'sourceMaps' as the key passed through to Webpack, so that
|
118
93
|
// users may safely use either one alongside our default use of
|
119
94
|
// 'this.sourceMap' below without getting error about conflicting aliases.
|
120
|
-
|
121
|
-
|
122
95
|
if (Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMap") && !Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMaps")) {
|
123
96
|
loaderOptions = Object.assign({}, loaderOptions, {
|
124
97
|
sourceMaps: loaderOptions.sourceMap
|
125
98
|
});
|
126
99
|
delete loaderOptions.sourceMap;
|
127
100
|
}
|
128
|
-
|
129
101
|
const programmaticOptions = Object.assign({}, loaderOptions, {
|
130
102
|
filename,
|
131
103
|
inputSourceMap: inputSourceMap || loaderOptions.inputSourceMap,
|
@@ -136,27 +108,24 @@ function _loader() {
|
|
136
108
|
// so that it can properly map the module back to its internal cached
|
137
109
|
// modules.
|
138
110
|
sourceFileName: filename
|
139
|
-
});
|
140
|
-
|
111
|
+
});
|
112
|
+
// Remove loader related options
|
141
113
|
delete programmaticOptions.customize;
|
142
114
|
delete programmaticOptions.cacheDirectory;
|
143
115
|
delete programmaticOptions.cacheIdentifier;
|
144
116
|
delete programmaticOptions.cacheCompression;
|
145
117
|
delete programmaticOptions.metadataSubscribers;
|
146
|
-
|
147
118
|
if (!babel.loadPartialConfig) {
|
148
119
|
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`);
|
149
|
-
}
|
150
|
-
|
120
|
+
}
|
151
121
|
|
122
|
+
// babel.loadPartialConfigAsync is available in v7.8.0+
|
152
123
|
const {
|
153
124
|
loadPartialConfigAsync = babel.loadPartialConfig
|
154
125
|
} = babel;
|
155
126
|
const config = yield loadPartialConfigAsync(injectCaller(programmaticOptions, this.target));
|
156
|
-
|
157
127
|
if (config) {
|
158
128
|
let options = config.options;
|
159
|
-
|
160
129
|
if (overrides && overrides.config) {
|
161
130
|
options = yield overrides.config.call(this, config, {
|
162
131
|
source,
|
@@ -164,7 +133,6 @@ function _loader() {
|
|
164
133
|
customOptions
|
165
134
|
});
|
166
135
|
}
|
167
|
-
|
168
136
|
if (options.sourceMaps === "inline") {
|
169
137
|
// Babel has this weird behavior where if you set "inline", we
|
170
138
|
// inline the sourcemap, and set 'result.map = null'. This results
|
@@ -174,7 +142,6 @@ function _loader() {
|
|
174
142
|
// behavior here so "inline" just behaves like 'true'.
|
175
143
|
options.sourceMaps = true;
|
176
144
|
}
|
177
|
-
|
178
145
|
const {
|
179
146
|
cacheDirectory = null,
|
180
147
|
cacheIdentifier = JSON.stringify({
|
@@ -186,7 +153,6 @@ function _loader() {
|
|
186
153
|
metadataSubscribers = []
|
187
154
|
} = loaderOptions;
|
188
155
|
let result;
|
189
|
-
|
190
156
|
if (cacheDirectory) {
|
191
157
|
result = yield cache({
|
192
158
|
source,
|
@@ -198,24 +164,22 @@ function _loader() {
|
|
198
164
|
});
|
199
165
|
} else {
|
200
166
|
result = yield transform(source, options);
|
201
|
-
}
|
202
|
-
// https://github.com/babel/babel/pull/11907
|
203
|
-
|
167
|
+
}
|
204
168
|
|
169
|
+
// Availabe since Babel 7.12
|
170
|
+
// https://github.com/babel/babel/pull/11907
|
205
171
|
if (config.files) {
|
206
172
|
config.files.forEach(configFile => this.addDependency(configFile));
|
207
173
|
} else {
|
208
174
|
// .babelrc.json
|
209
175
|
if (typeof config.babelrc === "string") {
|
210
176
|
this.addDependency(config.babelrc);
|
211
|
-
}
|
212
|
-
|
213
|
-
|
177
|
+
}
|
178
|
+
// babel.config.js
|
214
179
|
if (config.config) {
|
215
180
|
this.addDependency(config.config);
|
216
181
|
}
|
217
182
|
}
|
218
|
-
|
219
183
|
if (result) {
|
220
184
|
if (overrides && overrides.result) {
|
221
185
|
result = yield overrides.result.call(this, result, {
|
@@ -226,20 +190,21 @@ function _loader() {
|
|
226
190
|
options
|
227
191
|
});
|
228
192
|
}
|
229
|
-
|
230
193
|
const {
|
231
194
|
code,
|
232
195
|
map,
|
233
|
-
metadata
|
196
|
+
metadata,
|
197
|
+
externalDependencies
|
234
198
|
} = result;
|
199
|
+
externalDependencies == null ? void 0 : externalDependencies.forEach(dep => this.addDependency(dep));
|
235
200
|
metadataSubscribers.forEach(subscriber => {
|
236
201
|
subscribe(subscriber, metadata, this);
|
237
202
|
});
|
238
203
|
return [code, map];
|
239
204
|
}
|
240
|
-
}
|
241
|
-
|
205
|
+
}
|
242
206
|
|
207
|
+
// If the file was ignored, pass through the original content.
|
243
208
|
return [source, inputSourceMap];
|
244
209
|
});
|
245
210
|
return _loader.apply(this, arguments);
|
package/lib/injectCaller.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
const babel = require("@babel/core");
|
4
|
-
|
5
4
|
module.exports = function injectCaller(opts, target) {
|
6
5
|
if (!supportsCallerOption()) return opts;
|
7
6
|
return Object.assign({}, opts, {
|
@@ -19,13 +18,12 @@ module.exports = function injectCaller(opts, target) {
|
|
19
18
|
supportsTopLevelAwait: true
|
20
19
|
}, opts.caller)
|
21
20
|
});
|
22
|
-
};
|
21
|
+
};
|
22
|
+
|
23
|
+
// TODO: We can remove this eventually, I'm just adding it so that people have
|
23
24
|
// a little time to migrate to the newer RCs of @babel/core without getting
|
24
25
|
// hard-to-diagnose errors about unknown 'caller' options.
|
25
|
-
|
26
|
-
|
27
26
|
let supportsCallerOptionFlag = undefined;
|
28
|
-
|
29
27
|
function supportsCallerOption() {
|
30
28
|
if (supportsCallerOptionFlag === undefined) {
|
31
29
|
try {
|
@@ -41,6 +39,5 @@ function supportsCallerOption() {
|
|
41
39
|
supportsCallerOptionFlag = false;
|
42
40
|
}
|
43
41
|
}
|
44
|
-
|
45
42
|
return supportsCallerOptionFlag;
|
46
43
|
}
|
package/lib/transform.js
CHANGED
@@ -1,59 +1,51 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
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
4
|
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); }); }; }
|
6
|
-
|
7
5
|
const babel = require("@babel/core");
|
8
|
-
|
9
6
|
const {
|
10
7
|
promisify
|
11
8
|
} = require("util");
|
12
|
-
|
13
9
|
const LoaderError = require("./Error");
|
14
|
-
|
15
10
|
const transform = promisify(babel.transform);
|
16
|
-
|
17
11
|
module.exports = /*#__PURE__*/function () {
|
18
12
|
var _ref = _asyncToGenerator(function* (source, options) {
|
19
13
|
let result;
|
20
|
-
|
21
14
|
try {
|
22
15
|
result = yield transform(source, options);
|
23
16
|
} catch (err) {
|
24
17
|
throw err.message && err.codeFrame ? new LoaderError(err) : err;
|
25
18
|
}
|
19
|
+
if (!result) return null;
|
26
20
|
|
27
|
-
|
21
|
+
// We don't return the full result here because some entries are not
|
28
22
|
// really serializable. For a full list of properties see here:
|
29
23
|
// https://github.com/babel/babel/blob/main/packages/babel-core/src/transformation/index.js
|
30
24
|
// For discussion on this topic see here:
|
31
25
|
// https://github.com/babel/babel-loader/pull/629
|
32
|
-
|
33
26
|
const {
|
34
27
|
ast,
|
35
28
|
code,
|
36
29
|
map,
|
37
30
|
metadata,
|
38
|
-
sourceType
|
31
|
+
sourceType,
|
32
|
+
externalDependencies
|
39
33
|
} = result;
|
40
|
-
|
41
34
|
if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
|
42
35
|
map.sourcesContent = [source];
|
43
36
|
}
|
44
|
-
|
45
37
|
return {
|
46
38
|
ast,
|
47
39
|
code,
|
48
40
|
map,
|
49
41
|
metadata,
|
50
|
-
sourceType
|
42
|
+
sourceType,
|
43
|
+
// Convert it from a Set to an Array to make it JSON-serializable.
|
44
|
+
externalDependencies: Array.from(externalDependencies || [])
|
51
45
|
};
|
52
46
|
});
|
53
|
-
|
54
47
|
return function (_x, _x2) {
|
55
48
|
return _ref.apply(this, arguments);
|
56
49
|
};
|
57
50
|
}();
|
58
|
-
|
59
51
|
module.exports.version = babel.version;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "babel-loader",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.3.0",
|
4
4
|
"description": "babel module loader for webpack",
|
5
5
|
"files": [
|
6
6
|
"lib"
|
@@ -21,9 +21,9 @@
|
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
23
23
|
"@ava/babel": "^1.0.1",
|
24
|
-
"@babel/cli": "^7.
|
25
|
-
"@babel/core": "^7.
|
26
|
-
"@babel/preset-env": "^7.
|
24
|
+
"@babel/cli": "^7.19.3",
|
25
|
+
"@babel/core": "^7.19.6",
|
26
|
+
"@babel/preset-env": "^7.19.4",
|
27
27
|
"ava": "^3.13.0",
|
28
28
|
"babel-eslint": "^10.0.1",
|
29
29
|
"babel-plugin-istanbul": "^6.0.0",
|
@@ -120,5 +120,8 @@
|
|
120
120
|
"node ./scripts/yarn-install.js",
|
121
121
|
"git add yarn.lock"
|
122
122
|
]
|
123
|
+
},
|
124
|
+
"resolutions": {
|
125
|
+
"nyc/node-preload": "0.2.0"
|
123
126
|
}
|
124
127
|
}
|