wxt 0.19.25 → 0.19.27
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/builtin-modules/unimport.d.ts +0 -3
- package/dist/builtin-modules/unimport.mjs +2 -24
- package/dist/client/content-scripts/content-script-context.d.ts +2 -0
- package/dist/client/content-scripts/content-script-context.mjs +11 -2
- package/dist/core/generate-wxt-dir.mjs +1 -1
- package/dist/core/wxt.mjs +1 -1
- package/dist/testing/wxt-vitest-plugin.mjs +2 -5
- package/dist/version.mjs +1 -1
- package/package.json +3 -3
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { EslintGlobalsPropValue, WxtDirFileEntry, WxtModule, WxtResolvedUnimportOptions } from '../types';
|
|
2
|
-
import { type Unimport } from 'unimport';
|
|
3
|
-
import { Plugin } from 'vite';
|
|
4
2
|
declare const _default: WxtModule<import("../types").WxtModuleOptions>;
|
|
5
3
|
export default _default;
|
|
6
|
-
export declare function vitePlugin(unimport: Unimport): Plugin;
|
|
7
4
|
export declare function getEslint8ConfigEntry(options: WxtResolvedUnimportOptions, globals: Record<string, EslintGlobalsPropValue>): WxtDirFileEntry;
|
|
8
5
|
export declare function getEslint9ConfigEntry(options: WxtResolvedUnimportOptions, globals: Record<string, EslintGlobalsPropValue>): WxtDirFileEntry;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { addViteConfig, defineWxtModule } from "../modules.mjs";
|
|
2
2
|
import { createUnimport } from "unimport";
|
|
3
|
-
import
|
|
3
|
+
import UnimportPlugin from "unimport/unplugin";
|
|
4
4
|
export default defineWxtModule({
|
|
5
5
|
name: "wxt:built-in:unimport",
|
|
6
6
|
setup(wxt) {
|
|
@@ -30,32 +30,10 @@ export default defineWxtModule({
|
|
|
30
30
|
);
|
|
31
31
|
});
|
|
32
32
|
addViteConfig(wxt, () => ({
|
|
33
|
-
plugins: [
|
|
33
|
+
plugins: [UnimportPlugin.vite(options)]
|
|
34
34
|
}));
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
-
export function vitePlugin(unimport) {
|
|
38
|
-
const ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
39
|
-
".js",
|
|
40
|
-
".jsx",
|
|
41
|
-
".ts",
|
|
42
|
-
".tsx",
|
|
43
|
-
".vue",
|
|
44
|
-
".svelte"
|
|
45
|
-
]);
|
|
46
|
-
return {
|
|
47
|
-
name: "wxt:unimport",
|
|
48
|
-
async transform(code, id) {
|
|
49
|
-
if (id.includes("node_modules")) return;
|
|
50
|
-
if (!ENABLED_EXTENSIONS.has(extname(id))) return;
|
|
51
|
-
const injected = await unimport.injectImports(code, id);
|
|
52
|
-
return {
|
|
53
|
-
code: injected.code,
|
|
54
|
-
map: injected.s.generateMap({ hires: "boundary", source: id })
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
37
|
async function getImportsDeclarationEntry(unimport) {
|
|
60
38
|
await unimport.init();
|
|
61
39
|
return {
|
|
@@ -37,6 +37,7 @@ export declare class ContentScriptContext implements AbortController {
|
|
|
37
37
|
private isTopFrame;
|
|
38
38
|
private abortController;
|
|
39
39
|
private locationWatcher;
|
|
40
|
+
private receivedMessageIds;
|
|
40
41
|
constructor(contentScriptName: string, options?: Omit<ContentScriptDefinition, "main"> | undefined);
|
|
41
42
|
get signal(): AbortSignal;
|
|
42
43
|
abort(reason?: any): void;
|
|
@@ -112,6 +113,7 @@ export declare class ContentScriptContext implements AbortController {
|
|
|
112
113
|
*/
|
|
113
114
|
notifyInvalidated(): void;
|
|
114
115
|
stopOldScripts(): void;
|
|
116
|
+
verifyScriptStartedEvent(event: MessageEvent): boolean;
|
|
115
117
|
listenForNewerScripts(options?: {
|
|
116
118
|
ignoreFirstEvent?: boolean;
|
|
117
119
|
}): void;
|
|
@@ -20,6 +20,7 @@ export class ContentScriptContext {
|
|
|
20
20
|
isTopFrame = window.self === window.top;
|
|
21
21
|
abortController;
|
|
22
22
|
locationWatcher = createLocationWatcher(this);
|
|
23
|
+
receivedMessageIds = /* @__PURE__ */ new Set();
|
|
23
24
|
get signal() {
|
|
24
25
|
return this.abortController.signal;
|
|
25
26
|
}
|
|
@@ -136,15 +137,23 @@ export class ContentScriptContext {
|
|
|
136
137
|
window.postMessage(
|
|
137
138
|
{
|
|
138
139
|
type: ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE,
|
|
139
|
-
contentScriptName: this.contentScriptName
|
|
140
|
+
contentScriptName: this.contentScriptName,
|
|
141
|
+
messageId: Math.random().toString(36).slice(2)
|
|
140
142
|
},
|
|
141
143
|
"*"
|
|
142
144
|
);
|
|
143
145
|
}
|
|
146
|
+
verifyScriptStartedEvent(event) {
|
|
147
|
+
const isScriptStartedEvent = event.data?.type === ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE;
|
|
148
|
+
const isSameContentScript = event.data?.contentScriptName === this.contentScriptName;
|
|
149
|
+
const isNotDuplicate = !this.receivedMessageIds.has(event.data?.messageId);
|
|
150
|
+
return isScriptStartedEvent && isSameContentScript && isNotDuplicate;
|
|
151
|
+
}
|
|
144
152
|
listenForNewerScripts(options) {
|
|
145
153
|
let isFirst = true;
|
|
146
154
|
const cb = (event) => {
|
|
147
|
-
if (
|
|
155
|
+
if (this.verifyScriptStartedEvent(event)) {
|
|
156
|
+
this.receivedMessageIds.add(event.data.messageId);
|
|
148
157
|
const wasFirst = isFirst;
|
|
149
158
|
isFirst = false;
|
|
150
159
|
if (wasFirst && options?.ignoreFirstEvent) return;
|
|
@@ -162,7 +162,7 @@ function getMainDeclarationEntry(references) {
|
|
|
162
162
|
} else if (ref.tsReference) {
|
|
163
163
|
const absolutePath = resolve(wxt.config.wxtDir, ref.path);
|
|
164
164
|
const relativePath = relative(wxt.config.wxtDir, absolutePath);
|
|
165
|
-
lines.push(`/// <reference
|
|
165
|
+
lines.push(`/// <reference path="./${normalizePath(relativePath)}" />`);
|
|
166
166
|
}
|
|
167
167
|
});
|
|
168
168
|
return {
|
package/dist/core/wxt.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { builtinModules } from "../builtin-modules/index.mjs";
|
|
|
6
6
|
import { relative } from "path";
|
|
7
7
|
export let wxt;
|
|
8
8
|
export async function registerWxt(command, inlineConfig = {}) {
|
|
9
|
-
process.env.NODE_ENV ??= command === "serve" ? "development" : "production";
|
|
9
|
+
process.env.NODE_ENV ??= inlineConfig.mode ?? (command === "serve" ? "development" : "production");
|
|
10
10
|
const hooks = createHooks();
|
|
11
11
|
const config = await resolveConfig(inlineConfig, command);
|
|
12
12
|
const builder = await createViteBuilder(config, hooks, () => wxt.server);
|
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
extensionApiMock,
|
|
6
6
|
resolveAppConfig
|
|
7
7
|
} from "../core/builders/vite/plugins/index.mjs";
|
|
8
|
-
import
|
|
9
|
-
import { createUnimport } from "unimport";
|
|
8
|
+
import UnimportPlugin from "unimport/unplugin";
|
|
10
9
|
import { registerWxt, wxt } from "../core/wxt.mjs";
|
|
11
10
|
export async function WxtVitest(inlineConfig) {
|
|
12
11
|
await registerWxt("serve", inlineConfig ?? {});
|
|
@@ -18,9 +17,7 @@ export async function WxtVitest(inlineConfig) {
|
|
|
18
17
|
extensionApiMock(wxt.config)
|
|
19
18
|
];
|
|
20
19
|
if (wxt.config.imports !== false) {
|
|
21
|
-
|
|
22
|
-
await unimport.init();
|
|
23
|
-
plugins.push(unimportPlugin(unimport));
|
|
20
|
+
plugins.push(UnimportPlugin.vite(wxt.config.imports));
|
|
24
21
|
}
|
|
25
22
|
return plugins;
|
|
26
23
|
}
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.19.
|
|
1
|
+
export const version = "0.19.27";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.19.
|
|
4
|
+
"version": "0.19.27",
|
|
5
5
|
"description": "Next gen framework for developing web extensions",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -109,11 +109,11 @@
|
|
|
109
109
|
"perfect-debounce": "^1.0.0",
|
|
110
110
|
"picocolors": "^1.1.1",
|
|
111
111
|
"prompts": "^2.4.2",
|
|
112
|
-
"publish-browser-extension": "^2.
|
|
112
|
+
"publish-browser-extension": "^2.3.0 || ^3.0.0",
|
|
113
113
|
"scule": "^1.3.0",
|
|
114
114
|
"unimport": "^3.13.1",
|
|
115
115
|
"vite": "^5.0.0 || <=6.0.8",
|
|
116
|
-
"vite-node": "^2.1.4",
|
|
116
|
+
"vite-node": "^2.1.4 || ^3.0.0",
|
|
117
117
|
"web-ext-run": "^0.2.1",
|
|
118
118
|
"webextension-polyfill": "^0.12.0"
|
|
119
119
|
},
|