@rsbuild/plugin-babel 1.0.7 → 1.1.1

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.
@@ -1,6 +1,6 @@
1
1
  (() => {
2
2
  var __webpack_modules__ = {
3
- 808: (module) => {
3
+ 297: (module) => {
4
4
  const STRIP_FILENAME_RE = /^[^:]+: /;
5
5
  const format = (err) => {
6
6
  if (err instanceof SyntaxError) {
@@ -26,7 +26,7 @@
26
26
  }
27
27
  module.exports = LoaderError;
28
28
  },
29
- 908: (module, __unused_webpack_exports, __nccwpck_require__) => {
29
+ 69: (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);
@@ -34,8 +34,8 @@
34
34
  const { readFile, writeFile, mkdir } = __nccwpck_require__(943);
35
35
  const { sync: findUpSync } = __nccwpck_require__(48);
36
36
  const { env } = process;
37
- const transform = __nccwpck_require__(30);
38
- const serialize = __nccwpck_require__(452);
37
+ const transform = __nccwpck_require__(499);
38
+ const serialize = __nccwpck_require__(641);
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
- 314: (module, __unused_webpack_exports, __nccwpck_require__) => {
168
+ 523: (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__(908);
188
- const transform = __nccwpck_require__(30);
189
- const injectCaller = __nccwpck_require__(174);
190
- const schema = __nccwpck_require__(779);
187
+ const cache = __nccwpck_require__(69);
188
+ const transform = __nccwpck_require__(499);
189
+ const injectCaller = __nccwpck_require__(257);
190
+ const schema = __nccwpck_require__(652);
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
- 174: (module) => {
376
+ 257: (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
- 452: (module) => {
392
+ 641: (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
- 30: (module, __unused_webpack_exports, __nccwpck_require__) => {
458
+ 499: (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__(808);
461
+ const LoaderError = __nccwpck_require__(297);
462
462
  const transform = promisify(babel.transform);
463
463
  module.exports = async function (source, options) {
464
464
  let result;
@@ -809,7 +809,7 @@
809
809
  "use strict";
810
810
  module.exports = require("zlib");
811
811
  },
812
- 779: (module) => {
812
+ 652: (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__(314);
841
+ var __webpack_exports__ = __nccwpck_require__(523);
842
842
  module.exports = __webpack_exports__;
843
843
  })();
package/dist/index.cjs CHANGED
@@ -28,11 +28,9 @@ __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_expo
28
28
  });
29
29
  const external_node_path_namespaceObject = require("node:path");
30
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 : [
31
+ const external_reduce_configs_namespaceObject = require("reduce-configs"), BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
34
32
  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)=>{
33
+ ], normalizeToPosixPath = (p)=>(0, external_node_path_namespaceObject.normalize)(p || '').replace(/\\/g, '/').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
34
  config.plugins ? config.plugins.push(...plugins) : config.plugins = plugins;
37
35
  }, addPresets = (presets, config)=>{
38
36
  config.presets ? config.presets.push(...presets) : config.presets = presets;
@@ -98,19 +96,14 @@ const BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array
98
96
  }
99
97
  return defaultOptions;
100
98
  }, 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);
108
- }
99
+ for (let rule of [
100
+ chain.module.rules.get(CHAIN_ID.RULE.JS).oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN),
101
+ chain.module.rules.get(CHAIN_ID.RULE.JS_DATA_URI),
102
+ chain.module.rules.get(BABEL_JS_RULE)
103
+ ].filter(Boolean))rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
109
104
  }, external_node_fs_namespaceObject = require("node:fs");
110
105
  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 = {
106
+ const external_node_module_namespaceObject = require("node:module"), external_node_url_namespaceObject = require("node:url"), 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
107
  allowNamespaces: !0,
115
108
  allExtensions: !0,
116
109
  allowDeclareFields: !0,
@@ -124,7 +117,7 @@ async function getCacheIdentifier(options) {
124
117
  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
118
  return identifier + `@babel/core@${coreVersion}babel-loader@${loaderVersion}`;
126
119
  }
127
- const getDefaultBabelOptions = (config, context)=>{
120
+ function getDefaultBabelOptions(config, context) {
128
121
  let isLegacyDecorators = 'legacy' === config.source.decorators.version, options = {
129
122
  babelrc: !1,
130
123
  configFile: !1,
@@ -132,7 +125,9 @@ const getDefaultBabelOptions = (config, context)=>{
132
125
  plugins: [
133
126
  [
134
127
  plugin_require.resolve('@babel/plugin-proposal-decorators'),
135
- config.source.decorators
128
+ {
129
+ ...config.source.decorators
130
+ }
136
131
  ],
137
132
  ...isLegacyDecorators ? [
138
133
  plugin_require.resolve('@babel/plugin-transform-class-properties')
@@ -141,7 +136,9 @@ const getDefaultBabelOptions = (config, context)=>{
141
136
  presets: [
142
137
  [
143
138
  plugin_require.resolve("@babel/preset-typescript"),
144
- DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
139
+ {
140
+ ...DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
141
+ }
145
142
  ]
146
143
  ]
147
144
  }, { buildCache = !0 } = config.performance;
@@ -150,11 +147,12 @@ const getDefaultBabelOptions = (config, context)=>{
150
147
  options.cacheCompression = !1, options.cacheDirectory = (0, external_node_path_namespaceObject.join)(cacheDirectory, 'babel-loader');
151
148
  }
152
149
  return options;
153
- }, pluginBabel = (options = {})=>({
150
+ }
151
+ const pluginBabel = (options = {})=>({
154
152
  name: PLUGIN_BABEL_NAME,
155
153
  setup (api) {
156
154
  let getBabelOptions = async (environment)=>{
157
- let { config } = environment, baseOptions = getDefaultBabelOptions(config, api.context), mergedOptions = applyUserBabelConfig(external_deepmerge_default()({}, baseOptions), options.babelLoaderOptions);
155
+ let { config } = environment, mergedOptions = applyUserBabelConfig(getDefaultBabelOptions(config, api.context), options.babelLoaderOptions);
158
156
  return mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier && (mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions)), mergedOptions;
159
157
  };
160
158
  api.modifyBundlerChain({
@@ -166,7 +164,10 @@ const getDefaultBabelOptions = (config, context)=>{
166
164
  if (include) for (let condition of castArray(include))rule.include.add(condition);
167
165
  if (exclude) for (let condition of castArray(exclude))rule.exclude.add(condition);
168
166
  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);
167
+ } else {
168
+ let isV1 = api.context.version.startsWith('1.'), jsRule = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX);
169
+ (isV1 ? jsRule : jsRule.oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN)).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
170
+ }
170
171
  }
171
172
  });
172
173
  }
package/dist/index.js CHANGED
@@ -1,13 +1,11 @@
1
1
  import node_path, { isAbsolute, join, normalize, sep } from "node:path";
2
2
  import { reduceConfigsWithContext } from "reduce-configs";
3
- import upath from "upath";
4
3
  import node_fs from "node:fs";
5
4
  import { createRequire } from "node:module";
6
5
  import { fileURLToPath } from "node:url";
7
- import deepmerge from "deepmerge";
8
6
  let BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
9
7
  arr
10
- ], normalizeToPosixPath = (p)=>upath.normalizeSafe(normalize(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`), formatPath = (originPath)=>isAbsolute(originPath) ? originPath.split(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 = [])=>{
8
+ ], normalizeToPosixPath = (p)=>normalize(p || '').replace(/\\/g, '/').replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`), formatPath = (originPath)=>isAbsolute(originPath) ? originPath.split(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 = [])=>{
11
9
  presets.forEach((preset, index)=>{
12
10
  Array.isArray(preset) ? 'string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName) && (preset[1] = {
13
11
  ...preset[1] || {},
@@ -56,14 +54,11 @@ let BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.i
56
54
  }
57
55
  };
58
56
  }, modifyBabelLoaderOptions = ({ chain, CHAIN_ID, modifier })=>{
59
- for (let ruleId of [
60
- CHAIN_ID.RULE.JS,
61
- CHAIN_ID.RULE.JS_DATA_URI,
62
- BABEL_JS_RULE
63
- ])if (chain.module.rules.has(ruleId)) {
64
- let rule = chain.module.rule(ruleId);
65
- rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
66
- }
57
+ for (let rule of [
58
+ chain.module.rules.get(CHAIN_ID.RULE.JS).oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN),
59
+ chain.module.rules.get(CHAIN_ID.RULE.JS_DATA_URI),
60
+ chain.module.rules.get(BABEL_JS_RULE)
61
+ ].filter(Boolean))rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
67
62
  }, plugin_dirname = node_path.dirname(fileURLToPath(import.meta.url)), plugin_require = createRequire(import.meta.url), PLUGIN_BABEL_NAME = 'rsbuild:babel', SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
68
63
  allowNamespaces: !0,
69
64
  allExtensions: !0,
@@ -78,7 +73,7 @@ async function getCacheIdentifier(options) {
78
73
  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 ?? '';
79
74
  return identifier + `@babel/core@${coreVersion}babel-loader@${loaderVersion}`;
80
75
  }
81
- let getDefaultBabelOptions = (config, context)=>{
76
+ function getDefaultBabelOptions(config, context) {
82
77
  let isLegacyDecorators = 'legacy' === config.source.decorators.version, options = {
83
78
  babelrc: !1,
84
79
  configFile: !1,
@@ -86,7 +81,9 @@ let getDefaultBabelOptions = (config, context)=>{
86
81
  plugins: [
87
82
  [
88
83
  plugin_require.resolve('@babel/plugin-proposal-decorators'),
89
- config.source.decorators
84
+ {
85
+ ...config.source.decorators
86
+ }
90
87
  ],
91
88
  ...isLegacyDecorators ? [
92
89
  plugin_require.resolve('@babel/plugin-transform-class-properties')
@@ -95,7 +92,9 @@ let getDefaultBabelOptions = (config, context)=>{
95
92
  presets: [
96
93
  [
97
94
  plugin_require.resolve("@babel/preset-typescript"),
98
- DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
95
+ {
96
+ ...DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
97
+ }
99
98
  ]
100
99
  ]
101
100
  }, { buildCache = !0 } = config.performance;
@@ -104,7 +103,8 @@ let getDefaultBabelOptions = (config, context)=>{
104
103
  options.cacheCompression = !1, options.cacheDirectory = join(cacheDirectory, 'babel-loader');
105
104
  }
106
105
  return options;
107
- }, pluginBabel = (options = {})=>({
106
+ }
107
+ let pluginBabel = (options = {})=>({
108
108
  name: PLUGIN_BABEL_NAME,
109
109
  setup (api) {
110
110
  let getBabelOptions = async (environment)=>{
@@ -121,7 +121,7 @@ let getDefaultBabelOptions = (config, context)=>{
121
121
  });
122
122
  }
123
123
  return defaultOptions;
124
- })(deepmerge({}, getDefaultBabelOptions(config, api.context)), options.babelLoaderOptions);
124
+ })(getDefaultBabelOptions(config, api.context), options.babelLoaderOptions);
125
125
  return mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier && (mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions)), mergedOptions;
126
126
  };
127
127
  api.modifyBundlerChain({
@@ -133,7 +133,10 @@ let getDefaultBabelOptions = (config, context)=>{
133
133
  if (include) for (let condition of castArray(include))rule.include.add(condition);
134
134
  if (exclude) for (let condition of castArray(exclude))rule.exclude.add(condition);
135
135
  rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
136
- } 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);
136
+ } else {
137
+ let isV1 = api.context.version.startsWith('1.'), jsRule = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX);
138
+ (isV1 ? jsRule : jsRule.oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN)).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
139
+ }
137
140
  }
138
141
  });
139
142
  }
package/dist/plugin.d.ts CHANGED
@@ -1,5 +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
- export declare const getDefaultBabelOptions: (config: NormalizedEnvironmentConfig, context: RsbuildContext) => BabelLoaderOptions;
4
+ export declare function getDefaultBabelOptions(config: NormalizedEnvironmentConfig, context: RsbuildContext): BabelLoaderOptions;
5
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.7",
3
+ "version": "1.1.1",
4
4
  "description": "Babel plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,22 +23,21 @@
23
23
  "compiled"
24
24
  ],
25
25
  "dependencies": {
26
- "@babel/core": "^7.28.5",
27
- "@babel/plugin-proposal-decorators": "^7.28.0",
28
- "@babel/plugin-transform-class-properties": "^7.27.1",
26
+ "@babel/core": "^7.29.0",
27
+ "@babel/plugin-proposal-decorators": "^7.29.0",
28
+ "@babel/plugin-transform-class-properties": "^7.28.6",
29
29
  "@babel/preset-typescript": "^7.28.5",
30
30
  "@types/babel__core": "^7.20.5",
31
- "deepmerge": "^4.3.1",
32
- "reduce-configs": "^1.1.1",
33
- "upath": "2.0.1"
31
+ "reduce-configs": "^1.1.1"
34
32
  },
35
33
  "devDependencies": {
36
- "@rslib/core": "0.19.1",
37
- "@types/node": "^24.10.4",
34
+ "@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.3",
35
+ "@rslib/core": "0.19.6",
36
+ "@types/node": "^24.11.0",
38
37
  "babel-loader": "10.0.0",
39
- "prebundle": "1.6.0",
38
+ "prebundle": "1.6.2",
40
39
  "typescript": "^5.9.3",
41
- "@rsbuild/core": "1.7.2",
40
+ "@rsbuild/core": "2.0.0-beta.6",
42
41
  "@scripts/test-helper": "1.0.1"
43
42
  },
44
43
  "peerDependencies": {