@@ -12,41 +12,50 @@ import {
12
12
FixTags ,
13
13
Interpolater ,
14
14
LoadHeaders ,
15
+ LoadHeadersOptions ,
15
16
ProcessProxyScript ,
16
17
ProcessSSRI ,
18
+ ProxyScriptOptions ,
17
19
RenderHeaders ,
20
+ RenderHeadersOptions ,
18
21
ResolveBaseURLs ,
22
+ ResolveBaseURLsOptions ,
19
23
SetDefaultTags ,
24
+ SSRIOptions ,
20
25
ValidateHeaders ,
26
+ ValidateHeadersOptions ,
21
27
} from './features' ;
22
28
import {
23
29
CompilationContext ,
24
30
FileInfo ,
25
31
HeadersProps ,
26
- UserscriptOptions ,
27
32
UserscriptPluginInstance ,
28
33
WaterfallContext ,
29
34
} from './types' ;
30
35
import { date } from './utils' ;
31
36
32
37
const { ConcatSource, RawSource } = sources ;
33
38
39
+ export interface UserscriptPluginOptions {
40
+ metajs ?: boolean ;
41
+ skip ?: ( fileInfo : FileInfo ) => boolean ;
42
+ proxyScript ?: unknown ;
43
+ }
44
+
45
+ export type UserscriptOptions = LoadHeadersOptions &
46
+ ResolveBaseURLsOptions &
47
+ SSRIOptions &
48
+ ProxyScriptOptions &
49
+ RenderHeadersOptions &
50
+ ValidateHeadersOptions &
51
+ UserscriptPluginOptions ;
52
+
34
53
export class UserscriptPlugin
35
54
implements WebpackPluginInstance , UserscriptPluginInstance
36
55
{
37
56
public readonly name = 'UserscriptPlugin' ;
38
57
39
- public readonly features : Feature [ ] = [
40
- new LoadHeaders ( this . options ) ,
41
- new FixTags ( this . options ) ,
42
- new ResolveBaseURLs ( this . options ) ,
43
- new ProcessSSRI ( this . options ) ,
44
- new SetDefaultTags ( this . options ) ,
45
- new ProcessProxyScript ( this . options ) ,
46
- new Interpolater ( this . options ) ,
47
- new ValidateHeaders ( this . options ) ,
48
- new RenderHeaders ( this . options ) ,
49
- ] ;
58
+ public readonly features : Feature [ ] ;
50
59
51
60
public readonly hooks = {
52
61
init : new AsyncParallelHook < [ Compiler ] > ( [ 'compiler' ] ) ,
@@ -79,14 +88,25 @@ export class UserscriptPlugin
79
88
} ;
80
89
81
90
private readonly contexts = new WeakMap < Compilation , CompilationContext > ( ) ;
82
-
83
- public constructor ( public options : UserscriptOptions = { } ) {
84
- const { metajs = true , strict = true } = this . options ;
85
-
86
- Object . assign ( this . options , {
87
- metajs,
88
- strict,
89
- } ) ;
91
+ private options : UserscriptPluginOptions = { } ;
92
+
93
+ public constructor ( options : UserscriptOptions = { } ) {
94
+ const { metajs = true , strict = true } = options ;
95
+ Object . assign ( options , { metajs, strict } as UserscriptOptions ) ;
96
+
97
+ this . features = [
98
+ new LoadHeaders ( options ) ,
99
+ new FixTags ( options ) ,
100
+ new ResolveBaseURLs ( options ) ,
101
+ new ProcessSSRI ( options ) ,
102
+ new SetDefaultTags ( options ) ,
103
+ new ProcessProxyScript ( options ) ,
104
+ new Interpolater ( options ) ,
105
+ new ValidateHeaders ( options ) ,
106
+ new RenderHeaders ( options ) ,
107
+ ] ;
108
+
109
+ this . options = options ;
90
110
}
91
111
92
112
public apply ( compiler : Compiler ) : void {
0 commit comments