wxt 0.20.18 → 0.20.19

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 (141) hide show
  1. package/bin/wxt-publish-extension.mjs +4 -3
  2. package/dist/browser.d.mts +7 -6
  3. package/dist/browser.mjs +6 -5
  4. package/dist/builtin-modules/index.mjs +1 -3
  5. package/dist/builtin-modules/unimport.mjs +1 -3
  6. package/dist/cli/cli-utils.mjs +5 -6
  7. package/dist/cli/commands.mjs +1 -3
  8. package/dist/cli/index.mjs +1 -3
  9. package/dist/core/build.d.mts +9 -8
  10. package/dist/core/build.mjs +10 -11
  11. package/dist/core/builders/vite/index.mjs +27 -25
  12. package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +1 -3
  13. package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +6 -6
  14. package/dist/core/builders/vite/plugins/defineImportMeta.mjs +3 -4
  15. package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +33 -25
  16. package/dist/core/builders/vite/plugins/devServerGlobals.mjs +3 -3
  17. package/dist/core/builders/vite/plugins/download.mjs +15 -11
  18. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +2 -6
  19. package/dist/core/builders/vite/plugins/extensionApiMock.mjs +13 -8
  20. package/dist/core/builders/vite/plugins/globals.mjs +1 -3
  21. package/dist/core/builders/vite/plugins/iifeAnonymous.mjs +1 -2
  22. package/dist/core/builders/vite/plugins/iifeFooter.mjs +6 -6
  23. package/dist/core/builders/vite/plugins/index.mjs +18 -19
  24. package/dist/core/builders/vite/plugins/noopBackground.mjs +14 -9
  25. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +10 -12
  26. package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +14 -10
  27. package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +15 -13
  28. package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +1 -2
  29. package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +22 -17
  30. package/dist/core/clean.d.mts +7 -7
  31. package/dist/core/clean.mjs +6 -7
  32. package/dist/core/create-server.d.mts +6 -5
  33. package/dist/core/create-server.mjs +12 -11
  34. package/dist/core/define-config.mjs +1 -2
  35. package/dist/core/define-web-ext-config.d.mts +3 -4
  36. package/dist/core/define-web-ext-config.mjs +4 -7
  37. package/dist/core/generate-wxt-dir.mjs +8 -9
  38. package/dist/core/index.mjs +10 -11
  39. package/dist/core/initialize.mjs +10 -11
  40. package/dist/core/keyboard-shortcuts.mjs +2 -6
  41. package/dist/core/package-managers/bun.mjs +1 -3
  42. package/dist/core/package-managers/deno.mjs +1 -2
  43. package/dist/core/package-managers/index.mjs +1 -3
  44. package/dist/core/package-managers/npm.mjs +3 -5
  45. package/dist/core/package-managers/pnpm.mjs +1 -3
  46. package/dist/core/package-managers/yarn.mjs +1 -3
  47. package/dist/core/prepare.mjs +1 -3
  48. package/dist/core/resolve-config.mjs +20 -23
  49. package/dist/core/runners/index.mjs +1 -3
  50. package/dist/core/runners/manual.mjs +2 -6
  51. package/dist/core/runners/safari.mjs +3 -4
  52. package/dist/core/runners/web-ext.mjs +2 -6
  53. package/dist/core/runners/wsl.mjs +3 -4
  54. package/dist/core/utils/arrays.mjs +4 -11
  55. package/dist/core/utils/building/build-entrypoints.mjs +8 -9
  56. package/dist/core/utils/building/detect-dev-changes.mjs +21 -13
  57. package/dist/core/utils/building/find-entrypoints.mjs +16 -11
  58. package/dist/core/utils/building/group-entrypoints.mjs +3 -4
  59. package/dist/core/utils/building/index.mjs +7 -8
  60. package/dist/core/utils/building/internal-build.mjs +13 -13
  61. package/dist/core/utils/building/rebuild.mjs +10 -10
  62. package/dist/core/utils/cache.mjs +6 -8
  63. package/dist/core/utils/constants.mjs +3 -4
  64. package/dist/core/utils/content-scripts.mjs +3 -4
  65. package/dist/core/utils/content-security-policy.mjs +2 -5
  66. package/dist/core/utils/entrypoints.mjs +6 -10
  67. package/dist/core/utils/env.mjs +2 -6
  68. package/dist/core/utils/environments/browser-environment.mjs +1 -3
  69. package/dist/core/utils/environments/environment.mjs +1 -2
  70. package/dist/core/utils/environments/extension-environment.mjs +1 -3
  71. package/dist/core/utils/environments/index.mjs +3 -4
  72. package/dist/core/utils/eslint.mjs +1 -2
  73. package/dist/core/utils/fs.mjs +23 -14
  74. package/dist/core/utils/globals.mjs +1 -2
  75. package/dist/core/utils/i18n.mjs +1 -2
  76. package/dist/core/utils/index.mjs +2 -3
  77. package/dist/core/utils/log/index.mjs +5 -6
  78. package/dist/core/utils/log/printBuildSummary.mjs +1 -3
  79. package/dist/core/utils/log/printFileList.mjs +3 -5
  80. package/dist/core/utils/log/printHeader.mjs +1 -3
  81. package/dist/core/utils/log/printTable.mjs +1 -2
  82. package/dist/core/utils/manifest.mjs +23 -31
  83. package/dist/core/utils/minimatch-multiple.mjs +5 -7
  84. package/dist/core/utils/network.mjs +3 -5
  85. package/dist/core/utils/number.mjs +1 -2
  86. package/dist/core/utils/package.mjs +3 -5
  87. package/dist/core/utils/paths.d.mts +2 -2
  88. package/dist/core/utils/paths.mjs +7 -9
  89. package/dist/core/utils/strings.mjs +4 -7
  90. package/dist/core/utils/syntax-errors.mjs +1 -3
  91. package/dist/core/utils/time.mjs +2 -5
  92. package/dist/core/utils/transform.mjs +8 -6
  93. package/dist/core/utils/validation.mjs +1 -2
  94. package/dist/core/utils/virtual-modules.mjs +9 -15
  95. package/dist/core/utils/wsl.mjs +2 -6
  96. package/dist/core/wxt.mjs +7 -9
  97. package/dist/core/zip.d.mts +1 -0
  98. package/dist/core/zip.mjs +11 -10
  99. package/dist/index.d.mts +0 -1
  100. package/dist/index.mjs +1 -2
  101. package/dist/modules.d.mts +64 -61
  102. package/dist/modules.mjs +70 -66
  103. package/dist/testing/fake-browser.mjs +1 -2
  104. package/dist/testing/index.mjs +1 -2
  105. package/dist/testing/wxt-vitest-plugin.d.mts +4 -2
  106. package/dist/testing/wxt-vitest-plugin.mjs +5 -5
  107. package/dist/types.d.mts +455 -435
  108. package/dist/utils/app-config.mjs +1 -3
  109. package/dist/utils/content-script-context.d.mts +49 -39
  110. package/dist/utils/content-script-context.mjs +36 -31
  111. package/dist/utils/content-script-ui/iframe.d.mts +12 -13
  112. package/dist/utils/content-script-ui/iframe.mjs +1 -3
  113. package/dist/utils/content-script-ui/integrated.d.mts +8 -7
  114. package/dist/utils/content-script-ui/integrated.mjs +1 -3
  115. package/dist/utils/content-script-ui/shadow-root.d.mts +37 -25
  116. package/dist/utils/content-script-ui/shadow-root.mjs +4 -7
  117. package/dist/utils/content-script-ui/shared.mjs +1 -3
  118. package/dist/utils/content-script-ui/types.d.mts +29 -34
  119. package/dist/utils/content-script-ui/types.mjs +1 -1
  120. package/dist/utils/define-app-config.d.mts +4 -3
  121. package/dist/utils/define-app-config.mjs +5 -5
  122. package/dist/utils/define-background.mjs +1 -2
  123. package/dist/utils/define-content-script.mjs +1 -2
  124. package/dist/utils/define-unlisted-script.mjs +1 -2
  125. package/dist/utils/define-wxt-plugin.mjs +1 -2
  126. package/dist/utils/inject-script.mjs +1 -3
  127. package/dist/utils/internal/custom-events.mjs +3 -4
  128. package/dist/utils/internal/location-watcher.mjs +4 -6
  129. package/dist/utils/internal/logger.mjs +2 -5
  130. package/dist/utils/match-patterns.mjs +2 -3
  131. package/dist/utils/split-shadow-root-css.d.mts +6 -2
  132. package/dist/utils/split-shadow-root-css.mjs +7 -4
  133. package/dist/utils/storage.mjs +2 -3
  134. package/dist/version.mjs +2 -3
  135. package/dist/virtual/background-entrypoint.mjs +4 -16
  136. package/dist/virtual/content-script-isolated-world-entrypoint.mjs +2 -7
  137. package/dist/virtual/content-script-main-world-entrypoint.mjs +2 -7
  138. package/dist/virtual/mock-browser.mjs +1 -3
  139. package/dist/virtual/reload-html.mjs +3 -10
  140. package/dist/virtual/unlisted-script-entrypoint.mjs +2 -7
  141. package/package.json +15 -17
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * A alias around `publish-extension` that is always installed on the path without having to install
4
- * `publish-browser-extension` as a direct dependency (like for PNPM, which doesn't link
5
- * sub-dependency binaries to "node_modules/.bin")
3
+ * A alias around `publish-extension` that is always installed on the path
4
+ * without having to install `publish-browser-extension` as a direct dependency
5
+ * (like for PNPM, which doesn't link sub-dependency binaries to
6
+ * "node_modules/.bin")
6
7
  */
