@rsbuild/plugin-babel 1.0.0-alpha.2 → 1.0.0-alpha.3

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/dist/helper.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { ChainIdentifier, NormalizedConfig, RspackChain } from '@rsbuild/core';
2
2
  import type { BabelConfigUtils, BabelLoaderOptions, BabelTransformOptions, PluginBabelOptions } from './types';
3
3
  export declare const BABEL_JS_RULE = "babel-js";
4
+ export declare const castArray: <T>(arr?: T | T[]) => T[];
4
5
  export declare const getBabelUtils: (config: BabelTransformOptions) => BabelConfigUtils;
5
6
  export declare const applyUserBabelConfig: (defaultOptions: BabelLoaderOptions, userBabelConfig?: PluginBabelOptions["babelLoaderOptions"], extraBabelUtils?: Partial<BabelConfigUtils>) => BabelLoaderOptions;
6
7
  export declare const getUseBuiltIns: (config: NormalizedConfig) => false | "usage" | "entry";
package/dist/index.cjs CHANGED
@@ -42,14 +42,19 @@ module.exports = __toCommonJS(src_exports);
42
42
  // src/plugin.ts
43
43
  var import_node_fs = __toESM(require("fs"));
44
44
  var import_node_path2 = __toESM(require("path"));
45
- var import_shared2 = require("@rsbuild/shared");
45
+ var import_deepmerge = __toESM(require("deepmerge"));
46
46
 
47
47
  // src/helper.ts
48
48
  var import_node_path = require("path");
49
- var import_shared = require("@rsbuild/shared");
50
49
  var import_reduce_configs = require("reduce-configs");
51
50
  var import_upath = __toESM(require("upath"));
52
51
  var BABEL_JS_RULE = "babel-js";
52
+ var castArray = (arr) => {
53
+ if (arr === void 0) {
54
+ return [];
55
+ }
56
+ return Array.isArray(arr) ? arr : [arr];
57
+ };
53
58
  var normalizeToPosixPath = (p) => import_upath.default.normalizeSafe((0, import_node_path.normalize)(p || "")).replace(/^([a-zA-Z]+):/, (_, m) => `/${m.toLowerCase()}`);
