-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: shared Rsbuild plugin should run only once
- Loading branch information
1 parent
e3f98f1
commit fa5ea86
Showing
8 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import fs from 'node:fs'; | ||
import { buildAndGetResults } from 'test-helper'; | ||
import { expect, test } from 'vitest'; | ||
import { distIndex } from './rslib.config'; | ||
|
||
test('should run shared plugins only once', async () => { | ||
const fixturePath = __dirname; | ||
await buildAndGetResults({ fixturePath }); | ||
|
||
const content = fs.readFileSync(distIndex, 'utf-8'); | ||
expect(content).toEqual('count: 1'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "plugins-test", | ||
"version": "1.0.0", | ||
"private": true, | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import type { RsbuildPlugin } from '@rsbuild/core'; | ||
import { defineConfig } from '@rslib/core'; | ||
|
||
let count = 0; | ||
export const distIndex = path.resolve(__dirname, 'dist/count.txt'); | ||
|
||
const testPlugin: RsbuildPlugin = { | ||
name: 'test', | ||
setup(api) { | ||
api.onAfterBuild(() => { | ||
fs.writeFileSync(distIndex, `count: ${++count}`); | ||
}); | ||
}, | ||
}; | ||
|
||
export default defineConfig({ | ||
lib: [{ format: 'esm' }, { format: 'cjs' }], | ||
plugins: [testPlugin], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const test = 'hello'; |