wxt 0.21.4 → 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 (139) 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 +6 -6
  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/{core/utils/building → internal}/build-entrypoints.mjs +5 -5
  20. package/dist/internal/builders/unknown.mjs +22 -0
  21. package/dist/{core → internal}/builders/vite/index.mjs +136 -138
  22. package/dist/internal/builders/vite/plugins/add-entrypoint-group-runtime-env-entries.mjs +16 -0
  23. package/dist/internal/builders/vite/plugins/add-runtime-env-entries.mjs +14 -0
  24. package/dist/{core/builders/vite/plugins/bundleAnalysis.mjs → internal/builders/vite/plugins/bundle-analysis.mjs} +1 -1
  25. package/dist/{core/builders/vite/plugins/cssEntrypoints.mjs → internal/builders/vite/plugins/css-entrypoints.mjs} +2 -2
  26. package/dist/{core/builders/vite/plugins/defineImportMeta.mjs → internal/builders/vite/plugins/define-import-meta.mjs} +1 -1
  27. package/dist/{core/builders/vite/plugins/devHtmlPrerender.mjs → internal/builders/vite/plugins/dev-html-prerender.mjs} +4 -5
  28. package/dist/{core/builders/vite/plugins/devServerGlobals.mjs → internal/builders/vite/plugins/dev-server-globals.mjs} +1 -1
  29. package/dist/{core/builders/vite/plugins/extensionApiMock.mjs → internal/builders/vite/plugins/extension-api-mock.mjs} +1 -1
  30. package/dist/{core/builders/vite/plugins/iifeAnonymous.mjs → internal/builders/vite/plugins/iife-anonymous.mjs} +1 -1
  31. package/dist/{core/builders/vite/plugins/iifeFooter.mjs → internal/builders/vite/plugins/iife-footer.mjs} +1 -1
  32. package/dist/internal/builders/vite/plugins/index.mjs +17 -0
  33. package/dist/{core/builders/vite/plugins/noopBackground.mjs → internal/builders/vite/plugins/noop-background.mjs} +2 -2
  34. package/dist/{core/builders/vite/plugins/removeEntrypointMainFunction.mjs → internal/builders/vite/plugins/remove-entrypoint-main-function.mjs} +3 -4
  35. package/dist/{core/builders/vite/plugins/resolveAppConfig.mjs → internal/builders/vite/plugins/resolve-app-config.mjs} +2 -2
  36. package/dist/{core/builders/vite/plugins/resolveVirtualModules.mjs → internal/builders/vite/plugins/resolve-virtual-modules.mjs} +8 -6
  37. package/dist/{core/builders/vite/plugins/tsconfigPaths.mjs → internal/builders/vite/plugins/tsconfig-paths.mjs} +1 -1
  38. package/dist/internal/builders/vite/plugins/wxt-plugin-loader.mjs +77 -0
  39. package/dist/{builtin-modules → internal/builtin-modules}/escape-unicode.mjs +2 -2
  40. package/dist/{builtin-modules → internal/builtin-modules}/favicon-permission.mjs +2 -2
  41. package/dist/{builtin-modules → internal/builtin-modules}/index.mjs +4 -2
  42. package/dist/internal/builtin-modules/plugins.mjs +21 -0
  43. package/dist/{builtin-modules → internal/builtin-modules}/unimport.mjs +17 -6
  44. package/dist/{core/utils → internal}/constants.mjs +1 -1
  45. package/dist/internal/detect-builder.mjs +9 -0
  46. package/dist/{core/utils/building → internal}/detect-dev-changes.mjs +4 -4
  47. package/dist/internal/detect-runner.mjs +11 -0
  48. package/dist/internal/entrypoint-finders/flat.mjs +84 -0
  49. package/dist/internal/environments/browser-environment.mjs +48 -0
  50. package/dist/{core/utils → internal}/environments/environment.mjs +1 -1
  51. package/dist/{core/utils → internal}/environments/extension-environment.mjs +1 -1
  52. package/dist/{core/utils/create-file-reloader.mjs → internal/file-reloader.mjs} +10 -11
  53. package/dist/{core/utils/building → internal}/find-entrypoints.mjs +8 -73
  54. package/dist/{core → internal}/generate-wxt-dir.mjs +10 -10
  55. package/dist/internal/get-public-files.mjs +14 -0
  56. package/dist/{core/utils/building → internal}/group-entrypoints.mjs +1 -1
  57. package/dist/{core/utils → internal}/i18n.mjs +1 -1
  58. package/dist/{core/utils/building → internal}/internal-build.mjs +10 -10
  59. package/dist/{core → internal}/keyboard-shortcuts.mjs +1 -1
  60. package/dist/{core/utils → internal}/manifest.mjs +9 -9
  61. package/dist/{core → internal}/package-managers/bun.mjs +1 -1
  62. package/dist/{core → internal}/package-managers/deno.mjs +1 -1
  63. package/dist/{core → internal}/package-managers/index.mjs +1 -1
  64. package/dist/{core → internal}/package-managers/npm.mjs +1 -1
  65. package/dist/{core → internal}/package-managers/pnpm.mjs +1 -1
  66. package/dist/{core → internal}/package-managers/yarn.mjs +1 -1
  67. package/dist/{core/utils → internal}/package.mjs +3 -3
  68. package/dist/{core/utils/building → internal}/rebuild.mjs +5 -5
  69. package/dist/{core → internal}/resolve-config.mjs +14 -32
  70. package/dist/internal/runners/manual.mjs +22 -0
  71. package/dist/internal/runners/web-ext.mjs +79 -0
  72. package/dist/{core/utils/globals.mjs → internal/runtime-env-entries.mjs} +4 -4
  73. package/dist/{core/utils → internal}/spinner.mjs +1 -1
  74. package/dist/{core/utils → internal}/syntax-errors.mjs +2 -2
  75. package/dist/{core/utils → internal}/theme-icons.mjs +3 -3
  76. package/dist/{core/utils → internal}/transform.mjs +1 -1
  77. package/dist/{core/utils → internal}/validation.mjs +1 -1
  78. package/dist/{core → internal}/wxt.mjs +24 -7
  79. package/dist/{core/utils/arrays.mjs → internal-utils/array-utils.mjs} +1 -1
  80. package/dist/{core/utils/cache.mjs → internal-utils/cache-utils.mjs} +3 -3
  81. package/dist/{core/utils/content-scripts.mjs → internal-utils/content-script-utils.mjs} +2 -2
  82. package/dist/{core/utils/content-security-policy.mjs → internal-utils/csp-utils.mjs} +1 -1
  83. package/dist/{core/utils/entrypoints.d.mts → internal-utils/entrypoint-utils.d.mts} +2 -2
  84. package/dist/{core/utils/entrypoints.mjs → internal-utils/entrypoint-utils.mjs} +2 -2
  85. package/dist/{core/utils/env.mjs → internal-utils/env-utils.mjs} +3 -3
  86. package/dist/internal-utils/eslint-utils.mjs +8 -0
  87. package/dist/{core/utils/fs.mjs → internal-utils/fs-utils.mjs} +2 -12
  88. package/dist/internal-utils/log/index.mjs +6 -0
  89. package/dist/{core/utils/log/printBuildSummary.mjs → internal-utils/log/print-build-summary.mjs} +3 -3
  90. package/dist/{core/utils/log/printFileList.mjs → internal-utils/log/print-file-list.mjs} +7 -6
  91. package/dist/{core/utils/log/printHeader.mjs → internal-utils/log/print-header.mjs} +2 -2
  92. package/dist/{core/utils/log/printTable.mjs → internal-utils/log/print-table.mjs} +1 -1
  93. package/dist/{core/utils/log/wxtLogger.mjs → internal-utils/log/wxt-logger.mjs} +1 -1
  94. package/dist/internal-utils/module-utils.mjs +32 -0
  95. package/dist/{core/utils/number.mjs → internal-utils/number-utils.mjs} +1 -1
  96. package/dist/{core/utils/paths.d.mts → internal-utils/path-utils.d.mts} +1 -1
  97. package/dist/{core/utils/paths.mjs → internal-utils/path-utils.mjs} +2 -2
  98. package/dist/{core/utils/strings.mjs → internal-utils/string-utils.mjs} +2 -2
  99. package/dist/{core/utils/time.mjs → internal-utils/time-utils.mjs} +1 -1
  100. package/dist/{core/utils/types.d.mts → internal-utils/type-utils.d.mts} +2 -1
  101. package/dist/{modules.d.mts → modules/index.d.mts} +10 -4
  102. package/dist/{modules.mjs → modules/index.mjs} +14 -5
  103. package/dist/prepare.d.mts +6 -0
  104. package/dist/prepare.mjs +11 -0
  105. package/dist/testing/wxt-vitest-plugin.mjs +7 -7
  106. package/dist/types.d.mts +72 -19
  107. package/dist/utils/content-script-context.d.mts +1 -1
  108. package/dist/utils/content-script-ui/iframe.d.mts +5 -0
  109. package/dist/utils/content-script-ui/integrated.d.mts +5 -0
  110. package/dist/utils/content-script-ui/shadow-root.d.mts +5 -0
  111. package/dist/utils/content-script-ui/types.d.mts +23 -7
  112. package/dist/utils/internal/custom-events.d.mts +11 -1
  113. package/dist/utils/internal/custom-events.mjs +4 -0
  114. package/dist/version.mjs +1 -1
  115. package/dist/virtual/background-entrypoint.mjs +11 -0
  116. package/dist/{core/zip.d.mts → zip.d.mts} +2 -2
  117. package/dist/{core/zip.mjs → zip.mjs} +11 -13
  118. package/package.json +7 -7
  119. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +0 -16
  120. package/dist/core/builders/vite/plugins/globals.mjs +0 -14
  121. package/dist/core/builders/vite/plugins/index.mjs +0 -17
  122. package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +0 -56
  123. package/dist/core/define-config.d.mts +0 -6
  124. package/dist/core/index.d.mts +0 -10
  125. package/dist/core/index.mjs +0 -12
  126. package/dist/core/prepare.d.mts +0 -6
  127. package/dist/core/prepare.mjs +0 -12
  128. package/dist/core/runners/manual.mjs +0 -11
  129. package/dist/core/runners/safari.mjs +0 -14
  130. package/dist/core/runners/web-ext.mjs +0 -63
  131. package/dist/core/runners/wsl.mjs +0 -14
  132. package/dist/core/utils/building/index.mjs +0 -7
  133. package/dist/core/utils/environments/browser-environment.mjs +0 -18
  134. package/dist/core/utils/eslint.mjs +0 -11
  135. package/dist/core/utils/index.d.mts +0 -2
  136. package/dist/core/utils/index.mjs +0 -3
  137. package/dist/core/utils/log/index.mjs +0 -6
  138. /package/dist/{core/utils → internal}/environments/index.mjs +0 -0
  139. /package/dist/{core/utils → internal}/virtual-modules.mjs +0 -0
