Skip to content

Commit fa5ea86

Browse files
committed
fix: shared Rsbuild plugin should run only once
1 parent e3f98f1 commit fa5ea86

File tree

8 files changed

+45
-1
lines changed

8 files changed

+45
-1
lines changed

packages/core/src/cli/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export async function build(
1111
const environments = await composeRsbuildEnvironments(config);
1212
const rsbuildInstance = await createRsbuild({
1313
rsbuildConfig: {
14+
plugins: config.plugins,
1415
environments: pruneEnvironments(environments, options.lib),
1516
},
1617
});

packages/core/src/cli/inspect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export async function inspect(
1010
const environments = await composeRsbuildEnvironments(config);
1111
const rsbuildInstance = await createRsbuild({
1212
rsbuildConfig: {
13+
plugins: config.plugins,
1314
environments: pruneEnvironments(environments, options.lib),
1415
},
1516
});

packages/core/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ export async function composeCreateRsbuildConfig(
12581258
rslibConfig: RslibConfig,
12591259
): Promise<RsbuildConfigWithLibInfo[]> {
12601260
const constantRsbuildConfig = await createConstantRsbuildConfig();
1261-
const { lib: libConfigsArray, ...sharedRsbuildConfig } = rslibConfig;
1261+
const { lib: libConfigsArray, plugins, ...sharedRsbuildConfig } = rslibConfig;
12621262

12631263
if (!libConfigsArray) {
12641264
throw new Error(

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import fs from 'node:fs';
2+
import { buildAndGetResults } from 'test-helper';
3+
import { expect, test } from 'vitest';
4+
import { distIndex } from './rslib.config';
5+
6+
test('should run shared plugins only once', async () => {
7+
const fixturePath = __dirname;
8+
await buildAndGetResults({ fixturePath });
9+
10+
const content = fs.readFileSync(distIndex, 'utf-8');
11+
expect(content).toEqual('count: 1');
12+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "plugins-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import type { RsbuildPlugin } from '@rsbuild/core';
4+
import { defineConfig } from '@rslib/core';
5+
6+
let count = 0;
7+
export const distIndex = path.resolve(__dirname, 'dist/count.txt');
8+
9+
const testPlugin: RsbuildPlugin = {
10+
name: 'test',
11+
setup(api) {
12+
api.onAfterBuild(() => {
13+
fs.writeFileSync(distIndex, `count: ${++count}`);
14+
});
15+
},
16+
};
17+
18+
export default defineConfig({
19+
lib: [{ format: 'esm' }, { format: 'cjs' }],
20+
plugins: [testPlugin],
21+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const test = 'hello';

0 commit comments

Comments
 (0)