@rsbuild/plugin-babel 1.1.2 → 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.
- package/compiled/babel-loader/index.js +16 -28
- package/compiled/babel-loader/package.json +1 -1
- package/dist/helper.d.ts +2 -1
- package/dist/index.cjs +9 -5
- package/dist/index.js +7 -3
- package/package.json +15 -17
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
-
|
|
3
|
+
482: (module) => {
|
|
4
4
|
const STRIP_FILENAME_RE = /^[^:]+: /;
|
|
5
5
|
const format = (err) => {
|
|
6
6
|
if (err instanceof SyntaxError) {
|
|
@@ -26,8 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
module.exports = LoaderError;
|
|
28
28
|
},
|
|
29
|
-
|
|
30
|
-
const nodeModule = __nccwpck_require__(995);
|
|
29
|
+
686: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
31
30
|
const os = __nccwpck_require__(857);
|
|
32
31
|
const path = __nccwpck_require__(928);
|
|
33
32
|
const zlib = __nccwpck_require__(106);
|
|
@@ -35,18 +34,11 @@
|
|
|
35
34
|
const { readFile, writeFile, mkdir } = __nccwpck_require__(943);
|
|
36
35
|
const { sync: findUpSync } = __nccwpck_require__(48);
|
|
37
36
|
const { env } = process;
|
|
38
|
-
const transform = __nccwpck_require__(
|
|
39
|
-
const serialize = __nccwpck_require__(
|
|
37
|
+
const transform = __nccwpck_require__(816);
|
|
38
|
+
const serialize = __nccwpck_require__(946);
|
|
40
39
|
let defaultCacheDirectory = null;
|
|
41
40
|
const gunzip = promisify(zlib.gunzip);
|
|
42
41
|
const gzip = promisify(zlib.gzip);
|
|
43
|
-
const findRootPackageJSON = () => {
|
|
44
|
-
if (nodeModule.findPackageJSON) {
|
|
45
|
-
return nodeModule.findPackageJSON("..", __filename);
|
|
46
|
-
} else {
|
|
47
|
-
return findUpSync("package.json");
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
42
|
const read = async function (filename, compress) {
|
|
51
43
|
const data = await readFile(filename + (compress ? ".gz" : ""));
|
|
52
44
|
const content = compress ? await gunzip(data) : data;
|
|
@@ -170,7 +162,7 @@
|
|
|
170
162
|
) {
|
|
171
163
|
return path.join(env.CACHE_DIR, name);
|
|
172
164
|
}
|
|
173
|
-
const rootPkgJSONPath =
|
|
165
|
+
const rootPkgJSONPath = findUpSync("package.json");
|
|
174
166
|
if (rootPkgJSONPath) {
|
|
175
167
|
return path.join(
|
|
176
168
|
path.dirname(rootPkgJSONPath),
|
|
@@ -182,7 +174,7 @@
|
|
|
182
174
|
return os.tmpdir();
|
|
183
175
|
}
|
|
184
176
|
},
|
|
185
|
-
|
|
177
|
+
688: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
186
178
|
let babel;
|
|
187
179
|
try {
|
|
188
180
|
babel = __nccwpck_require__(571);
|
|
@@ -201,10 +193,10 @@
|
|
|
201
193
|
);
|
|
202
194
|
}
|
|
203
195
|
const { version } = __nccwpck_require__(344);
|
|
204
|
-
const cache = __nccwpck_require__(
|
|
205
|
-
const transform = __nccwpck_require__(
|
|
206
|
-
const injectCaller = __nccwpck_require__(
|
|
207
|
-
const schema = __nccwpck_require__(
|
|
196
|
+
const cache = __nccwpck_require__(686);
|
|
197
|
+
const transform = __nccwpck_require__(816);
|
|
198
|
+
const injectCaller = __nccwpck_require__(515);
|
|
199
|
+
const schema = __nccwpck_require__(919);
|
|
208
200
|
const { isAbsolute } = __nccwpck_require__(928);
|
|
209
201
|
const { promisify } = __nccwpck_require__(23);
|
|
210
202
|
function subscribe(subscriber, metadata, context) {
|
|
@@ -391,7 +383,7 @@
|
|
|
391
383
|
return [source, inputSourceMap];
|
|
392
384
|
}
|
|
393
385
|
},
|
|
394
|
-
|
|
386
|
+
515: (module) => {
|
|
395
387
|
module.exports = function injectCaller(opts, target) {
|
|
396
388
|
return {
|
|
397
389
|
...opts,
|
|
@@ -408,7 +400,7 @@
|
|
|
408
400
|
};
|
|
409
401
|
};
|
|
410
402
|
},
|
|
411
|
-
|
|
403
|
+
946: (module) => {
|
|
412
404
|
var objToString = Object.prototype.toString;
|
|
413
405
|
var objKeys = Object.getOwnPropertyNames;
|
|
414
406
|
function serialize(val, isArrayProp) {
|
|
@@ -474,10 +466,10 @@
|
|
|
474
466
|
}
|
|
475
467
|
};
|
|
476
468
|
},
|
|
477
|
-
|
|
469
|
+
816: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
478
470
|
const babel = __nccwpck_require__(571);
|
|
479
471
|
const { promisify } = __nccwpck_require__(23);
|
|
480
|
-
const LoaderError = __nccwpck_require__(
|
|
472
|
+
const LoaderError = __nccwpck_require__(482);
|
|
481
473
|
const babelTransform = babel.transformAsync ?? promisify(babel.transform);
|
|
482
474
|
module.exports = async function transform(source, options) {
|
|
483
475
|
let result;
|
|
@@ -812,10 +804,6 @@
|
|
|
812
804
|
"use strict";
|
|
813
805
|
module.exports = require("fs/promises");
|
|
814
806
|
},
|
|
815
|
-
995: (module) => {
|
|
816
|
-
"use strict";
|
|
817
|
-
module.exports = require("node:module");
|
|
818
|
-
},
|
|
819
807
|
857: (module) => {
|
|
820
808
|
"use strict";
|
|
821
809
|
module.exports = require("os");
|
|
@@ -832,7 +820,7 @@
|
|
|
832
820
|
"use strict";
|
|
833
821
|
module.exports = require("zlib");
|
|
834
822
|
},
|
|
835
|
-
|
|
823
|
+
919: (module) => {
|
|
836
824
|
"use strict";
|
|
837
825
|
module.exports = JSON.parse(
|
|
838
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}',
|
|
@@ -861,6 +849,6 @@
|
|
|
861
849
|
}
|
|
862
850
|
if (typeof __nccwpck_require__ !== "undefined")
|
|
863
851
|
__nccwpck_require__.ab = __dirname + "/";
|
|
864
|
-
var __webpack_exports__ = __nccwpck_require__(
|
|
852
|
+
var __webpack_exports__ = __nccwpck_require__(688);
|
|
865
853
|
module.exports = __webpack_exports__;
|
|
866
854
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"babel-loader","author":"Luis Couto <hello@luiscouto.pt>","version":"10.1.
|
|
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[
|
|
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
|
-
|
|
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',
|
|
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
|
|
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(
|
|
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(
|
|
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,
|
|
@@ -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(
|
|
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.
|
|
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,20 +24,20 @@
|
|
|
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.
|
|
29
|
-
"@babel/preset-typescript": "^7.
|
|
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.
|
|
30
|
+
"reduce-configs": "^1.1.2"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
|
-
"@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.
|
|
35
|
-
"@rslib/core": "0.
|
|
36
|
-
"@types/node": "^24.12.
|
|
37
|
-
"babel-loader": "10.1.
|
|
38
|
-
"prebundle": "1.6.
|
|
39
|
-
"typescript": "^
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
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"
|
|
@@ -53,9 +52,8 @@
|
|
|
53
52
|
"registry": "https://registry.npmjs.org/"
|
|
54
53
|
},
|
|
55
54
|
"scripts": {
|
|
56
|
-
"build": "rslib
|
|
57
|
-
"dev": "rslib
|
|
58
|
-
"prebundle": "prebundle"
|
|
59
|
-
"bump": "pnpx bumpp --no-tag"
|
|
55
|
+
"build": "rslib",
|
|
56
|
+
"dev": "rslib -w",
|
|
57
|
+
"prebundle": "prebundle"
|
|
60
58
|
}
|
|
61
59
|
}
|