7
8
  await import('publish-browser-extension/cli');
@@ -3,12 +3,16 @@ import { Browser, browser as browser$1 } from "@wxt-dev/browser";
3
3
 
4
4
  //#region src/browser.d.ts
5
5
  /**
6
- * This interface is empty because it is generated per-project when running `wxt prepare`. See:
6
+ * This interface is empty because it is generated per-project when running `wxt
7
+ * prepare`. See:
8
+ *
7
9
  * - `.wxt/types/paths.d.ts`
8
10
  */
9
11
  interface WxtRuntime {}
10
12
  /**
11
- * This interface is empty because it is generated per-project when running `wxt prepare`. See:
13
+ * This interface is empty because it is generated per-project when running `wxt
14
+ * prepare`. See:
15
+ *
12
16
  * - `.wxt/types/i18n.d.ts`
13
17
  */
14
18
  interface WxtI18n {}
@@ -20,10 +24,7 @@ type ScriptInjection<Args extends any[], Result> = Browser.scripting.ScriptInjec
20
24
  type InjectionResult<Result> = Array<Browser.scripting.InjectionResult<Awaited<Result>>>;
21
25
  interface WxtScripting {
22
26
  executeScript: {
23
- /**
24
- * @see {@link Browser.scripting.executeScript}
25
- */
26
- <Args extends any[], Result>(injection: ScriptInjection<Args, Result>): Promise<InjectionResult<Result>>;
27
+ /** @see {@link Browser.scripting.executeScript} */<Args extends any[], Result>(injection: ScriptInjection<Args, Result>): Promise<InjectionResult<Result>>;
27
28
  <Args extends any[], Result>(injection: ScriptInjection<Args, Result>, callback: (results: InjectionResult<Result>) => void): void;
28
29
  };
29
30
  }
