wxt 0.20.18 → 0.20.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/bin/wxt-publish-extension.mjs +4 -3
  2. package/dist/browser.d.mts +7 -6
  3. package/dist/browser.mjs +6 -5
  4. package/dist/builtin-modules/index.mjs +1 -3
  5. package/dist/builtin-modules/unimport.mjs +1 -3
  6. package/dist/cli/cli-utils.mjs +5 -6
  7. package/dist/cli/commands.mjs +1 -3
  8. package/dist/cli/index.mjs +1 -3
  9. package/dist/core/build.d.mts +9 -8
  10. package/dist/core/build.mjs +10 -11
  11. package/dist/core/builders/vite/index.mjs +27 -25
  12. package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +1 -3
  13. package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +6 -6
  14. package/dist/core/builders/vite/plugins/defineImportMeta.mjs +3 -4
  15. package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +33 -25
  16. package/dist/core/builders/vite/plugins/devServerGlobals.mjs +3 -3
  17. package/dist/core/builders/vite/plugins/download.mjs +15 -11
  18. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +2 -6
  19. package/dist/core/builders/vite/plugins/extensionApiMock.mjs +13 -8
  20. package/dist/core/builders/vite/plugins/globals.mjs +1 -3
  21. package/dist/core/builders/vite/plugins/iifeAnonymous.mjs +1 -2
  22. package/dist/core/builders/vite/plugins/iifeFooter.mjs +14 -7
  23. package/dist/core/builders/vite/plugins/index.mjs +18 -19
  24. package/dist/core/builders/vite/plugins/noopBackground.mjs +14 -9
  25. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +10 -12
  26. package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +14 -10
  27. package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +15 -13
  28. package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +1 -2
  29. package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +22 -17
  30. package/dist/core/clean.d.mts +7 -7
  31. package/dist/core/clean.mjs +6 -7
  32. package/dist/core/create-server.d.mts +6 -5
  33. package/dist/core/create-server.mjs +12 -11
  34. package/dist/core/define-config.mjs +1 -2
  35. package/dist/core/define-web-ext-config.d.mts +3 -4
  36. package/dist/core/define-web-ext-config.mjs +4 -7
  37. package/dist/core/generate-wxt-dir.mjs +8 -9
  38. package/dist/core/index.mjs +10 -11
  39. package/dist/core/initialize.mjs +10 -11
  40. package/dist/core/keyboard-shortcuts.mjs +2 -6
  41. package/dist/core/package-managers/bun.mjs +1 -3
  42. package/dist/core/package-managers/deno.mjs +1 -2
  43. package/dist/core/package-managers/index.mjs +1 -3
  44. package/dist/core/package-managers/npm.mjs +3 -5
  45. package/dist/core/package-managers/pnpm.mjs +1 -3
  46. package/dist/core/package-managers/yarn.mjs +1 -3
  47. package/dist/core/prepare.mjs +1 -3
  48. package/dist/core/resolve-config.mjs +20 -23
  49. package/dist/core/runners/index.mjs +1 -3
  50. package/dist/core/runners/manual.mjs +2 -6
  51. package/dist/core/runners/safari.mjs +3 -4
  52. package/dist/core/runners/web-ext.mjs +2 -6
  53. package/dist/core/runners/wsl.mjs +3 -4
  54. package/dist/core/utils/arrays.mjs +4 -11
  55. package/dist/core/utils/building/build-entrypoints.mjs +8 -9
  56. package/dist/core/utils/building/detect-dev-changes.mjs +21 -13
  57. package/dist/core/utils/building/find-entrypoints.mjs +16 -11
  58. package/dist/core/utils/building/group-entrypoints.mjs +3 -4
  59. package/dist/core/utils/building/index.mjs +7 -8
  60. package/dist/core/utils/building/internal-build.mjs +13 -13
  61. package/dist/core/utils/building/rebuild.mjs +10 -10
  62. package/dist/core/utils/cache.mjs +6 -8
  63. package/dist/core/utils/constants.mjs +3 -4
  64. package/dist/core/utils/content-scripts.mjs +3 -4
  65. package/dist/core/utils/content-security-policy.mjs +2 -5
  66. package/dist/core/utils/entrypoints.mjs +6 -10
  67. package/dist/core/utils/env.mjs +2 -6
  68. package/dist/core/utils/environments/browser-environment.mjs +1 -3
  69. package/dist/core/utils/environments/environment.mjs +1 -2
  70. package/dist/core/utils/environments/extension-environment.mjs +1 -3
  71. package/dist/core/utils/environments/index.mjs +3 -4
  72. package/dist/core/utils/eslint.mjs +1 -2
  73. package/dist/core/utils/fs.mjs +23 -14
  74. package/dist/core/utils/globals.mjs +1 -2
  75. package/dist/core/utils/i18n.mjs +1 -2
  76. package/dist/core/utils/index.mjs +2 -3
  77. package/dist/core/utils/log/index.mjs +5 -6
  78. package/dist/core/utils/log/printBuildSummary.mjs +1 -3
  79. package/dist/core/utils/log/printFileList.mjs +3 -5
  80. package/dist/core/utils/log/printHeader.mjs +1 -3
  81. package/dist/core/utils/log/printTable.mjs +1 -2
  82. package/dist/core/utils/manifest.mjs +23 -31
  83. package/dist/core/utils/minimatch-multiple.mjs +5 -7
  84. package/dist/core/utils/network.mjs +3 -5
  85. package/dist/core/utils/number.mjs +1 -2
  86. package/dist/core/utils/package.mjs +3 -5
  87. package/dist/core/utils/paths.d.mts +2 -2
  88. package/dist/core/utils/paths.mjs +7 -9
  89. package/dist/core/utils/strings.mjs +4 -7
  90. package/dist/core/utils/syntax-errors.mjs +1 -3
  91. package/dist/core/utils/time.mjs +2 -5
  92. package/dist/core/utils/transform.mjs +8 -6
  93. package/dist/core/utils/validation.mjs +1 -2
  94. package/dist/core/utils/virtual-modules.mjs +9 -15
  95. package/dist/core/utils/wsl.mjs +2 -6
  96. package/dist/core/wxt.mjs +7 -9
  97. package/dist/core/zip.d.mts +1 -0
  98. package/dist/core/zip.mjs +11 -10
  99. package/dist/index.d.mts +0 -1
  100. package/dist/index.mjs +1 -2
  101. package/dist/modules.d.mts +64 -61
  102. package/dist/modules.mjs +70 -66
  103. package/dist/testing/fake-browser.mjs +1 -2
  104. package/dist/testing/index.mjs +1 -2
  105. package/dist/testing/wxt-vitest-plugin.d.mts +4 -2
  106. package/dist/testing/wxt-vitest-plugin.mjs +5 -5
  107. package/dist/types.d.mts +455 -435
  108. package/dist/utils/app-config.mjs +1 -3
  109. package/dist/utils/content-script-context.d.mts +49 -39
  110. package/dist/utils/content-script-context.mjs +36 -31
  111. package/dist/utils/content-script-ui/iframe.d.mts +12 -13
  112. package/dist/utils/content-script-ui/iframe.mjs +1 -3
  113. package/dist/utils/content-script-ui/integrated.d.mts +8 -7
  114. package/dist/utils/content-script-ui/integrated.mjs +1 -3
  115. package/dist/utils/content-script-ui/shadow-root.d.mts +37 -25
  116. package/dist/utils/content-script-ui/shadow-root.mjs +4 -7
  117. package/dist/utils/content-script-ui/shared.mjs +1 -3
  118. package/dist/utils/content-script-ui/types.d.mts +29 -34
  119. package/dist/utils/content-script-ui/types.mjs +1 -1
  120. package/dist/utils/define-app-config.d.mts +4 -3
  121. package/dist/utils/define-app-config.mjs +5 -5
  122. package/dist/utils/define-background.mjs +1 -2
  123. package/dist/utils/define-content-script.mjs +1 -2
  124. package/dist/utils/define-unlisted-script.mjs +1 -2
  125. package/dist/utils/define-wxt-plugin.mjs +1 -2
  126. package/dist/utils/inject-script.mjs +1 -3
  127. package/dist/utils/internal/custom-events.mjs +3 -4
  128. package/dist/utils/internal/location-watcher.mjs +4 -6
  129. package/dist/utils/internal/logger.mjs +2 -5
  130. package/dist/utils/match-patterns.mjs +2 -3
  131. package/dist/utils/split-shadow-root-css.d.mts +6 -2
  132. package/dist/utils/split-shadow-root-css.mjs +7 -4
  133. package/dist/utils/storage.mjs +2 -3
  134. package/dist/version.mjs +2 -3
  135. package/dist/virtual/background-entrypoint.mjs +4 -16
  136. package/dist/virtual/content-script-isolated-world-entrypoint.mjs +2 -7
  137. package/dist/virtual/content-script-main-world-entrypoint.mjs +2 -7
  138. package/dist/virtual/mock-browser.mjs +1 -3
  139. package/dist/virtual/reload-html.mjs +3 -10
  140. package/dist/virtual/unlisted-script-entrypoint.mjs +2 -7
  141. package/package.json +17 -19
