Skip to content

Commit 8187d30

Browse files
committed
♻️ resolve circular dependencies
1 parent f92a885 commit 8187d30

File tree

3 files changed

+56
-59
lines changed

3 files changed

+56
-59
lines changed

lib/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,21 @@ import { UserscriptPlugin } from './plugin';
44

55
export default UserscriptPlugin;
66

7+
export {
8+
Feature,
9+
HeaderClass,
10+
HeadersProvider,
11+
LoadHeadersOptions,
12+
ProxyScriptFeatureOptions,
13+
ProxyScriptOptions,
14+
RenderHeadersOptions,
15+
ResolveBaseURLsOptions,
16+
SSRIAlgorithm,
17+
SSRIFeatureOptions,
18+
SSRIOptions,
19+
SSRITag,
20+
URLFilter,
21+
ValidateHeadersOptions,
22+
} from './features';
723
export * from './plugin';
824
export * from './types';

lib/plugin.ts

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,50 @@ import {
1212
FixTags,
1313
Interpolater,
1414
LoadHeaders,
15+
LoadHeadersOptions,
1516
ProcessProxyScript,
1617
ProcessSSRI,
18+
ProxyScriptOptions,
1719
RenderHeaders,
20+
RenderHeadersOptions,
1821
ResolveBaseURLs,
22+
ResolveBaseURLsOptions,
1923
SetDefaultTags,
24+
SSRIOptions,
2025
ValidateHeaders,
26+
ValidateHeadersOptions,
2127
} from './features';
2228
import {
2329
CompilationContext,
2430
FileInfo,
2531
HeadersProps,
26-
UserscriptOptions,
2732
UserscriptPluginInstance,
2833
WaterfallContext,
2934
} from './types';
3035
import { date } from './utils';
3136

3237
const { ConcatSource, RawSource } = sources;
3338

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+
3453
export class UserscriptPlugin
3554
implements WebpackPluginInstance, UserscriptPluginInstance
3655
{
3756
public readonly name = 'UserscriptPlugin';
3857

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[];
5059

5160
public readonly hooks = {
5261
init: new AsyncParallelHook<[Compiler]>(['compiler']),
@@ -79,14 +88,25 @@ export class UserscriptPlugin
7988
};
8089

8190
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;
90110
}
91111

92112
public apply(compiler: Compiler): void {

lib/types.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ import {
55
} from 'tapable';
66
import { Chunk, Compilation, Compiler } from 'webpack';
77

8-
import {
9-
LoadHeadersOptions,
10-
ProxyScriptOptions,
11-
RenderHeadersOptions,
12-
ResolveBaseURLsOptions,
13-
SSRIOptions,
14-
ValidateHeadersOptions,
15-
} from './features';
16-
178
export type SingleValue = string | undefined;
189
export type MultiValue = SingleValue | SingleValue[];
1910
export type NamedValue = Record<string, SingleValue>;
@@ -141,33 +132,3 @@ export interface UserscriptPluginInstance {
141132
renderProxyHeaders: AsyncSeriesBailHook<HeadersProps, string>;
142133
};
143134
}
144-
145-
export interface UserscriptPluginOptions {
146-
metajs?: boolean;
147-
skip?: (fileInfo: FileInfo) => boolean;
148-
}
149-
150-
export type UserscriptOptions = LoadHeadersOptions &
151-
ResolveBaseURLsOptions &
152-
SSRIOptions &
153-
ProxyScriptOptions &
154-
RenderHeadersOptions &
155-
ValidateHeadersOptions &
156-
UserscriptPluginOptions;
157-
158-
export {
159-
Feature,
160-
HeaderClass,
161-
HeadersProvider,
162-
LoadHeadersOptions,
163-
ProxyScriptFeatureOptions,
164-
ProxyScriptOptions,
165-
RenderHeadersOptions,
166-
ResolveBaseURLsOptions,
167-
SSRIAlgorithm,
168-
SSRIFeatureOptions,
169-
SSRIOptions,
170-
SSRITag,
171-
URLFilter,
172-
ValidateHeadersOptions,
173-
} from './features';

0 commit comments

Comments
 (0)