wxt 0.3.0 → 0.3.2

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.js CHANGED
@@ -15,6 +15,8 @@ function normalizePath2(path5) {
15
15
  function unnormalizePath(path5) {
16
16
  return nodePath.normalize(path5);
17
17
  }
18
+ var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
19
+ var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
18
20
 
19
21
  // src/core/utils/entrypoints.ts
20
22
  function getEntrypointName(entrypointsDir, inputPath) {
@@ -234,7 +236,7 @@ function getUnimportOptions(config) {
234
236
  imports: [{ name: "defineConfig", from: "wxt" }],
235
237
  presets: [{ package: "wxt/client" }, { package: "wxt/browser" }],
236
238
  warn: config.logger.warn,
237
- dirs: ["./components/*", "./composables/*", "./hooks/*", "./utils/*"]
239
+ dirs: ["components", "composables", "hooks", "utils"]
238
240
  };
239
241
  return mergeConfig(
240
242
  defaultOptions,
@@ -328,6 +330,30 @@ export default defineBackground(() => void 0)`;
328
330
  }
329
331
  var VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
330
332
 
333
+ // src/core/vite-plugins/cssEntrypoints.ts
334
+ function cssEntrypoints(entrypoint, config) {
335
+ return {
336
+ name: "wxt:css-entrypoint",
337
+ config() {
338
+ return {
339
+ build: {
340
+ rollupOptions: {
341
+ output: {
342
+ assetFileNames: () => getEntrypointBundlePath(entrypoint, config.outDir, ".css")
343
+ }
344
+ }
345
+ }
346
+ };
347
+ },
348
+ generateBundle(_, bundle) {
349
+ Object.keys(bundle).forEach((file) => {
350
+ if (file.endsWith(".js"))
351
+ delete bundle[file];
352
+ });
353
+ }
354
+ };
355
+ }
356
+
331
357
  // src/core/utils/createFsCache.ts
332
358
  import fs3, { ensureDir as ensureDir2 } from "fs-extra";
333
359
  import { dirname as dirname3, resolve as resolve5 } from "path";
@@ -662,7 +688,12 @@ async function buildEntrypoints(groups, config) {
662
688
  async function buildSingleEntrypoint(entrypoint, config) {
663
689
  const isVirtual = ["background", "content-script"].includes(entrypoint.type);
664
690
  const entry = isVirtual ? `virtual:wxt-${entrypoint.type}?${entrypoint.inputPath}` : entrypoint.inputPath;
691
+ const plugins = [];
692
+ if (entrypoint.type === "content-script-style" || entrypoint.type === "unlisted-style") {
693
+ plugins.push(cssEntrypoints(entrypoint, config));
694
+ }
665
695
  const libMode = {
696
+ plugins,
666
697
  build: {
667
698
  lib: {
668
699
  entry,
@@ -758,7 +789,7 @@ async function copyPublicDirectory(config) {
758
789
  // src/core/build/findEntrypoints.ts
759
790
  import { relative as relative3, resolve as resolve9 } from "path";
760
791
  import fs8 from "fs-extra";
761
- import picomatch from "picomatch";
792
+ import { minimatch } from "minimatch";
762
793
  import { parseHTML as parseHTML2 } from "linkedom";
763
794
  import JSON5 from "json5";
764
795
 
@@ -833,7 +864,7 @@ async function findEntrypoints(config) {
833
864
  relativePaths.map(async (relativePath) => {
834
865
  const path5 = resolve9(config.entrypointsDir, relativePath);
835
866
  const matchingGlob = pathGlobs.find(
836
- (glob3) => picomatch.isMatch(relativePath, glob3)
867
+ (glob3) => minimatch(relativePath, glob3)
837
868
  );
838
869
  if (matchingGlob == null) {
839
870
  return config.logger.warn(
@@ -867,6 +898,14 @@ ${JSON.stringify(
867
898
  path5
868
899
  );
869
900
  break;
901
+ case "content-script-style":
902
+ entrypoint = {
903
+ type,
904
+ name: getEntrypointName(config.entrypointsDir, path5),
905
+ inputPath: path5,
906
+ outputDir: resolve9(config.outDir, CONTENT_SCRIPT_OUT_DIR)
907
+ };
908
+ break;
870
909
  default:
871
910
  entrypoint = {
872
911
  type,
@@ -982,7 +1021,7 @@ async function getContentScriptEntrypoint(config, name, path5) {
982
1021
  type: "content-script",
983
1022
  name: getEntrypointName(config.entrypointsDir, path5),
984
1023
  inputPath: path5,
985
- outputDir: resolve9(config.outDir, "content-scripts"),
1024
+ outputDir: resolve9(config.outDir, CONTENT_SCRIPT_OUT_DIR),
986
1025
  options
987
1026
  };
988
1027
  }
@@ -1009,6 +1048,10 @@ var PATH_GLOB_TO_TYPE_MAP = {
1009
1048
  "content/index.ts?(x)": "content-script",
1010
1049
  "*.content.ts?(x)": "content-script",
1011
1050
  "*.content/index.ts?(x)": "content-script",
1051
+ [`content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
1052
+ [`*.content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
1053
+ [`content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
1054
+ [`*.content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
1012
1055
  "popup.html": "popup",
1013
1056
  "popup/index.html": "popup",
1014
1057
  "options.html": "options",
@@ -1016,9 +1059,13 @@ var PATH_GLOB_TO_TYPE_MAP = {
1016
1059
  "*.html": "unlisted-page",
1017
1060
  "*/index.html": "unlisted-page",
1018
1061
  "*.ts": "unlisted-script",
1062
+ "*/index.ts": "unlisted-script",
1063
+ [`*.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
1064
+ [`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
1019
1065
  // Don't warn about any files in subdirectories, like CSS or JS entrypoints for HTML files
1020
1066
  "*/*": "ignored"
1021
1067
  };
1068
+ var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
1022
1069
 
1023
1070
  // src/core/build/generateTypesDir.ts
1024
1071
  import { createUnimport as createUnimport3 } from "unimport";
@@ -1262,7 +1309,8 @@ async function generateMainfest(entrypoints, buildOutput, config) {
1262
1309
  version: pkg?.version && simplifyVersion(pkg.version),
1263
1310
  // Only add the version name to chromium and if the user hasn't specified a custom version.
1264
1311
  version_name: config.browser !== "firefox" && !config.manifest.version ? pkg?.version : void 0,
1265
- short_name: pkg?.shortName
1312
+ short_name: pkg?.shortName,
1313
+ icons: discoverIcons(buildOutput)
1266
1314
  },
1267
1315
  config.manifest
1268
1316
  );
@@ -1273,11 +1321,11 @@ async function generateMainfest(entrypoints, buildOutput, config) {
1273
1321
  addDevModePermissions(manifest, config);
1274
1322
  if (manifest.name == null)
1275
1323
  throw Error(
1276
- "Manifest 'name' is missing. Either:\n1. Set the name in your <root>/package.json\n2. Set a name via the manifest option in your wxt.config.ts"
1324
+ "Manifest 'name' is missing. Either:\n1. Set the name in your <rootDir>/package.json\n2. Set a name via the manifest option in your wxt.config.ts"
1277
1325
  );
1278
1326
  if (manifest.version == null) {
1279
1327
  throw Error(
1280
- "Manifest 'version' is missing. Either:\n1. Add a version in your <root>/package.json\n2. Pass the version via the manifest option in your wxt.config.ts"
1328
+ "Manifest 'version' is missing. Either:\n1. Add a version in your <rootDir>/package.json\n2. Pass the version via the manifest option in your wxt.config.ts"
1281
1329
  );
1282
1330
  }
1283
1331
  return manifest;
@@ -1466,6 +1514,39 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
1466
1514
  }
1467
1515
  }
1468
1516
  }
1517
+ function discoverIcons(buildOutput) {
1518
+ const icons = [];
1519
+ const iconRegex = [
1520
+ /^icon-([0-9]+)\.(png|bmp|jpeg|jpg|ico|gif)$/,
1521
+ // icon-16.png
1522
+ /^icon-([0-9]+)x[0-9]+\.(png|bmp|jpeg|jpg|ico|gif)$/,
1523
+ // icon-16x16.png
1524
+ /^icon@([0-9]+)w\.(png|bmp|jpeg|jpg|ico|gif)$/,
1525
+ // icon@16w.png
1526
+ /^icon@([0-9]+)h\.(png|bmp|jpeg|jpg|ico|gif)$/,
1527
+ // icon@16h.png
1528
+ /^icon@([0-9]+)\.(png|bmp|jpeg|jpg|ico|gif)$/,
1529
+ // icon@16.png
1530
+ /^icon[\/\\]([0-9]+)\.(png|bmp|jpeg|jpg|ico|gif)$/,
1531
+ // icon/16.png
1532
+ /^icon[\/\\]([0-9]+)x[0-9]+\.(png|bmp|jpeg|jpg|ico|gif)$/
1533
+ // icon/16x16.png
1534
+ ];
1535
+ buildOutput.publicAssets.forEach((asset) => {
1536
+ let size;
1537
+ for (const regex of iconRegex) {
1538
+ const match = asset.fileName.match(regex);
1539
+ if (match?.[1] != null) {
1540
+ size = match[1];
1541
+ break;
1542
+ }
1543
+ }
1544
+ if (size == null)
1545
+ return;
1546
+ icons.push([size, normalizePath2(asset.fileName)]);
1547
+ });
1548
+ return icons.length > 0 ? Object.fromEntries(icons) : void 0;
1549
+ }
1469
1550
  function addDevModeCsp(manifest, config) {
1470
1551
  const permission = `http://${config.server?.hostname ?? ""}/*`;
1471
1552
  const allowedCsp = config.server?.origin ?? "http://localhost:*";
@@ -1558,7 +1639,9 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
1558
1639
  "unlisted-page": "extension-page",
1559
1640
  background: "no-group",
1560
1641
  "content-script": "no-group",
1561
- "unlisted-script": "no-group"
1642
+ "unlisted-script": "no-group",
1643
+ "unlisted-style": "no-group",
1644
+ "content-script-style": "no-group"
1562
1645
  };
1563
1646
 
1564
1647
  // src/core/utils/formatDuration.ts
@@ -1582,7 +1665,7 @@ import fs12 from "fs-extra";
1582
1665
  import { filesize } from "filesize";
1583
1666
 
1584
1667
  // src/core/log/printTable.ts
1585
- function printTable(log, rows, gap = 2) {
1668
+ function printTable(log, header, rows, gap = 2) {
1586
1669
  if (rows.length === 0)
1587
1670
  return;
1588
1671
  const columnWidths = rows.reduce(
@@ -1604,11 +1687,12 @@ function printTable(log, rows, gap = 2) {
1604
1687
  if (i !== rows.length - 1)
1605
1688
  str += "\n";
1606
1689
  });
1607
- log(str);
1690
+ log(`${header}
1691
+ ${str}`);
1608
1692
  }
1609
1693
 
1610
1694
  // src/core/log/printFileList.ts
1611
- async function printFileList(log, baseDir, files) {
1695
+ async function printFileList(log, header, baseDir, files) {
1612
1696
  let totalSize = 0;
1613
1697
  const fileRows = await Promise.all(
1614
1698
  files.map(async (file, i) => {
@@ -1627,8 +1711,8 @@ async function printFileList(log, baseDir, files) {
1627
1711
  ];
1628
1712
  })
1629
1713
  );
1630
- printTable(log, fileRows);
1631
- log(`${pc.cyan("\u03A3 Total size:")} ${String(filesize(totalSize))}`);
1714
+ fileRows.push([`${pc.cyan("\u03A3 Total size:")} ${String(filesize(totalSize))}`]);
1715
+ printTable(log, header, fileRows);
1632
1716
  }
1633
1717
  var DEFAULT_COLOR = pc.blue;
1634
1718
  var CHUNK_COLORS = {
@@ -1643,7 +1727,7 @@ function getChunkColor(filename) {
1643
1727
  }
1644
1728
 
1645
1729
  // src/core/log/printBuildSummary.ts
1646
- async function printBuildSummary(output, config) {
1730
+ async function printBuildSummary(log, header, output, config) {
1647
1731
  const chunks = [
1648
1732
  ...output.steps.flatMap((step) => step.chunks),
1649
1733
  ...output.publicAssets
@@ -1656,7 +1740,7 @@ async function printBuildSummary(output, config) {
1656
1740
  return l.fileName.localeCompare(r.fileName);
1657
1741
  });
1658
1742
  const files = chunks.map((chunk) => resolve13(config.outDir, chunk.fileName));
1659
- await printFileList(config.logger.log, config.outDir, files);
1743
+ await printFileList(log, header, config.outDir, files);
1660
1744
  }
1661
1745
  var DEFAULT_SORT_WEIGHT = 100;
1662
1746
  var CHUNK_SORT_WEIGHTS = {
@@ -1687,10 +1771,12 @@ async function buildInternal(config) {
1687
1771
  const entrypoints = await findEntrypoints(config);
1688
1772
  const groups = groupEntrypoints(entrypoints);
1689
1773
  const { output } = await rebuild(config, groups, void 0);
1690
- config.logger.success(
1691
- `Built extension in ${formatDuration(Date.now() - startTime)}`
1774
+ await printBuildSummary(
1775
+ config.logger.success,
1776
+ `Built extension in ${formatDuration(Date.now() - startTime)}`,
1777
+ output,
1778
+ config
1692
1779
  );
1693
- await printBuildSummary(output, config);
1694
1780
  return output;
1695
1781
  }
1696
1782
  async function rebuild(config, entrypointGroups, existingOutput = {
@@ -1878,7 +1964,7 @@ function reloadHtmlPages(groups, server, config) {
1878
1964
  }
1879
1965
 
1880
1966
  // package.json
1881
- var version2 = "0.3.0";
1967
+ var version2 = "0.3.2";
1882
1968
 
1883
1969
  // src/core/utils/defineConfig.ts
1884
1970
  function defineConfig(config) {