54
59
  var formatPath = (originPath) => {
55
60
  if ((0, import_node_path.isAbsolute)(originPath)) {
@@ -84,7 +89,7 @@ var removePlugins = (plugins, config) => {
84
89
  if (!config.plugins) {
85
90
  return;
86
91
  }
87
- const removeList = (0, import_shared.castArray)(plugins);
92
+ const removeList = castArray(plugins);
88
93
  config.plugins = config.plugins.filter((item) => {
89
94
  const name = getPluginItemName(item);
90
95
  if (name) {
@@ -97,7 +102,7 @@ var removePresets = (presets, config) => {
97
102
  if (!config.presets) {
98
103
  return;
99
104
  }
100
- const removeList = (0, import_shared.castArray)(presets);
105
+ const removeList = castArray(presets);
101
106
  config.presets = config.presets.filter((item) => {
102
107
  const name = getPluginItemName(item);
103
108
  if (name) {
@@ -177,6 +182,7 @@ var modifyBabelLoaderOptions = ({
177
182
 
178
183
  // src/plugin.ts
179
184
  var PLUGIN_BABEL_NAME = "rsbuild:babel";
185
+ var SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
180
186
  var DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
181
187
  allowNamespaces: true,
182
188
  allExtensions: true,
@@ -245,7 +251,7 @@ var pluginBabel = (options = {}) => ({
245
251
  const { config } = environment;
246
252
  const baseOptions = getDefaultBabelOptions(config, api.context);
247
253
  const mergedOptions = applyUserBabelConfig(
248
- (0, import_shared2.cloneDeep)(baseOptions),
254
+ (0, import_deepmerge.default)({}, baseOptions),
249
255
  options.babelLoaderOptions
250
256
  );
251
257
  if (mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier) {
@@ -265,19 +271,19 @@ var pluginBabel = (options = {}) => ({
265
271
  if (include || exclude) {
266
272
  const rule = chain.module.rule(BABEL_JS_RULE).after(CHAIN_ID.RULE.JS);
267
273
  if (include) {
268
- for (const condition of (0, import_shared2.castArray)(include)) {
274
+ for (const condition of castArray(include)) {
269
275
  rule.include.add(condition);
270
276
  }
271
277
  }
272
278
  if (exclude) {
273
- for (const condition of (0, import_shared2.castArray)(exclude)) {
279
+ for (const condition of castArray(exclude)) {
274
280
  rule.exclude.add(condition);
275
281
  }
276
282
  }
277
- rule.test(import_shared2.SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
283
+ rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
278
284
  } else {
279
285
  const rule = chain.module.rule(CHAIN_ID.RULE.JS);
280
- rule.test(import_shared2.SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
286
+ rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
281
287
  }
282
288
  }
283
289
  });
package/dist/index.js CHANGED
@@ -19,14 +19,19 @@ var __dirname = /* @__PURE__ */ getDirname();
19
19
  // src/plugin.ts
20
20
  import fs from "fs";
21
21
  import path2, { isAbsolute as isAbsolute2, join } from "path";
22
- import { SCRIPT_REGEX, castArray as castArray2, cloneDeep } from "@rsbuild/shared";
22
+ import deepmerge from "deepmerge";
23
23
 
24
24
  // src/helper.ts
25
25
  import { isAbsolute, normalize, sep } from "path";
26
- import { castArray } from "@rsbuild/shared";
27
26
  import { reduceConfigsWithContext } from "reduce-configs";
28
27
  import upath from "upath";
29
28
  var BABEL_JS_RULE = "babel-js";
29
+ var castArray = (arr) => {
30
+ if (arr === void 0) {
31
+ return [];
32
+ }
33
+ return Array.isArray(arr) ? arr : [arr];
34
+ };
30
35
  var normalizeToPosixPath = (p) => upath.normalizeSafe(normalize(p || "")).replace(/^([a-zA-Z]+):/, (_, m) => `/${m.toLowerCase()}`);
31
36
  var formatPath = (originPath) => {
32
37
  if (isAbsolute(originPath)) {
@@ -154,6 +159,7 @@ var modifyBabelLoaderOptions = ({
154
159
 
155
160
  // src/plugin.ts
156
161
  var PLUGIN_BABEL_NAME = "rsbuild:babel";
162
+ var SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
157
163
  var DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
158
164
  allowNamespaces: true,
159
165
  allExtensions: true,
@@ -222,7 +228,7 @@ var pluginBabel = (options = {}) => ({
222
228
  const { config } = environment;
223
229
  const baseOptions = getDefaultBabelOptions(config, api.context);
224
230
  const mergedOptions = applyUserBabelConfig(
225
- cloneDeep(baseOptions),
231
+ deepmerge({}, baseOptions),
226
232
  options.babelLoaderOptions
227
233
  );
228
234
  if (mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier) {
@@ -242,12 +248,12 @@ var pluginBabel = (options = {}) => ({
242
248
  if (include || exclude) {
243
249
  const rule = chain.module.rule(BABEL_JS_RULE).after(CHAIN_ID.RULE.JS);
244
250
  if (include) {
245
- for (const condition of castArray2(include)) {
251
+ for (const condition of castArray(include)) {
246
252
  rule.include.add(condition);
247
253
  }
248
254
  }
249
255
  if (exclude) {
250
- for (const condition of castArray2(exclude)) {
256
+ for (const condition of castArray(exclude)) {
251
257
  rule.exclude.add(condition);
252
258
  }
253
259
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-babel",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.3",
4
4
  "description": "Babel plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,20 +28,20 @@
28
28
  "@babel/plugin-transform-class-properties": "^7.24.7",
29
29
  "@babel/preset-typescript": "^7.24.7",
30
30
  "@types/babel__core": "^7.20.5",
31
+ "deepmerge": "^4.3.1",
31
32
  "reduce-configs": "^1.0.0",
32
- "upath": "2.0.1",
33
- "@rsbuild/shared": "1.0.0-alpha.2"
33
+ "upath": "2.0.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "18.x",
37
37
  "babel-loader": "9.1.3",
38
38
  "prebundle": "1.1.0",
39
39
  "typescript": "^5.5.2",
40
- "@rsbuild/core": "1.0.0-alpha.2",
41
- "@scripts/test-helper": "1.0.0-alpha.2"
40
+ "@rsbuild/core": "1.0.0-alpha.3",
41
+ "@scripts/test-helper": "1.0.0-alpha.3"
42
42
  },
43
43
  "peerDependencies": {
44
- "@rsbuild/core": "^1.0.0-alpha.2"
44
+ "@rsbuild/core": "^1.0.0-alpha.3"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public",