package/dist/browser.mjs CHANGED
@@ -1,18 +1,19 @@
1
1
  import { browser as browser$1 } from "@wxt-dev/browser";
2
-
3
2
  //#region src/browser.ts
4
3
  /**
5
- * Contains the `browser` export which you should use to access the extension APIs in your project:
4
+ * Contains the `browser` export which you should use to access the extension
5
+ * APIs in your project:
6
+ *
6
7
  * ```ts
7
8
  * import { browser } from 'wxt/browser';
8
9
  *
9
10
  * browser.runtime.onInstalled.addListener(() => {
10
11
  * // ...
11
- * })
12
+ * });
12
13
  * ```
14
+ *
13
15
  * @module wxt/browser
14
16
  */
15
17
  const browser = browser$1;
16
-
17
18
  //#endregion
18
- export { browser };
19
+ export { browser };
@@ -1,7 +1,5 @@
1
1
  import unimport_default from "./unimport.mjs";
2
-
3
2
  //#region src/builtin-modules/index.ts
4
3
  const builtinModules = [unimport_default];
5
-
6
4
  //#endregion
7
- export { builtinModules };
5
+ export { builtinModules };
@@ -1,7 +1,6 @@
1
1
  import { addViteConfig, defineWxtModule } from "../modules.mjs";
2
2
  import { createUnimport, toExports } from "unimport";
3
3
  import UnimportPlugin from "unimport/unplugin";
4
-
5
4
  //#region src/builtin-modules/unimport.ts
