@crxjs/vite-plugin 1.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.
@@ -0,0 +1,255 @@
1
+ import { ConfigEnv, Plugin, ViteDevServer, PluginOption } from 'vite';
2
+ import { PluginContext, OutputBundle, OutputOptions } from 'rollup';
3
+ import { Options } from 'fast-glob';
4
+
5
+ interface DeclarativeNetRequestResource {
6
+ id: string;
7
+ enabled: boolean;
8
+ path: string;
9
+ }
10
+ interface WebAccessibleResourceByMatch {
11
+ matches: string[];
12
+ resources: string[];
13
+ use_dynamic_url?: boolean;
14
+ }
15
+ interface WebAccessibleResourceById {
16
+ extension_ids: string[];
17
+ resources: string[];
18
+ use_dynamic_url?: boolean;
19
+ }
20
+ interface ManifestV3 {
21
+ manifest_version: number;
22
+ name: string;
23
+ version: string;
24
+ default_locale?: string | undefined;
25
+ description?: string | undefined;
26
+ icons?: chrome.runtime.ManifestIcons | undefined;
27
+ action?: chrome.runtime.ManifestAction | undefined;
28
+ author?: string | undefined;
29
+ background?: {
30
+ service_worker: string;
31
+ type?: 'module';
32
+ } | undefined;
33
+ chrome_settings_overrides?: {
34
+ homepage?: string | undefined;
35
+ search_provider?: chrome.runtime.SearchProvider | undefined;
36
+ startup_pages?: string[] | undefined;
37
+ } | undefined;
38
+ chrome_ui_overrides?: {
39
+ bookmarks_ui?: {
40
+ remove_bookmark_shortcut?: boolean | undefined;
41
+ remove_button?: boolean | undefined;
42
+ } | undefined;
43
+ } | undefined;
44
+ chrome_url_overrides?: {
45
+ bookmarks?: string | undefined;
46
+ history?: string | undefined;
47
+ newtab?: string | undefined;
48
+ } | undefined;
49
+ commands?: {
50
+ [name: string]: {
51
+ suggested_key?: {
52
+ default?: string | undefined;
53
+ windows?: string | undefined;
54
+ mac?: string | undefined;
55
+ chromeos?: string | undefined;
56
+ linux?: string | undefined;
57
+ } | undefined;
58
+ description?: string | undefined;
59
+ global?: boolean | undefined;
60
+ };
61
+ } | undefined;
62
+ content_capabilities?: {
63
+ matches?: string[] | undefined;
64
+ permissions?: string[] | undefined;
65
+ } | undefined;
66
+ content_scripts?: {
67
+ matches?: string[] | undefined;
68
+ exclude_matches?: string[] | undefined;
69
+ css?: string[] | undefined;
70
+ js?: string[] | undefined;
71
+ run_at?: string | undefined;
72
+ all_frames?: boolean | undefined;
73
+ match_about_blank?: boolean | undefined;
74
+ include_globs?: string[] | undefined;
75
+ exclude_globs?: string[] | undefined;
76
+ }[] | undefined;
77
+ content_security_policy?: {
78
+ extension_pages?: string;
79
+ sandbox?: string;
80
+ };
81
+ converted_from_user_script?: boolean | undefined;
82
+ current_locale?: string | undefined;
83
+ declarative_net_request?: {
84
+ rule_resources: DeclarativeNetRequestResource[];
85
+ };
86
+ devtools_page?: string | undefined;
87
+ event_rules?: {
88
+ event?: string | undefined;
89
+ actions?: {
90
+ type: string;
91
+ }[] | undefined;
92
+ conditions?: chrome.declarativeContent.PageStateMatcherProperties[] | undefined;
93
+ }[] | undefined;
94
+ externally_connectable?: {
95
+ ids?: string[] | undefined;
96
+ matches?: string[] | undefined;
97
+ accepts_tls_channel_id?: boolean | undefined;
98
+ } | undefined;
99
+ file_browser_handlers?: {
100
+ id?: string | undefined;
101
+ default_title?: string | undefined;
102
+ file_filters?: string[] | undefined;
103
+ }[] | undefined;
104
+ file_system_provider_capabilities?: {
105
+ configurable?: boolean | undefined;
106
+ watchable?: boolean | undefined;
107
+ multiple_mounts?: boolean | undefined;
108
+ source?: string | undefined;
109
+ } | undefined;
110
+ homepage_url?: string | undefined;
111
+ host_permissions?: string[] | undefined;
112
+ import?: {
113
+ id: string;
114
+ minimum_version?: string | undefined;
115
+ }[] | undefined;
116
+ export?: {
117
+ whitelist?: string[] | undefined;
118
+ } | undefined;
119
+ incognito?: string | undefined;
120
+ input_components?: {
121
+ name?: string | undefined;
122
+ type?: string | undefined;
123
+ id?: string | undefined;
124
+ description?: string | undefined;
125
+ language?: string | undefined;
126
+ layouts?: string[] | undefined;
127
+ }[] | undefined;
128
+ key?: string | undefined;
129
+ minimum_chrome_version?: string | undefined;
130
+ nacl_modules?: {
131
+ path: string;
132
+ mime_type: string;
133
+ }[] | undefined;
134
+ oauth2?: {
135
+ client_id: string;
136
+ scopes?: string[] | undefined;
137
+ } | undefined;
138
+ offline_enabled?: boolean | undefined;
139
+ omnibox?: {
140
+ keyword: string;
141
+ } | undefined;
142
+ optional_permissions?: chrome.runtime.ManifestPermissions[] | string[] | undefined;
143
+ options_page?: string | undefined;
144
+ options_ui?: {
145
+ page?: string | undefined;
146
+ chrome_style?: boolean | undefined;
147
+ open_in_tab?: boolean | undefined;
148
+ } | undefined;
149
+ permissions?: chrome.runtime.ManifestPermissions[] | string[] | undefined;
150
+ platforms?: {
151
+ nacl_arch?: string | undefined;
152
+ sub_package_path: string;
153
+ }[] | undefined;
154
+ plugins?: {
155
+ path: string;
156
+ }[] | undefined;
157
+ requirements?: {
158
+ '3D'?: {
159
+ features?: string[] | undefined;
160
+ } | undefined;
161
+ plugins?: {
162
+ npapi?: boolean | undefined;
163
+ } | undefined;
164
+ } | undefined;
165
+ sandbox?: {
166
+ pages: string[];
167
+ content_security_policy?: string | undefined;
168
+ } | undefined;
169
+ short_name?: string | undefined;
170
+ spellcheck?: {
171
+ dictionary_language?: string | undefined;
172
+ dictionary_locale?: string | undefined;
173
+ dictionary_format?: string | undefined;
174
+ dictionary_path?: string | undefined;
175
+ } | undefined;
176
+ storage?: {
177
+ managed_schema: string;
178
+ } | undefined;
179
+ tts_engine?: {
180
+ voices: {
181
+ voice_name: string;
182
+ lang?: string | undefined;
183
+ gender?: string | undefined;
184
+ event_types?: string[] | undefined;
185
+ }[];
186
+ } | undefined;
187
+ update_url?: string | undefined;
188
+ version_name?: string | undefined;
189
+ web_accessible_resources?: (WebAccessibleResourceById | WebAccessibleResourceByMatch)[] | undefined;
190
+ }
191
+
192
+ declare type ManifestV3Export = ManifestV3 | Promise<ManifestV3> | ManifestV3Fn;
193
+ declare type ManifestV3Fn = (env: ConfigEnv) => ManifestV3 | Promise<ManifestV3>;
194
+ declare const defineManifest: (manifest: ManifestV3Export) => ManifestV3Export;
195
+ /**
196
+ * Content script resources like CSS and image files must be declared in the
197
+ * manifest under `web_accessible_resources`. Manifest V3 uses a match pattern
198
+ * to narrow the origins that can access a Chrome CRX resource.
199
+ *
200
+ * Content script resources use the same match pattern as the content script for
201
+ * web accessible resources.
202
+ *
203
+ * You don't need to define a match pattern for dynamic content script
204
+ * resources, but if you want to do so, you can use the helper function
205
+ * `defineDynamicResource` to define your web accessible resources in a TypeScript file:
206
+ *
207
+ * ```typescript
208
+ * import { crx, defineManifest, defineDynamicResource }
209
+ * const manifest = defineManifest({
210
+ * "web_accessible_resources": [
211
+ * defineDynamicResource({
212
+ * matches: ["https://google.com/*", "file:///*.mp3", "..."]
213
+ * use_dynamic_url?: true
214
+ * })
215
+ * ]
216
+ * })
217
+ * ```
218
+ */
219
+ declare const defineDynamicResource: ({ matches, use_dynamic_url, }: Omit<WebAccessibleResourceByMatch, 'resources'>) => WebAccessibleResourceByMatch;
220
+
221
+ interface CrxPlugin extends Plugin {
222
+ /** Runs during dev mode when the file writer has started and server is listening. */
223
+ fileWriterStart?: (server: ViteDevServer) => Promise<void> | void;
224
+ /** Runs during the transform hook for the manifest. */
225
+ transformCrxManifest?: (this: PluginContext, manifest: ManifestV3) => Promise<ManifestV3 | null | undefined> | ManifestV3 | null | undefined;
226
+ /** Runs during generateBundle, before manifest output. */
227
+ renderCrxManifest?: (this: PluginContext, manifest: ManifestV3, bundle: OutputBundle) => Promise<ManifestV3 | null | undefined> | ManifestV3 | null | undefined;
228
+ }
229
+ interface CrxOptions {
230
+ contentScripts?: {
231
+ preambleCode?: string | false;
232
+ hmrTimeout?: number;
233
+ injectCss?: boolean;
234
+ };
235
+ fastGlobOptions?: Options;
236
+ }
237
+
238
+ declare const filesReady: () => Promise<{
239
+ type: 'writeBundle';
240
+ options: OutputOptions;
241
+ bundle: OutputBundle;
242
+ duration: number;
243
+ timestamp: number;
244
+ }>;
245
+ /** Trigger a rebuild from other plugins */
246
+ declare const rebuildFiles: () => Promise<void>;
247
+
248
+ declare const crx: ({ manifest, ...options }: {
249
+ manifest: ManifestV3Export;
250
+ } & CrxOptions) => PluginOption[];
251
+ declare const chromeExtension: ({ manifest, ...options }: {
252
+ manifest: ManifestV3Export;
253
+ } & CrxOptions) => PluginOption[];
254
+
255
+ export { CrxPlugin, ManifestV3Export, chromeExtension, crx, defineDynamicResource, defineManifest, filesReady, rebuildFiles };