wxt 0.16.3 → 0.16.4

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.
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.16.3";
2
+ var version = "0.16.4";
3
3
 
4
4
  // src/core/utils/fs.ts
5
5
  import fs from "fs-extra";
@@ -8,11 +8,11 @@ import glob from "fast-glob";
8
8
  // src/core/utils/paths.ts
9
9
  import systemPath from "node:path";
10
10
  import normalize from "normalize-path";
11
- function normalizePath(path6) {
12
- return normalize(path6);
11
+ function normalizePath(path7) {
12
+ return normalize(path7);
13
13
  }
14
- function unnormalizePath(path6) {
15
- return systemPath.normalize(path6);
14
+ function unnormalizePath(path7) {
15
+ return systemPath.normalize(path7);
16
16
  }
17
17
  var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
18
18
  var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
@@ -45,6 +45,7 @@ async function buildEntrypoints(groups, spinner) {
45
45
  try {
46
46
  steps.push(await wxt.config.builder.build(group));
47
47
  } catch (err) {
48
+ wxt.logger.error(err);
48
49
  throw Error(`Failed to build ${groupNames.join(", ")}`, { cause: err });
49
50
  }
50
51
  }
@@ -724,7 +725,7 @@ async function writePathsDeclarationFile(entrypoints) {
724
725
  wxt.config.outDir,
725
726
  entry.inputPath.endsWith(".html") ? ".html" : ".js"
726
727
  )
727
- ).concat(await getPublicFiles()).map(normalizePath).map((path6) => ` | "/${path6}"`).sort().join("\n");
728
+ ).concat(await getPublicFiles()).map(normalizePath).map((path7) => ` | "/${path7}"`).sort().join("\n");
728
729
  const template = `// Generated by wxt
729
730
  import "wxt/browser";
730
731
 
@@ -832,7 +833,7 @@ async function writeMainDeclarationFile(references) {
832
833
  }
833
834
  async function writeTsConfigFile(mainReference) {
834
835
  const dir = wxt.config.wxtDir;
835
- const getTsconfigPath = (path6) => normalizePath(relative3(dir, path6));
836
+ const getTsconfigPath = (path7) => normalizePath(relative3(dir, path7));
836
837
  const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
837
838
  const aliasPath = getTsconfigPath(absolutePath);
838
839
  return [
@@ -868,7 +869,7 @@ ${paths}
868
869
 
869
870
  // src/core/utils/building/resolve-config.ts
870
871
  import { loadConfig } from "c12";
871
- import path4 from "node:path";
872
+ import path5 from "node:path";
872
873
 
873
874
  // src/core/utils/cache.ts
874
875
  import fs5, { ensureDir } from "fs-extra";
@@ -877,14 +878,14 @@ function createFsCache(wxtDir) {
877
878
  const getPath = (key) => resolve5(wxtDir, "cache", encodeURIComponent(key));
878
879
  return {
879
880
  async set(key, value) {
880
- const path6 = getPath(key);
881
- await ensureDir(dirname2(path6));
882
- await writeFileIfDifferent(path6, value);
881
+ const path7 = getPath(key);
882
+ await ensureDir(dirname2(path7));
883
+ await writeFileIfDifferent(path7, value);
883
884
  },
884
885
  async get(key) {
885
- const path6 = getPath(key);
886
+ const path7 = getPath(key);
886
887
  try {
887
- return await fs5.readFile(path6, "utf-8");
888
+ return await fs5.readFile(path7, "utf-8");
888
889
  } catch {
889
890
  return void 0;
890
891
  }
@@ -1018,10 +1019,10 @@ function pointToDevServer(config, server, id, document, querySelector, attr) {
1018
1019
  relative4(config.root, resolvedAbsolutePath)
1019
1020
  );
1020
1021
  if (relativePath.startsWith(".")) {
1021
- let path6 = normalizePath(resolvedAbsolutePath);
1022
- if (!path6.startsWith("/"))
1023
- path6 = "/" + path6;
1024
- element.setAttribute(attr, `${server.origin}/@fs${path6}`);
1022
+ let path7 = normalizePath(resolvedAbsolutePath);
1023
+ if (!path7.startsWith("/"))
1024
+ path7 = "/" + path7;
1025
+ element.setAttribute(attr, `${server.origin}/@fs${path7}`);
1025
1026
  } else {
1026
1027
  const url = new URL(relativePath, server.origin);
1027
1028
  element.setAttribute(attr, url.href);
@@ -1318,12 +1319,12 @@ function cssEntrypoints(entrypoint, config) {
1318
1319
 
1319
1320
  // src/core/builders/vite/plugins/bundleAnalysis.ts
1320
1321
  import { visualizer } from "rollup-plugin-visualizer";
1322
+ import path3 from "node:path";
1321
1323
  var increment = 0;
1322
- function bundleAnalysis() {
1324
+ function bundleAnalysis(config) {
1323
1325
  return visualizer({
1324
- emitFile: true,
1325
1326
  template: "raw-data",
1326
- filename: `stats-${increment++}.json`
1327
+ filename: path3.resolve(config.outDir, `stats-${increment++}.json`)
1327
1328
  });
1328
1329
  }
1329
1330
 
@@ -1344,7 +1345,7 @@ function globals(config) {
1344
1345
  }
1345
1346
 
1346
1347
  // src/core/builders/vite/plugins/webextensionPolyfillMock.ts
1347
- import path3 from "node:path";
1348
+ import path4 from "node:path";
1348
1349
  function webextensionPolyfillMock(config) {
1349
1350
  return {
1350
1351
  name: "wxt:testing-inline-deps",
@@ -1353,7 +1354,7 @@ function webextensionPolyfillMock(config) {
1353
1354
  resolve: {
1354
1355
  alias: {
1355
1356
  // Alias to use a mocked version of the polyfill
1356
- "webextension-polyfill": path3.resolve(
1357
+ "webextension-polyfill": path4.resolve(
1357
1358
  config.root,
1358
1359
  "node_modules/wxt/dist/virtual/mock-browser"
1359
1360
  )
@@ -1464,7 +1465,7 @@ async function createViteBuilder(inlineConfig, userConfig, wxtConfig) {
1464
1465
  defineImportMeta()
1465
1466
  );
1466
1467
  if (wxtConfig.analysis.enabled) {
1467
- config.plugins.push(bundleAnalysis());
1468
+ config.plugins.push(bundleAnalysis(wxtConfig));
1468
1469
  }
1469
1470
  return config;
1470
1471
  };
@@ -1665,20 +1666,20 @@ async function resolveConfig(inlineConfig, command, server) {
1665
1666
  const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
1666
1667
  const mode = mergedConfig.mode ?? (command === "build" ? "production" : "development");
1667
1668
  const env = { browser, command, manifestVersion, mode };
1668
- const root = path4.resolve(
1669
+ const root = path5.resolve(
1669
1670
  inlineConfig.root ?? userConfig.root ?? process.cwd()
1670
1671
  );
1671
- const wxtDir = path4.resolve(root, ".wxt");
1672
- const srcDir = path4.resolve(root, mergedConfig.srcDir ?? root);
1673
- const entrypointsDir = path4.resolve(
1672
+ const wxtDir = path5.resolve(root, ".wxt");
1673
+ const srcDir = path5.resolve(root, mergedConfig.srcDir ?? root);
1674
+ const entrypointsDir = path5.resolve(
1674
1675
  srcDir,
1675
1676
  mergedConfig.entrypointsDir ?? "entrypoints"
1676
1677
  );
1677
1678
  const filterEntrypoints = !!mergedConfig.filterEntrypoints?.length ? new Set(mergedConfig.filterEntrypoints) : void 0;
1678
- const publicDir = path4.resolve(srcDir, mergedConfig.publicDir ?? "public");
1679
- const typesDir = path4.resolve(wxtDir, "types");
1680
- const outBaseDir = path4.resolve(root, mergedConfig.outDir ?? ".output");
1681
- const outDir = path4.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
1679
+ const publicDir = path5.resolve(srcDir, mergedConfig.publicDir ?? "public");
1680
+ const typesDir = path5.resolve(wxtDir, "types");
1681
+ const outBaseDir = path5.resolve(root, mergedConfig.outDir ?? ".output");
1682
+ const outDir = path5.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
1682
1683
  const reloadCommand = mergedConfig.dev?.reloadCommand ?? "Alt+R";
1683
1684
  const runnerConfig = await loadConfig({
1684
1685
  name: "web-ext",
@@ -1695,7 +1696,7 @@ async function resolveConfig(inlineConfig, command, server) {
1695
1696
  "~": srcDir,
1696
1697
  "@@": root,
1697
1698
  "~~": root
1698
- }).map(([key, value]) => [key, path4.resolve(root, value)])
1699
+ }).map(([key, value]) => [key, path5.resolve(root, value)])
1699
1700
  );
1700
1701
  const finalConfig = {
1701
1702
  browser,
@@ -1725,7 +1726,11 @@ async function resolveConfig(inlineConfig, command, server) {
1725
1726
  },
1726
1727
  analysis: {
1727
1728
  enabled: mergedConfig.analysis?.enabled ?? false,
1728
- template: mergedConfig.analysis?.template ?? "treemap"
1729
+ template: mergedConfig.analysis?.template ?? "treemap",
1730
+ outputFile: path5.resolve(
1731
+ root,
1732
+ mergedConfig.analysis?.outputFile ?? "stats.html"
1733
+ )
1729
1734
  },
1730
1735
  userConfigMetadata: userConfigMetadata ?? {},
1731
1736
  alias,
@@ -1795,8 +1800,8 @@ function mergeInlineConfig(inlineConfig, userConfig) {
1795
1800
  outDir: inlineConfig.outDir ?? userConfig.outDir,
1796
1801
  zip,
1797
1802
  analysis: {
1798
- enabled: inlineConfig.analysis?.enabled ?? userConfig.analysis?.enabled,
1799
- template: inlineConfig.analysis?.template ?? userConfig.analysis?.template
1803
+ ...userConfig.analysis,
1804
+ ...inlineConfig.analysis
1800
1805
  },
1801
1806
  alias: {
1802
1807
  ...userConfig.alias,
@@ -1903,16 +1908,16 @@ ${noImports}`;
1903
1908
  // src/core/utils/building/import-entrypoint.ts