6
5
  var unimport_default = defineWxtModule({
7
6
  name: "wxt:built-in:unimport",
@@ -86,6 +85,5 @@ export default {
86
85
  `
87
86
  };
88
87
  }
89
-
90
88
  //#endregion
91
- export { unimport_default as default };
89
+ export { unimport_default as default };
@@ -6,10 +6,10 @@ import "../core/utils/log/index.mjs";
6
6
  import { ValidationError } from "../core/utils/validation.mjs";
7
7
  import consola, { LogLevels } from "consola";
8
8
  import spawn from "nano-spawn";
9
-
10
9
  //#region src/cli/cli-utils.ts
11
10
  /**
12
- * Wrap an action handler to add a timer, error handling, and maybe enable debug mode.
11
+ * Wrap an action handler to add a timer, error handling, and maybe enable debug
12
+ * mode.
13
13
  */
14
14
  function wrapAction(cb, options) {
15
15
  return async (...args) => {
@@ -28,8 +28,8 @@ function wrapAction(cb, options) {
28
28
  };
29
29
  }
30
30
  /**
31
- * Array flags, when not passed, are either `undefined` or `[undefined]`. This function filters out
32
- * the
31
+ * Array flags, when not passed, are either `undefined` or `[undefined]`. This
32
+ * function filters out the
33
33
  */
34
34
  function getArrayFromFlags(flags, name) {
35
35
  const result = filterTruthy(toArray(flags[name]));
@@ -57,6 +57,5 @@ function createAliasedCommand(base, name, alias, bin, docsUrl) {
57
57
  function isAliasedCommand(command) {
58
58
  return !!command && aliasCommandNames.has(command.name);
59
59
  }
60
-
61
60
  //#endregion
62
- export { createAliasedCommand, getArrayFromFlags, isAliasedCommand, wrapAction };
61
+ export { createAliasedCommand, getArrayFromFlags, isAliasedCommand, wrapAction };
@@ -7,7 +7,6 @@ import { zip } from "../core/zip.mjs";
7
7
  import "../core/index.mjs";
8
8
  import { createAliasedCommand, getArrayFromFlags, wrapAction } from "./cli-utils.mjs";
9
9
  import cac from "cac";
10
-
11
10
  //#region src/cli/commands.ts
12
11
  const cli = cac("wxt");
13
12
  cli.option("--debug", "enable debug mode");
@@ -76,6 +75,5 @@ cli.command("init [directory]", "initialize a new project").option("-t, --templa
76
75
  });
77
76
  }, { disableFinishedLog: true }));
78
77
  createAliasedCommand(cli, "submit", "publish-extension", "wxt-publish-extension", "https://www.npmjs.com/publish-browser-extension");
79
-
80
78
  //#endregion
81
- export { cli as default };
79
+ export { cli as default };
@@ -1,7 +1,6 @@
1
1
  import { version } from "../version.mjs";
2
2
  import { isAliasedCommand } from "./cli-utils.mjs";
3
3
  import cli from "./commands.mjs";
4
-
5
4
  //#region src/cli/index.ts
6
5
  cli.parse(process.argv, { run: false });
7
6
  if (!isAliasedCommand(cli.matchedCommand)) {
@@ -10,6 +9,5 @@ if (!isAliasedCommand(cli.matchedCommand)) {
10
9
  cli.parse(process.argv, { run: false });
11
10
  }
12
11
  await cli.runMatchedCommand();
13
-
14
12
  //#endregion
15
- export { };
13
+ export {};
@@ -2,17 +2,18 @@ import { BuildOutput, InlineConfig } from "../types.mjs";
2
2
 
3
3
  //#region src/core/build.d.ts
4
4
  /**
5
- * Bundles the extension for production. Returns a promise of the build result. Discovers the `wxt.config.ts` file in
6
- * the root directory, and merges that config with what is passed in.
5
+ * Bundles the extension for production. Returns a promise of the build result.
6
+ * Discovers the `wxt.config.ts` file in the root directory, and merges that
7
+ * config with what is passed in.
7
8
  *
8
9
  * @example
9
- * // Use config from `wxt.config.ts`
10
- * const res = await build()
10
+ * // Use config from `wxt.config.ts`
11
+ * const res = await build();
11
12
  *
12
- * // or override config `from wxt.config.ts`
13
- * const res = await build({
14
- * // Override config...
15
- * })
13
+ * // or override config `from wxt.config.ts`
14
+ * const res = await build({
15
+ * // Override config...
16
+ * });
16
17
  */
17
18
  declare function build(config?: InlineConfig): Promise<BuildOutput>;
18
19
  //#endregion
@@ -1,25 +1,24 @@
1
1
  import { registerWxt } from "./wxt.mjs";
2
2
  import { internalBuild } from "./utils/building/internal-build.mjs";
3
3
  import "./utils/building/index.mjs";
4
-
5
4
  //#region src/core/build.ts
6
5
  /**
7
- * Bundles the extension for production. Returns a promise of the build result. Discovers the `wxt.config.ts` file in
8
- * the root directory, and merges that config with what is passed in.
6
+ * Bundles the extension for production. Returns a promise of the build result.
7
+ * Discovers the `wxt.config.ts` file in the root directory, and merges that
8
+ * config with what is passed in.
9
9
  *
10
10
  * @example
11
- * // Use config from `wxt.config.ts`
12
- * const res = await build()
11
+ * // Use config from `wxt.config.ts`
12
+ * const res = await build();
13
13
  *
14
- * // or override config `from wxt.config.ts`
15
- * const res = await build({
16
- * // Override config...
17
- * })
14
+ * // or override config `from wxt.config.ts`
15
+ * const res = await build({
16
+ * // Override config...
17
+ * });
18
18
  */
19
19
  async function build(config) {
20
20
  await registerWxt("build", config);
21
21
  return await internalBuild();
22
22
  }
23
-
24
23
  //#endregion
25
- export { build };
24
+ export { build };
@@ -22,17 +22,17 @@ import { toArray } from "../../utils/arrays.mjs";
22
22
  import { safeVarName } from "../../utils/strings.mjs";
23
23
  import { createExtensionEnvironment } from "../../utils/environments/extension-environment.mjs";
24
24
  import "../../utils/environments/index.mjs";
25
- import fs from "fs-extra";
25
+ import { mkdir, readdir, rename, rmdir, stat } from "node:fs/promises";
26
26
  import { dirname, extname, join, relative } from "node:path";
27
27
  import { ViteNodeServer } from "vite-node/server";
28
28
  import { ViteNodeRunner } from "vite-node/client";
29
29
  import { installSourcemapsSupport } from "vite-node/source-map";
30
-
31
30
  //#region src/core/builders/vite/index.ts
32
31
  async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
33
32
  const vite = await import("vite");
34
33
  /**
35
- * Returns the base vite config shared by all builds based on the inline and user config.
34
+ * Returns the base vite config shared by all builds based on the inline and
35
+ * user config.
36
36
  */
37
37
  const getBaseConfig = async (baseConfigOptions) => {
38
38
  const config = await wxtConfig.vite(wxtConfig.env);
@@ -59,7 +59,8 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
59
59
  return config;
60
60
  };
61
61
  /**
62
- * Return the basic config for building an entrypoint in [lib mode](https://vitejs.dev/guide/build.html#library-mode).
62
+ * Return the basic config for building an entrypoint in [lib
63
+ * mode](https://vitejs.dev/guide/build.html#library-mode).
63
64
  */
64
65
  const getLibModeConfig = (entrypoint) => {
65
66
  const entry = getRollupEntry(entrypoint);
@@ -94,7 +95,8 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
94
95
  };
95
96
  };
96
97
  /**
97
- * Return the basic config for building multiple entrypoints in [multi-page mode](https://vitejs.dev/guide/build.html#multi-page-app).
98
+ * Return the basic config for building multiple entrypoints in [multi-page
99
+ * mode](https://vitejs.dev/guide/build.html#multi-page-app).
98
100
  */
99
101
  const getMultiPageConfig = (entrypoints) => {
100
102
  const htmlEntrypoints = new Set(entrypoints.filter(isHtmlEntrypoint).map((e) => e.name));
@@ -118,7 +120,8 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
118
120
  };
119
121
  };
120
122
  /**
121
- * Return the basic config for building a single CSS entrypoint in [multi-page mode](https://vitejs.dev/guide/build.html#multi-page-app).
123
+ * Return the basic config for building a single CSS entrypoint in [multi-page
124
+ * mode](https://vitejs.dev/guide/build.html#multi-page-app).
122
125
  */
123
126
  const getCssConfig = (entrypoint) => {
124
127
  return {
@@ -242,8 +245,8 @@ function getBuildOutputChunks(result) {
242
245
  return result.output;
243
246
  }
244
247
  /**
245
- * Returns the input module ID (virtual or real file) for an entrypoint. The returned string should
246
- * be passed as an input to rollup.
248
+ * Returns the input module ID (virtual or real file) for an entrypoint. The
249
+ * returned string should be passed as an input to rollup.
247
250
  */
248
251
  function getRollupEntry(entrypoint) {
249
252
  let virtualEntrypointType;
@@ -260,15 +263,17 @@ function getRollupEntry(entrypoint) {
260
263
  return entrypoint.inputPath;
261
264
  }
262
265
  /**
263
- * Ensures the HTML files output by a multipage build are in the correct location. This does two
264
- * things:
266
+ * Ensures the HTML files output by a multipage build are in the correct
267
+ * location. This does two things:
265
268
  *
266
- * 1. Moves the HTML files to their final location at `<outDir>/<entrypoint.name>.html`.
267
- * 2. Updates the bundle so it summarizes the files correctly in the returned build output.
269
+ * 1. Moves the HTML files to their final location at
270
+ * `<outDir>/<entrypoint.name>.html`.
271
+ * 2. Updates the bundle so it summarizes the files correctly in the returned build
272
+ * output.
268
273
  *
269
- * Assets (JS and CSS) are output to the `<outDir>/assets` directory, and don't need to be modified.
270
- * HTML files access them via absolute URLs, so we don't need to update any import paths in the HTML
271
- * files either.
274
+ * Assets (JS and CSS) are output to the `<outDir>/assets` directory, and don't
275
+ * need to be modified. HTML files access them via absolute URLs, so we don't
276
+ * need to update any import paths in the HTML files either.
272
277
  */
273
278
  async function moveHtmlFiles(config, group, chunks) {
274
279
  if (!Array.isArray(group)) return chunks;
@@ -284,8 +289,8 @@ async function moveHtmlFiles(config, group, chunks) {
284
289
  const newBundlePath = getEntrypointBundlePath(entry, config.outDir, extname(chunk.fileName));
285
290
  const oldAbsPath = join(config.outDir, oldBundlePath);
286
291
  const newAbsPath = join(config.outDir, newBundlePath);
287
- await fs.ensureDir(dirname(newAbsPath));
288
- await fs.move(oldAbsPath, newAbsPath, { overwrite: true });
292
+ await mkdir(dirname(newAbsPath), { recursive: true });
293
+ await rename(oldAbsPath, newAbsPath);
289
294
  return {
290
295
  ...chunk,
291
296
  fileName: newBundlePath
@@ -294,19 +299,16 @@ async function moveHtmlFiles(config, group, chunks) {
294
299
  await removeEmptyDirs(config.outDir);
295
300
  return movedChunks;
296
301
  }
297
- /**
298
- * Recursively remove all directories that are empty/
299
- */
302
+ /** Recursively remove all directories that are empty/ */
300
303
  async function removeEmptyDirs(dir) {
301
- const files = await fs.readdir(dir);
304
+ const files = await readdir(dir);
302
305
  for (const file of files) {
303
306
  const filePath = join(dir, file);
304
- if ((await fs.stat(filePath)).isDirectory()) await removeEmptyDirs(filePath);
307
+ if ((await stat(filePath)).isDirectory()) await removeEmptyDirs(filePath);
305
308
  }
306
309
  try {
307
- await fs.rmdir(dir);
310
+ await rmdir(dir);
308
311
  } catch {}
309
312
  }
310
-
311
313
  //#endregion
312
- export { createViteBuilder };
314
+ export { createViteBuilder };
@@ -1,6 +1,5 @@
1
1
  import path from "node:path";
2
2
  import { visualizer } from "@aklinker1/rollup-plugin-visualizer";
3
-
4
3
  //#region src/core/builders/vite/plugins/bundleAnalysis.ts
5
4
  let increment = 0;
6
5
  function bundleAnalysis(config) {
@@ -9,6 +8,5 @@ function bundleAnalysis(config) {
9
8
  filename: path.resolve(config.analysis.outputDir, `${config.analysis.outputName}-${increment++}.json`)
10
9
  });
11
10
  }
12
-
13
11
  //#endregion
14
- export { bundleAnalysis };
12
+ export { bundleAnalysis };
@@ -1,15 +1,16 @@
1
1
  import { getEntrypointBundlePath } from "../../../utils/entrypoints.mjs";
2
-
3
2
  //#region src/core/builders/vite/plugins/cssEntrypoints.ts
4
3
  /**
5
- * Rename CSS entrypoint outputs to ensure a JS file is not generated, and that the CSS file is
6
- * placed in the correct place.
4
+ * Rename CSS entrypoint outputs to ensure a JS file is not generated, and that
5
+ * the CSS file is placed in the correct place.
7
6
  *
8
7
  * It:
8
+ *
9
9
  * 1. Renames CSS files to their final paths
10
10
  * 2. Removes the JS file that get's output by lib mode
11
11
  *
12
- * THIS PLUGIN SHOULD ONLY BE APPLIED TO CSS LIB MODE BUILDS. It should not be added to every build.
12
+ * THIS PLUGIN SHOULD ONLY BE APPLIED TO CSS LIB MODE BUILDS. It should not be
13
+ * added to every build.
13
14
  */
14
15
  function cssEntrypoints(entrypoint, config) {
15
16
  return {
@@ -24,6 +25,5 @@ function cssEntrypoints(entrypoint, config) {
24
25
  }
25
26
  };
26
27
  }
27
-
28
28
  //#endregion
29
- export { cssEntrypoints };
29
+ export { cssEntrypoints };
@@ -2,8 +2,8 @@
2
2
  /**
3
3
  * Overrides definitions for `import.meta.*`
4
4
  *
5
- * - `import.meta.url`: Without this, background service workers crash trying to access
6
- * `document.location`, see https://github.com/wxt-dev/wxt/issues/392
5
+ * - `import.meta.url`: Without this, background service workers crash trying to
6
+ * access `document.location`, see https://github.com/wxt-dev/wxt/issues/392
7
7
  */
8
8
  function defineImportMeta() {
9
9
  return {
@@ -13,6 +13,5 @@ function defineImportMeta() {
13
13
  }
14
14
  };
15
15
  }
16
-
17
16
  //#endregion
18
- export { defineImportMeta };
17
+ export { defineImportMeta };
@@ -4,11 +4,11 @@ import { getEntrypointName } from "../../../utils/entrypoints.mjs";
4
4
  import { dirname, relative, resolve } from "node:path";
5
5
  import { parseHTML } from "linkedom";
6
6
  import { hash } from "ohash";
7
-
8
7
  //#region src/core/builders/vite/plugins/devHtmlPrerender.ts
9
8
  const inlineScriptContents = {};
10
9
  /**
11
- * Pre-renders the HTML entrypoints when building the extension to connect to the dev server.
10
+ * Pre-renders the HTML entrypoints when building the extension to connect to
11
+ * the dev server.
12
12
  */
13
13
  function devHtmlPrerender(config, server) {
14
14
  const htmlReloadId = "@wxt/reload-html";
@@ -21,21 +21,24 @@ function devHtmlPrerender(config, server) {
21
21
  config() {
22
22
  return { resolve: { alias: { [htmlReloadId]: resolvedHtmlReloadId } } };
23
23
  },
24
- transform(code, id) {
25
- if (config.command !== "serve" || server == null || !id.endsWith(".html")) return;
26
- const { document } = parseHTML(code);
27
- const _pointToDevServer = (querySelector, attr) => pointToDevServer(config, server, id, document, querySelector, attr);
28
- _pointToDevServer("script[type=module]", "src");
29
- _pointToDevServer("link[rel=stylesheet]", "href");
30
- const reloader = document.createElement("script");
31
- reloader.src = htmlReloadId;
32
- reloader.type = "module";
33
- document.head.appendChild(reloader);
34
- const newHtml = document.toString();
35
- config.logger.debug("transform " + id);
36
- config.logger.debug("Old HTML:\n" + code);
37
- config.logger.debug("New HTML:\n" + newHtml);
38
- return newHtml;
24
+ transform: {
25
+ filter: { id: /\.html$/ },
26
+ handler(code, id) {
27
+ if (config.command !== "serve" || server == null) return;
28
+ const { document } = parseHTML(code);
29
+ const _pointToDevServer = (querySelector, attr) => pointToDevServer(config, server, id, document, querySelector, attr);
30
+ _pointToDevServer("script[type=module]", "src");
31
+ _pointToDevServer("link[rel=stylesheet]", "href");
32
+ const reloader = document.createElement("script");
33
+ reloader.src = htmlReloadId;
34
+ reloader.type = "module";
35
+ document.head.appendChild(reloader);
36
+ const newHtml = document.toString();
37
+ config.logger.debug("transform " + id);
38
+ config.logger.debug("Old HTML:\n" + code);
39
+ config.logger.debug("New HTML:\n" + newHtml);
40
+ return newHtml;
41
+ }
39
42
  },
40
43
  async transformIndexHtml(html, ctx) {
41
44
  if (config.command !== "serve" || server == null) return;
@@ -63,13 +66,19 @@ function devHtmlPrerender(config, server) {
63
66
  }, {
64
67
  name: "wxt:virtualize-inline-scripts",
65
68
  apply: "serve",
66
- resolveId(id) {
67
- if (id.startsWith(virtualInlineScript)) return "\0" + id;
68
- if (id.startsWith("/chunks/")) return "\0noop";
69
+ resolveId: {
70
+ filter: { id: [new RegExp(`^${virtualInlineScript}`), /* @__PURE__ */ new RegExp("^/chunks/")] },
71
+ handler(id) {
72
+ if (id.startsWith("/chunks/")) return "\0noop";
73
+ return `\0${id}`;
74
+ }
69
75
  },
70
- load(id) {
71
- if (id.startsWith(resolvedVirtualInlineScript)) return inlineScriptContents[id.substring(id.indexOf("?") + 1)];
72
- if (id === "\0noop") return "";
76
+ load: {
77
+ filter: { id: [new RegExp(`^${resolvedVirtualInlineScript}`), /* @__PURE__ */ new RegExp("^\0noop")] },
78
+ handler(id) {
79
+ if (id === "\0noop") return "";
80
+ return inlineScriptContents[id.substring(id.indexOf("?") + 1)];
81
+ }
73
82
  }
74
83
  }];
75
84
  }
@@ -108,6 +117,5 @@ function isUrl(str) {
108
117
  return false;
109
118
  }
110
119
  }
111
-
112
120
  //#endregion
113
- export { devHtmlPrerender, pointToDevServer };
121
+ export { devHtmlPrerender, pointToDevServer };
@@ -1,6 +1,7 @@
1
1
  //#region src/core/builders/vite/plugins/devServerGlobals.ts
2
2
  /**
3
- * Defines global constants about the dev server. Helps scripts connect to the server's web socket.
3
+ * Defines global constants about the dev server. Helps scripts connect to the
4
+ * server's web socket.
4
5
  */
5
6
  function devServerGlobals(config, server) {
6
7
  return {
@@ -11,6 +12,5 @@ function devServerGlobals(config, server) {
11
12
  }
12
13
  };
13
14
  }
14
-
15
15
  //#endregion
16
- export { devServerGlobals };
16
+ export { devServerGlobals };
@@ -1,25 +1,29 @@
1
1
  import { fetchCached } from "../../../utils/network.mjs";
2
-
3
2
  //#region src/core/builders/vite/plugins/download.ts
4
3
  /**
5
- * Downloads any URL imports, like Google Analytics, into virtual modules so they are bundled with
6
- * the extension instead of depending on remote code at runtime.
4
+ * Downloads any URL imports, like Google Analytics, into virtual modules so
5
+ * they are bundled with the extension instead of depending on remote code at
6
+ * runtime.
7
7
  *
8
8
  * @example
9
- * import "url:https://google-tagmanager.com/gtag?id=XYZ";
9
+ * import 'url:https://google-tagmanager.com/gtag?id=XYZ';
10
10
  */
11
11
  function download(config) {
12
12
  return {
13
13
  name: "wxt:download",
14
- resolveId(id) {
15
- if (id.startsWith("url:")) return "\0" + id;
14
+ resolveId: {
15
+ filter: { id: /^url:/ },
16
+ handler(id) {
17
+ return `\0${id}`;
18
+ }
16
19
  },
17
- load(id) {
18
- if (!id.startsWith("\0url:")) return;
19
- return fetchCached(id.replace("\0url:", ""), config);
20
+ load: {
21
+ filter: { id: /^\x00url:/ },
22
+ handler(id) {
23
+ return fetchCached(id.replace("\0url:", ""), config);
24
+ }
20
25
  }
21
26
  };
22
27
  }
23
-
24
28
  //#endregion
25
- export { download };
29
+ export { download };
@@ -1,9 +1,6 @@
1
1
  import { getEntrypointGlobals } from "../../../utils/globals.mjs";
2
-
3
2
  //#region src/core/builders/vite/plugins/entrypointGroupGlobals.ts
4
- /**
5
- * Define a set of global variables specific to an entrypoint.
6
- */
3
+ /** Define a set of global variables specific to an entrypoint. */
7
4
  function entrypointGroupGlobals(entrypointGroup) {
8
5
  return {
9
6
  name: "wxt:entrypoint-group-globals",
@@ -15,6 +12,5 @@ function entrypointGroupGlobals(entrypointGroup) {
15
12
  }
16
13
  };
17
14
  }
18
-
19
15
  //#endregion
20
- export { entrypointGroupGlobals };
16
+ export { entrypointGroupGlobals };
@@ -1,8 +1,8 @@
1
1
  import path from "node:path";
2
-
3
2
  //#region src/core/builders/vite/plugins/extensionApiMock.ts
4
3
  /**
5
- * Mock `wxt/browser` and stub the global `browser`/`chrome` types with a fake version of the extension APIs
4
+ * Mock `wxt/browser` and stub the global `browser`/`chrome` types with a fake
5
+ * version of the extension APIs
6
6
  */
7
7
  function extensionApiMock(config) {
8
8
  const virtualSetupModule = "virtual:wxt-setup";
@@ -20,11 +20,17 @@ function extensionApiMock(config) {
20
20
  ssr: { noExternal: ["wxt"] }
21
21
  };
22
22
  },
23
- resolveId(id) {
24
- if (id.endsWith(virtualSetupModule)) return resolvedVirtualSetupModule;
23
+ resolveId: {
24
+ filter: { id: new RegExp(`${virtualSetupModule}$`) },
25
+ handler() {
26
+ return resolvedVirtualSetupModule;
27
+ }
25
28
  },
26
- load(id) {
27
- if (id === resolvedVirtualSetupModule) return setupTemplate;
29
+ load: {
30
+ filter: { id: new RegExp(`^${resolvedVirtualSetupModule}$`) },
31
+ handler() {
32
+ return setupTemplate;
33
+ }
28
34
  }
29
35
  };
30
36
  }
@@ -35,6 +41,5 @@ const setupTemplate = `
35
41
  vi.stubGlobal("chrome", fakeBrowser);
36
42
  vi.stubGlobal("browser", fakeBrowser);
37
43
  `;
38
-
39
44
  //#endregion
40
- export { extensionApiMock };
45
+ export { extensionApiMock };
@@ -1,5 +1,4 @@
1
1
  import { getGlobals } from "../../../utils/globals.mjs";
2
-
3
2
  //#region src/core/builders/vite/plugins/globals.ts
4
3
  function globals(config) {
5
4
  return {
@@ -11,6 +10,5 @@ function globals(config) {
11
10
  }
12
11
  };
13
12
  }
14
-
15
13
  //#endregion
16
- export { globals };
14
+ export { globals };
@@ -10,6 +10,5 @@ function iifeAnonymous(iifeReturnValueName) {
10
10
  }
11
11
  };
12
12
  }
13
-
14
13
  //#endregion
15
- export { iifeAnonymous };
14
+ export { iifeAnonymous };