wxt 0.20.13 → 0.20.14
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.d.mts +20 -0
- package/dist/browser.mjs +18 -3
- package/dist/builtin-modules/index.mjs +7 -2
- package/dist/builtin-modules/unimport.mjs +69 -75
- package/dist/cli/cli-utils.mjs +52 -50
- package/dist/cli/commands.mjs +77 -103
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +9 -4
- package/dist/core/{build.d.ts → build.d.mts} +6 -2
- package/dist/core/build.mjs +23 -4
- package/dist/core/builders/vite/index.mjs +292 -343
- package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +11 -12
- package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +27 -20
- package/dist/core/builders/vite/plugins/defineImportMeta.mjs +17 -12
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +104 -136
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +15 -14
- package/dist/core/builders/vite/plugins/download.mjs +23 -12
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +18 -14
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +31 -33
- package/dist/core/builders/vite/plugins/globals.mjs +14 -13
- package/dist/core/builders/vite/plugins/iifeFooter.mjs +17 -11
- package/dist/core/builders/vite/plugins/index.mjs +18 -16
- package/dist/core/builders/vite/plugins/noopBackground.mjs +21 -15
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +25 -23
- package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +25 -23
- package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +27 -26
- package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +11 -11
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +41 -47
- package/dist/core/{clean.d.ts → clean.d.mts} +7 -3
- package/dist/core/clean.mjs +38 -35
- package/dist/core/{create-server.d.ts → create-server.d.mts} +6 -2
- package/dist/core/create-server.mjs +236 -247
- package/dist/core/define-config.d.mts +6 -0
- package/dist/core/define-config.mjs +6 -2
- package/dist/core/define-web-ext-config.d.mts +13 -0
- package/dist/core/define-web-ext-config.mjs +16 -7
- package/dist/core/generate-wxt-dir.mjs +109 -148
- package/dist/core/index.d.mts +8 -0
- package/dist/core/index.mjs +10 -8
- package/dist/core/initialize.d.mts +8 -0
- package/dist/core/initialize.mjs +110 -124
- package/dist/core/keyboard-shortcuts.mjs +30 -28
- package/dist/core/package-managers/bun.mjs +18 -16
- package/dist/core/package-managers/deno.mjs +12 -8
- package/dist/core/package-managers/index.mjs +52 -60
- package/dist/core/package-managers/npm.mjs +51 -52
- package/dist/core/package-managers/pnpm.mjs +21 -18
- package/dist/core/package-managers/yarn.mjs +31 -28
- package/dist/core/prepare.d.mts +6 -0
- package/dist/core/prepare.mjs +12 -7
- package/dist/core/resolve-config.mjs +393 -462
- package/dist/core/runners/index.mjs +11 -6
- package/dist/core/runners/manual.mjs +16 -14
- package/dist/core/runners/safari.mjs +16 -14
- package/dist/core/runners/web-ext.mjs +62 -83
- package/dist/core/runners/wsl.mjs +16 -14
- package/dist/core/utils/arrays.mjs +23 -12
- package/dist/core/utils/building/build-entrypoints.mjs +44 -40
- package/dist/core/utils/building/detect-dev-changes.mjs +84 -105
- package/dist/core/utils/building/find-entrypoints.mjs +275 -359
- package/dist/core/utils/building/group-entrypoints.mjs +42 -35
- package/dist/core/utils/building/index.mjs +8 -6
- package/dist/core/utils/building/internal-build.mjs +87 -102
- package/dist/core/utils/building/rebuild.mjs +50 -30
- package/dist/core/utils/cache.mjs +29 -18
- package/dist/core/utils/constants.mjs +9 -1
- package/dist/core/utils/content-scripts.mjs +56 -54
- package/dist/core/utils/content-security-policy.mjs +36 -39
- package/dist/core/utils/entrypoints.mjs +51 -28
- package/dist/core/utils/env.mjs +22 -17
- package/dist/core/utils/environments/browser-environment.mjs +13 -12
- package/dist/core/utils/environments/environment.mjs +36 -33
- package/dist/core/utils/environments/extension-environment.mjs +15 -10
- package/dist/core/utils/environments/index.mjs +4 -2
- package/dist/core/utils/eslint.mjs +11 -10
- package/dist/core/utils/fs.mjs +23 -11
- package/dist/core/utils/globals.mjs +53 -51
- package/dist/core/utils/i18n.mjs +41 -32
- package/dist/core/utils/log/index.mjs +6 -4
- package/dist/core/utils/log/printBuildSummary.mjs +20 -25
- package/dist/core/utils/log/printFileList.mjs +30 -33
- package/dist/core/utils/log/printHeader.mjs +10 -5
- package/dist/core/utils/log/printTable.mjs +19 -21
- package/dist/core/utils/manifest.mjs +364 -479
- package/dist/core/utils/minimatch-multiple.mjs +26 -15
- package/dist/core/utils/network.mjs +30 -33
- package/dist/core/utils/number.mjs +7 -3
- package/dist/core/utils/package.mjs +20 -13
- package/dist/core/utils/paths.mjs +26 -7
- package/dist/core/utils/strings.mjs +19 -14
- package/dist/core/utils/syntax-errors.mjs +14 -16
- package/dist/core/utils/time.mjs +19 -15
- package/dist/core/utils/transform.mjs +129 -160
- package/dist/core/utils/types.d.mts +6 -0
- package/dist/core/utils/validation.mjs +43 -50
- package/dist/core/utils/virtual-modules.mjs +20 -12
- package/dist/core/utils/wsl.mjs +10 -3
- package/dist/core/wxt.mjs +66 -60
- package/dist/core/{zip.d.ts → zip.d.mts} +6 -2
- package/dist/core/zip.mjs +116 -140
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +12 -3
- package/dist/{modules.d.ts → modules.d.mts} +14 -16
- package/dist/modules.mjs +181 -51
- package/dist/testing/fake-browser.d.mts +2 -0
- package/dist/testing/fake-browser.mjs +3 -1
- package/dist/testing/index.d.mts +3 -0
- package/dist/testing/index.mjs +4 -2
- package/dist/testing/{wxt-vitest-plugin.d.ts → wxt-vitest-plugin.d.mts} +7 -9
- package/dist/testing/wxt-vitest-plugin.mjs +38 -19
- package/dist/types.d.mts +1453 -0
- package/dist/utils/app-config.d.mts +6 -0
- package/dist/utils/app-config.mjs +8 -2
- package/dist/utils/content-script-context.d.mts +137 -0
- package/dist/utils/content-script-context.mjs +192 -175
- package/dist/utils/content-script-ui/iframe.d.mts +42 -0
- package/dist/utils/content-script-ui/iframe.mjs +42 -27
- package/dist/utils/content-script-ui/integrated.d.mts +37 -0
- package/dist/utils/content-script-ui/integrated.mjs +36 -29
- package/dist/utils/content-script-ui/shadow-root.d.mts +80 -0
- package/dist/utils/content-script-ui/shadow-root.mjs +75 -82
- package/dist/utils/content-script-ui/shared.mjs +117 -150
- package/dist/utils/content-script-ui/types.d.mts +107 -0
- package/dist/utils/content-script-ui/types.mjs +1 -0
- package/dist/utils/{define-app-config.d.ts → define-app-config.d.mts} +5 -3
- package/dist/utils/define-app-config.mjs +22 -2
- package/dist/utils/define-background.d.mts +7 -0
- package/dist/utils/define-background.mjs +7 -3
- package/dist/utils/define-content-script.d.mts +6 -0
- package/dist/utils/define-content-script.mjs +6 -2
- package/dist/utils/define-unlisted-script.d.mts +7 -0
- package/dist/utils/define-unlisted-script.mjs +7 -3
- package/dist/utils/define-wxt-plugin.d.mts +6 -0
- package/dist/utils/define-wxt-plugin.mjs +6 -2
- package/dist/utils/inject-script.d.mts +41 -0
- package/dist/utils/inject-script.mjs +44 -34
- package/dist/utils/internal/custom-events.d.mts +9 -0
- package/dist/utils/internal/custom-events.mjs +18 -10
- package/dist/utils/internal/location-watcher.mjs +23 -20
- package/dist/utils/internal/logger.mjs +15 -12
- package/dist/utils/match-patterns.d.mts +1 -0
- package/dist/utils/match-patterns.mjs +3 -1
- package/dist/utils/{split-shadow-root-css.d.ts → split-shadow-root-css.d.mts} +6 -3
- package/dist/utils/split-shadow-root-css.mjs +16 -7
- package/dist/utils/storage.d.mts +1 -0
- package/dist/utils/storage.mjs +3 -1
- package/dist/version.d.mts +4 -0
- package/dist/version.mjs +5 -1
- package/dist/virtual/background-entrypoint.d.mts +4 -0
- package/dist/virtual/background-entrypoint.mjs +146 -161
- package/dist/virtual/content-script-isolated-world-entrypoint.d.mts +4 -0
- package/dist/virtual/content-script-isolated-world-entrypoint.mjs +26 -27
- package/dist/virtual/content-script-main-world-entrypoint.d.mts +4 -0
- package/dist/virtual/content-script-main-world-entrypoint.mjs +24 -24
- package/dist/virtual/mock-browser.d.mts +6 -0
- package/dist/virtual/mock-browser.mjs +5 -3
- package/dist/virtual/reload-html.d.mts +1 -0
- package/dist/virtual/reload-html.mjs +60 -53
- package/dist/virtual/unlisted-script-entrypoint.d.mts +4 -0
- package/dist/virtual/unlisted-script-entrypoint.mjs +35 -43
- package/package.json +47 -49
- package/dist/browser.d.ts +0 -30
- package/dist/builtin-modules/index.d.ts +0 -2
- package/dist/builtin-modules/unimport.d.ts +0 -5
- package/dist/cli/cli-utils.d.ts +0 -25
- package/dist/cli/commands.d.ts +0 -2
- package/dist/cli/index.d.ts +0 -1
- package/dist/core/builders/vite/index.d.ts +0 -7
- package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +0 -7
- package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +0 -13
- package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +0 -14
- package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +0 -7
- package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +0 -6
- package/dist/core/builders/vite/plugins/download.d.ts +0 -10
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +0 -6
- package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +0 -6
- package/dist/core/builders/vite/plugins/globals.d.ts +0 -3
- package/dist/core/builders/vite/plugins/iifeFooter.d.ts +0 -8
- package/dist/core/builders/vite/plugins/index.d.ts +0 -16
- package/dist/core/builders/vite/plugins/noopBackground.d.ts +0 -6
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +0 -6
- package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +0 -6
- package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +0 -6
- package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +0 -3
- package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +0 -6
- package/dist/core/define-config.d.ts +0 -2
- package/dist/core/define-web-ext-config.d.ts +0 -9
- package/dist/core/generate-wxt-dir.d.ts +0 -5
- package/dist/core/index.d.ts +0 -8
- package/dist/core/initialize.d.ts +0 -5
- package/dist/core/keyboard-shortcuts.d.ts +0 -12
- package/dist/core/package-managers/bun.d.ts +0 -2
- package/dist/core/package-managers/deno.d.ts +0 -2
- package/dist/core/package-managers/index.d.ts +0 -2
- package/dist/core/package-managers/npm.d.ts +0 -17
- package/dist/core/package-managers/pnpm.d.ts +0 -2
- package/dist/core/package-managers/types.d.ts +0 -2
- package/dist/core/package-managers/types.mjs +0 -0
- package/dist/core/package-managers/yarn.d.ts +0 -2
- package/dist/core/prepare.d.ts +0 -2
- package/dist/core/resolve-config.d.ts +0 -11
- package/dist/core/runners/index.d.ts +0 -2
- package/dist/core/runners/manual.d.ts +0 -5
- package/dist/core/runners/safari.d.ts +0 -5
- package/dist/core/runners/web-ext.d.ts +0 -5
- package/dist/core/runners/wsl.d.ts +0 -5
- package/dist/core/utils/arrays.d.ts +0 -13
- package/dist/core/utils/building/build-entrypoints.d.ts +0 -3
- package/dist/core/utils/building/detect-dev-changes.d.ts +0 -61
- package/dist/core/utils/building/find-entrypoints.d.ts +0 -5
- package/dist/core/utils/building/group-entrypoints.d.ts +0 -8
- package/dist/core/utils/building/index.d.ts +0 -6
- package/dist/core/utils/building/internal-build.d.ts +0 -12
- package/dist/core/utils/building/rebuild.d.ts +0 -23
- package/dist/core/utils/cache.d.ts +0 -8
- package/dist/core/utils/cli.d.ts +0 -3
- package/dist/core/utils/cli.mjs +0 -26
- package/dist/core/utils/constants.d.ts +0 -5
- package/dist/core/utils/content-scripts.d.ts +0 -12
- package/dist/core/utils/content-security-policy.d.ts +0 -14
- package/dist/core/utils/entrypoints.d.ts +0 -31
- package/dist/core/utils/env.d.ts +0 -5
- package/dist/core/utils/environments/browser-environment.d.ts +0 -3
- package/dist/core/utils/environments/environment.d.ts +0 -8
- package/dist/core/utils/environments/extension-environment.d.ts +0 -6
- package/dist/core/utils/environments/index.d.ts +0 -2
- package/dist/core/utils/eslint.d.ts +0 -1
- package/dist/core/utils/fs.d.ts +0 -13
- package/dist/core/utils/globals.d.ts +0 -11
- package/dist/core/utils/i18n.d.ts +0 -11
- package/dist/core/utils/log/index.d.ts +0 -4
- package/dist/core/utils/log/printBuildSummary.d.ts +0 -2
- package/dist/core/utils/log/printFileList.d.ts +0 -1
- package/dist/core/utils/log/printHeader.d.ts +0 -1
- package/dist/core/utils/log/printTable.d.ts +0 -1
- package/dist/core/utils/manifest.d.ts +0 -40
- package/dist/core/utils/minimatch-multiple.d.ts +0 -15
- package/dist/core/utils/network.d.ts +0 -7
- package/dist/core/utils/number.d.ts +0 -1
- package/dist/core/utils/package.d.ts +0 -6
- package/dist/core/utils/paths.d.ts +0 -11
- package/dist/core/utils/strings.d.ts +0 -14
- package/dist/core/utils/syntax-errors.d.ts +0 -11
- package/dist/core/utils/testing/fake-objects.d.ts +0 -11665
- package/dist/core/utils/testing/fake-objects.mjs +0 -326
- package/dist/core/utils/time.d.ts +0 -9
- package/dist/core/utils/transform.d.ts +0 -11
- package/dist/core/utils/types.d.ts +0 -13
- package/dist/core/utils/types.mjs +0 -0
- package/dist/core/utils/validation.d.ts +0 -15
- package/dist/core/utils/virtual-modules.d.ts +0 -22
- package/dist/core/utils/wsl.d.ts +0 -4
- package/dist/core/wxt.d.ts +0 -24
- package/dist/index.d.ts +0 -11
- package/dist/testing/fake-browser.d.ts +0 -10
- package/dist/testing/index.d.ts +0 -10
- package/dist/types.d.ts +0 -1459
- package/dist/types.mjs +0 -0
- package/dist/utils/app-config.d.ts +0 -2
- package/dist/utils/content-script-context.d.ts +0 -134
- package/dist/utils/content-script-ui/iframe.d.ts +0 -32
- package/dist/utils/content-script-ui/integrated.d.ts +0 -34
- package/dist/utils/content-script-ui/shadow-root.d.ts +0 -76
- package/dist/utils/content-script-ui/shared.d.ts +0 -5
- package/dist/utils/content-script-ui/types.d.ts +0 -104
- package/dist/utils/define-background.d.ts +0 -4
- package/dist/utils/define-content-script.d.ts +0 -3
- package/dist/utils/define-unlisted-script.d.ts +0 -4
- package/dist/utils/define-wxt-plugin.d.ts +0 -3
- package/dist/utils/inject-script.d.ts +0 -36
- package/dist/utils/internal/custom-events.d.ts +0 -10
- package/dist/utils/internal/dev-server-websocket.d.ts +0 -21
- package/dist/utils/internal/dev-server-websocket.mjs +0 -37
- package/dist/utils/internal/location-watcher.d.ts +0 -12
- package/dist/utils/internal/logger.d.ts +0 -9
- package/dist/utils/match-patterns.d.ts +0 -5
- package/dist/utils/storage.d.ts +0 -5
- package/dist/version.d.ts +0 -1
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import * as vite from 'vite';
|
|
8
|
-
import type { UnimportOptions } from 'unimport';
|
|
9
|
-
export { WxtModule };
|
|
10
|
-
export declare function defineWxtModule<TOptions extends WxtModuleOptions>(module: WxtModule<TOptions> | WxtModuleSetup<TOptions>): WxtModule<TOptions>;
|
|
1
|
+
import { Entrypoint, Wxt, WxtModule, WxtModuleOptions, WxtModuleSetup } from "./types.mjs";
|
|
2
|
+
import * as vite from "vite";
|
|
3
|
+
import { UnimportOptions } from "unimport";
|
|
4
|
+
|
|
5
|
+
//#region src/modules.d.ts
|
|
6
|
+
declare function defineWxtModule<TOptions extends WxtModuleOptions>(module: WxtModule<TOptions> | WxtModuleSetup<TOptions>): WxtModule<TOptions>;
|
|
11
7
|
/**
|
|
12
8
|
* Adds a TS/JS file as an entrypoint to the project. This file will be bundled
|
|
13
9
|
* along with the other entrypoints.
|
|
@@ -35,7 +31,7 @@ export declare function defineWxtModule<TOptions extends WxtModuleOptions>(modul
|
|
|
35
31
|
* });
|
|
36
32
|
* });
|
|
37
33
|
*/
|
|
38
|
-
|
|
34
|
+
declare function addEntrypoint(wxt: Wxt, entrypoint: Entrypoint): void;
|
|
39
35
|
/**
|
|
40
36
|
* Copy files inside a directory (as if it were the public directory) into the
|
|
41
37
|
* extension's output directory. The directory itself is not copied, just the
|
|
@@ -49,7 +45,7 @@ export declare function addEntrypoint(wxt: Wxt, entrypoint: Entrypoint): void;
|
|
|
49
45
|
* addPublicAssets(wxt, "./dist/prebundled");
|
|
50
46
|
* });
|
|
51
47
|
*/
|
|
52
|
-
|
|
48
|
+
declare function addPublicAssets(wxt: Wxt, dir: string): void;
|
|
53
49
|
/**
|
|
54
50
|
* Merge additional vite config for one or more entrypoint "groups" that make
|
|
55
51
|
* up individual builds. Config in the project's `wxt.config.ts` file takes
|
|
@@ -68,7 +64,7 @@ export declare function addPublicAssets(wxt: Wxt, dir: string): void;
|
|
|
68
64
|
* });
|
|
69
65
|
* });
|
|
70
66
|
*/
|
|
71
|
-
|
|
67
|
+
declare function addViteConfig(wxt: Wxt, viteConfig: (env: vite.ConfigEnv) => vite.UserConfig | undefined): void;
|
|
72
68
|
/**
|
|
73
69
|
* Add a runtime plugin to the project. In each entrypoint, before executing
|
|
74
70
|
* the `main` function, plugins are executed.
|
|
@@ -82,7 +78,7 @@ export declare function addViteConfig(wxt: Wxt, viteConfig: (env: vite.ConfigEnv
|
|
|
82
78
|
* addWxtPlugin(wxt, "wxt-module-analytics/client-plugin");
|
|
83
79
|
* });
|
|
84
80
|
*/
|
|
85
|
-
|
|
81
|
+
declare function addWxtPlugin(wxt: Wxt, plugin: string): void;
|
|
86
82
|
/**
|
|
87
83
|
* Add an Unimport preset ([built-in](https://github.com/unjs/unimport?tab=readme-ov-file#built-in-presets),
|
|
88
84
|
* [custom](https://github.com/unjs/unimport?tab=readme-ov-file#custom-presets),
|
|
@@ -110,7 +106,7 @@ export declare function addWxtPlugin(wxt: Wxt, plugin: string): void;
|
|
|
110
106
|
* addImportPreset(wxt, { package: "vue" });
|
|
111
107
|
* });
|
|
112
108
|
*/
|
|
113
|
-
|
|
109
|
+
declare function addImportPreset(wxt: Wxt, preset: UnimportOptions['presets'][0]): void;
|
|
114
110
|
/**
|
|
115
111
|
* Adds an import alias to the project's TSConfig paths and bundler. Path can
|
|
116
112
|
* be absolute or relative to the project's root directory.
|
|
@@ -138,4 +134,6 @@ export declare function addImportPreset(wxt: Wxt, preset: UnimportOptions['prese
|
|
|
138
134
|
* addAlias(wxt, "#i18n", i18nPath);
|
|
139
135
|
* });
|
|
140
136
|
*/
|
|
141
|
-
|
|
137
|
+
declare function addAlias(wxt: Wxt, alias: string, path: string): void;
|
|
138
|
+
//#endregion
|
|
139
|
+
export { WxtModule, addAlias, addEntrypoint, addImportPreset, addPublicAssets, addViteConfig, addWxtPlugin, defineWxtModule };
|
package/dist/modules.mjs
CHANGED
|
@@ -1,60 +1,190 @@
|
|
|
1
|
-
import * as vite from "vite";
|
|
2
1
|
import glob from "fast-glob";
|
|
3
2
|
import { resolve } from "node:path";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import * as vite from "vite";
|
|
4
|
+
|
|
5
|
+
//#region src/modules.ts
|
|
6
|
+
function defineWxtModule(module) {
|
|
7
|
+
if (typeof module === "function") return { setup: module };
|
|
8
|
+
return module;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Adds a TS/JS file as an entrypoint to the project. This file will be bundled
|
|
12
|
+
* along with the other entrypoints.
|
|
13
|
+
*
|
|
14
|
+
* If you're publishing the module to NPM, you should probably pre-build the
|
|
15
|
+
* entrypoint and use `addPublicAssets` instead to copy pre-bundled assets into
|
|
16
|
+
* the output directory. This will speed up project builds since it just has to
|
|
17
|
+
* copy some files instead of bundling them.
|
|
18
|
+
*
|
|
19
|
+
* To extract entrypoint options from a JS/TS file, use
|
|
20
|
+
* `wxt.builder.importEntrypoint` (see example).
|
|
21
|
+
*
|
|
22
|
+
* @param wxt The wxt instance provided by the module's setup function.
|
|
23
|
+
* @param entrypoint The entrypoint to be bundled along with the extension.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* export default defineWxtModule(async (wxt, options) => {
|
|
27
|
+
* const entrypointPath = "/path/to/my-entrypoint.ts";
|
|
28
|
+
* addEntrypoint(wxt, {
|
|
29
|
+
* type: "content-script",
|
|
30
|
+
* name: "some-name",
|
|
31
|
+
* inputPath: entrypointPath,
|
|
32
|
+
* outputDir: wxt.config.outDir,
|
|
33
|
+
* options: await wxt.builder.importEntrypoint(entrypointPath),
|
|
34
|
+
* });
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
function addEntrypoint(wxt, entrypoint) {
|
|
38
|
+
wxt.hooks.hook("entrypoints:resolved", (_, entrypoints) => {
|
|
39
|
+
entrypoints.push(entrypoint);
|
|
40
|
+
});
|
|
13
41
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Copy files inside a directory (as if it were the public directory) into the
|
|
44
|
+
* extension's output directory. The directory itself is not copied, just the
|
|
45
|
+
* files inside it. If a filename matches an existing one, it is ignored.
|
|
46
|
+
*
|
|
47
|
+
* @param wxt The wxt instance provided by the module's setup function.
|
|
48
|
+
* @param dir The directory to copy.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* export default defineWxtModule((wxt, options) => {
|
|
52
|
+
* addPublicAssets(wxt, "./dist/prebundled");
|
|
53
|
+
* });
|
|
54
|
+
*/
|
|
55
|
+
function addPublicAssets(wxt, dir) {
|
|
56
|
+
wxt.hooks.hook("build:publicAssets", async (wxt, files) => {
|
|
57
|
+
const moreFiles = await glob("**/*", { cwd: dir });
|
|
58
|
+
if (moreFiles.length === 0) {
|
|
59
|
+
wxt.logger.warn("No files to copy in", dir);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
moreFiles.forEach((file) => {
|
|
63
|
+
files.unshift({
|
|
64
|
+
absoluteSrc: resolve(dir, file),
|
|
65
|
+
relativeDest: file
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
25
69
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Merge additional vite config for one or more entrypoint "groups" that make
|
|
72
|
+
* up individual builds. Config in the project's `wxt.config.ts` file takes
|
|
73
|
+
* precedence over any config added by this function.
|
|
74
|
+
*
|
|
75
|
+
* @param wxt The wxt instance provided by the module's setup function.
|
|
76
|
+
* @param viteConfig A function that returns the vite config the module is
|
|
77
|
+
adding. Same format as `vite` in `wxt.config.ts`.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* export default defineWxtModule((wxt, options) => {
|
|
81
|
+
* addViteConfig(wxt, () => ({
|
|
82
|
+
* build: {
|
|
83
|
+
* sourceMaps: true,
|
|
84
|
+
* },
|
|
85
|
+
* });
|
|
86
|
+
* });
|
|
87
|
+
*/
|
|
88
|
+
function addViteConfig(wxt, viteConfig) {
|
|
89
|
+
wxt.hooks.hook("config:resolved", (wxt) => {
|
|
90
|
+
const userVite = wxt.config.vite;
|
|
91
|
+
wxt.config.vite = async (env) => {
|
|
92
|
+
const fromUser = await userVite(env);
|
|
93
|
+
const fromModule = viteConfig(env) ?? {};
|
|
94
|
+
return vite.mergeConfig(fromModule, fromUser);
|
|
95
|
+
};
|
|
96
|
+
});
|
|
35
97
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Add a runtime plugin to the project. In each entrypoint, before executing
|
|
100
|
+
* the `main` function, plugins are executed.
|
|
101
|
+
*
|
|
102
|
+
* @param wxt The wxt instance provided by the module's setup function.
|
|
103
|
+
* @param plugin An import from an NPM module, or an absolute file path to the
|
|
104
|
+
* file to load at runtime.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* export default defineWxtModule((wxt) => {
|
|
108
|
+
* addWxtPlugin(wxt, "wxt-module-analytics/client-plugin");
|
|
109
|
+
* });
|
|
110
|
+
*/
|
|
111
|
+
function addWxtPlugin(wxt, plugin) {
|
|
112
|
+
wxt.hooks.hook("config:resolved", (wxt) => {
|
|
113
|
+
wxt.config.plugins.push(plugin);
|
|
114
|
+
});
|
|
40
115
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Add an Unimport preset ([built-in](https://github.com/unjs/unimport?tab=readme-ov-file#built-in-presets),
|
|
118
|
+
* [custom](https://github.com/unjs/unimport?tab=readme-ov-file#custom-presets),
|
|
119
|
+
* or [auto-scanned](https://github.com/unjs/unimport?tab=readme-ov-file#exports-auto-scan)),
|
|
120
|
+
* to the project's list of auto-imported utilities.
|
|
121
|
+
*
|
|
122
|
+
* Some things to note:
|
|
123
|
+
* - This function will only de-duplicate built-in preset names. It will not
|
|
124
|
+
* stop you adding duplicate custom or auto-scanned presets.
|
|
125
|
+
* - If the project has disabled imports, this function has no effect.
|
|
126
|
+
*
|
|
127
|
+
* @param wxt The wxt instance provided by the module's setup function.
|
|
128
|
+
* @param preset The preset to add to the project.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* export default defineWxtModule((wxt) => {
|
|
132
|
+
* // Built-in preset:
|
|
133
|
+
* addImportPreset(wxt, "vue");
|
|
134
|
+
* // Custom preset:
|
|
135
|
+
* addImportPreset(wxt, {
|
|
136
|
+
* from: "vue",
|
|
137
|
+
* imports: ["ref", "reactive", ...],
|
|
138
|
+
* });
|
|
139
|
+
* // Auto-scanned preset:
|
|
140
|
+
* addImportPreset(wxt, { package: "vue" });
|
|
141
|
+
* });
|
|
142
|
+
*/
|
|
143
|
+
function addImportPreset(wxt, preset) {
|
|
144
|
+
wxt.hooks.hook("config:resolved", (wxt) => {
|
|
145
|
+
if (!wxt.config.imports) return;
|
|
146
|
+
wxt.config.imports.presets ??= [];
|
|
147
|
+
if (wxt.config.imports.presets.includes(preset)) return;
|
|
148
|
+
wxt.config.imports.presets.push(preset);
|
|
149
|
+
});
|
|
48
150
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
151
|
+
/**
|
|
152
|
+
* Adds an import alias to the project's TSConfig paths and bundler. Path can
|
|
153
|
+
* be absolute or relative to the project's root directory.
|
|
154
|
+
*
|
|
155
|
+
* Usually, this is used to provide access to some code generated by your
|
|
156
|
+
* module. In the example below, a `i18n` plugin generates a variable that it
|
|
157
|
+
* wants to provide access to, so it creates the file and adds an import alias
|
|
158
|
+
* to it.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* import path from 'node:path';
|
|
162
|
+
*
|
|
163
|
+
* export default defineWxtModule((wxt) => {
|
|
164
|
+
* const i18nPath = path.resolve(wxt.config.wxtDir, "i18n.ts");
|
|
165
|
+
*
|
|
166
|
+
* // Generate the file
|
|
167
|
+
* wxt.hooks.hook("prepare:types", (_, entries) => {
|
|
168
|
+
* entries.push({
|
|
169
|
+
* path: i18nPath,
|
|
170
|
+
* text: `export const i18n = ...`,
|
|
171
|
+
* });
|
|
172
|
+
* });
|
|
173
|
+
*
|
|
174
|
+
* // Add alias
|
|
175
|
+
* addAlias(wxt, "#i18n", i18nPath);
|
|
176
|
+
* });
|
|
177
|
+
*/
|
|
178
|
+
function addAlias(wxt, alias, path) {
|
|
179
|
+
wxt.hooks.hook("config:resolved", (wxt) => {
|
|
180
|
+
const target = resolve(wxt.config.root, path);
|
|
181
|
+
if (wxt.config.alias[alias] != null && wxt.config.alias[alias] !== target) {
|
|
182
|
+
wxt.logger.warn(`Skipped adding alias (${alias} => ${target}) because an alias with the same name already exists: ${alias} => ${wxt.config.alias[alias]}`);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
wxt.config.alias[alias] = target;
|
|
186
|
+
});
|
|
60
187
|
}
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
export { addAlias, addEntrypoint, addImportPreset, addPublicAssets, addViteConfig, addWxtPlugin, defineWxtModule };
|
package/dist/testing/index.mjs
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @module wxt/testing/vitest
|
|
6
|
-
*/
|
|
7
|
-
import type * as vite from 'vite';
|
|
8
|
-
import { InlineConfig } from '../types';
|
|
1
|
+
import { InlineConfig } from "../types.mjs";
|
|
2
|
+
import * as vite from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/testing/wxt-vitest-plugin.d.ts
|
|
9
5
|
/**
|
|
10
6
|
* Vite plugin that configures Vitest with everything required to test a WXT extension, based on the `<root>/wxt.config.ts`
|
|
11
7
|
*
|
|
@@ -21,4 +17,6 @@ import { InlineConfig } from '../types';
|
|
|
21
17
|
*
|
|
22
18
|
* @param inlineConfig Customize WXT's config for testing. Any config specified here overrides the config from your `wxt.config.ts` file.
|
|
23
19
|
*/
|
|
24
|
-
|
|
20
|
+
declare function WxtVitest(inlineConfig?: InlineConfig): Promise<vite.PluginOption[]>;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { WxtVitest };
|
|
@@ -1,21 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "../core/builders/vite/plugins/index.mjs";
|
|
8
|
-
import UnimportPlugin from "unimport/unplugin";
|
|
1
|
+
import { download } from "../core/builders/vite/plugins/download.mjs";
|
|
2
|
+
import { tsconfigPaths } from "../core/builders/vite/plugins/tsconfigPaths.mjs";
|
|
3
|
+
import { globals } from "../core/builders/vite/plugins/globals.mjs";
|
|
4
|
+
import { extensionApiMock } from "../core/builders/vite/plugins/extensionApiMock.mjs";
|
|
5
|
+
import { resolveAppConfig } from "../core/builders/vite/plugins/resolveAppConfig.mjs";
|
|
6
|
+
import "../core/builders/vite/plugins/index.mjs";
|
|
9
7
|
import { registerWxt, wxt } from "../core/wxt.mjs";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
import UnimportPlugin from "unimport/unplugin";
|
|
9
|
+
|
|
10
|
+
//#region src/testing/wxt-vitest-plugin.ts
|
|
11
|
+
/**
|
|
12
|
+
* Vite plugin that configures Vitest with everything required to test a WXT extension, based on the `<root>/wxt.config.ts`
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* // vitest.config.ts
|
|
16
|
+
* import { defineConfig } from 'vitest/config';
|
|
17
|
+
* import { WxtVitest } from 'wxt/testing/vitest-plugin';
|
|
18
|
+
*
|
|
19
|
+
* export default defineConfig({
|
|
20
|
+
* plugins: [WxtVitest()],
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param inlineConfig Customize WXT's config for testing. Any config specified here overrides the config from your `wxt.config.ts` file.
|
|
25
|
+
*/
|
|
26
|
+
async function WxtVitest(inlineConfig) {
|
|
27
|
+
await registerWxt("serve", inlineConfig ?? {});
|
|
28
|
+
const plugins = [
|
|
29
|
+
globals(wxt.config),
|
|
30
|
+
download(wxt.config),
|
|
31
|
+
tsconfigPaths(wxt.config),
|
|
32
|
+
resolveAppConfig(wxt.config),
|
|
33
|
+
extensionApiMock(wxt.config)
|
|
34
|
+
];
|
|
35
|
+
plugins.push(UnimportPlugin.vite(wxt.config.imports));
|
|
36
|
+
return plugins;
|
|
21
37
|
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { WxtVitest };
|