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/README.md +4 -2
- package/bin/wxt.cjs +2 -0
- package/dist/cli.cjs +6872 -153
- package/dist/index.cjs +105 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +420 -0
- package/dist/index.d.ts +24 -27
- package/dist/index.js +105 -19
- package/dist/index.js.map +1 -1
- package/package.json +20 -16
package/dist/index.cjs
CHANGED
|
@@ -55,6 +55,8 @@ function normalizePath2(path5) {
|
|
|
55
55
|
function unnormalizePath(path5) {
|
|
56
56
|
return import_node_path.default.normalize(path5);
|
|
57
57
|
}
|
|
58
|
+
var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
|
|
59
|
+
var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
|
|
58
60
|
|
|
59
61
|
// src/core/utils/entrypoints.ts
|
|
60
62
|
function getEntrypointName(entrypointsDir, inputPath) {
|
|
@@ -274,7 +276,7 @@ function getUnimportOptions(config) {
|
|
|
274
276
|
imports: [{ name: "defineConfig", from: "wxt" }],
|
|
275
277
|
presets: [{ package: "wxt/client" }, { package: "wxt/browser" }],
|
|
276
278
|
warn: config.logger.warn,
|
|
277
|
-
dirs: ["
|
|
279
|
+
dirs: ["components", "composables", "hooks", "utils"]
|
|
278
280
|
};
|
|
279
281
|
return (0, import_vite.mergeConfig)(
|
|
280
282
|
defaultOptions,
|
|
@@ -368,6 +370,30 @@ export default defineBackground(() => void 0)`;
|
|
|
368
370
|
}
|
|
369
371
|
var VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
|
|
370
372
|
|
|
373
|
+
// src/core/vite-plugins/cssEntrypoints.ts
|
|
374
|
+
function cssEntrypoints(entrypoint, config) {
|
|
375
|
+
return {
|
|
376
|
+
name: "wxt:css-entrypoint",
|
|
377
|
+
config() {
|
|
378
|
+
return {
|
|
379
|
+
build: {
|
|
380
|
+
rollupOptions: {
|
|
381
|
+
output: {
|
|
382
|
+
assetFileNames: () => getEntrypointBundlePath(entrypoint, config.outDir, ".css")
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
},
|
|
388
|
+
generateBundle(_, bundle) {
|
|
389
|
+
Object.keys(bundle).forEach((file) => {
|
|
390
|
+
if (file.endsWith(".js"))
|
|
391
|
+
delete bundle[file];
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
371
397
|
// src/core/utils/createFsCache.ts
|
|
372
398
|
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
373
399
|
var import_path4 = require("path");
|
|
@@ -702,7 +728,12 @@ async function buildEntrypoints(groups, config) {
|
|
|
702
728
|
async function buildSingleEntrypoint(entrypoint, config) {
|
|
703
729
|
const isVirtual = ["background", "content-script"].includes(entrypoint.type);
|
|
704
730
|
const entry = isVirtual ? `virtual:wxt-${entrypoint.type}?${entrypoint.inputPath}` : entrypoint.inputPath;
|
|
731
|
+
const plugins = [];
|
|
732
|
+
if (entrypoint.type === "content-script-style" || entrypoint.type === "unlisted-style") {
|
|
733
|
+
plugins.push(cssEntrypoints(entrypoint, config));
|
|
734
|
+
}
|
|
705
735
|
const libMode = {
|
|
736
|
+
plugins,
|
|
706
737
|
build: {
|
|
707
738
|
lib: {
|
|
708
739
|
entry,
|
|
@@ -798,7 +829,7 @@ async function copyPublicDirectory(config) {
|
|
|
798
829
|
// src/core/build/findEntrypoints.ts
|
|
799
830
|
var import_path8 = require("path");
|
|
800
831
|
var import_fs_extra8 = __toESM(require("fs-extra"), 1);
|
|
801
|
-
var
|
|
832
|
+
var import_minimatch = require("minimatch");
|
|
802
833
|
var import_linkedom2 = require("linkedom");
|
|
803
834
|
var import_json5 = __toESM(require("json5"), 1);
|
|
804
835
|
|
|
@@ -873,7 +904,7 @@ async function findEntrypoints(config) {
|
|
|
873
904
|
relativePaths.map(async (relativePath) => {
|
|
874
905
|
const path5 = (0, import_path8.resolve)(config.entrypointsDir, relativePath);
|
|
875
906
|
const matchingGlob = pathGlobs.find(
|
|
876
|
-
(glob3) =>
|
|
907
|
+
(glob3) => (0, import_minimatch.minimatch)(relativePath, glob3)
|
|
877
908
|
);
|
|
878
909
|
if (matchingGlob == null) {
|
|
879
910
|
return config.logger.warn(
|
|
@@ -907,6 +938,14 @@ ${JSON.stringify(
|
|
|
907
938
|
path5
|
|
908
939
|
);
|
|
909
940
|
break;
|
|
941
|
+
case "content-script-style":
|
|
942
|
+
entrypoint = {
|
|
943
|
+
type,
|
|
944
|
+
name: getEntrypointName(config.entrypointsDir, path5),
|
|
945
|
+
inputPath: path5,
|
|
946
|
+
outputDir: (0, import_path8.resolve)(config.outDir, CONTENT_SCRIPT_OUT_DIR)
|
|
947
|
+
};
|
|
948
|
+
break;
|
|
910
949
|
default:
|
|
911
950
|
entrypoint = {
|
|
912
951
|
type,
|
|
@@ -1022,7 +1061,7 @@ async function getContentScriptEntrypoint(config, name, path5) {
|
|
|
1022
1061
|
type: "content-script",
|
|
1023
1062
|
name: getEntrypointName(config.entrypointsDir, path5),
|
|
1024
1063
|
inputPath: path5,
|
|
1025
|
-
outputDir: (0, import_path8.resolve)(config.outDir,
|
|
1064
|
+
outputDir: (0, import_path8.resolve)(config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
1026
1065
|
options
|
|
1027
1066
|
};
|
|
1028
1067
|
}
|
|
@@ -1049,6 +1088,10 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
1049
1088
|
"content/index.ts?(x)": "content-script",
|
|
1050
1089
|
"*.content.ts?(x)": "content-script",
|
|
1051
1090
|
"*.content/index.ts?(x)": "content-script",
|
|
1091
|
+
[`content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
1092
|
+
[`*.content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
1093
|
+
[`content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
1094
|
+
[`*.content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
1052
1095
|
"popup.html": "popup",
|
|
1053
1096
|
"popup/index.html": "popup",
|
|
1054
1097
|
"options.html": "options",
|
|
@@ -1056,9 +1099,13 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
1056
1099
|
"*.html": "unlisted-page",
|
|
1057
1100
|
"*/index.html": "unlisted-page",
|
|
1058
1101
|
"*.ts": "unlisted-script",
|
|
1102
|
+
"*/index.ts": "unlisted-script",
|
|
1103
|
+
[`*.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
|
|
1104
|
+
[`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
|
|
1059
1105
|
// Don't warn about any files in subdirectories, like CSS or JS entrypoints for HTML files
|
|
1060
1106
|
"*/*": "ignored"
|
|
1061
1107
|
};
|
|
1108
|
+
var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|
|
1062
1109
|
|
|
1063
1110
|
// src/core/build/generateTypesDir.ts
|
|
1064
1111
|
var import_unimport3 = require("unimport");
|
|
@@ -1302,7 +1349,8 @@ async function generateMainfest(entrypoints, buildOutput, config) {
|
|
|
1302
1349
|
version: pkg?.version && simplifyVersion(pkg.version),
|
|
1303
1350
|
// Only add the version name to chromium and if the user hasn't specified a custom version.
|
|
1304
1351
|
version_name: config.browser !== "firefox" && !config.manifest.version ? pkg?.version : void 0,
|
|
1305
|
-
short_name: pkg?.shortName
|
|
1352
|
+
short_name: pkg?.shortName,
|
|
1353
|
+
icons: discoverIcons(buildOutput)
|
|
1306
1354
|
},
|
|
1307
1355
|
config.manifest
|
|
1308
1356
|
);
|
|
@@ -1313,11 +1361,11 @@ async function generateMainfest(entrypoints, buildOutput, config) {
|
|
|
1313
1361
|
addDevModePermissions(manifest, config);
|
|
1314
1362
|
if (manifest.name == null)
|
|
1315
1363
|
throw Error(
|
|
1316
|
-
"Manifest 'name' is missing. Either:\n1. Set the name in your <
|
|
1364
|
+
"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"
|
|
1317
1365
|
);
|
|
1318
1366
|
if (manifest.version == null) {
|
|
1319
1367
|
throw Error(
|
|
1320
|
-
"Manifest 'version' is missing. Either:\n1. Add a version in your <
|
|
1368
|
+
"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"
|
|
1321
1369
|
);
|
|
1322
1370
|
}
|
|
1323
1371
|
return manifest;
|
|
@@ -1506,6 +1554,39 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
1506
1554
|
}
|
|
1507
1555
|
}
|
|
1508
1556
|
}
|
|
1557
|
+
function discoverIcons(buildOutput) {
|
|
1558
|
+
const icons = [];
|
|
1559
|
+
const iconRegex = [
|
|
1560
|
+
/^icon-([0-9]+)\.(png|bmp|jpeg|jpg|ico|gif)$/,
|
|
1561
|
+
// icon-16.png
|
|
1562
|
+
/^icon-([0-9]+)x[0-9]+\.(png|bmp|jpeg|jpg|ico|gif)$/,
|
|
1563
|
+
// icon-16x16.png
|
|
1564
|
+
/^icon@([0-9]+)w\.(png|bmp|jpeg|jpg|ico|gif)$/,
|
|
1565
|
+
// icon@16w.png
|
|
1566
|
+
/^icon@([0-9]+)h\.(png|bmp|jpeg|jpg|ico|gif)$/,
|
|
1567
|
+
// icon@16h.png
|
|
1568
|
+
/^icon@([0-9]+)\.(png|bmp|jpeg|jpg|ico|gif)$/,
|
|
1569
|
+
// icon@16.png
|
|
1570
|
+
/^icon[\/\\]([0-9]+)\.(png|bmp|jpeg|jpg|ico|gif)$/,
|
|
1571
|
+
// icon/16.png
|
|
1572
|
+
/^icon[\/\\]([0-9]+)x[0-9]+\.(png|bmp|jpeg|jpg|ico|gif)$/
|
|
1573
|
+
// icon/16x16.png
|
|
1574
|
+
];
|
|
1575
|
+
buildOutput.publicAssets.forEach((asset) => {
|
|
1576
|
+
let size;
|
|
1577
|
+
for (const regex of iconRegex) {
|
|
1578
|
+
const match = asset.fileName.match(regex);
|
|
1579
|
+
if (match?.[1] != null) {
|
|
1580
|
+
size = match[1];
|
|
1581
|
+
break;
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
if (size == null)
|
|
1585
|
+
return;
|
|
1586
|
+
icons.push([size, normalizePath2(asset.fileName)]);
|
|
1587
|
+
});
|
|
1588
|
+
return icons.length > 0 ? Object.fromEntries(icons) : void 0;
|
|
1589
|
+
}
|
|
1509
1590
|
function addDevModeCsp(manifest, config) {
|
|
1510
1591
|
const permission = `http://${config.server?.hostname ?? ""}/*`;
|
|
1511
1592
|
const allowedCsp = config.server?.origin ?? "http://localhost:*";
|
|
@@ -1598,7 +1679,9 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
|
|
|
1598
1679
|
"unlisted-page": "extension-page",
|
|
1599
1680
|
background: "no-group",
|
|
1600
1681
|
"content-script": "no-group",
|
|
1601
|
-
"unlisted-script": "no-group"
|
|
1682
|
+
"unlisted-script": "no-group",
|
|
1683
|
+
"unlisted-style": "no-group",
|
|
1684
|
+
"content-script-style": "no-group"
|
|
1602
1685
|
};
|
|
1603
1686
|
|
|
1604
1687
|
// src/core/utils/formatDuration.ts
|
|
@@ -1622,7 +1705,7 @@ var import_fs_extra12 = __toESM(require("fs-extra"), 1);
|
|
|
1622
1705
|
var import_filesize = require("filesize");
|
|
1623
1706
|
|
|
1624
1707
|
// src/core/log/printTable.ts
|
|
1625
|
-
function printTable(log, rows, gap = 2) {
|
|
1708
|
+
function printTable(log, header, rows, gap = 2) {
|
|
1626
1709
|
if (rows.length === 0)
|
|
1627
1710
|
return;
|
|
1628
1711
|
const columnWidths = rows.reduce(
|
|
@@ -1644,11 +1727,12 @@ function printTable(log, rows, gap = 2) {
|
|
|
1644
1727
|
if (i !== rows.length - 1)
|
|
1645
1728
|
str += "\n";
|
|
1646
1729
|
});
|
|
1647
|
-
log(
|
|
1730
|
+
log(`${header}
|
|
1731
|
+
${str}`);
|
|
1648
1732
|
}
|
|
1649
1733
|
|
|
1650
1734
|
// src/core/log/printFileList.ts
|
|
1651
|
-
async function printFileList(log, baseDir, files) {
|
|
1735
|
+
async function printFileList(log, header, baseDir, files) {
|
|
1652
1736
|
let totalSize = 0;
|
|
1653
1737
|
const fileRows = await Promise.all(
|
|
1654
1738
|
files.map(async (file, i) => {
|
|
@@ -1667,8 +1751,8 @@ async function printFileList(log, baseDir, files) {
|
|
|
1667
1751
|
];
|
|
1668
1752
|
})
|
|
1669
1753
|
);
|
|
1670
|
-
|
|
1671
|
-
log
|
|
1754
|
+
fileRows.push([`${import_picocolors.default.cyan("\u03A3 Total size:")} ${String((0, import_filesize.filesize)(totalSize))}`]);
|
|
1755
|
+
printTable(log, header, fileRows);
|
|
1672
1756
|
}
|
|
1673
1757
|
var DEFAULT_COLOR = import_picocolors.default.blue;
|
|
1674
1758
|
var CHUNK_COLORS = {
|
|
@@ -1683,7 +1767,7 @@ function getChunkColor(filename) {
|
|
|
1683
1767
|
}
|
|
1684
1768
|
|
|
1685
1769
|
// src/core/log/printBuildSummary.ts
|
|
1686
|
-
async function printBuildSummary(output, config) {
|
|
1770
|
+
async function printBuildSummary(log, header, output, config) {
|
|
1687
1771
|
const chunks = [
|
|
1688
1772
|
...output.steps.flatMap((step) => step.chunks),
|
|
1689
1773
|
...output.publicAssets
|
|
@@ -1696,7 +1780,7 @@ async function printBuildSummary(output, config) {
|
|
|
1696
1780
|
return l.fileName.localeCompare(r.fileName);
|
|
1697
1781
|
});
|
|
1698
1782
|
const files = chunks.map((chunk) => (0, import_path11.resolve)(config.outDir, chunk.fileName));
|
|
1699
|
-
await printFileList(
|
|
1783
|
+
await printFileList(log, header, config.outDir, files);
|
|
1700
1784
|
}
|
|
1701
1785
|
var DEFAULT_SORT_WEIGHT = 100;
|
|
1702
1786
|
var CHUNK_SORT_WEIGHTS = {
|
|
@@ -1727,10 +1811,12 @@ async function buildInternal(config) {
|
|
|
1727
1811
|
const entrypoints = await findEntrypoints(config);
|
|
1728
1812
|
const groups = groupEntrypoints(entrypoints);
|
|
1729
1813
|
const { output } = await rebuild(config, groups, void 0);
|
|
1730
|
-
|
|
1731
|
-
|
|
1814
|
+
await printBuildSummary(
|
|
1815
|
+
config.logger.success,
|
|
1816
|
+
`Built extension in ${formatDuration(Date.now() - startTime)}`,
|
|
1817
|
+
output,
|
|
1818
|
+
config
|
|
1732
1819
|
);
|
|
1733
|
-
await printBuildSummary(output, config);
|
|
1734
1820
|
return output;
|
|
1735
1821
|
}
|
|
1736
1822
|
async function rebuild(config, entrypointGroups, existingOutput = {
|
|
@@ -1918,7 +2004,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1918
2004
|
}
|
|
1919
2005
|
|
|
1920
2006
|
// package.json
|
|
1921
|
-
var version2 = "0.3.
|
|
2007
|
+
var version2 = "0.3.2";
|
|
1922
2008
|
|
|
1923
2009
|
// src/core/utils/defineConfig.ts
|
|
1924
2010
|
function defineConfig(config) {
|