@rsbuild/plugin-babel 1.0.6 → 1.0.7

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 CHANGED
@@ -7,7 +7,7 @@ An Rsbuild plugin to use Babel to transpile the code.
7
7
  <img src="https://img.shields.io/npm/v/@rsbuild/plugin-babel?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
8
8
  </a>
9
9
  <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
10
- <a href="https://npmcharts.com/compare/@rsbuild/plugin-babel?minimal=true"><img src="https://img.shields.io/npm/dm/@rsbuild/plugin-babel.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
10
+ <a href="https://npmcharts.com/compare/@rsbuild/plugin-babel"><img src="https://img.shields.io/npm/dm/@rsbuild/plugin-babel.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
11
11
  </p>
12
12
 
13
13
  ## Documentation
@@ -1,6 +1,6 @@
1
1
  (() => {
2
2
  var __webpack_modules__ = {
3
- 698: (module) => {
3
+ 808: (module) => {
4
4
  const STRIP_FILENAME_RE = /^[^:]+: /;
5
5
  const format = (err) => {
6
6
  if (err instanceof SyntaxError) {
@@ -26,16 +26,16 @@
26
26
  }
27
27
  module.exports = LoaderError;
28
28
  },
29
- 846: (module, __unused_webpack_exports, __nccwpck_require__) => {
29
+ 908: (module, __unused_webpack_exports, __nccwpck_require__) => {
30
30
  const os = __nccwpck_require__(857);
31
31
  const path = __nccwpck_require__(928);
32
32
  const zlib = __nccwpck_require__(106);
33
33
  const { promisify } = __nccwpck_require__(23);
34
34
  const { readFile, writeFile, mkdir } = __nccwpck_require__(943);
35
- const { sync: findUpSync } = __nccwpck_require__(609);
35
+ const { sync: findUpSync } = __nccwpck_require__(48);
36
36
  const { env } = process;
37
- const transform = __nccwpck_require__(80);
38
- const serialize = __nccwpck_require__(786);
37
+ const transform = __nccwpck_require__(30);
38
+ const serialize = __nccwpck_require__(452);
39
39
  let defaultCacheDirectory = null;
40
40
  const gunzip = promisify(zlib.gunzip);
41
41
  const gzip = promisify(zlib.gzip);
@@ -165,7 +165,7 @@
165
165
  return os.tmpdir();
166
166
  }
167
167
  },
168
- 448: (module, __unused_webpack_exports, __nccwpck_require__) => {
168
+ 314: (module, __unused_webpack_exports, __nccwpck_require__) => {
169
169
  let babel;
170
170
  try {
171
171
  babel = __nccwpck_require__(571);
@@ -184,10 +184,10 @@
184
184
  );
185
185
  }
186
186
  const { version } = __nccwpck_require__(344);
187
- const cache = __nccwpck_require__(846);
188
- const transform = __nccwpck_require__(80);
189
- const injectCaller = __nccwpck_require__(976);
190
- const schema = __nccwpck_require__(690);
187
+ const cache = __nccwpck_require__(908);
188
+ const transform = __nccwpck_require__(30);
189
+ const injectCaller = __nccwpck_require__(174);
190
+ const schema = __nccwpck_require__(779);
191
191
  const { isAbsolute } = __nccwpck_require__(928);
192
192
  const { promisify } = __nccwpck_require__(23);
193
193
  function subscribe(subscriber, metadata, context) {
@@ -373,7 +373,7 @@
373
373
  return [source, inputSourceMap];
374
374
  }
375
375
  },
376
- 976: (module) => {
376
+ 174: (module) => {
377
377
  module.exports = function injectCaller(opts, target) {
378
378
  return Object.assign({}, opts, {
379
379
  caller: Object.assign(
@@ -389,7 +389,7 @@
389
389
  });
390
390
  };
391
391
  },
392
- 786: (module) => {
392
+ 452: (module) => {
393
393
  var objToString = Object.prototype.toString;
394
394
  var objKeys = Object.getOwnPropertyNames;
395
395
  function serialize(val, isArrayProp) {
@@ -455,10 +455,10 @@
455
455
  }
456
456
  };
457
457
  },
458
- 80: (module, __unused_webpack_exports, __nccwpck_require__) => {
458
+ 30: (module, __unused_webpack_exports, __nccwpck_require__) => {
459
459
  const babel = __nccwpck_require__(571);
460
460
  const { promisify } = __nccwpck_require__(23);
461
- const LoaderError = __nccwpck_require__(698);
461
+ const LoaderError = __nccwpck_require__(808);
462
462
  const transform = promisify(babel.transform);
463
463
  module.exports = async function (source, options) {
464
464
  let result;
@@ -487,11 +487,11 @@
487
487
  };
488
488
  module.exports.version = babel.version;
489
489
  },
490
- 609: (module, __unused_webpack_exports, __nccwpck_require__) => {
490
+ 48: (module, __unused_webpack_exports, __nccwpck_require__) => {
491
491
  "use strict";
492
492
  const path = __nccwpck_require__(928);
493
- const locatePath = __nccwpck_require__(440);
494
- const pathExists = __nccwpck_require__(374);
493
+ const locatePath = __nccwpck_require__(597);
494
+ const pathExists = __nccwpck_require__(219);
495
495
  const stop = Symbol("findUp.stop");
496
496
  module.exports = async (name, options = {}) => {
497
497
  let directory = path.resolve(options.cwd || "");
@@ -553,12 +553,12 @@
553
553
  module.exports.sync.exists = pathExists.sync;
554
554
  module.exports.stop = stop;
555
555
  },
556
- 440: (module, __unused_webpack_exports, __nccwpck_require__) => {
556
+ 597: (module, __unused_webpack_exports, __nccwpck_require__) => {
557
557
  "use strict";
558
558
  const path = __nccwpck_require__(928);
559
559
  const fs = __nccwpck_require__(896);
560
560
  const { promisify } = __nccwpck_require__(23);
561
- const pLocate = __nccwpck_require__(601);
561
+ const pLocate = __nccwpck_require__(108);
562
562
  const fsStat = promisify(fs.stat);
563
563
  const fsLStat = promisify(fs.lstat);
564
564
  const typeMappings = { directory: "isDirectory", file: "isFile" };
@@ -611,9 +611,9 @@
611
611
  }
612
612
  };
613
613
  },
614
- 600: (module, __unused_webpack_exports, __nccwpck_require__) => {
614
+ 333: (module, __unused_webpack_exports, __nccwpck_require__) => {
615
615
  "use strict";
616
- const Queue = __nccwpck_require__(179);
616
+ const Queue = __nccwpck_require__(882);
617
617
  const pLimit = (concurrency) => {
618
618
  if (
619
619
  !(
@@ -668,9 +668,9 @@
668
668
  };
669
669
  module.exports = pLimit;
670
670
  },
671
- 601: (module, __unused_webpack_exports, __nccwpck_require__) => {
671
+ 108: (module, __unused_webpack_exports, __nccwpck_require__) => {
672
672
  "use strict";
673
- const pLimit = __nccwpck_require__(600);
673
+ const pLimit = __nccwpck_require__(333);
674
674
  class EndError extends Error {
675
675
  constructor(value) {
676
676
  super();
@@ -706,7 +706,7 @@
706
706
  };
707
707
  module.exports = pLocate;
708
708
  },
709
- 374: (module, __unused_webpack_exports, __nccwpck_require__) => {
709
+ 219: (module, __unused_webpack_exports, __nccwpck_require__) => {
710
710
  "use strict";
711
711
  const fs = __nccwpck_require__(896);
712
712
  const { promisify } = __nccwpck_require__(23);
@@ -728,7 +728,7 @@
728
728
  }
729
729
  };
730
730
  },
731
- 179: (module) => {
731
+ 882: (module) => {
732
732
  class Node {
733
733
  constructor(value) {
734
734
  this.value = value;
@@ -809,7 +809,7 @@
809
809
  "use strict";
810
810
  module.exports = require("zlib");
811
811
  },
812
- 690: (module) => {
812
+ 779: (module) => {
813
813
  "use strict";
814
814
  module.exports = JSON.parse(
815
815
  '{"title":"Babel Loader options","type":"object","properties":{"cacheDirectory":{"anyOf":[{"type":"boolean"},{"type":"string"}],"default":false},"cacheIdentifier":{"type":"string"},"cacheCompression":{"type":"boolean","default":true},"customize":{"anyOf":[{"type":"null"},{"type":"string"}],"default":null},"metadataSubscribers":{"type":"array"}},"additionalProperties":true}',
@@ -838,6 +838,6 @@
838
838
  }
839
839
  if (typeof __nccwpck_require__ !== "undefined")
840
840
  __nccwpck_require__.ab = __dirname + "/";
841
- var __webpack_exports__ = __nccwpck_require__(448);
841
+ var __webpack_exports__ = __nccwpck_require__(314);
842
842
  module.exports = __webpack_exports__;
843
843
  })();
package/dist/index.cjs CHANGED
@@ -1,20 +1,6 @@
1
1
  "use strict";
2
- let __rslib_import_meta_url__ = 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
3
- var __webpack_modules__ = {
4
- "@babel/core": function(module) {
5
- module.exports = import("@babel/core").then(function(module) {
6
- return module;
7
- });
8
- }
9
- }, __webpack_module_cache__ = {};
10
- function __webpack_require__(moduleId) {
11
- var cachedModule = __webpack_module_cache__[moduleId];
12
- if (void 0 !== cachedModule) return cachedModule.exports;
13
- var module = __webpack_module_cache__[moduleId] = {
14
- exports: {}
15
- };
16
- return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
17
- }
2
+ const __rslib_import_meta_url__ = "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
3
+ var __webpack_require__ = {};
18
4
  __webpack_require__.n = (module)=>{
19
5
  var getter = module && module.__esModule ? ()=>module.default : ()=>module;
20
6
  return __webpack_require__.d(getter, {
@@ -26,172 +12,172 @@ __webpack_require__.n = (module)=>{
26
12
  get: definition[key]
27
13
  });
28
14
  }, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
29
- 'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
15
+ "u" > typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
30
16
  value: 'Module'
31
17
  }), Object.defineProperty(exports1, '__esModule', {
32
18
  value: !0
33
19
  });
34
20
  };
35
21
  var __webpack_exports__ = {};
36
- for(var __webpack_i__ in (()=>{
37
- __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
38
- PLUGIN_BABEL_NAME: ()=>PLUGIN_BABEL_NAME,
39
- pluginBabel: ()=>pluginBabel,
40
- modifyBabelLoaderOptions: ()=>modifyBabelLoaderOptions,
41
- getBabelUtils: ()=>getBabelUtils,
42
- getDefaultBabelOptions: ()=>getDefaultBabelOptions
22
+ __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
23
+ getDefaultBabelOptions: ()=>getDefaultBabelOptions,
24
+ getBabelUtils: ()=>getBabelUtils,
25
+ modifyBabelLoaderOptions: ()=>modifyBabelLoaderOptions,
26
+ PLUGIN_BABEL_NAME: ()=>PLUGIN_BABEL_NAME,
27
+ pluginBabel: ()=>pluginBabel
28
+ });
29
+ const external_node_path_namespaceObject = require("node:path");
30
+ var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
31
+ const external_reduce_configs_namespaceObject = require("reduce-configs"), external_upath_namespaceObject = require("upath");
32
+ var external_upath_default = __webpack_require__.n(external_upath_namespaceObject);
33
+ const BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
34
+ arr
35
+ ], normalizeToPosixPath = (p)=>external_upath_default().normalizeSafe((0, external_node_path_namespaceObject.normalize)(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`), formatPath = (originPath)=>(0, external_node_path_namespaceObject.isAbsolute)(originPath) ? originPath.split(external_node_path_namespaceObject.sep).join('/') : originPath, getPluginItemName = (item)=>'string' == typeof item ? formatPath(item) : Array.isArray(item) && 'string' == typeof item[0] ? formatPath(item[0]) : null, addPlugins = (plugins, config)=>{
36
+ config.plugins ? config.plugins.push(...plugins) : config.plugins = plugins;
37
+ }, addPresets = (presets, config)=>{
38
+ config.presets ? config.presets.push(...presets) : config.presets = presets;
39
+ }, removePlugins = (plugins, config)=>{
40
+ if (!config.plugins) return;
41
+ let removeList = castArray(plugins);
42
+ config.plugins = config.plugins.filter((item)=>{
43
+ let name = getPluginItemName(item);
44
+ return !name || !removeList.find((removeItem)=>name.includes(removeItem));
43
45
  });
44
- let external_node_path_namespaceObject = require("node:path");
45
- var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
46
- let external_reduce_configs_namespaceObject = require("reduce-configs"), external_upath_namespaceObject = require("upath");
47
- var external_upath_default = __webpack_require__.n(external_upath_namespaceObject);
48
- let BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
49
- arr
50
- ], normalizeToPosixPath = (p)=>external_upath_default().normalizeSafe((0, external_node_path_namespaceObject.normalize)(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`), formatPath = (originPath)=>(0, external_node_path_namespaceObject.isAbsolute)(originPath) ? originPath.split(external_node_path_namespaceObject.sep).join('/') : originPath, getPluginItemName = (item)=>'string' == typeof item ? formatPath(item) : Array.isArray(item) && 'string' == typeof item[0] ? formatPath(item[0]) : null, modifyPresetOptions = (presetName, options, presets = [])=>{
51
- presets.forEach((preset, index)=>{
52
- Array.isArray(preset) ? 'string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName) && (preset[1] = {
53
- ...preset[1] || {},
54
- ...options
55
- }) : 'string' == typeof preset && normalizeToPosixPath(preset).includes(presetName) && (presets[index] = [
56
- preset,
57
- options
58
- ]);
59
- });
60
- }, getBabelUtils = (config)=>{
61
- let noop = ()=>{};
62
- return {
63
- addPlugins: (plugins)=>{
64
- ((plugins, config)=>{
65
- config.plugins ? config.plugins.push(...plugins) : config.plugins = plugins;
66
- })(plugins, config);
67
- },
68
- addPresets: (presets)=>{
69
- ((presets, config)=>{
70
- config.presets ? config.presets.push(...presets) : config.presets = presets;
71
- })(presets, config);
72
- },
73
- removePlugins: (plugins)=>{
74
- ((plugins, config)=>{
75
- if (!config.plugins) return;
76
- let removeList = castArray(plugins);
77
- config.plugins = config.plugins.filter((item)=>{
78
- let name = getPluginItemName(item);
79
- return !name || !removeList.find((removeItem)=>name.includes(removeItem));
80
- });
81
- })(plugins, config);
82
- },
83
- removePresets: (presets)=>{
84
- ((presets, config)=>{
85
- if (!config.presets) return;
86
- let removeList = castArray(presets);
87
- config.presets = config.presets.filter((item)=>{
88
- let name = getPluginItemName(item);
89
- return !name || !removeList.find((removeItem)=>name.includes(removeItem));
90
- });
91
- })(presets, config);
92
- },
93
- addIncludes: noop,
94
- addExcludes: noop,
95
- modifyPresetEnvOptions: (options)=>{
96
- modifyPresetOptions('@babel/preset-env', options, config.presets || []);
97
- },
98
- modifyPresetReactOptions: (options)=>{
99
- modifyPresetOptions('@babel/preset-react', options, config.presets || []);
100
- }
101
- };
102
- }, modifyBabelLoaderOptions = ({ chain, CHAIN_ID, modifier })=>{
103
- for (let ruleId of [
104
- CHAIN_ID.RULE.JS,
105
- CHAIN_ID.RULE.JS_DATA_URI,
106
- BABEL_JS_RULE
107
- ])if (chain.module.rules.has(ruleId)) {
108
- let rule = chain.module.rule(ruleId);
109
- rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
46
+ }, removePresets = (presets, config)=>{
47
+ if (!config.presets) return;
48
+ let removeList = castArray(presets);
49
+ config.presets = config.presets.filter((item)=>{
50
+ let name = getPluginItemName(item);
51
+ return !name || !removeList.find((removeItem)=>name.includes(removeItem));
52
+ });
53
+ }, modifyPresetOptions = (presetName, options, presets = [])=>{
54
+ presets.forEach((preset, index)=>{
55
+ Array.isArray(preset) ? 'string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName) && (preset[1] = {
56
+ ...preset[1] || {},
57
+ ...options
58
+ }) : 'string' == typeof preset && normalizeToPosixPath(preset).includes(presetName) && (presets[index] = [
59
+ preset,
60
+ options
61
+ ]);
62
+ });
63
+ }, getBabelUtils = (config)=>{
64
+ let noop = ()=>{};
65
+ return {
66
+ addPlugins: (plugins)=>{
67
+ addPlugins(plugins, config);
68
+ },
69
+ addPresets: (presets)=>{
70
+ addPresets(presets, config);
71
+ },
72
+ removePlugins: (plugins)=>{
73
+ removePlugins(plugins, config);
74
+ },
75
+ removePresets: (presets)=>{
76
+ removePresets(presets, config);
77
+ },
78
+ addIncludes: noop,
79
+ addExcludes: noop,
80
+ modifyPresetEnvOptions: (options)=>{
81
+ modifyPresetOptions('@babel/preset-env', options, config.presets || []);
82
+ },
83
+ modifyPresetReactOptions: (options)=>{
84
+ modifyPresetOptions('@babel/preset-react', options, config.presets || []);
110
85
  }
111
- }, external_node_fs_namespaceObject = require("node:fs");
112
- var external_node_fs_default = __webpack_require__.n(external_node_fs_namespaceObject);
113
- let external_node_module_namespaceObject = require("node:module"), external_node_url_namespaceObject = require("node:url"), external_deepmerge_namespaceObject = require("deepmerge");
114
- var external_deepmerge_default = __webpack_require__.n(external_deepmerge_namespaceObject);
115
- let plugin_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__)), plugin_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), PLUGIN_BABEL_NAME = 'rsbuild:babel', SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
116
- allowNamespaces: !0,
117
- allExtensions: !0,
118
- allowDeclareFields: !0,
119
- optimizeConstEnums: !0,
120
- isTSX: !0
121
86
  };
122
- async function getCacheIdentifier(options) {
123
- let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`, { version: coreVersion } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@babel/core")), loaderVersion = JSON.parse(await external_node_fs_default().promises.readFile((0, external_node_path_namespaceObject.join)(plugin_dirname, '../compiled/babel-loader/package.json'), 'utf-8')).version ?? '';
124
- return identifier += `@babel/core@${coreVersion}babel-loader@${loaderVersion}`;
87
+ }, applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
88
+ if (userBabelConfig) {
89
+ let babelUtils = {
90
+ ...getBabelUtils(defaultOptions),
91
+ ...extraBabelUtils
92
+ };
93
+ return (0, external_reduce_configs_namespaceObject.reduceConfigsWithContext)({
94
+ initial: defaultOptions,
95
+ config: userBabelConfig,
96
+ ctx: babelUtils
97
+ });
98
+ }
99
+ return defaultOptions;
100
+ }, modifyBabelLoaderOptions = ({ chain, CHAIN_ID, modifier })=>{
101
+ for (let ruleId of [
102
+ CHAIN_ID.RULE.JS,
103
+ CHAIN_ID.RULE.JS_DATA_URI,
104
+ BABEL_JS_RULE
105
+ ])if (chain.module.rules.has(ruleId)) {
106
+ let rule = chain.module.rule(ruleId);
107
+ rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
125
108
  }
126
- let getDefaultBabelOptions = (config, context)=>{
127
- let isLegacyDecorators = 'legacy' === config.source.decorators.version, options = {
128
- babelrc: !1,
129
- configFile: !1,
130
- compact: 'production' === config.mode,
131
- plugins: [
132
- [
133
- plugin_require.resolve('@babel/plugin-proposal-decorators'),
134
- config.source.decorators
135
- ],
136
- ...isLegacyDecorators ? [
137
- plugin_require.resolve('@babel/plugin-transform-class-properties')
138
- ] : []
109
+ }, external_node_fs_namespaceObject = require("node:fs");
110
+ var external_node_fs_default = __webpack_require__.n(external_node_fs_namespaceObject);
111
+ const external_node_module_namespaceObject = require("node:module"), external_node_url_namespaceObject = require("node:url"), external_deepmerge_namespaceObject = require("deepmerge");
112
+ var external_deepmerge_default = __webpack_require__.n(external_deepmerge_namespaceObject);
113
+ const plugin_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__)), plugin_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), PLUGIN_BABEL_NAME = 'rsbuild:babel', SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
114
+ allowNamespaces: !0,
115
+ allExtensions: !0,
116
+ allowDeclareFields: !0,
117
+ optimizeConstEnums: !0,
118
+ isTSX: !0
119
+ };
120
+ function getCacheDirectory(context, cacheDirectory) {
121
+ return cacheDirectory ? (0, external_node_path_namespaceObject.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, external_node_path_namespaceObject.join)(context.rootPath, cacheDirectory) : (0, external_node_path_namespaceObject.join)(context.cachePath);
122
+ }
123
+ async function getCacheIdentifier(options) {
124
+ let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`, { version: coreVersion } = await import("@babel/core"), loaderVersion = JSON.parse(await external_node_fs_default().promises.readFile((0, external_node_path_namespaceObject.join)(plugin_dirname, '../compiled/babel-loader/package.json'), 'utf-8')).version ?? '';
125
+ return identifier + `@babel/core@${coreVersion}babel-loader@${loaderVersion}`;
126
+ }
127
+ const getDefaultBabelOptions = (config, context)=>{
128
+ let isLegacyDecorators = 'legacy' === config.source.decorators.version, options = {
129
+ babelrc: !1,
130
+ configFile: !1,
131
+ compact: 'production' === config.mode,
132
+ plugins: [
133
+ [
134
+ plugin_require.resolve('@babel/plugin-proposal-decorators'),
135
+ config.source.decorators
139
136
  ],
140
- presets: [
141
- [
142
- plugin_require.resolve("@babel/preset-typescript"),
143
- DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
144
- ]
137
+ ...isLegacyDecorators ? [
138
+ plugin_require.resolve('@babel/plugin-transform-class-properties')
139
+ ] : []
140
+ ],
141
+ presets: [
142
+ [
143
+ plugin_require.resolve("@babel/preset-typescript"),
144
+ DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
145
145
  ]
146
- }, { buildCache = !0 } = config.performance;
147
- if (buildCache && 'rspack' === context.bundlerType) {
148
- let cacheDirectory = function(context, cacheDirectory) {
149
- return cacheDirectory ? (0, external_node_path_namespaceObject.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, external_node_path_namespaceObject.join)(context.rootPath, cacheDirectory) : (0, external_node_path_namespaceObject.join)(context.cachePath);
150
- }(context, 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory);
151
- options.cacheCompression = !1, options.cacheDirectory = (0, external_node_path_namespaceObject.join)(cacheDirectory, 'babel-loader');
146
+ ]
147
+ }, { buildCache = !0 } = config.performance;
148
+ if (buildCache && 'rspack' === context.bundlerType) {
149
+ let cacheDirectory = getCacheDirectory(context, 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory);
150
+ options.cacheCompression = !1, options.cacheDirectory = (0, external_node_path_namespaceObject.join)(cacheDirectory, 'babel-loader');
151
+ }
152
+ return options;
153
+ }, pluginBabel = (options = {})=>({
154
+ name: PLUGIN_BABEL_NAME,
155
+ setup (api) {
156
+ let getBabelOptions = async (environment)=>{
157
+ let { config } = environment, baseOptions = getDefaultBabelOptions(config, api.context), mergedOptions = applyUserBabelConfig(external_deepmerge_default()({}, baseOptions), options.babelLoaderOptions);
158
+ return mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier && (mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions)), mergedOptions;
159
+ };
160
+ api.modifyBundlerChain({
161
+ order: 'pre',
162
+ handler: async (chain, { CHAIN_ID, environment })=>{
163
+ let babelOptions = await getBabelOptions(environment), babelLoader = external_node_path_default().resolve(plugin_dirname, '../compiled/babel-loader/index.js'), { include, exclude } = options;
164
+ if (include || exclude) {
165
+ let rule = chain.module.rule(BABEL_JS_RULE).after(CHAIN_ID.RULE.JS);
166
+ if (include) for (let condition of castArray(include))rule.include.add(condition);
167
+ if (exclude) for (let condition of castArray(exclude))rule.exclude.add(condition);
168
+ rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
169
+ } else chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
170
+ }
171
+ });
152
172
  }
153
- return options;
154
- }, pluginBabel = (options = {})=>({
155
- name: PLUGIN_BABEL_NAME,
156
- setup (api) {
157
- let getBabelOptions = async (environment)=>{
158
- let { config } = environment, baseOptions = getDefaultBabelOptions(config, api.context), mergedOptions = ((defaultOptions, userBabelConfig, extraBabelUtils)=>{
159
- if (userBabelConfig) {
160
- let babelUtils = {
161
- ...getBabelUtils(defaultOptions),
162
- ...void 0
163
- };
164
- return (0, external_reduce_configs_namespaceObject.reduceConfigsWithContext)({
165
- initial: defaultOptions,
166
- config: userBabelConfig,
167
- ctx: babelUtils
168
- });
169
- }
170
- return defaultOptions;
171
- })(external_deepmerge_default()({}, baseOptions), options.babelLoaderOptions);
172
- return mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier && (mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions)), mergedOptions;
173
- };
174
- api.modifyBundlerChain({
175
- order: 'pre',
176
- handler: async (chain, { CHAIN_ID, environment })=>{
177
- let babelOptions = await getBabelOptions(environment), babelLoader = external_node_path_default().resolve(plugin_dirname, '../compiled/babel-loader/index.js'), { include, exclude } = options;
178
- if (include || exclude) {
179
- let rule = chain.module.rule(BABEL_JS_RULE).after(CHAIN_ID.RULE.JS);
180
- if (include) for (let condition of castArray(include))rule.include.add(condition);
181
- if (exclude) for (let condition of castArray(exclude))rule.exclude.add(condition);
182
- rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
183
- } else chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
184
- }
185
- });
186
- }
187
- });
188
- })(), exports.PLUGIN_BABEL_NAME = __webpack_exports__.PLUGIN_BABEL_NAME, exports.getBabelUtils = __webpack_exports__.getBabelUtils, exports.getDefaultBabelOptions = __webpack_exports__.getDefaultBabelOptions, exports.modifyBabelLoaderOptions = __webpack_exports__.modifyBabelLoaderOptions, exports.pluginBabel = __webpack_exports__.pluginBabel, __webpack_exports__)-1 === [
173
+ });
174
+ for(var __rspack_i in exports.PLUGIN_BABEL_NAME = __webpack_exports__.PLUGIN_BABEL_NAME, exports.getBabelUtils = __webpack_exports__.getBabelUtils, exports.getDefaultBabelOptions = __webpack_exports__.getDefaultBabelOptions, exports.modifyBabelLoaderOptions = __webpack_exports__.modifyBabelLoaderOptions, exports.pluginBabel = __webpack_exports__.pluginBabel, __webpack_exports__)-1 === [
189
175
  "PLUGIN_BABEL_NAME",
190
176
  "getBabelUtils",
191
177
  "getDefaultBabelOptions",
192
178
  "modifyBabelLoaderOptions",
193
179
  "pluginBabel"
194
- ].indexOf(__webpack_i__) && (exports[__webpack_i__] = __webpack_exports__[__webpack_i__]);
180
+ ].indexOf(__rspack_i) && (exports[__rspack_i] = __webpack_exports__[__rspack_i]);
195
181
  Object.defineProperty(exports, '__esModule', {
196
182
  value: !0
197
183
  });
package/dist/index.js CHANGED
@@ -71,6 +71,9 @@ let BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.i
71
71
  optimizeConstEnums: !0,
72
72
  isTSX: !0
73
73
  };
74
+ function getCacheDirectory(context, cacheDirectory) {
75
+ return cacheDirectory ? isAbsolute(cacheDirectory) ? cacheDirectory : join(context.rootPath, cacheDirectory) : join(context.cachePath);
76
+ }
74
77
  async function getCacheIdentifier(options) {
75
78
  let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`, { version: coreVersion } = await import("@babel/core"), loaderVersion = JSON.parse(await node_fs.promises.readFile(join(plugin_dirname, '../compiled/babel-loader/package.json'), 'utf-8')).version ?? '';
76
79
  return identifier + `@babel/core@${coreVersion}babel-loader@${loaderVersion}`;
@@ -97,9 +100,8 @@ let getDefaultBabelOptions = (config, context)=>{
97
100
  ]
98
101
  }, { buildCache = !0 } = config.performance;
99
102
  if (buildCache && 'rspack' === context.bundlerType) {
100
- var cacheDirectory;
101
- let cacheDirectory1 = (cacheDirectory = 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory) ? isAbsolute(cacheDirectory) ? cacheDirectory : join(context.rootPath, cacheDirectory) : join(context.cachePath);
102
- options.cacheCompression = !1, options.cacheDirectory = join(cacheDirectory1, 'babel-loader');
103
+ let cacheDirectory = getCacheDirectory(context, 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory);
104
+ options.cacheCompression = !1, options.cacheDirectory = join(cacheDirectory, 'babel-loader');
103
105
  }
104
106
  return options;
105
107
  }, pluginBabel = (options = {})=>({
package/dist/plugin.d.ts CHANGED
@@ -1,15 +1,5 @@
1
1
  import type { NormalizedEnvironmentConfig, RsbuildContext, RsbuildPlugin } from '@rsbuild/core';
2
2
  import type { BabelLoaderOptions, PluginBabelOptions } from './types.js';
3
3
  export declare const PLUGIN_BABEL_NAME = "rsbuild:babel";
4
- /**
5
- * The `@babel/preset-typescript` default options.
6
- */
7
- export declare const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS: {
8
- allowNamespaces: boolean;
9
- allExtensions: boolean;
10
- allowDeclareFields: boolean;
11
- optimizeConstEnums: boolean;
12
- isTSX: boolean;
13
- };
14
4
  export declare const getDefaultBabelOptions: (config: NormalizedEnvironmentConfig, context: RsbuildContext) => BabelLoaderOptions;
15
5
  export declare const pluginBabel: (options?: PluginBabelOptions) => RsbuildPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-babel",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Babel plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,26 +23,26 @@
23
23
  "compiled"
24
24
  ],
25
25
  "dependencies": {
26
- "@babel/core": "^7.28.0",
26
+ "@babel/core": "^7.28.5",
27
27
  "@babel/plugin-proposal-decorators": "^7.28.0",
28
28
  "@babel/plugin-transform-class-properties": "^7.27.1",
29
- "@babel/preset-typescript": "^7.27.1",
29
+ "@babel/preset-typescript": "^7.28.5",
30
30
  "@types/babel__core": "^7.20.5",
31
31
  "deepmerge": "^4.3.1",
32
- "reduce-configs": "^1.1.0",
32
+ "reduce-configs": "^1.1.1",
33
33
  "upath": "2.0.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@rslib/core": "0.11.1",
37
- "@types/node": "^22.17.0",
36
+ "@rslib/core": "0.19.1",
37
+ "@types/node": "^24.10.4",
38
38
  "babel-loader": "10.0.0",
39
- "prebundle": "1.4.0",
40
- "typescript": "^5.9.2",
41
- "@rsbuild/core": "1.4.14",
39
+ "prebundle": "1.6.0",
40
+ "typescript": "^5.9.3",
41
+ "@rsbuild/core": "1.7.2",
42
42
  "@scripts/test-helper": "1.0.1"
43
43
  },
44
44
  "peerDependencies": {
45
- "@rsbuild/core": "1.x"
45
+ "@rsbuild/core": "^1.0.0 || ^2.0.0-0"
46
46
  },
47
47
  "publishConfig": {
48
48
  "access": "public",
@@ -50,8 +50,8 @@
50
50
  },
51
51
  "scripts": {
52
52
  "build": "rslib build",
53
- "dev": "rslib build --watch",
53
+ "dev": "rslib build -w",
54
54
  "prebundle": "prebundle",
55
- "bump": "npx bumpp --no-tag"
55
+ "bump": "pnpx bumpp --no-tag"
56
56
  }
57
57
  }
@@ -1 +0,0 @@
1
- module.exports.validate = () => {};