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,6 +1,6 @@
1
1
  import { dedupeDependencies, npm } from "./npm.mjs";
2
2
  import { x } from "tinyexec";
3
- //#region src/core/package-managers/yarn.ts
3
+ //#region src/internal/package-managers/yarn.ts
4
4
  const yarn = {
5
5
  overridesKey: "resolutions",
6
6
  downloadDependency(...args) {
@@ -1,7 +1,7 @@
1
- import { wxt } from "../wxt.mjs";
2
- import { readJson } from "./fs.mjs";
1
+ import { readJson } from "../internal-utils/fs-utils.mjs";
2
+ import { wxt } from "./wxt.mjs";
3
3
  import { resolve } from "node:path";
4
- //#region src/core/utils/package.ts
4
+ //#region src/internal/package.ts
5
5
  /**
6
6
  * Read the project's package.json.
7
7
  *
@@ -1,9 +1,9 @@
1
- import { wxt } from "../../wxt.mjs";
1
+ import { wxt } from "./wxt.mjs";
2
+ import { createSpinner } from "./spinner.mjs";
3
+ import { generateWxtDir } from "./generate-wxt-dir.mjs";
4
+ import { generateManifest, writeManifest } from "./manifest.mjs";
2
5
  import { buildEntrypoints } from "./build-entrypoints.mjs";
3
- import { createSpinner } from "../spinner.mjs";
4
- import { generateWxtDir } from "../../generate-wxt-dir.mjs";
5
- import { generateManifest, writeManifest } from "../manifest.mjs";
6
- //#region src/core/utils/building/rebuild.ts
6
+ //#region src/internal/rebuild.ts
7
7
  /**
8
8
  * Given a configuration, list of entrypoints, and an existing, partial output,
9
9
  * build the entrypoints and merge the new output with the existing output.
@@ -1,24 +1,19 @@
1
- import { builtinModules } from "../builtin-modules/index.mjs";
2
- import { normalizePath } from "./utils/paths.mjs";
3
- import "./utils/index.mjs";
4
- import { createFsCache } from "./utils/cache.mjs";
5
- import { getEslintVersion } from "./utils/eslint.mjs";
6
- import { safeStringToNumber } from "./utils/number.mjs";
7
- import { loadEnv } from "./utils/env.mjs";
1
+ import { normalizePath } from "../internal-utils/path-utils.mjs";
2
+ import { builtinModules } from "./builtin-modules/index.mjs";
3
+ import { pathExists } from "../internal-utils/fs-utils.mjs";
4
+ import { createFsCache } from "../internal-utils/cache-utils.mjs";
5
+ import { getEslintVersion } from "../internal-utils/eslint-utils.mjs";
6
+ import { safeStringToNumber } from "../internal-utils/number-utils.mjs";
7
+ import { loadEnv } from "../internal-utils/env-utils.mjs";
8
8
  import { v } from "../inline/get-port-please/index.mjs";
9
- import { createSafariRunner } from "./runners/safari.mjs";
10
- import { d } from "../inline/is-wsl/index.mjs";
11
- import { createWslRunner } from "./runners/wsl.mjs";
12
- import { createManualRunner } from "./runners/manual.mjs";
13
- import { createWxtLogger } from "./utils/log/wxtLogger.mjs";
14
- import { pathExists } from "./utils/fs.mjs";
15
- import { glob } from "tinyglobby";
9
+ import { createWxtLogger } from "../internal-utils/log/wxt-logger.mjs";
16
10
  import path from "node:path";
11
+ import { glob } from "tinyglobby";
17
12
  import { loadConfig } from "c12";
18
13
  import consola, { LogLevels } from "consola";
19
14
  import defu from "defu";
20
- import { fileURLToPath, pathToFileURL } from "node:url";
21
- //#region src/core/resolve-config.ts
15
+ import { fileURLToPath } from "node:url";
16
+ //#region src/internal/resolve-config.ts
22
17
  /**
23
18
  * Given an inline config, discover the config file if necessary, merge the
24
19
  * results, resolve any relative paths, and apply any defaults.
@@ -142,7 +137,7 @@ async function resolveConfig(inlineConfig, command) {
142
137
  wxtModuleDir,
143
138
  root,
144
139
  webExt,
145
- runner: command === "serve" ? await resolveRunner(browser, logger, webExt.config) : createManualRunner(),
140
+ runner: void 0,
146
141
  srcDir,
147
142
  typesDir,
148
143
  wxtDir,
@@ -363,7 +358,7 @@ async function getUnimportEslintOptions(logger, wxtDir, options) {
363
358
  }
364
359
  /** Returns the path to `node_modules/wxt`. */
365
360
  function resolveWxtModuleDir() {
366
- const url = import.meta.resolve("wxt", import.meta.url);
361
+ const url = import.meta.resolve("wxt");
367
362
  return path.resolve(fileURLToPath(url), "../..");
368
363
  }
369
364
  async function isDirMissing(dir) {
@@ -388,9 +383,8 @@ async function mergeBuilderConfig(logger, inlineConfig, userConfig) {
388
383
  throw Error("Builder not found. Make sure vite is installed.");
389
384
  }
390
385
  async function resolveWxtUserModules(root, modulesDir, modules = []) {
391
- const importer = pathToFileURL(path.join(root, "index.js")).href;
392
386
  const npmModules = await Promise.all(modules.map(async (moduleId) => {
393
- const mod = await import(import.meta.resolve(moduleId, importer));
387
+ const mod = await import(import.meta.resolve(moduleId));
394
388
  if (mod.default == null) throw Error("Module missing default export: " + moduleId);
395
389
  return {
396
390
  ...mod.default,
@@ -424,17 +418,5 @@ async function resolveWxtUserModules(root, modulesDir, modules = []) {
424
418
  }));
425
419
  return [...npmModules, ...localModules];
426
420
  }
427
- async function resolveRunner(browser, logger, webExt) {
428
- if (browser === "safari") return createSafariRunner();
429
- if (d) return createWslRunner();
430
- try {
431
- const { createWebExtRunner } = await import("./runners/web-ext.mjs");
432
- return webExt.disabled ? createManualRunner() : createWebExtRunner();
433
- } catch (err) {
434
- if (err?.code !== "ERR_MODULE_NOT_FOUND") throw err;
435
- logger.debug("Error loading the web-ext runner", err);
436
- }
437
- return createManualRunner();
438
- }
439
421
  //#endregion
440
422
  export { resolveConfig };
@@ -0,0 +1,22 @@
1
+ import { relative } from "node:path";
2
+ //#region src/internal/runners/manual.ts
3
+ /**
4
+ * Base runner that just tells developers to load the extension into their
5
+ * browser manually.
6
+ *
7
+ * You can extend this class and call any `super` method when your runner can't
8
+ * open the browser.
9
+ */
10
+ var ManualRunner = class {
11
+ constructor(config) {
12
+ this.config = config;
13
+ }
14
+ canOpen() {
15
+ return Promise.resolve(false);
16
+ }
17
+ async openBrowser() {
18
+ this.config.logger.info(`Load "${relative(process.cwd(), this.config.outDir)}" as an unpacked extension manually`);
19
+ }
20
+ };
21
+ //#endregion
22
+ export { ManualRunner };
@@ -0,0 +1,79 @@
1
+ import { d } from "../../inline/is-wsl/index.mjs";
2
+ import { formatDuration } from "../../internal-utils/time-utils.mjs";
3
+ import { mkdir } from "node:fs/promises";
4
+ import { relative } from "node:path";
5
+ import defu from "defu";
6
+ //#region src/internal/runners/web-ext.ts
7
+ /**
8
+ * WXT's default `ExtensionRunner` that uses web-ext to open the browser. It
9
+ * cannot open the browser automatically in some environments, like WSL.
10
+ */
11
+ var WebExtRunner = class {
12
+ instance;
13
+ constructor(webExt, logger, config) {
14
+ this.webExt = webExt;
15
+ this.logger = logger;
16
+ this.config = config;
17
+ }
18
+ async canOpen() {
19
+ return true;
20
+ }
21
+ async openBrowser() {
22
+ if (this.config.browser === "safari") return this.logManualReason("Cannot open Safari using web-ext");
23
+ if (d) return this.logManualReason("Cannot open browser when using WSL");
24
+ if (this.config.webExt.config.disabled) return this.config.logger.info(this.loadManualMessage());
25
+ const startTime = Date.now();
26
+ this.logger.consoleStream.write = ({ level, msg, name }) => {
27
+ if (level >= ERROR_LOG_LEVEL) this.config.logger.error(name, msg);
28
+ if (level >= WARN_LOG_LEVEL) this.config.logger.warn(msg);
29
+ };
30
+ const wxtUserConfig = this.config.webExt.config;
31
+ if (this.config.browser !== "firefox" && wxtUserConfig?.chromiumProfile) await mkdir(wxtUserConfig.chromiumProfile, { recursive: true });
32
+ const finalConfig = {
33
+ browserConsole: wxtUserConfig?.openConsole,
34
+ devtools: wxtUserConfig?.openDevtools,
35
+ startUrl: wxtUserConfig?.startUrls,
36
+ keepProfileChanges: wxtUserConfig?.keepProfileChanges,
37
+ chromiumPort: wxtUserConfig?.chromiumPort,
38
+ ...this.config.browser === "firefox" ? {
39
+ firefox: wxtUserConfig?.binaries?.firefox,
40
+ firefoxProfile: wxtUserConfig?.firefoxProfile,
41
+ pref: wxtUserConfig?.firefoxPref,
42
+ args: wxtUserConfig?.firefoxArgs
43
+ } : {
44
+ chromiumBinary: wxtUserConfig?.binaries?.[this.config.browser],
45
+ chromiumProfile: wxtUserConfig?.chromiumProfile,
46
+ chromiumPref: defu(wxtUserConfig?.chromiumPref, DEFAULT_CHROMIUM_PREFS),
47
+ args: ["--unsafely-disable-devtools-self-xss-warnings", ...wxtUserConfig?.chromiumArgs ?? []]
48
+ },
49
+ target: this.config.browser === "firefox" ? "firefox-desktop" : "chromium",
50
+ sourceDir: this.config.outDir,
51
+ noReloadManagerExtension: true,
52
+ noReload: true,
53
+ noInput: true
54
+ };
55
+ const options = { shouldExitProgram: false };
56
+ this.config.logger.debug("web-ext config:", finalConfig);
57
+ this.config.logger.debug("web-ext options:", options);
58
+ this.instance = await this.webExt.cmd.run(finalConfig, options);
59
+ const duration = Date.now() - startTime;
60
+ this.config.logger.success(`Opened browser in ${formatDuration(duration)}`);
61
+ }
62
+ async closeBrowser() {
63
+ await this.instance?.exit();
64
+ }
65
+ logManualReason(reason) {
66
+ this.config.logger.warn(`${reason}. ${this.loadManualMessage()}`);
67
+ }
68
+ loadManualMessage() {
69
+ return `Load "${relative(process.cwd(), this.config.outDir)}" as an unpacked extension manually`;
70
+ }
71
+ };
72
+ const WARN_LOG_LEVEL = 40;
73
+ const ERROR_LOG_LEVEL = 50;
74
+ const DEFAULT_CHROMIUM_PREFS = { devtools: { synced_preferences_sync_disabled: {
75
+ skipContentScripts: false,
76
+ "skip-content-scripts": false
77
+ } } };
78
+ //#endregion
79
+ export { WebExtRunner };
@@ -1,5 +1,5 @@
1
- //#region src/core/utils/globals.ts
2
- function getGlobals(config) {
1
+ //#region src/internal/runtime-env-entries.ts
2
+ function getRuntimeEnvEntries(config) {
3
3
  return [
4
4
  {
5
5
  name: "MANIFEST_VERSION",
@@ -43,7 +43,7 @@ function getGlobals(config) {
43
43
  }
44
44
  ];
45
45
  }
46
- function getEntrypointGlobals(entrypointName) {
46
+ function getEntrypointRuntimeEnvEntries(entrypointName) {
47
47
  return [{
48
48
  name: "ENTRYPOINT",
49
49
  value: entrypointName,
@@ -51,4 +51,4 @@ function getEntrypointGlobals(entrypointName) {
51
51
  }];
52
52
  }
53
53
  //#endregion
54
- export { getEntrypointGlobals, getGlobals };
54
+ export { getEntrypointRuntimeEnvEntries, getRuntimeEnvEntries };
@@ -1,5 +1,5 @@
1
1
  import { styleText } from "node:util";
2
- //#region src/core/utils/spinner.ts
2
+ //#region src/internal/spinner.ts
3
3
  function createSpinner(initialText = "", options = {}) {
4
4
  const { color = "cyan" } = options;
5
5
  const frames = [
@@ -1,7 +1,7 @@
1
- import { wxt } from "../wxt.mjs";
1
+ import { wxt } from "./wxt.mjs";
2
2
  import { relative } from "node:path";
3
3
  import { styleText } from "node:util";
4
- //#region src/core/utils/syntax-errors.ts
4
+ //#region src/internal/syntax-errors.ts
5
5
  function isBabelSyntaxError(error) {
6
6
  return error instanceof SyntaxError && error.code === "BABEL_PARSER_SYNTAX_ERROR";
7
7
  }
@@ -1,6 +1,6 @@
1
- import { normalizePath } from "./paths.mjs";
2
- import { wxt } from "../wxt.mjs";
3
- //#region src/core/utils/theme-icons.ts
1
+ import { normalizePath } from "../internal-utils/path-utils.mjs";
2
+ import { wxt } from "./wxt.mjs";
3
+ //#region src/internal/theme-icons.ts
4
4
  /**
5
5
  * Firefox only.
6
6
  *
@@ -1,5 +1,5 @@
1
1
  import { parseModule } from "magicast";
2
- //#region src/core/utils/transform.ts
2
+ //#region src/internal/transform.ts
3
3
  /**
4
4
  * Removes any code used at runtime related to an entrypoint's main function.
5
5
  *
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/validation.ts
1
+ //#region src/internal/validation.ts
2
2
  function validateEntrypoints(entrypoints) {
3
3
  const errors = entrypoints.flatMap((entrypoint) => {
4
4
  switch (entrypoint.type) {
@@ -1,10 +1,12 @@
1
- import { builtinModules } from "../builtin-modules/index.mjs";
2
- import { createViteBuilder } from "./builders/vite/index.mjs";
1
+ import { builtinModules } from "./builtin-modules/index.mjs";
3
2
  import { createWxtPackageManager } from "./package-managers/index.mjs";
4
3
  import { resolveConfig } from "./resolve-config.mjs";
5
- import { createHooks } from "hookable";
4
+ import { FlatEntrypointFinder } from "./entrypoint-finders/flat.mjs";
5
+ import { detectBuilder } from "./detect-builder.mjs";
6
+ import { detectRunner } from "./detect-runner.mjs";
6
7
  import { relative } from "path";
7
- //#region src/core/wxt.ts
8
+ import { createHooks } from "hookable";
9
+ //#region src/internal/wxt.ts
8
10
  /**
9
11
  * Global variable set once `createWxt` is called once. Since this variable is
10
12
  * used everywhere, this global can be used instead of passing the variable as a
@@ -12,14 +14,27 @@ import { relative } from "path";
12
14
  */
13
15
  let wxt;
14
16
  /**
15
- * Create and register a global instance of the Wxt interface for use throughout
16
- * the project.
17
+ * Create and register a global instance of the `Wxt` interface for use
18
+ * throughout the project.
17
19
  */
18
20
  async function registerWxt(command, inlineConfig = {}) {
19
21
  process.env.NODE_ENV ??= inlineConfig.mode ?? (command === "serve" ? "development" : "production");
20
22
  const hooks = createHooks();
21
23
  const config = await resolveConfig(inlineConfig, command);
22
- const [builder, pm] = await Promise.all([createViteBuilder(config, hooks, () => wxt.server), createWxtPackageManager(config.root)]);
24
+ const [pm, builder, runner] = await Promise.all([
25
+ createWxtPackageManager(config.root),
26
+ detectBuilder(config, hooks, () => wxt.server),
27
+ detectRunner(config)
28
+ ]);
29
+ const entrypointFinder = new FlatEntrypointFinder(config);
30
+ Object.defineProperty(config, "runner", {
31
+ get() {
32
+ return runner;
33
+ },
34
+ set(value) {
35
+ wxt.runner = value;
36
+ }
37
+ });
23
38
  wxt = {
24
39
  config,
25
40
  hooks,
@@ -39,6 +54,8 @@ async function registerWxt(command, inlineConfig = {}) {
39
54
  },
40
55
  pm,
41
56
  builder,
57
+ runner,
58
+ entrypointFinder,
42
59
  server: void 0
43
60
  };
44
61
  await initWxtModules();
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/arrays.ts
1
+ //#region src/internal-utils/array-utils.ts
2
2
  /** Checks if `predicate` returns truthy for all elements of the array. */
3
3
  function every(array, predicate) {
4
4
  for (let i = 0; i < array.length; i++) if (!predicate(array[i], i)) return false;
@@ -1,7 +1,7 @@
1
- import { writeFileIfDifferent } from "./fs.mjs";
2
- import { mkdir, readFile } from "node:fs/promises";
1
+ import { writeFileIfDifferent } from "./fs-utils.mjs";
3
2
  import { dirname, resolve } from "path";
4
- //#region src/core/utils/cache.ts
3
+ import { mkdir, readFile } from "node:fs/promises";
4
+ //#region src/internal-utils/cache-utils.ts
5
5
  /**
6
6
  * A basic file system cache stored at `<srcDir>/.wxt/cache/<key>`. Just caches
7
7
  * a string in a file for the given key.
@@ -1,5 +1,5 @@
1
- import { getEntrypointBundlePath } from "./entrypoints.mjs";
2
- //#region src/core/utils/content-scripts.ts
1
+ import { getEntrypointBundlePath } from "./entrypoint-utils.mjs";
2
+ //#region src/internal-utils/content-script-utils.ts
3
3
  /**
4
4
  * Returns a unique and consistent string hash based on a content scripts
5
5
  * options.
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/content-security-policy.ts
1
+ //#region src/internal-utils/csp-utils.ts
2
2
  var ContentSecurityPolicy = class ContentSecurityPolicy {
3
3
  static DIRECTIVE_ORDER = {
4
4
  "default-src": 0,
@@ -1,6 +1,6 @@
1
- import { Entrypoint } from "../../types.mjs";
1
+ import { Entrypoint } from "../types.mjs";
2
2
 
3
- //#region src/core/utils/entrypoints.d.ts
3
+ //#region src/internal-utils/entrypoint-utils.d.ts
4
4
  /**
5
5
  * Return's the entrypoint's output path relative to the output directory. Used
6
6
  * for paths in the manifest and rollup's bundle.
@@ -1,6 +1,6 @@
1
- import { normalizePath } from "./paths.mjs";
1
+ import { normalizePath } from "./path-utils.mjs";
2
2
  import path, { extname, relative, resolve } from "node:path";
3
- //#region src/core/utils/entrypoints.ts
3
+ //#region src/internal-utils/entrypoint-utils.ts
4
4
  function getEntrypointName(entrypointsDir, inputPath) {
5
5
  return path.relative(entrypointsDir, inputPath).split(/[./\\]/, 2)[0];
6
6
  }
@@ -1,7 +1,7 @@
1
- import { expand } from "dotenv-expand";
1
+ import dotenv_expand_default from "../inline/dotenv-expand/index.mjs";
2
2
  import { existsSync, readFileSync } from "node:fs";
3
3
  import { parseEnv } from "node:util";
4
- //#region src/core/utils/env.ts
4
+ //#region src/internal-utils/env-utils.ts
5
5
  /** Returns true when running in a CI environment. */
6
6
  function isCI() {
7
7
  return !!process.env.CI && process.env.CI !== "false";
@@ -27,7 +27,7 @@ function loadEnv(mode, browser) {
27
27
  return [];
28
28
  }
29
29
  }));
30
- expand({ parsed });
30
+ dotenv_expand_default.expand({ parsed });
31
31
  return parsed;
32
32
  }
33
33
  //#endregion
@@ -0,0 +1,8 @@
1
+ import { tryImport } from "./module-utils.mjs";
2
+ //#region src/internal-utils/eslint-utils.ts
3
+ async function getEslintVersion() {
4
+ const mod = await tryImport(() => import("eslint"));
5
+ return mod ? mod.ESLint.version?.split(".") ?? [] : [];
6
+ }
7
+ //#endregion
8
+ export { getEslintVersion };
@@ -1,8 +1,5 @@
1
- import { unnormalizePath } from "./paths.mjs";
2
- import { wxt } from "../wxt.mjs";
3
1
  import { access, readFile, writeFile } from "node:fs/promises";
4
- import { glob } from "tinyglobby";
5
- //#region src/core/utils/fs.ts
2
+ //#region src/internal-utils/fs-utils.ts
6
3
  async function pathExists(path) {
7
4
  try {
8
5
  await access(path);
@@ -25,17 +22,10 @@ async function readJson(path) {
25
22
  async function writeFileIfDifferent(file, newContents) {
26
23
  if (await readFile(file, "utf-8").catch(() => void 0) !== newContents) await writeFile(file, newContents);
27
24
  }
28
- async function getPublicFiles() {
29
- if (!await pathExists(wxt.config.publicDir)) return [];
30
- return (await glob("**/*", {
31
- cwd: wxt.config.publicDir,
32
- expandDirectories: false
33
- })).map(unnormalizePath);
34
- }
35
25
  function getBytesDisplay(bytes) {
36
26
  if (bytes < 1e3) return `${bytes} B`;
37
27
  if (bytes < 999995) return `${(bytes / 1e3).toFixed(2)} kB`;
38
28
  return `${(bytes / 1e6).toFixed(2)} MB`;
39
29
  }
40
30
  //#endregion
41
- export { getBytesDisplay, getPublicFiles, pathExists, readJson, writeFileIfDifferent };
31
+ export { getBytesDisplay, pathExists, readJson, writeFileIfDifferent };
@@ -0,0 +1,6 @@
1
+ import "./wxt-logger.mjs";
2
+ import "./print-table.mjs";
3
+ import "./print-file-list.mjs";
4
+ import "./print-build-summary.mjs";
5
+ import "./print-header.mjs";
6
+ export {};
@@ -1,7 +1,7 @@
1
- import { wxt } from "../../wxt.mjs";
2
- import { printFileList } from "./printFileList.mjs";
1
+ import { wxt } from "../../internal/wxt.mjs";
2
+ import { printFileList } from "./print-file-list.mjs";
3
3
  import { resolve } from "path";
4
- //#region src/core/utils/log/printBuildSummary.ts
4
+ //#region src/internal-utils/log/print-build-summary.ts
5
5
  async function printBuildSummary(log, header, output) {
6
6
  const files = [...output.steps.flatMap((step) => step.chunks), ...output.publicAssets].sort((l, r) => {
7
7
  const diff = getChunkSortWeight(l.fileName) - getChunkSortWeight(r.fileName);
@@ -1,19 +1,20 @@
1
- import { wxt } from "../../wxt.mjs";
2
- import { getBytesDisplay } from "../fs.mjs";
3
- import { printTable } from "./printTable.mjs";
1
+ import { getBytesDisplay } from "../fs-utils.mjs";
2
+ import { wxt } from "../../internal/wxt.mjs";
3
+ import { printTable } from "./print-table.mjs";
4
4
  import { lstat } from "node:fs/promises";
5
5
  import path from "node:path";
6
6
  import { styleText } from "node:util";
7
- //#region src/core/utils/log/printFileList.ts
7
+ //#region src/internal-utils/log/print-file-list.ts
8
8
  async function printFileList(log, header, baseDir, files) {
9
9
  let totalSize = 0;
10
10
  const fileRows = await Promise.all(files.map(async (file, i) => {
11
- const parts = [path.relative(process.cwd(), baseDir) + path.sep, path.relative(baseDir, file)];
11
+ const absoluteFile = path.resolve(baseDir, file);
12
+ const parts = [path.relative(process.cwd(), baseDir) + path.sep, path.relative(baseDir, absoluteFile)];
12
13
  const prefix = i === files.length - 1 ? " └─" : " ├─";
13
14
  const chunkColor = getChunkColor(file);
14
15
  let size = "";
15
16
  try {
16
- const stats = await lstat(file);
17
+ const stats = await lstat(absoluteFile);
17
18
  totalSize += stats.size;
18
19
  size = getBytesDisplay(stats.size);
19
20
  } catch (ex) {
@@ -1,7 +1,7 @@
1
- import { version } from "../../../version.mjs";
1
+ import { version } from "../../version.mjs";
2
2
  import { consola as consola$1 } from "consola";
3
3
  import { styleText } from "node:util";
4
- //#region src/core/utils/log/printHeader.ts
4
+ //#region src/internal-utils/log/print-header.ts
5
5
  function printHeader() {
6
6
  consola$1.log(`\n${styleText("gray", "WXT")} ${styleText(["bold", "gray"], version)}`);
7
7
  }
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/log/printTable.ts
1
+ //#region src/internal-utils/log/print-table.ts
2
2
  function printTable(log, header, rows, gap = 2) {
3
3
  if (rows.length === 0) return;
4
4
  const columnWidths = rows.reduce((widths, row) => {
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/log/wxtLogger.ts
1
+ //#region src/internal-utils/log/wxt-logger.ts
2
2
  const warned = /* @__PURE__ */ new Set();
3
3
  /**
4
4
  * Wraps a `Logger` with a `warnOnce`. The set of already-warned messages is
@@ -0,0 +1,32 @@
1
+ //#region src/internal-utils/module-utils.ts
2
+ /**
3
+ * Returns the result of the first mapper function that resolves successfully.
4
+ * If an error other than "module-not-found" is thrown, it is re-thrown
5
+ * immediately.
6
+ *
7
+ * @param mappers - An array of functions that dynamically import a module and
8
+ * return a value based on it.
9
+ * @returns The result of the first module that resolves successfully.
10
+ */
11
+ async function withFirstModule(...mappers) {
12
+ for (const map of mappers) try {
13
+ return await map();
14
+ } catch (err) {
15
+ if (!isModuleNotFound(err)) throw err;
16
+ }
17
+ throw Error("No optional modules found");
18
+ }
19
+ async function tryImport(fn) {
20
+ try {
21
+ return await fn();
22
+ } catch (err) {
23
+ if (isModuleNotFound(err)) return void 0;
24
+ throw err;
25
+ }
26
+ }
27
+ const MODULE_NOT_FOUND_CODE = "ERR_MODULE_NOT_FOUND";
28
+ function isModuleNotFound(err) {
29
+ return err?.code === MODULE_NOT_FOUND_CODE;
30
+ }
31
+ //#endregion
32
+ export { tryImport, withFirstModule };
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/number.ts
1
+ //#region src/internal-utils/number-utils.ts
2
2
  function safeStringToNumber(str) {
3
3
  const num = Number(str);
4
4
  return isNaN(num) ? null : num;
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/paths.d.ts
1
+ //#region src/internal-utils/path-utils.d.ts
2
2
  /**
3
3
  * Converts system paths to normalized bundler path. On Windows, this returns
4
4
  * paths with `/` instead of `\`.
@@ -1,6 +1,6 @@
1
- import normalize_path_default from "../../inline/normalize-path/index.mjs";
1
+ import normalize_path_default from "../inline/normalize-path/index.mjs";
2
2
  import path from "node:path";
3
- //#region src/core/utils/paths.ts
3
+ //#region src/internal-utils/path-utils.ts
4
4
  /**
5
5
  * Converts system paths to normalized bundler path. On Windows, this returns
6
6
  * paths with `/` instead of `\`.
@@ -1,5 +1,5 @@
1
- import { s } from "../../inline/scule/index.mjs";
2
- //#region src/core/utils/strings.ts
1
+ import { s } from "../inline/scule/index.mjs";
2
+ //#region src/internal-utils/string-utils.ts
3
3
  function kebabCaseAlphanumeric(str) {
4
4
  return str.toLowerCase().replace(/[^a-z0-9-\s]/g, "").replace(/\s+/g, "-");
5
5
  }
@@ -1,4 +1,4 @@
1
- //#region src/core/utils/time.ts
1
+ //#region src/internal-utils/time-utils.ts
2
2
  function formatDuration(duration) {
3
3
  if (duration < 1e3) return `${duration} ms`;
4
4
  if (duration < 1e4) return `${(duration / 1e3).toFixed(3)} s`;
@@ -1,6 +1,7 @@
1
+ import { styleText } from "node:util";
1
2
  import { Browser } from "@wxt-dev/browser";
2
3
 
3
- //#region src/core/utils/types.d.ts
4
+ //#region src/internal-utils/type-utils.d.ts
4
5
  type ManifestContentScript = NonNullable<Browser.runtime.Manifest['content_scripts']>[number];
5
6
  //#endregion
6
7
  export { ManifestContentScript };