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
@@ -2,30 +2,31 @@ import { wxt } from "../../wxt.mjs";
2
2
  import { buildEntrypoints } from "./build-entrypoints.mjs";
3
3
  import { generateWxtDir } from "../../generate-wxt-dir.mjs";
4
4
  import { generateManifest, writeManifest } from "../manifest.mjs";
5
-
5
+ import { createSpinner } from "nanospinner";
6
6
  //#region src/core/utils/building/rebuild.ts
7
7
  /**
8
- * Given a configuration, list of entrypoints, and an existing, partial output, build the
9
- * entrypoints and merge the new output with the existing output.
8
+ * Given a configuration, list of entrypoints, and an existing, partial output,
9
+ * build the entrypoints and merge the new output with the existing output.
10
10
  *
11
11
  * This function will:
12
+ *
12
13
  * 1. Generate the .wxt directory's types
13
14
  * 2. Build the `entrypointGroups` (and copies public files)
14
15
  * 3. Generate the latest manifest for all entrypoints
15
16
  * 4. Write the new manifest to the file system
16
17
  *
17
18
  * @param config Internal config containing all the project information.
18
- * @param allEntrypoints List of entrypoints used to generate the types inside .wxt directory.
19
+ * @param allEntrypoints List of entrypoints used to generate the types inside
20
+ * .wxt directory.
19
21
  * @param entrypointGroups The list of entrypoint groups to build.
20
- * @param existingOutput The previous output to combine the rebuild results into. An emptry array if
21
- * this is the first build.
22
+ * @param existingOutput The previous output to combine the rebuild results
23
+ * into. An empty array if this is the first build.
22
24
  */
