wxt 0.2.2 → 0.2.4
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.cjs +185 -92
- package/dist/index.cjs +116 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +55 -4
- package/dist/index.js +117 -92
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -470,7 +470,27 @@ async function getInternalConfig(config, command) {
|
|
|
470
470
|
wxtDir,
|
|
471
471
|
typesDir,
|
|
472
472
|
fsCache: createFsCache(wxtDir),
|
|
473
|
-
manifest
|
|
473
|
+
manifest,
|
|
474
|
+
zip: {
|
|
475
|
+
sourcesTemplate: "{{name}}-{{version}}-sources.zip",
|
|
476
|
+
artifactTemplate: "{{name}}-{{version}}-{{browser}}.zip",
|
|
477
|
+
sourcesRoot: root,
|
|
478
|
+
...userConfig.zip,
|
|
479
|
+
...config.zip,
|
|
480
|
+
ignoredSources: [
|
|
481
|
+
"**/node_modules",
|
|
482
|
+
// WXT files
|
|
483
|
+
"**/web-ext.config.ts",
|
|
484
|
+
// Hidden files
|
|
485
|
+
"**/.*",
|
|
486
|
+
// Tests
|
|
487
|
+
"**/__tests__/**",
|
|
488
|
+
"**/*.+(test|spec).?(c|m)+(j|t)s?(x)",
|
|
489
|
+
// User config
|
|
490
|
+
...userConfig.zip?.ignoredSources ?? [],
|
|
491
|
+
...config.zip?.ignoredSources ?? []
|
|
492
|
+
]
|
|
493
|
+
}
|
|
474
494
|
};
|
|
475
495
|
finalConfig.vite.root = root;
|
|
476
496
|
finalConfig.vite.configFile = false;
|
|
@@ -598,7 +618,7 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
598
618
|
// src/index.ts
|
|
599
619
|
var import_async_mutex = require("async-mutex");
|
|
600
620
|
var import_consola2 = require("consola");
|
|
601
|
-
var
|
|
621
|
+
var import_node_path6 = require("path");
|
|
602
622
|
|
|
603
623
|
// src/core/build/buildEntrypoints.ts
|
|
604
624
|
var vite2 = __toESM(require("vite"), 1);
|
|
@@ -890,15 +910,15 @@ async function getOptionsEntrypoint(config, path5) {
|
|
|
890
910
|
const { document } = (0, import_linkedom2.parseHTML)(content);
|
|
891
911
|
const openInTabContent = document.querySelector("meta[name='manifest.open_in_tab']")?.getAttribute("content");
|
|
892
912
|
if (openInTabContent) {
|
|
893
|
-
options.openInTab =
|
|
913
|
+
options.openInTab = openInTabContent === "true";
|
|
894
914
|
}
|
|
895
915
|
const chromeStyleContent = document.querySelector("meta[name='manifest.chrome_style']")?.getAttribute("content");
|
|
896
916
|
if (chromeStyleContent) {
|
|
897
|
-
options.chromeStyle =
|
|
917
|
+
options.chromeStyle = chromeStyleContent === "true";
|
|
898
918
|
}
|
|
899
919
|
const browserStyleContent = document.querySelector("meta[name='manifest.browser_style']")?.getAttribute("content");
|
|
900
920
|
if (browserStyleContent) {
|
|
901
|
-
options.browserStyle =
|
|
921
|
+
options.browserStyle = browserStyleContent === "true";
|
|
902
922
|
}
|
|
903
923
|
return {
|
|
904
924
|
type: "options",
|
|
@@ -1089,7 +1109,7 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1089
1109
|
}
|
|
1090
1110
|
|
|
1091
1111
|
// src/core/utils/manifest.ts
|
|
1092
|
-
var
|
|
1112
|
+
var import_fs_extra10 = __toESM(require("fs-extra"), 1);
|
|
1093
1113
|
var import_path10 = require("path");
|
|
1094
1114
|
|
|
1095
1115
|
// src/core/utils/ContentSecurityPolicy.ts
|
|
@@ -1173,11 +1193,26 @@ function mapWxtOptionsToContentScript(options) {
|
|
|
1173
1193
|
};
|
|
1174
1194
|
}
|
|
1175
1195
|
|
|
1196
|
+
// src/core/utils/package.ts
|
|
1197
|
+
var import_node_path4 = require("path");
|
|
1198
|
+
var import_fs_extra9 = __toESM(require("fs-extra"), 1);
|
|
1199
|
+
async function getPackageJson(config) {
|
|
1200
|
+
const file = (0, import_node_path4.resolve)(config.root, "package.json");
|
|
1201
|
+
try {
|
|
1202
|
+
return await import_fs_extra9.default.readJson(file);
|
|
1203
|
+
} catch (err) {
|
|
1204
|
+
config.logger.debug(
|
|
1205
|
+
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
1206
|
+
);
|
|
1207
|
+
return {};
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1176
1211
|
// src/core/utils/manifest.ts
|
|
1177
1212
|
async function writeManifest(manifest, output, config) {
|
|
1178
1213
|
const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
1179
|
-
await
|
|
1180
|
-
await
|
|
1214
|
+
await import_fs_extra10.default.ensureDir(config.outDir);
|
|
1215
|
+
await import_fs_extra10.default.writeFile((0, import_path10.resolve)(config.outDir, "manifest.json"), str, "utf-8");
|
|
1181
1216
|
output.publicAssets.unshift({
|
|
1182
1217
|
type: "asset",
|
|
1183
1218
|
fileName: "manifest.json",
|
|
@@ -1188,30 +1223,34 @@ async function writeManifest(manifest, output, config) {
|
|
|
1188
1223
|
}
|
|
1189
1224
|
async function generateMainfest(entrypoints, buildOutput, config) {
|
|
1190
1225
|
const pkg = await getPackageJson(config);
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
...config.manifest
|
|
1204
|
-
};
|
|
1226
|
+
const manifest = Object.assign(
|
|
1227
|
+
{
|
|
1228
|
+
manifest_version: config.manifestVersion,
|
|
1229
|
+
name: pkg?.name,
|
|
1230
|
+
description: pkg?.description,
|
|
1231
|
+
version: pkg?.version && simplifyVersion(pkg.version),
|
|
1232
|
+
// Only add the version name to chromium and if the user hasn't specified a custom version.
|
|
1233
|
+
version_name: config.browser !== "firefox" && !config.manifest.version ? pkg?.version : void 0,
|
|
1234
|
+
short_name: pkg?.shortName
|
|
1235
|
+
},
|
|
1236
|
+
config.manifest
|
|
1237
|
+
);
|
|
1205
1238
|
addEntrypoints(manifest, entrypoints, buildOutput, config);
|
|
1206
1239
|
if (config.command === "serve")
|
|
1207
1240
|
addDevModeCsp(manifest, config);
|
|
1208
1241
|
if (config.command === "serve")
|
|
1209
1242
|
addDevModePermissions(manifest, config);
|
|
1243
|
+
if (manifest.name == null)
|
|
1244
|
+
throw Error(
|
|
1245
|
+
"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"
|
|
1246
|
+
);
|
|
1247
|
+
if (manifest.version == null) {
|
|
1248
|
+
throw Error(
|
|
1249
|
+
"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"
|
|
1250
|
+
);
|
|
1251
|
+
}
|
|
1210
1252
|
return manifest;
|
|
1211
1253
|
}
|
|
1212
|
-
async function getPackageJson(config) {
|
|
1213
|
-
return await import_fs_extra9.default.readJson((0, import_path10.resolve)(config.root, "package.json"));
|
|
1214
|
-
}
|
|
1215
1254
|
function simplifyVersion(versionName) {
|
|
1216
1255
|
const version3 = /^((0|[1-9][0-9]{0,8})([.](0|[1-9][0-9]{0,8})){0,3}).*$/.exec(
|
|
1217
1256
|
versionName
|
|
@@ -1455,7 +1494,7 @@ function addHostPermission(manifest, hostPermission) {
|
|
|
1455
1494
|
// src/core/build.ts
|
|
1456
1495
|
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
1457
1496
|
var vite3 = __toESM(require("vite"), 1);
|
|
1458
|
-
var
|
|
1497
|
+
var import_fs_extra12 = __toESM(require("fs-extra"), 1);
|
|
1459
1498
|
|
|
1460
1499
|
// src/core/utils/groupEntrypoints.ts
|
|
1461
1500
|
function groupEntrypoints(entrypoints) {
|
|
@@ -1503,7 +1542,13 @@ function formatDuration(duration) {
|
|
|
1503
1542
|
}
|
|
1504
1543
|
|
|
1505
1544
|
// src/core/log/printBuildSummary.ts
|
|
1506
|
-
var import_path11 =
|
|
1545
|
+
var import_path11 = require("path");
|
|
1546
|
+
|
|
1547
|
+
// src/core/log/printFileList.ts
|
|
1548
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
1549
|
+
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
1550
|
+
var import_fs_extra11 = __toESM(require("fs-extra"), 1);
|
|
1551
|
+
var import_filesize = require("filesize");
|
|
1507
1552
|
|
|
1508
1553
|
// src/core/log/printTable.ts
|
|
1509
1554
|
function printTable(log, rows, gap = 2) {
|
|
@@ -1531,10 +1576,42 @@ function printTable(log, rows, gap = 2) {
|
|
|
1531
1576
|
log(str);
|
|
1532
1577
|
}
|
|
1533
1578
|
|
|
1579
|
+
// src/core/log/printFileList.ts
|
|
1580
|
+
async function printFileList(log, baseDir, files) {
|
|
1581
|
+
let totalSize = 0;
|
|
1582
|
+
const fileRows = await Promise.all(
|
|
1583
|
+
files.map(async (file, i) => {
|
|
1584
|
+
const parts = [
|
|
1585
|
+
import_node_path5.default.relative(process.cwd(), baseDir) + import_node_path5.default.sep,
|
|
1586
|
+
import_node_path5.default.relative(baseDir, file)
|
|
1587
|
+
];
|
|
1588
|
+
const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1589
|
+
const color = getChunkColor(file);
|
|
1590
|
+
const stats = await import_fs_extra11.default.lstat(file);
|
|
1591
|
+
totalSize += stats.size;
|
|
1592
|
+
const size = String((0, import_filesize.filesize)(stats.size));
|
|
1593
|
+
return [
|
|
1594
|
+
`${import_picocolors.default.gray(prefix)} ${import_picocolors.default.dim(parts[0])}${color(parts[1])}`,
|
|
1595
|
+
import_picocolors.default.dim(size)
|
|
1596
|
+
];
|
|
1597
|
+
})
|
|
1598
|
+
);
|
|
1599
|
+
printTable(log, fileRows);
|
|
1600
|
+
log(`${import_picocolors.default.cyan("\u03A3 Total size:")} ${String((0, import_filesize.filesize)(totalSize))}`);
|
|
1601
|
+
}
|
|
1602
|
+
var DEFAULT_COLOR = import_picocolors.default.blue;
|
|
1603
|
+
var CHUNK_COLORS = {
|
|
1604
|
+
".js.map": import_picocolors.default.gray,
|
|
1605
|
+
".html": import_picocolors.default.green,
|
|
1606
|
+
".css": import_picocolors.default.magenta,
|
|
1607
|
+
".js": import_picocolors.default.cyan,
|
|
1608
|
+
".zip": import_picocolors.default.yellow
|
|
1609
|
+
};
|
|
1610
|
+
function getChunkColor(filename) {
|
|
1611
|
+
return Object.entries(CHUNK_COLORS).find(([key]) => filename.endsWith(key))?.[1] ?? DEFAULT_COLOR;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1534
1614
|
// src/core/log/printBuildSummary.ts
|
|
1535
|
-
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
1536
|
-
var import_fs_extra10 = __toESM(require("fs-extra"), 1);
|
|
1537
|
-
var import_filesize = require("filesize");
|
|
1538
1615
|
async function printBuildSummary(output, config) {
|
|
1539
1616
|
const chunks = [
|
|
1540
1617
|
...output.steps.flatMap((step) => step.chunks),
|
|
@@ -1547,28 +1624,8 @@ async function printBuildSummary(output, config) {
|
|
|
1547
1624
|
return diff;
|
|
1548
1625
|
return l.fileName.localeCompare(r.fileName);
|
|
1549
1626
|
});
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
chunks.map(async (chunk, i) => {
|
|
1553
|
-
const file = [
|
|
1554
|
-
(0, import_path11.relative)(process.cwd(), config.outDir) + import_path11.default.sep,
|
|
1555
|
-
chunk.fileName
|
|
1556
|
-
];
|
|
1557
|
-
const prefix = i === chunks.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1558
|
-
const color = getChunkColor(chunk.fileName);
|
|
1559
|
-
const stats = await import_fs_extra10.default.lstat((0, import_path11.resolve)(config.outDir, chunk.fileName));
|
|
1560
|
-
totalSize += stats.size;
|
|
1561
|
-
const size = String((0, import_filesize.filesize)(stats.size));
|
|
1562
|
-
return [
|
|
1563
|
-
`${import_picocolors.default.gray(prefix)} ${import_picocolors.default.dim(file[0])}${color(file[1])}`,
|
|
1564
|
-
import_picocolors.default.dim(size)
|
|
1565
|
-
];
|
|
1566
|
-
})
|
|
1567
|
-
);
|
|
1568
|
-
printTable(config.logger.log, chunkRows);
|
|
1569
|
-
config.logger.log(
|
|
1570
|
-
`${import_picocolors.default.cyan("\u03A3 Total size:")} ${String((0, import_filesize.filesize)(totalSize))}`
|
|
1571
|
-
);
|
|
1627
|
+
const files = chunks.map((chunk) => (0, import_path11.resolve)(config.outDir, chunk.fileName));
|
|
1628
|
+
await printFileList(config.logger.log, config.outDir, files);
|
|
1572
1629
|
}
|
|
1573
1630
|
var DEFAULT_SORT_WEIGHT = 100;
|
|
1574
1631
|
var CHUNK_SORT_WEIGHTS = {
|
|
@@ -1583,16 +1640,6 @@ function getChunkSortWeight(filename) {
|
|
|
1583
1640
|
([key]) => filename.endsWith(key)
|
|
1584
1641
|
)?.[1] ?? DEFAULT_SORT_WEIGHT;
|
|
1585
1642
|
}
|
|
1586
|
-
var DEFAULT_COLOR = import_picocolors.default.blue;
|
|
1587
|
-
var CHUNK_COLORS = {
|
|
1588
|
-
".js.map": import_picocolors.default.gray,
|
|
1589
|
-
".html": import_picocolors.default.green,
|
|
1590
|
-
".css": import_picocolors.default.magenta,
|
|
1591
|
-
".js": import_picocolors.default.cyan
|
|
1592
|
-
};
|
|
1593
|
-
function getChunkColor(filename) {
|
|
1594
|
-
return Object.entries(CHUNK_COLORS).find(([key]) => filename.endsWith(key))?.[1] ?? DEFAULT_COLOR;
|
|
1595
|
-
}
|
|
1596
1643
|
|
|
1597
1644
|
// src/core/build.ts
|
|
1598
1645
|
async function buildInternal(config) {
|
|
@@ -1604,8 +1651,8 @@ async function buildInternal(config) {
|
|
|
1604
1651
|
)}`
|
|
1605
1652
|
);
|
|
1606
1653
|
const startTime = Date.now();
|
|
1607
|
-
await
|
|
1608
|
-
await
|
|
1654
|
+
await import_fs_extra12.default.rm(config.outDir, { recursive: true, force: true });
|
|
1655
|
+
await import_fs_extra12.default.ensureDir(config.outDir);
|
|
1609
1656
|
const entrypoints = await findEntrypoints(config);
|
|
1610
1657
|
const groups = groupEntrypoints(entrypoints);
|
|
1611
1658
|
const { output } = await rebuild(config, groups);
|
|
@@ -1652,29 +1699,6 @@ async function rebuild(config, entrypointGroups, existingOutput = {
|
|
|
1652
1699
|
// src/core/server.ts
|
|
1653
1700
|
var vite4 = __toESM(require("vite"), 1);
|
|
1654
1701
|
|
|
1655
|
-
// src/core/utils/findOpenPort.ts
|
|
1656
|
-
var import_node_net = __toESM(require("net"), 1);
|
|
1657
|
-
function findOpenPort(startPort, endPort) {
|
|
1658
|
-
return findOpenPortRecursive(startPort, startPort, endPort);
|
|
1659
|
-
}
|
|
1660
|
-
function findOpenPortRecursive(port, startPort, endPort) {
|
|
1661
|
-
return new Promise((resolve13, reject) => {
|
|
1662
|
-
if (port > endPort)
|
|
1663
|
-
return reject(
|
|
1664
|
-
Error(`Could not find open port between ${startPort}-${endPort}`)
|
|
1665
|
-
);
|
|
1666
|
-
const server = import_node_net.default.createServer();
|
|
1667
|
-
server.listen(port, () => {
|
|
1668
|
-
server.once("close", () => resolve13(port));
|
|
1669
|
-
server.close();
|
|
1670
|
-
});
|
|
1671
|
-
server.on(
|
|
1672
|
-
"error",
|
|
1673
|
-
() => resolve13(findOpenPortRecursive(port + 1, startPort, endPort))
|
|
1674
|
-
);
|
|
1675
|
-
});
|
|
1676
|
-
}
|
|
1677
|
-
|
|
1678
1702
|
// src/core/runners/createWebExtRunner.ts
|
|
1679
1703
|
function createWebExtRunner() {
|
|
1680
1704
|
let runner;
|
|
@@ -1734,7 +1758,8 @@ var ERROR_LOG_LEVEL = 50;
|
|
|
1734
1758
|
|
|
1735
1759
|
// src/core/server.ts
|
|
1736
1760
|
async function getServerInfo() {
|
|
1737
|
-
const
|
|
1761
|
+
const { default: getPort, portNumbers } = await import("get-port");
|
|
1762
|
+
const port = await getPort({ port: portNumbers(3e3, 3010) });
|
|
1738
1763
|
const hostname = "localhost";
|
|
1739
1764
|
const origin = `http://${hostname}:${port}`;
|
|
1740
1765
|
const serverConfig = {
|
|
@@ -1818,7 +1843,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1818
1843
|
}
|
|
1819
1844
|
|
|
1820
1845
|
// package.json
|
|
1821
|
-
var version2 = "0.2.
|
|
1846
|
+
var version2 = "0.2.4";
|
|
1822
1847
|
|
|
1823
1848
|
// src/core/utils/defineConfig.ts
|
|
1824
1849
|
function defineConfig(config) {
|
|
@@ -1862,11 +1887,11 @@ async function createServer2(config) {
|
|
|
1862
1887
|
if (changes.type === "no-change")
|
|
1863
1888
|
return;
|
|
1864
1889
|
internalConfig.logger.info(
|
|
1865
|
-
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => import_picocolors3.default.dim((0,
|
|
1890
|
+
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => import_picocolors3.default.dim((0, import_node_path6.relative)(internalConfig.root, file))).join(", ")}`
|
|
1866
1891
|
);
|
|
1867
1892
|
const rebuiltNames = changes.rebuildGroups.flat().map((entry) => {
|
|
1868
1893
|
return import_picocolors3.default.cyan(
|
|
1869
|
-
(0,
|
|
1894
|
+
(0, import_node_path6.relative)(internalConfig.outDir, getEntrypointOutputFile(entry, ""))
|
|
1870
1895
|
);
|
|
1871
1896
|
}).join(import_picocolors3.default.dim(", "));
|
|
1872
1897
|
internalConfig = await getLatestInternalConfig();
|