wxt 0.4.0 → 0.5.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/index.cjs CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  build: () => build2,
34
+ clean: () => clean,
34
35
  createServer: () => createServer2,
35
36
  defineConfig: () => defineConfig,
36
37
  defineRunnerConfig: () => defineRunnerConfig,
@@ -49,11 +50,11 @@ var import_node_path2 = __toESM(require("path"), 1);
49
50
  // src/core/utils/paths.ts
50
51
  var import_node_path = __toESM(require("path"), 1);
51
52
  var vite = __toESM(require("vite"), 1);
52
- function normalizePath2(path6) {
53
- return vite.normalizePath(path6);
53
+ function normalizePath2(path7) {
54
+ return vite.normalizePath(path7);
54
55
  }
55
- function unnormalizePath(path6) {
56
- return import_node_path.default.normalize(path6);
56
+ function unnormalizePath(path7) {
57
+ return import_node_path.default.normalize(path7);
57
58
  }
58
59
  var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
59
60
  var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
@@ -407,20 +408,31 @@ function cssEntrypoints(entrypoint, config) {
407
408
  }
408
409
 
409
410
  // src/core/utils/createFsCache.ts
410
- var import_fs_extra3 = __toESM(require("fs-extra"), 1);
411
+ var import_fs_extra4 = __toESM(require("fs-extra"), 1);
411
412
  var import_path4 = require("path");
413
+
414
+ // src/core/utils/fs.ts
415
+ var import_fs_extra3 = __toESM(require("fs-extra"), 1);
416
+ async function writeFileIfDifferent(file, newContents) {
417
+ const existingContents = await import_fs_extra3.default.readFile(file, "utf-8").catch(() => void 0);
418
+ if (existingContents !== newContents) {
419
+ await import_fs_extra3.default.writeFile(file, newContents);
420
+ }
421
+ }
422
+
423
+ // src/core/utils/createFsCache.ts
412
424
  function createFsCache(wxtDir) {
413
425
  const getPath = (key) => (0, import_path4.resolve)(wxtDir, "cache", encodeURIComponent(key));
414
426
  return {
415
427
  async set(key, value) {
416
- const path6 = getPath(key);
417
- await (0, import_fs_extra3.ensureDir)((0, import_path4.dirname)(path6));
418
- await import_fs_extra3.default.writeFile(path6, value, "utf-8");
428
+ const path7 = getPath(key);
429
+ await (0, import_fs_extra4.ensureDir)((0, import_path4.dirname)(path7));
430
+ await writeFileIfDifferent(path7, value);
419
431
  },
420
432
  async get(key) {
421
- const path6 = getPath(key);
433
+ const path7 = getPath(key);
422
434
  try {
423
- return await import_fs_extra3.default.readFile(path6, "utf-8");
435
+ return await import_fs_extra4.default.readFile(path7, "utf-8");
424
436
  } catch {
425
437
  return void 0;
426
438
  }
@@ -528,7 +540,7 @@ async function getInternalConfig(config, command) {
528
540
  srcDir,
529
541
  userConfig.entrypointsDir ?? "entrypoints"
530
542
  );
531
- const publicDir = (0, import_node_path4.resolve)(root, userConfig.publicDir ?? "public");
543
+ const publicDir = (0, import_node_path4.resolve)(srcDir, userConfig.publicDir ?? "public");
532
544
  const wxtDir = (0, import_node_path4.resolve)(root, ".wxt");
533
545
  const typesDir = (0, import_node_path4.resolve)(wxtDir, "types");
534
546
  const env = { mode, browser, manifestVersion, command };
@@ -595,7 +607,7 @@ async function resolveManifestConfig(env, manifest) {
595
607
  }
596
608
 
597
609
  // src/index.ts
598
- var import_picocolors3 = __toESM(require("picocolors"), 1);
610
+ var import_picocolors4 = __toESM(require("picocolors"), 1);
599
611
  var vite6 = __toESM(require("vite"), 1);
600
612
 
601
613
  // src/core/utils/arrays.ts
@@ -692,39 +704,39 @@ function findEffectedSteps(changedFile, currentOutput) {
692
704
 
693
705
  // src/index.ts
694
706
  var import_async_mutex = require("async-mutex");
695
- var import_consola2 = require("consola");
696
- var import_node_path8 = require("path");
707
+ var import_consola3 = require("consola");
708
+ var import_node_path9 = require("path");
697
709
 
698
710
  // src/core/build/buildEntrypoints.ts
699
711
  var vite3 = __toESM(require("vite"), 1);
700
712
 
701
713
  // src/core/utils/removeEmptyDirs.ts
702
- var import_fs_extra4 = __toESM(require("fs-extra"), 1);
714
+ var import_fs_extra5 = __toESM(require("fs-extra"), 1);
703
715
  var import_path5 = __toESM(require("path"), 1);
704
716
  async function removeEmptyDirs(dir) {
705
- const files = await import_fs_extra4.default.readdir(dir);
717
+ const files = await import_fs_extra5.default.readdir(dir);
706
718
  for (const file of files) {
707
719
  const filePath = import_path5.default.join(dir, file);
708
- const stats = await import_fs_extra4.default.stat(filePath);
720
+ const stats = await import_fs_extra5.default.stat(filePath);
709
721
  if (stats.isDirectory()) {
710
722
  await removeEmptyDirs(filePath);
711
723
  }
712
724
  }
713
725
  try {
714
- await import_fs_extra4.default.rmdir(dir);
726
+ await import_fs_extra5.default.rmdir(dir);
715
727
  } catch {
716
728
  }
717
729
  }
718
730
 
719
731
  // src/core/build/buildEntrypoints.ts
720
- var import_fs_extra6 = __toESM(require("fs-extra"), 1);
732
+ var import_fs_extra7 = __toESM(require("fs-extra"), 1);
721
733
  var import_path6 = require("path");
722
734
 
723
735
  // src/core/utils/public.ts
724
- var import_fs_extra5 = __toESM(require("fs-extra"), 1);
736
+ var import_fs_extra6 = __toESM(require("fs-extra"), 1);
725
737
  var import_fast_glob = __toESM(require("fast-glob"), 1);
726
738
  async function getPublicFiles(config) {
727
- if (!await import_fs_extra5.default.exists(config.publicDir))
739
+ if (!await import_fs_extra6.default.exists(config.publicDir))
728
740
  return [];
729
741
  const files = await (0, import_fast_glob.default)("**/*", { cwd: config.publicDir });
730
742
  return files.map(unnormalizePath);
@@ -829,14 +841,14 @@ async function copyPublicDirectory(config) {
829
841
  for (const file of files) {
830
842
  const srcPath = (0, import_path6.resolve)(config.publicDir, file);
831
843
  const outPath = (0, import_path6.resolve)(config.outDir, file);
832
- await import_fs_extra6.default.ensureDir((0, import_path6.dirname)(outPath));
833
- await import_fs_extra6.default.copyFile(srcPath, outPath);
844
+ await import_fs_extra7.default.ensureDir((0, import_path6.dirname)(outPath));
845
+ await import_fs_extra7.default.copyFile(srcPath, outPath);
834
846
  publicAssets.push({
835
847
  type: "asset",
836
848
  fileName: file,
837
849
  name: file,
838
850
  needsCodeReference: false,
839
- source: await import_fs_extra6.default.readFile(srcPath)
851
+ source: await import_fs_extra7.default.readFile(srcPath)
840
852
  });
841
853
  }
842
854
  return publicAssets;
@@ -844,7 +856,7 @@ async function copyPublicDirectory(config) {
844
856
 
845
857
  // src/core/build/findEntrypoints.ts
846
858
  var import_path8 = require("path");
847
- var import_fs_extra8 = __toESM(require("fs-extra"), 1);
859
+ var import_fs_extra9 = __toESM(require("fs-extra"), 1);
848
860
  var import_minimatch = require("minimatch");
849
861
  var import_linkedom2 = require("linkedom");
850
862
  var import_json5 = __toESM(require("json5"), 1);
@@ -852,7 +864,7 @@ var import_json5 = __toESM(require("json5"), 1);
852
864
  // src/core/utils/importTsFile.ts
853
865
  var import_jiti = __toESM(require("jiti"), 1);
854
866
  var import_unimport2 = require("unimport");
855
- var import_fs_extra7 = __toESM(require("fs-extra"), 1);
867
+ var import_fs_extra8 = __toESM(require("fs-extra"), 1);
856
868
  var import_path7 = require("path");
857
869
  var import_babel = __toESM(require("jiti/dist/babel"), 1);
858
870
 
@@ -865,16 +877,16 @@ function removeImportStatements(text) {
865
877
  }
866
878
 
867
879
  // src/core/utils/importTsFile.ts
868
- async function importTsFile(path6, config) {
869
- config.logger.debug("Loading file metadata:", path6);
870
- const normalPath = normalizePath2(path6);
880
+ async function importTsFile(path7, config) {
881
+ config.logger.debug("Loading file metadata:", path7);
882
+ const normalPath = normalizePath2(path7);
871
883
  const unimport2 = (0, import_unimport2.createUnimport)({
872
884
  ...getUnimportOptions(config),
873
885
  // Only allow specific imports, not all from the project
874
886
  dirs: []
875
887
  });
876
888
  await unimport2.init();
877
- const text = await import_fs_extra7.default.readFile(path6, "utf-8");
889
+ const text = await import_fs_extra8.default.readFile(path7, "utf-8");
878
890
  const textNoImports = removeImportStatements(text);
879
891
  const { code } = await unimport2.injectImports(textNoImports);
880
892
  config.logger.debug(
@@ -898,7 +910,7 @@ async function importTsFile(path6, config) {
898
910
  }
899
911
  });
900
912
  try {
901
- return await jiti(path6);
913
+ return await jiti(path7);
902
914
  } catch (err) {
903
915
  config.logger.error(err);
904
916
  throw err;
@@ -918,9 +930,9 @@ async function findEntrypoints(config) {
918
930
  let hasBackground = false;
919
931
  await Promise.all(
920
932
  relativePaths.map(async (relativePath) => {
921
- const path6 = (0, import_path8.resolve)(config.entrypointsDir, relativePath);
933
+ const path7 = (0, import_path8.resolve)(config.entrypointsDir, relativePath);
922
934
  const matchingGlob = pathGlobs.find(
923
- (glob3) => (0, import_minimatch.minimatch)(relativePath, glob3)
935
+ (glob4) => (0, import_minimatch.minimatch)(relativePath, glob4)
924
936
  );
925
937
  if (matchingGlob == null) {
926
938
  return config.logger.warn(
@@ -938,35 +950,35 @@ ${JSON.stringify(
938
950
  let entrypoint;
939
951
  switch (type) {
940
952
  case "popup":
941
- entrypoint = await getPopupEntrypoint(config, path6);
953
+ entrypoint = await getPopupEntrypoint(config, path7);
942
954
  break;
943
955
  case "options":
944
- entrypoint = await getOptionsEntrypoint(config, path6);
956
+ entrypoint = await getOptionsEntrypoint(config, path7);
945
957
  break;
946
958
  case "background":
947
- entrypoint = await getBackgroundEntrypoint(config, path6);
959
+ entrypoint = await getBackgroundEntrypoint(config, path7);
948
960
  hasBackground = true;
949
961
  break;
950
962
  case "content-script":
951
963
  entrypoint = await getContentScriptEntrypoint(
952
964
  config,
953
- getEntrypointName(config.entrypointsDir, path6),
954
- path6
965
+ getEntrypointName(config.entrypointsDir, path7),
966
+ path7
955
967
  );
956
968
  break;
957
969
  case "content-script-style":
958
970
  entrypoint = {
959
971
  type,
960
- name: getEntrypointName(config.entrypointsDir, path6),
961
- inputPath: path6,
972
+ name: getEntrypointName(config.entrypointsDir, path7),
973
+ inputPath: path7,
962
974
  outputDir: (0, import_path8.resolve)(config.outDir, CONTENT_SCRIPT_OUT_DIR)
963
975
  };
964
976
  break;
965
977
  default:
966
978
  entrypoint = {
967
979
  type,
968
- name: getEntrypointName(config.entrypointsDir, path6),
969
- inputPath: path6,
980
+ name: getEntrypointName(config.entrypointsDir, path7),
981
+ inputPath: path7,
970
982
  outputDir: config.outDir
971
983
  };
972
984
  }
@@ -990,9 +1002,9 @@ ${JSON.stringify(
990
1002
  }
991
1003
  return entrypoints;
992
1004
  }
993
- async function getPopupEntrypoint(config, path6) {
1005
+ async function getPopupEntrypoint(config, path7) {
994
1006
  const options = {};
995
- const content = await import_fs_extra8.default.readFile(path6, "utf-8");
1007
+ const content = await import_fs_extra9.default.readFile(path7, "utf-8");
996
1008
  const { document } = (0, import_linkedom2.parseHTML)(content);
997
1009
  const title = document.querySelector("title");
998
1010
  if (title != null)
@@ -1016,13 +1028,13 @@ async function getPopupEntrypoint(config, path6) {
1016
1028
  type: "popup",
1017
1029
  name: "popup",
1018
1030
  options,
1019
- inputPath: path6,
1031
+ inputPath: path7,
1020
1032
  outputDir: config.outDir
1021
1033
  };
1022
1034
  }
1023
- async function getOptionsEntrypoint(config, path6) {
1035
+ async function getOptionsEntrypoint(config, path7) {
1024
1036
  const options = {};
1025
- const content = await import_fs_extra8.default.readFile(path6, "utf-8");
1037
+ const content = await import_fs_extra9.default.readFile(path7, "utf-8");
1026
1038
  const { document } = (0, import_linkedom2.parseHTML)(content);
1027
1039
  const openInTabContent = document.querySelector("meta[name='manifest.open_in_tab']")?.getAttribute("content");
1028
1040
  if (openInTabContent) {
@@ -1040,15 +1052,15 @@ async function getOptionsEntrypoint(config, path6) {
1040
1052
  type: "options",
1041
1053
  name: "options",
1042
1054
  options,
1043
- inputPath: path6,
1055
+ inputPath: path7,
1044
1056
  outputDir: config.outDir
1045
1057
  };
1046
1058
  }
1047
- async function getBackgroundEntrypoint(config, path6) {
1059
+ async function getBackgroundEntrypoint(config, path7) {
1048
1060
  let options = {};
1049
- if (path6 !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
1061
+ if (path7 !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
1050
1062
  const defaultExport = await importTsFile(
1051
- path6,
1063
+ path7,
1052
1064
  config
1053
1065
  );
1054
1066
  if (defaultExport == null) {
@@ -1060,14 +1072,14 @@ async function getBackgroundEntrypoint(config, path6) {
1060
1072
  return {
1061
1073
  type: "background",
1062
1074
  name: "background",
1063
- inputPath: path6,
1075
+ inputPath: path7,
1064
1076
  outputDir: config.outDir,
1065
1077
  options
1066
1078
  };
1067
1079
  }
1068
- async function getContentScriptEntrypoint(config, name, path6) {
1080
+ async function getContentScriptEntrypoint(config, name, path7) {
1069
1081
  const { main: _, ...options } = await importTsFile(
1070
- path6,
1082
+ path7,
1071
1083
  config
1072
1084
  );
1073
1085
  if (options == null) {
@@ -1075,8 +1087,8 @@ async function getContentScriptEntrypoint(config, name, path6) {
1075
1087
  }
1076
1088
  return {
1077
1089
  type: "content-script",
1078
- name: getEntrypointName(config.entrypointsDir, path6),
1079
- inputPath: path6,
1090
+ name: getEntrypointName(config.entrypointsDir, path7),
1091
+ inputPath: path7,
1080
1092
  outputDir: (0, import_path8.resolve)(config.outDir, CONTENT_SCRIPT_OUT_DIR),
1081
1093
  options
1082
1094
  };
@@ -1125,7 +1137,7 @@ var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
1125
1137
 
1126
1138
  // src/core/build/generateTypesDir.ts
1127
1139
  var import_unimport3 = require("unimport");
1128
- var import_fs_extra9 = __toESM(require("fs-extra"), 1);
1140
+ var import_fs_extra10 = __toESM(require("fs-extra"), 1);
1129
1141
  var import_path9 = require("path");
1130
1142
  var import_node_path5 = __toESM(require("path"), 1);
1131
1143
 
@@ -1168,7 +1180,7 @@ function parseI18nMessages(messagesJson) {
1168
1180
 
1169
1181
  // src/core/build/generateTypesDir.ts
1170
1182
  async function generateTypesDir(entrypoints, config) {
1171
- await import_fs_extra9.default.ensureDir(config.typesDir);
1183
+ await import_fs_extra10.default.ensureDir(config.typesDir);
1172
1184
  const references = [];
1173
1185
  references.push(await writeImportsDeclarationFile(config));
1174
1186
  references.push(await writePathsDeclarationFile(entrypoints, config));
@@ -1181,7 +1193,7 @@ async function writeImportsDeclarationFile(config) {
1181
1193
  const filePath = (0, import_path9.resolve)(config.typesDir, "imports.d.ts");
1182
1194
  const unimport2 = (0, import_unimport3.createUnimport)(getUnimportOptions(config));
1183
1195
  await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
1184
- await import_fs_extra9.default.writeFile(
1196
+ await writeFileIfDifferent(
1185
1197
  filePath,
1186
1198
  ["// Generated by wxt", await unimport2.generateTypeDeclarations()].join(
1187
1199
  "\n"
@@ -1197,7 +1209,7 @@ async function writePathsDeclarationFile(entrypoints, config) {
1197
1209
  config.outDir,
1198
1210
  entry.inputPath.endsWith(".html") ? ".html" : ".js"
1199
1211
  )
1200
- ).concat(await getPublicFiles(config)).map(normalizePath2).map((path6) => ` | "/${path6}"`).sort().join("\n");
1212
+ ).concat(await getPublicFiles(config)).map(normalizePath2).map((path7) => ` | "/${path7}"`).sort().join("\n");
1201
1213
  const template = `// Generated by wxt
1202
1214
  import "wxt/browser";
1203
1215
 
@@ -1209,7 +1221,7 @@ declare module "wxt/browser" {
1209
1221
  }
1210
1222
  }
1211
1223
  `;
1212
- await import_fs_extra9.default.writeFile(
1224
+ await writeFileIfDifferent(
1213
1225
  filePath,
1214
1226
  template.replace("{{ union }}", unions || " | never")
1215
1227
  );
@@ -1245,7 +1257,7 @@ declare module "wxt/browser" {
1245
1257
  defaultLocale,
1246
1258
  "messages.json"
1247
1259
  );
1248
- const content = JSON.parse(await import_fs_extra9.default.readFile(defaultLocalePath, "utf-8"));
1260
+ const content = JSON.parse(await import_fs_extra10.default.readFile(defaultLocalePath, "utf-8"));
1249
1261
  messages = parseI18nMessages(content);
1250
1262
  } else {
1251
1263
  messages = parseI18nMessages({});
@@ -1262,7 +1274,7 @@ declare module "wxt/browser" {
1262
1274
  options?: GetMessageOptions,
1263
1275
  ): string;`;
1264
1276
  });
1265
- await import_fs_extra9.default.writeFile(
1277
+ await writeFileIfDifferent(
1266
1278
  filePath,
1267
1279
  template.replace("{{ overrides }}", overrides.join("\n"))
1268
1280
  );
@@ -1271,7 +1283,7 @@ declare module "wxt/browser" {
1271
1283
  async function writeGlobalsDeclarationFile(config) {
1272
1284
  const filePath = (0, import_path9.resolve)(config.typesDir, "globals.d.ts");
1273
1285
  const globals = getGlobals(config);
1274
- await import_fs_extra9.default.writeFile(
1286
+ await writeFileIfDifferent(
1275
1287
  filePath,
1276
1288
  [
1277
1289
  "// Generated by wxt",
@@ -1279,15 +1291,14 @@ async function writeGlobalsDeclarationFile(config) {
1279
1291
  "declare global {",
1280
1292
  ...globals.map((global) => ` const ${global.name}: ${global.type};`),
1281
1293
  "}"
1282
- ].join("\n") + "\n",
1283
- "utf-8"
1294
+ ].join("\n") + "\n"
1284
1295
  );
1285
1296
  return filePath;
1286
1297
  }
1287
1298
  async function writeMainDeclarationFile(references, config) {
1288
1299
  const dir = config.wxtDir;
1289
1300
  const filePath = (0, import_path9.resolve)(dir, "wxt.d.ts");
1290
- await import_fs_extra9.default.writeFile(
1301
+ await writeFileIfDifferent(
1291
1302
  filePath,
1292
1303
  [
1293
1304
  "// Generated by wxt",
@@ -1303,7 +1314,7 @@ async function writeTsConfigFile(mainReference, config) {
1303
1314
  const dir = config.wxtDir;
1304
1315
  const rootPath = normalizePath2((0, import_path9.relative)(dir, config.root));
1305
1316
  const srcPath = normalizePath2((0, import_path9.relative)(dir, config.srcDir));
1306
- await import_fs_extra9.default.writeFile(
1317
+ await writeFileIfDifferent(
1307
1318
  (0, import_path9.resolve)(dir, "tsconfig.json"),
1308
1319
  `{
1309
1320
  "compilerOptions": {
@@ -1338,7 +1349,7 @@ async function writeTsConfigFile(mainReference, config) {
1338
1349
  }
1339
1350
 
1340
1351
  // src/core/utils/manifest.ts
1341
- var import_fs_extra11 = __toESM(require("fs-extra"), 1);
1352
+ var import_fs_extra12 = __toESM(require("fs-extra"), 1);
1342
1353
  var import_path10 = require("path");
1343
1354
 
1344
1355
  // src/core/utils/ContentSecurityPolicy.ts
@@ -1424,11 +1435,11 @@ function mapWxtOptionsToContentScript(options) {
1424
1435
 
1425
1436
  // src/core/utils/package.ts
1426
1437
  var import_node_path6 = require("path");
1427
- var import_fs_extra10 = __toESM(require("fs-extra"), 1);
1438
+ var import_fs_extra11 = __toESM(require("fs-extra"), 1);
1428
1439
  async function getPackageJson(config) {
1429
1440
  const file = (0, import_node_path6.resolve)(config.root, "package.json");
1430
1441
  try {
1431
- return await import_fs_extra10.default.readJson(file);
1442
+ return await import_fs_extra11.default.readJson(file);
1432
1443
  } catch (err) {
1433
1444
  config.logger.debug(
1434
1445
  `Failed to read package.json at: ${file}. Returning undefined.`
@@ -1440,8 +1451,8 @@ async function getPackageJson(config) {
1440
1451
  // src/core/utils/manifest.ts
1441
1452
  async function writeManifest(manifest, output, config) {
1442
1453
  const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
1443
- await import_fs_extra11.default.ensureDir(config.outDir);
1444
- await import_fs_extra11.default.writeFile((0, import_path10.resolve)(config.outDir, "manifest.json"), str, "utf-8");
1454
+ await import_fs_extra12.default.ensureDir(config.outDir);
1455
+ await writeFileIfDifferent((0, import_path10.resolve)(config.outDir, "manifest.json"), str);
1445
1456
  output.publicAssets.unshift({
1446
1457
  type: "asset",
1447
1458
  fileName: "manifest.json",
@@ -1761,7 +1772,7 @@ function addHostPermission(manifest, hostPermission) {
1761
1772
  // src/core/build.ts
1762
1773
  var import_picocolors2 = __toESM(require("picocolors"), 1);
1763
1774
  var vite4 = __toESM(require("vite"), 1);
1764
- var import_fs_extra13 = __toESM(require("fs-extra"), 1);
1775
+ var import_fs_extra14 = __toESM(require("fs-extra"), 1);
1765
1776
 
1766
1777
  // src/core/utils/groupEntrypoints.ts
1767
1778
  function groupEntrypoints(entrypoints) {
@@ -1816,7 +1827,7 @@ var import_path11 = require("path");
1816
1827
  // src/core/log/printFileList.ts
1817
1828
  var import_node_path7 = __toESM(require("path"), 1);
1818
1829
  var import_picocolors = __toESM(require("picocolors"), 1);
1819
- var import_fs_extra12 = __toESM(require("fs-extra"), 1);
1830
+ var import_fs_extra13 = __toESM(require("fs-extra"), 1);
1820
1831
  var import_filesize = require("filesize");
1821
1832
 
1822
1833
  // src/core/log/printTable.ts
@@ -1857,7 +1868,7 @@ async function printFileList(log, header, baseDir, files) {
1857
1868
  ];
1858
1869
  const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
1859
1870
  const color = getChunkColor(file);
1860
- const stats = await import_fs_extra12.default.lstat(file);
1871
+ const stats = await import_fs_extra13.default.lstat(file);
1861
1872
  totalSize += stats.size;
1862
1873
  const size = String((0, import_filesize.filesize)(stats.size));
1863
1874
  return [
@@ -1921,9 +1932,10 @@ async function buildInternal(config) {
1921
1932
  )}`
1922
1933
  );
1923
1934
  const startTime = Date.now();
1924
- await import_fs_extra13.default.rm(config.outDir, { recursive: true, force: true });
1925
- await import_fs_extra13.default.ensureDir(config.outDir);
1935
+ await import_fs_extra14.default.rm(config.outDir, { recursive: true, force: true });
1936
+ await import_fs_extra14.default.ensureDir(config.outDir);
1926
1937
  const entrypoints = await findEntrypoints(config);
1938
+ config.logger.debug("Detected entrypoints:", entrypoints);
1927
1939
  const groups = groupEntrypoints(entrypoints);
1928
1940
  const { output } = await rebuild(config, groups, void 0);
1929
1941
  await printBuildSummary(
@@ -2066,8 +2078,8 @@ async function setupServer(serverInfo, config) {
2066
2078
  const reloadExtension = () => {
2067
2079
  viteServer.ws.send("wxt:reload-extension");
2068
2080
  };
2069
- const reloadPage = (path6) => {
2070
- viteServer.ws.send("wxt:reload-page", path6);
2081
+ const reloadPage = (path7) => {
2082
+ viteServer.ws.send("wxt:reload-page", path7);
2071
2083
  };
2072
2084
  const reloadContentScript = (contentScript) => {
2073
2085
  viteServer.ws.send("wxt:reload-content-script", contentScript);
@@ -2113,13 +2125,48 @@ function reloadContentScripts(steps, config, server) {
2113
2125
  }
2114
2126
  function reloadHtmlPages(groups, server, config) {
2115
2127
  groups.flat().forEach((entry) => {
2116
- const path6 = getEntrypointBundlePath(entry, config.outDir, ".html");
2117
- server.reloadPage(path6);
2128
+ const path7 = getEntrypointBundlePath(entry, config.outDir, ".html");
2129
+ server.reloadPage(path7);
2118
2130
  });
2119
2131
  }
2120
2132
 
2133
+ // src/core/clean.ts
2134
+ var import_node_path8 = __toESM(require("path"), 1);
2135
+ var import_fast_glob3 = __toESM(require("fast-glob"), 1);
2136
+ var import_fs_extra15 = __toESM(require("fs-extra"), 1);
2137
+ var import_consola2 = require("consola");
2138
+ var import_picocolors3 = __toESM(require("picocolors"), 1);
2139
+ async function clean(root = process.cwd()) {
2140
+ import_consola2.consola.info("Cleaning Project");
2141
+ const tempDirs = [
2142
+ "node_modules/.vite",
2143
+ "node_modules/.cache",
2144
+ "**/.wxt",
2145
+ ".output/*"
2146
+ ];
2147
+ import_consola2.consola.debug("Looking for:", tempDirs.map(import_picocolors3.default.cyan).join(", "));
2148
+ const directories = await (0, import_fast_glob3.default)(tempDirs, {
2149
+ cwd: import_node_path8.default.resolve(root),
2150
+ absolute: true,
2151
+ onlyDirectories: true,
2152
+ deep: 2
2153
+ });
2154
+ if (directories.length === 0) {
2155
+ import_consola2.consola.debug("No generated files found.");
2156
+ return;
2157
+ }
2158
+ import_consola2.consola.debug(
2159
+ "Found:",
2160
+ directories.map((dir) => import_picocolors3.default.cyan(import_node_path8.default.relative(root, dir))).join(", ")
2161
+ );
2162
+ for (const directory of directories) {
2163
+ await import_fs_extra15.default.rm(directory, { force: true, recursive: true });
2164
+ import_consola2.consola.debug("Deleted " + import_picocolors3.default.cyan(import_node_path8.default.relative(root, directory)));
2165
+ }
2166
+ }
2167
+
2121
2168
  // package.json
2122
- var version2 = "0.4.0";
2169
+ var version2 = "0.5.0";
2123
2170
 
2124
2171
  // src/core/utils/defineConfig.ts
2125
2172
  function defineConfig(config) {
@@ -2153,10 +2200,10 @@ async function createServer2(config) {
2153
2200
  server.ws.on("wxt:background-initialized", () => {
2154
2201
  reloadContentScripts(server.currentOutput.steps, internalConfig, server);
2155
2202
  });
2156
- server.watcher.on("all", async (event, path6, _stats) => {
2157
- if (path6.startsWith(internalConfig.outBaseDir))
2203
+ server.watcher.on("all", async (event, path7, _stats) => {
2204
+ if (path7.startsWith(internalConfig.outBaseDir))
2158
2205
  return;
2159
- changeQueue.push([event, path6]);
2206
+ changeQueue.push([event, path7]);
2160
2207
  await fileChangedMutex.runExclusive(async () => {
2161
2208
  const fileChanges = changeQueue.splice(0, changeQueue.length);
2162
2209
  if (fileChanges.length === 0)
@@ -2165,13 +2212,13 @@ async function createServer2(config) {
2165
2212
  if (changes.type === "no-change")
2166
2213
  return;
2167
2214
  internalConfig.logger.info(
2168
- `Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => import_picocolors3.default.dim((0, import_node_path8.relative)(internalConfig.root, file))).join(", ")}`
2215
+ `Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => import_picocolors4.default.dim((0, import_node_path9.relative)(internalConfig.root, file))).join(", ")}`
2169
2216
  );
2170
2217
  const rebuiltNames = changes.rebuildGroups.flat().map((entry) => {
2171
- return import_picocolors3.default.cyan(
2172
- (0, import_node_path8.relative)(internalConfig.outDir, getEntrypointOutputFile(entry, ""))
2218
+ return import_picocolors4.default.cyan(
2219
+ (0, import_node_path9.relative)(internalConfig.outDir, getEntrypointOutputFile(entry, ""))
2173
2220
  );
2174
- }).join(import_picocolors3.default.dim(", "));
2221
+ }).join(import_picocolors4.default.dim(", "));
2175
2222
  internalConfig = await getLatestInternalConfig();
2176
2223
  internalConfig.server = server;
2177
2224
  const { output: newOutput } = await rebuild(
@@ -2192,7 +2239,7 @@ async function createServer2(config) {
2192
2239
  reloadContentScripts(changes.changedSteps, internalConfig, server);
2193
2240
  break;
2194
2241
  }
2195
- import_consola2.consola.success(`Reloaded: ${rebuiltNames}`);
2242
+ import_consola3.consola.success(`Reloaded: ${rebuiltNames}`);
2196
2243
  });
2197
2244
  });
2198
2245
  return server;
@@ -2200,6 +2247,7 @@ async function createServer2(config) {
2200
2247
  // Annotate the CommonJS export names for ESM import in node:
2201
2248
  0 && (module.exports = {
2202
2249
  build,
2250
+ clean,
2203
2251
  createServer,
2204
2252
  defineConfig,
2205
2253
  defineRunnerConfig,