@@ -1,11 +1,8 @@
1
1
  import { wxt } from "./wxt.mjs";
2
2
  import pc from "picocolors";
3
3
  import readline from "node:readline";
4
-
5
4
  //#region src/core/keyboard-shortcuts.ts
6
- /**
7
- * Function that creates a keyboard shortcut handler for the extension.
8
- */
5
+ /** Function that creates a keyboard shortcut handler for the extension. */
9
6
  function createKeyboardShortcuts(server) {
10
7
  let rl;
11
8
  const handleInput = (line) => {
@@ -28,6 +25,5 @@ function createKeyboardShortcuts(server) {
28
25
  }
29
26
  };
30
27
  }
31
-
32
28
  //#endregion
33
- export { createKeyboardShortcuts };
29
+ export { createKeyboardShortcuts };
@@ -1,6 +1,5 @@
1
1
  import { dedupeDependencies, npm } from "./npm.mjs";
2
2
  import spawn from "nano-spawn";
3
-
4
3
  //#region src/core/package-managers/bun.ts
5
4
  const bun = {
6
5
  overridesKey: "overrides",
@@ -16,6 +15,5 @@ const bun = {
16
15
  })));
17
16
  }
18
17
  };
19
-
20
18
  //#endregion
21
- export { bun };
19
+ export { bun };
@@ -8,6 +8,5 @@ const deno = {
8
8
  throw Error("Deno not supported");
9
9
  }
