Skip to content

Commit

Permalink
feat: add issuerLayer option to api.transform() (#3884)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Nov 2, 2024
1 parent d2449ba commit 0cc5196
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/initPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ export function initPluginAPI({
if (descriptor.layer) {
rule.layer(descriptor.layer);
}
if (descriptor.issuerLayer) {
rule.issuerLayer(descriptor.issuerLayer);
}

const loaderName = descriptor.raw
? 'transformRawLoader.cjs'
Expand Down
15 changes: 12 additions & 3 deletions packages/core/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,20 @@ export type TransformDescriptor = {
*/
resourceQuery?: Rspack.RuleSetCondition;
/**
* Match based on the Rsbuild targets and only apply the transform to certain targets.
* Match based on the Rsbuild targets and only apply the transform to
* certain targets.
* @see https://rsbuild.dev/config/output/target
*/
targets?: RsbuildTarget[];
/**
* Match based on the Rsbuild environment names and only apply the transform to certain environments.
* Match based on the Rsbuild environment names and only apply the transform
* to certain environments.
* @see https://rsbuild.dev/config/environments
*/
environments?: string[];
/**
* If raw is `true`, the transform handler will receive the Buffer type code instead of the string type.
* If raw is `true`, the transform handler will receive the Buffer type code
* instead of the string type.
* @see https://rspack.dev/api/loader-api/examples#raw-loader
*/
raw?: boolean;
Expand All @@ -307,6 +310,12 @@ export type TransformDescriptor = {
* @see https://rspack.dev/config/module#rulelayer
*/
layer?: string;
/**
* Matches all modules that match this resource, and will match against layer of
* the module that issued the current module.
* @see https://rspack.dev/config/module#ruleissuerlayer
*/
issuerLayer?: string;
};

export type TransformFn = (
Expand Down
1 change: 1 addition & 0 deletions website/docs/en/plugins/dev/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ api.transform({ test: /\.node$/, raw: true }, ({ code }) => {
```

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

### Handler Param

Expand Down
1 change: 1 addition & 0 deletions website/docs/zh/plugins/dev/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ api.transform({ test: /\.node$/, raw: true }, ({ code }) => {
```

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

### handler 参数

Expand Down

1 comment on commit 0cc5196

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
plugins ✅ success
rspress ✅ success
rslib ✅ success
examples ✅ success

Please sign in to comment.