wxt 0.5.4 → 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 +24 -4
- package/dist/client.d.ts +53 -1
- package/dist/index.cjs +23 -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 +23 -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) {
|
|
@@ -804,8 +813,15 @@ async function buildSingleEntrypoint(entrypoint, config) {
|
|
|
804
813
|
assetFileNames: `assets/${entrypoint.name}.[ext]`
|
|
805
814
|
}
|
|
806
815
|
}
|
|
816
|
+
},
|
|
817
|
+
define: {
|
|
818
|
+
// See https://github.com/aklinker1/vite-plugin-web-extension/issues/96
|
|
819
|
+
"process.env.NODE_ENV": JSON.stringify(config.mode)
|
|
807
820
|
}
|
|
808
821
|
};
|
|
822
|
+
for (const global of getEntrypointGlobals(config, entrypoint.name)) {
|
|
823
|
+
libMode.define[global.name] = JSON.stringify(global.value);
|
|
824
|
+
}
|
|
809
825
|
const entryConfig = vite3.mergeConfig(
|
|
810
826
|
libMode,
|
|
811
827
|
config.vite
|
|
@@ -834,8 +850,12 @@ async function buildMultipleEntrypoints(entrypoints, config) {
|
|
|
834
850
|
assetFileNames: "assets/[name]-[hash].[ext]"
|
|
835
851
|
}
|
|
836
852
|
}
|
|
837
|
-
}
|
|
853
|
+
},
|
|
854
|
+
define: {}
|
|
838
855
|
};
|
|
856
|
+
for (const global of getEntrypointGlobals(config, "html")) {
|
|
857
|
+
multiPage.define[global.name] = JSON.stringify(global.value);
|
|
858
|
+
}
|
|
839
859
|
const entryConfig = vite3.mergeConfig(
|
|
840
860
|
multiPage,
|
|
841
861
|
config.vite
|
|
@@ -1358,7 +1378,7 @@ declare module "wxt/browser" {
|
|
|
1358
1378
|
}
|
|
1359
1379
|
async function writeGlobalsDeclarationFile(config) {
|
|
1360
1380
|
const filePath = resolve9(config.typesDir, "globals.d.ts");
|
|
1361
|
-
const globals = getGlobals(config);
|
|
1381
|
+
const globals = [...getGlobals(config), ...getEntrypointGlobals(config, "")];
|
|
1362
1382
|
await writeFileIfDifferent(
|
|
1363
1383
|
filePath,
|
|
1364
1384
|
[
|
|
@@ -2242,7 +2262,7 @@ async function clean(root = process.cwd()) {
|
|
|
2242
2262
|
}
|
|
2243
2263
|
|
|
2244
2264
|
// package.json
|
|
2245
|
-
var version2 = "0.5.
|
|
2265
|
+
var version2 = "0.5.6";
|
|
2246
2266
|
|
|
2247
2267
|
// src/core/utils/defineConfig.ts
|
|
2248
2268
|
function defineConfig(config) {
|