@rsbuild/plugin-babel 1.1.1 → 1.2.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.
@@ -1,6 +1,6 @@
1
1
  (() => {
2
2
  var __webpack_modules__ = {
3
- 297: (module) => {
3
+ 482: (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
- 69: (module, __unused_webpack_exports, __nccwpck_require__) => {
29
+ 686: (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__(499);
38
- const serialize = __nccwpck_require__(641);
37
+ const transform = __nccwpck_require__(816);
38
+ const serialize = __nccwpck_require__(946);
39
39
  let defaultCacheDirectory = null;
40
40
  const gunzip = promisify(zlib.gunzip);
41
41
  const gzip = promisify(zlib.gzip);
@@ -129,6 +129,10 @@
129
129
  }
130
130
  logger.debug(`applying Babel transform`);
131
131
  const result = await transform(source, options);
132
+ if (!result) {
133
+ logger.debug(`no result from Babel transform, skipping cache write`);
134
+ return null;
135
+ }
132
136
  await addTimestamps(result.externalDependencies, getFileTimestamp);
133
137
  try {
134
138
  logger.debug(`writing result to cache file '${file}'`);
@@ -141,7 +145,7 @@
141
145
  }
142
146
  return result;
143
147
  };
144
- module.exports = async function (params) {
148
+ module.exports = async function cache(params) {
145
149
  let directory;
146
150
  if (typeof params.cacheDirectory === "string") {
147
151
  directory = params.cacheDirectory;
@@ -158,14 +162,19 @@
158
162
  ) {
159
163
  return path.join(env.CACHE_DIR, name);
160
164
  }
161
- const rootPkgJSONPath = path.dirname(findUpSync("package.json"));
165
+ const rootPkgJSONPath = findUpSync("package.json");
162
166
  if (rootPkgJSONPath) {
163
- return path.join(rootPkgJSONPath, "node_modules", ".cache", name);
167
+ return path.join(
168
+ path.dirname(rootPkgJSONPath),
169
+ "node_modules",
170
+ ".cache",
171
+ name,
172
+ );
164
173
  }
165
174
  return os.tmpdir();
166
175
  }
167
176
  },
168
- 523: (module, __unused_webpack_exports, __nccwpck_require__) => {
177
+ 688: (module, __unused_webpack_exports, __nccwpck_require__) => {
169
178
  let babel;
170
179
  try {
171
180
  babel = __nccwpck_require__(571);
@@ -184,10 +193,10 @@
184
193
  );
185
194
  }
186
195
  const { version } = __nccwpck_require__(344);
187
- const cache = __nccwpck_require__(69);
188
- const transform = __nccwpck_require__(499);
189
- const injectCaller = __nccwpck_require__(257);
190
- const schema = __nccwpck_require__(652);
196
+ const cache = __nccwpck_require__(686);
197
+ const transform = __nccwpck_require__(816);
198
+ const injectCaller = __nccwpck_require__(515);
199
+ const schema = __nccwpck_require__(919);
191
200
  const { isAbsolute } = __nccwpck_require__(928);
192
201
  const { promisify } = __nccwpck_require__(23);
193
202
  function subscribe(subscriber, metadata, context) {
@@ -199,13 +208,14 @@
199
208
  module.exports.custom = makeLoader;
200
209
  function makeLoader(callback) {
201
210
  const overrides = callback ? callback(babel) : undefined;
202
- return function (source, inputSourceMap) {
211
+ const webpackLoader = function (source, inputSourceMap) {
203
212
  const callback = this.async();
204
213
  loader.call(this, source, inputSourceMap, overrides).then(
205
214
  (args) => callback(null, ...args),
206
215
  (err) => callback(err),
207
216
  );
208
217
  };
218
+ return webpackLoader;
209
219
  }
210
220
  async function loader(source, inputSourceMap, overrides) {
211
221
  const filename = this.resourcePath;
@@ -373,9 +383,10 @@
373
383
  return [source, inputSourceMap];
374
384
  }
375
385
  },
376
- 257: (module) => {
386
+ 515: (module) => {
377
387
  module.exports = function injectCaller(opts, target) {
378
- return Object.assign({}, opts, {
388
+ return {
389
+ ...opts,
379
390
  caller: Object.assign(
380
391
  {
381
392
  name: "babel-loader",
@@ -386,10 +397,10 @@
386
397
  },
387
398
  opts.caller,
388
399
  ),
389
- });
400
+ };
390
401
  };
391
402
  },
392
- 641: (module) => {
403
+ 946: (module) => {
393
404
  var objToString = Object.prototype.toString;
394
405
  var objKeys = Object.getOwnPropertyNames;
395
406
  function serialize(val, isArrayProp) {
@@ -455,15 +466,15 @@
455
466
  }
456
467
  };
457
468
  },
458
- 499: (module, __unused_webpack_exports, __nccwpck_require__) => {
469
+ 816: (module, __unused_webpack_exports, __nccwpck_require__) => {
459
470
  const babel = __nccwpck_require__(571);
460
471
  const { promisify } = __nccwpck_require__(23);
461
- const LoaderError = __nccwpck_require__(297);
462
- const transform = promisify(babel.transform);
463
- module.exports = async function (source, options) {
472
+ const LoaderError = __nccwpck_require__(482);
473
+ const babelTransform = babel.transformAsync ?? promisify(babel.transform);
474
+ module.exports = async function transform(source, options) {
464
475
  let result;
465
476
  try {
466
- result = await transform(source, options);
477
+ result = await babelTransform(source, options);
467
478
  } catch (err) {
468
479
  throw err.message && err.codeFrame ? new LoaderError(err) : err;
469
480
  }
@@ -809,7 +820,7 @@
809
820
  "use strict";
810
821
  module.exports = require("zlib");
811
822
  },
812
- 652: (module) => {
823
+ 919: (module) => {
813
824
  "use strict";
814
825
  module.exports = JSON.parse(
815
826
  '{"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 +849,6 @@
838
849
  }
839
850
  if (typeof __nccwpck_require__ !== "undefined")
840
851
  __nccwpck_require__.ab = __dirname + "/";
841
- var __webpack_exports__ = __nccwpck_require__(523);
852
+ var __webpack_exports__ = __nccwpck_require__(688);
842
853
  module.exports = __webpack_exports__;
843
854
  })();
@@ -1 +1 @@
1
- {"name":"babel-loader","author":"Luis Couto <hello@luiscouto.pt>","version":"10.0.0","license":"MIT","types":"index.d.ts","type":"commonjs"}
1
+ {"name":"babel-loader","author":"Luis Couto <hello@luiscouto.pt>","version":"10.1.1","license":"MIT","types":"index.d.ts","type":"commonjs"}
package/dist/helper.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import type { ChainIdentifier, RspackChain } from '@rsbuild/core';
2
2
  import type { BabelConfigUtils, BabelLoaderOptions, BabelTransformOptions, PluginBabelOptions } from './types.js';
3
3
  export declare const BABEL_JS_RULE = "babel-js";
4
+ export declare const getBabelRuleId: (chain: RspackChain) => string;
4
5
  export declare const castArray: <T>(arr?: T | T[]) => T[];
5
6
  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 applyUserBabelConfig: (defaultOptions: BabelLoaderOptions, userBabelConfig?: PluginBabelOptions['babelLoaderOptions'], extraBabelUtils?: Partial<BabelConfigUtils>) => BabelLoaderOptions;
7
8
  export declare const modifyBabelLoaderOptions: ({ chain, CHAIN_ID, modifier, }: {
8
9
  chain: RspackChain;
9
10
  CHAIN_ID: ChainIdentifier;
package/dist/index.cjs CHANGED
@@ -20,15 +20,19 @@ __webpack_require__.n = (module)=>{
20
20
  };
21
21
  var __webpack_exports__ = {};
22
22
  __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
23
- getDefaultBabelOptions: ()=>getDefaultBabelOptions,
23
+ PLUGIN_BABEL_NAME: ()=>PLUGIN_BABEL_NAME,
24
24
  getBabelUtils: ()=>getBabelUtils,
25
+ getDefaultBabelOptions: ()=>getDefaultBabelOptions,
25
26
  modifyBabelLoaderOptions: ()=>modifyBabelLoaderOptions,
26
- PLUGIN_BABEL_NAME: ()=>PLUGIN_BABEL_NAME,
27
27
  pluginBabel: ()=>pluginBabel
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"), 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', BABEL_JS_RULE_REGEXP = /^babel-js(?:-\d+)?$/, getBabelRuleId = (chain)=>{
32
+ let id = BABEL_JS_RULE, index = 0;
33
+ for(; chain.module.rules.has(id);)id = `${BABEL_JS_RULE}-${++index}`;
34
+ return id;
35
+ }, isBabelRuleId = (id)=>BABEL_JS_RULE_REGEXP.test(id), getBabelRules = (chain)=>Object.keys(chain.module.rules.entries()).filter(isBabelRuleId).map((id)=>chain.module.rules.get(id)), castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
32
36
  arr
33
37
  ], 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)=>{
34
38
  config.plugins ? config.plugins.push(...plugins) : config.plugins = plugins;
@@ -99,7 +103,7 @@ const external_reduce_configs_namespaceObject = require("reduce-configs"), BABEL
99
103
  for (let rule of [
100
104
  chain.module.rules.get(CHAIN_ID.RULE.JS).oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN),
101
105
  chain.module.rules.get(CHAIN_ID.RULE.JS_DATA_URI),
102
- chain.module.rules.get(BABEL_JS_RULE)
106
+ ...getBabelRules(chain)
103
107
  ].filter(Boolean))rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
104
108
  }, external_node_fs_namespaceObject = require("node:fs");
105
109
  var external_node_fs_default = __webpack_require__.n(external_node_fs_namespaceObject);
@@ -160,7 +164,7 @@ const pluginBabel = (options = {})=>({
160
164
  handler: async (chain, { CHAIN_ID, environment })=>{
161
165
  let babelOptions = await getBabelOptions(environment), babelLoader = external_node_path_default().resolve(plugin_dirname, '../compiled/babel-loader/index.js'), { include, exclude } = options;
162
166
  if (include || exclude) {
163
- let rule = chain.module.rule(BABEL_JS_RULE).after(CHAIN_ID.RULE.JS);
167
+ let rule = chain.module.rule(getBabelRuleId(chain)).after(CHAIN_ID.RULE.JS);
164
168
  if (include) for (let condition of castArray(include))rule.include.add(condition);
165
169
  if (exclude) for (let condition of castArray(exclude))rule.exclude.add(condition);
166
170
  rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { reduceConfigsWithContext } from "reduce-configs";
3
3
  import node_fs from "node:fs";
4
4
  import { createRequire } from "node:module";
5
5
  import { fileURLToPath } from "node:url";
6
- let BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
6
+ let BABEL_JS_RULE = 'babel-js', BABEL_JS_RULE_REGEXP = /^babel-js(?:-\d+)?$/, isBabelRuleId = (id)=>BABEL_JS_RULE_REGEXP.test(id), castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
7
7
  arr
8
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 = [])=>{
9
9
  presets.forEach((preset, index)=>{
@@ -57,7 +57,7 @@ let BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.i
57
57
  for (let rule of [
58
58
  chain.module.rules.get(CHAIN_ID.RULE.JS).oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN),
59
59
  chain.module.rules.get(CHAIN_ID.RULE.JS_DATA_URI),
60
- chain.module.rules.get(BABEL_JS_RULE)
60
+ ...Object.keys(chain.module.rules.entries()).filter(isBabelRuleId).map((id)=>chain.module.rules.get(id))
61
61
  ].filter(Boolean))rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
62
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 = {
63
63
  allowNamespaces: !0,
@@ -108,7 +108,7 @@ let pluginBabel = (options = {})=>({
108
108
  name: PLUGIN_BABEL_NAME,
109
109
  setup (api) {
110
110
  let getBabelOptions = async (environment)=>{
111
- let { config } = environment, mergedOptions = ((defaultOptions, userBabelConfig, extraBabelUtils)=>{
111
+ let { config } = environment, mergedOptions = ((defaultOptions, userBabelConfig)=>{
112
112
  if (userBabelConfig) {
113
113
  let babelUtils = {
114
114
  ...getBabelUtils(defaultOptions),
@@ -129,7 +129,11 @@ let pluginBabel = (options = {})=>({
129
129
  handler: async (chain, { CHAIN_ID, environment })=>{
130
130
  let babelOptions = await getBabelOptions(environment), babelLoader = node_path.resolve(plugin_dirname, '../compiled/babel-loader/index.js'), { include, exclude } = options;
131
131
  if (include || exclude) {
132
- let rule = chain.module.rule(BABEL_JS_RULE).after(CHAIN_ID.RULE.JS);
132
+ let rule = chain.module.rule(((chain)=>{
133
+ let id = BABEL_JS_RULE, index = 0;
134
+ for(; chain.module.rules.has(id);)id = `${BABEL_JS_RULE}-${++index}`;
135
+ return id;
136
+ })(chain)).after(CHAIN_ID.RULE.JS);
133
137
  if (include) for (let condition of castArray(include))rule.include.add(condition);
134
138
  if (exclude) for (let condition of castArray(exclude))rule.exclude.add(condition);
135
139
  rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-babel",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Babel plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,6 @@
16
16
  "require": "./dist/index.cjs"
17
17
  }
18
18
  },
19
- "main": "./dist/index.cjs",
20
19
  "types": "./dist/index.d.ts",
21
20
  "files": [
22
21
  "dist",
@@ -25,32 +24,36 @@
25
24
  "dependencies": {
26
25
  "@babel/core": "^7.29.0",
27
26
  "@babel/plugin-proposal-decorators": "^7.29.0",
28
- "@babel/plugin-transform-class-properties": "^7.28.6",
29
- "@babel/preset-typescript": "^7.28.5",
27
+ "@babel/plugin-transform-class-properties": "^7.29.7",
28
+ "@babel/preset-typescript": "^7.29.7",
30
29
  "@types/babel__core": "^7.20.5",
31
- "reduce-configs": "^1.1.1"
30
+ "reduce-configs": "^1.1.2"
32
31
  },
33
32
  "devDependencies": {
34
- "@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.3",
35
- "@rslib/core": "0.19.6",
36
- "@types/node": "^24.11.0",
37
- "babel-loader": "10.0.0",
38
- "prebundle": "1.6.2",
39
- "typescript": "^5.9.3",
40
- "@rsbuild/core": "2.0.0-beta.6",
41
- "@scripts/test-helper": "1.0.1"
33
+ "@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.5",
34
+ "@rslib/core": "0.21.5",
35
+ "@types/node": "^24.12.4",
36
+ "babel-loader": "10.1.1",
37
+ "prebundle": "1.6.4",
38
+ "typescript": "^6.0.3",
39
+ "@rsbuild/core": "2.0.7",
40
+ "@scripts/test-helper": "1.0.0"
42
41
  },
43
42
  "peerDependencies": {
44
43
  "@rsbuild/core": "^1.0.0 || ^2.0.0-0"
45
44
  },
45
+ "peerDependenciesMeta": {
46
+ "@rsbuild/core": {
47
+ "optional": true
48
+ }
49
+ },
46
50
  "publishConfig": {
47
51
  "access": "public",
48
52
  "registry": "https://registry.npmjs.org/"
49
53
  },
50
54
  "scripts": {
51
- "build": "rslib build",
52
- "dev": "rslib build -w",
53
- "prebundle": "prebundle",
54
- "bump": "pnpx bumpp --no-tag"
55
+ "build": "rslib",
56
+ "dev": "rslib -w",
57
+ "prebundle": "prebundle"
55
58
  }
56
59
  }