wxt 0.21.3 → 0.21.5

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 (148) hide show
  1. package/README.md +1 -1
  2. package/dist/{core/build.d.mts → build.d.mts} +2 -2
  3. package/dist/{core/build.mjs → build.mjs} +3 -4
  4. package/dist/{core/clean.d.mts → clean.d.mts} +2 -2
  5. package/dist/{core/clean.mjs → clean.mjs} +3 -3
  6. package/dist/cli/cli-utils.mjs +11 -8
  7. package/dist/cli/commands.mjs +10 -9
  8. package/dist/{core/create-server.d.mts → create-server.d.mts} +2 -2
  9. package/dist/{core/create-server.mjs → create-server.mjs} +13 -14
  10. package/dist/define-config.d.mts +6 -0
  11. package/dist/{core/define-config.mjs → define-config.mjs} +1 -1
  12. package/dist/{core/define-web-ext-config.d.mts → define-web-ext-config.d.mts} +2 -2
  13. package/dist/{core/define-web-ext-config.mjs → define-web-ext-config.mjs} +1 -1
  14. package/dist/index.d.mts +12 -12
  15. package/dist/index.mjs +10 -11
  16. package/dist/{core/initialize.d.mts → initialize.d.mts} +2 -1
  17. package/dist/{core/initialize.mjs → initialize.mjs} +22 -7
  18. package/dist/inline/dotenv-expand/index.mjs +31 -0
  19. package/dist/inline/get-port-please/index.mjs +196 -0
  20. package/dist/inline/is-wsl/index.mjs +44 -0
  21. package/dist/inline/normalize-path/index.mjs +23 -0
  22. package/dist/inline/ohash/index.mjs +113 -0
  23. package/dist/inline/scule/index.mjs +50 -0
  24. package/dist/{core/utils/building → internal}/build-entrypoints.mjs +5 -5
  25. package/dist/internal/builders/unknown.mjs +22 -0
  26. package/dist/{core → internal}/builders/vite/index.mjs +144 -139
  27. package/dist/internal/builders/vite/plugins/add-entrypoint-group-runtime-env-entries.mjs +16 -0
  28. package/dist/internal/builders/vite/plugins/add-runtime-env-entries.mjs +14 -0
  29. package/dist/{core/builders/vite/plugins/bundleAnalysis.mjs → internal/builders/vite/plugins/bundle-analysis.mjs} +1 -1
  30. package/dist/{core/builders/vite/plugins/cssEntrypoints.mjs → internal/builders/vite/plugins/css-entrypoints.mjs} +2 -2
  31. package/dist/{core/builders/vite/plugins/defineImportMeta.mjs → internal/builders/vite/plugins/define-import-meta.mjs} +1 -1
  32. package/dist/{core/builders/vite/plugins/devHtmlPrerender.mjs → internal/builders/vite/plugins/dev-html-prerender.mjs} +6 -7
  33. package/dist/{core/builders/vite/plugins/devServerGlobals.mjs → internal/builders/vite/plugins/dev-server-globals.mjs} +1 -1
  34. package/dist/{core/builders/vite/plugins/extensionApiMock.mjs → internal/builders/vite/plugins/extension-api-mock.mjs} +1 -1
  35. package/dist/{core/builders/vite/plugins/iifeAnonymous.mjs → internal/builders/vite/plugins/iife-anonymous.mjs} +1 -1
  36. package/dist/{core/builders/vite/plugins/iifeFooter.mjs → internal/builders/vite/plugins/iife-footer.mjs} +1 -1
  37. package/dist/internal/builders/vite/plugins/index.mjs +17 -0
  38. package/dist/{core/builders/vite/plugins/noopBackground.mjs → internal/builders/vite/plugins/noop-background.mjs} +2 -2
  39. package/dist/{core/builders/vite/plugins/removeEntrypointMainFunction.mjs → internal/builders/vite/plugins/remove-entrypoint-main-function.mjs} +3 -4
  40. package/dist/{core/builders/vite/plugins/resolveAppConfig.mjs → internal/builders/vite/plugins/resolve-app-config.mjs} +2 -2
  41. package/dist/{core/builders/vite/plugins/resolveVirtualModules.mjs → internal/builders/vite/plugins/resolve-virtual-modules.mjs} +8 -6
  42. package/dist/{core/builders/vite/plugins/tsconfigPaths.mjs → internal/builders/vite/plugins/tsconfig-paths.mjs} +1 -1
  43. package/dist/internal/builders/vite/plugins/wxt-plugin-loader.mjs +77 -0
  44. package/dist/{builtin-modules → internal/builtin-modules}/escape-unicode.mjs +2 -2
  45. package/dist/{builtin-modules → internal/builtin-modules}/favicon-permission.mjs +2 -2
  46. package/dist/{builtin-modules → internal/builtin-modules}/index.mjs +4 -2
  47. package/dist/internal/builtin-modules/plugins.mjs +21 -0
  48. package/dist/{builtin-modules → internal/builtin-modules}/unimport.mjs +20 -9
  49. package/dist/{core/utils → internal}/constants.mjs +1 -1
  50. package/dist/internal/detect-builder.mjs +9 -0
  51. package/dist/{core/utils/building → internal}/detect-dev-changes.mjs +4 -4
  52. package/dist/internal/detect-runner.mjs +11 -0
  53. package/dist/internal/entrypoint-finders/flat.mjs +84 -0
  54. package/dist/internal/environments/browser-environment.mjs +48 -0
  55. package/dist/{core/utils → internal}/environments/environment.mjs +1 -1
  56. package/dist/{core/utils → internal}/environments/extension-environment.mjs +1 -1
  57. package/dist/{core/utils/create-file-reloader.mjs → internal/file-reloader.mjs} +10 -11
  58. package/dist/{core/utils/building → internal}/find-entrypoints.mjs +10 -75
  59. package/dist/{core → internal}/generate-wxt-dir.mjs +10 -10
  60. package/dist/internal/get-public-files.mjs +14 -0
  61. package/dist/{core/utils/building → internal}/group-entrypoints.mjs +1 -1
  62. package/dist/{core/utils → internal}/i18n.mjs +1 -1
  63. package/dist/{core/utils/building → internal}/internal-build.mjs +10 -10
  64. package/dist/{core → internal}/keyboard-shortcuts.mjs +2 -1
  65. package/dist/{core/utils → internal}/manifest.mjs +14 -14
  66. package/dist/internal/package-managers/bun.mjs +22 -0
  67. package/dist/{core → internal}/package-managers/deno.mjs +1 -1
  68. package/dist/{core → internal}/package-managers/index.mjs +1 -1
  69. package/dist/{core → internal}/package-managers/npm.mjs +11 -5
  70. package/dist/{core → internal}/package-managers/pnpm.mjs +6 -3
  71. package/dist/{core → internal}/package-managers/yarn.mjs +6 -3
  72. package/dist/{core/utils → internal}/package.mjs +3 -3
  73. package/dist/{core/utils/building → internal}/rebuild.mjs +5 -5
  74. package/dist/{core → internal}/resolve-config.mjs +22 -42
  75. package/dist/internal/runners/manual.mjs +22 -0
  76. package/dist/internal/runners/web-ext.mjs +79 -0
  77. package/dist/{core/utils/globals.mjs → internal/runtime-env-entries.mjs} +4 -4
  78. package/dist/internal/spinner.mjs +69 -0
  79. package/dist/{core/utils → internal}/syntax-errors.mjs +2 -2
  80. package/dist/{core/utils → internal}/theme-icons.mjs +3 -3
  81. package/dist/{core/utils → internal}/transform.mjs +1 -1
  82. package/dist/{core/utils → internal}/validation.mjs +1 -1
  83. package/dist/{core → internal}/wxt.mjs +24 -7
  84. package/dist/{core/utils/arrays.mjs → internal-utils/array-utils.mjs} +1 -1
  85. package/dist/{core/utils/cache.mjs → internal-utils/cache-utils.mjs} +3 -3
  86. package/dist/{core/utils/content-scripts.mjs → internal-utils/content-script-utils.mjs} +2 -2
  87. package/dist/{core/utils/content-security-policy.mjs → internal-utils/csp-utils.mjs} +1 -1
  88. package/dist/{core/utils/entrypoints.d.mts → internal-utils/entrypoint-utils.d.mts} +2 -2
  89. package/dist/{core/utils/entrypoints.mjs → internal-utils/entrypoint-utils.mjs} +2 -2
  90. package/dist/{core/utils/env.mjs → internal-utils/env-utils.mjs} +3 -3
  91. package/dist/internal-utils/eslint-utils.mjs +8 -0
  92. package/dist/{core/utils/fs.mjs → internal-utils/fs-utils.mjs} +6 -11
  93. package/dist/internal-utils/log/index.mjs +6 -0
  94. package/dist/{core/utils/log/printBuildSummary.mjs → internal-utils/log/print-build-summary.mjs} +3 -3
  95. package/dist/{core/utils/log/printFileList.mjs → internal-utils/log/print-file-list.mjs} +9 -8
  96. package/dist/{core/utils/log/printHeader.mjs → internal-utils/log/print-header.mjs} +2 -2
  97. package/dist/{core/utils/log/printTable.mjs → internal-utils/log/print-table.mjs} +1 -1
  98. package/dist/internal-utils/log/wxt-logger.mjs +32 -0
  99. package/dist/internal-utils/module-utils.mjs +32 -0
  100. package/dist/{core/utils/number.mjs → internal-utils/number-utils.mjs} +1 -1
  101. package/dist/{core/utils/paths.d.mts → internal-utils/path-utils.d.mts} +1 -1
  102. package/dist/{core/utils/paths.mjs → internal-utils/path-utils.mjs} +3 -3
  103. package/dist/{core/utils/strings.mjs → internal-utils/string-utils.mjs} +3 -3
  104. package/dist/{core/utils/time.mjs → internal-utils/time-utils.mjs} +1 -1
  105. package/dist/{core/utils/types.d.mts → internal-utils/type-utils.d.mts} +2 -1
  106. package/dist/{modules.d.mts → modules/index.d.mts} +10 -4
  107. package/dist/{modules.mjs → modules/index.mjs} +14 -5
  108. package/dist/prepare.d.mts +6 -0
  109. package/dist/prepare.mjs +11 -0
  110. package/dist/testing/wxt-vitest-plugin.mjs +7 -7
  111. package/dist/types.d.mts +97 -47
  112. package/dist/utils/content-script-context.d.mts +1 -1
  113. package/dist/utils/content-script-ui/iframe.d.mts +7 -0
  114. package/dist/utils/content-script-ui/iframe.mjs +2 -0
  115. package/dist/utils/content-script-ui/integrated.d.mts +7 -0
  116. package/dist/utils/content-script-ui/integrated.mjs +2 -0
  117. package/dist/utils/content-script-ui/shadow-root.d.mts +7 -0
  118. package/dist/utils/content-script-ui/shadow-root.mjs +2 -0
  119. package/dist/utils/content-script-ui/types.d.mts +23 -7
  120. package/dist/utils/internal/custom-events.d.mts +11 -1
  121. package/dist/utils/internal/custom-events.mjs +4 -0
  122. package/dist/version.mjs +1 -1
  123. package/dist/virtual/background-entrypoint.mjs +11 -0
  124. package/dist/{core/zip.d.mts → zip.d.mts} +2 -2
  125. package/dist/{core/zip.mjs → zip.mjs} +11 -13
  126. package/package.json +14 -15
  127. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +0 -16
  128. package/dist/core/builders/vite/plugins/globals.mjs +0 -14
  129. package/dist/core/builders/vite/plugins/index.mjs +0 -17
  130. package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +0 -56
  131. package/dist/core/define-config.d.mts +0 -6
  132. package/dist/core/index.d.mts +0 -10
  133. package/dist/core/index.mjs +0 -12
  134. package/dist/core/package-managers/bun.mjs +0 -19
  135. package/dist/core/prepare.d.mts +0 -6
  136. package/dist/core/prepare.mjs +0 -12
  137. package/dist/core/runners/manual.mjs +0 -11
  138. package/dist/core/runners/safari.mjs +0 -14
  139. package/dist/core/runners/web-ext.mjs +0 -63
  140. package/dist/core/runners/wsl.mjs +0 -14
  141. package/dist/core/utils/building/index.mjs +0 -7
  142. package/dist/core/utils/environments/browser-environment.mjs +0 -18
  143. package/dist/core/utils/eslint.mjs +0 -11
  144. package/dist/core/utils/index.d.mts +0 -2
  145. package/dist/core/utils/index.mjs +0 -3
  146. package/dist/core/utils/log/index.mjs +0 -5
  147. /package/dist/{core/utils → internal}/environments/index.mjs +0 -0
  148. /package/dist/{core/utils → internal}/virtual-modules.mjs +0 -0
