wxt 0.18.6 → 0.18.8

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
@@ -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) {
@@ -942,10 +917,13 @@ try {
942
917
  // Use "pre" so the new script is added before vite bundles all the scripts
943
918
  order: "pre",
944
919
  handler(html, _ctx) {
920
+ const src = config.command === "serve" ? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
945
921
  const { document } = parseHTML2(html);
922
+ const existing = document.querySelector(`script[src='${src}']`);
923
+ if (existing) return;
946
924
  const script = document.createElement("script");
947
925
  script.type = "module";
948
- script.src = "virtual:wxt-html-plugins";
926
+ script.src = src;
949
927
  if (document.head == null) {
950
928
  const newHead = document.createElement("head");
951
929
  document.documentElement.prepend(newHead);
@@ -960,14 +938,12 @@ try {
960
938
  // src/core/utils/arrays.ts
961
939
  function every(array, predicate) {
962
940
  for (let i = 0; i < array.length; i++)
963
- if (!predicate(array[i], i))
964
- return false;
941
+ if (!predicate(array[i], i)) return false;
965
942
  return true;
966
943
  }
967
944
  function some(array, predicate) {
968
945
  for (let i = 0; i < array.length; i++)
969
- if (predicate(array[i], i))
970
- return true;
946
+ if (predicate(array[i], i)) return true;
971
947
  return false;
972
948
  }
973
949
  function toArray(a) {
@@ -1110,8 +1086,7 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1110
1086
  // Include a hash to prevent conflicts
1111
1087
  chunkFileNames: "chunks/[name]-[hash].js",
1112
1088
  entryFileNames: ({ name }) => {
1113
- if (htmlEntrypoints.has(name))
1114
- return "chunks/[name]-[hash].js";
1089
+ if (htmlEntrypoints.has(name)) return "chunks/[name]-[hash].js";
1115
1090
  return "[name].js";
1116
1091
  },
1117
1092
  // We can't control the "name", so we need a hash to prevent conflicts
@@ -1164,12 +1139,10 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1164
1139
  },
1165
1140
  async build(group) {
1166
1141
  let entryConfig;
1167
- if (Array.isArray(group))
1168
- entryConfig = getMultiPageConfig(group);
1142
+ if (Array.isArray(group)) entryConfig = getMultiPageConfig(group);
1169
1143
  else if (group.inputPath.endsWith(".css"))
1170
1144
  entryConfig = getCssConfig(group);
1171
- else
1172
- entryConfig = getLibModeConfig(group);
1145
+ else entryConfig = getLibModeConfig(group);
1173
1146
  const buildConfig = vite.mergeConfig(await getBaseConfig(), entryConfig);
1174
1147
  await hooks.callHook(
1175
1148
  "vite:build:extendConfig",
@@ -1220,10 +1193,8 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1220
1193
  };
1221
1194
  }
1222
1195
  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);
1196
+ if ("on" in result) throw Error("wxt does not support vite watch mode.");
1197
+ if (Array.isArray(result)) return result.flatMap(({ output }) => output);
1227
1198
  return result.output;
1228
1199
  }
1229
1200
  function getRollupEntry(entrypoint) {
@@ -1266,8 +1237,7 @@ async function registerWxt(command, inlineConfig = {}, getServer) {
1266
1237
  server
1267
1238
  };
1268
1239
  for (const module of config.modules) {
1269
- if (module.hooks)
1270
- wxt.hooks.addHooks(module.hooks);
1240
+ if (module.hooks) wxt.hooks.addHooks(module.hooks);
1271
1241
  if (wxt.config.imports !== false && module.imports) {
1272
1242
  wxt.config.imports.imports ??= [];
1273
1243
  wxt.config.imports.imports.push(...module.imports);
@@ -1290,8 +1260,7 @@ async function writeFileIfDifferent(file, newContents) {
1290
1260
  }
1291
1261
  }
1292
1262
  async function getPublicFiles() {
1293
- if (!await fs3.exists(wxt.config.publicDir))
1294
- return [];
1263
+ if (!await fs3.exists(wxt.config.publicDir)) return [];
1295
1264
  const files = await glob("**/*", { cwd: wxt.config.publicDir });
1296
1265
  return files.map(unnormalizePath);
1297
1266
  }
@@ -1324,8 +1293,7 @@ async function copyPublicDirectory() {
1324
1293
  relativeDest: file
1325
1294
  }));
1326
1295
  await wxt.hooks.callHook("build:publicAssets", wxt, files);
1327
- if (files.length === 0)
1328
- return [];
1296
+ if (files.length === 0) return [];
1329
1297
  const publicAssets = [];
1330
1298
  for (const { absoluteSrc, relativeDest } of files) {
1331
1299
  const absoluteDest = resolve6(wxt.config.outDir, relativeDest);
@@ -1345,25 +1313,36 @@ function detectDevChanges(changedFiles, currentOutput) {
1345
1313
  changedFiles,
1346
1314
  (file) => file === wxt.config.userConfigMetadata.configFile
1347
1315
  );
1348
- if (isConfigChange)
1349
- return { type: "full-restart" };
1316
+ if (isConfigChange) return { type: "full-restart" };
1350
1317
  const isRunnerChange = some(
1351
1318
  changedFiles,
1352
1319
  (file) => file === wxt.config.runnerConfig.configFile
1353
1320
  );
1354
- if (isRunnerChange)
1355
- return { type: "browser-restart" };
1321
+ if (isRunnerChange) return { type: "browser-restart" };
1356
1322
  const changedSteps = new Set(
1357
1323
  changedFiles.flatMap(
1358
1324
  (changedFile) => findEffectedSteps(changedFile, currentOutput)
1359
1325
  )
1360
1326
  );
1361
- if (changedSteps.size === 0)
1362
- return { type: "no-change" };
1327
+ if (changedSteps.size === 0) {
1328
+ const hasPublicChange = some(
1329
+ changedFiles,
1330
+ (file) => file.startsWith(wxt.config.publicDir)
1331
+ );
1332
+ if (hasPublicChange) {
1333
+ return {
1334
+ type: "extension-reload",
1335
+ rebuildGroups: [],
1336
+ cachedOutput: currentOutput
1337
+ };
1338
+ } else {
1339
+ return { type: "no-change" };
1340
+ }
1341
+ }
1363
1342
  const unchangedOutput = {
1364
1343
  manifest: currentOutput.manifest,
1365
1344
  steps: [],
1366
- publicAssets: []
1345
+ publicAssets: [...currentOutput.publicAssets]
1367
1346
  };
1368
1347
  const changedOutput = {
1369
1348
  manifest: currentOutput.manifest,
@@ -1377,13 +1356,6 @@ function detectDevChanges(changedFiles, currentOutput) {
1377
1356
  unchangedOutput.steps.push(step);
1378
1357
  }
1379
1358
  }
1380
- for (const asset of currentOutput.publicAssets) {
1381
- if (changedSteps.has(asset)) {
1382
- changedOutput.publicAssets.push(asset);
1383
- } else {
1384
- unchangedOutput.publicAssets.push(asset);
1385
- }
1386
- }
1387
1359
  const isOnlyHtmlChanges = changedFiles.length > 0 && every(changedFiles, (file) => file.endsWith(".html"));
1388
1360
  if (isOnlyHtmlChanges) {
1389
1361
  return {
@@ -1422,14 +1394,8 @@ function findEffectedSteps(changedFile, currentOutput) {
1422
1394
  );
1423
1395
  for (const step of currentOutput.steps) {
1424
1396
  const effectedChunk = step.chunks.find((chunk) => isChunkEffected(chunk));
1425
- if (effectedChunk)
1426
- changes.push(step);
1397
+ if (effectedChunk) changes.push(step);
1427
1398
  }
1428
- const effectedAsset = currentOutput.publicAssets.find(
1429
- (chunk) => isChunkEffected(chunk)
1430
- );
1431
- if (effectedAsset)
1432
- changes.push(effectedAsset);
1433
1399
  return changes;
1434
1400
  }
1435
1401
 
@@ -2209,8 +2175,7 @@ async function resolveConfig(inlineConfig, command) {
2209
2175
  const mergedConfig = await mergeInlineConfig(inlineConfig, userConfig);
2210
2176
  const debug = mergedConfig.debug ?? false;
2211
2177
  const logger = mergedConfig.logger ?? consola;
2212
- if (debug)
2213
- logger.level = LogLevels.debug;
2178
+ if (debug) logger.level = LogLevels.debug;
2214
2179
  const browser = mergedConfig.browser ?? "chrome";
2215
2180
  const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
2216
2181
  const mode = mergedConfig.mode ?? COMMAND_MODES[command];
@@ -2386,8 +2351,7 @@ function resolveAnalysisConfig(root, mergedConfig) {
2386
2351
  };
2387
2352
  }
2388
2353
  async function getUnimportOptions(wxtDir, logger, config) {
2389
- if (config.imports === false)
2390
- return false;
2354
+ if (config.imports === false) return false;
2391
2355
  const enabledConfig = config.imports?.eslintrc?.enabled;
2392
2356
  let enabled;
2393
2357
  switch (enabledConfig) {
@@ -2555,8 +2519,7 @@ import { filesize } from "filesize";
2555
2519
 
2556
2520
  // src/core/utils/log/printTable.ts
2557
2521
  function printTable(log, header, rows, gap = 2) {
2558
- if (rows.length === 0)
2559
- return;
2522
+ if (rows.length === 0) return;
2560
2523
  const columnWidths = rows.reduce(
2561
2524
  (widths, row) => {
2562
2525
  for (let i = 0; i < Math.max(widths.length, row.length); i++) {
@@ -2570,11 +2533,9 @@ function printTable(log, header, rows, gap = 2) {
2570
2533
  rows.forEach((row, i) => {
2571
2534
  row.forEach((col, j) => {
2572
2535
  str += col.padEnd(columnWidths[j], " ");
2573
- if (j !== row.length - 1)
2574
- str += "".padEnd(gap, " ");
2536
+ if (j !== row.length - 1) str += "".padEnd(gap, " ");
2575
2537
  });
2576
- if (i !== rows.length - 1)
2577
- str += "\n";
2538
+ if (i !== rows.length - 1) str += "\n";
2578
2539
  });
2579
2540
  log(`${header}
2580
2541
  ${str}`);
@@ -2628,8 +2589,7 @@ async function printBuildSummary(log, header, output) {
2628
2589
  const lWeight = getChunkSortWeight(l.fileName);
2629
2590
  const rWeight = getChunkSortWeight(r.fileName);
2630
2591
  const diff = lWeight - rWeight;
2631
- if (diff !== 0)
2632
- return diff;
2592
+ if (diff !== 0) return diff;
2633
2593
  return l.fileName.localeCompare(r.fileName);
2634
2594
  });
2635
2595
  const files = chunks.map(
@@ -2655,7 +2615,7 @@ function getChunkSortWeight(filename) {
2655
2615
  import pc4 from "picocolors";
2656
2616
 
2657
2617
  // package.json
2658
- var version = "0.18.6";
2618
+ var version = "0.18.7";
2659
2619
 
2660
2620
  // src/core/utils/log/printHeader.ts
2661
2621
  function printHeader() {
@@ -2683,8 +2643,7 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
2683
2643
  const sections = csp.split(";").map((section) => section.trim());
2684
2644
  this.data = sections.reduce((data, section) => {
2685
2645
  const [key, ...values] = section.split(" ").map((item) => item.trim());
2686
- if (key)
2687
- data[key] = values;
2646
+ if (key) data[key] = values;
2688
2647
  return data;
2689
2648
  }, {});
2690
2649
  } else {
@@ -2697,8 +2656,7 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
2697
2656
  add(directive, ...newValues) {
2698
2657
  const values = this.data[directive] ?? [];
2699
2658
  newValues.forEach((newValue) => {
2700
- if (!values.includes(newValue))
2701
- values.push(newValue);
2659
+ if (!values.includes(newValue)) values.push(newValue);
2702
2660
  });
2703
2661
  this.data[directive] = values;
2704
2662
  return this;
@@ -2721,8 +2679,7 @@ function hashContentScriptOptions(options) {
2721
2679
  void 0
2722
2680
  );
2723
2681
  Object.keys(simplifiedOptions).forEach((key) => {
2724
- if (simplifiedOptions[key] == null)
2725
- delete simplifiedOptions[key];
2682
+ if (simplifiedOptions[key] == null) delete simplifiedOptions[key];
2726
2683
  });
2727
2684
  const withDefaults = {
2728
2685
  exclude_globs: [],
@@ -2738,10 +2695,8 @@ function hashContentScriptOptions(options) {
2738
2695
  };
2739
2696
  return JSON.stringify(
2740
2697
  Object.entries(withDefaults).map(([key, value]) => {
2741
- if (Array.isArray(value))
2742
- return [key, value.sort()];
2743
- else
2744
- return [key, value];
2698
+ if (Array.isArray(value)) return [key, value.sort()];
2699
+ else return [key, value];
2745
2700
  }).sort((l, r) => l[0].localeCompare(r[0]))
2746
2701
  );
2747
2702
  }
@@ -2831,10 +2786,8 @@ async function generateManifest(entrypoints, buildOutput) {
2831
2786
  manifest.version_name = // Firefox doesn't support version_name
2832
2787
  wxt.config.browser === "firefox" || versionName === version2 ? void 0 : versionName;
2833
2788
  addEntrypoints(manifest, entrypoints, buildOutput);
2834
- if (wxt.config.command === "serve")
2835
- addDevModeCsp(manifest);
2836
- if (wxt.config.command === "serve")
2837
- addDevModePermissions(manifest);
2789
+ if (wxt.config.command === "serve") addDevModeCsp(manifest);
2790
+ if (wxt.config.command === "serve") addDevModePermissions(manifest);
2838
2791
  wxt.config.transformManifest?.(manifest);
2839
2792
  await wxt.hooks.callHook("build:manifestGenerated", wxt, manifest);
2840
2793
  if (wxt.config.manifestVersion === 2) {
@@ -3039,10 +2992,8 @@ function addEntrypoints(manifest, entrypoints, buildOutput) {
3039
2992
  } else {
3040
2993
  const hashToEntrypointsMap = contentScripts.filter((cs) => cs.options.registration !== "runtime").reduce((map, script) => {
3041
2994
  const hash = hashContentScriptOptions(script.options);
3042
- if (map.has(hash))
3043
- map.get(hash)?.push(script);
3044
- else
3045
- map.set(hash, [script]);
2995
+ if (map.has(hash)) map.get(hash)?.push(script);
2996
+ else map.set(hash, [script]);
3046
2997
  return map;
3047
2998
  }, /* @__PURE__ */ new Map());
3048
2999
  const manifestContentScripts = Array.from(
@@ -3111,8 +3062,7 @@ function discoverIcons(buildOutput) {
3111
3062
  break;
3112
3063
  }
3113
3064
  }
3114
- if (size == null)
3115
- return;
3065
+ if (size == null) return;
3116
3066
  icons.push([size, normalizePath(asset.fileName)]);
3117
3067
  });
3118
3068
  return icons.length > 0 ? Object.fromEntries(icons) : void 0;
@@ -3151,8 +3101,7 @@ function addDevModeCsp(manifest) {
3151
3101
  }
3152
3102
  function addDevModePermissions(manifest) {
3153
3103
  addPermission(manifest, "tabs");
3154
- if (wxt.config.manifestVersion === 3)
3155
- addPermission(manifest, "scripting");
3104
+ if (wxt.config.manifestVersion === 3) addPermission(manifest, "scripting");
3156
3105
  }
3157
3106
  function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
3158
3107
  const css = [];
@@ -3160,23 +3109,18 @@ function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
3160
3109
  if (script.options.cssInjectionMode === "manual" || script.options.cssInjectionMode === "ui")
3161
3110
  return;
3162
3111
  const cssFile = contentScriptCssMap[script.name];
3163
- if (cssFile == null)
3164
- return;
3165
- if (cssFile)
3166
- css.push(cssFile);
3112
+ if (cssFile == null) return;
3113
+ if (cssFile) css.push(cssFile);
3167
3114
  });
3168
- if (css.length > 0)
3169
- return css;
3115
+ if (css.length > 0) return css;
3170
3116
  return void 0;
3171
3117
  }
3172
3118
  function getContentScriptCssWebAccessibleResources(contentScripts, contentScriptCssMap) {
3173
3119
  const resources = [];
3174
3120
  contentScripts.forEach((script) => {
3175
- if (script.options.cssInjectionMode !== "ui")
3176
- return;
3121
+ if (script.options.cssInjectionMode !== "ui") return;
3177
3122
  const cssFile = contentScriptCssMap[script.name];
3178
- if (cssFile == null)
3179
- return;
3123
+ if (cssFile == null) return;
3180
3124
  resources.push({
3181
3125
  resources: [cssFile],
3182
3126
  matches: script.options.matches.map(
@@ -3193,46 +3137,39 @@ function getContentScriptsCssMap(buildOutput, scripts) {
3193
3137
  const relatedCss = allChunks.find(
3194
3138
  (chunk) => chunk.fileName === `content-scripts/${script.name}.css`
3195
3139
  );
3196
- if (relatedCss != null)
3197
- map[script.name] = relatedCss.fileName;
3140
+ if (relatedCss != null) map[script.name] = relatedCss.fileName;
3198
3141
  });
3199
3142
  return map;
3200
3143
  }
3201
3144
  function addPermission(manifest, permission) {
3202
3145
  manifest.permissions ??= [];
3203
- if (manifest.permissions.includes(permission))
3204
- return;
3146
+ if (manifest.permissions.includes(permission)) return;
3205
3147
  manifest.permissions.push(permission);
3206
3148
  }
3207
3149
  function addHostPermission(manifest, hostPermission) {
3208
3150
  manifest.host_permissions ??= [];
3209
- if (manifest.host_permissions.includes(hostPermission))
3210
- return;
3151
+ if (manifest.host_permissions.includes(hostPermission)) return;
3211
3152
  manifest.host_permissions.push(hostPermission);
3212
3153
  }
3213
3154
  function stripPathFromMatchPattern(pattern) {
3214
3155
  const protocolSepIndex = pattern.indexOf("://");
3215
- if (protocolSepIndex === -1)
3216
- return pattern;
3156
+ if (protocolSepIndex === -1) return pattern;
3217
3157
  const startOfPath = pattern.indexOf("/", protocolSepIndex + 3);
3218
3158
  return pattern.substring(0, startOfPath) + "/*";
3219
3159
  }
3220
3160
  function convertWebAccessibleResourcesToMv2(manifest) {
3221
- if (manifest.web_accessible_resources == null)
3222
- return;
3161
+ if (manifest.web_accessible_resources == null) return;
3223
3162
  manifest.web_accessible_resources = Array.from(
3224
3163
  new Set(
3225
3164
  manifest.web_accessible_resources.flatMap((item) => {
3226
- if (typeof item === "string")
3227
- return item;
3165
+ if (typeof item === "string") return item;
3228
3166
  return item.resources;
3229
3167
  })
3230
3168
  )
3231
3169
  );
3232
3170
  }
3233
3171
  function moveHostPermissionsToPermissions(manifest) {
3234
- if (!manifest.host_permissions?.length)
3235
- return;
3172
+ if (!manifest.host_permissions?.length) return;
3236
3173
  manifest.host_permissions.forEach(
3237
3174
  (permission) => addPermission(manifest, permission)
3238
3175
  );
@@ -3244,8 +3181,7 @@ function convertActionToMv2(manifest) {
3244
3181
  manifest.browser_action = manifest.action;
3245
3182
  }
3246
3183
  function validateMv3WebAccessbileResources(manifest) {
3247
- if (manifest.web_accessible_resources == null)
3248
- return;
3184
+ if (manifest.web_accessible_resources == null) return;
3249
3185
  const stringResources = manifest.web_accessible_resources.filter(
3250
3186
  (item) => typeof item === "string"
3251
3187
  );
@@ -3307,8 +3243,7 @@ async function rebuild(allEntrypoints, entrypointGroups, existingOutput = {
3307
3243
  const spinner = ora(`Preparing...`).start();
3308
3244
  await generateTypesDir(allEntrypoints).catch((err) => {
3309
3245
  wxt.logger.warn("Failed to update .wxt directory:", err);
3310
- if (wxt.config.command === "build")
3311
- throw err;
3246
+ if (wxt.config.command === "build") throw err;
3312
3247
  });
3313
3248
  const newOutput = await buildEntrypoints(entrypointGroups, spinner);
3314
3249
  const mergedOutput = {
@@ -3352,10 +3287,8 @@ function validateEntrypoints(entrypoints) {
3352
3287
  let errorCount = 0;
3353
3288
  let warningCount = 0;
3354
3289
  for (const err of errors) {
3355
- if (err.type === "warning")
3356
- warningCount++;
3357
- else
3358
- errorCount++;
3290
+ if (err.type === "warning") warningCount++;
3291
+ else errorCount++;
3359
3292
  }
3360
3293
  return {
3361
3294
  errors,
@@ -3568,10 +3501,8 @@ function createWebExtRunner() {
3568
3501
  }
3569
3502
  const webExtLogger = await import("web-ext-run/util/logger");
3570
3503
  webExtLogger.consoleStream.write = ({ level, msg, name }) => {
3571
- if (level >= ERROR_LOG_LEVEL)
3572
- wxt.logger.error(name, msg);
3573
- if (level >= WARN_LOG_LEVEL)
3574
- wxt.logger.warn(msg);
3504
+ if (level >= ERROR_LOG_LEVEL) wxt.logger.error(name, msg);
3505
+ if (level >= WARN_LOG_LEVEL) wxt.logger.warn(msg);
3575
3506
  };
3576
3507
  const wxtUserConfig = wxt.config.runnerConfig.config;
3577
3508
  const userConfig = {
@@ -3673,12 +3604,9 @@ async function isWsl() {
3673
3604
 
3674
3605
  // src/core/runners/index.ts
3675
3606
  async function createExtensionRunner() {
3676
- if (wxt.config.browser === "safari")
3677
- return createSafariRunner();
3678
- if (await isWsl())
3679
- return createWslRunner();
3680
- if (wxt.config.runnerConfig.config?.disabled)
3681
- return createManualRunner();
3607
+ if (wxt.config.browser === "safari") return createSafariRunner();
3608
+ if (await isWsl()) return createWslRunner();
3609
+ if (wxt.config.runnerConfig.config?.disabled) return createManualRunner();
3682
3610
  return createWebExtRunner();
3683
3611
  }
3684
3612
 
@@ -3755,8 +3683,7 @@ async function createServer(inlineConfig) {
3755
3683
  runner = await createExtensionRunner();
3756
3684
  };
3757
3685
  server.ws.on("wxt:background-initialized", () => {
3758
- if (server.currentOutput == null)
3759
- return;
3686
+ if (server.currentOutput == null) return;
3760
3687
  reloadContentScripts(server.currentOutput.steps, server);
3761
3688
  });
3762
3689
  const reloadOnChange = createFileReloader(server);
@@ -3768,18 +3695,15 @@ function createFileReloader(server) {
3768
3695
  const changeQueue = [];
3769
3696
  return async (event, path11) => {
3770
3697
  await wxt.reloadConfig();
3771
- if (path11.startsWith(wxt.config.outBaseDir))
3772
- return;
3698
+ if (path11.startsWith(wxt.config.outBaseDir)) return;
3699
+ if (path11.startsWith(wxt.config.wxtDir)) return;
3773
3700
  changeQueue.push([event, path11]);
3774
3701
  await fileChangedMutex.runExclusive(async () => {
3775
- if (server.currentOutput == null)
3776
- return;
3702
+ if (server.currentOutput == null) return;
3777
3703
  const fileChanges = changeQueue.splice(0, changeQueue.length).map(([_, file]) => file);
3778
- if (fileChanges.length === 0)
3779
- return;
3704
+ if (fileChanges.length === 0) return;
3780
3705
  const changes = detectDevChanges(fileChanges, server.currentOutput);
3781
- if (changes.type === "no-change")
3782
- return;
3706
+ if (changes.type === "no-change") return;
3783
3707
  if (changes.type === "full-restart") {
3784
3708
  wxt.logger.info("Config changed, restarting server...");
3785
3709
  server.restart();
@@ -3828,11 +3752,9 @@ function createFileReloader(server) {
3828
3752
  function reloadContentScripts(steps, server) {
3829
3753
  if (wxt.config.manifestVersion === 3) {
3830
3754
  steps.forEach((step) => {
3831
- if (server.currentOutput == null)
3832
- return;
3755
+ if (server.currentOutput == null) return;
3833
3756
  const entry = step.entrypoints;
3834
- if (Array.isArray(entry) || entry.type !== "content-script")
3835
- return;
3757
+ if (Array.isArray(entry) || entry.type !== "content-script") return;
3836
3758
  const js = getContentScriptJs(wxt.config, entry);
3837
3759
  const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
3838
3760
  const css = getContentScriptCssFiles([entry], cssMap);
@@ -3870,8 +3792,7 @@ function getExternalOutputDependencies(server) {
3870
3792
  return [];
3871
3793
  }
3872
3794
  return step.chunks.flatMap((chunk) => {
3873
- if (chunk.type === "asset")
3874
- return [];
3795
+ if (chunk.type === "asset") return [];
3875
3796
  return chunk.moduleIds;
3876
3797
  });
3877
3798
  }).filter(
@@ -3949,8 +3870,7 @@ async function initialize(options) {
3949
3870
  console.log();
3950
3871
  consola.log("Next steps:");
3951
3872
  let step = 0;
3952
- if (cdPath !== "")
3953
- consola.log(` ${++step}.`, pc8.cyan(`cd ${cdPath}`));
3873
+ if (cdPath !== "") consola.log(` ${++step}.`, pc8.cyan(`cd ${cdPath}`));
3954
3874
  consola.log(` ${++step}.`, pc8.cyan(`${input.packageManager} install`));
3955
3875
  console.log();
3956
3876
  }
@@ -3964,8 +3884,7 @@ async function listTemplates() {
3964
3884
  const lWeight = TEMPLATE_SORT_WEIGHT[l.name] ?? Number.MAX_SAFE_INTEGER;
3965
3885
  const rWeight = TEMPLATE_SORT_WEIGHT[r.name] ?? Number.MAX_SAFE_INTEGER;
3966
3886
  const diff = lWeight - rWeight;
3967
- if (diff !== 0)
3968
- return diff;
3887
+ if (diff !== 0) return diff;
3969
3888
  return l.name.localeCompare(r.name);
3970
3889
  });
3971
3890
  } catch (err) {
@@ -4075,8 +3994,9 @@ async function zipDir(directory, outputPath, options) {
4075
3994
  cwd: directory,
4076
3995
  // Ignore node_modules, otherwise this glob step takes forever
4077
3996
  ignore: ["**/node_modules"],
4078
- onlyFiles: true,
4079
- dot: true
3997
+ onlyFiles: true
3998
+ // TODO: Fix #738
3999
+ // dot: true,
4080
4000
  })).filter((relativePath) => {
4081
4001
  return options?.include?.some((pattern) => minimatch2(relativePath, pattern)) || !options?.exclude?.some((pattern) => minimatch2(relativePath, pattern));
4082
4002
  });
@@ -4135,8 +4055,7 @@ async function downloadPrivatePackages() {
4135
4055
  return { overrides, files };
4136
4056
  }
4137
4057
  function addOverridesToPackageJson(absolutePackageJsonPath, content, overrides) {
4138
- if (Object.keys(overrides).length === 0)
4139
- return content;
4058
+ if (Object.keys(overrides).length === 0) return content;
4140
4059
  const packageJsonDir = path10.dirname(absolutePackageJsonPath);
4141
4060
  const oldPackage = JSON.parse(content);
4142
4061
  const newPackage = {
@@ -4189,7 +4108,7 @@ function createAliasedCommand(base, name, alias, bin, docsUrl) {
4189
4108
  const args = process.argv.slice(
4190
4109
  process.argv.indexOf(aliasedCommand.name) + 1
4191
4110
  );
4192
- const { execa } = await import("./execa-QQUOQNS3.js");
4111
+ const { execa } = await import("./execa-ATHZH2Y4.js");
4193
4112
  await execa(bin, args, {
4194
4113
  stdio: "inherit"
4195
4114
  });