@rsbuild/plugin-babel 1.0.0 → 1.0.1-beta.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.
@@ -0,0 +1,508 @@
1
+ (() => {
2
+ var __webpack_modules__ = {
3
+ 989: (module) => {
4
+ const STRIP_FILENAME_RE = /^[^:]+: /;
5
+ const format = (err) => {
6
+ if (err instanceof SyntaxError) {
7
+ err.name = "SyntaxError";
8
+ err.message = err.message.replace(STRIP_FILENAME_RE, "");
9
+ err.hideStack = true;
10
+ } else if (err instanceof TypeError) {
11
+ err.name = null;
12
+ err.message = err.message.replace(STRIP_FILENAME_RE, "");
13
+ err.hideStack = true;
14
+ }
15
+ return err;
16
+ };
17
+ class LoaderError extends Error {
18
+ constructor(err) {
19
+ super();
20
+ const { name, message, codeFrame, hideStack } = format(err);
21
+ this.name = "BabelLoaderError";
22
+ this.message = `${name ? `${name}: ` : ""}${message}\n\n${codeFrame}\n`;
23
+ this.hideStack = hideStack;
24
+ Error.captureStackTrace(this, this.constructor);
25
+ }
26
+ }
27
+ module.exports = LoaderError;
28
+ },
29
+ 552: (module, __unused_webpack_exports, __nccwpck_require__) => {
30
+ const os = __nccwpck_require__(37);
31
+ const path = __nccwpck_require__(17);
32
+ const zlib = __nccwpck_require__(796);
33
+ const crypto = __nccwpck_require__(113);
34
+ const { promisify } = __nccwpck_require__(837);
35
+ const { readFile, writeFile, mkdir } = __nccwpck_require__(292);
36
+ const findCacheDirP = __nccwpck_require__
37
+ .e(672)
38
+ .then(__nccwpck_require__.bind(__nccwpck_require__, 672));
39
+ const transform = __nccwpck_require__(915);
40
+ let defaultCacheDirectory = null;
41
+ let hashType = "sha256";
42
+ try {
43
+ crypto.createHash(hashType);
44
+ } catch (err) {
45
+ hashType = "md5";
46
+ }
47
+ const gunzip = promisify(zlib.gunzip);
48
+ const gzip = promisify(zlib.gzip);
49
+ const read = async function (filename, compress) {
50
+ const data = await readFile(filename + (compress ? ".gz" : ""));
51
+ const content = compress ? await gunzip(data) : data;
52
+ return JSON.parse(content.toString());
53
+ };
54
+ const write = async function (filename, compress, result) {
55
+ const content = JSON.stringify(result);
56
+ const data = compress ? await gzip(content) : content;
57
+ return await writeFile(filename + (compress ? ".gz" : ""), data);
58
+ };
59
+ const filename = function (source, identifier, options) {
60
+ const hash = crypto.createHash(hashType);
61
+ const contents = JSON.stringify({ source, options, identifier });
62
+ hash.update(contents);
63
+ return hash.digest("hex") + ".json";
64
+ };
65
+ const handleCache = async function (directory, params) {
66
+ const {
67
+ source,
68
+ options = {},
69
+ cacheIdentifier,
70
+ cacheDirectory,
71
+ cacheCompression,
72
+ } = params;
73
+ const file = path.join(
74
+ directory,
75
+ filename(source, cacheIdentifier, options),
76
+ );
77
+ try {
78
+ return await read(file, cacheCompression);
79
+ } catch (err) {}
80
+ const fallback =
81
+ typeof cacheDirectory !== "string" && directory !== os.tmpdir();
82
+ try {
83
+ await mkdir(directory, { recursive: true });
84
+ } catch (err) {
85
+ if (fallback) {
86
+ return handleCache(os.tmpdir(), params);
87
+ }
88
+ throw err;
89
+ }
90
+ const result = await transform(source, options);
91
+ if (!result.externalDependencies.length) {
92
+ try {
93
+ await write(file, cacheCompression, result);
94
+ } catch (err) {
95
+ if (fallback) {
96
+ return handleCache(os.tmpdir(), params);
97
+ }
98
+ throw err;
99
+ }
100
+ }
101
+ return result;
102
+ };
103
+ module.exports = async function (params) {
104
+ let directory;
105
+ if (typeof params.cacheDirectory === "string") {
106
+ directory = params.cacheDirectory;
107
+ } else {
108
+ if (defaultCacheDirectory === null) {
109
+ const { default: findCacheDir } = await findCacheDirP;
110
+ defaultCacheDirectory =
111
+ findCacheDir({ name: "babel-loader" }) || os.tmpdir();
112
+ }
113
+ directory = defaultCacheDirectory;
114
+ }
115
+ return await handleCache(directory, params);
116
+ };
117
+ },
118
+ 417: (module, __unused_webpack_exports, __nccwpck_require__) => {
119
+ let babel;
120
+ try {
121
+ babel = __nccwpck_require__(718);
122
+ } catch (err) {
123
+ if (err.code === "MODULE_NOT_FOUND") {
124
+ err.message +=
125
+ "\n babel-loader@9 requires Babel 7.12+ (the package '@babel/core'). " +
126
+ "If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'.";
127
+ }
128
+ throw err;
129
+ }
130
+ if (/^6\./.test(babel.version)) {
131
+ throw new Error(
132
+ "\n babel-loader@9 will not work with the '@babel/core@6' bridge package. " +
133
+ "If you want to use Babel 6.x, install 'babel-loader@7'.",
134
+ );
135
+ }
136
+ const { version } = __nccwpck_require__(684);
137
+ const cache = __nccwpck_require__(552);
138
+ const transform = __nccwpck_require__(915);
139
+ const injectCaller = __nccwpck_require__(663);
140
+ const schema = __nccwpck_require__(508);
141
+ const { isAbsolute } = __nccwpck_require__(17);
142
+ const validateOptions = __nccwpck_require__(14).validate;
143
+ function subscribe(subscriber, metadata, context) {
144
+ if (context[subscriber]) {
145
+ context[subscriber](metadata);
146
+ }
147
+ }
148
+ module.exports = makeLoader();
149
+ module.exports.custom = makeLoader;
150
+ function makeLoader(callback) {
151
+ const overrides = callback ? callback(babel) : undefined;
152
+ return function (source, inputSourceMap) {
153
+ const callback = this.async();
154
+ loader.call(this, source, inputSourceMap, overrides).then(
155
+ (args) => callback(null, ...args),
156
+ (err) => callback(err),
157
+ );
158
+ };
159
+ }
160
+ async function loader(source, inputSourceMap, overrides) {
161
+ const filename = this.resourcePath;
162
+ let loaderOptions = this.getOptions();
163
+ validateOptions(schema, loaderOptions, { name: "Babel loader" });
164
+ if (loaderOptions.customize != null) {
165
+ if (typeof loaderOptions.customize !== "string") {
166
+ throw new Error(
167
+ "Customized loaders must be implemented as standalone modules.",
168
+ );
169
+ }
170
+ if (!isAbsolute(loaderOptions.customize)) {
171
+ throw new Error(
172
+ "Customized loaders must be passed as absolute paths, since " +
173
+ "babel-loader has no way to know what they would be relative to.",
174
+ );
175
+ }
176
+ if (overrides) {
177
+ throw new Error(
178
+ "babel-loader's 'customize' option is not available when already " +
179
+ "using a customized babel-loader wrapper.",
180
+ );
181
+ }
182
+ let override = require(loaderOptions.customize);
183
+ if (override.__esModule) override = override.default;
184
+ if (typeof override !== "function") {
185
+ throw new Error("Custom overrides must be functions.");
186
+ }
187
+ overrides = override(babel);
188
+ }
189
+ let customOptions;
190
+ if (overrides && overrides.customOptions) {
191
+ const result = await overrides.customOptions.call(
192
+ this,
193
+ loaderOptions,
194
+ { source, map: inputSourceMap },
195
+ );
196
+ customOptions = result.custom;
197
+ loaderOptions = result.loader;
198
+ }
199
+ if ("forceEnv" in loaderOptions) {
200
+ console.warn(
201
+ "The option `forceEnv` has been removed in favor of `envName` in Babel 7.",
202
+ );
203
+ }
204
+ if (typeof loaderOptions.babelrc === "string") {
205
+ console.warn(
206
+ "The option `babelrc` should not be set to a string anymore in the babel-loader config. " +
207
+ "Please update your configuration and set `babelrc` to true or false.\n" +
208
+ "If you want to specify a specific babel config file to inherit config from " +
209
+ "please use the `extends` option.\nFor more information about this options see " +
210
+ "https://babeljs.io/docs/core-packages/#options",
211
+ );
212
+ }
213
+ if (
214
+ Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMap") &&
215
+ !Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMaps")
216
+ ) {
217
+ loaderOptions = Object.assign({}, loaderOptions, {
218
+ sourceMaps: loaderOptions.sourceMap,
219
+ });
220
+ delete loaderOptions.sourceMap;
221
+ }
222
+ const programmaticOptions = Object.assign({}, loaderOptions, {
223
+ filename,
224
+ inputSourceMap: inputSourceMap || loaderOptions.inputSourceMap,
225
+ sourceMaps:
226
+ loaderOptions.sourceMaps === undefined
227
+ ? this.sourceMap
228
+ : loaderOptions.sourceMaps,
229
+ sourceFileName: filename,
230
+ });
231
+ delete programmaticOptions.customize;
232
+ delete programmaticOptions.cacheDirectory;
233
+ delete programmaticOptions.cacheIdentifier;
234
+ delete programmaticOptions.cacheCompression;
235
+ delete programmaticOptions.metadataSubscribers;
236
+ const config = await babel.loadPartialConfigAsync(
237
+ injectCaller(programmaticOptions, this.target),
238
+ );
239
+ if (config) {
240
+ let options = config.options;
241
+ if (overrides && overrides.config) {
242
+ options = await overrides.config.call(this, config, {
243
+ source,
244
+ map: inputSourceMap,
245
+ customOptions,
246
+ });
247
+ }
248
+ if (options.sourceMaps === "inline") {
249
+ options.sourceMaps = true;
250
+ }
251
+ const {
252
+ cacheDirectory = null,
253
+ cacheIdentifier = JSON.stringify({
254
+ options,
255
+ "@babel/core": transform.version,
256
+ "@babel/loader": version,
257
+ }),
258
+ cacheCompression = true,
259
+ metadataSubscribers = [],
260
+ } = loaderOptions;
261
+ let result;
262
+ if (cacheDirectory) {
263
+ result = await cache({
264
+ source,
265
+ options,
266
+ transform,
267
+ cacheDirectory,
268
+ cacheIdentifier,
269
+ cacheCompression,
270
+ });
271
+ } else {
272
+ result = await transform(source, options);
273
+ }
274
+ config.files.forEach((configFile) => this.addDependency(configFile));
275
+ if (result) {
276
+ if (overrides && overrides.result) {
277
+ result = await overrides.result.call(this, result, {
278
+ source,
279
+ map: inputSourceMap,
280
+ customOptions,
281
+ config,
282
+ options,
283
+ });
284
+ }
285
+ const { code, map, metadata, externalDependencies } = result;
286
+ externalDependencies == null
287
+ ? void 0
288
+ : externalDependencies.forEach((dep) => this.addDependency(dep));
289
+ metadataSubscribers.forEach((subscriber) => {
290
+ subscribe(subscriber, metadata, this);
291
+ });
292
+ return [code, map];
293
+ }
294
+ }
295
+ return [source, inputSourceMap];
296
+ }
297
+ },
298
+ 663: (module, __unused_webpack_exports, __nccwpck_require__) => {
299
+ const babel = __nccwpck_require__(718);
300
+ module.exports = function injectCaller(opts, target) {
301
+ if (!supportsCallerOption()) return opts;
302
+ return Object.assign({}, opts, {
303
+ caller: Object.assign(
304
+ {
305
+ name: "babel-loader",
306
+ target,
307
+ supportsStaticESM: true,
308
+ supportsDynamicImport: true,
309
+ supportsTopLevelAwait: true,
310
+ },
311
+ opts.caller,
312
+ ),
313
+ });
314
+ };
315
+ let supportsCallerOptionFlag = undefined;
316
+ function supportsCallerOption() {
317
+ if (supportsCallerOptionFlag === undefined) {
318
+ try {
319
+ babel.loadPartialConfig({
320
+ caller: undefined,
321
+ babelrc: false,
322
+ configFile: false,
323
+ });
324
+ supportsCallerOptionFlag = true;
325
+ } catch (err) {
326
+ supportsCallerOptionFlag = false;
327
+ }
328
+ }
329
+ return supportsCallerOptionFlag;
330
+ }
331
+ },
332
+ 915: (module, __unused_webpack_exports, __nccwpck_require__) => {
333
+ const babel = __nccwpck_require__(718);
334
+ const { promisify } = __nccwpck_require__(837);
335
+ const LoaderError = __nccwpck_require__(989);
336
+ const transform = promisify(babel.transform);
337
+ module.exports = async function (source, options) {
338
+ let result;
339
+ try {
340
+ result = await transform(source, options);
341
+ } catch (err) {
342
+ throw err.message && err.codeFrame ? new LoaderError(err) : err;
343
+ }
344
+ if (!result) return null;
345
+ const { ast, code, map, metadata, sourceType, externalDependencies } =
346
+ result;
347
+ if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
348
+ map.sourcesContent = [source];
349
+ }
350
+ return {
351
+ ast,
352
+ code,
353
+ map,
354
+ metadata,
355
+ sourceType,
356
+ externalDependencies: Array.from(externalDependencies || []),
357
+ };
358
+ };
359
+ module.exports.version = babel.version;
360
+ },
361
+ 684: (module) => {
362
+ "use strict";
363
+ module.exports = require("./package.json");
364
+ },
365
+ 14: (module) => {
366
+ "use strict";
367
+ module.exports = require("./schema-utils");
368
+ },
369
+ 718: (module) => {
370
+ "use strict";
371
+ module.exports = require("@babel/core");
372
+ },
373
+ 113: (module) => {
374
+ "use strict";
375
+ module.exports = require("crypto");
376
+ },
377
+ 292: (module) => {
378
+ "use strict";
379
+ module.exports = require("fs/promises");
380
+ },
381
+ 561: (module) => {
382
+ "use strict";
383
+ module.exports = require("node:fs");
384
+ },
385
+ 411: (module) => {
386
+ "use strict";
387
+ module.exports = require("node:path");
388
+ },
389
+ 742: (module) => {
390
+ "use strict";
391
+ module.exports = require("node:process");
392
+ },
393
+ 41: (module) => {
394
+ "use strict";
395
+ module.exports = require("node:url");
396
+ },
397
+ 37: (module) => {
398
+ "use strict";
399
+ module.exports = require("os");
400
+ },
401
+ 17: (module) => {
402
+ "use strict";
403
+ module.exports = require("path");
404
+ },
405
+ 837: (module) => {
406
+ "use strict";
407
+ module.exports = require("util");
408
+ },
409
+ 796: (module) => {
410
+ "use strict";
411
+ module.exports = require("zlib");
412
+ },
413
+ 508: (module) => {
414
+ "use strict";
415
+ module.exports = JSON.parse(
416
+ '{"type":"object","properties":{"cacheDirectory":{"oneOf":[{"type":"boolean"},{"type":"string"}],"default":false},"cacheIdentifier":{"type":"string"},"cacheCompression":{"type":"boolean","default":true},"customize":{"type":"string","default":null}},"additionalProperties":true}',
417
+ );
418
+ },
419
+ };
420
+ var __webpack_module_cache__ = {};
421
+ function __nccwpck_require__(moduleId) {
422
+ var cachedModule = __webpack_module_cache__[moduleId];
423
+ if (cachedModule !== undefined) {
424
+ return cachedModule.exports;
425
+ }
426
+ var module = (__webpack_module_cache__[moduleId] = { exports: {} });
427
+ var threw = true;
428
+ try {
429
+ __webpack_modules__[moduleId](
430
+ module,
431
+ module.exports,
432
+ __nccwpck_require__,
433
+ );
434
+ threw = false;
435
+ } finally {
436
+ if (threw) delete __webpack_module_cache__[moduleId];
437
+ }
438
+ return module.exports;
439
+ }
440
+ __nccwpck_require__.m = __webpack_modules__;
441
+ (() => {
442
+ __nccwpck_require__.d = (exports, definition) => {
443
+ for (var key in definition) {
444
+ if (
445
+ __nccwpck_require__.o(definition, key) &&
446
+ !__nccwpck_require__.o(exports, key)
447
+ ) {
448
+ Object.defineProperty(exports, key, {
449
+ enumerable: true,
450
+ get: definition[key],
451
+ });
452
+ }
453
+ }
454
+ };
455
+ })();
456
+ (() => {
457
+ __nccwpck_require__.f = {};
458
+ __nccwpck_require__.e = (chunkId) =>
459
+ Promise.all(
460
+ Object.keys(__nccwpck_require__.f).reduce((promises, key) => {
461
+ __nccwpck_require__.f[key](chunkId, promises);
462
+ return promises;
463
+ }, []),
464
+ );
465
+ })();
466
+ (() => {
467
+ __nccwpck_require__.u = (chunkId) => "" + chunkId + ".index.js";
468
+ })();
469
+ (() => {
470
+ __nccwpck_require__.o = (obj, prop) =>
471
+ Object.prototype.hasOwnProperty.call(obj, prop);
472
+ })();
473
+ (() => {
474
+ __nccwpck_require__.r = (exports) => {
475
+ if (typeof Symbol !== "undefined" && Symbol.toStringTag) {
476
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
477
+ }
478
+ Object.defineProperty(exports, "__esModule", { value: true });
479
+ };
480
+ })();
481
+ if (typeof __nccwpck_require__ !== "undefined")
482
+ __nccwpck_require__.ab = __dirname + "/";
483
+ (() => {
484
+ var installedChunks = { 179: 1 };
485
+ var installChunk = (chunk) => {
486
+ var moreModules = chunk.modules,
487
+ chunkIds = chunk.ids,
488
+ runtime = chunk.runtime;
489
+ for (var moduleId in moreModules) {
490
+ if (__nccwpck_require__.o(moreModules, moduleId)) {
491
+ __nccwpck_require__.m[moduleId] = moreModules[moduleId];
492
+ }
493
+ }
494
+ if (runtime) runtime(__nccwpck_require__);
495
+ for (var i = 0; i < chunkIds.length; i++)
496
+ installedChunks[chunkIds[i]] = 1;
497
+ };
498
+ __nccwpck_require__.f.require = (chunkId, promises) => {
499
+ if (!installedChunks[chunkId]) {
500
+ if (true) {
501
+ installChunk(require("./" + __nccwpck_require__.u(chunkId)));
502
+ } else installedChunks[chunkId] = 1;
503
+ }
504
+ };
505
+ })();
506
+ var __webpack_exports__ = __nccwpck_require__(417);
507
+ module.exports = __webpack_exports__;
508
+ })();
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014-2019 Luís Couto <hello@luiscouto.pt>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ {"name":"babel-loader","author":"Luis Couto <hello@luiscouto.pt>","version":"9.1.3","license":"MIT","types":"index.d.ts","type":"commonjs"}
@@ -0,0 +1 @@
1
+ module.exports.validate = () => {};
@@ -0,0 +1,11 @@
1
+ import type { ChainIdentifier, RspackChain } from '@rsbuild/core';
2
+ import type { BabelConfigUtils, BabelLoaderOptions, BabelTransformOptions, PluginBabelOptions } from './types';
3
+ export declare const BABEL_JS_RULE = "babel-js";
4
+ export declare const castArray: <T>(arr?: T | T[]) => T[];
5
+ export declare const getBabelUtils: (config: BabelTransformOptions) => BabelConfigUtils;
6
+ export declare const applyUserBabelConfig: (defaultOptions: BabelLoaderOptions, userBabelConfig?: PluginBabelOptions["babelLoaderOptions"], extraBabelUtils?: Partial<BabelConfigUtils>) => BabelLoaderOptions;
7
+ export declare const modifyBabelLoaderOptions: ({ chain, CHAIN_ID, modifier, }: {
8
+ chain: RspackChain;
9
+ CHAIN_ID: ChainIdentifier;
10
+ modifier: (config: BabelTransformOptions) => BabelTransformOptions;
11
+ }) => void;