vite-userscript-plugin 1.11.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -98
- package/dist/index.d.ts +254 -180
- package/dist/index.js +890 -282
- package/package.json +51 -44
- package/types/greasemonkey.d.ts +267 -270
- package/types/tampermonkey.d.ts +1096 -954
- package/types/violentmonkey-ambient.d.ts +149 -0
- package/types/violentmonkey.d.ts +319 -186
- package/virtual.d.ts +7 -0
- package/dist/ws.js +0 -14
- package/types/README.md +0 -21
package/dist/index.d.ts
CHANGED
|
@@ -1,187 +1,261 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare const GM: readonly ["setValue", "getValue", "deleteValue", "listValues", "setClipboard", "addStyle", "addElement", "addValueChangeListener", "removeValueChangeListener", "registerMenuCommand", "unregisterMenuCommand", "download", "getTab", "getTabs", "saveTab", "openInTab", "notification", "getResourceURL", "getResourceText", "xmlhttpRequest", "log", "info"];
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
//#region src/grants/catalog.d.ts
|
|
3
|
+
declare const GM: readonly ["setValue", "getValue", "deleteValue", "listValues", "setValues", "getValues", "deleteValues", "setClipboard", "addStyle", "addElement", "addValueChangeListener", "removeValueChangeListener", "registerMenuCommand", "unregisterMenuCommand", "download", "getTab", "getTabs", "saveTab", "openInTab", "notification", "getResourceURL", "getResourceText", "xmlhttpRequest", "webRequest", "cookie", "audio", "log", "info"];
|
|
4
4
|
declare const GMwindow: readonly ["unsafeWindow", "window.onurlchange", "window.focus", "window.close"];
|
|
5
|
-
|
|
5
|
+
declare const GM_DOT_ALIASES: readonly ["GM.xmlHttpRequest", "GM.getResourceUrl"];
|
|
6
|
+
type CatalogGrant = `GM_${(typeof GM)[number]}` | `GM.${(typeof GM)[number]}` | (typeof GMwindow)[number] | (typeof GM_DOT_ALIASES)[number];
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/grants/types.d.ts
|
|
9
|
+
type Grants = CatalogGrant;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/types.d.ts
|
|
6
12
|
type RunAt = 'document-start' | 'document-body' | 'document-end' | 'document-idle' | 'context-menu';
|
|
7
|
-
type GMLiterals<T extends string> = [`GM_${T}` | `GM.${T}`];
|
|
8
|
-
type GMWindow = (typeof GMwindow)[number];
|
|
9
|
-
type Grants = GMWindow | GMLiterals<(typeof GM)[number]>[number];
|
|
10
13
|
type HeaderConfig = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
14
|
+
[property: string]: any;
|
|
15
|
+
/**
|
|
16
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:name
|
|
17
|
+
*/
|
|
18
|
+
'name': string;
|
|
19
|
+
/**
|
|
20
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:namespace
|
|
21
|
+
*/
|
|
22
|
+
'namespace'?: string;
|
|
23
|
+
/**
|
|
24
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:copyright
|
|
25
|
+
*/
|
|
26
|
+
'copyright'?: string;
|
|
27
|
+
/**
|
|
28
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:version
|
|
29
|
+
*/
|
|
30
|
+
'version': string;
|
|
31
|
+
/**
|
|
32
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:description
|
|
33
|
+
*/
|
|
34
|
+
'description'?: string;
|
|
35
|
+
/**
|
|
36
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon
|
|
37
|
+
*/
|
|
38
|
+
'icon'?: string;
|
|
39
|
+
/**
|
|
40
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon
|
|
41
|
+
*/
|
|
42
|
+
'iconURL'?: string;
|
|
43
|
+
/**
|
|
44
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon
|
|
45
|
+
*/
|
|
46
|
+
'defaulticon'?: string;
|
|
47
|
+
/**
|
|
48
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon64
|
|
49
|
+
*/
|
|
50
|
+
'icon64'?: string;
|
|
51
|
+
/**
|
|
52
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon64
|
|
53
|
+
*/
|
|
54
|
+
'icon64URL'?: string;
|
|
55
|
+
/**
|
|
56
|
+
* `@grant none` disables GM APIs. Do not mix with auto-detected grants.
|
|
57
|
+
*
|
|
58
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:grant
|
|
59
|
+
*/
|
|
60
|
+
'grant'?: Grants[] | 'none';
|
|
61
|
+
/**
|
|
62
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:author
|
|
63
|
+
*/
|
|
64
|
+
'author'?: string;
|
|
65
|
+
/**
|
|
66
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
67
|
+
*/
|
|
68
|
+
'homepage'?: string;
|
|
69
|
+
/**
|
|
70
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
71
|
+
*/
|
|
72
|
+
'homepageURL'?: string;
|
|
73
|
+
/**
|
|
74
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
75
|
+
*/
|
|
76
|
+
'website'?: string;
|
|
77
|
+
/**
|
|
78
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
|
79
|
+
*/
|
|
80
|
+
'source'?: string;
|
|
81
|
+
/**
|
|
82
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:antifeature
|
|
83
|
+
*/
|
|
84
|
+
'antifeature'?: [type: string, description: string][];
|
|
85
|
+
/**
|
|
86
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:require
|
|
87
|
+
*/
|
|
88
|
+
'require'?: string[] | string;
|
|
89
|
+
/**
|
|
90
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:resource
|
|
91
|
+
*/
|
|
92
|
+
'resource'?: [key: string, value: string][];
|
|
93
|
+
/**
|
|
94
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:include
|
|
95
|
+
*/
|
|
96
|
+
'include'?: string[] | string;
|
|
97
|
+
/**
|
|
98
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:match
|
|
99
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#match--exclude-match
|
|
100
|
+
*/
|
|
101
|
+
'match': string[] | string;
|
|
102
|
+
/**
|
|
103
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#match--exclude-match
|
|
104
|
+
*/
|
|
105
|
+
'exclude-match'?: string[] | string;
|
|
106
|
+
/**
|
|
107
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:exclude
|
|
108
|
+
*/
|
|
109
|
+
'exclude'?: string[] | string;
|
|
110
|
+
/**
|
|
111
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:run_at
|
|
112
|
+
*/
|
|
113
|
+
'run-at'?: RunAt;
|
|
114
|
+
/**
|
|
115
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:sandbox
|
|
116
|
+
*/
|
|
117
|
+
'sandbox'?: string;
|
|
118
|
+
/**
|
|
119
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:connect
|
|
120
|
+
*/
|
|
121
|
+
'connect'?: string[] | string;
|
|
122
|
+
/**
|
|
123
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:noframes
|
|
124
|
+
*/
|
|
125
|
+
'noframes'?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:updateURL
|
|
128
|
+
*/
|
|
129
|
+
'updateURL'?: string;
|
|
130
|
+
/**
|
|
131
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:downloadURL
|
|
132
|
+
*/
|
|
133
|
+
'downloadURL'?: string;
|
|
134
|
+
/**
|
|
135
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:supportURL
|
|
136
|
+
*/
|
|
137
|
+
'supportURL'?: string;
|
|
138
|
+
/**
|
|
139
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:webRequest
|
|
140
|
+
*/
|
|
141
|
+
'webRequest'?: string[];
|
|
142
|
+
/**
|
|
143
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:unwrap
|
|
144
|
+
*/
|
|
145
|
+
'unwrap'?: boolean;
|
|
141
146
|
};
|
|
142
147
|
interface ServerConfig {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Open the `.dev.user.js` install URL when the Vite server starts.
|
|
150
|
+
*
|
|
151
|
+
* @default false
|
|
152
|
+
*/
|
|
153
|
+
open?: boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Prefix applied to `@name` in serve mode.
|
|
156
|
+
* Set `false` to disable.
|
|
157
|
+
*
|
|
158
|
+
* @default 'server:'
|
|
159
|
+
*/
|
|
160
|
+
prefix?: string | false;
|
|
151
161
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
entry: string;
|
|
157
|
-
/**
|
|
158
|
-
* Userscript file name.
|
|
159
|
-
*/
|
|
160
|
-
fileName?: string;
|
|
161
|
-
/**
|
|
162
|
-
* Userscript header config.
|
|
163
|
-
*
|
|
164
|
-
* @see https://www.tampermonkey.net/documentation.php
|
|
165
|
-
*/
|
|
166
|
-
header: HeaderConfig;
|
|
167
|
-
/**
|
|
168
|
-
* Server config.
|
|
169
|
-
*/
|
|
170
|
-
server?: ServerConfig;
|
|
171
|
-
/**
|
|
172
|
-
* Override default esbuild transform options.
|
|
173
|
-
*
|
|
174
|
-
* @default
|
|
175
|
-
* ```json
|
|
176
|
-
* {
|
|
177
|
-
* "minify": true,
|
|
178
|
-
* "legalComments": "none"
|
|
179
|
-
* }
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
esbuildTransformOptions?: Omit<EsbuildTransformOptions, 'format' | 'target' | 'loader' | 'sourcemap'>;
|
|
162
|
+
type HeaderMode = 'serve' | 'build' | 'meta';
|
|
163
|
+
interface HeaderGenerateContext {
|
|
164
|
+
userscript: string;
|
|
165
|
+
mode: HeaderMode;
|
|
183
166
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
167
|
+
type CssInject = 'auto' | string | ((css: string) => void);
|
|
168
|
+
/**
|
|
169
|
+
* One userscript. Pass an object, or an array of these, to {@link UserscriptPluginConfig}.
|
|
170
|
+
*/
|
|
171
|
+
interface UserscriptConfig {
|
|
172
|
+
/**
|
|
173
|
+
* Path of the userscript entry.
|
|
174
|
+
*/
|
|
175
|
+
entry: string;
|
|
176
|
+
/**
|
|
177
|
+
* Output base name (`{fileName}.user.js`).
|
|
178
|
+
*
|
|
179
|
+
* @default sanitized `header.name`
|
|
180
|
+
*/
|
|
181
|
+
fileName?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Userscript header (`name`, `version`, `match` required).
|
|
184
|
+
*/
|
|
185
|
+
header: HeaderConfig;
|
|
186
|
+
/**
|
|
187
|
+
* Serve-mode options.
|
|
188
|
+
*/
|
|
189
|
+
server?: ServerConfig;
|
|
190
|
+
/**
|
|
191
|
+
* How to inject collected CSS in production builds.
|
|
192
|
+
*
|
|
193
|
+
* @default 'auto'
|
|
194
|
+
*/
|
|
195
|
+
cssInject?: CssInject;
|
|
196
|
+
/**
|
|
197
|
+
* Extra spaces after the longest `@key`, or `false` for a single space.
|
|
198
|
+
*
|
|
199
|
+
* @default 1
|
|
200
|
+
*/
|
|
201
|
+
align?: number | false;
|
|
202
|
+
/**
|
|
203
|
+
* Rewrite the generated metablock.
|
|
204
|
+
*/
|
|
205
|
+
generate?: (ctx: HeaderGenerateContext) => string;
|
|
206
|
+
/**
|
|
207
|
+
* Derive `updateURL` / `downloadURL` from `homepage`, `homepageURL`,
|
|
208
|
+
* `website`, or `source` when those fields are empty. Warns if no homepage
|
|
209
|
+
* alias is set, or if `metaFile` is `false` (`@updateURL` would point at a
|
|
210
|
+
* missing file).
|
|
211
|
+
*
|
|
212
|
+
* @default false
|
|
213
|
+
*/
|
|
214
|
+
autoMetaUrls?: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Emit `{fileName}.meta.js` alongside the userscript.
|
|
217
|
+
* Keep enabled when using `autoMetaUrls`, otherwise `@updateURL` 404s.
|
|
218
|
+
*
|
|
219
|
+
* @default true
|
|
220
|
+
*/
|
|
221
|
+
metaFile?: boolean;
|
|
222
|
+
}
|
|
223
|
+
type UserscriptPluginConfig = UserscriptConfig | UserscriptConfig[];
|
|
224
|
+
interface ResolvedScript {
|
|
225
|
+
entry: string;
|
|
226
|
+
fileName: string;
|
|
227
|
+
iifeName: string;
|
|
228
|
+
header: HeaderConfig;
|
|
229
|
+
server: {
|
|
230
|
+
open: boolean;
|
|
231
|
+
prefix: string | false;
|
|
232
|
+
};
|
|
233
|
+
cssInject: CssInject;
|
|
234
|
+
align: number | false;
|
|
235
|
+
generate?: (ctx: HeaderGenerateContext) => string;
|
|
236
|
+
autoMetaUrls: boolean;
|
|
237
|
+
metaFile: boolean;
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/header.d.ts
|
|
241
|
+
interface HeaderOptions {
|
|
242
|
+
align?: number | false;
|
|
243
|
+
autoMetaUrls?: boolean;
|
|
244
|
+
fileName?: string;
|
|
245
|
+
generate?: (ctx: HeaderGenerateContext) => string;
|
|
246
|
+
mode?: HeaderMode;
|
|
247
|
+
}
|
|
248
|
+
declare function resolveHomePage(header: HeaderConfig): string | undefined;
|
|
249
|
+
declare function resolvePublicFileUrl(header: HeaderConfig, fileName: string): string | undefined;
|
|
250
|
+
declare function generateHeader(config: HeaderConfig, options?: HeaderOptions): string;
|
|
251
|
+
declare class Header {
|
|
252
|
+
private readonly config;
|
|
253
|
+
private readonly options;
|
|
254
|
+
constructor(config: HeaderConfig, options?: HeaderOptions);
|
|
255
|
+
generate(): string;
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/plugin.d.ts
|
|
259
|
+
declare function UserscriptPlugin(config: UserscriptPluginConfig): Plugin[];
|
|
260
|
+
//#endregion
|
|
261
|
+
export { type CssInject, Header, type HeaderConfig, type HeaderGenerateContext, type ResolvedScript, type ServerConfig, type UserscriptConfig, type UserscriptPluginConfig, UserscriptPlugin as default, generateHeader, resolveHomePage, resolvePublicFileUrl };
|