23
25
  async function rebuild(allEntrypoints, entrypointGroups, existingOutput = {
24
26
  steps: [],
25
27
  publicAssets: []
26
28
  }) {
27
- const { default: ora } = await import("ora");
28
- const spinner = ora(`Preparing...`).start();
29
+ const spinner = createSpinner("Preparing...").start();
29
30
  await generateWxtDir(allEntrypoints).catch((err) => {
30
31
  wxt.logger.warn("Failed to update .wxt directory:", err);
31
32
  if (wxt.config.command === "build") throw err;
@@ -48,6 +49,5 @@ async function rebuild(allEntrypoints, entrypointGroups, existingOutput = {
48
49
  warnings: manifestWarnings
49
50
  };
50
51
  }
51
-
52
52
  //#endregion
53
- export { rebuild };
53
+ export { rebuild };
@@ -1,11 +1,10 @@
1
1
  import { writeFileIfDifferent } from "./fs.mjs";
2
- import fs, { ensureDir } from "fs-extra";
2
+ import { mkdir, readFile } from "node:fs/promises";
3
3
  import { dirname, resolve } from "path";
4
-
5
4
  //#region src/core/utils/cache.ts
6
5
  /**
7
- * A basic file system cache stored at `<srcDir>/.wxt/cache/<key>`. Just caches a string in a
8
- * file for the given key.
6
+ * A basic file system cache stored at `<srcDir>/.wxt/cache/<key>`. Just caches
7
+ * a string in a file for the given key.
9
8
  *
10
9
  * @param srcDir Absolute path to source directory. See `InternalConfig.srcDir`
11
10
  */
@@ -14,19 +13,18 @@ function createFsCache(wxtDir) {
14
13
  return {
15
14
  async set(key, value) {
16
15
  const path = getPath(key);
17
- await ensureDir(dirname(path));
16
+ await mkdir(dirname(path), { recursive: true });
18
17
  await writeFileIfDifferent(path, value);
19
18
  },
20
19
  async get(key) {
21
20
  const path = getPath(key);
22
21
  try {
23
- return await fs.readFile(path, "utf-8");
22
+ return await readFile(path, "utf-8");
24
23
  } catch {
25
24
  return;
26
25
  }
27
26
  }
28
27
  };
29
28
  }
30
-
31
29
  //#endregion
32
- export { createFsCache };
30
+ export { createFsCache };
@@ -1,9 +1,8 @@
1
1
  //#region src/core/utils/constants.ts
2
2
  /**
3
- * Module ID used to build the background in dev mode if the extension doesn't include a background
4
- * script/service worker.
3
+ * Module ID used to build the background in dev mode if the extension doesn't
4
+ * include a background script/service worker.
5
5
  */
6
6
  const VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
7
-
8
7
  //#endregion
9
- export { VIRTUAL_NOOP_BACKGROUND_MODULE_ID };
8
+ export { VIRTUAL_NOOP_BACKGROUND_MODULE_ID };
@@ -1,8 +1,8 @@
1
1
  import { getEntrypointBundlePath } from "./entrypoints.mjs";
2
-
3
2
  //#region src/core/utils/content-scripts.ts
4
3
  /**
5
- * Returns a unique and consistent string hash based on a content scripts options.
4
+ * Returns a unique and consistent string hash based on a content scripts
5
+ * options.
6
6
  *
7
7
  * It is able to recognize default values,
8
8
  */
@@ -56,6 +56,5 @@ function mapWxtOptionsToRegisteredContentScript(options, js, css) {
56
56
  function getContentScriptJs(config, entrypoint) {
57
57
  return [getEntrypointBundlePath(entrypoint, config.outDir, ".js")];
58
58
  }
59
-
60
59
  //#endregion
61
- export { getContentScriptJs, hashContentScriptOptions, mapWxtOptionsToContentScript, mapWxtOptionsToRegisteredContentScript };
60
+ export { getContentScriptJs, hashContentScriptOptions, mapWxtOptionsToContentScript, mapWxtOptionsToRegisteredContentScript };
@@ -14,9 +14,7 @@ var ContentSecurityPolicy = class ContentSecurityPolicy {
14
14
  }, {});
15
15
  else this.data = {};
16
16
  }
17
- /**
18
- * Ensure a set of values are listed under a directive.
19
- */
17
+ /** Ensure a set of values are listed under a directive. */
20
18
  add(directive, ...newValues) {
21
19
  const values = this.data[directive] ?? [];
22
20
  newValues.forEach((newValue) => {
@@ -31,6 +29,5 @@ var ContentSecurityPolicy = class ContentSecurityPolicy {
31
29
  }).map((entry) => entry.flat().join(" ")).join("; ") + ";";
32
30
  }
33
31
  };
34
-
35
32
  //#endregion
36
- export { ContentSecurityPolicy };
33
+ export { ContentSecurityPolicy };
@@ -1,6 +1,5 @@
1
1
  import { normalizePath } from "./paths.mjs";
2
2
  import path, { extname, relative, resolve } from "node:path";
3
-
4
3
  //#region src/core/utils/entrypoints.ts
5
4
  function getEntrypointName(entrypointsDir, inputPath) {
6
5
  return path.relative(entrypointsDir, inputPath).split(/[./\\]/, 2)[0];
@@ -9,15 +8,13 @@ function getEntrypointOutputFile(entrypoint, ext) {
9
8
  return resolve(entrypoint.outputDir, `${entrypoint.name}${ext}`);
10
9
  }
11
10
  /**
12
- * Return's the entrypoint's output path relative to the output directory. Used for paths in the
13
- * manifest and rollup's bundle.
11
+ * Return's the entrypoint's output path relative to the output directory. Used
12
+ * for paths in the manifest and rollup's bundle.
14
13
  */
15
14
  function getEntrypointBundlePath(entrypoint, outDir, ext) {
16
15
  return normalizePath(relative(outDir, getEntrypointOutputFile(entrypoint, ext)));
17
16
  }
18
- /**
19
- * Given an entrypoint option, resolve it's value based on a target browser.
20
- */
17
+ /** Given an entrypoint option, resolve it's value based on a target browser. */
21
18
  function resolvePerBrowserOption(option, browser) {
22
19
  if (typeof option === "object" && !Array.isArray(option)) return option[browser];
23
20
  return option;
@@ -25,8 +22,8 @@ function resolvePerBrowserOption(option, browser) {
25
22
  /**
26
23
  * Given an entrypoint option, resolve it's value based on a target browser.
27
24
  *
28
- * defaultIcon is special, it's the only key that's a record, which can confuse this function. So
29
- * it's been manually excluded from resolution.
25
+ * DefaultIcon is special, it's the only key that's a record, which can confuse
26
+ * this function. So it's been manually excluded from resolution.
30
27
  */
31
28
  function resolvePerBrowserOptions(options, browser) {
32
29
  return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, key === "defaultIcon" ? value : resolvePerBrowserOption(value, browser)]));
@@ -54,6 +51,5 @@ function isJsEntrypoint(entrypoint) {
54
51
  ".tsx"
55
52
  ].includes(ext);
56
53
  }
57
-
58
54
  //#endregion
59
- export { getEntrypointBundlePath, getEntrypointName, isHtmlEntrypoint, isJsEntrypoint, resolvePerBrowserOptions };
55
+ export { getEntrypointBundlePath, getEntrypointName, isHtmlEntrypoint, isJsEntrypoint, resolvePerBrowserOptions };
@@ -1,10 +1,7 @@
1
1
  import { config } from "dotenv";
2
2
  import { expand } from "dotenv-expand";
3
-
4
3
  //#region src/core/utils/env.ts
5
- /**
6
- * Load environment files based on the current mode and browser.
7
- */
4
+ /** Load environment files based on the current mode and browser. */
8
5
  function loadEnv(mode, browser) {
9
6
  return expand(config({
10
7
  quiet: true,
@@ -20,6 +17,5 @@ function loadEnv(mode, browser) {
20
17
  ]
21
18
  }));
22
19
  }
23
-
24
20
  //#endregion
25
- export { loadEnv };
21
+ export { loadEnv };
@@ -1,5 +1,4 @@
1
1
  import { parseHTML } from "linkedom";
2
-
3
2
  //#region src/core/utils/environments/browser-environment.ts
4
3
  function getBrowserEnvironmentGlobals() {
5
4
  const { window, document, global } = parseHTML(`
@@ -15,6 +14,5 @@ function getBrowserEnvironmentGlobals() {
15
14
  self: global
16
15
  };
17
16
  }
18
-
19
17
  //#endregion
20
- export { getBrowserEnvironmentGlobals };
18
+ export { getBrowserEnvironmentGlobals };
@@ -34,6 +34,5 @@ function applyGlobals(globals) {
34
34
  } catch {}
35
35
  });
36
36
  }
37
-
38
37
  //#endregion
39
- export { createEnvironment };
38
+ export { createEnvironment };
@@ -1,7 +1,6 @@
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
-
5
4
  //#region src/core/utils/environments/extension-environment.ts
6
5
  function createExtensionEnvironment() {
7
6
  return createEnvironment(getExtensionEnvironmentGlobals);
@@ -13,6 +12,5 @@ function getExtensionEnvironmentGlobals() {
13
12
  browser: fakeBrowser
14
13
  };
15
14
  }
16
-
17
15
  //#endregion
18
- export { createExtensionEnvironment, getExtensionEnvironmentGlobals };
16
+ export { createExtensionEnvironment, getExtensionEnvironmentGlobals };
@@ -1,4 +1,3 @@
1
- import { getBrowserEnvironmentGlobals } from "./browser-environment.mjs";
2
- import { createExtensionEnvironment, getExtensionEnvironmentGlobals } from "./extension-environment.mjs";
3
-
4
- export { };
1
+ import "./browser-environment.mjs";
2
+ import "./extension-environment.mjs";
3
+ export {};
@@ -7,6 +7,5 @@ async function getEslintVersion() {
7
7
  return [];
8
8
  }
9
9
  }
10
-
11
10
  //#endregion
12
- export { getEslintVersion };
11
+ export { getEslintVersion };
@@ -1,27 +1,36 @@
1
1
  import { unnormalizePath } from "./paths.mjs";
2
2
  import { wxt } from "../wxt.mjs";
3
- import fs from "fs-extra";
4
- import glob from "fast-glob";
5
-
3
+ import { access, readFile, writeFile } from "node:fs/promises";
4
+ import { glob } from "tinyglobby";
6
5
  //#region src/core/utils/fs.ts
6
+ async function pathExists(path) {
7
+ try {
8
+ await access(path);
9
+ return true;
10
+ } catch {
11
+ return false;
12
+ }
13
+ }
14
+ async function readJson(path) {
15
+ return JSON.parse(await readFile(path, "utf-8"));
16
+ }
7
17
  /**
8
- * Only write the contents to a file if it results in a change. This prevents unnecessary file
9
- * watchers from being triggered, like WXT's dev server or the TS language server in editors.
18
+ * Only write the contents to a file if it results in a change. This prevents
19
+ * unnecessary file watchers from being triggered, like WXT's dev server or the
20
+ * TS language server in editors.
10
21
  *
11
22
  * @param file The file to write to.
12
23
  * @param newContents The new text content to write.
13
24
  */
14
25
  async function writeFileIfDifferent(file, newContents) {
15
- if (await fs.readFile(file, "utf-8").catch(() => void 0) !== newContents) await fs.writeFile(file, newContents);
26
+ if (await readFile(file, "utf-8").catch(() => void 0) !== newContents) await writeFile(file, newContents);
16
27
  }
17
- /**
18
- * Get all the files in the project's public directory. Returned paths are relative to the
19
- * `config.publicDir`.
20
- */
21
28
  async function getPublicFiles() {
22
- if (!await fs.pathExists(wxt.config.publicDir)) return [];
23
- return (await glob("**/*", { cwd: wxt.config.publicDir })).map(unnormalizePath);
29
+ if (!await pathExists(wxt.config.publicDir)) return [];
30
+ return (await glob("**/*", {
31
+ cwd: wxt.config.publicDir,
32
+ expandDirectories: false
33
+ })).map(unnormalizePath);
24
34
  }
25
-
26
35
  //#endregion
27
- export { getPublicFiles, writeFileIfDifferent };
36
+ export { getPublicFiles, pathExists, readJson, writeFileIfDifferent };
@@ -50,6 +50,5 @@ function getEntrypointGlobals(entrypointName) {
50
50
  type: `string`
51
51
  }];
52
52
  }
53
-
54
53
  //#endregion
55
- export { getEntrypointGlobals, getGlobals };
54
+ export { getEntrypointGlobals, getGlobals };
@@ -39,6 +39,5 @@ function parseI18nMessages(messagesJson) {
39
39
  ...details
40
40
  }));
41
41
  }
42
-
43
42
  //#endregion
44
- export { parseI18nMessages };
43
+ export { parseI18nMessages };
@@ -1,3 +1,2 @@
1
- import { normalizePath } from "./paths.mjs";
2
-
3
- export { };
1
+ import "./paths.mjs";
2
+ export {};
@@ -1,6 +1,5 @@
1
- import { printTable } from "./printTable.mjs";
2
- import { printFileList } from "./printFileList.mjs";
3
- import { printBuildSummary } from "./printBuildSummary.mjs";
4
- import { printHeader } from "./printHeader.mjs";
5
-
6
- export { };
1
+ import "./printTable.mjs";
2
+ import "./printFileList.mjs";
3
+ import "./printBuildSummary.mjs";
4
+ import "./printHeader.mjs";
5
+ export {};
@@ -1,7 +1,6 @@
1
1
  import { wxt } from "../../wxt.mjs";
2
2
  import { printFileList } from "./printFileList.mjs";
3
3
  import { resolve } from "path";
4
-
5
4
  //#region src/core/utils/log/printBuildSummary.ts
6
5
  async function printBuildSummary(log, header, output) {
7
6
  const files = [...output.steps.flatMap((step) => step.chunks), ...output.publicAssets].sort((l, r) => {
@@ -22,6 +21,5 @@ const CHUNK_SORT_WEIGHTS = {
22
21
  function getChunkSortWeight(filename) {
23
22
  return Object.entries(CHUNK_SORT_WEIGHTS).find(([key]) => filename.endsWith(key))?.[1] ?? DEFAULT_SORT_WEIGHT;
24
23
  }
25
-
26
24
  //#endregion
27
- export { printBuildSummary };
25
+ export { printBuildSummary };
@@ -1,9 +1,8 @@
1
1
  import { printTable } from "./printTable.mjs";
2
- import fs from "fs-extra";
2
+ import { lstat } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import pc from "picocolors";
5
5
  import { filesize } from "filesize";
6
-
7
6
  //#region src/core/utils/log/printFileList.ts
8
7
  async function printFileList(log, header, baseDir, files) {
9
8
  let totalSize = 0;
@@ -11,7 +10,7 @@ async function printFileList(log, header, baseDir, files) {
11
10
  const parts = [path.relative(process.cwd(), baseDir) + path.sep, path.relative(baseDir, file)];
12
11
  const prefix = i === files.length - 1 ? " └─" : " ├─";
13
12
  const color = getChunkColor(file);
14
- const stats = await fs.lstat(file);
13
+ const stats = await lstat(file);
15
14
  totalSize += stats.size;
16
15
  const size = String(filesize(stats.size));
17
16
  return [`${pc.gray(prefix)} ${pc.dim(parts[0])}${color(parts[1])}`, pc.dim(size)];
@@ -34,6 +33,5 @@ const CHUNK_COLORS = {
34
33
  function getChunkColor(filename) {
35
34
  return Object.entries(CHUNK_COLORS).find(([key]) => filename.endsWith(key))?.[1] ?? DEFAULT_COLOR;
36
35
  }
37
-
38
36
  //#endregion
39
- export { printFileList };
37
+ export { printFileList };
@@ -1,11 +1,9 @@
1
1
  import { version } from "../../../version.mjs";
2
2
  import { consola as consola$1 } from "consola";
3
3
  import pc from "picocolors";
4
-
5
4
  //#region src/core/utils/log/printHeader.ts
6
5
  function printHeader() {
7
6
  consola$1.log(`\n${pc.gray("WXT")} ${pc.gray(pc.bold(version))}`);
8
7
  }
9
-
10
8
  //#endregion
11
- export { printHeader };
9
+ export { printHeader };
@@ -15,6 +15,5 @@ function printTable(log, header, rows, gap = 2) {
15
15
  });
16
16
  log(`${header}\n${str}`);
17
17
  }
18
-
19
18
  //#endregion
20
- export { printTable };
19
+ export { printTable };
@@ -5,26 +5,21 @@ import { writeFileIfDifferent } from "./fs.mjs";
5
5
  import { ContentSecurityPolicy } from "./content-security-policy.mjs";
6
6
  import { hashContentScriptOptions, mapWxtOptionsToContentScript } from "./content-scripts.mjs";
7
7
  import { getPackageJson } from "./package.mjs";
8
- import fs from "fs-extra";
8
+ import { mkdir } from "node:fs/promises";
9
9
  import { resolve } from "path";
10
10
  import defu from "defu";
11
-
12
11
  //#region src/core/utils/manifest.ts
13
- /**
14
- * Writes the manifest to the output directory and the build output.
15
- */
12
+ /** Writes the manifest to the output directory and the build output. */
16
13
  async function writeManifest(manifest, output) {
17
14
  const str = wxt.config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
18
- await fs.ensureDir(wxt.config.outDir);
15
+ await mkdir(wxt.config.outDir, { recursive: true });
19
16
  await writeFileIfDifferent(resolve(wxt.config.outDir, "manifest.json"), str);
20
17
  output.publicAssets.unshift({
21
18
  type: "asset",
22
19
  fileName: "manifest.json"
23
20
  });
24
21
  }
25
- /**
26
- * Generates the manifest based on the config and entrypoints.
27
- */
22
+ /** Generates the manifest based on the config and entrypoints. */
28
23
  async function generateManifest(allEntrypoints, buildOutput) {
29
24
  const entrypoints = allEntrypoints.filter((entry) => !entry.skipped);
30
25
  const warnings = [];
@@ -79,8 +74,9 @@ async function generateManifest(allEntrypoints, buildOutput) {
79
74
  };
80
75
  }
81
76
  /**
82
- * Removes suffixes from the version, like X.Y.Z-alpha1 (which browsers don't allow), so it's a
83
- * simple version number, like X or X.Y or X.Y.Z, which browsers allow.
77
+ * Removes suffixes from the version, like X.Y.Z-alpha1 (which browsers don't
78
+ * allow), so it's a simple version number, like X or X.Y or X.Y.Z, which
79
+ * browsers allow.
84
80
  */
85
81
  function simplifyVersion(versionName) {
86
82
  const version = /^((0|[1-9][0-9]{0,8})([.](0|[1-9][0-9]{0,8})){0,3}).*$/.exec(versionName)?.[1];
@@ -264,8 +260,8 @@ function addDevModePermissions(manifest) {
264
260
  if (wxt.config.manifestVersion === 3) addPermission(manifest, "scripting");
265
261
  }
266
262
  /**
267
- * Returns the bundle paths to CSS files associated with a list of content scripts, or undefined if
268
- * there is no associated CSS.
263
+ * Returns the bundle paths to CSS files associated with a list of content
264
+ * scripts, or undefined if there is no associated CSS.
269
265
  */
270
266
  function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
271
267
  const css = [];
@@ -278,9 +274,9 @@ function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
278
274
  if (css.length > 0) return css;
279
275
  }
280
276
  /**
281
- * Content scripts configured with `cssInjectionMode: "ui"` need to add their CSS files to web
282
- * accessible resources so they can be fetched as text and added to shadow roots that the UI is
283
- * added to.
277
+ * Content scripts configured with `cssInjectionMode: "ui"` need to add their
278
+ * CSS files to web accessible resources so they can be fetched as text and
279
+ * added to shadow roots that the UI is added to.
284
280
  */
285
281
  function getContentScriptCssWebAccessibleResources(contentScripts, contentScriptCssMap) {
286
282
  const resources = [];
@@ -297,8 +293,8 @@ function getContentScriptCssWebAccessibleResources(contentScripts, contentScript
297
293
  return resources;
298
294
  }
299
295
  /**
300
- * Based on the build output, return a Record of each content script's name to it CSS file if the
301
- * script includes one.
296
+ * Based on the build output, return a Record of each content script's name to
297
+ * it CSS file if the script includes one.
302
298
  */
303
299
  function getContentScriptsCssMap(buildOutput, scripts) {
304
300
  const map = {};
@@ -320,8 +316,8 @@ function addHostPermission(manifest, hostPermission) {
320
316
  manifest.host_permissions.push(hostPermission);
321
317
  }
322
318
  /**
323
- * - "<all_urls>" &rarr; "<all_urls>"
324
- * - "*://play.google.com/books/*" &rarr; "*://play.google.com/*"
319
+ * - "<all_urls>" "<all_urls>"
320
+ * - "_://play.google.com/books/_" "_://play.google.com/_"
325
321
  */
326
322
  function stripPathFromMatchPattern(pattern) {
327
323
  const protocolSepIndex = pattern.indexOf("://");
@@ -330,9 +326,10 @@ function stripPathFromMatchPattern(pattern) {
330
326
  return pattern.substring(0, startOfPath) + "/*";
331
327
  }
332
328
  /**
333
- * Converts all MV3 web accessible resources to their MV2 forms. MV3 web accessible resources are
334
- * generated in this file, and may be defined by the user in their manifest. In both cases, when
335
- * targeting MV2, automatically convert their definitions down to the basic MV2 array.
329
+ * Converts all MV3 web accessible resources to their MV2 forms. MV3 web
330
+ * accessible resources are generated in this file, and may be defined by the
331
+ * user in their manifest. In both cases, when targeting MV2, automatically
332
+ * convert their definitions down to the basic MV2 array.
336
333
  */
337
334
  function convertWebAccessibleResourcesToMv2(manifest) {
338
335
  if (manifest.web_accessible_resources == null) return;
@@ -354,17 +351,13 @@ function convertCspToMv2(manifest) {
354
351
  if (typeof manifest.content_security_policy === "string" || manifest.content_security_policy?.extension_pages == null) return;
355
352
  manifest.content_security_policy = manifest.content_security_policy.extension_pages;
356
353
  }
357
- /**
358
- * Make sure all resources are in MV3 format. If not, add a warning.
359
- */
354
+ /** Make sure all resources are in MV3 format. If not, add a warning. */
360
355
  function validateMv3WebAccessibleResources(manifest) {
361
356
  if (manifest.web_accessible_resources == null) return;
362
357
  const stringResources = manifest.web_accessible_resources.filter((item) => typeof item === "string");
363
358
  if (stringResources.length > 0) throw Error(`Non-MV3 web_accessible_resources detected: ${JSON.stringify(stringResources)}. When manually defining web_accessible_resources, define them as MV3 objects ({ matches: [...], resources: [...] }), and WXT will automatically convert them to MV2 when necessary.`);
364
359
  }
365
- /**
366
- * Remove keys from the manifest based on the build target.
367
- */
360
+ /** Remove keys from the manifest based on the build target. */
368
361
  function stripKeys(manifest) {
369
362
  let keysToRemove = [];
370
363
  if (wxt.config.manifestVersion === 2) {
@@ -404,6 +397,5 @@ const firefoxMv3OnlyKeys = ["host_permissions"];
404
397
  const DEFAULT_MV3_EXTENSION_PAGES_CSP = "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';";
405
398
  const DEFAULT_MV3_SANDBOX_CSP = "sandbox allow-scripts allow-forms allow-popups allow-modals; script-src 'self' 'unsafe-inline' 'unsafe-eval'; child-src 'self';";
406
399
  const DEFAULT_MV2_CSP = "script-src 'self'; object-src 'self';";
407
-
408
400
  //#endregion
409
- export { generateManifest, getContentScriptCssFiles, getContentScriptsCssMap, writeManifest };
401
+ export { generateManifest, getContentScriptCssFiles, getContentScriptsCssMap, writeManifest };
@@ -1,5 +1,4 @@
1
1
  import { minimatch } from "minimatch";
2
-
3
2
  //#region src/core/utils/minimatch-multiple.ts
4
3
  /**
5
4
  * Run [`minimatch`](https://npmjs.com/package/minimatch) against multiple
@@ -9,10 +8,10 @@ import { minimatch } from "minimatch";
9
8
  * matches any of the negative patterns, it will return `false`.
10
9
  *
11
10
  * @example
12
- * ```ts
13
- * minimatchMultiple('a.json', ['*.json', '!b.json']); // => true
14
- * minimatchMultiple('b.json', ['*.json', '!b.json']); // => false
15
- * ```
11
+ * ```ts
12
+ * minimatchMultiple('a.json', ['*.json', '!b.json']); // => true
13
+ * minimatchMultiple('b.json', ['*.json', '!b.json']); // => false
14
+ * ```;
16
15
  */
17
16
  function minimatchMultiple(search, patterns, options) {
18
17
  if (patterns == null) return false;
@@ -23,6 +22,5 @@ function minimatchMultiple(search, patterns, options) {
23
22
  if (negatePatterns.some((negatePattern) => minimatch(search, negatePattern, options))) return false;
24
23
  return positivePatterns.some((positivePattern) => minimatch(search, positivePattern, options));
25
24
  }
26
-
27
25
  //#endregion
28
- export { minimatchMultiple };
26
+ export { minimatchMultiple };
@@ -1,7 +1,6 @@
1
1
  import { withTimeout } from "./time.mjs";
2
2
  import consola from "consola";
3
3
  import dns from "node:dns";
4
-
5
4
  //#region src/core/utils/network.ts
6
5
  async function isOffline() {
7
6
  try {
@@ -17,8 +16,8 @@ async function isOnline() {
17
16
  return !await isOffline();
18
17
  }
19
18
  /**
20
- * Fetches a URL with a simple GET request. Grabs it from cache if it doesn't exist, or throws an
21
- * error if it can't be resolved via the network or cache.
19
+ * Fetches a URL with a simple GET request. Grabs it from cache if it doesn't
20
+ * exist, or throws an error if it can't be resolved via the network or cache.
22
21
  */
23
22
  async function fetchCached(url, config) {
24
23
  let content = "";
@@ -33,6 +32,5 @@ async function fetchCached(url, config) {
33
32
  if (!content) throw Error(`Offline and "${url}" has not been cached. Try again when online.`);
34
33
  return content;
35
34
  }
36
-
37
35
  //#endregion
38
- export { fetchCached };
36
+ export { fetchCached };
@@ -3,6 +3,5 @@ function safeStringToNumber(str) {
3
3
  const num = Number(str);
4
4
  return isNaN(num) ? null : num;
5
5
  }
6
-
7
6
  //#endregion
8
- export { safeStringToNumber };
7
+ export { safeStringToNumber };
@@ -1,7 +1,6 @@
1
1
  import { wxt } from "../wxt.mjs";
2
- import fs from "fs-extra";
2
+ import { readJson } from "./fs.mjs";
3
3
  import { resolve } from "node:path";
4
-
5
4
  //#region src/core/utils/package.ts
6
5
  /**
7
6
  * Read the project's package.json.
@@ -11,12 +10,11 @@ import { resolve } from "node:path";
11
10
  async function getPackageJson() {
12
11
  const file = resolve(wxt.config.root, "package.json");
13
12
  try {
14
- return await fs.readJson(file);
13
+ return await readJson(file);
15
14
  } catch (err) {
16
15
  wxt.logger.debug(`Failed to read package.json at: ${file}. Returning undefined.`, err);
17
16
  return {};
18
17
  }
19
18
  }
20
-
21
19
  //#endregion
22
- export { getPackageJson };
20
+ export { getPackageJson };
@@ -1,7 +1,7 @@
1
1
  //#region src/core/utils/paths.d.ts
2
2
  /**
3
- * Converts system paths to normalized bundler path.
4
- * On Windows, this returns paths with `/` instead of `\`.
3
+ * Converts system paths to normalized bundler path. On Windows, this returns
4
+ * paths with `/` instead of `\`.
5
5
  */
6
6
  declare function normalizePath(path: string): string;
7
7
  //#endregion