1904
1909
  import { transformSync } from "esbuild";
1905
1910
  import { fileURLToPath } from "node:url";
1906
- async function importEntrypointFile(path6) {
1907
- wxt.logger.debug("Loading file metadata:", path6);
1908
- const normalPath = normalizePath(path6);
1911
+ async function importEntrypointFile(path7) {
1912
+ wxt.logger.debug("Loading file metadata:", path7);
1913
+ const normalPath = normalizePath(path7);
1909
1914
  const unimport2 = createUnimport3({
1910
1915
  ...getUnimportOptions(wxt.config),
1911
1916
  // Only allow specific imports, not all from the project
1912
1917
  dirs: []
1913
1918
  });
1914
1919
  await unimport2.init();
1915
- const text = await fs8.readFile(path6, "utf-8");
1920
+ const text = await fs8.readFile(path7, "utf-8");
1916
1921
  const textNoImports = removeProjectImportStatements(text);
1917
1922
  const { code } = await unimport2.injectImports(textNoImports);
1918
1923
  wxt.logger.debug(
@@ -1955,10 +1960,10 @@ async function importEntrypointFile(path6) {
1955
1960
  }
1956
1961
  );
1957
1962
  try {
1958
- const res = await jiti(path6);
1963
+ const res = await jiti(path7);
1959
1964
  return res.default;
1960
1965
  } catch (err) {
1961
- const filePath = relative5(wxt.config.root, path6);
1966
+ const filePath = relative5(wxt.config.root, path7);
1962
1967
  if (err instanceof ReferenceError) {
1963
1968
  const variableName = err.message.replace(" is not defined", "");
1964
1969
  throw Error(
@@ -1988,7 +1993,7 @@ import fs12 from "fs-extra";
1988
1993
  import { resolve as resolve10 } from "path";
1989
1994
 
1990
1995
  // src/core/utils/log/printFileList.ts
1991
- import path5 from "node:path";
1996
+ import path6 from "node:path";
1992
1997
  import pc3 from "picocolors";
1993
1998
  import fs9 from "fs-extra";
1994
1999
  import { filesize } from "filesize";
@@ -2026,8 +2031,8 @@ async function printFileList(log, header, baseDir, files) {
2026
2031
  const fileRows = await Promise.all(
2027
2032
  files.map(async (file, i) => {
2028
2033
  const parts = [
2029
- path5.relative(process.cwd(), baseDir) + path5.sep,
2030
- path5.relative(baseDir, file)
2034
+ path6.relative(process.cwd(), baseDir) + path6.sep,
2035
+ path6.relative(baseDir, file)
2031
2036
  ];
2032
2037
  const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
2033
2038
  const color = getChunkColor(file);
@@ -2219,7 +2224,6 @@ async function getPackageJson() {
2219
2224
  }
2220
2225
 
2221
2226
  // src/core/utils/manifest.ts
2222
- import { produce } from "immer";
2223
2227
  import defu3 from "defu";
2224
2228
  async function writeManifest(manifest, output) {
2225
2229
  const str = wxt.config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
@@ -2250,7 +2254,7 @@ async function generateManifest(entrypoints, buildOutput) {
2250
2254
  icons: discoverIcons(buildOutput)
2251
2255
  };
2252
2256
  const userManifest = wxt.config.manifest;
2253
- const manifest = defu3(
2257
+ let manifest = defu3(
2254
2258
  userManifest,
2255
2259
  baseManifest
2256
2260
  );
@@ -2277,19 +2281,24 @@ async function generateManifest(entrypoints, buildOutput) {
2277
2281
  addDevModeCsp(manifest);
2278
2282
  if (wxt.config.command === "serve")
2279
2283
  addDevModePermissions(manifest);
2280
- const finalManifest = produce(manifest, wxt.config.transformManifest);
2281
- await wxt.hooks.callHook("build:manifestGenerated", wxt, finalManifest);
2282
- if (finalManifest.name == null)
2284
+ wxt.config.transformManifest(manifest);
2285
+ await wxt.hooks.callHook("build:manifestGenerated", wxt, manifest);
2286
+ if (wxt.config.manifestVersion === 2)
2287
+ convertWebAccessibleResourcesToMv2(manifest);
2288
+ if (wxt.config.manifestVersion === 3) {
2289
+ validateMv3WebAccessbileResources(manifest);
2290
+ }
2291
+ if (manifest.name == null)
2283
2292
  throw Error(
2284
2293
  "Manifest 'name' is missing. Either:\n1. Set the name in your <rootDir>/package.json\n2. Set a name via the manifest option in your wxt.config.ts"
2285
2294
  );
2286
- if (finalManifest.version == null) {
2295
+ if (manifest.version == null) {
2287
2296
  throw Error(
2288
2297
  "Manifest 'version' is missing. Either:\n1. Add a version in your <rootDir>/package.json\n2. Pass the version via the manifest option in your wxt.config.ts"
2289
2298
  );
2290
2299
  }
2291
2300
  return {
2292
- manifest: finalManifest,
2301
+ manifest,
2293
2302
  warnings
2294
2303
  };
2295
2304
  }
@@ -2592,17 +2601,13 @@ function getContentScriptCssWebAccessibleResources(contentScripts, contentScript
2592
2601
  const cssFile = contentScriptCssMap[script.name];
2593
2602
  if (cssFile == null)
2594
2603
  return;
2595
- if (wxt.config.manifestVersion === 2) {
2596
- resources.push(cssFile);
2597
- } else {
2598
- resources.push({
2599
- resources: [cssFile],
2600
- matches: resolvePerBrowserOption(
2601
- script.options.matches,
2602
- wxt.config.browser
2603
- ).map((matchPattern) => stripPathFromMatchPattern(matchPattern))
2604
- });
2605
- }
2604
+ resources.push({
2605
+ resources: [cssFile],
2606
+ matches: resolvePerBrowserOption(
2607
+ script.options.matches,
2608
+ wxt.config.browser
2609
+ ).map((matchPattern) => stripPathFromMatchPattern(matchPattern))
2610
+ });
2606
2611
  });
2607
2612
  return resources;
2608
2613
  }
@@ -2637,6 +2642,33 @@ function stripPathFromMatchPattern(pattern) {
2637
2642
  const startOfPath = pattern.indexOf("/", protocolSepIndex + 3);
2638
2643
  return pattern.substring(0, startOfPath) + "/*";
2639
2644
  }
2645
+ function convertWebAccessibleResourcesToMv2(manifest) {
2646
+ if (manifest.web_accessible_resources == null)
2647
+ return;
2648
+ manifest.web_accessible_resources = Array.from(
2649
+ new Set(
2650
+ manifest.web_accessible_resources.flatMap((item) => {
2651
+ if (typeof item === "string")
2652
+ return item;
2653
+ return item.resources;
2654
+ })
2655
+ )
2656
+ );
2657
+ }
2658
+ function validateMv3WebAccessbileResources(manifest) {
2659
+ if (manifest.web_accessible_resources == null)
2660
+ return;
2661
+ const stringResources = manifest.web_accessible_resources.filter(
2662
+ (item) => typeof item === "string"
2663
+ );
2664
+ if (stringResources.length > 0) {
2665
+ throw Error(
2666
+ `Non-MV3 web_accessible_resources detected: ${JSON.stringify(
2667
+ stringResources
2668
+ )}. When manually defining web_accessible_resources, define them as MV3 objects ({ matches: [...], resources: [...] }), and WXT will automatically convert them to MV2 when necessary.`
2669
+ );
2670
+ }
2671
+ }
2640
2672
 
2641
2673
  // src/core/utils/building/rebuild.ts
2642
2674
  async function rebuild(allEntrypoints, entrypointGroups, existingOutput = {
@@ -2792,9 +2824,10 @@ async function internalBuild() {
2792
2824
  }
2793
2825
  if (wxt.config.analysis.enabled) {
2794
2826
  await combineAnalysisStats();
2827
+ const statsPath = relative6(wxt.config.root, wxt.config.analysis.outputFile);
2795
2828
  wxt.logger.info(
2796
2829
  `Analysis complete:
2797
- ${pc5.gray("\u2514\u2500")} ${pc5.yellow("stats.html")}`
2830
+ ${pc5.gray("\u2514\u2500")} ${pc5.yellow(statsPath)}`
2798
2831
  );
2799
2832
  }
2800
2833
  return output;
@@ -2807,9 +2840,16 @@ async function combineAnalysisStats() {
2807
2840
  const absolutePaths = unixFiles.map(unnormalizePath);
2808
2841
  await exec(
2809
2842
  "rollup-plugin-visualizer",
2810
- [...absolutePaths, "--template", wxt.config.analysis.template],
2843
+ [
2844
+ ...absolutePaths,
2845
+ "--template",
2846
+ wxt.config.analysis.template,
2847
+ "--filename",
2848
+ wxt.config.analysis.outputFile
2849
+ ],
2811
2850
  { cwd: wxt.config.root, stdio: "inherit" }
2812
2851
  );
2852
+ await Promise.all(absolutePaths.map((statsFile) => fs12.remove(statsFile)));
2813
2853
  }
2814
2854
  function printValidationResults({
2815
2855
  errorCount,