wxt 0.21.0 → 0.21.2

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 (153) hide show
  1. package/README.md +0 -1
  2. package/bin/wxt-publish-extension.mjs +4 -3
  3. package/dist/browser.d.mts +7 -6
  4. package/dist/browser.mjs +6 -5
  5. package/dist/builtin-modules/favicon-permission.mjs +28 -0
  6. package/dist/builtin-modules/index.mjs +3 -4
  7. package/dist/builtin-modules/unimport.mjs +1 -3
  8. package/dist/cli/cli-utils.mjs +8 -9
  9. package/dist/cli/commands.mjs +1 -3
  10. package/dist/cli/index.mjs +1 -3
  11. package/dist/core/build.d.mts +9 -8
  12. package/dist/core/build.mjs +10 -11
  13. package/dist/core/builders/vite/index.mjs +123 -75
  14. package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +1 -3
  15. package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +6 -6
  16. package/dist/core/builders/vite/plugins/defineImportMeta.mjs +3 -4
  17. package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +34 -26
  18. package/dist/core/builders/vite/plugins/devServerGlobals.mjs +3 -3
  19. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +2 -6
  20. package/dist/core/builders/vite/plugins/extensionApiMock.mjs +13 -8
  21. package/dist/core/builders/vite/plugins/globals.mjs +1 -3
  22. package/dist/core/builders/vite/plugins/iifeAnonymous.mjs +1 -2
  23. package/dist/core/builders/vite/plugins/iifeFooter.mjs +14 -7
  24. package/dist/core/builders/vite/plugins/index.mjs +17 -19
  25. package/dist/core/builders/vite/plugins/noopBackground.mjs +14 -9
  26. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +10 -12
  27. package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +14 -10
  28. package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +15 -13
  29. package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +1 -2
  30. package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +22 -17
  31. package/dist/core/clean.d.mts +3 -14
  32. package/dist/core/clean.mjs +19 -13
  33. package/dist/core/create-server.d.mts +6 -5
  34. package/dist/core/create-server.mjs +21 -117
  35. package/dist/core/define-config.mjs +1 -2
  36. package/dist/core/define-web-ext-config.d.mts +3 -6
  37. package/dist/core/define-web-ext-config.mjs +3 -12
  38. package/dist/core/generate-wxt-dir.mjs +53 -35
  39. package/dist/core/index.d.mts +3 -2
  40. package/dist/core/index.mjs +11 -11
  41. package/dist/core/initialize.mjs +28 -29
  42. package/dist/core/keyboard-shortcuts.mjs +4 -8
  43. package/dist/core/package-managers/bun.mjs +1 -3
  44. package/dist/core/package-managers/deno.mjs +1 -2
  45. package/dist/core/package-managers/index.mjs +1 -3
  46. package/dist/core/package-managers/npm.mjs +3 -5
  47. package/dist/core/package-managers/pnpm.mjs +1 -3
  48. package/dist/core/package-managers/yarn.mjs +1 -3
  49. package/dist/core/prepare.mjs +1 -3
  50. package/dist/core/resolve-config.mjs +63 -43
  51. package/dist/core/runners/manual.mjs +2 -6
  52. package/dist/core/runners/safari.mjs +3 -4
  53. package/dist/core/runners/web-ext.mjs +8 -11
  54. package/dist/core/runners/wsl.mjs +3 -4
  55. package/dist/core/utils/arrays.mjs +4 -11
  56. package/dist/core/utils/building/build-entrypoints.mjs +10 -11
  57. package/dist/core/utils/building/detect-dev-changes.mjs +37 -19
  58. package/dist/core/utils/building/find-entrypoints.mjs +40 -21
  59. package/dist/core/utils/building/group-entrypoints.mjs +3 -4
  60. package/dist/core/utils/building/index.mjs +7 -8
  61. package/dist/core/utils/building/internal-build.mjs +21 -21
  62. package/dist/core/utils/building/rebuild.mjs +10 -10
  63. package/dist/core/utils/cache.mjs +6 -8
  64. package/dist/core/utils/constants.mjs +3 -4
  65. package/dist/core/utils/content-scripts.mjs +3 -4
  66. package/dist/core/utils/content-security-policy.mjs +2 -5
  67. package/dist/core/utils/create-file-reloader.mjs +158 -0
  68. package/dist/core/utils/entrypoints.d.mts +10 -0
  69. package/dist/core/utils/entrypoints.mjs +6 -10
  70. package/dist/core/utils/env.mjs +24 -19
  71. package/dist/core/utils/environments/browser-environment.mjs +1 -3
  72. package/dist/core/utils/environments/environment.mjs +1 -2
  73. package/dist/core/utils/environments/extension-environment.mjs +1 -3
  74. package/dist/core/utils/environments/index.mjs +3 -4
  75. package/dist/core/utils/eslint.mjs +1 -2
  76. package/dist/core/utils/fs.mjs +23 -14
  77. package/dist/core/utils/globals.mjs +1 -2
  78. package/dist/core/utils/i18n.mjs +2 -3
  79. package/dist/core/utils/index.d.mts +2 -0
  80. package/dist/core/utils/index.mjs +3 -3
  81. package/dist/core/utils/log/index.mjs +5 -6
  82. package/dist/core/utils/log/printBuildSummary.mjs +1 -3
  83. package/dist/core/utils/log/printFileList.mjs +25 -21
  84. package/dist/core/utils/log/printHeader.mjs +3 -5
  85. package/dist/core/utils/log/printTable.mjs +1 -2
  86. package/dist/core/utils/manifest.mjs +39 -46
  87. package/dist/core/utils/number.mjs +1 -2
  88. package/dist/core/utils/package.mjs +3 -5
  89. package/dist/core/utils/paths.d.mts +2 -2
  90. package/dist/core/utils/paths.mjs +7 -9
  91. package/dist/core/utils/strings.mjs +4 -7
  92. package/dist/core/utils/syntax-errors.mjs +3 -5
  93. package/dist/core/utils/theme-icons.mjs +71 -0
  94. package/dist/core/utils/time.mjs +1 -13
  95. package/dist/core/utils/transform.mjs +9 -7
  96. package/dist/core/utils/validation.mjs +1 -2
  97. package/dist/core/utils/virtual-modules.mjs +9 -15
  98. package/dist/core/wxt.mjs +11 -12
  99. package/dist/core/zip.d.mts +1 -0
  100. package/dist/core/zip.mjs +25 -20
  101. package/dist/index.d.mts +4 -4
  102. package/dist/index.mjs +3 -3
  103. package/dist/modules.d.mts +64 -61
  104. package/dist/modules.mjs +70 -66
  105. package/dist/testing/fake-browser.mjs +1 -2
  106. package/dist/testing/wxt-vitest-plugin.d.mts +4 -2
  107. package/dist/testing/wxt-vitest-plugin.mjs +5 -7
  108. package/dist/types.d.mts +636 -450
  109. package/dist/utils/app-config.d.mts +1 -0
  110. package/dist/utils/app-config.mjs +3 -3
  111. package/dist/utils/content-script-context.d.mts +49 -39
  112. package/dist/utils/content-script-context.mjs +37 -32
  113. package/dist/utils/content-script-ui/iframe.d.mts +14 -15
  114. package/dist/utils/content-script-ui/iframe.mjs +1 -3
  115. package/dist/utils/content-script-ui/integrated.d.mts +8 -7
  116. package/dist/utils/content-script-ui/integrated.mjs +1 -3
  117. package/dist/utils/content-script-ui/shadow-root.d.mts +37 -25
  118. package/dist/utils/content-script-ui/shadow-root.mjs +5 -8
  119. package/dist/utils/content-script-ui/shared.mjs +1 -3
  120. package/dist/utils/content-script-ui/types.d.mts +29 -34
  121. package/dist/utils/content-script-ui/types.mjs +1 -1
  122. package/dist/utils/define-app-config.d.mts +4 -3
  123. package/dist/utils/define-app-config.mjs +5 -5
  124. package/dist/utils/define-background.mjs +1 -2
  125. package/dist/utils/define-content-script.mjs +1 -2
  126. package/dist/utils/define-unlisted-script.mjs +1 -2
  127. package/dist/utils/define-wxt-plugin.mjs +1 -2
  128. package/dist/utils/inject-script.d.mts +2 -2
  129. package/dist/utils/inject-script.mjs +4 -5
  130. package/dist/utils/internal/custom-events.mjs +3 -4
  131. package/dist/utils/internal/location-watcher.mjs +4 -6
  132. package/dist/utils/internal/logger.mjs +2 -5
  133. package/dist/utils/match-patterns.mjs +2 -3
  134. package/dist/utils/split-shadow-root-css.d.mts +6 -2
  135. package/dist/utils/split-shadow-root-css.mjs +7 -4
  136. package/dist/utils/storage.mjs +2 -3
  137. package/dist/version.mjs +2 -3
  138. package/dist/virtual/background-entrypoint.mjs +4 -16
  139. package/dist/virtual/content-script-isolated-world-entrypoint.mjs +2 -7
  140. package/dist/virtual/content-script-main-world-entrypoint.mjs +2 -7
  141. package/dist/virtual/mock-browser.d.mts +1 -1
  142. package/dist/virtual/mock-browser.mjs +2 -4
  143. package/dist/virtual/reload-html.mjs +3 -10
  144. package/dist/virtual/unlisted-script-entrypoint.mjs +2 -7
  145. package/package.json +55 -49
  146. package/LICENSE +0 -21
  147. package/dist/core/builders/vite/plugins/download.mjs +0 -25
  148. package/dist/core/runners/index.mjs +0 -17
  149. package/dist/core/utils/minimatch-multiple.mjs +0 -28
  150. package/dist/core/utils/network.mjs +0 -38
  151. package/dist/core/utils/wsl.mjs +0 -12
  152. package/dist/testing/index.d.mts +0 -3
  153. package/dist/testing/index.mjs +0 -4
@@ -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 };
@@ -1,14 +1,14 @@
1
1
  import { normalizePath } from "../../../utils/paths.mjs";
2
- import "../../../utils/index.mjs";
3
2
  import { getEntrypointName } from "../../../utils/entrypoints.mjs";
3
+ import "../../../utils/index.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,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 };
@@ -1,18 +1,25 @@
1
1
  //#region src/core/builders/vite/plugins/iifeFooter.ts
2
2
  /**
3
- * Add a footer with the returned value so it can return values to `scripting.executeScript`
4
- * Footer is added a part of esbuild to make sure it's not minified. It
5
- * get's removed if added to `build.rollupOptions.output.footer`
6
- * See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript#return_value
3
+ * Add a footer with the returned value so it can return values to
4
+ * `scripting.executeScript` Footer is added a part of esbuild to make sure it's
5
+ * not minified. It get's removed if added to
6
+ * `build.rollupOptions.output.footer` See
7
+ * https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript#return_value
7
8
  */
8
9
  function iifeFooter(iifeReturnValueName) {
9
10
  return {
10
11
  name: "wxt:iife-footer",
11
12
  generateBundle(_, bundle) {
12
- for (const chunk of Object.values(bundle)) if (chunk.type === "chunk" && chunk.isEntry) chunk.code += `${iifeReturnValueName};`;
13
+ for (const chunk of Object.values(bundle)) if (chunk.type === "chunk" && chunk.isEntry) {
14
+ const code = chunk.code;
15
+ const marker = "\n//# sourceMappingURL=";
16
+ const returnValue = `${iifeReturnValueName};`;
17
+ const index = code.indexOf(marker);
18
+ if (index >= 0) chunk.code = code.slice(0, index + 1) + `${returnValue}\n` + code.slice(index + 1);
19
+ else chunk.code += `\n${returnValue}`;
20
+ }
13
21
  }
14
22
  };
15
23
  }
