@rsbuild/plugin-babel 1.1.0 → 1.1.2
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 +47 -24
- package/compiled/babel-loader/package.json +1 -1
- package/dist/index.cjs +10 -10
- package/dist/index.js +9 -7
- package/package.json +15 -12
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
-
|
|
3
|
+
718: (module) => {
|
|
4
4
|
const STRIP_FILENAME_RE = /^[^:]+: /;
|
|
5
5
|
const format = (err) => {
|
|
6
6
|
if (err instanceof SyntaxError) {
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
}
|
|
27
27
|
module.exports = LoaderError;
|
|
28
28
|
},
|
|
29
|
-
|
|
29
|
+
818: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
30
|
+
const nodeModule = __nccwpck_require__(995);
|
|
30
31
|
const os = __nccwpck_require__(857);
|
|
31
32
|
const path = __nccwpck_require__(928);
|
|
32
33
|
const zlib = __nccwpck_require__(106);
|
|
@@ -34,11 +35,18 @@
|
|
|
34
35
|
const { readFile, writeFile, mkdir } = __nccwpck_require__(943);
|
|
35
36
|
const { sync: findUpSync } = __nccwpck_require__(48);
|
|
36
37
|
const { env } = process;
|
|
37
|
-
const transform = __nccwpck_require__(
|
|
38
|
-
const serialize = __nccwpck_require__(
|
|
38
|
+
const transform = __nccwpck_require__(180);
|
|
39
|
+
const serialize = __nccwpck_require__(790);
|
|
39
40
|
let defaultCacheDirectory = null;
|
|
40
41
|
const gunzip = promisify(zlib.gunzip);
|
|
41
42
|
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
|
+
};
|
|
42
50
|
const read = async function (filename, compress) {
|
|
43
51
|
const data = await readFile(filename + (compress ? ".gz" : ""));
|
|
44
52
|
const content = compress ? await gunzip(data) : data;
|
|
@@ -129,6 +137,10 @@
|
|
|
129
137
|
}
|
|
130
138
|
logger.debug(`applying Babel transform`);
|
|
131
139
|
const result = await transform(source, options);
|
|
140
|
+
if (!result) {
|
|
141
|
+
logger.debug(`no result from Babel transform, skipping cache write`);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
132
144
|
await addTimestamps(result.externalDependencies, getFileTimestamp);
|
|
133
145
|
try {
|
|
134
146
|
logger.debug(`writing result to cache file '${file}'`);
|
|
@@ -141,7 +153,7 @@
|
|
|
141
153
|
}
|
|
142
154
|
return result;
|
|
143
155
|
};
|
|
144
|
-
module.exports = async function (params) {
|
|
156
|
+
module.exports = async function cache(params) {
|
|
145
157
|
let directory;
|
|
146
158
|
if (typeof params.cacheDirectory === "string") {
|
|
147
159
|
directory = params.cacheDirectory;
|
|
@@ -158,14 +170,19 @@
|
|
|
158
170
|
) {
|
|
159
171
|
return path.join(env.CACHE_DIR, name);
|
|
160
172
|
}
|
|
161
|
-
const rootPkgJSONPath =
|
|
173
|
+
const rootPkgJSONPath = findRootPackageJSON();
|
|
162
174
|
if (rootPkgJSONPath) {
|
|
163
|
-
return path.join(
|
|
175
|
+
return path.join(
|
|
176
|
+
path.dirname(rootPkgJSONPath),
|
|
177
|
+
"node_modules",
|
|
178
|
+
".cache",
|
|
179
|
+
name,
|
|
180
|
+
);
|
|
164
181
|
}
|
|
165
182
|
return os.tmpdir();
|
|
166
183
|
}
|
|
167
184
|
},
|
|
168
|
-
|
|
185
|
+
556: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
169
186
|
let babel;
|
|
170
187
|
try {
|
|
171
188
|
babel = __nccwpck_require__(571);
|
|
@@ -184,10 +201,10 @@
|
|
|
184
201
|
);
|
|
185
202
|
}
|
|
186
203
|
const { version } = __nccwpck_require__(344);
|
|
187
|
-
const cache = __nccwpck_require__(
|
|
188
|
-
const transform = __nccwpck_require__(
|
|
189
|
-
const injectCaller = __nccwpck_require__(
|
|
190
|
-
const schema = __nccwpck_require__(
|
|
204
|
+
const cache = __nccwpck_require__(818);
|
|
205
|
+
const transform = __nccwpck_require__(180);
|
|
206
|
+
const injectCaller = __nccwpck_require__(516);
|
|
207
|
+
const schema = __nccwpck_require__(625);
|
|
191
208
|
const { isAbsolute } = __nccwpck_require__(928);
|
|
192
209
|
const { promisify } = __nccwpck_require__(23);
|
|
193
210
|
function subscribe(subscriber, metadata, context) {
|
|
@@ -199,13 +216,14 @@
|
|
|
199
216
|
module.exports.custom = makeLoader;
|
|
200
217
|
function makeLoader(callback) {
|
|
201
218
|
const overrides = callback ? callback(babel) : undefined;
|
|
202
|
-
|
|
219
|
+
const webpackLoader = function (source, inputSourceMap) {
|
|
203
220
|
const callback = this.async();
|
|
204
221
|
loader.call(this, source, inputSourceMap, overrides).then(
|
|
205
222
|
(args) => callback(null, ...args),
|
|
206
223
|
(err) => callback(err),
|
|
207
224
|
);
|
|
208
225
|
};
|
|
226
|
+
return webpackLoader;
|
|
209
227
|
}
|
|
210
228
|
async function loader(source, inputSourceMap, overrides) {
|
|
211
229
|
const filename = this.resourcePath;
|
|
@@ -373,9 +391,10 @@
|
|
|
373
391
|
return [source, inputSourceMap];
|
|
374
392
|
}
|
|
375
393
|
},
|
|
376
|
-
|
|
394
|
+
516: (module) => {
|
|
377
395
|
module.exports = function injectCaller(opts, target) {
|
|
378
|
-
return
|
|
396
|
+
return {
|
|
397
|
+
...opts,
|
|
379
398
|
caller: Object.assign(
|
|
380
399
|
{
|
|
381
400
|
name: "babel-loader",
|
|
@@ -386,10 +405,10 @@
|
|
|
386
405
|
},
|
|
387
406
|
opts.caller,
|
|
388
407
|
),
|
|
389
|
-
}
|
|
408
|
+
};
|
|
390
409
|
};
|
|
391
410
|
},
|
|
392
|
-
|
|
411
|
+
790: (module) => {
|
|
393
412
|
var objToString = Object.prototype.toString;
|
|
394
413
|
var objKeys = Object.getOwnPropertyNames;
|
|
395
414
|
function serialize(val, isArrayProp) {
|
|
@@ -455,15 +474,15 @@
|
|
|
455
474
|
}
|
|
456
475
|
};
|
|
457
476
|
},
|
|
458
|
-
|
|
477
|
+
180: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
459
478
|
const babel = __nccwpck_require__(571);
|
|
460
479
|
const { promisify } = __nccwpck_require__(23);
|
|
461
|
-
const LoaderError = __nccwpck_require__(
|
|
462
|
-
const
|
|
463
|
-
module.exports = async function (source, options) {
|
|
480
|
+
const LoaderError = __nccwpck_require__(718);
|
|
481
|
+
const babelTransform = babel.transformAsync ?? promisify(babel.transform);
|
|
482
|
+
module.exports = async function transform(source, options) {
|
|
464
483
|
let result;
|
|
465
484
|
try {
|
|
466
|
-
result = await
|
|
485
|
+
result = await babelTransform(source, options);
|
|
467
486
|
} catch (err) {
|
|
468
487
|
throw err.message && err.codeFrame ? new LoaderError(err) : err;
|
|
469
488
|
}
|
|
@@ -793,6 +812,10 @@
|
|
|
793
812
|
"use strict";
|
|
794
813
|
module.exports = require("fs/promises");
|
|
795
814
|
},
|
|
815
|
+
995: (module) => {
|
|
816
|
+
"use strict";
|
|
817
|
+
module.exports = require("node:module");
|
|
818
|
+
},
|
|
796
819
|
857: (module) => {
|
|
797
820
|
"use strict";
|
|
798
821
|
module.exports = require("os");
|
|
@@ -809,7 +832,7 @@
|
|
|
809
832
|
"use strict";
|
|
810
833
|
module.exports = require("zlib");
|
|
811
834
|
},
|
|
812
|
-
|
|
835
|
+
625: (module) => {
|
|
813
836
|
"use strict";
|
|
814
837
|
module.exports = JSON.parse(
|
|
815
838
|
'{"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 +861,6 @@
|
|
|
838
861
|
}
|
|
839
862
|
if (typeof __nccwpck_require__ !== "undefined")
|
|
840
863
|
__nccwpck_require__.ab = __dirname + "/";
|
|
841
|
-
var __webpack_exports__ = __nccwpck_require__(
|
|
864
|
+
var __webpack_exports__ = __nccwpck_require__(556);
|
|
842
865
|
module.exports = __webpack_exports__;
|
|
843
866
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"babel-loader","author":"Luis Couto <hello@luiscouto.pt>","version":"10.
|
|
1
|
+
{"name":"babel-loader","author":"Luis Couto <hello@luiscouto.pt>","version":"10.1.0","license":"MIT","types":"index.d.ts","type":"commonjs"}
|
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"),
|
|
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)=>
|
|
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;
|
|
@@ -105,9 +103,7 @@ const BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array
|
|
|
105
103
|
].filter(Boolean))rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
|
|
106
104
|
}, external_node_fs_namespaceObject = require("node:fs");
|
|
107
105
|
var external_node_fs_default = __webpack_require__.n(external_node_fs_namespaceObject);
|
|
108
|
-
const external_node_module_namespaceObject = require("node:module"), external_node_url_namespaceObject = require("node:url"),
|
|
109
|
-
var external_deepmerge_default = __webpack_require__.n(external_deepmerge_namespaceObject);
|
|
110
|
-
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 = {
|
|
111
107
|
allowNamespaces: !0,
|
|
112
108
|
allExtensions: !0,
|
|
113
109
|
allowDeclareFields: !0,
|
|
@@ -129,7 +125,9 @@ function getDefaultBabelOptions(config, context) {
|
|
|
129
125
|
plugins: [
|
|
130
126
|
[
|
|
131
127
|
plugin_require.resolve('@babel/plugin-proposal-decorators'),
|
|
132
|
-
|
|
128
|
+
{
|
|
129
|
+
...config.source.decorators
|
|
130
|
+
}
|
|
133
131
|
],
|
|
134
132
|
...isLegacyDecorators ? [
|
|
135
133
|
plugin_require.resolve('@babel/plugin-transform-class-properties')
|
|
@@ -138,7 +136,9 @@ function getDefaultBabelOptions(config, context) {
|
|
|
138
136
|
presets: [
|
|
139
137
|
[
|
|
140
138
|
plugin_require.resolve("@babel/preset-typescript"),
|
|
141
|
-
|
|
139
|
+
{
|
|
140
|
+
...DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
|
|
141
|
+
}
|
|
142
142
|
]
|
|
143
143
|
]
|
|
144
144
|
}, { buildCache = !0 } = config.performance;
|
|
@@ -152,7 +152,7 @@ const pluginBabel = (options = {})=>({
|
|
|
152
152
|
name: PLUGIN_BABEL_NAME,
|
|
153
153
|
setup (api) {
|
|
154
154
|
let getBabelOptions = async (environment)=>{
|
|
155
|
-
let { config } = environment,
|
|
155
|
+
let { config } = environment, mergedOptions = applyUserBabelConfig(getDefaultBabelOptions(config, api.context), options.babelLoaderOptions);
|
|
156
156
|
return mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier && (mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions)), mergedOptions;
|
|
157
157
|
};
|
|
158
158
|
api.modifyBundlerChain({
|
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)=>
|
|
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] || {},
|
|
@@ -83,7 +81,9 @@ function getDefaultBabelOptions(config, context) {
|
|
|
83
81
|
plugins: [
|
|
84
82
|
[
|
|
85
83
|
plugin_require.resolve('@babel/plugin-proposal-decorators'),
|
|
86
|
-
|
|
84
|
+
{
|
|
85
|
+
...config.source.decorators
|
|
86
|
+
}
|
|
87
87
|
],
|
|
88
88
|
...isLegacyDecorators ? [
|
|
89
89
|
plugin_require.resolve('@babel/plugin-transform-class-properties')
|
|
@@ -92,7 +92,9 @@ function getDefaultBabelOptions(config, context) {
|
|
|
92
92
|
presets: [
|
|
93
93
|
[
|
|
94
94
|
plugin_require.resolve("@babel/preset-typescript"),
|
|
95
|
-
|
|
95
|
+
{
|
|
96
|
+
...DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
|
|
97
|
+
}
|
|
96
98
|
]
|
|
97
99
|
]
|
|
98
100
|
}, { buildCache = !0 } = config.performance;
|
|
@@ -106,7 +108,7 @@ let pluginBabel = (options = {})=>({
|
|
|
106
108
|
name: PLUGIN_BABEL_NAME,
|
|
107
109
|
setup (api) {
|
|
108
110
|
let getBabelOptions = async (environment)=>{
|
|
109
|
-
let { config } = environment, mergedOptions = ((defaultOptions, userBabelConfig
|
|
111
|
+
let { config } = environment, mergedOptions = ((defaultOptions, userBabelConfig)=>{
|
|
110
112
|
if (userBabelConfig) {
|
|
111
113
|
let babelUtils = {
|
|
112
114
|
...getBabelUtils(defaultOptions),
|
|
@@ -119,7 +121,7 @@ let pluginBabel = (options = {})=>({
|
|
|
119
121
|
});
|
|
120
122
|
}
|
|
121
123
|
return defaultOptions;
|
|
122
|
-
})(
|
|
124
|
+
})(getDefaultBabelOptions(config, api.context), options.babelLoaderOptions);
|
|
123
125
|
return mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier && (mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions)), mergedOptions;
|
|
124
126
|
};
|
|
125
127
|
api.modifyBundlerChain({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-babel",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Babel plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,28 +23,31 @@
|
|
|
23
23
|
"compiled"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@babel/core": "^7.
|
|
27
|
-
"@babel/plugin-proposal-decorators": "^7.
|
|
26
|
+
"@babel/core": "^7.29.0",
|
|
27
|
+
"@babel/plugin-proposal-decorators": "^7.29.0",
|
|
28
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
|
-
"
|
|
32
|
-
"reduce-configs": "^1.1.1",
|
|
33
|
-
"upath": "2.0.1"
|
|
31
|
+
"reduce-configs": "^1.1.1"
|
|
34
32
|
},
|
|
35
33
|
"devDependencies": {
|
|
36
|
-
"@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.
|
|
37
|
-
"@rslib/core": "0.
|
|
38
|
-
"@types/node": "^24.
|
|
39
|
-
"babel-loader": "10.
|
|
34
|
+
"@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.3",
|
|
35
|
+
"@rslib/core": "0.20.0",
|
|
36
|
+
"@types/node": "^24.12.0",
|
|
37
|
+
"babel-loader": "10.1.0",
|
|
40
38
|
"prebundle": "1.6.2",
|
|
41
39
|
"typescript": "^5.9.3",
|
|
42
|
-
"@scripts/test-helper": "1.0.
|
|
43
|
-
"@rsbuild/core": "2.0.0-
|
|
40
|
+
"@scripts/test-helper": "1.0.0",
|
|
41
|
+
"@rsbuild/core": "2.0.0-beta.8"
|
|
44
42
|
},
|
|
45
43
|
"peerDependencies": {
|
|
46
44
|
"@rsbuild/core": "^1.0.0 || ^2.0.0-0"
|
|
47
45
|
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"@rsbuild/core": {
|
|
48
|
+
"optional": true
|
|
49
|
+
}
|
|
50
|
+
},
|
|
48
51
|
"publishConfig": {
|
|
49
52
|
"access": "public",
|
|
50
53
|
"registry": "https://registry.npmjs.org/"
|