wxt 0.5.5 → 0.5.6
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/dist/cli.cjs +20 -4
- package/dist/client.d.ts +53 -1
- package/dist/index.cjs +19 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +54 -2
- package/dist/index.d.ts +54 -2
- package/dist/index.js +19 -3
- package/dist/index.js.map +1 -1
- package/dist/virtual-modules/content-script-entrypoint.js +118 -1
- package/dist/virtual-modules/content-script-entrypoint.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3,6 +3,58 @@ import { Manifest, Scripting } from 'webextension-polyfill';
|
|
|
3
3
|
import { UnimportOptions } from 'unimport';
|
|
4
4
|
import { LogLevel } from 'consola';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Extends [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
|
|
8
|
+
* Used to detect and stop content script code when the script is invalidated.
|
|
9
|
+
*
|
|
10
|
+
* It also provides several utilities like `ctx.setTimeout` and `ctx.setInterval` that should be used in
|
|
11
|
+
* content scripts instead of `window.setTimeout` or `window.setInterval`.
|
|
12
|
+
*/
|
|
13
|
+
declare class ContentScriptContext extends AbortController {
|
|
14
|
+
#private;
|
|
15
|
+
private readonly contentScriptName;
|
|
16
|
+
static SCRIPT_STARTED_MESSAGE_TYPE: string;
|
|
17
|
+
constructor(contentScriptName: string);
|
|
18
|
+
get isInvalid(): boolean;
|
|
19
|
+
get isValid(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Add a listener that is called when the content script's context is invalidated.
|
|
22
|
+
*
|
|
23
|
+
* @returns A function to remove the listener.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* browser.runtime.onMessage.addListener(cb);
|
|
27
|
+
* const removeInvalidatedListener = ctx.onInvalidated(() => {
|
|
28
|
+
* browser.runtime.onMessage.removeListener(cb);
|
|
29
|
+
* })
|
|
30
|
+
* // ...
|
|
31
|
+
* removeInvalidatedListener();
|
|
32
|
+
*/
|
|
33
|
+
onInvalidated(cb: () => void): () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Wrapper around `window.setInterval` that automatically clears the interval when invalidated.
|
|
36
|
+
*/
|
|
37
|
+
setInterval(handler: () => void, timeout?: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Wrapper around `window.setTimeout` that automatically clears the interval when invalidated.
|
|
40
|
+
*/
|
|
41
|
+
setTimeout(handler: () => void, timeout?: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Wrapper around `window.requestAnimationFrame` that automatically cancels the request when
|
|
44
|
+
* invalidated.
|
|
45
|
+
*/
|
|
46
|
+
requestAnimationFrame(callback: FrameRequestCallback): number;
|
|
47
|
+
/**
|
|
48
|
+
* Wrapper around `window.requestIdleCallback` that automatically cancels the request when
|
|
49
|
+
* invalidated.
|
|
50
|
+
*/
|
|
51
|
+
requestIdleCallback(callback: IdleRequestCallback, options?: IdleRequestOptions): number;
|
|
52
|
+
/**
|
|
53
|
+
* Abort the abort controller and execute all `onInvalidated` listeners.
|
|
54
|
+
*/
|
|
55
|
+
notifyInvalidated(): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
6
58
|
interface InlineConfig {
|
|
7
59
|
/**
|
|
8
60
|
* Your project's root directory containing the `package.json` used to fill out the
|
|
@@ -331,7 +383,7 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
|
|
|
331
383
|
/**
|
|
332
384
|
* Main function executed when the content script is loaded.
|
|
333
385
|
*/
|
|
334
|
-
main(): void | Promise<void>;
|
|
386
|
+
main(ctx: ContentScriptContext): void | Promise<void>;
|
|
335
387
|
}
|
|
336
388
|
interface BackgroundScriptDefintition extends ExcludableEntrypoint {
|
|
337
389
|
type?: 'module';
|
|
@@ -426,7 +478,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
|
|
|
426
478
|
*/
|
|
427
479
|
declare function clean(root?: string): Promise<void>;
|
|
428
480
|
|
|
429
|
-
var version = "0.5.
|
|
481
|
+
var version = "0.5.6";
|
|
430
482
|
|
|
431
483
|
declare function defineConfig(config: UserConfig): UserConfig;
|
|
432
484
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,58 @@ import { Manifest, Scripting } from 'webextension-polyfill';
|
|
|
3
3
|
import { UnimportOptions } from 'unimport';
|
|
4
4
|
import { LogLevel } from 'consola';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Extends [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
|
|
8
|
+
* Used to detect and stop content script code when the script is invalidated.
|
|
9
|
+
*
|
|
10
|
+
* It also provides several utilities like `ctx.setTimeout` and `ctx.setInterval` that should be used in
|
|
11
|
+
* content scripts instead of `window.setTimeout` or `window.setInterval`.
|
|
12
|
+
*/
|
|
13
|
+
declare class ContentScriptContext extends AbortController {
|
|
14
|
+
#private;
|
|
15
|
+
private readonly contentScriptName;
|
|
16
|
+
static SCRIPT_STARTED_MESSAGE_TYPE: string;
|
|
17
|
+
constructor(contentScriptName: string);
|
|
18
|
+
get isInvalid(): boolean;
|
|
19
|
+
get isValid(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Add a listener that is called when the content script's context is invalidated.
|
|
22
|
+
*
|
|
23
|
+
* @returns A function to remove the listener.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* browser.runtime.onMessage.addListener(cb);
|
|
27
|
+
* const removeInvalidatedListener = ctx.onInvalidated(() => {
|
|
28
|
+
* browser.runtime.onMessage.removeListener(cb);
|
|
29
|
+
* })
|
|
30
|
+
* // ...
|
|
31
|
+
* removeInvalidatedListener();
|
|
32
|
+
*/
|
|
33
|
+
onInvalidated(cb: () => void): () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Wrapper around `window.setInterval` that automatically clears the interval when invalidated.
|
|
36
|
+
*/
|
|
37
|
+
setInterval(handler: () => void, timeout?: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Wrapper around `window.setTimeout` that automatically clears the interval when invalidated.
|
|
40
|
+
*/
|
|
41
|
+
setTimeout(handler: () => void, timeout?: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Wrapper around `window.requestAnimationFrame` that automatically cancels the request when
|
|
44
|
+
* invalidated.
|
|
45
|
+
*/
|
|
46
|
+
requestAnimationFrame(callback: FrameRequestCallback): number;
|
|
47
|
+
/**
|
|
48
|
+
* Wrapper around `window.requestIdleCallback` that automatically cancels the request when
|
|
49
|
+
* invalidated.
|
|
50
|
+
*/
|
|
51
|
+
requestIdleCallback(callback: IdleRequestCallback, options?: IdleRequestOptions): number;
|
|
52
|
+
/**
|
|
53
|
+
* Abort the abort controller and execute all `onInvalidated` listeners.
|
|
54
|
+
*/
|
|
55
|
+
notifyInvalidated(): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
6
58
|
interface InlineConfig {
|
|
7
59
|
/**
|
|
8
60
|
* Your project's root directory containing the `package.json` used to fill out the
|
|
@@ -331,7 +383,7 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
|
|
|
331
383
|
/**
|
|
332
384
|
* Main function executed when the content script is loaded.
|
|
333
385
|
*/
|
|
334
|
-
main(): void | Promise<void>;
|
|
386
|
+
main(ctx: ContentScriptContext): void | Promise<void>;
|
|
335
387
|
}
|
|
336
388
|
interface BackgroundScriptDefintition extends ExcludableEntrypoint {
|
|
337
389
|
type?: 'module';
|
|
@@ -426,7 +478,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
|
|
|
426
478
|
*/
|
|
427
479
|
declare function clean(root?: string): Promise<void>;
|
|
428
480
|
|
|
429
|
-
var version = "0.5.
|
|
481
|
+
var version = "0.5.6";
|
|
430
482
|
|
|
431
483
|
declare function defineConfig(config: UserConfig): UserConfig;
|
|
432
484
|
|
package/dist/index.js
CHANGED
|
@@ -451,6 +451,15 @@ function getGlobals(config) {
|
|
|
451
451
|
}
|
|
452
452
|
];
|
|
453
453
|
}
|
|
454
|
+
function getEntrypointGlobals(config, entrypointName) {
|
|
455
|
+
return [
|
|
456
|
+
{
|
|
457
|
+
name: "__ENTRYPOINT__",
|
|
458
|
+
value: entrypointName,
|
|
459
|
+
type: `string`
|
|
460
|
+
}
|
|
461
|
+
];
|
|
462
|
+
}
|
|
454
463
|
|
|
455
464
|
// src/core/utils/getInternalConfig.ts
|
|
456
465
|
async function getInternalConfig(inlineConfig, command) {
|
|
@@ -810,6 +819,9 @@ async function buildSingleEntrypoint(entrypoint, config) {
|
|
|
810
819
|
"process.env.NODE_ENV": JSON.stringify(config.mode)
|
|
811
820
|
}
|
|
812
821
|
};
|
|
822
|
+
for (const global of getEntrypointGlobals(config, entrypoint.name)) {
|
|
823
|
+
libMode.define[global.name] = JSON.stringify(global.value);
|
|
824
|
+
}
|
|
813
825
|
const entryConfig = vite3.mergeConfig(
|
|
814
826
|
libMode,
|
|
815
827
|
config.vite
|
|
@@ -838,8 +850,12 @@ async function buildMultipleEntrypoints(entrypoints, config) {
|
|
|
838
850
|
assetFileNames: "assets/[name]-[hash].[ext]"
|
|
839
851
|
}
|
|
840
852
|
}
|
|
841
|
-
}
|
|
853
|
+
},
|
|
854
|
+
define: {}
|
|
842
855
|
};
|
|
856
|
+
for (const global of getEntrypointGlobals(config, "html")) {
|
|
857
|
+
multiPage.define[global.name] = JSON.stringify(global.value);
|
|
858
|
+
}
|
|
843
859
|
const entryConfig = vite3.mergeConfig(
|
|
844
860
|
multiPage,
|
|
845
861
|
config.vite
|
|
@@ -1362,7 +1378,7 @@ declare module "wxt/browser" {
|
|
|
1362
1378
|
}
|
|
1363
1379
|
async function writeGlobalsDeclarationFile(config) {
|
|
1364
1380
|
const filePath = resolve9(config.typesDir, "globals.d.ts");
|
|
1365
|
-
const globals = getGlobals(config);
|
|
1381
|
+
const globals = [...getGlobals(config), ...getEntrypointGlobals(config, "")];
|
|
1366
1382
|
await writeFileIfDifferent(
|
|
1367
1383
|
filePath,
|
|
1368
1384
|
[
|
|
@@ -2246,7 +2262,7 @@ async function clean(root = process.cwd()) {
|
|
|
2246
2262
|
}
|
|
2247
2263
|
|
|
2248
2264
|
// package.json
|
|
2249
|
-
var version2 = "0.5.
|
|
2265
|
+
var version2 = "0.5.6";
|
|
2250
2266
|
|
|
2251
2267
|
// src/core/utils/defineConfig.ts
|
|
2252
2268
|
function defineConfig(config) {
|