wxt 0.19.6 → 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/plugins/extensionApiMock.mjs +18 -0
- package/dist/core/utils/building/generate-wxt-dir.mjs +5 -1
- 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
|
@@ -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
|
+
`;
|
|
@@ -176,7 +176,11 @@ function getMainDeclarationEntry(references) {
|
|
|
176
176
|
}
|
|
177
177
|
async function getTsConfigEntry() {
|
|
178
178
|
const dir = wxt.config.wxtDir;
|
|
179
|
-
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
|
+
};
|
|
180
184
|
const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
|
|
181
185
|
const aliasPath = getTsconfigPath(absolutePath);
|
|
182
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";
|