Skip to content

Commit 0cc5196

Browse files
authored
feat: add issuerLayer option to api.transform() (#3884)
1 parent d2449ba commit 0cc5196

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

packages/core/src/initPlugins.ts

+3
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ export function initPluginAPI({
280280
if (descriptor.layer) {
281281
rule.layer(descriptor.layer);
282282
}
283+
if (descriptor.issuerLayer) {
284+
rule.issuerLayer(descriptor.issuerLayer);
285+
}
283286

284287
const loaderName = descriptor.raw
285288
? 'transformRawLoader.cjs'

packages/core/src/types/plugin.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,20 @@ export type TransformDescriptor = {
286286
*/
287287
resourceQuery?: Rspack.RuleSetCondition;
288288
/**
289-
* Match based on the Rsbuild targets and only apply the transform to certain targets.
289+
* Match based on the Rsbuild targets and only apply the transform to
290+
* certain targets.
290291
* @see https://rsbuild.dev/config/output/target
291292
*/
292293
targets?: RsbuildTarget[];
293294
/**
294-
* Match based on the Rsbuild environment names and only apply the transform to certain environments.
295+
* Match based on the Rsbuild environment names and only apply the transform
296+
* to certain environments.
295297
* @see https://rsbuild.dev/config/environments
296298
*/
297299
environments?: string[];
298300
/**
299-
* If raw is `true`, the transform handler will receive the Buffer type code instead of the string type.
301+
* If raw is `true`, the transform handler will receive the Buffer type code
302+
* instead of the string type.
300303
* @see https://rspack.dev/api/loader-api/examples#raw-loader
301304
*/
302305
raw?: boolean;
@@ -307,6 +310,12 @@ export type TransformDescriptor = {
307310
* @see https://rspack.dev/config/module#rulelayer
308311
*/
309312
layer?: string;
313+
/**
314+
* Matches all modules that match this resource, and will match against layer of
315+
* the module that issued the current module.
316+
* @see https://rspack.dev/config/module#ruleissuerlayer
317+
*/
318+
issuerLayer?: string;
310319
};
311320

312321
export type TransformFn = (

website/docs/en/plugins/dev/core.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ api.transform({ test: /\.node$/, raw: true }, ({ code }) => {
259259
```
260260

261261
- `layer`: the same as Rspack's [Rule.layer](https://rspack.dev/config/module#rulelayer).
262+
- `issuerLayer`: the same as Rspack's [Rule.issuerLayer](https://rspack.dev/config/module#ruleissuerlayer).
262263

263264
### Handler Param
264265

website/docs/zh/plugins/dev/core.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ api.transform({ test: /\.node$/, raw: true }, ({ code }) => {
257257
```
258258

259259
- `layer`:等同于 Rspack 的 [Rule.layer](https://rspack.dev/config/module#rulelayer)
260+
- `issuerLayer`:等同于 Rspack 的 [Rule.issuerLayer](https://rspack.dev/config/module#ruleissuerlayer)
260261

261262
### handler 参数
262263

0 commit comments

Comments
 (0)