wxt 0.18.11 → 0.18.13

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.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <h1 align="center">
2
- <img style="vertical-align:middle" width="44" src="./docs/public/hero-logo.svg" alt="WXT Logo">
2
+ <img style="vertical-align:middle" width="44" src="https://raw.githubusercontent.com/wxt-dev/wxt/HEAD/docs/public/hero-logo.svg" alt="WXT Logo">
3
3
  <span>WXT</span>
4
4
  </h1>
5
5
 
@@ -22,22 +22,22 @@
22
22
  </p>
23
23
 
24
24
  <p align="center">
25
- <a href="https://wxt.dev" target="_blank">Get Started</a>
26
- &bull;
27
- <a href="https://wxt.dev/guide/installation.html" target="_blank">Installation</a>
25
+ <a href="https://wxt.dev/guide/installation.html" target="_blank">Get Started</a>
28
26
  &bull;
29
27
  <a href="https://wxt.dev/api/config.html" target="_blank">Configuration</a>
30
28
  &bull;
31
29
  <a href="https://wxt.dev/examples.html" target="_blank">Examples</a>
32
30
  &bull;
31
+ <a href="https://github.com/wxt-dev/wxt/blob/main/packages/wxt/CHANGELOG.md" target="_blank">Changelog</a>
32
+ &bull;
33
33
  <a href="https://discord.gg/ZFsZqGery9" target="_blank">Discord</a>
34
34
  </p>
35
35
 
36
- ![Example CLI Output](./docs/assets/cli-output.png)
36
+ ![Example CLI Output](https://raw.githubusercontent.com/wxt-dev/wxt/HEAD/docs/assets/cli-output.png)
37
37
 
38
38
  ## Demo
39
39
 
40
- https://github.com/wxt-dev/wxt/assets/10101283/4d678939-1bdb-495c-9c36-3aa281d84c94
40
+ <video src="https://github.com/wxt-dev/wxt/assets/10101283/4d678939-1bdb-495c-9c36-3aa281d84c94"></video>
41
41
 
42
42
  ## Quick Start
43
43
 
@@ -16,7 +16,7 @@ import {
16
16
  } from "./chunk-QGM4M3NI.js";
17
17
 
18
18
  // package.json
19
- var version = "0.18.10";
19
+ var version = "0.18.12";
20
20
 
21
21
  // src/core/utils/paths.ts
22
22
  import systemPath from "node:path";
@@ -242,14 +242,33 @@ function webextensionPolyfillMock(config) {
242
242
  };
243
243
  }
244
244
 
245
+ // src/core/builders/vite/plugins/resolveAppConfig.ts
246
+ import { exists } from "fs-extra";
247
+ import { resolve as resolve2 } from "node:path";
248
+ function resolveAppConfig(config) {
249
+ const virtualModuleId = "virtual:app-config";
250
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
251
+ const appConfigFile = resolve2(config.srcDir, "app.config.ts");
252
+ return {
253
+ name: "wxt:resolve-app-config",
254
+ async resolveId(id) {
255
+ if (id !== virtualModuleId) return;
256
+ return await exists(appConfigFile) ? appConfigFile : resolvedVirtualModuleId;
257
+ },
258
+ load(id) {
259
+ if (id === resolvedVirtualModuleId) return `export default {}`;
260
+ }
261
+ };
262
+ }
263
+
245
264
  // src/core/builders/vite/plugins/devHtmlPrerender.ts
246
265
  import { parseHTML } from "linkedom";
247
- import { dirname, relative as relative2, resolve as resolve2 } from "node:path";
266
+ import { dirname, relative as relative2, resolve as resolve3 } from "node:path";
248
267
  import { murmurHash } from "ohash";
249
268
  var inlineScriptContents = {};
