wxt 0.18.5 → 0.18.7

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.
Files changed (35) hide show
  1. package/dist/{chunk-7AOGIMIM.js → chunk-A3R6ZPUA.js} +120 -175
  2. package/dist/{chunk-5X3S6AWF.js → chunk-BERPNPEZ.js} +2 -4
  3. package/dist/{chunk-ZZCTFNQ5.js → chunk-BM6QYGAW.js} +1 -1
  4. package/dist/{chunk-NAMV4VWQ.js → chunk-KPD5J7PZ.js} +1 -1
  5. package/dist/{chunk-VBXJIVYU.js → chunk-QGM4M3NI.js} +1 -2
  6. package/dist/{chunk-73I7FAJU.js → chunk-SGKCDMVR.js} +1 -2
  7. package/dist/cli.js +141 -213
  8. package/dist/client.js +12 -24
  9. package/dist/{execa-QQUOQNS3.js → execa-ATHZH2Y4.js} +1576 -610
  10. package/dist/{execa-5TSWMF32.js → execa-D7CMCKO2.js} +1576 -610
  11. package/dist/{index-q2ZwJBs6.d.cts → index-D6lH9OkP.d.cts} +7 -3
  12. package/dist/{index-q2ZwJBs6.d.ts → index-D6lH9OkP.d.ts} +7 -3
  13. package/dist/index.cjs +2187 -1176
  14. package/dist/index.d.cts +3 -3
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +23 -38
  17. package/dist/modules.cjs +11 -2
  18. package/dist/modules.d.cts +31 -3
  19. package/dist/modules.d.ts +31 -3
  20. package/dist/modules.js +11 -3
  21. package/dist/{prompt-Y7B5HSD5.js → prompt-25QIVJDC.js} +28 -55
  22. package/dist/{prompt-TFJ7OLL7.js → prompt-7BMKNSWS.js} +28 -55
  23. package/dist/sandbox.js +2 -4
  24. package/dist/storage.cjs +4 -8
  25. package/dist/storage.js +6 -10
  26. package/dist/testing.cjs +47 -72
  27. package/dist/testing.d.cts +1 -1
  28. package/dist/testing.d.ts +1 -1
  29. package/dist/testing.js +4 -4
  30. package/dist/virtual/background-entrypoint.js +3 -6
  31. package/dist/virtual/content-script-isolated-world-entrypoint.js +1 -2
  32. package/dist/virtual/content-script-main-world-entrypoint.js +1 -2
  33. package/dist/virtual/reload-html.js +1 -2
  34. package/dist/virtual/unlisted-script-entrypoint.js +1 -2
  35. package/package.json +34 -33
package/dist/cli.js CHANGED
@@ -2,10 +2,10 @@ import { createRequire } from 'module';const require = createRequire(import.meta
2
2
  import {
3
3
  LogLevels,
4
4
  consola
5
- } from "./chunk-NAMV4VWQ.js";
5
+ } from "./chunk-KPD5J7PZ.js";
6
6
  import {
7
7
  __require
8
- } from "./chunk-73I7FAJU.js";
8
+ } from "./chunk-SGKCDMVR.js";
9
9
 
10
10
  // src/cli/commands.ts
11
11
  import cac from "cac";
@@ -46,7 +46,7 @@ var npm = {
46
46
  overridesKey: "overrides",
47
47
  async downloadDependency(id, downloadDir) {
48
48
  await ensureDir(downloadDir);
49
- const { execa } = await import("./execa-QQUOQNS3.js");
49
+ const { execa } = await import("./execa-ATHZH2Y4.js");
50
50
  const res = await execa("npm", ["pack", id, "--json"], {
51
51
  cwd: downloadDir
52
52
  });
@@ -58,7 +58,7 @@ var npm = {
58
58
  if (options?.all) {
59
59
  args.push("--depth", "Infinity");
60
60
  }
61
- const { execa } = await import("./execa-QQUOQNS3.js");
61
+ const { execa } = await import("./execa-ATHZH2Y4.js");
62
62
  const res = await execa("npm", args, { cwd: options?.cwd });
63
63
  const project = JSON.parse(res.stdout);
64
64
  return flattenNpmListOutput([project]);
@@ -68,10 +68,8 @@ function flattenNpmListOutput(projects) {
68
68
  const queue = projects.flatMap(
69
69
  (project) => {
70
70
  const acc = [];
71
- if (project.dependencies)
72
- acc.push(project.dependencies);
73
- if (project.devDependencies)
74
- acc.push(project.devDependencies);
71
+ if (project.dependencies) acc.push(project.dependencies);
72
+ if (project.devDependencies) acc.push(project.devDependencies);
75
73
  return acc;
76
74
  }
77
75
  );
@@ -82,10 +80,8 @@ function flattenNpmListOutput(projects) {
82
80
  name,
83
81
  version: meta.version
84
82
  });
85
- if (meta.dependencies)
86
- queue.push(meta.dependencies);
87
- if (meta.devDependencies)
88
- queue.push(meta.devDependencies);
83
+ if (meta.dependencies) queue.push(meta.dependencies);
84
+ if (meta.devDependencies) queue.push(meta.devDependencies);
89
85
  });
90
86
  }
91
87
  return dedupeDependencies(dependencies);
@@ -115,7 +111,7 @@ var bun = {
115
111
  if (options?.all) {
116
112
  args.push("--all");
117
113
  }
118
- const { execa } = await import("./execa-QQUOQNS3.js");
114
+ const { execa } = await import("./execa-ATHZH2Y4.js");
119
115
  const res = await execa("bun", args, { cwd: options?.cwd });
120
116
  return dedupeDependencies(
121
117
  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 }))
