wxt 0.19.5 → 0.19.7
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/browser/chrome.d.ts +3 -0
- package/dist/core/builders/vite/index.mjs +4 -1
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +18 -0
- package/dist/core/create-server.mjs +1 -3
- package/dist/core/utils/building/find-entrypoints.mjs +1 -1
- package/dist/core/utils/building/generate-wxt-dir.mjs +33 -9
- package/dist/core/utils/building/resolve-config.mjs +0 -3
- package/dist/modules.d.ts +28 -0
- package/dist/modules.mjs +11 -0
- package/dist/testing/wxt-vitest-plugin.mjs +9 -9
- package/dist/version.mjs +1 -1
- package/package.json +1 -1
package/dist/browser/chrome.d.ts
CHANGED
|
@@ -227,7 +227,10 @@ export async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
227
227
|
port: info.port,
|
|
228
228
|
strictPort: true,
|
|
229
229
|
host: info.hostname,
|
|
230
|
-
origin: info.origin
|
|
230
|
+
origin: info.origin,
|
|
231
|
+
watch: {
|
|
232
|
+
ignored: [`${wxtConfig.outBaseDir}/**`, `${wxtConfig.wxtDir}/**`]
|
|
233
|
+
}
|
|
231
234
|
}
|
|
232
235
|
};
|
|
233
236
|
const baseConfig = await getBaseConfig();
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
export function extensionApiMock(config) {
|
|
3
|
+
const virtualSetupModule = "virtual:wxt-setup";
|
|
4
|
+
const resolvedVirtualSetupModule = "\0" + virtualSetupModule;
|
|
3
5
|
return {
|
|
4
6
|
name: "wxt:extension-api-mock",
|
|
5
7
|
config() {
|
|
@@ -8,6 +10,9 @@ export function extensionApiMock(config) {
|
|
|
8
10
|
"dist/virtual/mock-browser"
|
|
9
11
|
);
|
|
10
12
|
return {
|
|
13
|
+
test: {
|
|
14
|
+
setupFiles: [virtualSetupModule]
|
|
15
|
+
},
|
|
11
16
|
resolve: {
|
|
12
17
|
alias: [
|
|
13
18
|
{ find: "webextension-polyfill", replacement },
|
|
@@ -21,6 +26,19 @@ export function extensionApiMock(config) {
|
|
|
21
26
|
noExternal: ["wxt"]
|
|
22
27
|
}
|
|
23
28
|
};
|
|
29
|
+
},
|
|
30
|
+
resolveId(id) {
|
|
31
|
+
if (id.endsWith(virtualSetupModule)) return resolvedVirtualSetupModule;
|
|
32
|
+
},
|
|
33
|
+
load(id) {
|
|
34
|
+
if (id === resolvedVirtualSetupModule) return setupTemplate;
|
|
24
35
|
}
|
|
25
36
|
};
|
|
26
37
|
}
|
|
38
|
+
const setupTemplate = `
|
|
39
|
+
import { vi } from 'vitest';
|
|
40
|
+
import { fakeBrowser } from 'wxt/testing';
|
|
41
|
+
|
|
42
|
+
vi.stubGlobal("chrome", fakeBrowser);
|
|
43
|
+
vi.stubGlobal("browser", fakeBrowser);
|
|
44
|
+
`;
|
|
@@ -99,14 +99,12 @@ function createFileReloader(server) {
|
|
|
99
99
|
const fileChangedMutex = new Mutex();
|
|
100
100
|
const changeQueue = [];
|
|
101
101
|
return async (event, path) => {
|
|
102
|
-
await wxt.reloadConfig();
|
|
103
|
-
if (path.startsWith(wxt.config.outBaseDir)) return;
|
|
104
|
-
if (path.startsWith(wxt.config.wxtDir)) return;
|
|
105
102
|
changeQueue.push([event, path]);
|
|
106
103
|
await fileChangedMutex.runExclusive(async () => {
|
|
107
104
|
if (server.currentOutput == null) return;
|
|
108
105
|
const fileChanges = changeQueue.splice(0, changeQueue.length).map(([_, file]) => file);
|
|
109
106
|
if (fileChanges.length === 0) return;
|
|
107
|
+
await wxt.reloadConfig();
|
|
110
108
|
const changes = detectDevChanges(fileChanges, server.currentOutput);
|
|
111
109
|
if (changes.type === "no-change") return;
|
|
112
110
|
if (changes.type === "full-restart") {
|
|
@@ -313,7 +313,7 @@ async function getSidepanelEntrypoint(info) {
|
|
|
313
313
|
const options = await getHtmlEntrypointOptions(
|
|
314
314
|
info,
|
|
315
315
|
{
|
|
316
|
-
browserStyle: "
|
|
316
|
+
browserStyle: "browser_style",
|
|
317
317
|
exclude: "exclude",
|
|
318
318
|
include: "include",
|
|
319
319
|
defaultIcon: "default_icon",
|
|
@@ -102,18 +102,38 @@ declare module "wxt/browser" {
|
|
|
102
102
|
} else {
|
|
103
103
|
messages = parseI18nMessages({});
|
|
104
104
|
}
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
const renderGetMessageOverload = (keyType, description, translation) => {
|
|
106
|
+
const commentLines = [];
|
|
107
|
+
if (description) commentLines.push(...description.split("\n"));
|
|
108
|
+
if (translation) {
|
|
109
|
+
if (commentLines.length > 0) commentLines.push("");
|
|
110
|
+
commentLines.push(`"${translation}"`);
|
|
111
|
+
}
|
|
112
|
+
const comment = commentLines.length > 0 ? `/**
|
|
113
|
+
${commentLines.map((line) => ` * ${line}`.trimEnd()).join("\n")}
|
|
110
114
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
` : "";
|
|
116
|
+
return ` ${comment}getMessage(
|
|
117
|
+
messageName: ${keyType},
|
|
113
118
|
substitutions?: string | string[],
|
|
114
119
|
options?: GetMessageOptions,
|
|
115
120
|
): string;`;
|
|
116
|
-
}
|
|
121
|
+
};
|
|
122
|
+
const overrides = [
|
|
123
|
+
// Generate individual overloads for each message so JSDoc contains description and base translation.
|
|
124
|
+
...messages.map(
|
|
125
|
+
(message) => renderGetMessageOverload(
|
|
126
|
+
`"${message.name}"`,
|
|
127
|
+
message.description,
|
|
128
|
+
message.message
|
|
129
|
+
)
|
|
130
|
+
),
|
|
131
|
+
// Include a final union-based override so TS accepts valid string templates or concatinations
|
|
132
|
+
// ie: browser.i18n.getMessage(`some_enum_${enumValue}`)
|
|
133
|
+
renderGetMessageOverload(
|
|
134
|
+
messages.map((message) => `"${message.name}"`).join(" | ")
|
|
135
|
+
)
|
|
136
|
+
];
|
|
117
137
|
return {
|
|
118
138
|
path: "types/i18n.d.ts",
|
|
119
139
|
text: template.replace("{{ overrides }}", overrides.join("\n")),
|
|
@@ -156,7 +176,11 @@ function getMainDeclarationEntry(references) {
|
|
|
156
176
|
}
|
|
157
177
|
async function getTsConfigEntry() {
|
|
158
178
|
const dir = wxt.config.wxtDir;
|
|
159
|
-
const getTsconfigPath = (path2) =>
|
|
179
|
+
const getTsconfigPath = (path2) => {
|
|
180
|
+
const res = normalizePath(relative(dir, path2));
|
|
181
|
+
if (res.startsWith(".") || res.startsWith("/")) return res;
|
|
182
|
+
return "./" + res;
|
|
183
|
+
};
|
|
160
184
|
const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
|
|
161
185
|
const aliasPath = getTsconfigPath(absolutePath);
|
|
162
186
|
return [
|
|
@@ -48,9 +48,6 @@ export async function resolveConfig(inlineConfig, command) {
|
|
|
48
48
|
}
|
|
49
49
|
const filterEntrypoints = !!mergedConfig.filterEntrypoints?.length ? new Set(mergedConfig.filterEntrypoints) : void 0;
|
|
50
50
|
const publicDir = path.resolve(srcDir, mergedConfig.publicDir ?? "public");
|
|
51
|
-
if (await isDirMissing(publicDir)) {
|
|
52
|
-
logMissingDir(logger, "Public", publicDir);
|
|
53
|
-
}
|
|
54
51
|
const typesDir = path.resolve(wxtDir, "types");
|
|
55
52
|
const outBaseDir = path.resolve(root, mergedConfig.outDir ?? ".output");
|
|
56
53
|
const outDir = path.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
|
package/dist/modules.d.ts
CHANGED
|
@@ -107,3 +107,31 @@ export declare function addWxtPlugin(wxt: Wxt, plugin: string): void;
|
|
|
107
107
|
* });
|
|
108
108
|
*/
|
|
109
109
|
export declare function addImportPreset(wxt: Wxt, preset: UnimportOptions['presets'][0]): void;
|
|
110
|
+
/**
|
|
111
|
+
* Adds an import alias to the project's TSConfig paths and bundler. Path can
|
|
112
|
+
* be absolute or relative to the project's root directory.
|
|
113
|
+
*
|
|
114
|
+
* Usually, this is used to provide access to some code generated by your
|
|
115
|
+
* module. In the example below, a `i18n` plugin generates a variable that it
|
|
116
|
+
* wants to provide access to, so it creates the file and adds an import alias
|
|
117
|
+
* to it.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* import path from 'node:path';
|
|
121
|
+
*
|
|
122
|
+
* export default defineWxtModule((wxt) => {
|
|
123
|
+
* const i18nPath = path.resolve(wxt.config.wxtDir, "i18n.ts");
|
|
124
|
+
*
|
|
125
|
+
* // Generate the file
|
|
126
|
+
* wxt.hooks.hook("prepare:types", (_, entries) => {
|
|
127
|
+
* entries.push({
|
|
128
|
+
* path: i18nPath,
|
|
129
|
+
* text: `export const i18n = ...`,
|
|
130
|
+
* });
|
|
131
|
+
* });
|
|
132
|
+
*
|
|
133
|
+
* // Add alias
|
|
134
|
+
* addAlias(wxt, "#i18n", i18nPath);
|
|
135
|
+
* });
|
|
136
|
+
*/
|
|
137
|
+
export declare function addAlias(wxt: Wxt, alias: string, path: string): void;
|
package/dist/modules.mjs
CHANGED
|
@@ -46,3 +46,14 @@ export function addImportPreset(wxt, preset) {
|
|
|
46
46
|
wxt2.config.imports.presets.push(preset);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
+
export function addAlias(wxt, alias, path) {
|
|
50
|
+
wxt.hooks.hook("ready", (wxt2) => {
|
|
51
|
+
const target = resolve(wxt2.config.root, path);
|
|
52
|
+
if (wxt2.config.alias[alias] != null) {
|
|
53
|
+
wxt2.logger.warn(
|
|
54
|
+
`Skipped adding alias (${alias} => ${target}) because an alias with the same name already exists: ${alias} => ${wxt2.config.alias[alias]}`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
wxt2.config.alias[alias] = target;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -5,20 +5,20 @@ import {
|
|
|
5
5
|
extensionApiMock,
|
|
6
6
|
resolveAppConfig
|
|
7
7
|
} from "../core/builders/vite/plugins/index.mjs";
|
|
8
|
-
import { resolveConfig } from "../core/utils/building/index.mjs";
|
|
9
8
|
import { vitePlugin as unimportPlugin } from "../builtin-modules/unimport.mjs";
|
|
10
9
|
import { createUnimport } from "unimport";
|
|
10
|
+
import { registerWxt, wxt } from "../core/wxt.mjs";
|
|
11
11
|
export async function WxtVitest(inlineConfig) {
|
|
12
|
-
|
|
12
|
+
await registerWxt("serve", inlineConfig ?? {});
|
|
13
13
|
const plugins = [
|
|
14
|
-
globals(config),
|
|
15
|
-
download(config),
|
|
16
|
-
tsconfigPaths(config),
|
|
17
|
-
resolveAppConfig(config),
|
|
18
|
-
extensionApiMock(config)
|
|
14
|
+
globals(wxt.config),
|
|
15
|
+
download(wxt.config),
|
|
16
|
+
tsconfigPaths(wxt.config),
|
|
17
|
+
resolveAppConfig(wxt.config),
|
|
18
|
+
extensionApiMock(wxt.config)
|
|
19
19
|
];
|
|
20
|
-
if (config.imports !== false) {
|
|
21
|
-
const unimport = createUnimport(config.imports);
|
|
20
|
+
if (wxt.config.imports !== false) {
|
|
21
|
+
const unimport = createUnimport(wxt.config.imports);
|
|
22
22
|
await unimport.init();
|
|
23
23
|
plugins.push(unimportPlugin(unimport));
|
|
24
24
|
}
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.19.
|
|
1
|
+
export const version = "0.19.7";
|