wxt 0.17.12 → 0.18.0

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/dist/cli.js CHANGED
@@ -1,4 +1,8 @@
1
1
  import { createRequire } from 'module';const require = createRequire(import.meta.url);
2
+ import {
3
+ LogLevels,
4
+ consola
5
+ } from "./chunk-NAMV4VWQ.js";
2
6
  import {
3
7
  __require
4
8
  } from "./chunk-73I7FAJU.js";
@@ -13,11 +17,11 @@ import glob from "fast-glob";
13
17
  // src/core/utils/paths.ts
14
18
  import systemPath from "node:path";
15
19
  import normalize from "normalize-path";
16
- function normalizePath(path10) {
17
- return normalize(path10);
20
+ function normalizePath(path11) {
21
+ return normalize(path11);
18
22
  }
19
- function unnormalizePath(path10) {
20
- return systemPath.normalize(path10);
23
+ function unnormalizePath(path11) {
24
+ return systemPath.normalize(path11);
21
25
  }
22
26
  var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
23
27
  var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
@@ -42,7 +46,7 @@ var npm = {
42
46
  overridesKey: "overrides",
43
47
  async downloadDependency(id, downloadDir) {
44
48
  await ensureDir(downloadDir);
45
- const { execa } = await import("./execa-Y2EWTC4S.js");
49
+ const { execa } = await import("./execa-6HO2IY2B.js");
46
50
  const res = await execa("npm", ["pack", id, "--json"], {
47
51
  cwd: downloadDir
48
52
  });
@@ -54,7 +58,7 @@ var npm = {
54
58
  if (options?.all) {
55
59
  args.push("--depth", "Infinity");
56
60
  }
57
- const { execa } = await import("./execa-Y2EWTC4S.js");
61
+ const { execa } = await import("./execa-6HO2IY2B.js");
58
62
  const res = await execa("npm", args, { cwd: options?.cwd });
59
63
  const project = JSON.parse(res.stdout);
60
64
  return flattenNpmListOutput([project]);
@@ -111,7 +115,7 @@ var bun = {
111
115
  if (options?.all) {
112
116
  args.push("--all");
113
117
  }
114
- const { execa } = await import("./execa-Y2EWTC4S.js");
118
+ const { execa } = await import("./execa-6HO2IY2B.js");
115
119
  const res = await execa("bun", args, { cwd: options?.cwd });
116
120
  return dedupeDependencies(
117
121
  res.stdout.split("\n").slice(1).map((line) => line.trim()).map((line) => /.* (@?\S+)@(\S+)$/.exec(line)).filter((match) => !!match).map(([_, name, version2]) => ({ name, version: version2 }))
@@ -130,7 +134,7 @@ var yarn = {
130
134
  if (options?.all) {
131
135
  args.push("--depth", "Infinity");
132
136
  }
133
- const { execa } = await import("./execa-Y2EWTC4S.js");
137
+ const { execa } = await import("./execa-6HO2IY2B.js");
134
138
  const res = await execa("yarn", args, { cwd: options?.cwd });
135
139
  const tree = res.stdout.split("\n").map((line) => JSON.parse(line)).find((line) => line.type === "tree")?.data;
136
140
  if (tree == null)
@@ -167,7 +171,7 @@ var pnpm = {
167
171
  if (typeof process !== "undefined" && process.env.WXT_PNPM_IGNORE_WORKSPACE === "true") {
168
172
  args.push("--ignore-workspace");
169
173
  }
170
- const { execa } = await import("./execa-Y2EWTC4S.js");
174
+ const { execa } = await import("./execa-6HO2IY2B.js");
171
175
  const res = await execa("pnpm", args, { cwd: options?.cwd });
172
176
  const projects = JSON.parse(res.stdout);
173
177
  return flattenNpmListOutput(projects);
@@ -383,10 +387,10 @@ function pointToDevServer(config, server, id, document, querySelector, attr) {
383
387
  relative2(config.root, resolvedAbsolutePath)
384
388
  );
385
389
  if (relativePath.startsWith(".")) {
386
- let path10 = normalizePath(resolvedAbsolutePath);
387
- if (!path10.startsWith("/"))
388
- path10 = "/" + path10;
389
- element.setAttribute(attr, `${server.origin}/@fs${path10}`);
390
+ let path11 = normalizePath(resolvedAbsolutePath);
391
+ if (!path11.startsWith("/"))
392
+ path11 = "/" + path11;
393
+ element.setAttribute(attr, `${server.origin}/@fs${path11}`);
390
394
  } else {
391
395
  const url = new URL(relativePath, server.origin);
392
396
  element.setAttribute(attr, url.href);
@@ -784,6 +788,31 @@ function globals(config) {
784
788
  };
785
789
  }
786
790
 
791
+ // src/core/builders/vite/plugins/webextensionPolyfillMock.ts
792
+ import path4 from "node:path";
793
+ function webextensionPolyfillMock(config) {
794
+ return {
795
+ name: "wxt:testing-inline-deps",
796
+ config() {
797
+ return {
798
+ resolve: {
799
+ alias: {
800
+ // Alias to use a mocked version of the polyfill
801
+ "webextension-polyfill": path4.resolve(
802
+ config.wxtModuleDir,
803
+ "dist/virtual/mock-browser"
804
+ )
805
+ }
806
+ },
807
+ ssr: {
808
+ // Inline all WXT modules
809
+ noExternal: ["wxt"]
810
+ }
811
+ };
812
+ }
813
+ };
814
+ }
815
+
787
816
  // src/core/builders/vite/plugins/excludeBrowserPolyfill.ts
788
817
  function excludeBrowserPolyfill(config) {
789
818
  const virtualId = "virtual:wxt-webextension-polyfill-disabled";
@@ -840,6 +869,38 @@ function defineImportMeta() {
840
869
  };
841
870
  }
842
871
 
872
+ // src/core/utils/transform.ts
873
+ import { parseModule } from "magicast";
874
+ function removeMainFunctionCode(code) {
875
+ const mod = parseModule(code);
876
+ emptyMainFunction(mod);
877
+ return mod.generate();
878
+ }
879
+ function emptyMainFunction(mod) {
880
+ if (mod.exports?.default?.$type === "function-call") {
881
+ if (mod.exports.default.$ast?.arguments?.[0]?.body) {
882
+ mod.exports.default.$ast.arguments[0].body.body = [];
883
+ } else if (mod.exports.default.$ast?.arguments?.[0]?.properties) {
884
+ mod.exports.default.$ast.arguments[0].properties = mod.exports.default.$ast.arguments[0].properties.filter(
885
+ (prop) => prop.key.name !== "main"
886
+ );
887
+ }
888
+ }
889
+ }
890
+
891
+ // src/core/builders/vite/plugins/removeEntrypointMainFunction.ts
892
+ import { resolve as resolve5 } from "node:path";
893
+ function removeEntrypointMainFunction(config, path11) {
894
+ const absPath = normalizePath(resolve5(config.root, path11));
895
+ return {
896
+ name: "wxt:remove-entrypoint-main-function",
897
+ transform(code, id) {
898
+ if (id === absPath)
899
+ return removeMainFunctionCode(code);
900
+ }
901
+ };
902
+ }
903
+
843
904
  // src/core/utils/arrays.ts
844
905
  function every(array, predicate) {
845
906
  for (let i = 0; i < array.length; i++)
@@ -860,13 +921,31 @@ function filterTruthy(array) {
860
921
  return array.filter((item) => !!item);
861
922
  }
862
923
 
924
+ // src/core/utils/strings.ts
925
+ function kebabCaseAlphanumeric(str) {
926
+ return str.toLowerCase().replace(/[^a-z0-9-\s]/g, "").replace(/\s+/g, "-");
927
+ }
928
+ function safeVarName(str) {
929
+ return "_" + kebabCaseAlphanumeric(str.trim()).replace("-", "_");
930
+ }
931
+ function removeImportStatements(text) {
932
+ return text.replace(
933
+ /(import\s?[{\w][\s\S]*?from\s?["'][\s\S]*?["'];?|import\s?["'][\s\S]*?["'];?)/gm,
934
+ ""
935
+ );
936
+ }
937
+ function removeProjectImportStatements(text) {
938
+ const noImports = removeImportStatements(text);
939
+ return `import { defineUnlistedScript, defineContentScript, defineBackground } from 'wxt/sandbox';
940
+
941
+ ${noImports}`;
942
+ }
943
+
863
944
  // src/core/builders/vite/index.ts
864
945
  async function createViteBuilder(wxtConfig, hooks, server) {
865
946
  const vite = await import("vite");
866
947
  const getBaseConfig = async () => {
867
- const config = await wxtConfig.vite({
868
- ...wxtConfig.env
869
- });
948
+ const config = await wxtConfig.vite(wxtConfig.env);
870
949
  config.root = wxtConfig.root;
871
950
  config.configFile = false;
872
951
  config.logLevel = "warn";
@@ -908,14 +987,22 @@ async function createViteBuilder(wxtConfig, hooks, server) {
908
987
  if (entrypoint.type === "content-script-style" || entrypoint.type === "unlisted-style") {
909
988
  plugins.push(cssEntrypoints(entrypoint, wxtConfig));
910
989
  }
990
+ const iifeReturnValueName = safeVarName(entrypoint.name);
911
991
  const libMode = {
912
992
  mode: wxtConfig.mode,
913
993
  plugins,
994
+ esbuild: {
995
+ // Add a footer with the returned value so it can return values to `scripting.executeScript`
996
+ // Footer is added apart of esbuild to make sure it's not minified. It
997
+ // get's removed if added to `build.rollupOptions.output.footer`
998
+ // See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript#return_value
999
+ footer: iifeReturnValueName + ";"
1000
+ },
914
1001
  build: {
915
1002
  lib: {
916
1003
  entry,
917
1004
  formats: ["iife"],
918
- name: "_",
1005
+ name: iifeReturnValueName,
919
1006
  fileName: entrypoint.name
920
1007
  },
921
1008
  rollupOptions: {
@@ -1002,6 +1089,22 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1002
1089
  return {
1003
1090
  name: "Vite",
1004
1091
  version: vite.version,
1092
+ async importEntrypoint(url) {
1093
+ const baseConfig = await getBaseConfig();
1094
+ const envConfig = {
1095
+ plugins: [
1096
+ webextensionPolyfillMock(wxtConfig),
1097
+ removeEntrypointMainFunction(wxtConfig, url)
1098
+ ]
1099
+ };
1100
+ const config = vite.mergeConfig(baseConfig, envConfig);
1101
+ const server2 = await vite.createServer(config);
1102
+ await server2.listen();
1103
+ const runtime = await vite.createViteRuntime(server2, { hmr: false });
1104
+ const module = await runtime.executeUrl(url);
1105
+ await server2.close();
1106
+ return module.default;
1107
+ },
1005
1108
  async build(group) {
1006
1109
  let entryConfig;
1007
1110
  if (Array.isArray(group))
@@ -1125,7 +1228,7 @@ async function getPublicFiles() {
1125
1228
 
1126
1229
  // src/core/utils/building/build-entrypoints.ts
1127
1230
  import fs4 from "fs-extra";
1128
- import { dirname as dirname3, resolve as resolve5 } from "path";
1231
+ import { dirname as dirname3, resolve as resolve6 } from "path";
1129
1232
  import pc from "picocolors";
1130
1233
  async function buildEntrypoints(groups, spinner) {
1131
1234
  const steps = [];
@@ -1151,8 +1254,8 @@ async function copyPublicDirectory() {
1151
1254
  return [];
1152
1255
  const publicAssets = [];
1153
1256
  for (const file of files) {
1154
- const srcPath = resolve5(wxt.config.publicDir, file);
1155
- const outPath = resolve5(wxt.config.outDir, file);
1257
+ const srcPath = resolve6(wxt.config.publicDir, file);
1258
+ const outPath = resolve6(wxt.config.outDir, file);
1156
1259
  await fs4.ensureDir(dirname3(outPath));
1157
1260
  await fs4.copyFile(srcPath, outPath);
1158
1261
  publicAssets.push({
@@ -1258,21 +1361,114 @@ function findEffectedSteps(changedFile, currentOutput) {
1258
1361
  }
1259
1362
 
1260
1363
  // src/core/utils/building/find-entrypoints.ts
1261
- import { relative as relative3, resolve as resolve6 } from "path";
1262
- import fs5 from "fs-extra";
1364
+ import { relative as relative4, resolve as resolve8 } from "path";
1365
+ import fs6 from "fs-extra";
1263
1366
  import { minimatch } from "minimatch";
1264
1367
  import { parseHTML as parseHTML2 } from "linkedom";
1265
1368
  import JSON5 from "json5";
1266
1369
  import glob2 from "fast-glob";
1267
1370
  import pc2 from "picocolors";
1371
+
1372
+ // src/core/utils/building/import-entrypoint.ts
1373
+ import createJITI from "jiti";
1374
+ import { createUnimport as createUnimport2 } from "unimport";
1375
+ import fs5 from "fs-extra";
1376
+ import { relative as relative3, resolve as resolve7 } from "node:path";
1377
+ import { transformSync } from "esbuild";
1378
+ import { fileURLToPath } from "node:url";
1379
+ async function importEntrypointFile(path11) {
1380
+ wxt.logger.debug("Loading file metadata:", path11);
1381
+ const normalPath = normalizePath(path11);
1382
+ const unimport2 = createUnimport2({
1383
+ ...wxt.config.imports,
1384
+ // Only allow specific imports, not all from the project
1385
+ dirs: []
1386
+ });
1387
+ await unimport2.init();
1388
+ const text = await fs5.readFile(path11, "utf-8");
1389
+ const textNoImports = removeProjectImportStatements(text);
1390
+ const { code } = await unimport2.injectImports(textNoImports);
1391
+ wxt.logger.debug(
1392
+ ["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
1393
+ );
1394
+ const jiti = createJITI(
1395
+ typeof __filename !== "undefined" ? __filename : fileURLToPath(import.meta.url),
1396
+ {
1397
+ cache: false,
1398
+ debug: wxt.config.debug,
1399
+ esmResolve: true,
1400
+ alias: {
1401
+ "webextension-polyfill": resolve7(
1402
+ wxt.config.wxtModuleDir,
1403
+ "dist/virtual/mock-browser.js"
1404
+ )
1405
+ },
1406
+ // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
1407
+ // respect the custom transform function when using it's native bun option.
1408
+ experimentalBun: false,
1409
+ // List of extensions to transform with esbuild
1410
+ extensions: [
1411
+ ".ts",
1412
+ ".cts",
1413
+ ".mts",
1414
+ ".tsx",
1415
+ ".js",
1416
+ ".cjs",
1417
+ ".mjs",
1418
+ ".jsx"
1419
+ ],
1420
+ transform(opts) {
1421
+ const isEntrypoint = opts.filename === normalPath;
1422
+ return transformSync(
1423
+ // Use modified source code for entrypoints
1424
+ isEntrypoint ? code : opts.source,
1425
+ getEsbuildOptions(opts)
1426
+ );
1427
+ }
1428
+ }
1429
+ );
1430
+ try {
1431
+ const res = await jiti(path11);
1432
+ return res.default;
1433
+ } catch (err) {
1434
+ const filePath = relative3(wxt.config.root, path11);
1435
+ if (err instanceof ReferenceError) {
1436
+ const variableName = err.message.replace(" is not defined", "");
1437
+ throw Error(
1438
+ `${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/entrypoints.html#side-effects`,
1439
+ { cause: err }
1440
+ );
1441
+ } else {
1442
+ wxt.logger.error(err);
1443
+ throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
1444
+ }
1445
+ }
1446
+ }
1447
+ function getEsbuildOptions(opts) {
1448
+ const isJsx = opts.filename?.endsWith("x");
1449
+ return {
1450
+ format: "cjs",
1451
+ loader: isJsx ? "tsx" : "ts",
1452
+ ...isJsx ? {
1453
+ // `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
1454
+ // grabbing the entrypoint's options.
1455
+ jsxFactory: "h",
1456
+ jsxFragment: "Fragment"
1457
+ } : void 0
1458
+ };
1459
+ }
1460
+
1461
+ // src/core/utils/building/find-entrypoints.ts
1268
1462
  async function findEntrypoints() {
1463
+ await fs6.mkdir(wxt.config.wxtDir, { recursive: true });
1464
+ await fs6.writeJson(resolve8(wxt.config.wxtDir, "tsconfig.json"), {});
1269
1465
  const relativePaths = await glob2(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
1270
1466
  cwd: wxt.config.entrypointsDir
1271
1467
  });
1272
1468
  relativePaths.sort();
1273
1469
  const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
1274
1470
  const entrypointInfos = relativePaths.reduce((results, relativePath) => {
1275
- const inputPath = resolve6(wxt.config.entrypointsDir, relativePath);
1471
+ const inputPath = resolve8(wxt.config.entrypointsDir, relativePath);
1276
1472
  const name = getEntrypointName(wxt.config.entrypointsDir, inputPath);
1277
1473
  const matchingGlob = pathGlobs.find(
1278
1474
  (glob6) => minimatch(relativePath, glob6)
@@ -1314,7 +1510,7 @@ async function findEntrypoints() {
1314
1510
  return {
1315
1511
  ...info,
1316
1512
  type,
1317
- outputDir: resolve6(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
1513
+ outputDir: resolve8(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
1318
1514
  options: {
1319
1515
  include: void 0,
1320
1516
  exclude: void 0
@@ -1388,7 +1584,7 @@ function preventDuplicateEntrypointNames(files) {
1388
1584
  if (absolutePaths.length > 1) {
1389
1585
  lines.push(`- ${name}`);
1390
1586
  absolutePaths.forEach((absolutePath) => {
1391
- lines.push(` - ${relative3(wxt.config.root, absolutePath)}`);
1587
+ lines.push(` - ${relative4(wxt.config.root, absolutePath)}`);
1392
1588
  });
1393
1589
  }
1394
1590
  return lines;
@@ -1476,7 +1672,7 @@ async function getUnlistedScriptEntrypoint({
1476
1672
  name,
1477
1673
  skipped
1478
1674
  }) {
1479
- const defaultExport = await importEntrypointFile(inputPath);
1675
+ const defaultExport = await importEntrypoint(inputPath);
1480
1676
  if (defaultExport == null) {
1481
1677
  throw Error(
1482
1678
  `${name}: Default export not found, did you forget to call "export default defineUnlistedScript(...)"?`
@@ -1499,7 +1695,7 @@ async function getBackgroundEntrypoint({
1499
1695
  }) {
1500
1696
  let options = {};
1501
1697
  if (inputPath !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
1502
- const defaultExport = await importEntrypointFile(inputPath);
1698
+ const defaultExport = await importEntrypoint(inputPath);
1503
1699
  if (defaultExport == null) {
1504
1700
  throw Error(
1505
1701
  `${name}: Default export not found, did you forget to call "export default defineBackground(...)"?`
@@ -1525,7 +1721,7 @@ async function getContentScriptEntrypoint({
1525
1721
  name,
1526
1722
  skipped
1527
1723
  }) {
1528
- const { main: _, ...options } = await importEntrypointFile(inputPath);
1724
+ const { main: _, ...options } = await importEntrypoint(inputPath);
1529
1725
  if (options == null) {
1530
1726
  throw Error(
1531
1727
  `${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
@@ -1535,7 +1731,7 @@ async function getContentScriptEntrypoint({
1535
1731
  type: "content-script",
1536
1732
  name,
1537
1733
  inputPath,
1538
- outputDir: resolve6(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
1734
+ outputDir: resolve8(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
1539
1735
  options: resolvePerBrowserOptions(options, wxt.config.browser),
1540
1736
  skipped
1541
1737
  };
@@ -1568,7 +1764,7 @@ async function getSidepanelEntrypoint(info) {
1568
1764
  };
1569
1765
  }
1570
1766
  async function getHtmlEntrypointOptions(info, keyMap, queries, parsers) {
1571
- const content = await fs5.readFile(info.inputPath, "utf-8");
1767
+ const content = await fs6.readFile(info.inputPath, "utf-8");
1572
1768
  const { document } = parseHTML2(content);
1573
1769
  const options = {};
1574
1770
  const defaultQuery = (manifestKey) => document.querySelector(`meta[name='manifest.${manifestKey}']`)?.getAttribute("content");
@@ -1628,12 +1824,15 @@ var PATH_GLOB_TO_TYPE_MAP = {
1628
1824
  [`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
1629
1825
  };
1630
1826
  var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
1827
+ function importEntrypoint(path11) {
1828
+ return wxt.config.experimental.viteRuntime ? wxt.builder.importEntrypoint(path11) : importEntrypointFile(path11);
1829
+ }
1631
1830
 
1632
1831
  // src/core/utils/building/generate-wxt-dir.ts
1633
- import { createUnimport as createUnimport2 } from "unimport";
1634
- import fs6 from "fs-extra";
1635
- import { relative as relative4, resolve as resolve7 } from "path";
1636
- import path4 from "node:path";
1832
+ import { createUnimport as createUnimport3 } from "unimport";
1833
+ import fs7 from "fs-extra";
1834
+ import { relative as relative5, resolve as resolve9 } from "path";
1835
+ import path5 from "node:path";
1637
1836
 
1638
1837
  // src/core/utils/i18n.ts
1639
1838
  var predefinedMessages = {
@@ -1674,10 +1873,10 @@ function parseI18nMessages(messagesJson) {
1674
1873
 
1675
1874
  // src/core/utils/building/generate-wxt-dir.ts
1676
1875
  async function generateTypesDir(entrypoints) {
1677
- await fs6.ensureDir(wxt.config.typesDir);
1876
+ await fs7.ensureDir(wxt.config.typesDir);
1678
1877
  const references = [];
1679
1878
  if (wxt.config.imports !== false) {
1680
- const unimport2 = createUnimport2(wxt.config.imports);
1879
+ const unimport2 = createUnimport3(wxt.config.imports);
1681
1880
  references.push(await writeImportsDeclarationFile(unimport2));
1682
1881
  if (wxt.config.imports.eslintrc.enabled) {
1683
1882
  await writeImportsEslintFile(unimport2, wxt.config.imports);
@@ -1690,7 +1889,7 @@ async function generateTypesDir(entrypoints) {
1690
1889
  await writeTsConfigFile(mainReference);
1691
1890
  }
1692
1891
  async function writeImportsDeclarationFile(unimport2) {
1693
- const filePath = resolve7(wxt.config.typesDir, "imports.d.ts");
1892
+ const filePath = resolve9(wxt.config.typesDir, "imports.d.ts");
1694
1893
  await unimport2.scanImportsFromDir(void 0, { cwd: wxt.config.srcDir });
1695
1894
  await writeFileIfDifferent(
1696
1895
  filePath,
@@ -1706,17 +1905,17 @@ async function writeImportsEslintFile(unimport2, options) {
1706
1905
  (await unimport2.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().forEach((name) => {
1707
1906
  eslintrc.globals[name] = options.eslintrc.globalsPropValue;
1708
1907
  });
1709
- await fs6.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
1908
+ await fs7.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
1710
1909
  }
1711
1910
  async function writePathsDeclarationFile(entrypoints) {
1712
- const filePath = resolve7(wxt.config.typesDir, "paths.d.ts");
1911
+ const filePath = resolve9(wxt.config.typesDir, "paths.d.ts");
1713
1912
  const unions = entrypoints.map(
1714
1913
  (entry) => getEntrypointBundlePath(
1715
1914
  entry,
1716
1915
  wxt.config.outDir,
1717
1916
  isHtmlEntrypoint(entry) ? ".html" : ".js"
1718
1917
  )
1719
- ).concat(await getPublicFiles()).map(normalizePath).map((path10) => ` | "/${path10}"`).sort().join("\n");
1918
+ ).concat(await getPublicFiles()).map(normalizePath).map((path11) => ` | "/${path11}"`).sort().join("\n");
1720
1919
  const template = `// Generated by wxt
1721
1920
  import "wxt/browser";
1722
1921
 
@@ -1737,7 +1936,7 @@ declare module "wxt/browser" {
1737
1936
  return filePath;
1738
1937
  }
1739
1938
  async function writeI18nDeclarationFile() {
1740
- const filePath = resolve7(wxt.config.typesDir, "i18n.d.ts");
1939
+ const filePath = resolve9(wxt.config.typesDir, "i18n.d.ts");
1741
1940
  const defaultLocale = wxt.config.manifest.default_locale;
1742
1941
  const template = `// Generated by wxt
1743
1942
  import "wxt/browser";
@@ -1760,13 +1959,13 @@ declare module "wxt/browser" {
1760
1959
  `;
1761
1960
  let messages;
1762
1961
  if (defaultLocale) {
1763
- const defaultLocalePath = path4.resolve(
1962
+ const defaultLocalePath = path5.resolve(
1764
1963
  wxt.config.publicDir,
1765
1964
  "_locales",
1766
1965
  defaultLocale,
1767
1966
  "messages.json"
1768
1967
  );
1769
- const content = JSON.parse(await fs6.readFile(defaultLocalePath, "utf-8"));
1968
+ const content = JSON.parse(await fs7.readFile(defaultLocalePath, "utf-8"));
1770
1969
  messages = parseI18nMessages(content);
1771
1970
  } else {
1772
1971
  messages = parseI18nMessages({});
@@ -1790,7 +1989,7 @@ declare module "wxt/browser" {
1790
1989
  return filePath;
1791
1990
  }
1792
1991
  async function writeGlobalsDeclarationFile() {
1793
- const filePath = resolve7(wxt.config.typesDir, "globals.d.ts");
1992
+ const filePath = resolve9(wxt.config.typesDir, "globals.d.ts");
1794
1993
  const globals2 = [...getGlobals(wxt.config), ...getEntrypointGlobals("")];
1795
1994
  await writeFileIfDifferent(
1796
1995
  filePath,
@@ -1809,14 +2008,14 @@ async function writeGlobalsDeclarationFile() {
1809
2008
  }
1810
2009
  async function writeMainDeclarationFile(references) {
1811
2010
  const dir = wxt.config.wxtDir;
1812
- const filePath = resolve7(dir, "wxt.d.ts");
2011
+ const filePath = resolve9(dir, "wxt.d.ts");
1813
2012
  await writeFileIfDifferent(
1814
2013
  filePath,
1815
2014
  [
1816
2015
  "// Generated by wxt",
1817
2016
  `/// <reference types="wxt/vite-builder-env" />`,
1818
2017
  ...references.map(
1819
- (ref) => `/// <reference types="./${normalizePath(relative4(dir, ref))}" />`
2018
+ (ref) => `/// <reference types="./${normalizePath(relative5(dir, ref))}" />`
1820
2019
  )
1821
2020
  ].join("\n") + "\n"
1822
2021
  );
@@ -1824,7 +2023,7 @@ async function writeMainDeclarationFile(references) {
1824
2023
  }
1825
2024
  async function writeTsConfigFile(mainReference) {
1826
2025
  const dir = wxt.config.wxtDir;
1827
- const getTsconfigPath = (path10) => normalizePath(relative4(dir, path10));
2026
+ const getTsconfigPath = (path11) => normalizePath(relative5(dir, path11));
1828
2027
  const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
1829
2028
  const aliasPath = getTsconfigPath(absolutePath);
1830
2029
  return [
@@ -1833,7 +2032,7 @@ async function writeTsConfigFile(mainReference) {
1833
2032
  ];
1834
2033
  }).join(",\n");
1835
2034
  await writeFileIfDifferent(
1836
- resolve7(dir, "tsconfig.json"),
2035
+ resolve9(dir, "tsconfig.json"),
1837
2036
  `{
1838
2037
  "compilerOptions": {
1839
2038
  "target": "ESNext",
@@ -1860,23 +2059,23 @@ ${paths}
1860
2059
 
1861
2060
  // src/core/utils/building/resolve-config.ts
1862
2061
  import { loadConfig } from "c12";
1863
- import path5 from "node:path";
2062
+ import path6 from "node:path";
1864
2063
 
1865
2064
  // src/core/utils/cache.ts
1866
- import fs7, { ensureDir as ensureDir3 } from "fs-extra";
1867
- import { dirname as dirname4, resolve as resolve8 } from "path";
2065
+ import fs8, { ensureDir as ensureDir3 } from "fs-extra";
2066
+ import { dirname as dirname4, resolve as resolve10 } from "path";
1868
2067
  function createFsCache(wxtDir) {
1869
- const getPath = (key) => resolve8(wxtDir, "cache", encodeURIComponent(key));
2068
+ const getPath = (key) => resolve10(wxtDir, "cache", encodeURIComponent(key));
1870
2069
  return {
1871
2070
  async set(key, value) {
1872
- const path10 = getPath(key);
1873
- await ensureDir3(dirname4(path10));
1874
- await writeFileIfDifferent(path10, value);
2071
+ const path11 = getPath(key);
2072
+ await ensureDir3(dirname4(path11));
2073
+ await writeFileIfDifferent(path11, value);
1875
2074
  },
1876
2075
  async get(key) {
1877
- const path10 = getPath(key);
2076
+ const path11 = getPath(key);
1878
2077
  try {
1879
- return await fs7.readFile(path10, "utf-8");
2078
+ return await fs8.readFile(path11, "utf-8");
1880
2079
  } catch {
1881
2080
  return void 0;
1882
2081
  }
@@ -1885,16 +2084,15 @@ function createFsCache(wxtDir) {
1885
2084
  }
1886
2085
 
1887
2086
  // src/core/utils/building/resolve-config.ts
1888
- import consola, { LogLevels } from "consola";
1889
2087
  import defu from "defu";
1890
2088
 
1891
2089
  // src/core/utils/package.ts
1892
- import { resolve as resolve9 } from "node:path";
1893
- import fs8 from "fs-extra";
2090
+ import { resolve as resolve11 } from "node:path";
2091
+ import fs9 from "fs-extra";
1894
2092
  async function getPackageJson() {
1895
- const file = resolve9(wxt.config.root, "package.json");
2093
+ const file = resolve11(wxt.config.root, "package.json");
1896
2094
  try {
1897
- return await fs8.readJson(file);
2095
+ return await fs9.readJson(file);
1898
2096
  } catch (err) {
1899
2097
  wxt.logger.debug(
1900
2098
  `Failed to read package.json at: ${file}. Returning undefined.`
@@ -1903,11 +2101,14 @@ async function getPackageJson() {
1903
2101
  }
1904
2102
  }
1905
2103
  function isModuleInstalled(name) {
1906
- return import(name).then(() => true).catch(() => false);
2104
+ return import(
2105
+ /* @vite-ignore */
2106
+ name
2107
+ ).then(() => true).catch(() => false);
1907
2108
  }
1908
2109
 
1909
2110
  // src/core/utils/building/resolve-config.ts
1910
- import fs9 from "fs-extra";
2111
+ import fs10 from "fs-extra";
1911
2112
  async function resolveConfig(inlineConfig, command) {
1912
2113
  let userConfig = {};
1913
2114
  let userConfigMetadata;
@@ -1933,13 +2134,13 @@ async function resolveConfig(inlineConfig, command) {
1933
2134
  const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
1934
2135
  const mode = mergedConfig.mode ?? COMMAND_MODES[command];
1935
2136
  const env = { browser, command, manifestVersion, mode };
1936
- const root = path5.resolve(
2137
+ const root = path6.resolve(
1937
2138
  inlineConfig.root ?? userConfig.root ?? process.cwd()
1938
2139
  );
1939
- const wxtDir = path5.resolve(root, ".wxt");
2140
+ const wxtDir = path6.resolve(root, ".wxt");
1940
2141
  const wxtModuleDir = await resolveWxtModuleDir();
1941
- const srcDir = path5.resolve(root, mergedConfig.srcDir ?? root);
1942
- const entrypointsDir = path5.resolve(
2142
+ const srcDir = path6.resolve(root, mergedConfig.srcDir ?? root);
2143
+ const entrypointsDir = path6.resolve(
1943
2144
  srcDir,
1944
2145
  mergedConfig.entrypointsDir ?? "entrypoints"
1945
2146
  );
@@ -1947,13 +2148,13 @@ async function resolveConfig(inlineConfig, command) {
1947
2148
  logMissingDir(logger, "Entrypoints", entrypointsDir);
1948
2149
  }
1949
2150
  const filterEntrypoints = !!mergedConfig.filterEntrypoints?.length ? new Set(mergedConfig.filterEntrypoints) : void 0;
1950
- const publicDir = path5.resolve(srcDir, mergedConfig.publicDir ?? "public");
2151
+ const publicDir = path6.resolve(srcDir, mergedConfig.publicDir ?? "public");
1951
2152
  if (await isDirMissing(publicDir)) {
1952
2153
  logMissingDir(logger, "Public", publicDir);
1953
2154
  }
1954
- const typesDir = path5.resolve(wxtDir, "types");
1955
- const outBaseDir = path5.resolve(root, mergedConfig.outDir ?? ".output");
1956
- const outDir = path5.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
2155
+ const typesDir = path6.resolve(wxtDir, "types");
2156
+ const outBaseDir = path6.resolve(root, mergedConfig.outDir ?? ".output");
2157
+ const outDir = path6.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
1957
2158
  const reloadCommand = mergedConfig.dev?.reloadCommand ?? "Alt+R";
1958
2159
  const runnerConfig = await loadConfig({
1959
2160
  name: "web-ext",
@@ -1970,7 +2171,7 @@ async function resolveConfig(inlineConfig, command) {
1970
2171
  "~": srcDir,
1971
2172
  "@@": root,
1972
2173
  "~~": root
1973
- }).map(([key, value]) => [key, path5.resolve(root, value)])
2174
+ }).map(([key, value]) => [key, path6.resolve(root, value)])
1974
2175
  );
1975
2176
  let devServerConfig;
1976
2177
  if (command === "serve") {
@@ -2012,7 +2213,8 @@ async function resolveConfig(inlineConfig, command) {
2012
2213
  userConfigMetadata: userConfigMetadata ?? {},
2013
2214
  alias,
2014
2215
  experimental: defu(mergedConfig.experimental, {
2015
- includeBrowserPolyfill: true
2216
+ includeBrowserPolyfill: true,
2217
+ viteRuntime: false
2016
2218
  }),
2017
2219
  dev: {
2018
2220
  server: devServerConfig,
@@ -2047,13 +2249,14 @@ async function mergeInlineConfig(inlineConfig, userConfig) {
2047
2249
  };
2048
2250
  }
2049
2251
  function resolveZipConfig(root, mergedConfig) {
2050
- const downloadedPackagesDir = path5.resolve(root, ".wxt/local_modules");
2252
+ const downloadedPackagesDir = path6.resolve(root, ".wxt/local_modules");
2051
2253
  return {
2052
2254
  name: void 0,
2053
2255
  sourcesTemplate: "{{name}}-{{version}}-sources.zip",
2054
2256
  artifactTemplate: "{{name}}-{{version}}-{{browser}}.zip",
2055
2257
  sourcesRoot: root,
2056
2258
  includeSources: [],
2259
+ compressionLevel: 9,
2057
2260
  ...mergedConfig.zip,
2058
2261
  excludeSources: [
2059
2262
  "**/node_modules",
@@ -2072,12 +2275,12 @@ function resolveZipConfig(root, mergedConfig) {
2072
2275
  };
2073
2276
  }
2074
2277
  function resolveAnalysisConfig(root, mergedConfig) {
2075
- const analysisOutputFile = path5.resolve(
2278
+ const analysisOutputFile = path6.resolve(
2076
2279
  root,
2077
2280
  mergedConfig.analysis?.outputFile ?? "stats.html"
2078
2281
  );
2079
- const analysisOutputDir = path5.dirname(analysisOutputFile);
2080
- const analysisOutputName = path5.parse(analysisOutputFile).name;
2282
+ const analysisOutputDir = path6.dirname(analysisOutputFile);
2283
+ const analysisOutputName = path6.parse(analysisOutputFile).name;
2081
2284
  return {
2082
2285
  enabled: mergedConfig.analysis?.enabled ?? false,
2083
2286
  open: mergedConfig.analysis?.open ?? false,
@@ -2117,7 +2320,7 @@ async function getUnimportOptions(wxtDir, logger, config) {
2117
2320
  dirs: ["components", "composables", "hooks", "utils"],
2118
2321
  eslintrc: {
2119
2322
  enabled,
2120
- filePath: path5.resolve(wxtDir, "eslintrc-auto-import.json"),
2323
+ filePath: path6.resolve(wxtDir, "eslintrc-auto-import.json"),
2121
2324
  globalsPropValue: true
2122
2325
  }
2123
2326
  };
@@ -2128,15 +2331,15 @@ async function getUnimportOptions(wxtDir, logger, config) {
2128
2331
  }
2129
2332
  async function resolveWxtModuleDir() {
2130
2333
  const requireResolve = __require?.resolve ?? (await import("node:module")).default.createRequire(import.meta.url).resolve;
2131
- return path5.resolve(requireResolve("wxt"), "../..");
2334
+ return path6.resolve(requireResolve("wxt"), "../..");
2132
2335
  }
2133
2336
  async function isDirMissing(dir) {
2134
- return !await fs9.exists(dir);
2337
+ return !await fs10.exists(dir);
2135
2338
  }
2136
2339
  function logMissingDir(logger, name, expected) {
2137
2340
  logger.warn(
2138
2341
  `${name} directory not found: ./${normalizePath(
2139
- path5.relative(process.cwd(), expected)
2342
+ path6.relative(process.cwd(), expected)
2140
2343
  )}`
2141
2344
  );
2142
2345
  }
@@ -2197,123 +2400,15 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
2197
2400
  "content-script-style": "individual"
2198
2401
  };
2199
2402
 
2200
- // src/core/utils/building/import-entrypoint.ts
2201
- import createJITI from "jiti";
2202
- import { createUnimport as createUnimport3 } from "unimport";
2203
- import fs10 from "fs-extra";
2204
- import { relative as relative5, resolve as resolve10 } from "node:path";
2205
-
2206
- // src/core/utils/strings.ts
2207
- function kebabCaseAlphanumeric(str) {
2208
- return str.toLowerCase().replace(/[^a-z0-9-\s]/g, "").replace(/\s+/g, "-");
2209
- }
2210
- function removeImportStatements(text) {
2211
- return text.replace(
2212
- /(import\s?[{\w][\s\S]*?from\s?["'][\s\S]*?["'];?|import\s?["'][\s\S]*?["'];?)/gm,
2213
- ""
2214
- );
2215
- }
2216
- function removeProjectImportStatements(text) {
2217
- const noImports = removeImportStatements(text);
2218
- return `import { defineUnlistedScript, defineContentScript, defineBackground } from 'wxt/sandbox';
2219
-
2220
- ${noImports}`;
2221
- }
2222
-
2223
- // src/core/utils/building/import-entrypoint.ts
2224
- import { transformSync } from "esbuild";
2225
- import { fileURLToPath } from "node:url";
2226
- async function importEntrypointFile(path10) {
2227
- wxt.logger.debug("Loading file metadata:", path10);
2228
- const normalPath = normalizePath(path10);
2229
- const unimport2 = createUnimport3({
2230
- ...wxt.config.imports,
2231
- // Only allow specific imports, not all from the project
2232
- dirs: []
2233
- });
2234
- await unimport2.init();
2235
- const text = await fs10.readFile(path10, "utf-8");
2236
- const textNoImports = removeProjectImportStatements(text);
2237
- const { code } = await unimport2.injectImports(textNoImports);
2238
- wxt.logger.debug(
2239
- ["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
2240
- );
2241
- const jiti = createJITI(
2242
- typeof __filename !== "undefined" ? __filename : fileURLToPath(import.meta.url),
2243
- {
2244
- cache: false,
2245
- debug: wxt.config.debug,
2246
- esmResolve: true,
2247
- alias: {
2248
- "webextension-polyfill": resolve10(
2249
- wxt.config.wxtModuleDir,
2250
- "dist/virtual/mock-browser.js"
2251
- )
2252
- },
2253
- // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
2254
- // respect the custom transform function when using it's native bun option.
2255
- experimentalBun: false,
2256
- // List of extensions to transform with esbuild
2257
- extensions: [
2258
- ".ts",
2259
- ".cts",
2260
- ".mts",
2261
- ".tsx",
2262
- ".js",
2263
- ".cjs",
2264
- ".mjs",
2265
- ".jsx"
2266
- ],
2267
- transform(opts) {
2268
- const isEntrypoint = opts.filename === normalPath;
2269
- return transformSync(
2270
- // Use modified source code for entrypoints
2271
- isEntrypoint ? code : opts.source,
2272
- getEsbuildOptions(opts)
2273
- );
2274
- }
2275
- }
2276
- );
2277
- try {
2278
- const res = await jiti(path10);
2279
- return res.default;
2280
- } catch (err) {
2281
- const filePath = relative5(wxt.config.root, path10);
2282
- if (err instanceof ReferenceError) {
2283
- const variableName = err.message.replace(" is not defined", "");
2284
- throw Error(
2285
- `${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/entrypoints.html#side-effects`,
2286
- { cause: err }
2287
- );
2288
- } else {
2289
- wxt.logger.error(err);
2290
- throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
2291
- }
2292
- }
2293
- }
2294
- function getEsbuildOptions(opts) {
2295
- const isJsx = opts.filename?.endsWith("x");
2296
- return {
2297
- format: "cjs",
2298
- loader: isJsx ? "tsx" : "ts",
2299
- ...isJsx ? {
2300
- // `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
2301
- // grabbing the entrypoint's options.
2302
- jsxFactory: "h",
2303
- jsxFragment: "Fragment"
2304
- } : void 0
2305
- };
2306
- }
2307
-
2308
2403
  // src/core/utils/building/internal-build.ts
2309
2404
  import pc5 from "picocolors";
2310
2405
  import fs13 from "fs-extra";
2311
2406
 
2312
2407
  // src/core/utils/log/printBuildSummary.ts
2313
- import { resolve as resolve11 } from "path";
2408
+ import { resolve as resolve12 } from "path";
2314
2409
 
2315
2410
  // src/core/utils/log/printFileList.ts
2316
- import path6 from "node:path";
2411
+ import path7 from "node:path";
2317
2412
  import pc3 from "picocolors";
2318
2413
  import fs11 from "fs-extra";
2319
2414
  import { filesize } from "filesize";
@@ -2351,8 +2446,8 @@ async function printFileList(log, header, baseDir, files) {
2351
2446
  const fileRows = await Promise.all(
2352
2447
  files.map(async (file, i) => {
2353
2448
  const parts = [
2354
- path6.relative(process.cwd(), baseDir) + path6.sep,
2355
- path6.relative(baseDir, file)
2449
+ path7.relative(process.cwd(), baseDir) + path7.sep,
2450
+ path7.relative(baseDir, file)
2356
2451
  ];
2357
2452
  const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
2358
2453
  const color = getChunkColor(file);
@@ -2398,7 +2493,7 @@ async function printBuildSummary(log, header, output) {
2398
2493
  return l.fileName.localeCompare(r.fileName);
2399
2494
  });
2400
2495
  const files = chunks.map(
2401
- (chunk) => resolve11(wxt.config.outDir, chunk.fileName)
2496
+ (chunk) => resolve12(wxt.config.outDir, chunk.fileName)
2402
2497
  );
2403
2498
  await printFileList(log, header, wxt.config.outDir, files);
2404
2499
  }
@@ -2423,10 +2518,9 @@ import pc4 from "picocolors";
2423
2518
  var version = "0.17.12";
2424
2519
 
2425
2520
  // src/core/utils/log/printHeader.ts
2426
- import { consola as consola2 } from "consola";
2427
2521
  function printHeader() {
2428
2522
  console.log();
2429
- consola2.log(`${pc4.gray("WXT")} ${pc4.gray(pc4.bold(version))}`);
2523
+ consola.log(`${pc4.gray("WXT")} ${pc4.gray(pc4.bold(version))}`);
2430
2524
  }
2431
2525
 
2432
2526
  // src/core/utils/building/internal-build.ts
@@ -2434,7 +2528,7 @@ import glob3 from "fast-glob";
2434
2528
 
2435
2529
  // src/core/utils/manifest.ts
2436
2530
  import fs12 from "fs-extra";
2437
- import { resolve as resolve12 } from "path";
2531
+ import { resolve as resolve13 } from "path";
2438
2532
 
2439
2533
  // src/core/utils/content-security-policy.ts
2440
2534
  var ContentSecurityPolicy = class _ContentSecurityPolicy {
@@ -2548,7 +2642,7 @@ import defu2 from "defu";
2548
2642
  async function writeManifest(manifest, output) {
2549
2643
  const str = wxt.config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
2550
2644
  await fs12.ensureDir(wxt.config.outDir);
2551
- await writeFileIfDifferent(resolve12(wxt.config.outDir, "manifest.json"), str);
2645
+ await writeFileIfDifferent(resolve13(wxt.config.outDir, "manifest.json"), str);
2552
2646
  output.publicAssets.unshift({
2553
2647
  type: "asset",
2554
2648
  fileName: "manifest.json"
@@ -2606,6 +2700,7 @@ async function generateManifest(entrypoints, buildOutput) {
2606
2700
  if (wxt.config.manifestVersion === 2) {
2607
2701
  convertWebAccessibleResourcesToMv2(manifest);
2608
2702
  convertActionToMv2(manifest);
2703
+ moveHostPermissionsToPermissions(manifest);
2609
2704
  }
2610
2705
  if (wxt.config.manifestVersion === 3) {
2611
2706
  validateMv3WebAccessbileResources(manifest);
@@ -2986,6 +3081,14 @@ function convertWebAccessibleResourcesToMv2(manifest) {
2986
3081
  )
2987
3082
  );
2988
3083
  }
3084
+ function moveHostPermissionsToPermissions(manifest) {
3085
+ if (!manifest.host_permissions?.length)
3086
+ return;
3087
+ manifest.host_permissions.forEach(
3088
+ (permission) => addPermission(manifest, permission)
3089
+ );
3090
+ delete manifest.host_permissions;
3091
+ }
2989
3092
  function convertActionToMv2(manifest) {
2990
3093
  if (manifest.action == null || manifest.browser_action != null || manifest.page_action != null)
2991
3094
  return;
@@ -3147,7 +3250,6 @@ var ValidationError = class extends Error {
3147
3250
  };
3148
3251
 
3149
3252
  // src/core/utils/building/internal-build.ts
3150
- import consola3 from "consola";
3151
3253
  import { mergeJsonOutputs } from "@aklinker1/rollup-plugin-visualizer";
3152
3254
  import { isCI } from "ci-info";
3153
3255
  async function internalBuild() {
@@ -3235,12 +3337,12 @@ function printValidationResults({
3235
3337
  return map;
3236
3338
  }, /* @__PURE__ */ new Map());
3237
3339
  Array.from(entrypointErrors.entries()).forEach(([entrypoint, errors2]) => {
3238
- consola3.log(relative6(cwd, entrypoint.inputPath));
3340
+ consola.log(relative6(cwd, entrypoint.inputPath));
3239
3341
  console.log();
3240
3342
  errors2.forEach((err) => {
3241
3343
  const type = err.type === "error" ? pc5.red("ERROR") : pc5.yellow("WARN");
3242
3344
  const recieved = pc5.dim(`(recieved: ${JSON.stringify(err.value)})`);
3243
- consola3.log(` - ${type} ${err.message} ${recieved}`);
3345
+ consola.log(` - ${type} ${err.message} ${recieved}`);
3244
3346
  });
3245
3347
  console.log();
3246
3348
  });
@@ -3253,37 +3355,36 @@ async function build(config) {
3253
3355
  }
3254
3356
 
3255
3357
  // src/core/clean.ts
3256
- import path7 from "node:path";
3358
+ import path8 from "node:path";
3257
3359
  import glob4 from "fast-glob";
3258
3360
  import fs14 from "fs-extra";
3259
- import { consola as consola4 } from "consola";
3260
3361
  import pc6 from "picocolors";
3261
3362
  async function clean(root = process.cwd()) {
3262
- consola4.info("Cleaning Project");
3363
+ consola.info("Cleaning Project");
3263
3364
  const tempDirs = [
3264
3365
  "node_modules/.vite",
3265
3366
  "node_modules/.cache",
3266
3367
  "**/.wxt",
3267
3368
  ".output/*"
3268
3369
  ];
3269
- consola4.debug("Looking for:", tempDirs.map(pc6.cyan).join(", "));
3370
+ consola.debug("Looking for:", tempDirs.map(pc6.cyan).join(", "));
3270
3371
  const directories = await glob4(tempDirs, {
3271
- cwd: path7.resolve(root),
3372
+ cwd: path8.resolve(root),
3272
3373
  absolute: true,
3273
3374
  onlyDirectories: true,
3274
3375
  deep: 2
3275
3376
  });
3276
3377
  if (directories.length === 0) {
3277
- consola4.debug("No generated files found.");
3378
+ consola.debug("No generated files found.");
3278
3379
  return;
3279
3380
  }
3280
- consola4.debug(
3381
+ consola.debug(
3281
3382
  "Found:",
3282
- directories.map((dir) => pc6.cyan(path7.relative(root, dir))).join(", ")
3383
+ directories.map((dir) => pc6.cyan(path8.relative(root, dir))).join(", ")
3283
3384
  );
3284
3385
  for (const directory of directories) {
3285
3386
  await fs14.rm(directory, { force: true, recursive: true });
3286
- consola4.debug("Deleted " + pc6.cyan(path7.relative(root, directory)));
3387
+ consola.debug("Deleted " + pc6.cyan(path8.relative(root, directory)));
3287
3388
  }
3288
3389
  }
3289
3390
 
@@ -3432,7 +3533,6 @@ async function createExtensionRunner() {
3432
3533
  }
3433
3534
 
3434
3535
  // src/core/create-server.ts
3435
- import { consola as consola5 } from "consola";
3436
3536
  import { Mutex } from "async-mutex";
3437
3537
  import pc7 from "picocolors";
3438
3538
  import { relative as relative10 } from "node:path";
@@ -3472,8 +3572,8 @@ async function createServer(inlineConfig) {
3472
3572
  reloadContentScript(payload) {
3473
3573
  server2.ws.send("wxt:reload-content-script", payload);
3474
3574
  },
3475
- reloadPage(path10) {
3476
- server2.ws.send("wxt:reload-page", path10);
3575
+ reloadPage(path11) {
3576
+ server2.ws.send("wxt:reload-page", path11);
3477
3577
  },
3478
3578
  reloadExtension() {
3479
3579
  server2.ws.send("wxt:reload-extension");
@@ -3516,11 +3616,11 @@ async function createServer(inlineConfig) {
3516
3616
  function createFileReloader(server) {
3517
3617
  const fileChangedMutex = new Mutex();
3518
3618
  const changeQueue = [];
3519
- return async (event, path10) => {
3619
+ return async (event, path11) => {
3520
3620
  await wxt.reloadConfig();
3521
- if (path10.startsWith(wxt.config.outBaseDir))
3621
+ if (path11.startsWith(wxt.config.outBaseDir))
3522
3622
  return;
3523
- changeQueue.push([event, path10]);
3623
+ changeQueue.push([event, path11]);
3524
3624
  await fileChangedMutex.runExclusive(async () => {
3525
3625
  if (server.currentOutput == null)
3526
3626
  return;
@@ -3555,19 +3655,19 @@ function createFileReloader(server) {
3555
3655
  switch (changes.type) {
3556
3656
  case "extension-reload":
3557
3657
  server.reloadExtension();
3558
- consola5.success(`Reloaded extension`);
3658
+ consola.success(`Reloaded extension`);
3559
3659
  break;
3560
3660
  case "html-reload":
3561
3661
  const { reloadedNames } = reloadHtmlPages(
3562
3662
  changes.rebuildGroups,
3563
3663
  server
3564
3664
  );
3565
- consola5.success(`Reloaded: ${getFilenameList(reloadedNames)}`);
3665
+ consola.success(`Reloaded: ${getFilenameList(reloadedNames)}`);
3566
3666
  break;
3567
3667
  case "content-script-reload":
3568
3668
  reloadContentScripts(changes.changedSteps, server);
3569
3669
  const rebuiltNames = changes.rebuildGroups.flat().map((entry) => entry.name);
3570
- consola5.success(`Reloaded: ${getFilenameList(rebuiltNames)}`);
3670
+ consola.success(`Reloaded: ${getFilenameList(rebuiltNames)}`);
3571
3671
  break;
3572
3672
  }
3573
3673
  } catch (err) {
@@ -3602,8 +3702,8 @@ function reloadContentScripts(steps, server) {
3602
3702
  function reloadHtmlPages(groups, server) {
3603
3703
  const htmlEntries = groups.flat().filter(isHtmlEntrypoint);
3604
3704
  htmlEntries.forEach((entry) => {
3605
- const path10 = getEntrypointBundlePath(entry, wxt.config.outDir, ".html");
3606
- server.reloadPage(path10);
3705
+ const path11 = getEntrypointBundlePath(entry, wxt.config.outDir, ".html");
3706
+ server.reloadPage(path11);
3607
3707
  });
3608
3708
  return {
3609
3709
  reloadedNames: htmlEntries.map((entry) => entry.name)
@@ -3631,13 +3731,12 @@ function getExternalOutputDependencies(server) {
3631
3731
 
3632
3732
  // src/core/initialize.ts
3633
3733
  import prompts from "prompts";
3634
- import { consola as consola6 } from "consola";
3635
3734
  import { downloadTemplate } from "giget";
3636
3735
  import fs15 from "fs-extra";
3637
- import path8 from "node:path";
3736
+ import path9 from "node:path";
3638
3737
  import pc8 from "picocolors";
3639
3738
  async function initialize(options) {
3640
- consola6.info("Initalizing new project");
3739
+ consola.info("Initalizing new project");
3641
3740
  const templates = await listTemplates();
3642
3741
  const defaultTemplate = templates.find(
3643
3742
  (template) => template.name === options.template?.toLowerCase().trim()
@@ -3685,24 +3784,24 @@ async function initialize(options) {
3685
3784
  if (isExists) {
3686
3785
  const isEmpty = (await fs15.readdir(input.directory)).length === 0;
3687
3786
  if (!isEmpty) {
3688
- consola6.error(
3689
- `The directory ${path8.resolve(input.directory)} is not empty. Aborted.`
3787
+ consola.error(
3788
+ `The directory ${path9.resolve(input.directory)} is not empty. Aborted.`
3690
3789
  );
3691
3790
  process.exit(1);
3692
3791
  }
3693
3792
  }
3694
3793
  await cloneProject(input);
3695
- const cdPath = path8.relative(process.cwd(), path8.resolve(input.directory));
3794
+ const cdPath = path9.relative(process.cwd(), path9.resolve(input.directory));
3696
3795
  console.log();
3697
- consola6.log(
3796
+ consola.log(
3698
3797
  `\u2728 WXT project created with the ${TEMPLATE_COLORS[input.template.name]?.(input.template.name) ?? input.template.name} template.`
3699
3798
  );
3700
3799
  console.log();
3701
- consola6.log("Next steps:");
3800
+ consola.log("Next steps:");
3702
3801
  let step = 0;
3703
3802
  if (cdPath !== "")
3704
- consola6.log(` ${++step}.`, pc8.cyan(`cd ${cdPath}`));
3705
- consola6.log(` ${++step}.`, pc8.cyan(`${input.packageManager} install`));
3803
+ consola.log(` ${++step}.`, pc8.cyan(`cd ${cdPath}`));
3804
+ consola.log(` ${++step}.`, pc8.cyan(`${input.packageManager} install`));
3706
3805
  console.log();
3707
3806
  }
3708
3807
  async function listTemplates() {
@@ -3720,7 +3819,7 @@ async function listTemplates() {
3720
3819
  return l.name.localeCompare(r.name);
3721
3820
  });
3722
3821
  } catch (err) {
3723
- consola6.error(err);
3822
+ consola.error(err);
3724
3823
  throw Error(`Failed to load templates`);
3725
3824
  }
3726
3825
  }
@@ -3737,10 +3836,10 @@ async function cloneProject({
3737
3836
  force: true
3738
3837
  });
3739
3838
  await fs15.move(
3740
- path8.join(directory, "_gitignore"),
3741
- path8.join(directory, ".gitignore")
3839
+ path9.join(directory, "_gitignore"),
3840
+ path9.join(directory, ".gitignore")
3742
3841
  ).catch(
3743
- (err) => consola6.warn("Failed to move _gitignore to .gitignore:", err)
3842
+ (err) => consola.warn("Failed to move _gitignore to .gitignore:", err)
3744
3843
  );
3745
3844
  spinner.succeed();
3746
3845
  } catch (err) {
@@ -3770,7 +3869,7 @@ async function prepare(config) {
3770
3869
  }
3771
3870
 
3772
3871
  // src/core/zip.ts
3773
- import path9 from "node:path";
3872
+ import path10 from "node:path";
3774
3873
  import fs16 from "fs-extra";
3775
3874
  import { minimatch as minimatch2 } from "minimatch";
3776
3875
  import JSZip from "jszip";
@@ -3782,7 +3881,7 @@ async function zip(config) {
3782
3881
  wxt.logger.info("Zipping extension...");
3783
3882
  const zipFiles = [];
3784
3883
  const projectName = wxt.config.zip.name ?? kebabCaseAlphanumeric(
3785
- (await getPackageJson())?.name || path9.dirname(process.cwd())
3884
+ (await getPackageJson())?.name || path10.dirname(process.cwd())
3786
3885
  );
3787
3886
  const applyTemplate = (template) => template.replaceAll("{{name}}", projectName).replaceAll("{{browser}}", wxt.config.browser).replaceAll(
3788
3887
  "{{version}}",
@@ -3790,13 +3889,13 @@ async function zip(config) {
3790
3889
  ).replaceAll("{{mode}}", wxt.config.mode).replaceAll("{{manifestVersion}}", `mv${wxt.config.manifestVersion}`);
3791
3890
  await fs16.ensureDir(wxt.config.outBaseDir);
3792
3891
  const outZipFilename = applyTemplate(wxt.config.zip.artifactTemplate);
3793
- const outZipPath = path9.resolve(wxt.config.outBaseDir, outZipFilename);
3892
+ const outZipPath = path10.resolve(wxt.config.outBaseDir, outZipFilename);
3794
3893
  await zipDir(wxt.config.outDir, outZipPath);
3795
3894
  zipFiles.push(outZipPath);
3796
3895
  if (wxt.config.browser === "firefox") {
3797
3896
  const { overrides, files: downloadedPackages } = await downloadPrivatePackages();
3798
3897
  const sourcesZipFilename = applyTemplate(wxt.config.zip.sourcesTemplate);
3799
- const sourcesZipPath = path9.resolve(
3898
+ const sourcesZipPath = path10.resolve(
3800
3899
  wxt.config.outBaseDir,
3801
3900
  sourcesZipFilename
3802
3901
  );
@@ -3837,11 +3936,11 @@ async function zipDir(directory, outputPath, options) {
3837
3936
  const filesToZip = [
3838
3937
  ...files,
3839
3938
  ...(options?.additionalFiles ?? []).map(
3840
- (file) => path9.relative(directory, file)
3939
+ (file) => path10.relative(directory, file)
3841
3940
  )
3842
3941
  ];
3843
3942
  for (const file of filesToZip) {
3844
- const absolutePath = path9.resolve(directory, file);
3943
+ const absolutePath = path10.resolve(directory, file);
3845
3944
  if (file.endsWith(".json")) {
3846
3945
  const content = await fs16.readFile(absolutePath, "utf-8");
3847
3946
  archive.file(
@@ -3854,7 +3953,13 @@ async function zipDir(directory, outputPath, options) {
3854
3953
  }
3855
3954
  }
3856
3955
  await options?.additionalWork?.(archive);
3857
- const buffer = await archive.generateAsync({ type: "base64" });
3956
+ const buffer = await archive.generateAsync({
3957
+ type: "base64",
3958
+ ...wxt.config.zip.compressionLevel === 0 ? { compression: "STORE" } : {
3959
+ compression: "DEFLATE",
3960
+ compressionOptions: { level: wxt.config.zip.compressionLevel }
3961
+ }
3962
+ });
3858
3963
  await fs16.writeFile(outputPath, buffer, "base64");
3859
3964
  }
3860
3965
  async function downloadPrivatePackages() {
@@ -3885,41 +3990,40 @@ async function downloadPrivatePackages() {
3885
3990
  function addOverridesToPackageJson(absolutePackageJsonPath, content, overrides) {
3886
3991
  if (Object.keys(overrides).length === 0)
3887
3992
  return content;
3888
- const packageJsonDir = path9.dirname(absolutePackageJsonPath);
3993
+ const packageJsonDir = path10.dirname(absolutePackageJsonPath);
3889
3994
  const oldPackage = JSON.parse(content);
3890
3995
  const newPackage = {
3891
3996
  ...oldPackage,
3892
3997
  [wxt.pm.overridesKey]: { ...oldPackage[wxt.pm.overridesKey] }
3893
3998
  };
3894
3999
  Object.entries(overrides).forEach(([key, absolutePath]) => {
3895
- newPackage[wxt.pm.overridesKey][key] = "file://./" + normalizePath(path9.relative(packageJsonDir, absolutePath));
4000
+ newPackage[wxt.pm.overridesKey][key] = "file://./" + normalizePath(path10.relative(packageJsonDir, absolutePath));
3896
4001
  });
3897
4002
  return JSON.stringify(newPackage, null, 2);
3898
4003
  }
3899
4004
 
3900
4005
  // src/cli/cli-utils.ts
3901
- import consola7, { LogLevels as LogLevels2 } from "consola";
3902
4006
  function wrapAction(cb, options) {
3903
4007
  return async (...args) => {
3904
4008
  const isDebug = !!args.find((arg) => arg?.debug);
3905
4009
  if (isDebug) {
3906
- consola7.level = LogLevels2.debug;
4010
+ consola.level = LogLevels.debug;
3907
4011
  }
3908
4012
  const startTime = Date.now();
3909
4013
  try {
3910
4014
  printHeader();
3911
4015
  const status = await cb(...args);
3912
4016
  if (!status?.isOngoing && !options?.disableFinishedLog)
3913
- consola7.success(
4017
+ consola.success(
3914
4018
  `Finished in ${formatDuration(Date.now() - startTime)}`
3915
4019
  );
3916
4020
  } catch (err) {
3917
- consola7.fail(
4021
+ consola.fail(
3918
4022
  `Command failed after ${formatDuration(Date.now() - startTime)}`
3919
4023
  );
3920
4024
  if (err instanceof ValidationError) {
3921
4025
  } else {
3922
- consola7.error(err);
4026
+ consola.error(err);
3923
4027
  }
3924
4028
  process.exit(1);
3925
4029
  }
@@ -3938,7 +4042,7 @@ function createAliasedCommand(base, name, alias, bin, docsUrl) {
3938
4042
  const args = process.argv.slice(
3939
4043
  process.argv.indexOf(aliasedCommand.name) + 1
3940
4044
  );
3941
- const { execa } = await import("./execa-Y2EWTC4S.js");
4045
+ const { execa } = await import("./execa-6HO2IY2B.js");
3942
4046
  await execa(bin, args, {
3943
4047
  stdio: "inherit"
3944
4048
  });