wxt 0.19.29 → 0.20.0-beta2

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.
Files changed (95) hide show
  1. package/dist/browser.d.ts +30 -0
  2. package/dist/browser.mjs +3 -0
  3. package/dist/builtin-modules/unimport.mjs +29 -10
  4. package/dist/cli/index.mjs +0 -1
  5. package/dist/core/builders/vite/index.mjs +17 -37
  6. package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +1 -6
  7. package/dist/core/builders/vite/plugins/extensionApiMock.mjs +2 -4
  8. package/dist/core/builders/vite/plugins/index.d.ts +0 -1
  9. package/dist/core/builders/vite/plugins/index.mjs +0 -1
  10. package/dist/core/builders/vite/plugins/noopBackground.mjs +1 -1
  11. package/dist/core/define-web-ext-config.d.ts +9 -0
  12. package/dist/core/define-web-ext-config.mjs +10 -0
  13. package/dist/core/generate-wxt-dir.mjs +3 -6
  14. package/dist/core/index.d.ts +1 -1
  15. package/dist/core/index.mjs +1 -1
  16. package/dist/core/resolve-config.mjs +142 -49
  17. package/dist/core/utils/building/index.d.ts +0 -1
  18. package/dist/core/utils/building/index.mjs +0 -1
  19. package/dist/core/utils/building/rebuild.d.ts +2 -2
  20. package/dist/core/utils/content-scripts.d.ts +4 -3
  21. package/dist/core/utils/content-scripts.mjs +2 -0
  22. package/dist/core/utils/manifest.d.ts +4 -8
  23. package/dist/core/utils/manifest.mjs +4 -7
  24. package/dist/core/utils/strings.d.ts +0 -4
  25. package/dist/core/utils/strings.mjs +0 -6
  26. package/dist/core/utils/testing/fake-objects.d.ts +3376 -1013
  27. package/dist/core/utils/testing/fake-objects.mjs +19 -22
  28. package/dist/core/utils/transform.d.ts +1 -1
  29. package/dist/core/utils/types.d.ts +3 -0
  30. package/dist/index.d.ts +5 -0
  31. package/dist/modules.d.ts +1 -1
  32. package/dist/testing/index.d.ts +1 -0
  33. package/dist/testing/wxt-vitest-plugin.mjs +1 -3
  34. package/dist/types.d.ts +42 -76
  35. package/dist/utils/app-config.d.ts +2 -0
  36. package/dist/{client/content-scripts → utils}/content-script-context.d.ts +4 -3
  37. package/dist/{client/content-scripts → utils}/content-script-context.mjs +5 -3
  38. package/dist/utils/content-script-ui/iframe.d.ts +32 -0
  39. package/dist/utils/content-script-ui/iframe.mjs +30 -0
  40. package/dist/utils/content-script-ui/integrated.d.ts +34 -0
  41. package/dist/utils/content-script-ui/integrated.mjs +32 -0
  42. package/dist/utils/content-script-ui/shadow-root.d.ts +76 -0
  43. package/dist/utils/content-script-ui/shadow-root.mjs +73 -0
  44. package/dist/utils/content-script-ui/shared.d.ts +5 -0
  45. package/dist/{client/content-scripts/ui/index.mjs → utils/content-script-ui/shared.mjs} +5 -138
  46. package/dist/{client/content-scripts/ui → utils/content-script-ui}/types.d.ts +1 -96
  47. package/dist/{sandbox → utils}/define-app-config.d.ts +3 -2
  48. package/dist/{sandbox → utils}/define-background.d.ts +1 -0
  49. package/dist/{sandbox → utils}/define-content-script.d.ts +1 -0
  50. package/dist/{sandbox → utils}/define-unlisted-script.d.ts +1 -0
  51. package/dist/{sandbox → utils}/define-wxt-plugin.d.ts +1 -0
  52. package/dist/{sandbox → utils/internal}/dev-server-websocket.mjs +1 -1
  53. package/dist/{client/content-scripts → utils/internal}/location-watcher.d.ts +1 -1
  54. package/dist/utils/match-patterns.d.ts +5 -0
  55. package/dist/utils/match-patterns.mjs +1 -0
  56. package/dist/utils/storage.d.ts +5 -0
  57. package/dist/version.mjs +1 -1
  58. package/dist/virtual/background-entrypoint.mjs +1 -1
  59. package/dist/virtual/content-script-isolated-world-entrypoint.mjs +1 -1
  60. package/package.json +109 -76
  61. package/dist/browser/chrome.d.ts +0 -13
  62. package/dist/browser/chrome.mjs +0 -7
  63. package/dist/browser/index.d.ts +0 -26
  64. package/dist/browser/index.mjs +0 -2
  65. package/dist/client/app-config.d.ts +0 -2
  66. package/dist/client/content-scripts/index.d.ts +0 -2
  67. package/dist/client/content-scripts/index.mjs +0 -2
  68. package/dist/client/content-scripts/ui/index.d.ts +0 -23
  69. package/dist/client/index.d.ts +0 -8
  70. package/dist/client/index.mjs +0 -3
  71. package/dist/core/builders/vite/plugins/resolveExtensionApi.d.ts +0 -10
  72. package/dist/core/builders/vite/plugins/resolveExtensionApi.mjs +0 -15
  73. package/dist/core/define-runner-config.d.ts +0 -2
  74. package/dist/core/define-runner-config.mjs +0 -3
  75. package/dist/core/utils/building/import-entrypoint.d.ts +0 -16
  76. package/dist/core/utils/building/import-entrypoint.mjs +0 -99
  77. package/dist/sandbox/index.d.ts +0 -11
  78. package/dist/sandbox/index.mjs +0 -6
  79. package/dist/storage.d.ts +0 -4
  80. /package/dist/{client → utils}/app-config.mjs +0 -0
  81. /package/dist/{client/content-scripts/ui → utils/content-script-ui}/types.mjs +0 -0
  82. /package/dist/{sandbox → utils}/define-app-config.mjs +0 -0
  83. /package/dist/{sandbox → utils}/define-background.mjs +0 -0
  84. /package/dist/{sandbox → utils}/define-content-script.mjs +0 -0
  85. /package/dist/{sandbox → utils}/define-unlisted-script.mjs +0 -0
  86. /package/dist/{sandbox → utils}/define-wxt-plugin.mjs +0 -0
  87. /package/dist/{client → utils}/inject-script.d.ts +0 -0
  88. /package/dist/{client → utils}/inject-script.mjs +0 -0
  89. /package/dist/{client/content-scripts → utils/internal}/custom-events.d.ts +0 -0
  90. /package/dist/{client/content-scripts → utils/internal}/custom-events.mjs +0 -0
  91. /package/dist/{sandbox → utils/internal}/dev-server-websocket.d.ts +0 -0
  92. /package/dist/{client/content-scripts → utils/internal}/location-watcher.mjs +0 -0
  93. /package/dist/{sandbox/utils → utils/internal}/logger.d.ts +0 -0
  94. /package/dist/{sandbox/utils → utils/internal}/logger.mjs +0 -0
  95. /package/dist/{storage.mjs → utils/storage.mjs} +0 -0
