wxt 0.1.4 → 0.1.6

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/index.cjs CHANGED
@@ -328,15 +328,41 @@ function virtualEntrypoin(type, config) {
328
328
  };
329
329
  }
330
330
 
331
+ // src/core/vite-plugins/tsconfigPaths.ts
332
+ var import_vite_tsconfig_paths = __toESM(require("vite-tsconfig-paths"), 1);
333
+ function tsconfigPaths(config) {
334
+ const fn = typeof import_vite_tsconfig_paths.default === "function" ? import_vite_tsconfig_paths.default : import_vite_tsconfig_paths.default.default;
335
+ return fn({
336
+ root: config.root
337
+ });
338
+ }
339
+
340
+ // src/core/vite-plugins/hmrLogger.ts
341
+ var import_path4 = require("path");
342
+ var import_picocolors = __toESM(require("picocolors"), 1);
343
+ function hmrLogger(config) {
344
+ return {
345
+ name: "wxt:hmr-logger",
346
+ apply: "serve",
347
+ handleHotUpdate(ctx) {
348
+ if (ctx.file.startsWith(config.srcDir) && !ctx.file.startsWith(config.wxtDir) && !ctx.file.endsWith(".html")) {
349
+ config.logger.info(
350
+ "Hot reload: " + import_picocolors.default.dim((0, import_path4.relative)(process.cwd(), ctx.file))
351
+ );
352
+ }
353
+ }
354
+ };
355
+ }
356
+
331
357
  // src/core/utils/createFsCache.ts
332
358
  var import_fs_extra3 = __toESM(require("fs-extra"), 1);