250
269
  function devHtmlPrerender(config, server) {
251
270
  const htmlReloadId = "@wxt/reload-html";
252
- const resolvedHtmlReloadId = resolve2(
271
+ const resolvedHtmlReloadId = resolve3(
253
272
  config.wxtModuleDir,
254
273
  "dist/virtual/reload-html.js"
255
274
  );
@@ -351,12 +370,12 @@ function pointToDevServer(config, server, id, document, querySelector, attr) {
351
370
  );
352
371
  if (matchingAlias) {
353
372
  const [alias, replacement] = matchingAlias;
354
- resolvedAbsolutePath = resolve2(
373
+ resolvedAbsolutePath = resolve3(
355
374
  config.root,
356
375
  src.replace(alias, replacement)
357
376
  );
358
377
  } else {
359
- resolvedAbsolutePath = resolve2(dirname(id), src);
378
+ resolvedAbsolutePath = resolve3(dirname(id), src);
360
379
  }
361
380
  if (resolvedAbsolutePath) {
362
381
  const relativePath = normalizePath(
@@ -400,7 +419,7 @@ function devServerGlobals(config, server) {
400
419
  }
401
420
 
402
421
  // src/core/builders/vite/plugins/multipageMove.ts
403
- import { dirname as dirname2, extname, resolve as resolve3, join } from "node:path";
422
+ import { dirname as dirname2, extname, resolve as resolve4, join } from "node:path";
404
423
  import fs, { ensureDir } from "fs-extra";
405
424
  function multipageMove(entrypoints, config) {
406
425
  return {
@@ -428,8 +447,8 @@ function multipageMove(entrypoints, config) {
428
447
  );
429
448
  continue;
430
449
  }
431
- const oldAbsPath = resolve3(config.outDir, oldBundlePath);
432
- const newAbsPath = resolve3(config.outDir, newBundlePath);
450
+ const oldAbsPath = resolve4(config.outDir, oldBundlePath);
451
+ const newAbsPath = resolve4(config.outDir, newBundlePath);
433
452
  await ensureDir(dirname2(newAbsPath));
434
453
  await fs.move(oldAbsPath, newAbsPath, { overwrite: true });
435
454
  const renamedChunk = {
@@ -476,7 +495,7 @@ var virtualModuleNames = [
476
495
 
477
496
  // src/core/builders/vite/plugins/resolveVirtualModules.ts
478
497
  import fs2 from "fs-extra";
479
- import { resolve as resolve4 } from "path";
498
+ import { resolve as resolve5 } from "path";
480
499
  function resolveVirtualModules(config) {
481
500
  return virtualModuleNames.map((name) => {
482
501
  const virtualId = `virtual:wxt-${name}?`;
@@ -493,7 +512,7 @@ function resolveVirtualModules(config) {
493
512
  if (!id.startsWith(resolvedVirtualId)) return;
494
513
  const inputPath = id.replace(resolvedVirtualId, "");
495
514
  const template = await fs2.readFile(
496
- resolve4(config.wxtModuleDir, `dist/virtual/${name}.js`),
515
+ resolve5(config.wxtModuleDir, `dist/virtual/${name}.js`),
497
516
  "utf-8"
498
517
  );
499
518
  return template.replace(`virtual:user-${name}`, inputPath);
@@ -635,9 +654,9 @@ function emptyMainFunction(mod) {
635
654
  }
636
655
 
637
656
  // src/core/builders/vite/plugins/removeEntrypointMainFunction.ts
638
- import { resolve as resolve5 } from "node:path";
657
+ import { resolve as resolve6 } from "node:path";
639
658
  function removeEntrypointMainFunction(config, path8) {
640
- const absPath = normalizePath(resolve5(config.root, path8));
659
+ const absPath = normalizePath(resolve6(config.root, path8));
641
660
  return {
642
661
  name: "wxt:remove-entrypoint-main-function",
643
662
  transform(code, id) {
@@ -813,6 +832,7 @@ function getEslint9ConfigEntry(options, globals2) {
813
832
  text: `const globals = ${JSON.stringify(globals2, null, 2)}
814
833
 
815
834
  export default {
835
+ name: "wxt/auto-imports",
816
836
  languageOptions: {
817
837
  globals,
818
838
  sourceType: "module",
@@ -839,7 +859,7 @@ async function getPublicFiles() {
839
859
 
840
860
  // src/core/utils/building/build-entrypoints.ts
841
861
  import fs4 from "fs-extra";
842
- import { dirname as dirname3, resolve as resolve6 } from "path";
862
+ import { dirname as dirname3, resolve as resolve7 } from "path";
843
863
  import pc from "picocolors";
844
864
  async function buildEntrypoints(groups, spinner) {
845
865
  const steps = [];
@@ -861,14 +881,14 @@ async function buildEntrypoints(groups, spinner) {
861
881
  }
862
882
  async function copyPublicDirectory() {
863
883
  const files = (await getPublicFiles()).map((file) => ({
864
- absoluteSrc: resolve6(wxt.config.publicDir, file),
884
+ absoluteSrc: resolve7(wxt.config.publicDir, file),
865
885
  relativeDest: file
866
886
  }));
867
887
  await wxt.hooks.callHook("build:publicAssets", wxt, files);
868
888
  if (files.length === 0) return [];
869
889
  const publicAssets = [];
870
890
  for (const file of files) {
871
- const absoluteDest = resolve6(wxt.config.outDir, file.relativeDest);
891
+ const absoluteDest = resolve7(wxt.config.outDir, file.relativeDest);
872
892
  await fs4.ensureDir(dirname3(absoluteDest));
873
893
  if ("absoluteSrc" in file) {
874
894
  await fs4.copyFile(file.absoluteSrc, absoluteDest);
@@ -976,7 +996,7 @@ function findEffectedSteps(changedFile, currentOutput) {
976
996
  }
977
997
 
978
998
  // src/core/utils/building/find-entrypoints.ts
979
- import { relative as relative3, resolve as resolve7 } from "path";
999
+ import { relative as relative3, resolve as resolve8 } from "path";
980
1000
  import fs5 from "fs-extra";
981
1001
  import { minimatch } from "minimatch";
982
1002
  import { parseHTML as parseHTML3 } from "linkedom";
@@ -985,14 +1005,14 @@ import glob2 from "fast-glob";
985
1005
  import pc2 from "picocolors";
986
1006
  async function findEntrypoints() {
987
1007
  await fs5.mkdir(wxt.config.wxtDir, { recursive: true });
988
- await fs5.writeJson(resolve7(wxt.config.wxtDir, "tsconfig.json"), {});
1008
+ await fs5.writeJson(resolve8(wxt.config.wxtDir, "tsconfig.json"), {});
989
1009
  const relativePaths = await glob2(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
990
1010
  cwd: wxt.config.entrypointsDir
991
1011
  });
992
1012
  relativePaths.sort();
993
1013
  const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
994
1014
  const entrypointInfos = relativePaths.reduce((results, relativePath) => {
995
- const inputPath = resolve7(wxt.config.entrypointsDir, relativePath);
1015
+ const inputPath = resolve8(wxt.config.entrypointsDir, relativePath);
996
1016
  const name = getEntrypointName(wxt.config.entrypointsDir, inputPath);
997
1017
  const matchingGlob = pathGlobs.find(
998
1018
  (glob5) => minimatch(relativePath, glob5)
@@ -1034,7 +1054,7 @@ async function findEntrypoints() {
1034
1054
  return {
1035
1055
  ...info,
1036
1056
  type,
1037
- outputDir: resolve7(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
1057
+ outputDir: resolve8(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
1038
1058
  options: {
1039
1059
  include: void 0,
1040
1060
  exclude: void 0
@@ -1261,7 +1281,7 @@ async function getContentScriptEntrypoint({
1261
1281
  type: "content-script",
1262
1282
  name,
1263
1283
  inputPath,
1264
- outputDir: resolve7(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
1284
+ outputDir: resolve8(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
1265
1285
  options: resolvePerBrowserOptions(options, wxt.config.browser),
1266
1286
  skipped
1267
1287
  };
@@ -1357,7 +1377,7 @@ var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
1357
1377
 
1358
1378
  // src/core/utils/building/generate-wxt-dir.ts
1359
1379
  import fs6 from "fs-extra";
1360
- import { dirname as dirname4, relative as relative4, resolve as resolve8 } from "node:path";
1380
+ import { dirname as dirname4, relative as relative4, resolve as resolve9 } from "node:path";
1361
1381
  import path4 from "node:path";
1362
1382
 
1363
1383
  // src/core/utils/i18n.ts
@@ -1416,7 +1436,7 @@ async function generateTypesDir(entrypoints) {
1416
1436
  entries.push(getMainDeclarationEntry(entries));
1417
1437
  const absoluteFileEntries = entries.filter((entry) => "path" in entry).map((entry) => ({
1418
1438
  ...entry,
1419
- path: resolve8(wxt.config.wxtDir, entry.path)
1439
+ path: resolve9(wxt.config.wxtDir, entry.path)
1420
1440
  }));
1421
1441
  await Promise.all(
1422
1442
  absoluteFileEntries.map(async (file) => {
@@ -1528,7 +1548,7 @@ function getMainDeclarationEntry(references) {
1528
1548
  if ("module" in ref) {
1529
1549
  return lines.push(`/// <reference types="${ref.module}" />`);
1530
1550
  } else if (ref.tsReference) {
1531
- const absolutePath = resolve8(wxt.config.wxtDir, ref.path);
1551
+ const absolutePath = resolve9(wxt.config.wxtDir, ref.path);
1532
1552
  const relativePath = relative4(wxt.config.wxtDir, absolutePath);
1533
1553
  lines.push(`/// <reference types="./${normalizePath(relativePath)}" />`);
1534
1554
  }
@@ -1581,9 +1601,9 @@ import path5 from "node:path";
1581
1601
 
1582
1602
  // src/core/utils/cache.ts
1583
1603
  import fs7, { ensureDir as ensureDir2 } from "fs-extra";
1584
- import { dirname as dirname5, resolve as resolve9 } from "path";
1604
+ import { dirname as dirname5, resolve as resolve10 } from "path";
1585
1605
  function createFsCache(wxtDir) {
1586
- const getPath = (key) => resolve9(wxtDir, "cache", encodeURIComponent(key));
1606
+ const getPath = (key) => resolve10(wxtDir, "cache", encodeURIComponent(key));
1587
1607
  return {
1588
1608
  async set(key, value) {
1589
1609
  const path8 = getPath(key);
@@ -1696,7 +1716,7 @@ async function resolveConfig(inlineConfig, command) {
1696
1716
  }
1697
1717
  devServerConfig = {
1698
1718
  port,
1699
- hostname: "localhost"
1719
+ hostname: mergedConfig.dev?.server?.hostname ?? "localhost"
1700
1720
  };
1701
1721
  }
1702
1722
  const userModules = await resolveWxtUserModules(
@@ -1771,9 +1791,14 @@ async function mergeInlineConfig(inlineConfig, userConfig) {
1771
1791
  userConfig.transformManifest?.(manifest2);
1772
1792
  inlineConfig.transformManifest?.(manifest2);
1773
1793
  };
1774
- const builderConfig = await mergeBuilderConfig(inlineConfig, userConfig);
1794
+ const merged = defu(inlineConfig, userConfig);
1795
+ const builderConfig = await mergeBuilderConfig(
1796
+ merged.logger ?? consola,
1797
+ inlineConfig,
1798
+ userConfig
1799
+ );
1775
1800
  return {
1776
- ...defu(inlineConfig, userConfig),
1801
+ ...merged,
1777
1802
  // Custom merge values
1778
1803
  transformManifest,
1779
1804
  imports,
@@ -1896,8 +1921,10 @@ var COMMAND_MODES = {
1896
1921
  build: "production",
1897
1922
  serve: "development"
1898
1923
  };
1899
- async function mergeBuilderConfig(inlineConfig, userConfig) {
1900
- const vite = await import("vite").catch(() => void 0);
1924
+ async function mergeBuilderConfig(logger, inlineConfig, userConfig) {
1925
+ const vite = await import("vite").catch((err) => {
1926
+ logger.debug("Failed to import vite:", err);
1927
+ });
1901
1928
  if (vite) {
1902
1929
  return {
1903
1930
  vite: async (env) => {
@@ -1999,7 +2026,7 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
1999
2026
  import createJITI from "jiti";
2000
2027
  import { createUnimport as createUnimport2 } from "unimport";
2001
2028
  import fs9 from "fs-extra";
2002
- import { relative as relative5, resolve as resolve10 } from "node:path";
2029
+ import { relative as relative5, resolve as resolve11 } from "node:path";
2003
2030
  import { transformSync } from "esbuild";
2004
2031
  import { fileURLToPath } from "node:url";
2005
2032
  async function importEntrypointFile(path8) {
@@ -2024,7 +2051,14 @@ async function importEntrypointFile(path8) {
2024
2051
  debug: wxt.config.debug,
2025
2052
  esmResolve: true,
2026
2053
  alias: {
2027
- "webextension-polyfill": resolve10(
2054
+ "webextension-polyfill": resolve11(
2055
+ wxt.config.wxtModuleDir,
2056
+ "dist/virtual/mock-browser.js"
2057
+ ),
2058
+ // TODO: Resolve this virtual module to some file with
2059
+ // `export default {}` instead of this hack of using another file with
2060
+ // a default export.
2061
+ "virtual:app-config": resolve11(
2028
2062
  wxt.config.wxtModuleDir,
2029
2063
  "dist/virtual/mock-browser.js"
2030
2064
  )
@@ -2089,7 +2123,7 @@ import pc5 from "picocolors";
2089
2123
  import fs13 from "fs-extra";
2090
2124
 
2091
2125
  // src/core/utils/log/printBuildSummary.ts
2092
- import { resolve as resolve11 } from "path";
2126
+ import { resolve as resolve12 } from "path";
2093
2127
 
2094
2128
  // src/core/utils/log/printFileList.ts
2095
2129
  import path6 from "node:path";
@@ -2173,7 +2207,7 @@ async function printBuildSummary(log, header, output) {
2173
2207
  return l.fileName.localeCompare(r.fileName);
2174
2208
  });
2175
2209
  const files = chunks.map(
2176
- (chunk) => resolve11(wxt.config.outDir, chunk.fileName)
2210
+ (chunk) => resolve12(wxt.config.outDir, chunk.fileName)
2177
2211
  );
2178
2212
  await printFileList(log, header, wxt.config.outDir, files);
2179
2213
  }
@@ -2199,7 +2233,7 @@ import glob4 from "fast-glob";
2199
2233
 
2200
2234
  // src/core/utils/manifest.ts
2201
2235
  import fs12 from "fs-extra";
2202
- import { resolve as resolve13 } from "path";
2236
+ import { resolve as resolve14 } from "path";
2203
2237
 
2204
2238
  // src/core/utils/content-security-policy.ts
2205
2239
  var ContentSecurityPolicy = class _ContentSecurityPolicy {
@@ -2304,10 +2338,10 @@ function getContentScriptJs(config, entrypoint) {
2304
2338
  }
2305
2339
 
2306
2340
  // src/core/utils/package.ts
2307
- import { resolve as resolve12 } from "node:path";
2341
+ import { resolve as resolve13 } from "node:path";
2308
2342
  import fs11 from "fs-extra";
2309
2343
  async function getPackageJson() {
2310
- const file = resolve12(wxt.config.root, "package.json");
2344
+ const file = resolve13(wxt.config.root, "package.json");
2311
2345
  try {
2312
2346
  return await fs11.readJson(file);
2313
2347
  } catch (err) {
@@ -2323,7 +2357,7 @@ import defu2 from "defu";
2323
2357
  async function writeManifest(manifest, output) {
2324
2358
  const str = wxt.config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
2325
2359
  await fs12.ensureDir(wxt.config.outDir);
2326
- await writeFileIfDifferent(resolve13(wxt.config.outDir, "manifest.json"), str);
2360
+ await writeFileIfDifferent(resolve14(wxt.config.outDir, "manifest.json"), str);
2327
2361
  output.publicAssets.unshift({
2328
2362
  type: "asset",
2329
2363
  fileName: "manifest.json"
@@ -3252,7 +3286,8 @@ async function createViteBuilder(wxtConfig, hooks, server) {
3252
3286
  globals(wxtConfig),
3253
3287
  excludeBrowserPolyfill(wxtConfig),
3254
3288
  defineImportMeta(),
3255
- wxtPluginLoader(wxtConfig)
3289
+ wxtPluginLoader(wxtConfig),
3290
+ resolveAppConfig(wxtConfig)
3256
3291
  );
3257
3292
  if (wxtConfig.analysis.enabled) {
3258
3293
  config.plugins.push(bundleAnalysis(wxtConfig));
@@ -3553,6 +3588,7 @@ export {
3553
3588
  tsconfigPaths,
3554
3589
  globals,
3555
3590
  webextensionPolyfillMock,
3591
+ resolveAppConfig,
3556
3592
  kebabCaseAlphanumeric,
3557
3593
  vitePlugin,
3558
3594
  wxt,