@@ -1,13 +0,0 @@
1
- /**
2
- * EXPERIMENTAL
3
- *
4
- * Includes the `chrome` API and types when using `extensionApi: 'chrome'`.
5
- *
6
- * @module wxt/browser/chrome
7
- */
8
- import type { WxtRuntime, WxtI18n } from './index';
9
- export type WxtBrowser = Omit<typeof chrome, 'runtime' | 'i18n'> & {
10
- runtime: WxtRuntime & Omit<(typeof chrome)['runtime'], 'getURL'>;
11
- i18n: WxtI18n & Omit<(typeof chrome)['i18n'], 'getMessage'>;
12
- };
13
- export declare const browser: WxtBrowser;
@@ -1,7 +0,0 @@
1
- export const browser = (
2
- // @ts-expect-error
3
- globalThis.browser?.runtime?.id == null ? globalThis.chrome : (
4
- // @ts-expect-error
5
- globalThis.browser
6
- )
7
- );
@@ -1,26 +0,0 @@
1
- /**
2
- * Includes the `browser` API and types when using `extensionApi: 'webextension-polyfill'` (the default).
3
- *
4
- * @module wxt/browser
5
- */
6
- import { Browser } from 'webextension-polyfill';
7
- export type AugmentedBrowser = Omit<Browser, 'runtime' | 'i18n'> & {
8
- runtime: WxtRuntime & Omit<Browser['runtime'], 'getURL'>;
9
- i18n: WxtI18n & Omit<Browser['i18n'], 'getMessage'>;
10
- };
11
- /**
12
- * This interface is empty because it is generated per-project when running `wxt prepare`. See:
13
- * - `.wxt/types/paths.d.ts`
14
- */
15
- export interface WxtRuntime {
16
- }
17
- /**
18
- * This interface is empty because it is generated per-project when running `wxt prepare`. See:
19
- * - `.wxt/types/i18n.d.ts`
20
- */
21
- export interface WxtI18n {
22
- }
23
- export declare const browser: AugmentedBrowser;
24
- /** @ignore */
25
- export type { ActivityLog, Alarms, Bookmarks, Action, BrowserAction, BrowserSettings, BrowsingData, CaptivePortal, Clipboard, Commands, ContentScripts, ContextualIdentities, Cookies, DeclarativeNetRequest, Devtools, Dns, Downloads, Events, Experiments, Extension, ExtensionTypes, Find, GeckoProfiler, History, I18n, Identity, Idle, Management, Manifest, // TODO: Export custom manifest types that are valid for both Chrome and Firefox.
26
- ContextMenus, Menus, NetworkStatus, NormandyAddonStudy, Notifications, Omnibox, PageAction, Permissions, Pkcs11, Privacy, Proxy, Runtime, Scripting, Search, Sessions, SidebarAction, Storage, Tabs, Theme, TopSites, Types, UserScripts, WebNavigation, WebRequest, Windows, } from 'webextension-polyfill';
@@ -1,2 +0,0 @@
1
- import originalBrowser from "webextension-polyfill";
2
- export const browser = originalBrowser;
@@ -1,2 +0,0 @@
1
- import type { WxtAppConfig } from '../sandbox/define-app-config';
2
- export declare function useAppConfig(): WxtAppConfig;
@@ -1,2 +0,0 @@
1
- export * from './content-script-context';
2
- export * from './ui';
@@ -1,2 +0,0 @@
1
- export * from "./content-script-context.mjs";
2
- export * from "./ui/index.mjs";
@@ -1,23 +0,0 @@
1
- import { ContentScriptContext } from '..';
2
- import { IframeContentScriptUi, IframeContentScriptUiOptions, IntegratedContentScriptUi, IntegratedContentScriptUiOptions, ShadowRootContentScriptUi, ShadowRootContentScriptUiOptions } from './types';
3
- export * from './types';
4
- /**
5
- * Create a content script UI without any isolation.
6
- *
7
- * @see https://wxt.dev/guide/essentials/content-scripts.html#integrated
8
- */
9
- export declare function createIntegratedUi<TMounted>(ctx: ContentScriptContext, options: IntegratedContentScriptUiOptions<TMounted>): IntegratedContentScriptUi<TMounted>;
10
- /**
11
- * Create a content script UI using an iframe.
12
- *
13
- * @see https://wxt.dev/guide/essentials/content-scripts.html#iframe
14
- */
15
- export declare function createIframeUi<TMounted>(ctx: ContentScriptContext, options: IframeContentScriptUiOptions<TMounted>): IframeContentScriptUi<TMounted>;
16
- /**
17
- * Create a content script UI inside a [`ShadowRoot`](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot).
18
- *
19
- * > This function is async because it has to load the CSS via a network call.
20
- *
21
- * @see https://wxt.dev/guide/essentials/content-scripts.html#shadow-root
22
- */
23
- export declare function createShadowRootUi<TMounted>(ctx: ContentScriptContext, options: ShadowRootContentScriptUiOptions<TMounted>): Promise<ShadowRootContentScriptUi<TMounted>>;
@@ -1,8 +0,0 @@
1
- /**
2
- * Any runtime APIs that use the web extension APIs.
3
- *
4
- * @module wxt/client
5
- */
6
- export * from './content-scripts';
7
- export * from './app-config';
8
- export * from './inject-script';
@@ -1,3 +0,0 @@
1
- export * from "./content-scripts/index.mjs";
2
- export * from "./app-config.mjs";
3
- export * from "./inject-script.mjs";
@@ -1,10 +0,0 @@
1
- import { ResolvedConfig } from '../../../../types';
2
- import type * as vite from 'vite';
3
- /**
4
- * Apply the experimental config for which extension API is used. This only
5
- * effects the extension API included at RUNTIME - during development, types
6
- * depend on the import.
7
- *
8
- * NOTE: this only works if we import `wxt/browser` instead of using the relative path.
9
- */
10
- export declare function resolveExtensionApi(config: ResolvedConfig): vite.Plugin;
@@ -1,15 +0,0 @@
1
- export function resolveExtensionApi(config) {
2
- return {
3
- name: "wxt:resolve-extension-api",
4
- config() {
5
- if (config.extensionApi === "webextension-polyfill") return;
6
- return {
7
- resolve: {
8
- alias: [
9
- { find: /^wxt\/browser$/, replacement: "wxt/browser/chrome" }
10
- ]
11
- }
12
- };
13
- }
14
- };
15
- }
@@ -1,2 +0,0 @@
1
- import { ExtensionRunnerConfig } from '../types';
2
- export declare function defineRunnerConfig(config: ExtensionRunnerConfig): ExtensionRunnerConfig;
@@ -1,3 +0,0 @@
1
- export function defineRunnerConfig(config) {
2
- return config;
3
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * Get the value from the default export of a `path`.
3
- *
4
- * It works by:
5
- *
6
- * 1. Reading the file text
7
- * 2. Stripping all imports from it via regex
8
- * 3. Auto-import only the client helper functions
9
- *
10
- * This prevents resolving imports of imports, speeding things up and preventing "xxx is not
11
- * defined" errors.
12
- *
13
- * Downside is that code cannot be executed outside of the main fucntion for the entrypoint,
14
- * otherwise you will see "xxx is not defined" errors for any imports used outside of main function.
15
- */
16
- export declare function importEntrypointFile<T>(path: string): Promise<T>;
@@ -1,99 +0,0 @@
1
- import createJITI from "jiti";
2
- import { createUnimport } from "unimport";
3
- import fs from "fs-extra";
4
- import { relative, resolve } from "node:path";
5
- import { removeProjectImportStatements } from "../../utils/strings.mjs";
6
- import { normalizePath } from "../../utils/paths.mjs";
7
- import { transformSync } from "esbuild";
8
- import { fileURLToPath } from "node:url";
9
- import { wxt } from "../../wxt.mjs";
10
- export async function importEntrypointFile(path) {
11
- wxt.logger.debug("Loading file metadata:", path);
12
- const normalPath = normalizePath(path);
13
- const unimport = createUnimport({
14
- ...wxt.config.imports,
15
- // Only allow specific imports, not all from the project
16
- dirs: []
17
- });
18
- await unimport.init();
19
- const text = await fs.readFile(path, "utf-8");
20
- const textNoImports = removeProjectImportStatements(text);
21
- const { code } = await unimport.injectImports(textNoImports);
22
- wxt.logger.debug(
23
- ["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
24
- );
25
- const jiti = createJITI(
26
- typeof __filename !== "undefined" ? __filename : fileURLToPath(import.meta.url),
27
- {
28
- cache: false,
29
- debug: wxt.config.debug,
30
- alias: {
31
- "webextension-polyfill": resolve(
32
- wxt.config.wxtModuleDir,
33
- "dist/virtual/mock-browser.mjs"
34
- ),
35
- // TODO: Resolve this virtual module to some file with
36
- // `export default {}` instead of this hack of using another file with
37
- // a default export.
38
- "virtual:app-config": resolve(
39
- wxt.config.wxtModuleDir,
40
- "dist/virtual/mock-browser.mjs"
41
- )
42
- },
43
- // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
44
- // respect the custom transform function when using it's native bun option.
45
- tryNative: false,
46
- // List of extensions to transform with esbuild
47
- extensions: [
48
- ".ts",
49
- ".cts",
50
- ".mts",
51
- ".tsx",
52
- ".js",
53
- ".cjs",
54
- ".mjs",
55
- ".jsx"
56
- ],
57
- transform(opts) {
58
- const isEntrypoint = opts.filename === normalPath;
59
- return transformSync(
60
- // Use modified source code for entrypoints
61
- isEntrypoint ? code : opts.source,
62
- getEsbuildOptions(opts)
63
- );
64
- }
65
- }
66
- );
67
- try {
68
- const res = await jiti(path);
69
- return res.default;
70
- } catch (err) {
71
- const filePath = relative(wxt.config.root, path);
72
- if (err instanceof ReferenceError) {
73
- const variableName = err.message.replace(" is not defined", "");
74
- throw Error(
75
- `${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/go-further/entrypoint-side-effects.html`,
76
- { cause: err }
77
- );
78
- } else {
79
- wxt.logger.error(err);
80
- throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
81
- }
82
- }
83
- }
84
- function getEsbuildOptions(opts) {
85
- const isJsx = opts.filename?.endsWith("x");
86
- return {
87
- format: "cjs",
88
- loader: isJsx ? "tsx" : "ts",
89
- define: {
90
- "import.meta.env.ENTRYPOINT": '"build"'
91
- },
92
- ...isJsx ? {
93
- // `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
94
- // grabbing the entrypoint's options.
95
- jsxFactory: "h",
96
- jsxFragment: "Fragment"
97
- } : void 0
98
- };
99
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Any runtime APIs that don't use the web extension APIs.
3
- *
4
- * @module wxt/sandbox
5
- */
6
- export * from './define-unlisted-script';
7
- export * from './define-background';
8
- export * from './define-content-script';
9
- export * from './define-wxt-plugin';
10
- export * from './define-app-config';
11
- export * from '@webext-core/match-patterns';
@@ -1,6 +0,0 @@
1
- export * from "./define-unlisted-script.mjs";
2
- export * from "./define-background.mjs";
3
- export * from "./define-content-script.mjs";
4
- export * from "./define-wxt-plugin.mjs";
5
- export * from "./define-app-config.mjs";
6
- export * from "@webext-core/match-patterns";
package/dist/storage.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * @module @wxt-dev/storage
3
- */
4
- export * from '@wxt-dev/storage';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes