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,10 +1,9 @@
1
- import { normalizePath } from "../../../utils/paths.mjs";
2
- import { getEntrypointName } from "../../../utils/entrypoints.mjs";
3
- import "../../../utils/index.mjs";
4
- import { dirname, relative, resolve } from "node:path";
1
+ import { normalizePath } from "../../../../internal-utils/path-utils.mjs";
2
+ import { getEntrypointName } from "../../../../internal-utils/entrypoint-utils.mjs";
3
+ import { c } from "../../../../inline/ohash/index.mjs";
5
4
  import { parseHTML } from "linkedom";
6
- import { hash } from "ohash";
7
- //#region src/core/builders/vite/plugins/devHtmlPrerender.ts
5
+ import { dirname, relative, resolve } from "node:path";
6
+ //#region src/internal/builders/vite/plugins/dev-html-prerender.ts
8
7
  const inlineScriptContents = {};
9
8
  /**
10
9
  * Pre-renders the HTML entrypoints when building the extension to connect to
@@ -48,7 +47,7 @@ function devHtmlPrerender(config, server) {
48
47
  const { document } = parseHTML(await server.transformHtml(url, html, originalUrl));
49
48
  document.querySelectorAll("script:not([src])").forEach((script) => {
50
49
  const textContent = script.textContent ?? "";
51
- const key = hash(textContent);
50
+ const key = c(textContent);
52
51
  inlineScriptContents[key] = textContent;
53
52
  const virtualScript = document.createElement("script");
54
53
  virtualScript.type = "module";
@@ -1,4 +1,4 @@
1
- //#region src/core/builders/vite/plugins/devServerGlobals.ts
1
+ //#region src/internal/builders/vite/plugins/dev-server-globals.ts
2
2
  /**
3
3
  * Defines global constants about the dev server. Helps scripts connect to the
4
4
  * server's web socket.
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- //#region src/core/builders/vite/plugins/extensionApiMock.ts
2
+ //#region src/internal/builders/vite/plugins/extension-api-mock.ts
3
3
  /**
4
4
  * Mock `wxt/browser` and stub the global `browser`/`chrome` types with a fake
5
5
  * version of the extension APIs
@@ -1,4 +1,4 @@
1
- //#region src/core/builders/vite/plugins/iifeAnonymous.ts
1
+ //#region src/internal/builders/vite/plugins/iife-anonymous.ts
2
2
  function iifeAnonymous(iifeReturnValueName) {
3
3
  return {
4
4
  name: "wxt:iife-anonymous",
@@ -1,4 +1,4 @@
1
- //#region src/core/builders/vite/plugins/iifeFooter.ts
1
+ //#region src/internal/builders/vite/plugins/iife-footer.ts
2
2
  /**
3
3
  * Add a footer with the returned value so it can return values to
4
4
  * `scripting.executeScript` Footer is added a part of esbuild to make sure it's
@@ -0,0 +1,17 @@
1
+ import "./resolve-virtual-modules.mjs";
2
+ import "./wxt-plugin-loader.mjs";
3
+ import "./add-entrypoint-group-runtime-env-entries.mjs";
4
+ import "./add-runtime-env-entries.mjs";
5
+ import "./bundle-analysis.mjs";
6
+ import "./css-entrypoints.mjs";
7
+ import "./define-import-meta.mjs";
8
+ import "./dev-html-prerender.mjs";
9
+ import "./dev-server-globals.mjs";
10
+ import "./extension-api-mock.mjs";
11
+ import "./iife-anonymous.mjs";
12
+ import "./iife-footer.mjs";
13
+ import "./noop-background.mjs";
14
+ import "./remove-entrypoint-main-function.mjs";
15
+ import "./resolve-app-config.mjs";
16
+ import "./tsconfig-paths.mjs";
17
+ export {};
@@ -1,5 +1,5 @@
1
- import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../../../utils/constants.mjs";
2
- //#region src/core/builders/vite/plugins/noopBackground.ts
1
+ import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../../../constants.mjs";
2
+ //#region src/internal/builders/vite/plugins/noop-background.ts
3
3
  /**
4
4
  * In dev mode, if there's not a background script listed, we need to add one so
5
5
  * that the web socket connection is setup and the extension reloads HTML pages
@@ -1,8 +1,7 @@
1
- import { normalizePath } from "../../../utils/paths.mjs";
2
- import "../../../utils/index.mjs";
3
- import { removeMainFunctionCode } from "../../../utils/transform.mjs";
1
+ import { normalizePath } from "../../../../internal-utils/path-utils.mjs";
2
+ import { removeMainFunctionCode } from "../../../transform.mjs";
4
3
  import { resolve } from "node:path";
5
- //#region src/core/builders/vite/plugins/removeEntrypointMainFunction.ts
4
+ //#region src/internal/builders/vite/plugins/remove-entrypoint-main-function.ts
6
5
  /**
7
6
  * Transforms entrypoints, removing the main function from the entrypoint if it
8
7
  * exists.
@@ -1,6 +1,6 @@
1
- import { pathExists } from "../../../utils/fs.mjs";
1
+ import { pathExists } from "../../../../internal-utils/fs-utils.mjs";
2
2
  import { resolve } from "node:path";
3
- //#region src/core/builders/vite/plugins/resolveAppConfig.ts
3
+ //#region src/internal/builders/vite/plugins/resolve-app-config.ts
4
4
  /**
5
5
  * When importing `virtual:app-config`, resolve it to the `app.config.ts` file
6
6
  * in the project.
@@ -1,9 +1,9 @@
1
- import { normalizePath } from "../../../utils/paths.mjs";
2
- import "../../../utils/index.mjs";
3
- import { virtualModuleNames } from "../../../utils/virtual-modules.mjs";
4
- import { readFile } from "node:fs/promises";
1
+ import { normalizePath } from "../../../../internal-utils/path-utils.mjs";
2
+ import { getEntrypointName } from "../../../../internal-utils/entrypoint-utils.mjs";
3
+ import { virtualModuleNames } from "../../../virtual-modules.mjs";
5
4
  import { resolve } from "path";
6
- //#region src/core/builders/vite/plugins/resolveVirtualModules.ts
5
+ import { readFile } from "node:fs/promises";
6
+ //#region src/internal/builders/vite/plugins/resolve-virtual-modules.ts
7
7
  /**
8
8
  * Resolve all the virtual modules to the `node_modules/wxt/dist/virtual`
9
9
  * directory.
@@ -24,7 +24,9 @@ function resolveVirtualModules(config) {
24
24
  filter: { id: new RegExp(`^${resolvedVirtualId}`) },
25
25
  async handler(id) {
26
26
  const inputPath = id.replace(resolvedVirtualId, "");
27
- return (await readFile(resolve(config.wxtModuleDir, `dist/virtual/${name}.mjs`), "utf-8")).replace(`virtual:user-${name}`, inputPath);
27
+ const template = await readFile(resolve(config.wxtModuleDir, `dist/virtual/${name}.mjs`), "utf-8");
28
+ const entrypointName = getEntrypointName(config.entrypointsDir, inputPath);
29
+ return template.replace(`virtual:user-${name}`, inputPath).replace("virtual:wxt-plugins", `virtual:wxt-plugins?entrypoint=${encodeURIComponent(entrypointName)}`);
28
30
  }
29
31
  }
30
32
  };
@@ -1,4 +1,4 @@
1
- //#region src/core/builders/vite/plugins/tsconfigPaths.ts
1
+ //#region src/internal/builders/vite/plugins/tsconfig-paths.ts
2
2
  function tsconfigPaths(config) {
3
3
  return {
4
4
  name: "wxt:aliases",
@@ -0,0 +1,77 @@
1
+ import { normalizePath } from "../../../../internal-utils/path-utils.mjs";
2
+ import { getEntrypointName } from "../../../../internal-utils/entrypoint-utils.mjs";
3
+ import { parseHTML } from "linkedom";
4
+ //#region src/internal/builders/vite/plugins/wxt-plugin-loader.ts
5
+ function getPluginModules(plugins, entrypoint) {
6
+ return plugins.map((plugin) => typeof plugin === "string" ? { module: plugin } : plugin).filter((plugin) => entrypoint == null || (plugin.apply?.(entrypoint) ?? true)).map((plugin) => plugin.module);
7
+ }
8
+ /**
9
+ * Resolve and load plugins for each entrypoint. This handles both JS
10
+ * entrypoints via the `virtual:wxt-plugins` import, and HTML files by adding
11
+ * `virtual:wxt-html-plugins` to the document's `<head>`. Accepts an optional
12
+ * `?entrypoint=<name>` query to evaluate plugin `apply` hooks per request.
13
+ *
14
+ * @param getEntrypoints Returns the most recently resolved entrypoints.
15
+ * Injected by the caller instead of read from a global, so this plugin
16
+ * doesn't depend on global `wxt` state.
17
+ */
18
+ function wxtPluginLoader(config, getEntrypoints) {
19
+ const virtualModuleId = "virtual:wxt-plugins";
20
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
21
+ const virtualHtmlModuleId = "virtual:wxt-html-plugins";
22
+ const resolvedVirtualHtmlModuleId = "\0" + virtualHtmlModuleId;
23
+ function getEntrypointFromId(id) {
24
+ const queryIndex = id.indexOf("?");
25
+ if (queryIndex === -1) return void 0;
26
+ const entrypointNameFromQueryParam = new URLSearchParams(id.slice(queryIndex)).get("entrypoint");
27
+ if (!entrypointNameFromQueryParam) return void 0;
28
+ return getEntrypoints().find((entry) => entry.name === entrypointNameFromQueryParam);
29
+ }
30
+ return {
31
+ name: "wxt:plugin-loader",
32
+ resolveId: {
33
+ filter: { id: [new RegExp(`^${virtualModuleId}`), new RegExp(`^${virtualHtmlModuleId}`)] },
34
+ handler(id) {
35
+ return "\0" + id;
36
+ }
37
+ },
38
+ load: {
39
+ filter: { id: [new RegExp(`^${resolvedVirtualModuleId}`), new RegExp(`^${resolvedVirtualHtmlModuleId}`)] },
40
+ handler(id) {
41
+ const bareId = id.slice(1);
42
+ const entrypoint = getEntrypointFromId(bareId);
43
+ if (bareId === virtualModuleId || bareId.startsWith(`${virtualModuleId}?`)) {
44
+ const modules = getPluginModules(config.plugins, entrypoint);
45
+ return `${modules.map((module, i) => `import initPlugin${i} from '${normalizePath(module)}';`).join("\n")}\n\nexport function initPlugins() {\n${modules.map((_, i) => ` initPlugin${i}();`).join("\n")}\n}`;
46
+ } else return `import { initPlugins } from '${entrypoint ? `${virtualModuleId}?entrypoint=${encodeURIComponent(entrypoint.name)}` : virtualModuleId}';
47
+ try {
48
+ initPlugins();
49
+ } catch (err) {
50
+ console.error("[wxt] Failed to initialize plugins", err);
51
+ }`;
52
+ }
53
+ },
54
+ transformIndexHtml: {
55
+ order: "pre",
56
+ handler(html, ctx) {
57
+ const entrypointName = getEntrypointName(config.entrypointsDir, ctx.filename);
58
+ const entrypoint = getEntrypoints().find((entry) => entry.name === entrypointName);
59
+ const htmlModuleId = `${virtualHtmlModuleId}${entrypoint ? `?entrypoint=${encodeURIComponent(entrypoint.name)}` : ""}`;
60
+ const src = config.command === "serve" ? `${config.dev.server?.origin}/@id/${htmlModuleId}` : htmlModuleId;
61
+ const { document } = parseHTML(html);
62
+ if (document.querySelector(`script[src='${src}']`)) return;
63
+ const script = document.createElement("script");
64
+ script.type = "module";
65
+ script.src = src;
66
+ if (document.head == null) {
67
+ const newHead = document.createElement("head");
68
+ document.documentElement.prepend(newHead);
69
+ }
70
+ document.head?.prepend(script);
71
+ return document.toString();
72
+ }
73
+ }
74
+ };
75
+ }
76
+ //#endregion
77
+ export { getPluginModules, wxtPluginLoader };
@@ -1,5 +1,5 @@
1
- import { addViteConfig, defineWxtModule } from "../modules.mjs";
2
- //#region src/builtin-modules/escape-unicode.ts
1
+ import { addViteConfig, defineWxtModule } from "../../modules/index.mjs";
2
+ //#region src/internal/builtin-modules/escape-unicode.ts
3
3
  var escape_unicode_default = defineWxtModule({
4
4
  name: "wxt:built-in:escape-unicode",
5
5
  setup(wxt) {
@@ -1,5 +1,5 @@
1
- import { defineWxtModule } from "../modules.mjs";
2
- //#region src/builtin-modules/favicon-permission.ts
1
+ import { defineWxtModule } from "../../modules/index.mjs";
2
+ //#region src/internal/builtin-modules/favicon-permission.ts
3
3
  /**
4
4
  * Adds a template-literal type for the `_favicon/` paths served by Chrome's
5
5
  * favicon API when the `favicon` permission is declared. With this module,
@@ -1,11 +1,13 @@
1
1
  import favicon_permission_default from "./favicon-permission.mjs";
2
2
  import unimport_default from "./unimport.mjs";
3
3
  import escape_unicode_default from "./escape-unicode.mjs";
4
- //#region src/builtin-modules/index.ts
4
+ import plugins_default from "./plugins.mjs";
5
+ //#region src/internal/builtin-modules/index.ts
5
6
  const builtinModules = [
6
7
  unimport_default,
7
8
  favicon_permission_default,
8
- escape_unicode_default
9
+ escape_unicode_default,
10
+ plugins_default
9
11
  ];
10
12
  //#endregion
11
13
  export { builtinModules };
@@ -0,0 +1,21 @@
1
+ import { addViteConfig, defineWxtModule } from "../../modules/index.mjs";
2
+ import { resolveVirtualModules } from "../builders/vite/plugins/resolve-virtual-modules.mjs";
3
+ import { wxtPluginLoader } from "../builders/vite/plugins/wxt-plugin-loader.mjs";
4
+ //#region src/internal/builtin-modules/plugins.ts
5
+ /**
6
+ * Owns the virtual `wxt-plugins`/`wxt-html-plugins` modules used by
7
+ * `addWxtPlugin`. Keeps the latest resolved entrypoints in module-local state
8
+ * instead of on the global `wxt` object.
9
+ */
10
+ var plugins_default = defineWxtModule({
11
+ name: "wxt:built-in:plugins",
12
+ setup(wxt) {
13
+ let entrypoints = [];
14
+ wxt.hooks.hook("entrypoints:resolved", (_, resolved) => {
15
+ entrypoints = resolved;
16
+ });
17
+ addViteConfig(wxt, () => ({ plugins: [resolveVirtualModules(wxt.config), wxtPluginLoader(wxt.config, () => entrypoints)] }));
18
+ }
19
+ });
20
+ //#endregion
21
+ export { plugins_default as default };
@@ -1,7 +1,8 @@
1
- import { addViteConfig, defineWxtModule } from "../modules.mjs";
1
+ import { addViteConfig, defineWxtModule } from "../../modules/index.mjs";
2
+ import { extname } from "node:path";
2
3
  import { createUnimport, toExports } from "unimport";
3
4
  import UnimportPlugin from "unimport/unplugin";
4
- //#region src/builtin-modules/unimport.ts
5
+ //#region src/internal/builtin-modules/unimport.ts
5
6
  var unimport_default = defineWxtModule({
6
7
  name: "wxt:built-in:unimport",
7
8
  setup(wxt) {
@@ -25,7 +26,8 @@ var unimport_default = defineWxtModule({
25
26
  if (!isEnabled()) return;
26
27
  entries.push(await getImportsDeclarationEntry(unimport));
27
28
  if (!wxt.config.imports.eslintrc.enabled) return;
28
- entries.push(await getEslintConfigEntry(unimport, wxt.config.imports.eslintrc.enabled, wxt.config.imports));
29
+ const eslintConfigEntries = await getEslintConfigEntry(unimport, wxt.config.imports.eslintrc.enabled, wxt.config.imports);
30
+ entries.push(...eslintConfigEntries);
29
31
  });
30
32
  addViteConfig(wxt, () => ({ plugins: [UnimportPlugin.vite(wxt.config.imports)] }));
31
33
  }
@@ -55,22 +57,22 @@ async function getImportsModuleEntry(wxt, unimport) {
55
57
  tsReference: true
56
58
  };
57
59
  }
58
- async function getEslintConfigEntry(unimport, version, options) {
60
+ async function getEslintConfigEntry(unimport, configVersion, options) {
59
61
  const globals = (await unimport.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().reduce((globals, name) => {
60
62
  globals[name] = options.eslintrc.globalsPropValue;
61
63
  return globals;
62
64
  }, {});
63
- if (version <= 8) return getEslint8ConfigEntry(options, globals);
64
- else return getEslint9ConfigEntry(options, globals);
65
+ if (configVersion === 8) return getEslint8ConfigEntry(options, globals);
66
+ return getEslint9ConfigEntry(options, globals);
65
67
  }
66
68
  function getEslint8ConfigEntry(options, globals) {
67
- return {
69
+ return [{
68
70
  path: options.eslintrc.filePath,
69
71
  text: JSON.stringify({ globals }, null, 2) + "\n"
70
- };
72
+ }];
71
73
  }
72
74
  function getEslint9ConfigEntry(options, globals) {
73
- return {
75
+ const javaScriptFileEntry = {
74
76
  path: options.eslintrc.filePath,
75
77
  text: `const globals = ${JSON.stringify(globals, null, 2)}
76
78
 
@@ -84,6 +86,15 @@ export default {
84
86
  };
85
87
  `
86
88
  };
89
+ const ext = extname(options.eslintrc.filePath);
90
+ const declarationExt = ext === ".mjs" ? ".d.mts" : ext === ".cjs" ? ".d.cts" : ".d.ts";
91
+ return [javaScriptFileEntry, {
92
+ path: options.eslintrc.filePath.slice(0, -ext.length) + declarationExt,
93
+ text: `import type { ConfigObject } from "@eslint/core";
94
+ declare const config: ConfigObject;
95
+ export default config;
96
+ `
97
+ }];
87
98
  }
88
99
  //#endregion
89
100
  export { unimport_default as default };
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/constants.ts
1
+ //#region src/internal/constants.ts
2
2
  /**
3
3
  * Module ID used to build the background in dev mode if the extension doesn't
4
4
  * include a background script/service worker.
@@ -0,0 +1,9 @@
1
+ import { withFirstModule } from "../internal-utils/module-utils.mjs";
2
+ import { ViteBuilder } from "./builders/vite/index.mjs";
3
+ import { UnknownBuilder } from "./builders/unknown.mjs";
4
+ //#region src/internal/detect-builder.ts
5
+ function detectBuilder(config, hooks, getWxtDevServer) {
6
+ return withFirstModule(async () => new ViteBuilder(await import("vite"), config, hooks, getWxtDevServer), () => new UnknownBuilder());
7
+ }
8
+ //#endregion
9
+ export { detectBuilder };
@@ -1,7 +1,7 @@
1
- import { normalizePath } from "../paths.mjs";
2
- import { every, some } from "../arrays.mjs";
3
- import { wxt } from "../../wxt.mjs";
4
- //#region src/core/utils/building/detect-dev-changes.ts
1
+ import { normalizePath } from "../internal-utils/path-utils.mjs";
2
+ import { every, some } from "../internal-utils/array-utils.mjs";
3
+ import { wxt } from "./wxt.mjs";
4
+ //#region src/internal/detect-dev-changes.ts
5
5
  /**
6
6
  * Compare the changed files vs the build output and determine what kind of
7
7
  * reload needs to happen:
@@ -0,0 +1,11 @@
1
+ import { withFirstModule } from "../internal-utils/module-utils.mjs";
2
+ import { ManualRunner } from "./runners/manual.mjs";
3
+ import { WebExtRunner } from "./runners/web-ext.mjs";
4
+ //#region src/internal/detect-runner.ts
5
+ async function detectRunner(config) {
6
+ return withFirstModule(async () => {
7
+ return new WebExtRunner(await import("web-ext").then((mod) => mod.default), await import("web-ext/util/logger"), config);
8
+ }, () => new ManualRunner(config));
9
+ }
10
+ //#endregion
11
+ export { detectRunner };
@@ -0,0 +1,84 @@
1
+ import { CSS_EXTENSIONS_PATTERN } from "../../internal-utils/path-utils.mjs";
2
+ import { getEntrypointName } from "../../internal-utils/entrypoint-utils.mjs";
3
+ import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../constants.mjs";
4
+ import { resolve } from "node:path";
5
+ import { glob } from "tinyglobby";
6
+ import picomatch from "picomatch";
7
+ //#region src/internal/entrypoint-finders/flat.ts
8
+ const PATH_GLOB_TO_TYPE_MAP = {
9
+ "sandbox.html": "sandbox",
10
+ "sandbox/index.html": "sandbox",
11
+ "*.sandbox.html": "sandbox",
12
+ "*.sandbox/index.html": "sandbox",
13
+ "bookmarks.html": "bookmarks",
14
+ "bookmarks/index.html": "bookmarks",
15
+ "history.html": "history",
16
+ "history/index.html": "history",
17
+ "newtab.html": "newtab",
18
+ "newtab/index.html": "newtab",
19
+ "sidepanel.html": "sidepanel",
20
+ "sidepanel/index.html": "sidepanel",
21
+ "*.sidepanel.html": "sidepanel",
22
+ "*.sidepanel/index.html": "sidepanel",
23
+ "devtools.html": "devtools",
24
+ "devtools/index.html": "devtools",
25
+ "background.[jt]s": "background",
26
+ "background/index.[jt]s": "background",
27
+ [VIRTUAL_NOOP_BACKGROUND_MODULE_ID]: "background",
28
+ "content.[jt]s?(x)": "content-script",
29
+ "content/index.[jt]s?(x)": "content-script",
30
+ "*.content.[jt]s?(x)": "content-script",
31
+ "*.content/index.[jt]s?(x)": "content-script",
32
+ [`content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
33
+ [`*.content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
34
+ [`content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
35
+ [`*.content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
36
+ "popup.html": "popup",
37
+ "popup/index.html": "popup",
38
+ "options.html": "options",
39
+ "options/index.html": "options",
40
+ "*.html": "unlisted-page",
41
+ "*/index.html": "unlisted-page",
42
+ "*.[jt]s?(x)": "unlisted-script",
43
+ "*/index.[jt]s?(x)": "unlisted-script",
44
+ [`*.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
45
+ [`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
46
+ };
47
+ /**
48
+ * WXT's default entrypoint finder. It looks up entrypoints using a flat folder
49
+ * structure inside the `entrypoints.` directory, as described in the docs:
50
+ * https://wxt.dev/guide/essentials/entrypoints.html
51
+ */
52
+ var FlatEntrypointFinder = class {
53
+ constructor(config) {
54
+ this.config = config;
55
+ }
56
+ async findEntrypoints() {
57
+ const relativePaths = await glob(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
58
+ cwd: this.config.entrypointsDir,
59
+ expandDirectories: false
60
+ });
61
+ relativePaths.sort();
62
+ const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
63
+ return relativePaths.reduce((results, relativePath) => {
64
+ const inputPath = resolve(this.config.entrypointsDir, relativePath);
65
+ const name = getEntrypointName(this.config.entrypointsDir, inputPath);
66
+ const matchingGlob = pathGlobs.find((glob) => picomatch(glob)(relativePath));
67
+ if (matchingGlob) {
68
+ const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob];
69
+ results.push({
70
+ name,
71
+ inputPath,
72
+ type
73
+ });
74
+ }
75
+ return results;
76
+ }, []).filter(({ name, inputPath }, _, entrypointInfos) => {
77
+ if (inputPath.endsWith(".html")) return true;
78
+ if (!/index\..+$/.test(inputPath)) return true;
79
+ return !entrypointInfos.some((entry) => entry.name === name && entry.inputPath.endsWith("index.html"));
80
+ });
81
+ }
82
+ };
83
+ //#endregion
84
+ export { FlatEntrypointFinder };
@@ -0,0 +1,48 @@
1
+ import { parseHTML } from "linkedom";
2
+ //#region src/internal/environments/browser-environment.ts
3
+ function getBrowserEnvironmentGlobals() {
4
+ const { window, document, global } = parseHTML(`
5
+ <html>
6
+ <head></head>
7
+ <body></body>
8
+ </html>
9
+ `);
10
+ const location = createBuildTimeLocation("http://localhost/");
11
+ window.location = location;
12
+ global.location = location;
13
+ return {
14
+ ...global,
15
+ window,
16
+ document,
17
+ self: global,
18
+ location
19
+ };
20
+ }
21
+ /**
22
+ * A read-only stand-in for `location`. There is no page to navigate at build
23
+ * time, so `assign`, `reload` and `replace` do nothing rather than throw.
24
+ */
25
+ function createBuildTimeLocation(href) {
26
+ const url = new URL(href);
27
+ return {
28
+ ancestorOrigins: Object.assign([], {
29
+ contains: () => false,
30
+ item: () => null
31
+ }),
32
+ hash: url.hash,
33
+ host: url.host,
34
+ hostname: url.hostname,
35
+ href: url.href,
36
+ origin: url.origin,
37
+ pathname: url.pathname,
38
+ port: url.port,
39
+ protocol: url.protocol,
40
+ search: url.search,
41
+ assign: () => {},
42
+ reload: () => {},
43
+ replace: () => {},
44
+ toString: () => url.href
45
+ };
46
+ }
47
+ //#endregion
48
+ export { getBrowserEnvironmentGlobals };
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/environments/environment.ts
1
+ //#region src/internal/environments/environment.ts
2
2
  function createEnvironment(getGlobals) {
3
3
  const setup = () => {
4
4
  const envGlobals = getGlobals();
@@ -1,7 +1,7 @@
1
1
  import { createEnvironment } from "./environment.mjs";
2
2
  import { getBrowserEnvironmentGlobals } from "./browser-environment.mjs";
3
3
  import { fakeBrowser } from "@webext-core/fake-browser";
4
- //#region src/core/utils/environments/extension-environment.ts
4
+ //#region src/internal/environments/extension-environment.ts
5
5
  function createExtensionEnvironment() {
6
6
  return createEnvironment(getExtensionEnvironmentGlobals);
7
7
  }
@@ -1,19 +1,18 @@
1
- import { normalizePath } from "./paths.mjs";
2
- import { getEntrypointBundlePath, isHtmlEntrypoint } from "./entrypoints.mjs";
3
- import { filterTruthy, toArray } from "./arrays.mjs";
4
- import { wxt } from "../wxt.mjs";
5
- import { detectDevChanges, getRelevantDevChangedFiles } from "./building/detect-dev-changes.mjs";
6
- import { findEntrypoints } from "./building/find-entrypoints.mjs";
7
- import { groupEntrypoints } from "./building/group-entrypoints.mjs";
8
- import { getContentScriptJs, mapWxtOptionsToRegisteredContentScript } from "./content-scripts.mjs";
1
+ import { normalizePath } from "../internal-utils/path-utils.mjs";
2
+ import { getEntrypointBundlePath, isHtmlEntrypoint } from "../internal-utils/entrypoint-utils.mjs";
3
+ import { filterTruthy, toArray } from "../internal-utils/array-utils.mjs";
4
+ import { wxt } from "./wxt.mjs";
5
+ import { findEntrypoints } from "./find-entrypoints.mjs";
6
+ import { groupEntrypoints } from "./group-entrypoints.mjs";
7
+ import { getContentScriptJs, mapWxtOptionsToRegisteredContentScript } from "../internal-utils/content-script-utils.mjs";
9
8
  import { getContentScriptCssFiles, getContentScriptsCssMap } from "./manifest.mjs";
10
- import { rebuild } from "./building/rebuild.mjs";
11
- import "./building/index.mjs";
9
+ import { rebuild } from "./rebuild.mjs";
12
10
  import { isBabelSyntaxError, logBabelSyntaxError } from "./syntax-errors.mjs";
11
+ import { detectDevChanges, getRelevantDevChangedFiles } from "./detect-dev-changes.mjs";
13
12
  import { relative } from "node:path";
14
13
  import { styleText } from "node:util";
15
14
  import { withLock } from "superlock";
16
- //#region src/core/utils/create-file-reloader.ts
15
+ //#region src/internal/file-reloader.ts
17
16
  /**
18
17
  * Returns a function responsible for reloading different parts of the extension
19
18
  * when a file changes.