File tree Expand file tree Collapse file tree 3 files changed +65
-1
lines changed
packages/ruleset-bundler/src Expand file tree Collapse file tree 3 files changed +65
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { rollup , Plugin } from 'rollup' ;
2
2
import { isURL } from '@stoplight/path' ;
3
3
import { isPackageImport } from './utils/isPackageImport' ;
4
+ import { dedupeRollupPlugins } from './utils/dedupeRollupPlugins' ;
4
5
5
6
export type BundleOptions = {
6
7
plugins : Plugin [ ] ;
@@ -17,7 +18,7 @@ export async function bundleRuleset(
17
18
) : Promise < string > {
18
19
const bundle = await rollup ( {
19
20
input,
20
- plugins,
21
+ plugins : dedupeRollupPlugins ( plugins ) ,
21
22
treeshake,
22
23
watch : false ,
23
24
perf : false ,
Original file line number Diff line number Diff line change
1
+ import type { Plugin } from 'rollup' ;
2
+
3
+ import { dedupeRollupPlugins } from '../dedupeRollupPlugins' ;
4
+
5
+ describe ( 'dedupeRollupPlugins util' , ( ) => {
6
+ it ( 'should keep plugins with different names' , ( ) => {
7
+ const plugins : Plugin [ ] = [
8
+ {
9
+ name : 'plugin 1' ,
10
+ } ,
11
+ {
12
+ name : 'plugin 2' ,
13
+ } ,
14
+ {
15
+ name : 'plugin 3' ,
16
+ } ,
17
+ ] ;
18
+
19
+ expect ( dedupeRollupPlugins ( [ ...plugins ] ) ) . toStrictEqual ( plugins ) ;
20
+ } ) ;
21
+
22
+ it ( 'given the same plugin, should replace the first declaration' , ( ) => {
23
+ const plugins : Plugin [ ] = [
24
+ {
25
+ name : 'plugin 1' ,
26
+ cacheKey : 'key 1' ,
27
+ } ,
28
+ {
29
+ name : 'plugin 2' ,
30
+ } ,
31
+ {
32
+ name : 'plugin 1' ,
33
+ cacheKey : 'key 2' ,
34
+ } ,
35
+ {
36
+ name : 'plugin 1' ,
37
+ cacheKey : 'key 3' ,
38
+ } ,
39
+ ] ;
40
+
41
+ expect ( dedupeRollupPlugins ( [ ...plugins ] ) ) . toStrictEqual ( [
42
+ {
43
+ name : 'plugin 1' ,
44
+ cacheKey : 'key 3' ,
45
+ } ,
46
+ {
47
+ name : 'plugin 2' ,
48
+ } ,
49
+ ] ) ;
50
+ } ) ;
51
+ } ) ;
Original file line number Diff line number Diff line change
1
+ // this function makes sure we can only have one plugin with the same name
2
+ // the last plugin definition has a precedence
3
+ import type { Plugin } from 'rollup' ;
4
+
5
+ export function dedupeRollupPlugins ( plugins : Plugin [ ] ) : Plugin [ ] {
6
+ const map = new Map < string , Plugin > ( ) ;
7
+ for ( const plugin of plugins ) {
8
+ map . set ( plugin . name , plugin ) ;
9
+ }
10
+
11
+ return Array . from ( map . values ( ) ) ;
12
+ }
You can’t perform that action at this time.
0 commit comments