babel-loader 8.2.5 → 8.4.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 +35 -50
- package/lib/index.js +43 -59
- package/lib/injectCaller.js +3 -6
- package/lib/transform.js +7 -15
- package/package.json +11 -7
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 {
|
@@ -123,50 +105,58 @@ const handleCache = /*#__PURE__*/function () {
|
|
123
105
|
options = {},
|
124
106
|
cacheIdentifier,
|
125
107
|
cacheDirectory,
|
126
|
-
cacheCompression
|
108
|
+
cacheCompression,
|
109
|
+
logger
|
127
110
|
} = params;
|
128
111
|
const file = path.join(directory, filename(source, cacheIdentifier, options));
|
129
|
-
|
130
112
|
try {
|
131
113
|
// No errors mean that the file was previously cached
|
132
114
|
// we just need to return it
|
115
|
+
logger.debug(`reading cache file '${file}'`);
|
133
116
|
return yield read(file, cacheCompression);
|
134
|
-
} catch (err) {
|
135
|
-
|
136
|
-
|
117
|
+
} catch (err) {
|
118
|
+
// conitnue if cache can't be read
|
119
|
+
logger.debug(`discarded cache as it can not be read`);
|
120
|
+
}
|
121
|
+
const fallback = typeof cacheDirectory !== "string" && directory !== os.tmpdir();
|
137
122
|
|
123
|
+
// Make sure the directory exists.
|
138
124
|
try {
|
125
|
+
logger.debug(`creating cache folder '${directory}'`);
|
139
126
|
yield makeDir(directory);
|
140
127
|
} catch (err) {
|
141
128
|
if (fallback) {
|
142
129
|
return handleCache(os.tmpdir(), params);
|
143
130
|
}
|
144
|
-
|
145
131
|
throw err;
|
146
|
-
}
|
147
|
-
// return it to the user asap and write it in cache
|
148
|
-
|
132
|
+
}
|
149
133
|
|
134
|
+
// Otherwise just transform the file
|
135
|
+
// return it to the user asap and write it in cache
|
136
|
+
logger.debug(`applying Babel transform`);
|
150
137
|
const result = yield transform(source, options);
|
151
138
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
139
|
+
// Do not cache if there are external dependencies,
|
140
|
+
// since they might change and we cannot control it.
|
141
|
+
if (!result.externalDependencies.length) {
|
142
|
+
try {
|
143
|
+
logger.debug(`writing result to cache file '${file}'`);
|
144
|
+
yield write(file, cacheCompression, result);
|
145
|
+
} catch (err) {
|
146
|
+
if (fallback) {
|
147
|
+
// Fallback to tmpdir if node_modules folder not writable
|
148
|
+
return handleCache(os.tmpdir(), params);
|
149
|
+
}
|
150
|
+
throw err;
|
158
151
|
}
|
159
|
-
|
160
|
-
throw err;
|
161
152
|
}
|
162
|
-
|
163
153
|
return result;
|
164
154
|
});
|
165
|
-
|
166
155
|
return function handleCache(_x6, _x7) {
|
167
156
|
return _ref3.apply(this, arguments);
|
168
157
|
};
|
169
158
|
}();
|
159
|
+
|
170
160
|
/**
|
171
161
|
* Retrieve file from cache, or create a new one for future reads
|
172
162
|
*
|
@@ -192,11 +182,9 @@ const handleCache = /*#__PURE__*/function () {
|
|
192
182
|
* });
|
193
183
|
*/
|
194
184
|
|
195
|
-
|
196
185
|
module.exports = /*#__PURE__*/function () {
|
197
186
|
var _ref4 = _asyncToGenerator(function* (params) {
|
198
187
|
let directory;
|
199
|
-
|
200
188
|
if (typeof params.cacheDirectory === "string") {
|
201
189
|
directory = params.cacheDirectory;
|
202
190
|
} else {
|
@@ -205,13 +193,10 @@ module.exports = /*#__PURE__*/function () {
|
|
205
193
|
name: "babel-loader"
|
206
194
|
}) || os.tmpdir();
|
207
195
|
}
|
208
|
-
|
209
196
|
directory = defaultCacheDirectory;
|
210
197
|
}
|
211
|
-
|
212
198
|
return yield handleCache(directory, params);
|
213
199
|
});
|
214
|
-
|
215
200
|
return function (_x8) {
|
216
201
|
return _ref4.apply(this, arguments);
|
217
202
|
};
|
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,73 +44,64 @@ 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;
|
53
|
+
const logger = this.getLogger("babel-loader");
|
70
54
|
let loaderOptions = loaderUtils.getOptions(this);
|
71
55
|
validateOptions(schema, loaderOptions, {
|
72
56
|
name: "Babel loader"
|
73
57
|
});
|
74
|
-
|
75
58
|
if (loaderOptions.customize != null) {
|
76
59
|
if (typeof loaderOptions.customize !== "string") {
|
77
60
|
throw new Error("Customized loaders must be implemented as standalone modules.");
|
78
61
|
}
|
79
|
-
|
80
62
|
if (!isAbsolute(loaderOptions.customize)) {
|
81
63
|
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
64
|
}
|
83
|
-
|
84
65
|
if (overrides) {
|
85
66
|
throw new Error("babel-loader's 'customize' option is not available when already " + "using a customized babel-loader wrapper.");
|
86
67
|
}
|
87
|
-
|
68
|
+
logger.debug(`loading customize override: '${loaderOptions.customize}'`);
|
88
69
|
let override = require(loaderOptions.customize);
|
89
|
-
|
90
70
|
if (override.__esModule) override = override.default;
|
91
|
-
|
92
71
|
if (typeof override !== "function") {
|
93
72
|
throw new Error("Custom overrides must be functions.");
|
94
73
|
}
|
95
|
-
|
74
|
+
logger.debug("applying customize override to @babel/core");
|
96
75
|
overrides = override(babel);
|
97
76
|
}
|
98
|
-
|
99
77
|
let customOptions;
|
100
|
-
|
101
78
|
if (overrides && overrides.customOptions) {
|
79
|
+
logger.debug("applying overrides customOptions() to loader options");
|
102
80
|
const result = yield overrides.customOptions.call(this, loaderOptions, {
|
103
81
|
source,
|
104
82
|
map: inputSourceMap
|
105
83
|
});
|
106
84
|
customOptions = result.custom;
|
107
85
|
loaderOptions = result.loader;
|
108
|
-
}
|
109
|
-
|
86
|
+
}
|
110
87
|
|
88
|
+
// Deprecation handling
|
111
89
|
if ("forceEnv" in loaderOptions) {
|
112
90
|
console.warn("The option `forceEnv` has been removed in favor of `envName` in Babel 7.");
|
113
91
|
}
|
114
|
-
|
115
92
|
if (typeof loaderOptions.babelrc === "string") {
|
116
93
|
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
|
-
}
|
94
|
+
}
|
95
|
+
logger.debug("normalizing loader options");
|
96
|
+
// Standardize on 'sourceMaps' as the key passed through to Webpack, so that
|
118
97
|
// users may safely use either one alongside our default use of
|
119
98
|
// 'this.sourceMap' below without getting error about conflicting aliases.
|
120
|
-
|
121
|
-
|
122
99
|
if (Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMap") && !Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMaps")) {
|
123
100
|
loaderOptions = Object.assign({}, loaderOptions, {
|
124
101
|
sourceMaps: loaderOptions.sourceMap
|
125
102
|
});
|
126
103
|
delete loaderOptions.sourceMap;
|
127
104
|
}
|
128
|
-
|
129
105
|
const programmaticOptions = Object.assign({}, loaderOptions, {
|
130
106
|
filename,
|
131
107
|
inputSourceMap: inputSourceMap || loaderOptions.inputSourceMap,
|
@@ -136,35 +112,33 @@ function _loader() {
|
|
136
112
|
// so that it can properly map the module back to its internal cached
|
137
113
|
// modules.
|
138
114
|
sourceFileName: filename
|
139
|
-
});
|
140
|
-
|
115
|
+
});
|
116
|
+
// Remove loader related options
|
141
117
|
delete programmaticOptions.customize;
|
142
118
|
delete programmaticOptions.cacheDirectory;
|
143
119
|
delete programmaticOptions.cacheIdentifier;
|
144
120
|
delete programmaticOptions.cacheCompression;
|
145
121
|
delete programmaticOptions.metadataSubscribers;
|
146
|
-
|
147
122
|
if (!babel.loadPartialConfig) {
|
148
123
|
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
|
-
|
124
|
+
}
|
151
125
|
|
126
|
+
// babel.loadPartialConfigAsync is available in v7.8.0+
|
152
127
|
const {
|
153
128
|
loadPartialConfigAsync = babel.loadPartialConfig
|
154
129
|
} = babel;
|
130
|
+
logger.debug("resolving Babel configs");
|
155
131
|
const config = yield loadPartialConfigAsync(injectCaller(programmaticOptions, this.target));
|
156
|
-
|
157
132
|
if (config) {
|
158
133
|
let options = config.options;
|
159
|
-
|
160
134
|
if (overrides && overrides.config) {
|
135
|
+
logger.debug("applying overrides config() to Babel config");
|
161
136
|
options = yield overrides.config.call(this, config, {
|
162
137
|
source,
|
163
138
|
map: inputSourceMap,
|
164
139
|
customOptions
|
165
140
|
});
|
166
141
|
}
|
167
|
-
|
168
142
|
if (options.sourceMaps === "inline") {
|
169
143
|
// Babel has this weird behavior where if you set "inline", we
|
170
144
|
// inline the sourcemap, and set 'result.map = null'. This results
|
@@ -174,7 +148,6 @@ function _loader() {
|
|
174
148
|
// behavior here so "inline" just behaves like 'true'.
|
175
149
|
options.sourceMaps = true;
|
176
150
|
}
|
177
|
-
|
178
151
|
const {
|
179
152
|
cacheDirectory = null,
|
180
153
|
cacheIdentifier = JSON.stringify({
|
@@ -186,38 +159,44 @@ function _loader() {
|
|
186
159
|
metadataSubscribers = []
|
187
160
|
} = loaderOptions;
|
188
161
|
let result;
|
189
|
-
|
190
162
|
if (cacheDirectory) {
|
163
|
+
logger.debug("cache is enabled");
|
191
164
|
result = yield cache({
|
192
165
|
source,
|
193
166
|
options,
|
194
167
|
transform,
|
195
168
|
cacheDirectory,
|
196
169
|
cacheIdentifier,
|
197
|
-
cacheCompression
|
170
|
+
cacheCompression,
|
171
|
+
logger
|
198
172
|
});
|
199
173
|
} else {
|
174
|
+
logger.debug("cache is disabled, applying Babel transform");
|
200
175
|
result = yield transform(source, options);
|
201
|
-
}
|
202
|
-
// https://github.com/babel/babel/pull/11907
|
203
|
-
|
176
|
+
}
|
204
177
|
|
178
|
+
// Availabe since Babel 7.12
|
179
|
+
// https://github.com/babel/babel/pull/11907
|
205
180
|
if (config.files) {
|
206
|
-
config.files.forEach(configFile =>
|
181
|
+
config.files.forEach(configFile => {
|
182
|
+
this.addDependency(configFile);
|
183
|
+
logger.debug(`added '${configFile}' to webpack dependencies`);
|
184
|
+
});
|
207
185
|
} else {
|
208
186
|
// .babelrc.json
|
209
187
|
if (typeof config.babelrc === "string") {
|
210
188
|
this.addDependency(config.babelrc);
|
211
|
-
|
212
|
-
|
213
|
-
|
189
|
+
logger.debug(`added '${config.babelrc}' to webpack dependencies`);
|
190
|
+
}
|
191
|
+
// babel.config.js
|
214
192
|
if (config.config) {
|
215
193
|
this.addDependency(config.config);
|
194
|
+
logger.debug(`added '${config.config}' to webpack dependencies`);
|
216
195
|
}
|
217
196
|
}
|
218
|
-
|
219
197
|
if (result) {
|
220
198
|
if (overrides && overrides.result) {
|
199
|
+
logger.debug("applying overrides result() to Babel transform results");
|
221
200
|
result = yield overrides.result.call(this, result, {
|
222
201
|
source,
|
223
202
|
map: inputSourceMap,
|
@@ -226,20 +205,25 @@ function _loader() {
|
|
226
205
|
options
|
227
206
|
});
|
228
207
|
}
|
229
|
-
|
230
208
|
const {
|
231
209
|
code,
|
232
210
|
map,
|
233
|
-
metadata
|
211
|
+
metadata,
|
212
|
+
externalDependencies
|
234
213
|
} = result;
|
214
|
+
externalDependencies == null ? void 0 : externalDependencies.forEach(dep => {
|
215
|
+
this.addDependency(dep);
|
216
|
+
logger.debug(`added '${dep}' to webpack dependencies`);
|
217
|
+
});
|
235
218
|
metadataSubscribers.forEach(subscriber => {
|
236
219
|
subscribe(subscriber, metadata, this);
|
220
|
+
logger.debug(`invoked metadata subscriber '${String(subscriber)}'`);
|
237
221
|
});
|
238
222
|
return [code, map];
|
239
223
|
}
|
240
|
-
}
|
241
|
-
|
224
|
+
}
|
242
225
|
|
226
|
+
// If the file was ignored, pass through the original content.
|
243
227
|
return [source, inputSourceMap];
|
244
228
|
});
|
245
229
|
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.4.0",
|
4
4
|
"description": "babel module loader for webpack",
|
5
5
|
"files": [
|
6
6
|
"lib"
|
@@ -11,7 +11,7 @@
|
|
11
11
|
},
|
12
12
|
"dependencies": {
|
13
13
|
"find-cache-dir": "^3.3.1",
|
14
|
-
"loader-utils": "^2.0.
|
14
|
+
"loader-utils": "^2.0.4",
|
15
15
|
"make-dir": "^3.1.0",
|
16
16
|
"schema-utils": "^2.6.5"
|
17
17
|
},
|
@@ -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",
|
@@ -44,7 +44,7 @@
|
|
44
44
|
"react-intl-webpack-plugin": "^0.3.0",
|
45
45
|
"rimraf": "^3.0.0",
|
46
46
|
"semver": "7.3.2",
|
47
|
-
"webpack": "^5.
|
47
|
+
"webpack": "^5.61.0"
|
48
48
|
},
|
49
49
|
"scripts": {
|
50
50
|
"clean": "rimraf lib/",
|
@@ -120,5 +120,9 @@
|
|
120
120
|
"node ./scripts/yarn-install.js",
|
121
121
|
"git add yarn.lock"
|
122
122
|
]
|
123
|
-
}
|
123
|
+
},
|
124
|
+
"resolutions": {
|
125
|
+
"nyc/node-preload": "0.2.0"
|
126
|
+
},
|
127
|
+
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
|
124
128
|
}
|