1
1
import { readFileSync } from 'fs' ;
2
- import type { Plugin } from 'rollup' ;
2
+ import type { NormalizedOutputOptions , Plugin } from 'rollup' ;
3
3
4
4
interface MwGadgetConfig {
5
5
/** Path of the gadget definition file. */
6
6
gadgetDef : string ,
7
7
/** Additional lazy-load dependencies. */
8
8
softDependencies ?: string [ ] ,
9
- /** Set to `true` if you need ECMAScript 5 compatibility. */
10
- legacy ?: boolean ,
11
9
}
12
10
13
11
const OPTION_REGEX = / \[ ( .* ?) \] / ;
@@ -42,6 +40,7 @@ function getGadgetDependencies(gadgetDefPath: string): string[] {
42
40
function mwGadget ( config : MwGadgetConfig ) : Plugin {
43
41
const dependencies = getGadgetDependencies ( config . gadgetDef ) ;
44
42
const softDependencies = config . softDependencies ?? [ ] ;
43
+ let outputOptions : NormalizedOutputOptions ;
45
44
46
45
return {
47
46
name : 'mediawiki-gadget' ,
@@ -50,13 +49,16 @@ function mwGadget(config: MwGadgetConfig): Plugin {
50
49
return false ;
51
50
}
52
51
} ,
52
+ async renderStart ( receivedOutputOptions ) {
53
+ outputOptions = receivedOutputOptions ;
54
+ } ,
53
55
renderDynamicImport ( { targetModuleId } ) {
54
56
if ( targetModuleId && softDependencies . includes ( targetModuleId ) ) {
55
57
return {
56
58
left : 'mw.loader.using(' ,
57
- right : config . legacy
58
- ? `).then(function( require){return require("${ targetModuleId } ")} )`
59
- : `).then(require=> require("${ targetModuleId } "))` ,
59
+ right : outputOptions . generatedCode . arrowFunctions
60
+ ? `).then(require=> require("${ targetModuleId } "))`
61
+ : `).then(function( require){return require("${ targetModuleId } ")} )` ,
60
62
} ;
61
63
}
62
64
} ,
0 commit comments