16
-
17
24
  //#endregion
18
- export { iifeFooter };
25
+ export { iifeFooter };
@@ -1,19 +1,17 @@
1
- import { devHtmlPrerender, pointToDevServer } from "./devHtmlPrerender.mjs";
2
- import { devServerGlobals } from "./devServerGlobals.mjs";
3
- import { download } from "./download.mjs";
4
- import { resolveVirtualModules } from "./resolveVirtualModules.mjs";
5
- import { tsconfigPaths } from "./tsconfigPaths.mjs";
6
- import { noopBackground } from "./noopBackground.mjs";
7
- import { cssEntrypoints } from "./cssEntrypoints.mjs";
8
- import { bundleAnalysis } from "./bundleAnalysis.mjs";
9
- import { globals } from "./globals.mjs";
10
- import { extensionApiMock } from "./extensionApiMock.mjs";
11
- import { entrypointGroupGlobals } from "./entrypointGroupGlobals.mjs";
12
- import { defineImportMeta } from "./defineImportMeta.mjs";
13
- import { removeEntrypointMainFunction } from "./removeEntrypointMainFunction.mjs";
14
- import { wxtPluginLoader } from "./wxtPluginLoader.mjs";
15
- import { resolveAppConfig } from "./resolveAppConfig.mjs";
16
- import { iifeFooter } from "./iifeFooter.mjs";
17
- import { iifeAnonymous } from "./iifeAnonymous.mjs";
18
-
19
- export { };
1
+ import "./devHtmlPrerender.mjs";
2
+ import "./devServerGlobals.mjs";
3
+ import "./resolveVirtualModules.mjs";
4
+ import "./tsconfigPaths.mjs";
5
+ import "./noopBackground.mjs";
6
+ import "./cssEntrypoints.mjs";
7
+ import "./bundleAnalysis.mjs";
8
+ import "./globals.mjs";
9
+ import "./extensionApiMock.mjs";
10
+ import "./entrypointGroupGlobals.mjs";
11
+ import "./defineImportMeta.mjs";
12
+ import "./removeEntrypointMainFunction.mjs";
13
+ import "./wxtPluginLoader.mjs";
14
+ import "./resolveAppConfig.mjs";
15
+ import "./iifeFooter.mjs";
16
+ import "./iifeAnonymous.mjs";
17
+ export {};
@@ -1,23 +1,28 @@
1
1
  import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../../../utils/constants.mjs";