@@ -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
  }
@@ -64,13 +66,13 @@ async function getEslintConfigEntry(unimport, configVersion, options) {
64
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.
@@ -1,16 +1,13 @@
1
- import { CSS_EXTENSIONS_PATTERN } from "../paths.mjs";
2
- import { getEntrypointName, isHtmlEntrypoint, isJsEntrypoint, resolvePerBrowserOptions } from "../entrypoints.mjs";
3
- import { s } from "../../../inline/scule/index.mjs";
4
- import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../constants.mjs";
5
- import { wxt } from "../../wxt.mjs";
6
- import { mkdir, readFile, writeFile } from "node:fs/promises";
7
- import { glob } from "tinyglobby";
1
+ import { isHtmlEntrypoint, isJsEntrypoint, resolvePerBrowserOptions } from "../internal-utils/entrypoint-utils.mjs";
2
+ import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "./constants.mjs";
3
+ import { s } from "../inline/scule/index.mjs";
4
+ import { wxt } from "./wxt.mjs";
8
5
  import { relative, resolve } from "path";
6
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
9
7
  import { parseHTML } from "linkedom";
10
- import { styleText } from "node:util";
11
- import picomatch from "picomatch";
12
8
  import JSON5 from "json5";
13
- //#region src/core/utils/building/find-entrypoints.ts
9
+ import { styleText } from "node:util";
10
+ //#region src/internal/find-entrypoints.ts
14
11
  /**
15
12
  * Return entrypoints and their configuration by looking through the project's
16
13
  * files.
@@ -22,30 +19,7 @@ async function findEntrypoints() {
22
19
  } catch (err) {
23
20
  if (!(err instanceof Error) || !("code" in err) || err.code !== "EEXIST") throw err;
24
21
  }
25
- const relativePaths = await glob(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
26
- cwd: wxt.config.entrypointsDir,
27
- expandDirectories: false
28
- });
29
- relativePaths.sort();
30
- const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
31
- const entrypointInfos = relativePaths.reduce((results, relativePath) => {
32
- const inputPath = resolve(wxt.config.entrypointsDir, relativePath);
33
- const name = getEntrypointName(wxt.config.entrypointsDir, inputPath);
34
- const matchingGlob = pathGlobs.find((glob) => picomatch(glob)(relativePath));
35
- if (matchingGlob) {
36
- const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob];
37
- results.push({
38
- name,
39
- inputPath,
40
- type
41
- });
42
- }
43
- return results;
44
- }, []).filter(({ name, inputPath }, _, entrypointInfos) => {
45
- if (inputPath.endsWith(".html")) return true;
46
- if (!/index\..+$/.test(inputPath)) return true;
47
- return !entrypointInfos.some((entry) => entry.name === name && entry.inputPath.endsWith("index.html"));
48
- });
22
+ const entrypointInfos = await wxt.entrypointFinder.findEntrypoints();
49
23
  await wxt.hooks.callHook("entrypoints:found", wxt, entrypointInfos);
50
24
  preventNoEntrypoints(entrypointInfos);
51
25
  preventDuplicateEntrypointNames(entrypointInfos);
@@ -256,45 +230,6 @@ function isEntrypointSkipped(entry) {
256
230
  if (include?.length && !exclude?.length) return !include.includes(wxt.config.browser);
257
231
  return false;
258
232
  }
259
- const PATH_GLOB_TO_TYPE_MAP = {
260
- "sandbox.html": "sandbox",
261
- "sandbox/index.html": "sandbox",
262
- "*.sandbox.html": "sandbox",
263
- "*.sandbox/index.html": "sandbox",
264
- "bookmarks.html": "bookmarks",
265
- "bookmarks/index.html": "bookmarks",
266
- "history.html": "history",
267
- "history/index.html": "history",
268
- "newtab.html": "newtab",
269
- "newtab/index.html": "newtab",
270
- "sidepanel.html": "sidepanel",
271
- "sidepanel/index.html": "sidepanel",
272
- "*.sidepanel.html": "sidepanel",
273
- "*.sidepanel/index.html": "sidepanel",
274
- "devtools.html": "devtools",
275
- "devtools/index.html": "devtools",
276
- "background.[jt]s": "background",
277
- "background/index.[jt]s": "background",
278
- [VIRTUAL_NOOP_BACKGROUND_MODULE_ID]: "background",
279
- "content.[jt]s?(x)": "content-script",
280
- "content/index.[jt]s?(x)": "content-script",
281
- "*.content.[jt]s?(x)": "content-script",
282
- "*.content/index.[jt]s?(x)": "content-script",
283
- [`content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
284
- [`*.content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
285
- [`content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
286
- [`*.content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
287
- "popup.html": "popup",
288
- "popup/index.html": "popup",
289
- "options.html": "options",
290
- "options/index.html": "options",
291
- "*.html": "unlisted-page",
292
- "*/index.html": "unlisted-page",
293
- "*.[jt]s?(x)": "unlisted-script",
294
- "*/index.[jt]s?(x)": "unlisted-script",
295
- [`*.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
296
- [`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
297
- };
298
233
  const CONTENT_SCRIPT_OUT_DIR = "content-scripts";
299
234
  //#endregion
300
235
  export { findEntrypoints };
@@ -1,13 +1,13 @@
1
- import { normalizePath } from "./utils/paths.mjs";
2
- import { getEntrypointBundlePath, isHtmlEntrypoint } from "./utils/entrypoints.mjs";
3
- import "./utils/index.mjs";
4
- import { getEntrypointGlobals, getGlobals } from "./utils/globals.mjs";
1
+ import { normalizePath } from "../internal-utils/path-utils.mjs";
2
+ import { getEntrypointBundlePath, isHtmlEntrypoint } from "../internal-utils/entrypoint-utils.mjs";
3
+ import { pathExists, writeFileIfDifferent } from "../internal-utils/fs-utils.mjs";
4
+ import { getEntrypointRuntimeEnvEntries, getRuntimeEnvEntries } from "./runtime-env-entries.mjs";
5
5
  import { wxt } from "./wxt.mjs";
6
- import { getPublicFiles, pathExists, writeFileIfDifferent } from "./utils/fs.mjs";
7
- import { parseI18nMessages } from "./utils/i18n.mjs";
6
+ import { parseI18nMessages } from "./i18n.mjs";
7
+ import { getPublicFiles } from "./get-public-files.mjs";
8
8
  import { mkdir, readFile } from "node:fs/promises";
9
9
  import path, { dirname, relative, resolve } from "node:path";
10
- //#region src/core/generate-wxt-dir.ts
10
+ //#region src/internal/generate-wxt-dir.ts
11
11
  /**
12
12
  * Generate and write all the files inside the `InternalConfig.typesDir`
13
13
  * directory.
@@ -20,7 +20,7 @@ async function generateWxtDir(entrypoints) {
20
20
  });
21
21
  entries.push(await getPathsDeclarationEntry(entrypoints));
22
22
  entries.push(await getI18nDeclarationEntry());
23
- entries.push(await getGlobalsDeclarationEntry());
23
+ entries.push(await getRuntimeEnvDeclarationEntry());
24
24
  entries.push(await getTsConfigEntry());
25
25
  await wxt.hooks.callHook("prepare:types", wxt, entries);
26
26
  entries.push(getMainDeclarationEntry(entries));
@@ -129,13 +129,13 @@ declare module "wxt/browser" {
129
129
  tsReference: true
130
130
  };
131
131
  }
132
- async function getGlobalsDeclarationEntry() {
132
+ async function getRuntimeEnvDeclarationEntry() {
133
133
  return {
134
134
  path: "types/globals.d.ts",
135
135
  text: [
136
136
  "// Generated by wxt",
137
137
  "interface ImportMetaEnv {",
138
- ...[...getGlobals(wxt.config), ...getEntrypointGlobals("")].map((global) => ` readonly ${global.name}: ${global.type};`),
138
+ ...[...getRuntimeEnvEntries(wxt.config), ...getEntrypointRuntimeEnvEntries("")].map((global) => ` readonly ${global.name}: ${global.type};`),
139
139
  "}",
140
140
  "interface ImportMeta {",
141
141
  " readonly env: ImportMetaEnv",
@@ -0,0 +1,14 @@
1
+ import { unnormalizePath } from "../internal-utils/path-utils.mjs";
2
+ import { pathExists } from "../internal-utils/fs-utils.mjs";
3
+ import { wxt } from "./wxt.mjs";
4
+ import { glob } from "tinyglobby";
5
+ //#region src/internal/get-public-files.ts
6
+ async function getPublicFiles() {
7
+ if (!await pathExists(wxt.config.publicDir)) return [];
8
+ return (await glob("**/*", {
9
+ cwd: wxt.config.publicDir,
10
+ expandDirectories: false
11
+ })).map(unnormalizePath);
12
+ }
13
+ //#endregion
14
+ export { getPublicFiles };
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/building/group-entrypoints.ts
1
+ //#region src/internal/group-entrypoints.ts
2
2
  /**
3
3
  * Entrypoints are built in groups. HTML pages can all be built together in a
4
4
  * single step, content scripts must be build individually, etc.
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/i18n.ts
1
+ //#region src/internal/i18n.ts
2
2
  const predefinedMessages = {
3
3
  "@@extension_id": {
4
4
  message: "<browser.runtime.id>",
@@ -1,20 +1,20 @@
1
- import { unnormalizePath } from "../paths.mjs";
2
- import { isCI } from "../env.mjs";
3
- import { wxt } from "../../wxt.mjs";
1
+ import { unnormalizePath } from "../internal-utils/path-utils.mjs";
2
+ import { isCI } from "../internal-utils/env-utils.mjs";
3
+ import { formatDuration } from "../internal-utils/time-utils.mjs";
4
+ import { wxt } from "./wxt.mjs";
4
5
  import { findEntrypoints } from "./find-entrypoints.mjs";
5
6
  import { groupEntrypoints } from "./group-entrypoints.mjs";
6
- import { formatDuration } from "../time.mjs";
7
- import { printBuildSummary } from "../log/printBuildSummary.mjs";
8
- import "../log/index.mjs";
7
+ import { printBuildSummary } from "../internal-utils/log/print-build-summary.mjs";
8
+ import "../internal-utils/log/index.mjs";
9
9
  import { rebuild } from "./rebuild.mjs";
10
- import { ValidationError, validateEntrypoints } from "../validation.mjs";
10
+ import { ValidationError, validateEntrypoints } from "./validation.mjs";
11
11
  import { mkdir, rm } from "node:fs/promises";
12
- import { glob } from "tinyglobby";
13
12
  import { relative } from "node:path";
14
- import { mergeJsonOutputs } from "@aklinker1/rollup-plugin-visualizer";
13
+ import { glob } from "tinyglobby";
15
14
  import { styleText } from "node:util";
15
+ import { mergeJsonOutputs } from "@aklinker1/rollup-plugin-visualizer";
16
16
  import open from "tiny-open";
17
- //#region src/core/utils/building/internal-build.ts
17
+ //#region src/internal/internal-build.ts
18
18
  /**
19
19
  * Builds the extension based on an internal config. No more config discovery is
20
20
  * performed, the build is based on exactly what is passed in.
@@ -1,7 +1,7 @@
1
1
  import { wxt } from "./wxt.mjs";
2
2
  import { styleText } from "node:util";
3
3
  import readline from "node:readline";
4
- //#region src/core/keyboard-shortcuts.ts
4
+ //#region src/internal/keyboard-shortcuts.ts
5
5
  /** Function that creates a keyboard shortcut handler for the extension. */