@@ -134,11 +130,10 @@ var yarn = {
134
130
  if (options?.all) {
135
131
  args.push("--depth", "Infinity");
136
132
  }
137
- const { execa } = await import("./execa-QQUOQNS3.js");
133
+ const { execa } = await import("./execa-ATHZH2Y4.js");
138
134
  const res = await execa("yarn", args, { cwd: options?.cwd });
139
135
  const tree = res.stdout.split("\n").map((line) => JSON.parse(line)).find((line) => line.type === "tree")?.data;
140
- if (tree == null)
141
- throw Error("'yarn list --json' did not output a tree");
136
+ if (tree == null) throw Error("'yarn list --json' did not output a tree");
142
137
  const queue = [...tree.trees];
143
138
  const dependencies = [];
144
139
  while (queue.length > 0) {
@@ -171,7 +166,7 @@ var pnpm = {
171
166
  if (typeof process !== "undefined" && process.env.WXT_PNPM_IGNORE_WORKSPACE === "true") {
172
167
  args.push("--ignore-workspace");
173
168
  }
174
- const { execa } = await import("./execa-QQUOQNS3.js");
169
+ const { execa } = await import("./execa-ATHZH2Y4.js");
175
170
  const res = await execa("pnpm", args, { cwd: options?.cwd });
176
171
  const projects = JSON.parse(res.stdout);
177
172
  return flattenNpmListOutput(projects);
@@ -184,8 +179,7 @@ async function createWxtPackageManager(root) {
184
179
  includeParentDirs: true
185
180
  });
186
181
  const requirePm = (cb) => {
187
- if (pm == null)
188
- throw Error("Could not detect package manager");
182
+ if (pm == null) throw Error("Could not detect package manager");
189
183
  return cb(pm);
190
184
  };
191
185
  return {
@@ -269,15 +263,16 @@ function isHtmlEntrypoint(entrypoint) {
269
263
  // src/core/builders/vite/plugins/devHtmlPrerender.ts
270
264
  import { parseHTML } from "linkedom";
271
265
  import { dirname, relative as relative2, resolve as resolve2 } from "node:path";
272
- var reactRefreshPreamble = "";
266
+ import { murmurHash } from "ohash";
267
+ var inlineScriptContents = {};
273
268
  function devHtmlPrerender(config, server) {
274
269
  const htmlReloadId = "@wxt/reload-html";
275
270
  const resolvedHtmlReloadId = resolve2(
276
271
  config.wxtModuleDir,
277
272
  "dist/virtual/reload-html.js"
278
273
  );
279
- const virtualReactRefreshId = "@wxt/virtual-react-refresh";
280
- const resolvedVirtualReactRefreshId = "\0" + virtualReactRefreshId;
274
+ const virtualInlineScript = "virtual:wxt-inline-script";
275
+ const resolvedVirtualInlineScript = "\0" + virtualInlineScript;
281
276
  return [
282
277
  {
283
278
  apply: "build",
@@ -312,23 +307,22 @@ function devHtmlPrerender(config, server) {
312
307
  },
313
308
  // Pass the HTML through the dev server to add dev-mode specific code
314
309
  async transformIndexHtml(html, ctx) {
315
- if (config.command !== "serve" || server == null)
316
- return;
310
+ if (config.command !== "serve" || server == null) return;
317
311
  const originalUrl = `${server.origin}${ctx.path}`;
318
312
  const name = getEntrypointName(config.entrypointsDir, ctx.filename);
319
313
  const url = `${server.origin}/${name}.html`;
320
314
  const serverHtml = await server.transformHtml(url, html, originalUrl);
321
315
  const { document } = parseHTML(serverHtml);
322
- const reactRefreshScript = Array.from(
323
- document.querySelectorAll("script[type=module]")
324
- ).find((script) => script.innerHTML.includes("@react-refresh"));
325
- if (reactRefreshScript) {
326
- reactRefreshPreamble = reactRefreshScript.innerHTML;
316
+ const inlineScripts = document.querySelectorAll("script:not([src])");
317
+ inlineScripts.forEach((script) => {
318
+ const textContent = script.textContent ?? "";
319
+ const hash = murmurHash(textContent);
320
+ inlineScriptContents[hash] = textContent;
327
321
  const virtualScript = document.createElement("script");
328
322
  virtualScript.type = "module";
329
- virtualScript.src = `${server.origin}/${virtualReactRefreshId}`;
330
- reactRefreshScript.replaceWith(virtualScript);
331
- }
323
+ virtualScript.src = `${server.origin}/@id/${virtualInlineScript}?${hash}`;
324
+ script.replaceWith(virtualScript);
325
+ });
332
326
  const viteClientScript = document.querySelector(
333
327
  "script[src='/@vite/client']"
334
328
  );
@@ -346,16 +340,17 @@ function devHtmlPrerender(config, server) {
346
340
  name: "wxt:virtualize-react-refresh",
347
341
  apply: "serve",
348
342
  resolveId(id) {
349
- if (id === `/${virtualReactRefreshId}`) {
350
- return resolvedVirtualReactRefreshId;
343
+ if (id.startsWith(virtualInlineScript)) {
344
+ return "\0" + id;
351
345
  }
352
346
  if (id.startsWith("/chunks/")) {
353
347
  return "\0noop";
354
348
  }
355
349
  },
356
350
  load(id) {
357
- if (id === resolvedVirtualReactRefreshId) {
358
- return reactRefreshPreamble;
351
+ if (id.startsWith(resolvedVirtualInlineScript)) {
352
+ const hash = Number(id.substring(id.indexOf("?") + 1));
353
+ return inlineScriptContents[hash];
359
354
  }
360
355
  if (id === "\0noop") {
361
356
  return "";
@@ -367,8 +362,7 @@ function devHtmlPrerender(config, server) {
367
362
  function pointToDevServer(config, server, id, document, querySelector, attr) {
368
363
  document.querySelectorAll(querySelector).forEach((element) => {
369
364
  const src = element.getAttribute(attr);
370
- if (!src || isUrl(src))
371
- return;
365
+ if (!src || isUrl(src)) return;
372
366
  let resolvedAbsolutePath;
373
367
  const matchingAlias = Object.entries(config.alias).find(
374
368
  ([key]) => src.startsWith(key)
@@ -388,8 +382,7 @@ function pointToDevServer(config, server, id, document, querySelector, attr) {
388
382
  );
389
383
  if (relativePath.startsWith(".")) {
390
384
  let path11 = normalizePath(resolvedAbsolutePath);
391
- if (!path11.startsWith("/"))
392
- path11 = "/" + path11;
385
+ if (!path11.startsWith("/")) path11 = "/" + path11;
393
386
  element.setAttribute(attr, `${server.origin}/@fs${path11}`);
394
387
  } else {
395
388
  const url = new URL(relativePath, server.origin);
@@ -412,8 +405,7 @@ function devServerGlobals(config, server) {
412
405
  return {
413
406
  name: "wxt:dev-server-globals",
414
407
  config() {
415
- if (server == null || config.command == "build")
416
- return;
408
+ if (server == null || config.command == "build") return;
417
409
  return {
418
410
  define: {
419
411
  __DEV_SERVER_PROTOCOL__: JSON.stringify("ws:"),
@@ -430,12 +422,9 @@ import dns from "node:dns";
430
422
 
431
423
  // src/core/utils/time.ts
432
424
  function formatDuration(duration) {
433
- if (duration < 1e3)
434
- return `${duration} ms`;
435
- if (duration < 1e4)
436
- return `${(duration / 1e3).toFixed(3)} s`;
437
- if (duration < 6e4)
438
- return `${(duration / 1e3).toFixed(1)} s`;
425
+ if (duration < 1e3) return `${duration} ms`;
426
+ if (duration < 1e4) return `${(duration / 1e3).toFixed(3)} s`;
427
+ if (duration < 6e4) return `${(duration / 1e3).toFixed(1)} s`;
439
428
  return `${(duration / 1e3).toFixed(0)} s`;
440
429
  }
441
430
  function withTimeout(promise, duration) {
@@ -477,8 +466,7 @@ async function fetchCached(url, config) {
477
466
  );
478
467
  }
479
468
  }
480
- if (!content)
481
- content = await config.fsCache.get(url) ?? "";
469
+ if (!content) content = await config.fsCache.get(url) ?? "";
482
470
  if (!content)
483
471
  throw Error(
484
472
  `Offline and "${url}" has not been cached. Try again when online.`
@@ -491,12 +479,10 @@ function download(config) {
491
479
  return {
492
480
  name: "wxt:download",
493
481
  resolveId(id) {
494
- if (id.startsWith("url:"))
495
- return "\0" + id;
482
+ if (id.startsWith("url:")) return "\0" + id;
496
483
  },
497
484
  async load(id) {
498
- if (!id.startsWith("\0url:"))
499
- return;
485
+ if (!id.startsWith("\0url:")) return;
500
486
  const url = id.replace("\0url:", "");
501
487
  return await fetchCached(url, config);
502
488
  }
@@ -575,8 +561,7 @@ var ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
575
561
  ]);
576
562
  function unimport(config) {
577
563
  const options = config.imports;
578
- if (options === false)
579
- return [];
564
+ if (options === false) return [];
580
565
  const unimport2 = createUnimport(options);
581
566
  return {
582
567
  name: "wxt:unimport",
@@ -584,10 +569,8 @@ function unimport(config) {
584
569
  await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
585
570
  },
586
571
  async transform(code, id) {
587
- if (id.includes("node_modules"))
588
- return;
589
- if (!ENABLED_EXTENSIONS.has(extname2(id)))
590
- return;
572
+ if (id.includes("node_modules")) return;
573
+ if (!ENABLED_EXTENSIONS.has(extname2(id))) return;
591
574
  const injected = await unimport2.injectImports(code, id);
592
575
  return {
593
576
  code: injected.code,
@@ -624,14 +607,12 @@ function resolveVirtualModules(config) {
624
607
  name: `wxt:resolve-virtual-${name}`,
625
608
  resolveId(id) {
626
609
  const index = id.indexOf(virtualId);
627
- if (index === -1)
628
- return;
610
+ if (index === -1) return;
629
611
  const inputPath = normalizePath(id.substring(index + virtualId.length));
630
612
  return resolvedVirtualId + inputPath;
631
613
  },
632
614
  async load(id) {
633
- if (!id.startsWith(resolvedVirtualId))
634
- return;
615
+ if (!id.startsWith(resolvedVirtualId)) return;
635
616
  const inputPath = id.replace(resolvedVirtualId, "");
636
617
  const template = await fs2.readFile(
637
618
  resolve4(config.wxtModuleDir, `dist/virtual/${name}.js`),
@@ -667,8 +648,7 @@ function noopBackground() {
667
648
  return {
668
649
  name: "wxt:noop-background",
669
650
  resolveId(id) {
670
- if (id === virtualModuleId)
671
- return resolvedVirtualModuleId;
651
+ if (id === virtualModuleId) return resolvedVirtualModuleId;
672
652
  },
673
653
  load(id) {
674
654
  if (id === resolvedVirtualModuleId) {
@@ -696,8 +676,7 @@ function cssEntrypoints(entrypoint, config) {
696
676
  },
697
677
  generateBundle(_, bundle) {
698
678
  Object.keys(bundle).forEach((file) => {
699
- if (file.endsWith(".js"))
700
- delete bundle[file];
679
+ if (file.endsWith(".js")) delete bundle[file];
701
680
  });
702
681
  }
703
682
  };
@@ -819,8 +798,7 @@ function excludeBrowserPolyfill(config) {
819
798
  return {
820
799
  name: "wxt:exclude-browser-polyfill",
821
800
  config() {
822
- if (config.experimental.includeBrowserPolyfill)
823
- return;
801
+ if (config.experimental.includeBrowserPolyfill) return;
824
802
  return {
825
803
  resolve: {
826
804
  alias: {
@@ -895,8 +873,7 @@ function removeEntrypointMainFunction(config, path11) {
895
873
  return {
896
874
  name: "wxt:remove-entrypoint-main-function",
897
875
  transform(code, id) {
898
- if (id === absPath)
899
- return removeMainFunctionCode(code);
876
+ if (id === absPath) return removeMainFunctionCode(code);
900
877
  }
901
878
  };
902
879
  }
@@ -911,10 +888,8 @@ function wxtPluginLoader(config) {
911
888
  return {
912
889
  name: "wxt:plugin-loader",
913
890
  resolveId(id) {
914
- if (id === virtualModuleId)
915
- return resolvedVirtualModuleId;
916
- if (id === virtualHtmlModuleId)
917
- return resolvedVirtualHtmlModuleId;
891
+ if (id === virtualModuleId) return resolvedVirtualModuleId;
892
+ if (id === virtualHtmlModuleId) return resolvedVirtualHtmlModuleId;
918
893
  },
919
894
  load(id) {
920
895
  if (id === resolvedVirtualModuleId) {
@@ -945,7 +920,7 @@ try {
945
920
  const { document } = parseHTML2(html);
946
921
  const script = document.createElement("script");
947
922
  script.type = "module";
948
- script.src = "virtual:wxt-html-plugins";
923
+ script.src = config.command === "serve" ? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
949
924
  if (document.head == null) {
950
925
  const newHead = document.createElement("head");
951
926
  document.documentElement.prepend(newHead);
@@ -960,14 +935,12 @@ try {
960
935
  // src/core/utils/arrays.ts
961
936
  function every(array, predicate) {
962
937
  for (let i = 0; i < array.length; i++)
963
- if (!predicate(array[i], i))
964
- return false;
938
+ if (!predicate(array[i], i)) return false;
965
939
  return true;
966
940
  }
967
941
  function some(array, predicate) {
968
942
  for (let i = 0; i < array.length; i++)
969
- if (predicate(array[i], i))
970
- return true;
943
+ if (predicate(array[i], i)) return true;
971
944
  return false;
972
945
  }
973
946
  function toArray(a) {
@@ -1110,8 +1083,7 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1110
1083
  // Include a hash to prevent conflicts
1111
1084
  chunkFileNames: "chunks/[name]-[hash].js",
1112
1085
  entryFileNames: ({ name }) => {
1113
- if (htmlEntrypoints.has(name))
1114
- return "chunks/[name]-[hash].js";
1086
+ if (htmlEntrypoints.has(name)) return "chunks/[name]-[hash].js";
1115
1087
  return "[name].js";
1116
1088
  },
1117
1089
  // We can't control the "name", so we need a hash to prevent conflicts
@@ -1164,12 +1136,10 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1164
1136
  },
1165
1137
  async build(group) {
1166
1138
  let entryConfig;
1167
- if (Array.isArray(group))
1168
- entryConfig = getMultiPageConfig(group);
1139
+ if (Array.isArray(group)) entryConfig = getMultiPageConfig(group);
1169
1140
  else if (group.inputPath.endsWith(".css"))
1170
1141
  entryConfig = getCssConfig(group);
1171
- else
1172
- entryConfig = getLibModeConfig(group);
1142
+ else entryConfig = getLibModeConfig(group);
1173
1143
  const buildConfig = vite.mergeConfig(await getBaseConfig(), entryConfig);
1174
1144
  await hooks.callHook(
1175
1145
  "vite:build:extendConfig",
@@ -1220,10 +1190,8 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1220
1190
  };
1221
1191
  }
1222
1192
  function getBuildOutputChunks(result) {
1223
- if ("on" in result)
1224
- throw Error("wxt does not support vite watch mode.");
1225
- if (Array.isArray(result))
1226
- return result.flatMap(({ output }) => output);
1193
+ if ("on" in result) throw Error("wxt does not support vite watch mode.");
1194
+ if (Array.isArray(result)) return result.flatMap(({ output }) => output);
1227
1195
  return result.output;
1228
1196
  }
1229
1197
  function getRollupEntry(entrypoint) {
@@ -1266,8 +1234,7 @@ async function registerWxt(command, inlineConfig = {}, getServer) {
1266
1234
  server
1267
1235
  };
1268
1236
  for (const module of config.modules) {
1269
- if (module.hooks)
1270
- wxt.hooks.addHooks(module.hooks);
1237
+ if (module.hooks) wxt.hooks.addHooks(module.hooks);
1271
1238
  if (wxt.config.imports !== false && module.imports) {
1272
1239
  wxt.config.imports.imports ??= [];
1273
1240
  wxt.config.imports.imports.push(...module.imports);
@@ -1290,8 +1257,7 @@ async function writeFileIfDifferent(file, newContents) {
1290
1257
  }
1291
1258
  }
1292
1259
  async function getPublicFiles() {
1293
- if (!await fs3.exists(wxt.config.publicDir))
1294
- return [];
1260
+ if (!await fs3.exists(wxt.config.publicDir)) return [];
1295
1261
  const files = await glob("**/*", { cwd: wxt.config.publicDir });
1296
1262
  return files.map(unnormalizePath);
1297
1263
  }
@@ -1324,8 +1290,7 @@ async function copyPublicDirectory() {
1324
1290
  relativeDest: file
1325
1291
  }));
1326
1292
  await wxt.hooks.callHook("build:publicAssets", wxt, files);
1327
- if (files.length === 0)
1328
- return [];
1293
+ if (files.length === 0) return [];
1329
1294
  const publicAssets = [];
1330
1295
  for (const { absoluteSrc, relativeDest } of files) {
1331
1296
  const absoluteDest = resolve6(wxt.config.outDir, relativeDest);
@@ -1345,21 +1310,18 @@ function detectDevChanges(changedFiles, currentOutput) {
1345
1310
  changedFiles,
1346
1311
  (file) => file === wxt.config.userConfigMetadata.configFile
1347
1312
  );
1348
- if (isConfigChange)
1349
- return { type: "full-restart" };
1313
+ if (isConfigChange) return { type: "full-restart" };
1350
1314
  const isRunnerChange = some(
1351
1315
  changedFiles,
1352
1316
  (file) => file === wxt.config.runnerConfig.configFile
1353
1317
  );
1354
- if (isRunnerChange)
1355
- return { type: "browser-restart" };
1318
+ if (isRunnerChange) return { type: "browser-restart" };
1356
1319
  const changedSteps = new Set(
1357
1320
  changedFiles.flatMap(
1358
1321
  (changedFile) => findEffectedSteps(changedFile, currentOutput)
1359
1322
  )
1360
1323
  );
1361
- if (changedSteps.size === 0)
1362
- return { type: "no-change" };
1324
+ if (changedSteps.size === 0) return { type: "no-change" };
1363
1325
  const unchangedOutput = {
1364
1326
  manifest: currentOutput.manifest,
1365
1327
  steps: [],
@@ -1422,14 +1384,12 @@ function findEffectedSteps(changedFile, currentOutput) {
1422
1384
  );
1423
1385
  for (const step of currentOutput.steps) {
1424
1386
  const effectedChunk = step.chunks.find((chunk) => isChunkEffected(chunk));
1425
- if (effectedChunk)
1426
- changes.push(step);
1387
+ if (effectedChunk) changes.push(step);
1427
1388
  }
1428
1389
  const effectedAsset = currentOutput.publicAssets.find(
1429
1390
  (chunk) => isChunkEffected(chunk)
1430
1391
  );
1431
- if (effectedAsset)
1432
- changes.push(effectedAsset);
1392
+ if (effectedAsset) changes.push(effectedAsset);
1433
1393
  return changes;
1434
1394
  }
1435
1395
 
@@ -2089,7 +2049,14 @@ async function writeMainDeclarationFile(references) {
2089
2049
  `/// <reference types="wxt/vite-builder-env" />`,
2090
2050
  ...references.map(
2091
2051
  (ref) => `/// <reference types="./${normalizePath(relative5(dir, ref))}" />`
2092
- )
2052
+ ),
2053
+ // Add references to modules installed from NPM to the TS project so
2054
+ // their type augmentation can update InlineConfig correctly. Local
2055
+ // modules defined in <root>/modules are already apart of the project, so
2056
+ // we don't need to add them.
2057
+ ...wxt.config.modules.filter(
2058
+ (module) => module.type === "node_module" && module.configKey != null
2059
+ ).map((module) => `/// <reference types="${module.id}" />`)
2093
2060
  ].join("\n") + "\n"
2094
2061
  );
2095
2062
  return filePath;
@@ -2202,8 +2169,7 @@ async function resolveConfig(inlineConfig, command) {
2202
2169
  const mergedConfig = await mergeInlineConfig(inlineConfig, userConfig);
2203
2170
  const debug = mergedConfig.debug ?? false;
2204
2171
  const logger = mergedConfig.logger ?? consola;
2205
- if (debug)
2206
- logger.level = LogLevels.debug;
2172
+ if (debug) logger.level = LogLevels.debug;
2207
2173
  const browser = mergedConfig.browser ?? "chrome";
2208
2174
  const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
2209
2175
  const mode = mergedConfig.mode ?? COMMAND_MODES[command];
@@ -2379,8 +2345,7 @@ function resolveAnalysisConfig(root, mergedConfig) {
2379
2345
  };
2380
2346
  }
2381
2347
  async function getUnimportOptions(wxtDir, logger, config) {
2382
- if (config.imports === false)
2383
- return false;
2348
+ if (config.imports === false) return false;
2384
2349
  const enabledConfig = config.imports?.eslintrc?.enabled;
2385
2350
  let enabled;
2386
2351
  switch (enabledConfig) {
@@ -2457,7 +2422,11 @@ async function resolveWxtModules(modulesDir, modules = []) {
2457
2422
  if (mod.default == null) {
2458
2423
  throw Error("Module missing default export: " + moduleId);
2459
2424
  }
2460
- return mod.default;
2425
+ return {
2426
+ ...mod.default,
2427
+ type: "node_module",
2428
+ id: moduleId
2429
+ };
2461
2430
  })
2462
2431
  );
2463
2432
  const localModulePaths = await glob3(["*.[tj]s", "*/index.[tj]s"], {
@@ -2466,8 +2435,9 @@ async function resolveWxtModules(modulesDir, modules = []) {
2466
2435
  }).catch(() => []);
2467
2436
  const localModules = await Promise.all(
2468
2437
  localModulePaths.map(async (file) => {
2438
+ const absolutePath = normalizePath(path6.resolve(modulesDir, file));
2469
2439
  const { config } = await loadConfig({
2470
- configFile: path6.resolve(modulesDir, file),
2440
+ configFile: absolutePath,
2471
2441
  globalRc: false,
2472
2442
  rcFile: false,
2473
2443
  packageJson: false,
@@ -2479,7 +2449,11 @@ async function resolveWxtModules(modulesDir, modules = []) {
2479
2449
  `No config found for ${file}. Did you forget to add a default export?`
2480
2450
  );
2481
2451
  config.name ??= file;
2482
- return config;
2452
+ return {
2453
+ ...config,
2454
+ type: "local",
2455
+ id: absolutePath
2456
+ };
2483
2457
  })
2484
2458
  );
2485
2459
  return [...npmModules, ...localModules];
@@ -2539,8 +2513,7 @@ import { filesize } from "filesize";
2539
2513
 
2540
2514
  // src/core/utils/log/printTable.ts
2541
2515
  function printTable(log, header, rows, gap = 2) {
2542
- if (rows.length === 0)
2543
- return;
2516
+ if (rows.length === 0) return;
2544
2517
  const columnWidths = rows.reduce(
2545
2518
  (widths, row) => {
2546
2519
  for (let i = 0; i < Math.max(widths.length, row.length); i++) {
@@ -2554,11 +2527,9 @@ function printTable(log, header, rows, gap = 2) {
2554
2527
  rows.forEach((row, i) => {
2555
2528
  row.forEach((col, j) => {
2556
2529
  str += col.padEnd(columnWidths[j], " ");
2557
- if (j !== row.length - 1)
2558
- str += "".padEnd(gap, " ");
2530
+ if (j !== row.length - 1) str += "".padEnd(gap, " ");
2559
2531
  });
2560
- if (i !== rows.length - 1)
2561
- str += "\n";
2532
+ if (i !== rows.length - 1) str += "\n";
2562
2533
  });
2563
2534
  log(`${header}
2564
2535
  ${str}`);
@@ -2612,8 +2583,7 @@ async function printBuildSummary(log, header, output) {
2612
2583
  const lWeight = getChunkSortWeight(l.fileName);
2613
2584
  const rWeight = getChunkSortWeight(r.fileName);
2614
2585
  const diff = lWeight - rWeight;
2615
- if (diff !== 0)
2616
- return diff;
2586
+ if (diff !== 0) return diff;
2617
2587
  return l.fileName.localeCompare(r.fileName);
2618
2588
  });
2619
2589
  const files = chunks.map(
@@ -2639,7 +2609,7 @@ function getChunkSortWeight(filename) {
2639
2609
  import pc4 from "picocolors";
2640
2610
 
2641
2611
  // package.json
2642
- var version = "0.18.5";
2612
+ var version = "0.18.6";
2643
2613
 
2644
2614
  // src/core/utils/log/printHeader.ts
2645
2615
  function printHeader() {
@@ -2667,8 +2637,7 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
2667
2637
  const sections = csp.split(";").map((section) => section.trim());
2668
2638
  this.data = sections.reduce((data, section) => {
2669
2639
  const [key, ...values] = section.split(" ").map((item) => item.trim());
2670
- if (key)
2671
- data[key] = values;
2640
+ if (key) data[key] = values;
2672
2641
  return data;
2673
2642
  }, {});
2674
2643
  } else {
@@ -2681,8 +2650,7 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
2681
2650
  add(directive, ...newValues) {
2682
2651
  const values = this.data[directive] ?? [];
2683
2652
  newValues.forEach((newValue) => {
2684
- if (!values.includes(newValue))
2685
- values.push(newValue);
2653
+ if (!values.includes(newValue)) values.push(newValue);
2686
2654
  });
2687
2655
  this.data[directive] = values;
2688
2656
  return this;
@@ -2705,8 +2673,7 @@ function hashContentScriptOptions(options) {
2705
2673
  void 0
2706
2674
  );
2707
2675
  Object.keys(simplifiedOptions).forEach((key) => {
2708
- if (simplifiedOptions[key] == null)
2709
- delete simplifiedOptions[key];
2676
+ if (simplifiedOptions[key] == null) delete simplifiedOptions[key];
2710
2677
  });
2711
2678
  const withDefaults = {
2712
2679
  exclude_globs: [],
@@ -2722,10 +2689,8 @@ function hashContentScriptOptions(options) {
2722
2689
  };
2723
2690
  return JSON.stringify(
2724
2691
  Object.entries(withDefaults).map(([key, value]) => {
2725
- if (Array.isArray(value))
2726
- return [key, value.sort()];
2727
- else
2728
- return [key, value];
2692
+ if (Array.isArray(value)) return [key, value.sort()];
2693
+ else return [key, value];
2729
2694
  }).sort((l, r) => l[0].localeCompare(r[0]))
2730
2695
  );
2731
2696
  }
@@ -2815,10 +2780,8 @@ async function generateManifest(entrypoints, buildOutput) {
2815
2780
  manifest.version_name = // Firefox doesn't support version_name
2816
2781
  wxt.config.browser === "firefox" || versionName === version2 ? void 0 : versionName;
2817
2782
  addEntrypoints(manifest, entrypoints, buildOutput);
2818
- if (wxt.config.command === "serve")
2819
- addDevModeCsp(manifest);
2820
- if (wxt.config.command === "serve")
2821
- addDevModePermissions(manifest);
2783
+ if (wxt.config.command === "serve") addDevModeCsp(manifest);
2784
+ if (wxt.config.command === "serve") addDevModePermissions(manifest);
2822
2785
  wxt.config.transformManifest?.(manifest);
2823
2786
  await wxt.hooks.callHook("build:manifestGenerated", wxt, manifest);
2824
2787
  if (wxt.config.manifestVersion === 2) {
@@ -3023,10 +2986,8 @@ function addEntrypoints(manifest, entrypoints, buildOutput) {
3023
2986
  } else {
3024
2987
  const hashToEntrypointsMap = contentScripts.filter((cs) => cs.options.registration !== "runtime").reduce((map, script) => {
3025
2988
  const hash = hashContentScriptOptions(script.options);
3026
- if (map.has(hash))
3027
- map.get(hash)?.push(script);
3028
- else
3029
- map.set(hash, [script]);
2989
+ if (map.has(hash)) map.get(hash)?.push(script);
2990
+ else map.set(hash, [script]);
3030
2991
  return map;
3031
2992
  }, /* @__PURE__ */ new Map());
3032
2993
  const manifestContentScripts = Array.from(
@@ -3095,8 +3056,7 @@ function discoverIcons(buildOutput) {
3095
3056
  break;
3096
3057
  }
3097
3058
  }
3098
- if (size == null)
3099
- return;
3059
+ if (size == null) return;
3100
3060
  icons.push([size, normalizePath(asset.fileName)]);
3101
3061
  });
3102
3062
  return icons.length > 0 ? Object.fromEntries(icons) : void 0;
@@ -3135,8 +3095,7 @@ function addDevModeCsp(manifest) {
3135
3095
  }
3136
3096
  function addDevModePermissions(manifest) {
3137
3097
  addPermission(manifest, "tabs");
3138
- if (wxt.config.manifestVersion === 3)
3139
- addPermission(manifest, "scripting");
3098
+ if (wxt.config.manifestVersion === 3) addPermission(manifest, "scripting");
3140
3099
  }
3141
3100
  function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
3142
3101
  const css = [];
@@ -3144,23 +3103,18 @@ function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
3144
3103
  if (script.options.cssInjectionMode === "manual" || script.options.cssInjectionMode === "ui")
3145
3104
  return;
3146
3105
  const cssFile = contentScriptCssMap[script.name];
3147
- if (cssFile == null)
3148
- return;
3149
- if (cssFile)
3150
- css.push(cssFile);
3106
+ if (cssFile == null) return;
3107
+ if (cssFile) css.push(cssFile);
3151
3108
  });
3152
- if (css.length > 0)
3153
- return css;
3109
+ if (css.length > 0) return css;
3154
3110
  return void 0;
3155
3111
  }
3156
3112
  function getContentScriptCssWebAccessibleResources(contentScripts, contentScriptCssMap) {
3157
3113
  const resources = [];
3158
3114
  contentScripts.forEach((script) => {
3159
- if (script.options.cssInjectionMode !== "ui")
3160
- return;
3115
+ if (script.options.cssInjectionMode !== "ui") return;
3161
3116
  const cssFile = contentScriptCssMap[script.name];
3162
- if (cssFile == null)
3163
- return;
3117
+ if (cssFile == null) return;
3164
3118
  resources.push({
3165
3119
  resources: [cssFile],
3166
3120
  matches: script.options.matches.map(
@@ -3177,46 +3131,39 @@ function getContentScriptsCssMap(buildOutput, scripts) {
3177
3131
  const relatedCss = allChunks.find(
3178
3132
  (chunk) => chunk.fileName === `content-scripts/${script.name}.css`
3179
3133
  );
3180
- if (relatedCss != null)
3181
- map[script.name] = relatedCss.fileName;
3134
+ if (relatedCss != null) map[script.name] = relatedCss.fileName;
3182
3135
  });
3183
3136
  return map;
3184
3137
  }
3185
3138
  function addPermission(manifest, permission) {
3186
3139
  manifest.permissions ??= [];
3187
- if (manifest.permissions.includes(permission))
3188
- return;
3140
+ if (manifest.permissions.includes(permission)) return;
3189
3141
  manifest.permissions.push(permission);
3190
3142
  }
3191
3143
  function addHostPermission(manifest, hostPermission) {
3192
3144
  manifest.host_permissions ??= [];
3193
- if (manifest.host_permissions.includes(hostPermission))
3194
- return;
3145
+ if (manifest.host_permissions.includes(hostPermission)) return;
3195
3146
  manifest.host_permissions.push(hostPermission);
3196
3147
  }
3197
3148
  function stripPathFromMatchPattern(pattern) {
3198
3149
  const protocolSepIndex = pattern.indexOf("://");
3199
- if (protocolSepIndex === -1)
3200
- return pattern;
3150
+ if (protocolSepIndex === -1) return pattern;
3201
3151
  const startOfPath = pattern.indexOf("/", protocolSepIndex + 3);
3202
3152
  return pattern.substring(0, startOfPath) + "/*";
3203
3153
  }
3204
3154
  function convertWebAccessibleResourcesToMv2(manifest) {
3205
- if (manifest.web_accessible_resources == null)
3206
- return;
3155
+ if (manifest.web_accessible_resources == null) return;
3207
3156
  manifest.web_accessible_resources = Array.from(
3208
3157
  new Set(
3209
3158
  manifest.web_accessible_resources.flatMap((item) => {
3210
- if (typeof item === "string")
3211
- return item;
3159
+ if (typeof item === "string") return item;
3212
3160
  return item.resources;
3213
3161
  })
3214
3162
  )
3215
3163
  );
3216
3164
  }
3217
3165
  function moveHostPermissionsToPermissions(manifest) {
3218
- if (!manifest.host_permissions?.length)
3219
- return;
3166
+ if (!manifest.host_permissions?.length) return;
3220
3167
  manifest.host_permissions.forEach(
3221
3168
  (permission) => addPermission(manifest, permission)
3222
3169
  );
@@ -3228,8 +3175,7 @@ function convertActionToMv2(manifest) {
3228
3175
  manifest.browser_action = manifest.action;
3229
3176
  }
3230
3177
  function validateMv3WebAccessbileResources(manifest) {
3231
- if (manifest.web_accessible_resources == null)
3232
- return;
3178
+ if (manifest.web_accessible_resources == null) return;
3233
3179
  const stringResources = manifest.web_accessible_resources.filter(
3234
3180
  (item) => typeof item === "string"
3235
3181
  );
@@ -3291,8 +3237,7 @@ async function rebuild(allEntrypoints, entrypointGroups, existingOutput = {
3291
3237
  const spinner = ora(`Preparing...`).start();
3292
3238
  await generateTypesDir(allEntrypoints).catch((err) => {
3293
3239
  wxt.logger.warn("Failed to update .wxt directory:", err);
3294
- if (wxt.config.command === "build")
3295
- throw err;
3240
+ if (wxt.config.command === "build") throw err;
3296
3241
  });
3297
3242
  const newOutput = await buildEntrypoints(entrypointGroups, spinner);
3298
3243
  const mergedOutput = {
@@ -3336,10 +3281,8 @@ function validateEntrypoints(entrypoints) {
3336
3281
  let errorCount = 0;
3337
3282
  let warningCount = 0;
3338
3283
  for (const err of errors) {
3339
- if (err.type === "warning")
3340
- warningCount++;
3341
- else
3342
- errorCount++;
3284
+ if (err.type === "warning") warningCount++;
3285
+ else errorCount++;
3343
3286
  }
3344
3287
  return {
3345
3288
  errors,
@@ -3552,10 +3495,8 @@ function createWebExtRunner() {
3552
3495
  }
3553
3496
  const webExtLogger = await import("web-ext-run/util/logger");
3554
3497
  webExtLogger.consoleStream.write = ({ level, msg, name }) => {
3555
- if (level >= ERROR_LOG_LEVEL)
3556
- wxt.logger.error(name, msg);
3557
- if (level >= WARN_LOG_LEVEL)
3558
- wxt.logger.warn(msg);
3498
+ if (level >= ERROR_LOG_LEVEL) wxt.logger.error(name, msg);
3499
+ if (level >= WARN_LOG_LEVEL) wxt.logger.warn(msg);
3559
3500
  };
3560
3501
  const wxtUserConfig = wxt.config.runnerConfig.config;
3561
3502
  const userConfig = {
@@ -3657,12 +3598,9 @@ async function isWsl() {
3657
3598
 
3658
3599
  // src/core/runners/index.ts
3659
3600
  async function createExtensionRunner() {
3660
- if (wxt.config.browser === "safari")
3661
- return createSafariRunner();
3662
- if (await isWsl())
3663
- return createWslRunner();
3664
- if (wxt.config.runnerConfig.config?.disabled)
3665
- return createManualRunner();
3601
+ if (wxt.config.browser === "safari") return createSafariRunner();
3602
+ if (await isWsl()) return createWslRunner();
3603
+ if (wxt.config.runnerConfig.config?.disabled) return createManualRunner();
3666
3604
  return createWebExtRunner();
3667
3605
  }
3668
3606
 
@@ -3739,8 +3677,7 @@ async function createServer(inlineConfig) {
3739
3677
  runner = await createExtensionRunner();
3740
3678
  };
3741
3679
  server.ws.on("wxt:background-initialized", () => {
3742
- if (server.currentOutput == null)
3743
- return;
3680
+ if (server.currentOutput == null) return;
3744
3681
  reloadContentScripts(server.currentOutput.steps, server);
3745
3682
  });
3746
3683
  const reloadOnChange = createFileReloader(server);
@@ -3752,18 +3689,14 @@ function createFileReloader(server) {
3752
3689
  const changeQueue = [];
3753
3690
  return async (event, path11) => {
3754
3691
  await wxt.reloadConfig();
3755
- if (path11.startsWith(wxt.config.outBaseDir))
3756
- return;
3692
+ if (path11.startsWith(wxt.config.outBaseDir)) return;
3757
3693
  changeQueue.push([event, path11]);
3758
3694
  await fileChangedMutex.runExclusive(async () => {
3759
- if (server.currentOutput == null)
3760
- return;
3695
+ if (server.currentOutput == null) return;
3761
3696
  const fileChanges = changeQueue.splice(0, changeQueue.length).map(([_, file]) => file);
3762
- if (fileChanges.length === 0)
3763
- return;
3697
+ if (fileChanges.length === 0) return;
3764
3698
  const changes = detectDevChanges(fileChanges, server.currentOutput);
3765
- if (changes.type === "no-change")
3766
- return;
3699
+ if (changes.type === "no-change") return;
3767
3700
  if (changes.type === "full-restart") {
3768
3701
  wxt.logger.info("Config changed, restarting server...");
3769
3702
  server.restart();
@@ -3812,11 +3745,9 @@ function createFileReloader(server) {
3812
3745
  function reloadContentScripts(steps, server) {
3813
3746
  if (wxt.config.manifestVersion === 3) {
3814
3747
  steps.forEach((step) => {
3815
- if (server.currentOutput == null)
3816
- return;
3748
+ if (server.currentOutput == null) return;
3817
3749
  const entry = step.entrypoints;
3818
- if (Array.isArray(entry) || entry.type !== "content-script")
3819
- return;
3750
+ if (Array.isArray(entry) || entry.type !== "content-script") return;
3820
3751
  const js = getContentScriptJs(wxt.config, entry);
3821
3752
  const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
3822
3753
  const css = getContentScriptCssFiles([entry], cssMap);
@@ -3854,8 +3785,7 @@ function getExternalOutputDependencies(server) {
3854
3785
  return [];
3855
3786
  }
3856
3787
  return step.chunks.flatMap((chunk) => {
3857
- if (chunk.type === "asset")
3858
- return [];
3788
+ if (chunk.type === "asset") return [];
3859
3789
  return chunk.moduleIds;
3860
3790
  });
3861
3791
  }).filter(
@@ -3933,8 +3863,7 @@ async function initialize(options) {
3933
3863
  console.log();
3934
3864
  consola.log("Next steps:");
3935
3865
  let step = 0;
3936
- if (cdPath !== "")
3937
- consola.log(` ${++step}.`, pc8.cyan(`cd ${cdPath}`));
3866
+ if (cdPath !== "") consola.log(` ${++step}.`, pc8.cyan(`cd ${cdPath}`));
3938
3867
  consola.log(` ${++step}.`, pc8.cyan(`${input.packageManager} install`));
3939
3868
  console.log();
3940
3869
  }
@@ -3948,8 +3877,7 @@ async function listTemplates() {
3948
3877
  const lWeight = TEMPLATE_SORT_WEIGHT[l.name] ?? Number.MAX_SAFE_INTEGER;
3949
3878
  const rWeight = TEMPLATE_SORT_WEIGHT[r.name] ?? Number.MAX_SAFE_INTEGER;
3950
3879
  const diff = lWeight - rWeight;
3951
- if (diff !== 0)
3952
- return diff;
3880
+ if (diff !== 0) return diff;
3953
3881
  return l.name.localeCompare(r.name);
3954
3882
  });
3955
3883
  } catch (err) {
@@ -4059,8 +3987,9 @@ async function zipDir(directory, outputPath, options) {
4059
3987
  cwd: directory,
4060
3988
  // Ignore node_modules, otherwise this glob step takes forever
4061
3989
  ignore: ["**/node_modules"],
4062
- onlyFiles: true,
4063
- dot: true
3990
+ onlyFiles: true
3991
+ // TODO: Fix #738
3992
+ // dot: true,
4064
3993
  })).filter((relativePath) => {
4065
3994
  return options?.include?.some((pattern) => minimatch2(relativePath, pattern)) || !options?.exclude?.some((pattern) => minimatch2(relativePath, pattern));
4066
3995
  });
@@ -4119,8 +4048,7 @@ async function downloadPrivatePackages() {
4119
4048
  return { overrides, files };
4120
4049
  }
4121
4050
  function addOverridesToPackageJson(absolutePackageJsonPath, content, overrides) {
4122
- if (Object.keys(overrides).length === 0)
4123
- return content;
4051
+ if (Object.keys(overrides).length === 0) return content;
4124
4052
  const packageJsonDir = path10.dirname(absolutePackageJsonPath);
4125
4053
  const oldPackage = JSON.parse(content);
4126
4054
  const newPackage = {
@@ -4173,7 +4101,7 @@ function createAliasedCommand(base, name, alias, bin, docsUrl) {
4173
4101
  const args = process.argv.slice(
4174
4102
  process.argv.indexOf(aliasedCommand.name) + 1
4175
4103
  );
4176
- const { execa } = await import("./execa-QQUOQNS3.js");
4104
+ const { execa } = await import("./execa-ATHZH2Y4.js");
4177
4105
  await execa(bin, args, {
4178
4106
  stdio: "inherit"
4179
4107
  });