2
-
3
2
  //#region src/core/builders/vite/plugins/noopBackground.ts
4
3
  /**
5
- * In dev mode, if there's not a background script listed, we need to add one so that the web socket
6
- * connection is setup and the extension reloads HTML pages and content scripts correctly.
4
+ * In dev mode, if there's not a background script listed, we need to add one so
5
+ * that the web socket connection is setup and the extension reloads HTML pages
6
+ * and content scripts correctly.
7
7
  */
8
8
  function noopBackground() {
9
9
  const virtualModuleId = VIRTUAL_NOOP_BACKGROUND_MODULE_ID;
10
10
  const resolvedVirtualModuleId = "\0" + virtualModuleId;
11
11
  return {
12
12
  name: "wxt:noop-background",
13
- resolveId(id) {
14
- if (id === virtualModuleId) return resolvedVirtualModuleId;
13
+ resolveId: {
14
+ filter: { id: new RegExp(`^${virtualModuleId}$`) },
15
+ handler() {
16
+ return resolvedVirtualModuleId;
17
+ }
15
18
  },
16
- load(id) {
17
- if (id === resolvedVirtualModuleId) return `import { defineBackground } from 'wxt/utils/define-background';\nexport default defineBackground(() => void 0)`;
19
+ load: {
20
+ filter: { id: new RegExp(`^${resolvedVirtualModuleId}$`) },
21
+ handler() {
22
+ return `import { defineBackground } from 'wxt/utils/define-background';\nexport default defineBackground(() => void 0)`;
23
+ }
18
24
  }
19
25
  };
20
26
  }
21
-
22
27
  //#endregion
23
- export { noopBackground };
28
+ export { noopBackground };
@@ -2,10 +2,10 @@ import { normalizePath } from "../../../utils/paths.mjs";
2
2
  import "../../../utils/index.mjs";
3
3
  import { removeMainFunctionCode } from "../../../utils/transform.mjs";
4
4
  import { resolve } from "node:path";
5
-
6
5
  //#region src/core/builders/vite/plugins/removeEntrypointMainFunction.ts
7
6
  /**
8
- * Transforms entrypoints, removing the main function from the entrypoint if it exists.
7
+ * Transforms entrypoints, removing the main function from the entrypoint if it
8
+ * exists.
9
9
  */
10
10
  function removeEntrypointMainFunction(config, path) {
11
11
  const absPath = normalizePath(resolve(config.root, path));
@@ -13,18 +13,16 @@ function removeEntrypointMainFunction(config, path) {
13
13
  name: "wxt:remove-entrypoint-main-function",
14
14
  transform: {
15
15
  order: "pre",
16
- handler(code, id) {
17
- if (id === absPath) {
18
- const newCode = removeMainFunctionCode(code);
19
- config.logger.debug("vite-node transformed entrypoint", path);
20
- config.logger.debug(`Original:\n---\n${code}\n---`);
21
- config.logger.debug(`Transformed:\n---\n${newCode.code}\n---`);
22
- return newCode;
23
- }
16
+ filter: { id: new RegExp(`^${absPath}$`) },
17
+ handler(code) {
18
+ const newCode = removeMainFunctionCode(code);
19
+ config.logger.debug("transformed entrypoint", path);
20
+ config.logger.debug(`Original:\n---\n${code}\n---`);
21
+ config.logger.debug(`Transformed:\n---\n${newCode.code}\n---`);
22
+ return newCode;
24
23
  }
25
24
  }
26
25
  };
27
26
  }
28
-
29
27
  //#endregion
30
- export { removeEntrypointMainFunction };
28
+ export { removeEntrypointMainFunction };
@@ -1,9 +1,9 @@
1
- import { pathExists } from "fs-extra";
1
+ import { pathExists } from "../../../utils/fs.mjs";
2
2
  import { resolve } from "node:path";
3
-
4
3
  //#region src/core/builders/vite/plugins/resolveAppConfig.ts
5
4
  /**
6
- * When importing `virtual:app-config`, resolve it to the `app.config.ts` file in the project.
5
+ * When importing `virtual:app-config`, resolve it to the `app.config.ts` file
6
+ * in the project.
7
7
  */
8
8
  function resolveAppConfig(config) {
9
9
  const virtualModuleId = "virtual:app-config";
@@ -14,15 +14,19 @@ function resolveAppConfig(config) {
14
14
  config() {
15
15
  return { optimizeDeps: { exclude: [virtualModuleId] } };
16
16
  },
17
- async resolveId(id) {
18
- if (id !== virtualModuleId) return;
19
- return await pathExists(appConfigFile) ? appConfigFile : resolvedVirtualModuleId;
17
+ resolveId: {
18
+ filter: { id: new RegExp(`^${virtualModuleId}$`) },
19
+ async handler() {
20
+ return await pathExists(appConfigFile) ? appConfigFile : resolvedVirtualModuleId;
21
+ }
20
22
  },
21
- load(id) {
22
- if (id === resolvedVirtualModuleId) return `export default {}`;
23
+ load: {
24
+ filter: { id: new RegExp(`^${resolvedVirtualModuleId}$`) },
25
+ handler() {
26
+ return `export default {}`;
27
+ }
23
28
  }
24
29
  };
25
30
  }
26
-
27
31
  //#endregion
28
- export { resolveAppConfig };
32
+ export { resolveAppConfig };
@@ -1,12 +1,12 @@
1
1
  import { normalizePath } from "../../../utils/paths.mjs";
2
2
  import "../../../utils/index.mjs";
3
3
  import { virtualModuleNames } from "../../../utils/virtual-modules.mjs";
4
- import fs from "fs-extra";
4
+ import { readFile } from "node:fs/promises";
5
5
  import { resolve } from "path";
6
-
7
6
  //#region src/core/builders/vite/plugins/resolveVirtualModules.ts
8
7
  /**
9
- * Resolve all the virtual modules to the `node_modules/wxt/dist/virtual` directory.
8
+ * Resolve all the virtual modules to the `node_modules/wxt/dist/virtual`
9
+ * directory.
10
10
  */
11
11
  function resolveVirtualModules(config) {
12
12
  return virtualModuleNames.map((name) => {
@@ -14,19 +14,21 @@ function resolveVirtualModules(config) {
14
14
  const resolvedVirtualId = "\0" + virtualId;
15
15
  return {
16
16
  name: `wxt:resolve-virtual-${name}`,
17
- resolveId(id) {
18
- const index = id.indexOf(virtualId);
19
- if (index === -1) return;
20
- return resolvedVirtualId + normalizePath(id.substring(index + virtualId.length));
17
+ resolveId: {
18
+ filter: { id: new RegExp(virtualId) },
19
+ handler(id) {
20
+ return resolvedVirtualId + normalizePath(id.substring(id.indexOf(virtualId) + virtualId.length));
21
+ }
21
22
  },
22
- async load(id) {
23
- if (!id.startsWith(resolvedVirtualId)) return;
24
- const inputPath = id.replace(resolvedVirtualId, "");
25
- return (await fs.readFile(resolve(config.wxtModuleDir, `dist/virtual/${name}.mjs`), "utf-8")).replace(`virtual:user-${name}`, inputPath);
23
+ load: {
24
+ filter: { id: new RegExp(`^${resolvedVirtualId}`) },
25
+ async handler(id) {
26
+ const inputPath = id.replace(resolvedVirtualId, "");
27
+ return (await readFile(resolve(config.wxtModuleDir, `dist/virtual/${name}.mjs`), "utf-8")).replace(`virtual:user-${name}`, inputPath);
28
+ }
26
29
  }
27
30
  };
28
31
  });
29
32
  }
30
-
31
33
  //#endregion
32
- export { resolveVirtualModules };
34
+ export { resolveVirtualModules };
@@ -7,6 +7,5 @@ function tsconfigPaths(config) {
7
7
  }
8
8
  };
9
9
  }
10
-
11
10
  //#endregion
12
- export { tsconfigPaths };
11
+ export { tsconfigPaths };
@@ -1,10 +1,11 @@
1
1
  import { normalizePath } from "../../../utils/paths.mjs";
2
2
  import "../../../utils/index.mjs";
3
3
  import { parseHTML } from "linkedom";
4
-
5
4
  //#region src/core/builders/vite/plugins/wxtPluginLoader.ts
6
5
  /**
7
- * Resolve and load plugins for each entrypoint. This handles both JS entrypoints via the `virtual:wxt-plugins` import, and HTML files by adding `virtual:wxt-html-plugins` to the document's `<head>`
6
+ * Resolve and load plugins for each entrypoint. This handles both JS
7
+ * entrypoints via the `virtual:wxt-plugins` import, and HTML files by adding
8
+ * `virtual:wxt-html-plugins` to the document's `<head>`
8
9
  */
9
10
  function wxtPluginLoader(config) {
10
11
  const virtualModuleId = "virtual:wxt-plugins";
@@ -13,19 +14,24 @@ function wxtPluginLoader(config) {
13
14
  const resolvedVirtualHtmlModuleId = "\0" + virtualHtmlModuleId;
14
15
  return {
15
16
  name: "wxt:plugin-loader",
16
- resolveId(id) {
17
- if (id === virtualModuleId) return resolvedVirtualModuleId;
18
- if (id === virtualHtmlModuleId) return resolvedVirtualHtmlModuleId;
17
+ resolveId: {
18
+ filter: { id: [new RegExp(`^${virtualModuleId}$`), new RegExp(`^${virtualHtmlModuleId}$`)] },
19
+ handler(id) {
20
+ if (id === virtualModuleId) return resolvedVirtualModuleId;
21
+ return resolvedVirtualHtmlModuleId;
22
+ }
19
23
  },
20
- load(id) {
21
- if (id === resolvedVirtualModuleId) return `${config.plugins.map((plugin, i) => `import initPlugin${i} from '${normalizePath(plugin)}';`).join("\n")}\n\nexport function initPlugins() {\n${config.plugins.map((_, i) => ` initPlugin${i}();`).join("\n")}\n}`;
22
- if (id === resolvedVirtualHtmlModuleId) return `import { initPlugins } from '${virtualModuleId}';
23
-
24
- try {
25
- initPlugins();
26
- } catch (err) {
27
- console.error("[wxt] Failed to initialize plugins", err);
28
- }`;
24
+ load: {
25
+ filter: { id: [new RegExp(`^${resolvedVirtualModuleId}$`), new RegExp(`^${resolvedVirtualHtmlModuleId}$`)] },
26
+ handler(id) {
27
+ if (id === resolvedVirtualModuleId) return `${config.plugins.map((plugin, i) => `import initPlugin${i} from '${normalizePath(plugin)}';`).join("\n")}\n\nexport function initPlugins() {\n${config.plugins.map((_, i) => ` initPlugin${i}();`).join("\n")}\n}`;
28
+ else return `import { initPlugins } from '${virtualModuleId}';
29
+ try {
30
+ initPlugins();
31
+ } catch (err) {
32
+ console.error("[wxt] Failed to initialize plugins", err);
33
+ }`;
34
+ }
29
35
  },
30
36
  transformIndexHtml: {
31
37
  order: "pre",
@@ -40,12 +46,11 @@ try {
40
46
  const newHead = document.createElement("head");
41
47
  document.documentElement.prepend(newHead);
42
48
  }
43
- document.head.prepend(script);
49
+ document.head?.prepend(script);
44
50
  return document.toString();
45
51
  }
46
52
  }
47
53
  };
48
54
  }
49
-
50
55
  //#endregion
51
- export { wxtPluginLoader };
56
+ export { wxtPluginLoader };
@@ -4,22 +4,11 @@ import { InlineConfig } from "../types.mjs";
4
4
  /**
5
5
  * Remove generated/temp files from the directory.
6
6
  *
7
- * @param config Optional config that will override your `<root>/wxt.config.ts`.
8
- *
9
7
  * @example
10
- * await clean();
11
- */
12
- declare function clean(config?: InlineConfig): Promise<void>;
13
- /**
14
- * Remove generated/temp files from the directory.
8
+ * await clean();
15
9
  *
16
- * @deprecated
17
- *
18
- * @param root The directory to look for generated/temp files in. Defaults to `process.cwd()`. Can be relative to `process.cwd()` or absolute.
19
- *
20
- * @example
21
- * await clean();
10
+ * @param config Optional config that will override your `<root>/wxt.config.ts`.
22
11
  */
23
- declare function clean(root?: string): Promise<void>;
12
+ declare function clean(config?: InlineConfig): Promise<void>;
24
13
  //#endregion
25
14
  export { clean };
@@ -1,41 +1,47 @@
1
1
  import { registerWxt, wxt } from "./wxt.mjs";
2
- import fs from "fs-extra";
3
- import glob from "fast-glob";
2
+ import { rm } from "node:fs/promises";
3
+ import { glob } from "tinyglobby";
4
4
  import path from "node:path";
5
- import pc from "picocolors";
6
-
5
+ import { styleText } from "node:util";
7
6
  //#region src/core/clean.ts
7
+ /**
8
+ * Remove generated/temp files from the directory.
9
+ *
10
+ * @example
11
+ * await clean();
12
+ *
13
+ * @param config Optional config that will override your `<root>/wxt.config.ts`.
14
+ */
8
15
  async function clean(config) {
9
- if (typeof config === "string") config = { root: config };
10
16
  await registerWxt("build", config);
11
17
  wxt.logger.info("Cleaning Project");
12
18
  const root = wxt.config.root;
13
19
  const tempDirs = [
14
20
  "node_modules/.vite",
15
21
  "node_modules/.cache",
16
- "**/.wxt",
22
+ "{,**/}.wxt",
17
23
  `${path.relative(root, wxt.config.outBaseDir)}/*`
18
24
  ];
19
- wxt.logger.debug("Looking for:", tempDirs.map(pc.cyan).join(", "));
25
+ wxt.logger.debug("Looking for:", tempDirs.map((dir) => styleText("cyan", dir)).join(", "));
20
26
  const directories = await glob(tempDirs, {
21
27
  cwd: root,
22
28
  absolute: true,
23
29
  onlyDirectories: true,
24
- deep: 2
30
+ deep: 2,
31
+ expandDirectories: false
25
32
  });
26
33
  if (directories.length === 0) {
27
34
  wxt.logger.debug("No generated files found.");
28
35
  return;
29
36
  }
30
- wxt.logger.debug("Found:", directories.map((dir) => pc.cyan(path.relative(root, dir))).join(", "));
37
+ wxt.logger.debug("Found:", directories.map((dir) => styleText("cyan", path.relative(root, dir))).join(", "));
31
38
  for (const directory of directories) {
32
- await fs.rm(directory, {
39
+ await rm(directory, {
33
40
  force: true,
34
41
  recursive: true
35
42
  });
36
- wxt.logger.debug("Deleted " + pc.cyan(path.relative(root, directory)));
43
+ wxt.logger.debug("Deleted " + styleText("cyan", path.relative(root, directory)));
37
44
  }
38
45
  }
39
-
40
46
  //#endregion
41
- export { clean };
47
+ export { clean };
@@ -2,13 +2,14 @@ import { InlineConfig, WxtDevServer } from "../types.mjs";
2
2
 
3
3
  //#region src/core/create-server.d.ts
4
4
  /**
5
- * Creates a dev server and pre-builds all the files that need to exist before loading the extension.
5
+ * Creates a dev server and pre-builds all the files that need to exist before
6
+ * loading the extension.
6
7
  *
7
8
  * @example
8
- * const server = await wxt.createServer({
9
- * // Enter config...
10
- * });
11
- * await server.start();
9
+ * const server = await wxt.createServer({
10
+ * // Enter config...
11
+ * });
12
+ * await server.start();
12
13
  */
13
14
  declare function createServer(inlineConfig?: InlineConfig): Promise<WxtDevServer>;
14
15
  //#endregion