333
- var import_path4 = require("path");
359
+ var import_path5 = require("path");
334
360
  function createFsCache(wxtDir) {
335
- const getPath = (key) => (0, import_path4.resolve)(wxtDir, "cache", encodeURIComponent(key));
361
+ const getPath = (key) => (0, import_path5.resolve)(wxtDir, "cache", encodeURIComponent(key));
336
362
  return {
337
363
  async set(key, value) {
338
364
  const path5 = getPath(key);
339
- await (0, import_fs_extra3.ensureDir)((0, import_path4.dirname)(path5));
365
+ await (0, import_fs_extra3.ensureDir)((0, import_path5.dirname)(path5));
340
366
  await import_fs_extra3.default.writeFile(path5, value, "utf-8");
341
367
  },
342
368
  async get(key) {
@@ -480,6 +506,8 @@ async function getInternalConfig(config, command) {
480
506
  virtualEntrypoin("content-script", finalConfig)
481
507
  );
482
508
  finalConfig.vite.plugins.push(devServerGlobals(finalConfig));
509
+ finalConfig.vite.plugins.push(tsconfigPaths(finalConfig));
510
+ finalConfig.vite.plugins.push(hmrLogger(finalConfig));
483
511
  finalConfig.vite.define ??= {};
484
512
  getGlobals(finalConfig).forEach((global) => {
485
513
  finalConfig.vite.define[global.name] = JSON.stringify(global.value);
@@ -491,7 +519,7 @@ async function resolveManifestConfig(env, manifest) {
491
519
  }
492
520
 
493
521
  // src/index.ts
494
- var import_picocolors3 = __toESM(require("picocolors"), 1);
522
+ var import_picocolors4 = __toESM(require("picocolors"), 1);
495
523
  var vite5 = __toESM(require("vite"), 1);
496
524
 
497
525
  // src/core/utils/arrays.ts
@@ -595,11 +623,11 @@ var vite2 = __toESM(require("vite"), 1);
595
623
 
596
624
  // src/core/utils/removeEmptyDirs.ts
597
625
  var import_fs_extra4 = __toESM(require("fs-extra"), 1);
598
- var import_path5 = __toESM(require("path"), 1);
626
+ var import_path6 = __toESM(require("path"), 1);
599
627
  async function removeEmptyDirs(dir) {
600
628
  const files = await import_fs_extra4.default.readdir(dir);
601
629
  for (const file of files) {
602
- const filePath = import_path5.default.join(dir, file);
630
+ const filePath = import_path6.default.join(dir, file);
603
631
  const stats = await import_fs_extra4.default.stat(filePath);
604
632
  if (stats.isDirectory()) {
605
633
  await removeEmptyDirs(filePath);
@@ -614,7 +642,7 @@ async function removeEmptyDirs(dir) {
614
642
  // src/core/build/buildEntrypoints.ts
615
643
  var import_fast_glob = __toESM(require("fast-glob"), 1);
616
644
  var import_fs_extra5 = __toESM(require("fs-extra"), 1);
617
- var import_path6 = require("path");
645
+ var import_path7 = require("path");
618
646
  async function buildEntrypoints(groups, config) {
619
647
  const steps = [];
620
648
  for (const group of groups) {
@@ -706,9 +734,9 @@ async function copyPublicDirectory(config) {
706
734
  return publicAssets;
707
735
  const files = await (0, import_fast_glob.default)("**/*", { cwd: config.publicDir });
708
736
  for (const file of files) {
709
- const srcPath = (0, import_path6.resolve)(config.publicDir, file);
710
- const outPath = (0, import_path6.resolve)(config.outDir, file);
711
- await import_fs_extra5.default.ensureDir((0, import_path6.dirname)(outPath));
737
+ const srcPath = (0, import_path7.resolve)(config.publicDir, file);
738
+ const outPath = (0, import_path7.resolve)(config.outDir, file);
739
+ await import_fs_extra5.default.ensureDir((0, import_path7.dirname)(outPath));
712
740
  await import_fs_extra5.default.copyFile(srcPath, outPath);
713
741
  publicAssets.push({
714
742
  type: "asset",
@@ -722,7 +750,7 @@ async function copyPublicDirectory(config) {
722
750
  }
723
751
 
724
752
  // src/core/build/findEntrypoints.ts
725
- var import_path8 = require("path");
753
+ var import_path9 = require("path");
726
754
  var import_fs_extra7 = __toESM(require("fs-extra"), 1);
727
755
  var import_picomatch = __toESM(require("picomatch"), 1);
728
756
  var import_linkedom2 = require("linkedom");
@@ -732,7 +760,7 @@ var import_json5 = __toESM(require("json5"), 1);
732
760
  var import_jiti = __toESM(require("jiti"), 1);
733
761
  var import_unimport2 = require("unimport");
734
762
  var import_fs_extra6 = __toESM(require("fs-extra"), 1);
735
- var import_path7 = require("path");
763
+ var import_path8 = require("path");
736
764
  var import_babel = __toESM(require("jiti/dist/babel"), 1);
737
765
  async function importTsFile(path5, config) {
738
766
  config.logger.debug("Loading file metadata:", path5);
@@ -754,7 +782,7 @@ async function importTsFile(path5, config) {
754
782
  esmResolve: true,
755
783
  interopDefault: true,
756
784
  alias: {
757
- "webextension-polyfill": (0, import_path7.resolve)(
785
+ "webextension-polyfill": (0, import_path8.resolve)(
758
786
  config.root,
759
787
  "node_modules/wxt/dist/virtual-modules/fake-browser.js"
760
788
  )
@@ -786,7 +814,7 @@ async function findEntrypoints(config) {
786
814
  const entrypoints = [];
787
815
  await Promise.all(
788
816
  relativePaths.map(async (relativePath) => {
789
- const path5 = (0, import_path8.resolve)(config.entrypointsDir, relativePath);
817
+ const path5 = (0, import_path9.resolve)(config.entrypointsDir, relativePath);
790
818
  const matchingGlob = pathGlobs.find(
791
819
  (glob3) => import_picomatch.default.isMatch(relativePath, glob3)
792
820
  );
@@ -833,8 +861,8 @@ ${JSON.stringify(
833
861
  if (withSameName) {
834
862
  throw Error(
835
863
  `Multiple entrypoints with the name "${entrypoint.name}" detected, but only one is allowed: ${[
836
- (0, import_path8.relative)(config.root, withSameName.inputPath),
837
- (0, import_path8.relative)(config.root, entrypoint.inputPath)
864
+ (0, import_path9.relative)(config.root, withSameName.inputPath),
865
+ (0, import_path9.relative)(config.root, entrypoint.inputPath)
838
866
  ].join(", ")}`
839
867
  );
840
868
  }
@@ -923,7 +951,7 @@ async function getContentScriptEntrypoint(config, name, path5) {
923
951
  type: "content-script",
924
952
  name: getEntrypointName(config.entrypointsDir, path5),
925
953
  inputPath: path5,
926
- outputDir: (0, import_path8.resolve)(config.outDir, "content-scripts"),
954
+ outputDir: (0, import_path9.resolve)(config.outDir, "content-scripts"),
927
955
  options
928
956
  };
929
957
  }
@@ -961,7 +989,7 @@ var PATH_GLOB_TO_TYPE_MAP = {
961
989
  // src/core/build/generateTypesDir.ts
962
990
  var import_unimport3 = require("unimport");
963
991
  var import_fs_extra8 = __toESM(require("fs-extra"), 1);
964
- var import_path9 = require("path");
992
+ var import_path10 = require("path");
965
993
  async function generateTypesDir(entrypoints, config) {
966
994
  await import_fs_extra8.default.ensureDir(config.typesDir);
967
995
  const references = [];
@@ -972,7 +1000,7 @@ async function generateTypesDir(entrypoints, config) {
972
1000
  await writeTsConfigFile(mainReference, config);
973
1001
  }
974
1002
  async function writeImportsDeclarationFile(config) {
975
- const filePath = (0, import_path9.resolve)(config.typesDir, "imports.d.ts");
1003
+ const filePath = (0, import_path10.resolve)(config.typesDir, "imports.d.ts");
976
1004
  const unimport2 = (0, import_unimport3.createUnimport)(getUnimportOptions(config));
977
1005
  await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
978
1006
  await import_fs_extra8.default.writeFile(
@@ -984,7 +1012,7 @@ async function writeImportsDeclarationFile(config) {
984
1012
  return filePath;
985
1013
  }
986
1014
  async function writePathsDeclarationFile(entrypoints, config) {
987
- const filePath = (0, import_path9.resolve)(config.typesDir, "paths.d.ts");
1015
+ const filePath = (0, import_path10.resolve)(config.typesDir, "paths.d.ts");
988
1016
  const unions = entrypoints.map((entry) => {
989
1017
  const path5 = getEntrypointBundlePath(
990
1018
  entry,
@@ -1004,7 +1032,7 @@ async function writePathsDeclarationFile(entrypoints, config) {
1004
1032
  return filePath;
1005
1033
  }
1006
1034
  async function writeGlobalsDeclarationFile(config) {
1007
- const filePath = (0, import_path9.resolve)(config.typesDir, "globals.d.ts");
1035
+ const filePath = (0, import_path10.resolve)(config.typesDir, "globals.d.ts");
1008
1036
  const globals = getGlobals(config);
1009
1037
  await import_fs_extra8.default.writeFile(
1010
1038
  filePath,
@@ -1021,13 +1049,14 @@ async function writeGlobalsDeclarationFile(config) {
1021
1049
  }
1022
1050
  async function writeMainDeclarationFile(references, config) {
1023
1051
  const dir = config.wxtDir;
1024
- const filePath = (0, import_path9.resolve)(dir, "wxt.d.ts");
1052
+ const filePath = (0, import_path10.resolve)(dir, "wxt.d.ts");
1025
1053
  await import_fs_extra8.default.writeFile(
1026
1054
  filePath,
1027
1055
  [
1028
1056
  "// Generated by wxt",
1057
+ `/// <reference types="vite/client" />`,
1029
1058
  ...references.map(
1030
- (ref) => `/// <reference types="./${(0, import_path9.relative)(dir, ref)}" />`
1059
+ (ref) => `/// <reference types="./${(0, import_path10.relative)(dir, ref)}" />`
1031
1060
  )
1032
1061
  ].join("\n") + "\n"
1033
1062
  );
@@ -1036,7 +1065,7 @@ async function writeMainDeclarationFile(references, config) {
1036
1065
  async function writeTsConfigFile(mainReference, config) {
1037
1066
  const dir = config.wxtDir;
1038
1067
  await import_fs_extra8.default.writeFile(
1039
- (0, import_path9.resolve)(dir, "tsconfig.json"),
1068
+ (0, import_path10.resolve)(dir, "tsconfig.json"),
1040
1069
  `{
1041
1070
  "compilerOptions": {
1042
1071
  "target": "ESNext",
@@ -1054,30 +1083,30 @@ async function writeTsConfigFile(mainReference, config) {
1054
1083
  "skipLibCheck": true,
1055
1084
 
1056
1085
  /* Aliases */
1057
- "baseUrl": "${(0, import_path9.relative)(dir, config.root)}",
1086
+ "baseUrl": "${(0, import_path10.relative)(dir, config.root)}",
1058
1087
  "paths": {
1059
1088
  "@@": ["."],
1060
1089
  "@@/*": ["./*"],
1061
1090
  "~~": ["."],
1062
1091
  "~~/*": ["./*"],
1063
- "@": ["${(0, import_path9.relative)(config.root, config.srcDir)}"],
1064
- "@/*": ["${(0, import_path9.relative)(config.root, config.srcDir)}/*"],
1065
- "~": ["${(0, import_path9.relative)(config.root, config.srcDir)}"],
1066
- "~/*": ["${(0, import_path9.relative)(config.root, config.srcDir)}/*"]
1092
+ "@": ["${(0, import_path10.relative)(config.root, config.srcDir)}"],
1093
+ "@/*": ["${(0, import_path10.relative)(config.root, config.srcDir)}/*"],
1094
+ "~": ["${(0, import_path10.relative)(config.root, config.srcDir)}"],
1095
+ "~/*": ["${(0, import_path10.relative)(config.root, config.srcDir)}/*"]
1067
1096
  }
1068
1097
  },
1069
1098
  "include": [
1070
- "${(0, import_path9.relative)(dir, config.root)}/**/*",
1071
- "./${(0, import_path9.relative)(dir, mainReference)}"
1099
+ "${(0, import_path10.relative)(dir, config.root)}/**/*",
1100
+ "./${(0, import_path10.relative)(dir, mainReference)}"
1072
1101
  ],
1073
- "exclude": ["${(0, import_path9.relative)(dir, config.outBaseDir)}"]
1102
+ "exclude": ["${(0, import_path10.relative)(dir, config.outBaseDir)}"]
1074
1103
  }`
1075
1104
  );
1076
1105
  }
1077
1106
 
1078
1107
  // src/core/utils/manifest.ts
1079
1108
  var import_fs_extra9 = __toESM(require("fs-extra"), 1);
1080
- var import_path10 = require("path");
1109
+ var import_path11 = require("path");
1081
1110
 
1082
1111
  // src/core/utils/ContentSecurityPolicy.ts
1083
1112
  var ContentSecurityPolicy = class _ContentSecurityPolicy {
@@ -1126,7 +1155,7 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
1126
1155
  async function writeManifest(manifest, output, config) {
1127
1156
  const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
1128
1157
  await import_fs_extra9.default.ensureDir(config.outDir);
1129
- await import_fs_extra9.default.writeFile((0, import_path10.resolve)(config.outDir, "manifest.json"), str, "utf-8");
1158
+ await import_fs_extra9.default.writeFile((0, import_path11.resolve)(config.outDir, "manifest.json"), str, "utf-8");
1130
1159
  output.publicAssets.unshift({
1131
1160
  type: "asset",
1132
1161
  fileName: "manifest.json",
@@ -1159,7 +1188,7 @@ async function generateMainfest(entrypoints, buildOutput, config) {
1159
1188
  return manifest;
1160
1189
  }
1161
1190
  async function getPackageJson(config) {
1162
- return await import_fs_extra9.default.readJson((0, import_path10.resolve)(config.root, "package.json"));
1191
+ return await import_fs_extra9.default.readJson((0, import_path11.resolve)(config.root, "package.json"));
1163
1192
  }
1164
1193
  function simplifyVersion(versionName) {
1165
1194
  const version3 = /^((0|[1-9][0-9]{0,8})([.](0|[1-9][0-9]{0,8})){0,3}).*$/.exec(
@@ -1402,7 +1431,7 @@ function addHostPermission(manifest, hostPermission) {
1402
1431
  }
1403
1432
 
1404
1433
  // src/core/build.ts
1405
- var import_picocolors2 = __toESM(require("picocolors"), 1);
1434
+ var import_picocolors3 = __toESM(require("picocolors"), 1);
1406
1435
  var vite3 = __toESM(require("vite"), 1);
1407
1436
  var import_fs_extra11 = __toESM(require("fs-extra"), 1);
1408
1437
 
@@ -1452,7 +1481,7 @@ function formatDuration(duration) {
1452
1481
  }
1453
1482
 
1454
1483
  // src/core/log/printBuildSummary.ts
1455
- var import_path11 = __toESM(require("path"), 1);
1484
+ var import_path12 = __toESM(require("path"), 1);
1456
1485
 
1457
1486
  // src/core/log/printTable.ts
1458
1487
  function printTable(log, rows, gap = 2) {
@@ -1481,7 +1510,7 @@ function printTable(log, rows, gap = 2) {
1481
1510
  }
1482
1511
 
1483
1512
  // src/core/log/printBuildSummary.ts
1484
- var import_picocolors = __toESM(require("picocolors"), 1);
1513
+ var import_picocolors2 = __toESM(require("picocolors"), 1);
1485
1514
  var import_fs_extra10 = __toESM(require("fs-extra"), 1);
1486
1515
  var import_filesize = require("filesize");
1487
1516
  async function printBuildSummary(output, config) {
@@ -1500,23 +1529,23 @@ async function printBuildSummary(output, config) {
1500
1529
  const chunkRows = await Promise.all(
1501
1530
  chunks.map(async (chunk, i) => {
1502
1531
  const file = [
1503
- (0, import_path11.relative)(process.cwd(), config.outDir) + import_path11.default.sep,
1532
+ (0, import_path12.relative)(process.cwd(), config.outDir) + import_path12.default.sep,
1504
1533
  chunk.fileName
1505
1534
  ];
1506
1535
  const prefix = i === chunks.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
1507
1536
  const color = getChunkColor(chunk.fileName);
1508
- const stats = await import_fs_extra10.default.lstat((0, import_path11.resolve)(config.outDir, chunk.fileName));
1537
+ const stats = await import_fs_extra10.default.lstat((0, import_path12.resolve)(config.outDir, chunk.fileName));
1509
1538
  totalSize += stats.size;
1510
1539
  const size = String((0, import_filesize.filesize)(stats.size));
1511
1540
  return [
1512
- `${import_picocolors.default.gray(prefix)} ${import_picocolors.default.dim(file[0])}${color(file[1])}`,
1513
- import_picocolors.default.dim(size)
1541
+ `${import_picocolors2.default.gray(prefix)} ${import_picocolors2.default.dim(file[0])}${color(file[1])}`,
1542
+ import_picocolors2.default.dim(size)
1514
1543
  ];
1515
1544
  })
1516
1545
  );
1517
1546
  printTable(config.logger.log, chunkRows);
1518
1547
  config.logger.log(
1519
- `${import_picocolors.default.cyan("\u03A3 Total size:")} ${String((0, import_filesize.filesize)(totalSize))}`
1548
+ `${import_picocolors2.default.cyan("\u03A3 Total size:")} ${String((0, import_filesize.filesize)(totalSize))}`
1520
1549
  );
1521
1550
  }
1522
1551
  var DEFAULT_SORT_WEIGHT = 100;
@@ -1532,12 +1561,12 @@ function getChunkSortWeight(filename) {
1532
1561
  ([key]) => filename.endsWith(key)
1533
1562
  )?.[1] ?? DEFAULT_SORT_WEIGHT;
1534
1563
  }
1535
- var DEFAULT_COLOR = import_picocolors.default.blue;
1564
+ var DEFAULT_COLOR = import_picocolors2.default.blue;
1536
1565
  var CHUNK_COLORS = {
1537
- ".js.map": import_picocolors.default.gray,
1538
- ".html": import_picocolors.default.green,
1539
- ".css": import_picocolors.default.magenta,
1540
- ".js": import_picocolors.default.cyan
1566
+ ".js.map": import_picocolors2.default.gray,
1567
+ ".html": import_picocolors2.default.green,
1568
+ ".css": import_picocolors2.default.magenta,
1569
+ ".js": import_picocolors2.default.cyan
1541
1570
  };
1542
1571
  function getChunkColor(filename) {
1543
1572
  return Object.entries(CHUNK_COLORS).find(([key]) => filename.endsWith(key))?.[1] ?? DEFAULT_COLOR;
@@ -1548,7 +1577,7 @@ async function buildInternal(config) {
1548
1577
  const verb = config.command === "serve" ? "Pre-rendering" : "Building";
1549
1578
  const target = `${config.browser}-mv${config.manifestVersion}`;
1550
1579
  config.logger.info(
1551
- `${verb} ${import_picocolors2.default.cyan(target)} for ${import_picocolors2.default.cyan(config.mode)} with ${import_picocolors2.default.green(
1580
+ `${verb} ${import_picocolors3.default.cyan(target)} for ${import_picocolors3.default.cyan(config.mode)} with ${import_picocolors3.default.green(
1552
1581
  `Vite ${vite3.version}`
1553
1582
  )}`
1554
1583
  );
@@ -1767,7 +1796,7 @@ function reloadHtmlPages(groups, server, config) {
1767
1796
  }
1768
1797
 
1769
1798
  // package.json
1770
- var version2 = "0.1.4";
1799
+ var version2 = "0.1.6";
1771
1800
 
1772
1801
  // src/core/utils/defineConfig.ts
1773
1802
  function defineConfig(config) {
@@ -1810,14 +1839,14 @@ async function createServer2(config) {
1810
1839
  const changes = detectDevChanges(fileChanges, server.currentOutput);
1811
1840
  if (changes.type === "no-change")
1812
1841
  return;
1813
- import_consola2.consola.info(
1814
- `Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => import_picocolors3.default.dim((0, import_node_path4.relative)(internalConfig.root, file))).join(", ")}`
1842
+ internalConfig.logger.info(
1843
+ `Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => import_picocolors4.default.dim((0, import_node_path4.relative)(internalConfig.root, file))).join(", ")}`
1815
1844
  );
1816
1845
  const rebuiltNames = changes.rebuildGroups.flat().map((entry) => {
1817
- return import_picocolors3.default.cyan(
1846
+ return import_picocolors4.default.cyan(
1818
1847
  (0, import_node_path4.relative)(internalConfig.outDir, getEntrypointOutputFile(entry, ""))
1819
1848
  );
1820
- }).join(import_picocolors3.default.dim(", "));
1849
+ }).join(import_picocolors4.default.dim(", "));
1821
1850
  internalConfig = await getLatestInternalConfig();
1822
1851
  internalConfig.server = server;
1823
1852
  const { output: newOutput } = await rebuild(