6
6
  function createKeyboardShortcuts(server) {
7
7
  let rl;
@@ -1,15 +1,15 @@
1
- import { normalizePath } from "./paths.mjs";
2
- import { getEntrypointBundlePath } from "./entrypoints.mjs";
3
- import { wxt } from "../wxt.mjs";
4
- import { writeFileIfDifferent } from "./fs.mjs";
5
- import { ContentSecurityPolicy } from "./content-security-policy.mjs";
6
- import { hashContentScriptOptions, mapWxtOptionsToContentScript } from "./content-scripts.mjs";
1
+ import { normalizePath } from "../internal-utils/path-utils.mjs";
2
+ import { getEntrypointBundlePath } from "../internal-utils/entrypoint-utils.mjs";
3
+ import { writeFileIfDifferent } from "../internal-utils/fs-utils.mjs";
4
+ import { wxt } from "./wxt.mjs";
5
+ import { ContentSecurityPolicy } from "../internal-utils/csp-utils.mjs";
6
+ import { hashContentScriptOptions, mapWxtOptionsToContentScript } from "../internal-utils/content-script-utils.mjs";
7
7
  import { getPackageJson } from "./package.mjs";
8
8
  import { addDiscoveredThemeIcons } from "./theme-icons.mjs";
9
- import { mkdir } from "node:fs/promises";
10
9
  import { resolve } from "path";
10
+ import { mkdir } from "node:fs/promises";
11
11
  import defu from "defu";
12
- //#region src/core/utils/manifest.ts
12
+ //#region src/internal/manifest.ts
13
13
  /** Writes the manifest to the output directory and the build output. */
14
14
  async function writeManifest(manifest, output) {
15
15
  const str = wxt.config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
@@ -28,7 +28,7 @@ async function generateManifest(allEntrypoints, buildOutput) {
28
28
  let versionName = wxt.config.manifest.version_name ?? wxt.config.manifest.version ?? pkg?.version;
29
29
  if (versionName == null) {
30
30
  versionName = "0.0.0";
31
- wxt.logger.warnOnce("Extension version not found, defaulting to \"0.0.0\". Add a version to your `package.json` or `wxt.config.ts` file. For more details, see: https://wxt.dev/guide/key-concepts/manifest.html#version-and-version-name");
31
+ wxt.logger.warnOnce("Extension version not found, defaulting to \"0.0.0\". Add a version to your `package.json` or `wxt.config.ts` file. For more details, see: https://wxt.dev/guide/essentials/config/manifest.html#version-and-version-name");
32
32
  }
33
33
  const version = wxt.config.manifest.version ?? simplifyVersion(versionName);
34
34
  const baseManifest = {
@@ -1,6 +1,6 @@
1
1
  import { dedupeDependencies, npm } from "./npm.mjs";
2
2
  import { x } from "tinyexec";
3
- //#region src/core/package-managers/bun.ts
3
+ //#region src/internal/package-managers/bun.ts
4
4
  const bun = {
5
5
  overridesKey: "overrides",
6
6
  downloadDependency(...args) {
@@ -1,4 +1,4 @@
1
- //#region src/core/package-managers/deno.ts
1
+ //#region src/internal/package-managers/deno.ts
2
2
  const deno = {
3
3
  overridesKey: "na",
4
4
  downloadDependency() {
@@ -4,7 +4,7 @@ import { yarn } from "./yarn.mjs";
4
4
  import { pnpm } from "./pnpm.mjs";
5
5
  import { deno } from "./deno.mjs";
6
6
  import { addDependency, addDevDependency, detectPackageManager, ensureDependencyInstalled, installDependencies, removeDependency } from "nypm";
7
- //#region src/core/package-managers/index.ts
7
+ //#region src/internal/package-managers/index.ts
8
8
  async function createWxtPackageManager(root) {
9
9
  const pm = await detectPackageManager(root, { includeParentDirs: true });
10
10
  const requirePm = (cb) => {
@@ -1,7 +1,7 @@
1
1
  import { mkdir } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { x } from "tinyexec";
4
- //#region src/core/package-managers/npm.ts
4
+ //#region src/internal/package-managers/npm.ts
5
5
  const npm = {
6
6
  overridesKey: "overrides",
7
7
  async downloadDependency(id, downloadDir) {
@@ -1,6 +1,6 @@
1
1
  import { flattenNpmListOutput, npm } from "./npm.mjs";
2
2
  import { x } from "tinyexec";
3
- //#region src/core/package-managers/pnpm.ts
3
+ //#region src/internal/package-managers/pnpm.ts
4
4
  const pnpm = {
5
5
  overridesKey: "resolutions",
6
6
  downloadDependency(...args) {