10
10
  };
11
-
12
11
  //#endregion
13
- export { deno };
12
+ export { deno };
@@ -4,7 +4,6 @@ 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
-
8
7
  //#region src/core/package-managers/index.ts
9
8
  async function createWxtPackageManager(root) {
10
9
  const pm = await detectPackageManager(root, { includeParentDirs: true });
@@ -54,6 +53,5 @@ const packageManagers = {
54
53
  yarn,
55
54
  deno
56
55
  };
57
-
58
56
  //#endregion
59
- export { createWxtPackageManager };
57
+ export { createWxtPackageManager };
@@ -1,12 +1,11 @@
1
- import { ensureDir } from "fs-extra";
1
+ import { mkdir } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import spawn from "nano-spawn";
4
-
5
4
  //#region src/core/package-managers/npm.ts
6
5
  const npm = {
7
6
  overridesKey: "overrides",
8
7
  async downloadDependency(id, downloadDir) {
9
- await ensureDir(downloadDir);
8
+ await mkdir(downloadDir, { recursive: true });
10
9
  const res = await spawn("npm", [
11
10
  "pack",
12
11
  id,
@@ -51,6 +50,5 @@ function dedupeDependencies(dependencies) {
51
50
  }
52
51
  });
53
52
  }
54
-
55
53
  //#endregion
56
- export { dedupeDependencies, flattenNpmListOutput, npm };
54
+ export { dedupeDependencies, flattenNpmListOutput, npm };
@@ -1,6 +1,5 @@
1
1
  import { flattenNpmListOutput, npm } from "./npm.mjs";
2
2
  import spawn from "nano-spawn";
3
-
4
3
  //#region src/core/package-managers/pnpm.ts
5
4
  const pnpm = {
6
5
  overridesKey: "resolutions",
@@ -19,6 +18,5 @@ const pnpm = {
19
18
  return flattenNpmListOutput(JSON.parse(res.stdout));
20
19
  }
21
20
  };
22
-
23
21
  //#endregion
24
- export { pnpm };
22
+ export { pnpm };
@@ -1,6 +1,5 @@
1
1
  import { dedupeDependencies, npm } from "./npm.mjs";
2
2
  import spawn from "nano-spawn";
3
-
4
3
  //#region src/core/package-managers/yarn.ts
5
4
  const yarn = {
6
5
  overridesKey: "resolutions",
@@ -29,6 +28,5 @@ const yarn = {
29
28
  return dedupeDependencies(dependencies);
30
29
  }
31
30
  };
32
-
33
31
  //#endregion
34
- export { yarn };
32
+ export { yarn };
@@ -2,13 +2,11 @@ import { registerWxt, wxt } from "./wxt.mjs";
2
2
  import { findEntrypoints } from "./utils/building/find-entrypoints.mjs";
3
3
  import { generateWxtDir } from "./generate-wxt-dir.mjs";
4
4
  import "./utils/building/index.mjs";
5
-
6
5
  //#region src/core/prepare.ts
7
6
  async function prepare(config) {
8
7
  await registerWxt("build", config);
9
8
  wxt.logger.info("Generating types...");
10
9
  await generateWxtDir(await findEntrypoints());
11
10
  }
12
-
13
11
  //#endregion
14
- export { prepare };
12
+ export { prepare };
@@ -1,27 +1,27 @@
1
- import { normalizePath } from "./utils/paths.mjs";
2
1
  import { createFsCache } from "./utils/cache.mjs";
2
+ import { normalizePath } from "./utils/paths.mjs";
3
3
  import "./utils/index.mjs";
4
4
  import { builtinModules } from "../builtin-modules/index.mjs";
5
5
  import { getEslintVersion } from "./utils/eslint.mjs";
6
6
  import { safeStringToNumber } from "./utils/number.mjs";
7
7
  import { loadEnv } from "./utils/env.mjs";
8
- import fs from "fs-extra";
9
- import glob from "fast-glob";
10
- import path from "node:path";
8
+ import { pathExists } from "./utils/fs.mjs";
9
+ import { glob } from "tinyglobby";
11
10
  import { loadConfig } from "c12";
12
- import { resolve as resolve$1 } from "import-meta-resolve";
11
+ import { resolve } from "import-meta-resolve";
12
+ import path from "node:path";
13
13
  import consola, { LogLevels } from "consola";
14
14
  import defu from "defu";
15
15
  import { getPort } from "get-port-please";
16
16
  import { fileURLToPath, pathToFileURL } from "node:url";
17
-
18
17
  //#region src/core/resolve-config.ts
19
18
  /**
20
- * Given an inline config, discover the config file if necessary, merge the results, resolve any
21
- * relative paths, and apply any defaults.
19
+ * Given an inline config, discover the config file if necessary, merge the
20
+ * results, resolve any relative paths, and apply any defaults.
22
21
  *
23
- * Inline config always has priority over user config. Cli flags are passed as inline config if set.
24
- * If unset, undefined is passed in, letting this function decide default values.
22
+ * Inline config always has priority over user config. Cli flags are passed as
23
+ * inline config if set. If unset, undefined is passed in, letting this function
24
+ * decide default values.
25
25
  */
26
26
  async function resolveConfig(inlineConfig, command) {
27
27
  let userConfig = {};
@@ -158,7 +158,8 @@ async function resolveManifestConfig(env, manifest) {
158
158
  return typeof manifest === "function" ? await manifest(env) : await (manifest ?? {});
159
159
  }
160
160
  /**
161
- * Merge the inline config and user config. Inline config is given priority. Defaults are not applied here.
161
+ * Merge the inline config and user config. Inline config is given priority.
162
+ * Defaults are not applied here.
162
163
  */
163
164
  async function mergeInlineConfig(inlineConfig, userConfig) {
164
165
  const imports = inlineConfig.imports === false || userConfig.imports === false ? false : userConfig.imports == null && inlineConfig.imports == null ? void 0 : defu(inlineConfig.imports ?? {}, userConfig.imports ?? {});
@@ -352,22 +353,18 @@ async function getUnimportEslintOptions(wxtDir, options) {
352
353
  globalsPropValue: true
353
354
  };
354
355
  }
355
- /**
356
- * Returns the path to `node_modules/wxt`.
357
- */
356
+ /** Returns the path to `node_modules/wxt`. */
358
357
  function resolveWxtModuleDir() {
359
- const url = resolve$1("wxt", import.meta.url);
358
+ const url = resolve("wxt", import.meta.url);
360
359
  return path.resolve(fileURLToPath(url), "../..");
361
360
  }
362
361
  async function isDirMissing(dir) {
363
- return !await fs.pathExists(dir);
362
+ return !await pathExists(dir);
364
363
  }
365
364
  function logMissingDir(logger, name, expected) {
366
365
  logger.warn(`${name} directory not found: ./${normalizePath(path.relative(process.cwd(), expected))}`);
367
366
  }
368
- /**
369
- * Map of `ConfigEnv` commands to their default modes.
370
- */
367
+ /** Map of `ConfigEnv` commands to their default modes. */
371
368
  const COMMAND_MODES = {
372
369
  build: "production",
373
370
  serve: "development"
@@ -385,7 +382,7 @@ async function mergeBuilderConfig(logger, inlineConfig, userConfig) {
385
382
  async function resolveWxtUserModules(root, modulesDir, modules = []) {
386
383
  const importer = pathToFileURL(path.join(root, "index.js")).href;
387
384
  const npmModules = await Promise.all(modules.map(async (moduleId) => {
388
- const mod = await import(resolve$1(moduleId, importer));
385
+ const mod = await import(resolve(moduleId, importer));
389
386
  if (mod.default == null) throw Error("Module missing default export: " + moduleId);
390
387
  return {
391
388
  ...mod.default,
@@ -395,7 +392,8 @@ async function resolveWxtUserModules(root, modulesDir, modules = []) {
395
392
  }));
396
393
  const localModulePaths = await glob(["*.[tj]s", "*/index.[tj]s"], {
397
394
  cwd: modulesDir,
398
- onlyFiles: true
395
+ onlyFiles: true,
396
+ expandDirectories: false
399
397
  }).catch(() => []);
400
398
  localModulePaths.sort();
401
399
  const localModules = await Promise.all(localModulePaths.map(async (file) => {
@@ -418,6 +416,5 @@ async function resolveWxtUserModules(root, modulesDir, modules = []) {
418
416
  }));
419
417
  return [...npmModules, ...localModules];
420
418
  }
421
-
422
419
  //#endregion
423
- export { resolveConfig };
420
+ export { resolveConfig };
@@ -4,7 +4,6 @@ import { createManualRunner } from "./manual.mjs";
4
4
  import { createSafariRunner } from "./safari.mjs";
5
5
  import { createWebExtRunner } from "./web-ext.mjs";
6
6
  import { createWslRunner } from "./wsl.mjs";
7
-
8
7
  //#region src/core/runners/index.ts
9
8
  async function createExtensionRunner() {
10
9
  if (wxt.config.browser === "safari") return createSafariRunner();
@@ -12,6 +11,5 @@ async function createExtensionRunner() {
12
11
  if (wxt.config.runnerConfig.config?.disabled) return createManualRunner();
13
12
  return createWebExtRunner();
14
13
  }
15
-
16
14
  //#endregion
17
- export { createExtensionRunner };
15
+ export { createExtensionRunner };
@@ -1,15 +1,11 @@
1
1
  import { wxt } from "../wxt.mjs";
2
2
  import { relative } from "node:path";
3
-
4
3
  //#region src/core/runners/manual.ts
5
- /**
6
- * The manual runner tells the user to load the unpacked extension manually.
7
- */
4
+ /** The manual runner tells the user to load the unpacked extension manually. */
8
5
  function createManualRunner() {
9
6
  return { async openBrowser() {
10
7
  wxt.logger.info(`Load "${relative(process.cwd(), wxt.config.outDir)}" as an unpacked extension manually`);
11
8
  } };
12
9
  }
13
-
14
10
  //#endregion
15
- export { createManualRunner };
11
+ export { createManualRunner };
@@ -1,15 +1,14 @@
1
1
  import { wxt } from "../wxt.mjs";
2
2
  import { relative } from "node:path";
3
-
4
3
  //#region src/core/runners/safari.ts
5
4
  /**
6
- * The Safari runner just logs a warning message because `web-ext` doesn't work with Safari.
5
+ * The Safari runner just logs a warning message because `web-ext` doesn't work
6
+ * with Safari.
7
7
  */
8
8
  function createSafariRunner() {
9
9
  return { async openBrowser() {
10
10
  wxt.logger.warn(`Cannot Safari using web-ext. Load "${relative(process.cwd(), wxt.config.outDir)}" as an unpacked extension manually`);
11
11
  } };
12
12
  }
13
-
14
13
  //#endregion
15
- export { createSafariRunner };
14
+ export { createSafariRunner };
@@ -1,11 +1,8 @@
1
1
  import { formatDuration } from "../utils/time.mjs";
2
2
  import { wxt } from "../wxt.mjs";
3
3
  import defu from "defu";
4
-
5
4
  //#region src/core/runners/web-ext.ts
6
- /**
7
- * Create an `ExtensionRunner` backed by `web-ext`.
8
- */
5
+ /** Create an `ExtensionRunner` backed by `web-ext`. */
9
6
  function createWebExtRunner() {
10
7
  let runner;
11
8
  return {
@@ -61,6 +58,5 @@ const DEFAULT_CHROMIUM_PREFS = { devtools: { synced_preferences_sync_disabled: {
61
58
  skipContentScripts: false,
62
59
  "skip-content-scripts": false
63
60
  } } };
64
-
65
61
  //#endregion
66
- export { createWebExtRunner };
62
+ export { createWebExtRunner };
@@ -1,15 +1,14 @@
1
1
  import { wxt } from "../wxt.mjs";
2
2
  import { relative } from "node:path";
3
-
4
3
  //#region src/core/runners/wsl.ts
5
4
  /**
6
- * The WSL runner just logs a warning message because `web-ext` doesn't work in WSL.
5
+ * The WSL runner just logs a warning message because `web-ext` doesn't work in
6
+ * WSL.
7
7
  */
8
8
  function createWslRunner() {
9
9
  return { async openBrowser() {
10
10
  wxt.logger.warn(`Cannot open browser when using WSL. Load "${relative(process.cwd(), wxt.config.outDir)}" as an unpacked extension manually`);
11
11
  } };
12
12
  }
13
-
14
13
  //#endregion
15
- export { createWslRunner };
14
+ export { createWslRunner };
@@ -1,27 +1,20 @@
1
1
  //#region src/core/utils/arrays.ts
2
- /**
3
- * Checks if `predicate` returns truthy for all elements of the array.
4
- */
2
+ /** Checks if `predicate` returns truthy for all elements of the array. */
5
3
  function every(array, predicate) {
6
4
  for (let i = 0; i < array.length; i++) if (!predicate(array[i], i)) return false;
7
5
  return true;
8
6
  }
9
- /**
10
- * Returns true when any of the predicates return true;
11
- */
7
+ /** Returns true when any of the predicates return true; */
12
8
  function some(array, predicate) {
13
9
  for (let i = 0; i < array.length; i++) if (predicate(array[i], i)) return true;
14
10
  return false;
15
11
  }
16
- /**
17
- * Convert an item or array to an array.
18
- */
12
+ /** Convert an item or array to an array. */
19
13
  function toArray(a) {
20
14
  return Array.isArray(a) ? a : [a];
21
15
  }
22
16
  function filterTruthy(array) {
23
17
  return array.filter((item) => !!item);
24
18
  }
25
-
26
19
  //#endregion
27
- export { every, filterTruthy, some, toArray };
20
+ export { every, filterTruthy, some, toArray };
@@ -1,10 +1,9 @@
1
1
  import { toArray } from "../arrays.mjs";
2
2
  import { wxt } from "../../wxt.mjs";
3
3
  import { getPublicFiles } from "../fs.mjs";
4
- import fs from "fs-extra";
4
+ import { copyFile, mkdir, writeFile } from "node:fs/promises";
5
5
  import { dirname, resolve } from "path";
6
6
  import pc from "picocolors";
7
-
8
7
  //#region src/core/utils/building/build-entrypoints.ts
9
8
  async function buildEntrypoints(groups, spinner) {
10
9
  const steps = [];
@@ -12,11 +11,12 @@ async function buildEntrypoints(groups, spinner) {
12
11
  const group = groups[i];
13
12
  const groupNames = toArray(group).map((e) => e.name);
14
13
  const groupNameColored = groupNames.join(pc.dim(", "));
15
- spinner.text = pc.dim(`[${i + 1}/${groups.length}]`) + ` ${groupNameColored}`;
14
+ spinner.update({ text: pc.dim(`[${i + 1}/${groups.length}]`) + ` ${groupNameColored}` });
16
15
  try {
17
16
  steps.push(await wxt.builder.build(group));
18
17
  } catch (err) {
19
- spinner.stop().clear();
18
+ spinner.stop();
19
+ spinner.clear();
20
20
  wxt.logger.error(err);
21
21
  throw Error(`Failed to build ${groupNames.join(", ")}`, { cause: err });
22
22
  }
@@ -36,9 +36,9 @@ async function copyPublicDirectory() {
36
36
  const publicAssets = [];
37
37
  for (const file of files) {
38
38
  const absoluteDest = resolve(wxt.config.outDir, file.relativeDest);
39
- await fs.ensureDir(dirname(absoluteDest));
40
- if ("absoluteSrc" in file) await fs.copyFile(file.absoluteSrc, absoluteDest);
41
- else await fs.writeFile(absoluteDest, file.contents, "utf8");
39
+ await mkdir(dirname(absoluteDest), { recursive: true });
40
+ if ("absoluteSrc" in file) await copyFile(file.absoluteSrc, absoluteDest);
41
+ else await writeFile(absoluteDest, file.contents, "utf8");
42
42
  publicAssets.push({
43
43
  type: "asset",
44
44
  fileName: file.relativeDest
@@ -46,6 +46,5 @@ async function copyPublicDirectory() {
46
46
  }
47
47
  return publicAssets;
48
48
  }
49
-
50
49
  //#endregion
51
- export { buildEntrypoints };
50
+ export { buildEntrypoints };
@@ -1,30 +1,38 @@
1
1
  import { normalizePath } from "../paths.mjs";
2
2
  import { every, some } from "../arrays.mjs";
3
3
  import { wxt } from "../../wxt.mjs";
4
-
5
4
  //#region src/core/utils/building/detect-dev-changes.ts
6
5
  /**
7
- * Compare the changed files vs the build output and determine what kind of reload needs to happen:
6
+ * Compare the changed files vs the build output and determine what kind of
7
+ * reload needs to happen:
8
8
  *
9
9
  * - Do nothing
10
- * - CSS or JS file associated with an HTML page is changed - this is handled automatically by the
11
- * dev server
10
+ *
11
+ * - CSS or JS file associated with an HTML page is changed - this is handled
12
+ * automatically by the dev server
12
13
  * - Change isn't used by any of the entrypoints
13
14
  * - Reload Content script
15
+ *
14
16
  * - CSS or JS file associated with a content script
15
17
  * - Background script will be told to reload the content script
16
18
  * - Reload HTML file
17
- * - HTML file itself is saved - HMR doesn't handle this because the HTML pages are pre-rendered
18
- * - Chrome is OK reloading the page when the HTML file is changed without reloading the whole
19
- * extension. Not sure about firefox, this might need to change to an extension reload
19
+ *
20
+ * - HTML file itself is saved - HMR doesn't handle this because the HTML pages
21
+ * are pre-rendered
22
+ * - Chrome is OK reloading the page when the HTML file is changed without
23
+ * reloading the whole extension. Not sure about firefox, this might need
24
+ * to change to an extension reload
20
25
  * - Reload extension
26
+ *
21
27
  * - Background script is changed
22
28
  * - Manifest is different
23
29
  * - Restart browser
24
- * - web-ext.config.ts (runner config changes)
30
+ *
31
+ * - Web-ext.config.ts (runner config changes)
25
32
  * - Full dev server restart
26
- * - wxt.config.ts (main config file)
27
- * - modules/* (any file related to WXT modules)
33
+ *
34
+ * - Wxt.config.ts (main config file)
35
+ * - Modules/* (any file related to WXT modules)
28
36
  * - .env (environment variable changed could effect build)
29
37
  */
30
38
  function detectDevChanges(changedFiles, currentOutput) {
@@ -68,7 +76,8 @@ function detectDevChanges(changedFiles, currentOutput) {
68
76
  };
69
77
  }
70
78
  /**
71
- * For a single change, return all the step of the build output that were effected by it.
79
+ * For a single change, return all the step of the build output that were
80
+ * effected by it.
72
81
  */
73
82
  function findEffectedSteps(changedFile, currentOutput) {
74
83
  const changes = [];
@@ -83,6 +92,5 @@ function findEffectedSteps(changedFile, currentOutput) {
83
92
  for (const step of currentOutput.steps) if (step.chunks.find((chunk) => isChunkEffected(chunk))) changes.push(step);
84
93
  return changes;
85
94
  }
86
-
87
95
  //#endregion
88
- export { detectDevChanges };
96
+ export { detectDevChanges };
@@ -2,27 +2,30 @@ import { CSS_EXTENSIONS_PATTERN } from "../paths.mjs";
2
2
  import { getEntrypointName, isHtmlEntrypoint, isJsEntrypoint, resolvePerBrowserOptions } from "../entrypoints.mjs";
3
3
  import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../constants.mjs";
4
4
  import { wxt } from "../../wxt.mjs";
5
- import fs from "fs-extra";
6
- import glob from "fast-glob";
5
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
6
+ import { glob } from "tinyglobby";
7
7
  import { relative, resolve } from "path";
8
8
  import { parseHTML } from "linkedom";
9
9
  import { camelCase } from "scule";
10
10
  import pc from "picocolors";
11
11
  import { minimatch } from "minimatch";
12
12
  import JSON5 from "json5";
13
-
14
13
  //#region src/core/utils/building/find-entrypoints.ts
15
14
  /**
16
- * Return entrypoints and their configuration by looking through the project's files.
15
+ * Return entrypoints and their configuration by looking through the project's
16
+ * files.
17
17
  */
18
18
  async function findEntrypoints() {
19
- await fs.mkdir(wxt.config.wxtDir, { recursive: true });
19
+ await mkdir(wxt.config.wxtDir, { recursive: true });
20
20
  try {
21
- await fs.writeJson(resolve(wxt.config.wxtDir, "tsconfig.json"), {}, { flag: "wx" });
21
+ await writeFile(resolve(wxt.config.wxtDir, "tsconfig.json"), JSON.stringify({}), { flag: "wx" });
22
22
  } catch (err) {
23
23
  if (!(err instanceof Error) || !("code" in err) || err.code !== "EEXIST") throw err;
24
24
  }
25
- const relativePaths = await glob(Object.keys(PATH_GLOB_TO_TYPE_MAP), { cwd: wxt.config.entrypointsDir });
25
+ const relativePaths = await glob(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
26
+ cwd: wxt.config.entrypointsDir,
27
+ expandDirectories: false
28
+ });
26
29
  relativePaths.sort();
27
30
  const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
28
31
  const entrypointInfos = relativePaths.reduce((results, relativePath) => {
@@ -104,9 +107,12 @@ async function importEntrypoints(infos) {
104
107
  })()]);
105
108
  return resMap;
106
109
  }
107
- /** Extract `manifest.` and `wxt.` options from meta tags, converting snake_case keys to camelCase */
110
+ /**
111
+ * Extract `manifest.` and `wxt.` options from meta tags, converting snake_case
112
+ * keys to camelCase
113
+ */
108
114
  async function importHtmlEntrypoint(info) {
109
- const { document } = parseHTML(await fs.readFile(info.inputPath, "utf-8"));
115
+ const { document } = parseHTML(await readFile(info.inputPath, "utf-8"));
110
116
  const metaTags = document.querySelectorAll("meta");
111
117
  const res = { title: document.querySelector("title")?.textContent || void 0 };
112
118
  metaTags.forEach((tag) => {
@@ -276,6 +282,5 @@ const PATH_GLOB_TO_TYPE_MAP = {
276
282
  [`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
277
283
  };
278
284
  const CONTENT_SCRIPT_OUT_DIR = "content-scripts";
279
-
280
285
  //#endregion
281
- export { findEntrypoints };
286
+ export { findEntrypoints };
@@ -1,7 +1,7 @@
1
1
  //#region src/core/utils/building/group-entrypoints.ts
2
2
  /**
3
- * Entrypoints are built in groups. HTML pages can all be built together in a single step,
4
- * content scripts must be build individually, etc.
3
+ * Entrypoints are built in groups. HTML pages can all be built together in a
4
+ * single step, content scripts must be build individually, etc.
5
5
  *
6
6
  * This function returns the entrypoints put into these types of groups.
7
7
  */
@@ -40,6 +40,5 @@ const ENTRY_TYPE_TO_GROUP_MAP = {
40
40
  "unlisted-style": "individual",
41
41
  "content-script-style": "individual"
42
42
  };
43
-
44
43
  //#endregion
45
- export { groupEntrypoints };
44
+ export { groupEntrypoints };
@@ -1,8 +1,7 @@
1
- import { buildEntrypoints } from "./build-entrypoints.mjs";
2
- import { detectDevChanges } from "./detect-dev-changes.mjs";
3
- import { findEntrypoints } from "./find-entrypoints.mjs";
4
- import { groupEntrypoints } from "./group-entrypoints.mjs";
5
- import { rebuild } from "./rebuild.mjs";
6
- import { internalBuild } from "./internal-build.mjs";
7
-
8
- export { };
1
+ import "./build-entrypoints.mjs";
2
+ import "./detect-dev-changes.mjs";
3
+ import "./find-entrypoints.mjs";
4
+ import "./group-entrypoints.mjs";
5
+ import "./rebuild.mjs";
6
+ import "./internal-build.mjs";
7
+ export {};
@@ -7,22 +7,22 @@ import { printBuildSummary } from "../log/printBuildSummary.mjs";
7
7
  import "../log/index.mjs";
8
8
  import { rebuild } from "./rebuild.mjs";
9
9
  import { ValidationError, validateEntrypoints } from "../validation.mjs";
10
- import fs from "fs-extra";
11
- import glob from "fast-glob";
10
+ import { mkdir, rm } from "node:fs/promises";
11
+ import { glob } from "tinyglobby";
12
12
  import { relative } from "node:path";
13
13
  import { mergeJsonOutputs } from "@aklinker1/rollup-plugin-visualizer";
14
14
  import pc from "picocolors";
15
15
  import { isCI } from "ci-info";
16
-
17
16
  //#region src/core/utils/building/internal-build.ts
18
17
  /**
19
- * Builds the extension based on an internal config. No more config discovery is performed, the
20
- * build is based on exactly what is passed in.
18
+ * Builds the extension based on an internal config. No more config discovery is
19
+ * performed, the build is based on exactly what is passed in.
21
20
  *
22
21
  * This function:
22
+ *
23
23
  * 1. Cleans the output directory
24
- * 2. Executes the rebuild function with a blank previous output so everything is built (see
25
- * `rebuild` for more details)
24
+ * 2. Executes the rebuild function with a blank previous output so everything is
25
+ * built (see `rebuild` for more details)
26
26
  * 3. Prints the summary
27
27
  */
28
28
  async function internalBuild() {
@@ -31,11 +31,11 @@ async function internalBuild() {
31
31
  const target = `${wxt.config.browser}-mv${wxt.config.manifestVersion}`;
32
32
  wxt.logger.info(`${verb} ${pc.cyan(target)} for ${pc.cyan(wxt.config.mode)} with ${pc.green(`${wxt.builder.name} ${wxt.builder.version}`)}`);
33
33
  const startTime = Date.now();
34
- await fs.rm(wxt.config.outDir, {
34
+ await rm(wxt.config.outDir, {
35
35
  recursive: true,
36
36
  force: true
37
37
  });
38
- await fs.ensureDir(wxt.config.outDir);
38
+ await mkdir(wxt.config.outDir, { recursive: true });
39
39
  const entrypoints = await findEntrypoints();
40
40
  wxt.logger.debug("Detected entrypoints:", entrypoints);
41
41
  const validationResults = validateEntrypoints(entrypoints);
@@ -63,14 +63,15 @@ async function internalBuild() {
63
63
  async function combineAnalysisStats() {
64
64
  const absolutePaths = (await glob(`${wxt.config.analysis.outputName}-*.json`, {
65
65
  cwd: wxt.config.analysis.outputDir,
66
- absolute: true
66
+ absolute: true,
67
+ expandDirectories: false
67
68
  })).map(unnormalizePath);
68
69
  await mergeJsonOutputs({
69
70
  inputs: absolutePaths,
70
71
  template: wxt.config.analysis.template,
71
72
  filename: wxt.config.analysis.outputFile
72
73
  });
73
- if (!wxt.config.analysis.keepArtifacts) await Promise.all(absolutePaths.map((statsFile) => fs.remove(statsFile)));
74
+ if (!wxt.config.analysis.keepArtifacts) await Promise.all(absolutePaths.map((statsFile) => rm(statsFile, { force: true })));
74
75
  }
75
76
  function printValidationResults({ errorCount, errors, warningCount }) {
76
77
  (errorCount > 0 ? wxt.logger.error : wxt.logger.warn)(`Entrypoint validation failed: ${errorCount} error${errorCount === 1 ? "" : "s"}, ${warningCount} warning${warningCount === 1 ? "" : "s"}`);
@@ -91,6 +92,5 @@ function printValidationResults({ errorCount, errors, warningCount }) {
91
92
  console.log();
92
93
  });
93
94
  }
94
-
95
95
  //#endregion
96
- export { internalBuild };
96
+ export { internalBuild };