@@ -1,6 +1,6 @@
1
- import { glob } from "tinyglobby";
2
1
  import { resolve } from "node:path";
3
- //#region src/modules.ts
2
+ import { glob } from "tinyglobby";
3
+ //#region src/modules/index.ts
4
4
  function defineWxtModule(module) {
5
5
  if (typeof module === "function") return { setup: module };
6
6
  return module;
@@ -102,16 +102,25 @@ function addViteConfig(wxt, viteConfig) {
102
102
  *
103
103
  * @example
104
104
  * export default defineWxtModule((wxt) => {
105
- * addWxtPlugin(wxt, 'wxt-module-analytics/client-plugin');
105
+ * addWxtPlugin(
106
+ * wxt,
107
+ * 'wxt-module-analytics/background-plugin',
108
+ * (entrypoint) => entrypoint.type === 'background',
109
+ * );
106
110
  * });
107
111
  *
108
112
  * @param wxt The wxt instance provided by the module's setup function.
109
113
  * @param plugin An import from an NPM module, or an absolute file path to the
110
114
  * file to load at runtime.
115
+ * @param apply Optional. Return `true` to load the plugin in the given
116
+ * entrypoint. Defaults to loading the plugin in every entrypoint.
111
117
  */
112
- function addWxtPlugin(wxt, plugin) {
118
+ function addWxtPlugin(wxt, plugin, apply) {
113
119
  wxt.hooks.hook("config:resolved", (wxt) => {
114
- wxt.config.plugins.push(plugin);
120
+ wxt.config.plugins.push({
121
+ module: plugin,
122
+ apply
123
+ });
115
124
  });
116
125
  }
117
126
  /**
@@ -0,0 +1,6 @@
1
+ import { InlineConfig } from "./types.mjs";
2
+
3
+ //#region src/prepare.d.ts
4
+ declare function prepare(config: InlineConfig): Promise<void>;
5
+ //#endregion
6
+ export { prepare };
@@ -0,0 +1,11 @@
1
+ import { registerWxt, wxt } from "./internal/wxt.mjs";
2
+ import { findEntrypoints } from "./internal/find-entrypoints.mjs";
3
+ import { generateWxtDir } from "./internal/generate-wxt-dir.mjs";
4
+ //#region src/prepare.ts
5
+ async function prepare(config) {
6
+ await registerWxt("build", config);
7
+ wxt.logger.info("Generating types...");
8
+ await generateWxtDir(await findEntrypoints());
9
+ }
10
+ //#endregion
11
+ export { prepare };
@@ -1,9 +1,9 @@
1
- import { tsconfigPaths } from "../core/builders/vite/plugins/tsconfigPaths.mjs";
2
- import { globals } from "../core/builders/vite/plugins/globals.mjs";
3
- import { extensionApiMock } from "../core/builders/vite/plugins/extensionApiMock.mjs";
4
- import { resolveAppConfig } from "../core/builders/vite/plugins/resolveAppConfig.mjs";
5
- import "../core/builders/vite/plugins/index.mjs";
6
- import { registerWxt, wxt } from "../core/wxt.mjs";
1
+ import { addRuntimeEnvEntries } from "../internal/builders/vite/plugins/add-runtime-env-entries.mjs";
2
+ import { extensionApiMock } from "../internal/builders/vite/plugins/extension-api-mock.mjs";
3
+ import { resolveAppConfig } from "../internal/builders/vite/plugins/resolve-app-config.mjs";
4
+ import { tsconfigPaths } from "../internal/builders/vite/plugins/tsconfig-paths.mjs";
5
+ import "../internal/builders/vite/plugins/index.mjs";
6
+ import { registerWxt, wxt } from "../internal/wxt.mjs";
7
7
  import UnimportPlugin from "unimport/unplugin";
8
8
  //#region src/testing/wxt-vitest-plugin.ts
9
9
  /**
@@ -26,7 +26,7 @@ import UnimportPlugin from "unimport/unplugin";
26
26
  async function WxtVitest(inlineConfig) {
27
27
  await registerWxt("serve", inlineConfig ?? {});
28
28
  const plugins = [
29
- globals(wxt.config),
29
+ addRuntimeEnvEntries(wxt.config),
30
30
  tsconfigPaths(wxt.config),
31
31
  resolveAppConfig(wxt.config),
32
32
  extensionApiMock(wxt.config)
package/dist/types.d.mts CHANGED
@@ -19,13 +19,13 @@
19
19
  * });
20
20
  * });
21
21
  */import { ContentScriptContext } from "./utils/content-script-context.mjs";
22
- import { ManifestContentScript } from "./core/utils/types.mjs";
22
+ import { ManifestContentScript } from "./internal-utils/type-utils.mjs";
23
23
  import { Hookable, NestedHooks } from "hookable";
24
24
  import { Import, UnimportOptions } from "unimport";
25
- import { PluginVisualizerOptions } from "@aklinker1/rollup-plugin-visualizer";
26
25
  import * as Nypm from "nypm";
27
26
  import { ResolvedConfig } from "c12";
28
27
  import { LogLevel } from "consola";
28
+ import { PluginVisualizerOptions } from "@aklinker1/rollup-plugin-visualizer";
29
29
  import { Browser } from "@wxt-dev/browser";
30
30
  import * as vite from "vite";
31
31
 
@@ -544,8 +544,8 @@ interface WxtHooks {
544
544
  * Called when WXT has created Vite's config for the dev server. Useful if you
545
545
  * want to add plugins or update the vite config per entrypoint group.
546
546
  *
547
- * @param viteConfig The config that will be used to build the entrypoints.
548
- * Can be updated by reference.
547
+ * @param config The config that will be used to build the entrypoints. Can be
548
+ * updated by reference.
549
549
  */
550
550
  'vite:devServer:extendConfig': (config: vite.InlineConfig) => HookResult;
551
551
  }
@@ -634,6 +634,17 @@ interface Logger {
634
634
  success(...args: any[]): void;
635
635
  level: LogLevel;
636
636
  }
637
+ /**
638
+ * The logger available at `wxt.logger` and `wxt.config.logger`. Extends
639
+ * {@link Logger} with a `warnOnce` which only logs a message once per process.
640
+ */
641
+ interface WxtLogger extends Logger {
642
+ /**
643
+ * Same as {@link Logger.warn}, but only logs a given message once per process,
644
+ * even if called multiple times with the same arguments.
645
+ */
646
+ warnOnce(...args: any[]): void;
647
+ }
637
648
  interface BaseEntrypointOptions {
638
649
  /**
639
650
  * List of target browsers to include this entrypoint in. Defaults to being
@@ -672,7 +683,7 @@ interface BaseScriptEntrypointOptions extends BaseEntrypointOptions {
672
683
  * the default IIFE variable name may conflict with an existing variable on
673
684
  * the target page. This applies to content scripts with world=MAIN, and
674
685
  * others, such as unlisted scripts, that could be dynamically injected into
675
- * the page with a <script> tag.
686
+ * the page with a `<script>` tag.
676
687
  *
677
688
  * Available options:
678
689
  *
@@ -1077,7 +1088,7 @@ interface ConfigEnv {
1077
1088
  /**
1078
1089
  * Manifest version passed in from the CLI via the `--mv2` or `--mv3` flags.
1079
1090
  * When not passed, it depends on the target browser. See [the
1080
- * guide](https://wxt.dev/guide/key-concepts/multiple-browsers.html#target-manifest-version)
1091
+ * guide](https://wxt.dev/guide/essentials/target-different-browsers.html#target-a-manifest-version)
1081
1092
  * for more details.
1082
1093
  */
1083
1094
  manifestVersion: 2 | 3;
@@ -1122,21 +1133,6 @@ interface WebExtConfig {
1122
1133
  * default_directory: "/my/custom/dir",
1123
1134
  * },
1124
1135
  * }
1125
- *
1126
- * @default
1127
- * // Enable dev mode and allow content script sourcemaps
1128
- * {
1129
- * devtools: {
1130
- * synced_preferences_sync_disabled: {
1131
- * skipContentScripts: false,
1132
- * },
1133
- * }
1134
- * extensions: {
1135
- * ui: {
1136
- * developer_mode: true,
1137
- * },
1138
- * }
1139
- * }
1140
1136
  */
1141
1137
  chromiumPref?: Record<string, any>;
1142
1138
  /**
@@ -1299,7 +1295,7 @@ interface WxtHooks {
1299
1295
  * Called once all entrypoints have been grouped into their build groups.
1300
1296
  *
1301
1297
  * @param wxt The configured WXT object
1302
- * @param entrypoints The list of groups to build in each build step
1298
+ * @param groups The list of groups to build in each build step
1303
1299
  */
1304
1300
  'entrypoints:grouped': (wxt: Wxt, groups: EntrypointGroup[]) => HookResult;
1305
1301
  /**
@@ -1307,7 +1303,7 @@ interface WxtHooks {
1307
1303
  * reference to add or remove public files.
1308
1304
  *
1309
1305
  * @param wxt The configured WXT object
1310
- * @param entrypoints The list of files that will be copied into the output
1306
+ * @param files The list of files that will be copied into the output
1311
1307
  * directory
1312
1308
  */
1313
1309
  'build:publicAssets': (wxt: Wxt, files: ResolvedPublicFile[]) => HookResult;
@@ -1381,16 +1377,47 @@ interface Wxt {
1381
1377
  hooks: Hookable<WxtHooks>;
1382
1378
  /** Alias for `wxt.hooks.hook(...)`. */
1383
1379
  hook: Hookable<WxtHooks>['hook'];
1384
- /** Alias for config.logger */
1385
- logger: Logger;
1380
+ /** Alias for `config.logger`. */
1381
+ logger: WxtLogger;
1386
1382
  /** Reload config file and update `wxt.config` with the result. */
1387
1383
  reloadConfig: () => Promise<void>;
1388
1384
  /** Package manager utilities. */
1389
1385
  pm: WxtPackageManager;
1390
1386
  /** If the dev server was started, it will be available. */
1391
1387
  server?: WxtDevServer;
1392
- /** The module in charge of executing all the build steps. */
1388
+ /**
1389
+ * The module in charge of executing all the build steps.
1390
+ *
1391
+ * To override the entire builder process, set this value in a module's
1392
+ * `setup` function or during the `config:resolved` hook.
1393
+ *
1394
+ * ```ts
1395
+ * wxt.build = new MyBuilder(wxt.config);
1396
+ * ```
1397
+ */
1393
1398
  builder: WxtBuilder;
1399
+ /**
1400
+ * Service responsible for discovering entrypoints in a project.
1401
+ *
1402
+ * To override how entrypoints are discovered, set this value in a module's
1403
+ * `setup` function or during the `config:resolved` hook.
1404
+ *
1405
+ * ```ts
1406
+ * wxt.entrypointFinder = new MyEntrypointFinder(wxt.config);
1407
+ * ```
1408
+ */
1409
+ entrypointFinder: EntrypointFinder;
1410
+ /**
1411
+ * Service responsible for opening the browser during dev mode.
1412
+ *
1413
+ * To override how the browser is opened, set this value in a module's `setup`
1414
+ * function or during the `config:resolved` hook.
1415
+ *
1416
+ * ```ts
1417
+ * wxt.runner = new MyRunner(wxt.config);
1418
+ * ```
1419
+ */
1420
+ runner: ExtensionRunner;
1394
1421
  }
1395
1422
  interface ResolvedConfig$1 {
1396
1423
  root: string;
@@ -1433,11 +1460,12 @@ interface ResolvedConfig$1 {
1433
1460
  targetBrowsers: TargetBrowser[];
1434
1461
  manifestVersion: TargetManifestVersion;
1435
1462
  env: ConfigEnv;
1436
- logger: Logger;
1463
+ logger: WxtLogger;
1437
1464
  imports: WxtResolvedUnimportOptions;
1438
1465
  manifest: UserManifest;
1439
1466
  fsCache: FsCache;
1440
1467
  webExt: ResolvedConfig<WebExtConfig>;
1468
+ /** @deprecated Use `wxt.runner` instead of `wxt.config.runner` */
1441
1469
  runner: ExtensionRunner;
1442
1470
  zip: {
1443
1471
  name?: string;
@@ -1507,13 +1535,27 @@ interface ResolvedConfig$1 {
1507
1535
  builtinModules: WxtModule<any>[];
1508
1536
  userModules: WxtModuleWithMetadata<any>[];
1509
1537
  /**
1510
- * An array of string to import plugins from. These paths should be resolvable
1511
- * by vite, and they should `export default defineWxtPlugin(...)`.
1538
+ * Plugins registered via `addWxtPlugin`. Each entry's `module` should be
1539
+ * resolvable by vite, and should `export default defineWxtPlugin(...)`. An
1540
+ * optional `apply` function restricts which entrypoints the plugin loads in.
1512
1541
  *
1513
1542
  * @example
1514
- * ['@wxt-dev/module-vue/plugin', 'wxt-module-google-analytics/plugin'];
1543
+ * [{ module: '@wxt-dev/module-vue/plugin' }];
1544
+ */
1545
+ plugins: Array<string | WxtPluginEntry>;
1546
+ }
1547
+ /**
1548
+ * A plugin registered via `addWxtPlugin`, along with an optional `apply`
1549
+ * function controlling which entrypoints it's loaded in.
1550
+ */
1551
+ interface WxtPluginEntry {
1552
+ /** Import path or absolute file path to the plugin module. */
1553
+ module: string;
1554
+ /**
1555
+ * Return `true` to include the plugin in this entrypoint. When omitted, the
1556
+ * plugin is included in every entrypoint.
1515
1557
  */
1516
- plugins: string[];
1558
+ apply?: (entrypoint: Entrypoint) => boolean;
1517
1559
  }
1518
1560
  interface FsCache {
1519
1561
  set(key: string, value: string): Promise<void>;
@@ -1523,31 +1565,32 @@ interface ExtensionRunner {
1523
1565
  openBrowser(): Promise<void>;
1524
1566
  closeBrowser?(): Promise<void>;
1525
1567
  /** Whether or not this runner actually opens the browser. */
1526
- canOpen?(): boolean;
1568
+ canOpen?(): Promise<boolean>;
1527
1569
  }
1528
1570
  type EslintGlobalsPropValue = boolean | 'readonly' | 'readable' | 'writable' | 'writeable';
1571
+ type EslintConfigVersion = 8 | 9;
1529
1572
  interface Eslintrc {
1530
1573
  /**
1531
- * When true, generates a file that can be used by ESLint to know which
1532
- * variables are valid globals.
1574
+ * Determines if and in what format a config file will be generated to inform
1575
+ * ESLint of unimport globals.
1533
1576
  *
1534
- * - `'auto'`: Check if eslint is installed, and if it is, generate a compatible
1535
- * config file.
1536
- * - `true`: Same as `'auto'`.
1537
- * - `false`: Don't generate the file.
1538
- * - `8`: Generate a config file compatible with ESLint 8.
1539
- * - `9`: Generate a config file compatible with ESLint 9.
1577
+ * - `true`: If eslint is installed, generate a compatible config file based on
1578
+ * the installed version.
1579
+ * - `false`: Never generate the file.
1580
+ * - `8`: Generate an eslintrc file compatible with ESLint &lte; 8.
1581
+ * - `9`: Generate a flat config file compatible with ESLint &gte; 9.
1582
+ * - `'auto'` (Deprecated): Same as `true`.
1540
1583
  *
1541
- * @default 'auto'
1584
+ * @default true
1542
1585
  */
1543
- enabled?: 'auto' | boolean | 8 | 9;
1586
+ enabled?: boolean | 'auto' | EslintConfigVersion;
1544
1587
  /**
1545
1588
  * File path to save the generated eslint config.
1546
1589
  *
1547
1590
  * Default depends on version of ESLint used:
1548
1591
  *
1549
- * - 9 and above: './.wxt/eslint-auto-imports.mjs'
1550
- * - 8 and below: './.wxt/eslintrc-auto-import.json'
1592
+ * - &gte; 9: './.wxt/eslint-auto-imports.mjs'
1593
+ * - &lte; 8: './.wxt/eslintrc-auto-import.json'
1551
1594
  */
1552
1595
  filePath?: string;
1553
1596
  /** @default true */
@@ -1555,7 +1598,7 @@ interface Eslintrc {
1555
1598
  }
1556
1599
  interface ResolvedEslintrc {
1557
1600
  /** False if disabled, otherwise the major version of ESLint installed */
1558
- enabled: false | 8 | 9;
1601
+ enabled: false | EslintConfigVersion;
1559
1602
  /** Absolute path */
1560
1603
  filePath: string;
1561
1604
  globalsPropValue: EslintGlobalsPropValue;
@@ -1567,7 +1610,7 @@ type WxtUnimportOptions = Partial<UnimportOptions> & {
1567
1610
  * extended, fixes these lint errors.
1568
1611
  *
1569
1612
  * See
1570
- * [https://wxt.dev/guide/key-concepts/auto-imports.html#eslint](https://wxt.dev/guide/key-concepts/auto-imports.html#eslint)
1613
+ * [https://wxt.dev/guide/essentials/config/auto-imports.html#eslint](https://wxt.dev/guide/essentials/config/auto-imports.html#eslint)
1571
1614
  */
1572
1615
  eslintrc?: Eslintrc;
1573
1616
  };
@@ -1700,5 +1743,12 @@ interface WxtDirFileEntry {
1700
1743
  /** Set to `true` to add a reference to this file in `.wxt/wxt.d.ts`. */
1701
1744
  tsReference?: boolean;
1702
1745
  }
1746
+ interface EntrypointFinder {
1747
+ /**
1748
+ * @returns A list of file paths (absolute or relative to
1749
+ * `wxt.config.rootDir`) to load as entrypoints for.
1750
+ */
1751
+ findEntrypoints(): Promise<EntrypointInfo[]> | EntrypointInfo[];
1752
+ }
1703
1753
  //#endregion
1704
- export { BackgroundDefinition, BackgroundEntrypoint, BackgroundEntrypointOptions, BaseContentScriptEntrypointOptions, BaseEntrypoint, BaseEntrypointOptions, BaseScriptEntrypointOptions, BuildOutput, BuildStepOutput, ConfigEnv, ContentScriptDefinition, ContentScriptEntrypoint, CopiedPublicFile, Dependency, Entrypoint, EntrypointGroup, EntrypointInfo, EslintGlobalsPropValue, Eslintrc, ExtensionRunner, FirefoxDataCollectionPermissions, FirefoxDataCollectionType, FsCache, GeneratedPublicFile, GenericEntrypoint, HookResult, InlineConfig, IsolatedWorldContentScriptDefinition, IsolatedWorldContentScriptEntrypointOptions, Logger, MainWorldContentScriptDefinition, MainWorldContentScriptEntrypointOptions, OnContentScriptStopped, OptionsEntrypoint, OptionsEntrypointOptions, OutputAsset, OutputChunk, OutputFile, PerBrowserMap, PerBrowserOption, PopupEntrypoint, PopupEntrypointOptions, PrepareTsconfigs, PublicPathEntry, ReloadContentScriptPayload, ResolvedBasePublicFile, ResolvedConfig$1 as ResolvedConfig, ResolvedEslintrc, ResolvedPerBrowserOptions, ResolvedPublicFile, ServerInfo, SidepanelEntrypoint, SidepanelEntrypointOptions, TargetBrowser, TargetManifestVersion, ThemeIcon, UnlistedScriptDefinition, UnlistedScriptEntrypoint, UserConfig, UserManifest, UserManifestFn, WebExtConfig, Wxt, WxtBuilder, WxtBuilderServer, WxtCommand, WxtDevServer, WxtDirEntry, WxtDirFileEntry, WxtDirTypeReferenceEntry, WxtHooks, WxtModule, WxtModuleOptions, WxtModuleSetup, WxtModuleWithMetadata, WxtPackageManager, WxtPlugin, WxtResolvedUnimportOptions, WxtUnimportOptions, WxtViteConfig };
1754
+ export { BackgroundDefinition, BackgroundEntrypoint, BackgroundEntrypointOptions, BaseContentScriptEntrypointOptions, BaseEntrypoint, BaseEntrypointOptions, BaseScriptEntrypointOptions, BuildOutput, BuildStepOutput, ConfigEnv, ContentScriptDefinition, ContentScriptEntrypoint, CopiedPublicFile, Dependency, Entrypoint, EntrypointFinder, EntrypointGroup, EntrypointInfo, EslintConfigVersion, EslintGlobalsPropValue, Eslintrc, ExtensionRunner, FirefoxDataCollectionPermissions, FirefoxDataCollectionType, FsCache, GeneratedPublicFile, GenericEntrypoint, HookResult, InlineConfig, IsolatedWorldContentScriptDefinition, IsolatedWorldContentScriptEntrypointOptions, Logger, MainWorldContentScriptDefinition, MainWorldContentScriptEntrypointOptions, OnContentScriptStopped, OptionsEntrypoint, OptionsEntrypointOptions, OutputAsset, OutputChunk, OutputFile, PerBrowserMap, PerBrowserOption, PopupEntrypoint, PopupEntrypointOptions, PrepareTsconfigs, PublicPathEntry, ReloadContentScriptPayload, ResolvedBasePublicFile, ResolvedConfig$1 as ResolvedConfig, ResolvedEslintrc, ResolvedPerBrowserOptions, ResolvedPublicFile, ServerInfo, SidepanelEntrypoint, SidepanelEntrypointOptions, TargetBrowser, TargetManifestVersion, ThemeIcon, UnlistedScriptDefinition, UnlistedScriptEntrypoint, UserConfig, UserManifest, UserManifestFn, WebExtConfig, Wxt, WxtBuilder, WxtBuilderServer, WxtCommand, WxtDevServer, WxtDirEntry, WxtDirFileEntry, WxtDirTypeReferenceEntry, WxtHooks, WxtLogger, WxtModule, WxtModuleOptions, WxtModuleSetup, WxtModuleWithMetadata, WxtPackageManager, WxtPlugin, WxtPluginEntry, WxtResolvedUnimportOptions, WxtUnimportOptions, WxtViteConfig };
@@ -141,4 +141,4 @@ interface WxtWindowEventMap extends WindowEventMap {
141
141
  'wxt:locationchange': WxtLocationChangeEvent;
142
142
  }
143
143
  //#endregion
144
- export { ContentScriptContext, WxtWindowEventMap };
144
+ export { ContentScriptContext, type WxtLocationChangeEvent, WxtWindowEventMap };
@@ -6,6 +6,8 @@ import * as _$wxt_browser0 from "wxt/browser";
6
6
  /**
7
7
  * Create a content script UI using an iframe.
8
8
  *
9
+ * @param options - Iframe options. See {@link ContentScriptUiOptions} for shared
10
+ * positioning, anchoring, `append`, and removal options.
9
11
  * @see https://wxt.dev/guide/essentials/content-scripts.html#iframe
10
12
  */
11
13
  declare function createIframeUi<TMounted>(ctx: ContentScriptContext, options: IframeContentScriptUiOptions<TMounted>): IframeContentScriptUi<TMounted>;
@@ -15,6 +17,11 @@ interface IframeContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
15
17
  /** A wrapper div that assists in positioning. */
16
18
  wrapper: HTMLDivElement;
17
19
  }
20
+ /**
21
+ * {@inheritDoc wxt/utils/content-script-ui/types!ContentScriptUiOptions}
22
+ *
23
+ * @interface
24
+ */
18
25
  type IframeContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
19
26
  /**
20
27
  * The path to the HTML page that will be shown in the iframe. This string
@@ -5,6 +5,8 @@ import { browser } from "wxt/browser";
5
5
  /**
6
6
  * Create a content script UI using an iframe.
7
7
  *
8
+ * @param options - Iframe options. See {@link ContentScriptUiOptions} for shared
9
+ * positioning, anchoring, `append`, and removal options.
8
10
  * @see https://wxt.dev/guide/essentials/content-scripts.html#iframe
9
11
  */
10
12
  function createIframeUi(ctx, options) {
@@ -5,6 +5,8 @@ import { ContentScriptUi, ContentScriptUiOptions } from "./types.mjs";
5
5
  /**
6
6
  * Create a content script UI without any isolation.
7
7
  *
8
+ * @param options - Integrated UI options. See {@link ContentScriptUiOptions} for
9
+ * shared positioning, anchoring, `append`, and removal options.
8
10
  * @see https://wxt.dev/guide/essentials/content-scripts.html#integrated
9
11
  */
10
12
  declare function createIntegratedUi<TMounted>(ctx: ContentScriptContext, options: IntegratedContentScriptUiOptions<TMounted>): IntegratedContentScriptUi<TMounted>;
@@ -17,6 +19,11 @@ interface IntegratedContentScriptUi<TMounted> extends ContentScriptUi<TMounted>
17
19
  /** A wrapper div that assists in positioning. */
18
20
  wrapper: HTMLElement;
19
21
  }
22
+ /**
23
+ * {@inheritDoc wxt/utils/content-script-ui/types!ContentScriptUiOptions}
24
+ *
25
+ * @interface
26
+ */
20
27
  type IntegratedContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
21
28
  /**
22
29
  * Tag used to create the wrapper element.
@@ -3,6 +3,8 @@ import { applyPosition, createMountFunctions, mountUi } from "./shared.mjs";
3
3
  /**
4
4
  * Create a content script UI without any isolation.
5
5
  *
6
+ * @param options - Integrated UI options. See {@link ContentScriptUiOptions} for
7
+ * shared positioning, anchoring, `append`, and removal options.
6
8
  * @see https://wxt.dev/guide/essentials/content-scripts.html#integrated
7
9
  */
8
10
  function createIntegratedUi(ctx, options) {
@@ -8,6 +8,8 @@ import { ContentScriptUi, ContentScriptUiOptions } from "./types.mjs";
8
8
  *
9
9
  * > This function is async because it has to load the CSS via a network call.
10
10
  *
11
+ * @param options - Shadow root options. See {@link ContentScriptUiOptions} for
12
+ * shared positioning, anchoring, `append`, and removal options.
11
13
  * @see https://wxt.dev/guide/essentials/content-scripts.html#shadow-root
12
14
  */
13
15
  declare function createShadowRootUi<TMounted>(ctx: ContentScriptContext, options: ShadowRootContentScriptUiOptions<TMounted>): Promise<ShadowRootContentScriptUi<TMounted>>;
@@ -26,6 +28,11 @@ interface ShadowRootContentScriptUi<TMounted> extends ContentScriptUi<TMounted>
26
28
  /** The shadow root performing the isolation. */
27
29
  shadow: ShadowRoot;
28
30
  }
31
+ /**
32
+ * {@inheritDoc wxt/utils/content-script-ui/types!ContentScriptUiOptions}
33
+ *
34
+ * @interface
35
+ */
29
36
  type ShadowRootContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
30
37
  /**
31
38
  * The name of the custom component used to host the ShadowRoot. Must be
@@ -11,6 +11,8 @@ import { createIsolatedElement } from "@webext-core/isolated-element";
11
11
  *
12
12
  * > This function is async because it has to load the CSS via a network call.
13
13
  *
14
+ * @param options - Shadow root options. See {@link ContentScriptUiOptions} for
15
+ * shared positioning, anchoring, `append`, and removal options.
14
16
  * @see https://wxt.dev/guide/essentials/content-scripts.html#shadow-root
15
17
  */
16
18
  async function createShadowRootUi(ctx, options) {
@@ -3,6 +3,13 @@
3
3
  interface ContentScriptUi<TMounted> extends MountFunctions {
4
4
  mounted: TMounted | undefined;
5
5
  }
6
+ /**
7
+ * Options shared by integrated, shadow root, and iframe UIs.
8
+ *
9
+ * `position` selects `"inline"`, `"overlay"`, or `"modal"` positioning.
10
+ * `zIndex` controls the positioning element's stacking level for overlays and
11
+ * modals. `alignment` is available for overlays.
12
+ */
6
13
  type ContentScriptUiOptions<TMounted> = ContentScriptPositioningOptions & ContentScriptAnchoredOptions & {
7
14
  /**
8
15
  * Callback called before the UI is removed from the webpage. Use to cleanup
@@ -20,19 +27,24 @@ type ContentScriptOverlayAlignment = 'top-left' | 'top-right' | 'bottom-left' |
20
27
  * modes](https://wxt.dev/content-script-ui-append.png)
21
28
  */
22
29
  type ContentScriptAppendMode = 'last' | 'first' | 'replace' | 'before' | 'after' | ((anchor: Element, ui: Element) => void);
30
+ /** Inline positioning does not support `zIndex` or `alignment`. */
23
31
  interface ContentScriptInlinePositioningOptions {
32
+ /** Choose between `"inline"`, `"overlay"`, or `"modal"` positioning. */
24
33
  position: 'inline';
34
+ zIndex?: never;
35
+ alignment?: never;
25
36
  }
26
37
  interface ContentScriptOverlayPositioningOptions {
27
38
  position: 'overlay';
28
39
  /**
29
- * The `z-index` used on the `wrapper` element. Set to a positive number to
40
+ * The `z-index` used on the positioning element. Set to a positive number to
30
41
  * show your UI over website content.
31
42
  */
32
43
  zIndex?: number;
33
44
  /**
34
- * When using `type: "overlay"`, the mounted element is 0px by 0px in size.
35
- * Alignment specifies which corner is aligned with that 0x0 pixel space.
45
+ * When using `position: "overlay"`, the mounted element is 0px by 0px in
46
+ * size. Alignment specifies which corner is aligned with that 0x0 pixel
47
+ * space.
36
48
  *
37
49
  * [Visualization of alignment
38
50
  * options](https://wxt.dev/content-script-ui-alignment.png)
@@ -41,13 +53,17 @@ interface ContentScriptOverlayPositioningOptions {
41
53
  */
42
54
  alignment?: ContentScriptOverlayAlignment;
43
55
  }
56
+ /**
57
+ * Modal positioning options.
58
+ *
59
+ * @property zIndex The `z-index` used on the `shadowHost` element. Set to a
60
+ * positive number to show your UI over website content.
61
+ * @property alignment Only available when `position` is `"overlay"`.
62
+ */
44
63
  interface ContentScriptModalPositioningOptions {
45
64
  position: 'modal';
46
- /**
47
- * The `z-index` used on the `shadowHost`. Set to a positive number to show
48
- * your UI over website content.
49
- */
50
65
  zIndex?: number;
66
+ alignment?: never;
51
67
  }
52
68
  /**
53
69
  * Choose between `"inline"`, `"overlay"`, or `"modal"` positions.
@@ -1,9 +1,19 @@
1
1
  //#region src/utils/internal/custom-events.d.ts
2
+ /**
3
+ * Fired on `window` as `wxt:locationchange` when a content script detects a
4
+ * same-document URL change.
5
+ */
2
6
  declare class WxtLocationChangeEvent extends Event {
7
+ /** The URL after the change. */
3
8
  readonly newUrl: URL;
9
+ /** The URL before the change. */
4
10
  readonly oldUrl: URL;
5
11
  static EVENT_NAME: string;
6
- constructor(newUrl: URL, oldUrl: URL);
12
+ constructor(/** The URL after the change. */
13
+
14
+ newUrl: URL, /** The URL before the change. */
15
+
16
+ oldUrl: URL);
7
17
  }
8
18
  //#endregion
9
19
  export { WxtLocationChangeEvent };
@@ -1,5 +1,9 @@
1
1
  import { browser } from "wxt/browser";
2
2
  //#region src/utils/internal/custom-events.ts
3
+ /**
4
+ * Fired on `window` as `wxt:locationchange` when a content script detects a
5
+ * same-document URL change.
6
+ */
3
7
  var WxtLocationChangeEvent = class WxtLocationChangeEvent extends Event {
4
8
  static EVENT_NAME = getUniqueEventName("wxt:locationchange");
5
9
  constructor(newUrl, oldUrl) {
package/dist/version.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/version.ts
2
- const version = "0.21.3";
2
+ const version = "0.21.5";
3
3
  //#endregion
4
4
  export { version };
@@ -69,8 +69,19 @@ async function reloadContentScriptMv3({ registration, contentScript }) {
69
69
  if (registration === "runtime") await reloadRuntimeContentScriptMv3(contentScript);
70
70
  else await reloadManifestContentScriptMv3(contentScript);
71
71
  }
72
+ /**
73
+ * Reloads of one script run one after another. Two reloads that overlap can
74
+ * both read an empty registration list and both register, and the second
75
+ * registration throws "Duplicate script ID".
76
+ */
77
+ const manifestReloads = /* @__PURE__ */ new Map();
72
78
  async function reloadManifestContentScriptMv3(contentScript) {
73
79
  const id = `wxt:${contentScript.js[0]}`;
80
+ const reload = (manifestReloads.get(id) ?? Promise.resolve()).then(() => reloadManifestContentScriptNow(id, contentScript));
81
+ manifestReloads.set(id, reload.catch(() => {}));
82
+ return reload;
83
+ }
84
+ async function reloadManifestContentScriptNow(id, contentScript) {
74
85
  logger.log("Reloading content script:", contentScript);
75
86
  const registered = await browser.scripting.getRegisteredContentScripts();
76
87
  logger.debug("Existing scripts:", registered);
@@ -1,6 +1,6 @@
1
- import { InlineConfig } from "../types.mjs";
1
+ import { InlineConfig } from "./types.mjs";
2
2
 
3
- //#region src/core/zip.d.ts
3
+ //#region src/zip.d.ts
4
4
  /**
5
5
  * Build and zip the extension for distribution.
6
6
  *
@@ -1,19 +1,17 @@
1
- import { normalizePath } from "./utils/paths.mjs";
2
- import "./utils/index.mjs";
3
- import { safeFilename } from "./utils/strings.mjs";
4
- import { registerWxt, wxt } from "./wxt.mjs";
5
- import { findEntrypoints } from "./utils/building/find-entrypoints.mjs";
6
- import { formatDuration } from "./utils/time.mjs";
7
- import { printFileList } from "./utils/log/printFileList.mjs";
8
- import "./utils/log/index.mjs";
9
- import { getPackageJson } from "./utils/package.mjs";
10
- import { internalBuild } from "./utils/building/internal-build.mjs";
11
- import "./utils/building/index.mjs";
1
+ import { normalizePath } from "./internal-utils/path-utils.mjs";
2
+ import { safeFilename } from "./internal-utils/string-utils.mjs";
3
+ import { formatDuration } from "./internal-utils/time-utils.mjs";
4
+ import { registerWxt, wxt } from "./internal/wxt.mjs";
5
+ import { findEntrypoints } from "./internal/find-entrypoints.mjs";
6
+ import { printFileList } from "./internal-utils/log/print-file-list.mjs";
7
+ import "./internal-utils/log/index.mjs";
8
+ import { getPackageJson } from "./internal/package.mjs";
9
+ import { internalBuild } from "./internal/internal-build.mjs";
12
10
  import { mkdir, readFile, writeFile } from "node:fs/promises";
13
- import { glob } from "tinyglobby";
14
11
  import path from "node:path";
12
+ import { glob } from "tinyglobby";
15
13
  import { createZip } from "@aklinker1/zero-zip";
16
- //#region src/core/zip.ts
14
+ //#region src/zip.ts
17
15
  /**
18
16
  * Build and zip the extension for distribution.
19
17
  *