wxt 0.2.3 → 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 +159 -59
- package/dist/index.cjs +90 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +52 -1
- package/dist/index.js +91 -59
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -91,6 +91,57 @@ interface InlineConfig {
|
|
|
91
91
|
* Custom runner options. Options set here can be overridden in a `web-ext.config.ts` file.
|
|
92
92
|
*/
|
|
93
93
|
runner?: ExtensionRunnerConfig;
|
|
94
|
+
zip?: {
|
|
95
|
+
/**
|
|
96
|
+
* Configure the filename output when zipping files.
|
|
97
|
+
*
|
|
98
|
+
* Available template variables:
|
|
99
|
+
*
|
|
100
|
+
* - `{{name}}` - The project's name converted to kebab-case
|
|
101
|
+
* - `{{version}} - The version_name or version from the manifest
|
|
102
|
+
* - `{{browser}} - The target browser from the `--browser` CLI flag
|
|
103
|
+
* - `{{manifestVersion}}` - Either "2" or "3"
|
|
104
|
+
*
|
|
105
|
+
* @default "{{name}}-{{version}}-{{browser}}.zip"
|
|
106
|
+
*/
|
|
107
|
+
artifactTemplate?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Configure the filename output when zipping files.
|
|
110
|
+
*
|
|
111
|
+
* Available template variables:
|
|
112
|
+
*
|
|
113
|
+
* - `{{name}}` - The project's name converted to kebab-case
|
|
114
|
+
* - `{{version}} - The version_name or version from the manifest
|
|
115
|
+
* - `{{browser}} - The target browser from the `--browser` CLI flag
|
|
116
|
+
* - `{{manifestVersion}}` - Either "2" or "3"
|
|
117
|
+
*
|
|
118
|
+
* @default "{{name}}-{{version}}-sources.zip"
|
|
119
|
+
*/
|
|
120
|
+
sourcesTemplate?: string;
|
|
121
|
+
/**
|
|
122
|
+
* Override the artifactTemplate's `{{name}}` template variable. Defaults to the package.json's
|
|
123
|
+
* name, or if that doesn't exist, the current working directories name.
|
|
124
|
+
*/
|
|
125
|
+
name?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Root directory to ZIP. The ZIP can be uploaded to the Firefox Addon Store as your source
|
|
128
|
+
* code. Defaults to the `config.root` directory.
|
|
129
|
+
*/
|
|
130
|
+
sourcesRoot?: string;
|
|
131
|
+
/**
|
|
132
|
+
* [Minimatch](https://www.npmjs.com/package/minimatch) patterns of files to exclude when
|
|
133
|
+
* creating a ZIP of all your source code for Firfox. Patterns are relative to your
|
|
134
|
+
* `config.zip.sourcesRoot`.
|
|
135
|
+
*
|
|
136
|
+
* Hidden files, node_modules, and tests are ignored by default.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* [
|
|
140
|
+
* "coverage", // Ignore the coverage directory in the `sourcesRoot`
|
|
141
|
+
* ]
|
|
142
|
+
*/
|
|
143
|
+
ignoredSources?: string[];
|
|
144
|
+
};
|
|
94
145
|
}
|
|
95
146
|
interface WxtInlineViteConfig extends Omit<vite.InlineConfig, 'root' | 'configFile' | 'mode' | 'build'> {
|
|
96
147
|
build?: Omit<vite.BuildOptions, 'outDir'>;
|
|
@@ -353,7 +404,7 @@ interface ExtensionRunnerConfig {
|
|
|
353
404
|
|
|
354
405
|
type EntrypointGroup = Entrypoint | Entrypoint[];
|
|
355
406
|
|
|
356
|
-
var version = "0.2.
|
|
407
|
+
var version = "0.2.4";
|
|
357
408
|
|
|
358
409
|
declare function defineConfig(config: UserConfig): UserConfig;
|
|
359
410
|
|
package/dist/index.js
CHANGED
|
@@ -430,7 +430,27 @@ async function getInternalConfig(config, command) {
|
|
|
430
430
|
wxtDir,
|
|
431
431
|
typesDir,
|
|
432
432
|
fsCache: createFsCache(wxtDir),
|
|
433
|
-
manifest
|
|
433
|
+
manifest,
|
|
434
|
+
zip: {
|
|
435
|
+
sourcesTemplate: "{{name}}-{{version}}-sources.zip",
|
|
436
|
+
artifactTemplate: "{{name}}-{{version}}-{{browser}}.zip",
|
|
437
|
+
sourcesRoot: root,
|
|
438
|
+
...userConfig.zip,
|
|
439
|
+
...config.zip,
|
|
440
|
+
ignoredSources: [
|
|
441
|
+
"**/node_modules",
|
|
442
|
+
// WXT files
|
|
443
|
+
"**/web-ext.config.ts",
|
|
444
|
+
// Hidden files
|
|
445
|
+
"**/.*",
|
|
446
|
+
// Tests
|
|
447
|
+
"**/__tests__/**",
|
|
448
|
+
"**/*.+(test|spec).?(c|m)+(j|t)s?(x)",
|
|
449
|
+
// User config
|
|
450
|
+
...userConfig.zip?.ignoredSources ?? [],
|
|
451
|
+
...config.zip?.ignoredSources ?? []
|
|
452
|
+
]
|
|
453
|
+
}
|
|
434
454
|
};
|
|
435
455
|
finalConfig.vite.root = root;
|
|
436
456
|
finalConfig.vite.configFile = false;
|
|
@@ -558,7 +578,7 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
558
578
|
// src/index.ts
|
|
559
579
|
import { Mutex } from "async-mutex";
|
|
560
580
|
import { consola as consola2 } from "consola";
|
|
561
|
-
import { relative as
|
|
581
|
+
import { relative as relative5 } from "node:path";
|
|
562
582
|
|
|
563
583
|
// src/core/build/buildEntrypoints.ts
|
|
564
584
|
import * as vite2 from "vite";
|
|
@@ -1049,8 +1069,8 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1049
1069
|
}
|
|
1050
1070
|
|
|
1051
1071
|
// src/core/utils/manifest.ts
|
|
1052
|
-
import
|
|
1053
|
-
import { resolve as
|
|
1072
|
+
import fs10 from "fs-extra";
|
|
1073
|
+
import { resolve as resolve12 } from "path";
|
|
1054
1074
|
|
|
1055
1075
|
// src/core/utils/ContentSecurityPolicy.ts
|
|
1056
1076
|
var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
@@ -1133,11 +1153,26 @@ function mapWxtOptionsToContentScript(options) {
|
|
|
1133
1153
|
};
|
|
1134
1154
|
}
|
|
1135
1155
|
|
|
1156
|
+
// src/core/utils/package.ts
|
|
1157
|
+
import { resolve as resolve11 } from "node:path";
|
|
1158
|
+
import fs9 from "fs-extra";
|
|
1159
|
+
async function getPackageJson(config) {
|
|
1160
|
+
const file = resolve11(config.root, "package.json");
|
|
1161
|
+
try {
|
|
1162
|
+
return await fs9.readJson(file);
|
|
1163
|
+
} catch (err) {
|
|
1164
|
+
config.logger.debug(
|
|
1165
|
+
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
1166
|
+
);
|
|
1167
|
+
return {};
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1136
1171
|
// src/core/utils/manifest.ts
|
|
1137
1172
|
async function writeManifest(manifest, output, config) {
|
|
1138
1173
|
const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
1139
|
-
await
|
|
1140
|
-
await
|
|
1174
|
+
await fs10.ensureDir(config.outDir);
|
|
1175
|
+
await fs10.writeFile(resolve12(config.outDir, "manifest.json"), str, "utf-8");
|
|
1141
1176
|
output.publicAssets.unshift({
|
|
1142
1177
|
type: "asset",
|
|
1143
1178
|
fileName: "manifest.json",
|
|
@@ -1176,17 +1211,6 @@ async function generateMainfest(entrypoints, buildOutput, config) {
|
|
|
1176
1211
|
}
|
|
1177
1212
|
return manifest;
|
|
1178
1213
|
}
|
|
1179
|
-
async function getPackageJson(config) {
|
|
1180
|
-
const file = resolve11(config.root, "package.json");
|
|
1181
|
-
try {
|
|
1182
|
-
return await fs9.readJson(file);
|
|
1183
|
-
} catch (err) {
|
|
1184
|
-
config.logger.debug(
|
|
1185
|
-
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
1186
|
-
);
|
|
1187
|
-
return {};
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
1214
|
function simplifyVersion(versionName) {
|
|
1191
1215
|
const version3 = /^((0|[1-9][0-9]{0,8})([.](0|[1-9][0-9]{0,8})){0,3}).*$/.exec(
|
|
1192
1216
|
versionName
|
|
@@ -1430,7 +1454,7 @@ function addHostPermission(manifest, hostPermission) {
|
|
|
1430
1454
|
// src/core/build.ts
|
|
1431
1455
|
import pc2 from "picocolors";
|
|
1432
1456
|
import * as vite3 from "vite";
|
|
1433
|
-
import
|
|
1457
|
+
import fs12 from "fs-extra";
|
|
1434
1458
|
|
|
1435
1459
|
// src/core/utils/groupEntrypoints.ts
|
|
1436
1460
|
function groupEntrypoints(entrypoints) {
|
|
@@ -1478,7 +1502,13 @@ function formatDuration(duration) {
|
|
|
1478
1502
|
}
|
|
1479
1503
|
|
|
1480
1504
|
// src/core/log/printBuildSummary.ts
|
|
1481
|
-
import
|
|
1505
|
+
import { resolve as resolve13 } from "path";
|
|
1506
|
+
|
|
1507
|
+
// src/core/log/printFileList.ts
|
|
1508
|
+
import path4 from "node:path";
|
|
1509
|
+
import pc from "picocolors";
|
|
1510
|
+
import fs11 from "fs-extra";
|
|
1511
|
+
import { filesize } from "filesize";
|
|
1482
1512
|
|
|
1483
1513
|
// src/core/log/printTable.ts
|
|
1484
1514
|
function printTable(log, rows, gap = 2) {
|
|
@@ -1506,10 +1536,42 @@ function printTable(log, rows, gap = 2) {
|
|
|
1506
1536
|
log(str);
|
|
1507
1537
|
}
|
|
1508
1538
|
|
|
1539
|
+
// src/core/log/printFileList.ts
|
|
1540
|
+
async function printFileList(log, baseDir, files) {
|
|
1541
|
+
let totalSize = 0;
|
|
1542
|
+
const fileRows = await Promise.all(
|
|
1543
|
+
files.map(async (file, i) => {
|
|
1544
|
+
const parts = [
|
|
1545
|
+
path4.relative(process.cwd(), baseDir) + path4.sep,
|
|
1546
|
+
path4.relative(baseDir, file)
|
|
1547
|
+
];
|
|
1548
|
+
const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1549
|
+
const color = getChunkColor(file);
|
|
1550
|
+
const stats = await fs11.lstat(file);
|
|
1551
|
+
totalSize += stats.size;
|
|
1552
|
+
const size = String(filesize(stats.size));
|
|
1553
|
+
return [
|
|
1554
|
+
`${pc.gray(prefix)} ${pc.dim(parts[0])}${color(parts[1])}`,
|
|
1555
|
+
pc.dim(size)
|
|
1556
|
+
];
|
|
1557
|
+
})
|
|
1558
|
+
);
|
|
1559
|
+
printTable(log, fileRows);
|
|
1560
|
+
log(`${pc.cyan("\u03A3 Total size:")} ${String(filesize(totalSize))}`);
|
|
1561
|
+
}
|
|
1562
|
+
var DEFAULT_COLOR = pc.blue;
|
|
1563
|
+
var CHUNK_COLORS = {
|
|
1564
|
+
".js.map": pc.gray,
|
|
1565
|
+
".html": pc.green,
|
|
1566
|
+
".css": pc.magenta,
|
|
1567
|
+
".js": pc.cyan,
|
|
1568
|
+
".zip": pc.yellow
|
|
1569
|
+
};
|
|
1570
|
+
function getChunkColor(filename) {
|
|
1571
|
+
return Object.entries(CHUNK_COLORS).find(([key]) => filename.endsWith(key))?.[1] ?? DEFAULT_COLOR;
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1509
1574
|
// src/core/log/printBuildSummary.ts
|
|
1510
|
-
import pc from "picocolors";
|
|
1511
|
-
import fs10 from "fs-extra";
|
|
1512
|
-
import { filesize } from "filesize";
|
|
1513
1575
|
async function printBuildSummary(output, config) {
|
|
1514
1576
|
const chunks = [
|
|
1515
1577
|
...output.steps.flatMap((step) => step.chunks),
|
|
@@ -1522,28 +1584,8 @@ async function printBuildSummary(output, config) {
|
|
|
1522
1584
|
return diff;
|
|
1523
1585
|
return l.fileName.localeCompare(r.fileName);
|
|
1524
1586
|
});
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
chunks.map(async (chunk, i) => {
|
|
1528
|
-
const file = [
|
|
1529
|
-
relative5(process.cwd(), config.outDir) + path4.sep,
|
|
1530
|
-
chunk.fileName
|
|
1531
|
-
];
|
|
1532
|
-
const prefix = i === chunks.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1533
|
-
const color = getChunkColor(chunk.fileName);
|
|
1534
|
-
const stats = await fs10.lstat(resolve12(config.outDir, chunk.fileName));
|
|
1535
|
-
totalSize += stats.size;
|
|
1536
|
-
const size = String(filesize(stats.size));
|
|
1537
|
-
return [
|
|
1538
|
-
`${pc.gray(prefix)} ${pc.dim(file[0])}${color(file[1])}`,
|
|
1539
|
-
pc.dim(size)
|
|
1540
|
-
];
|
|
1541
|
-
})
|
|
1542
|
-
);
|
|
1543
|
-
printTable(config.logger.log, chunkRows);
|
|
1544
|
-
config.logger.log(
|
|
1545
|
-
`${pc.cyan("\u03A3 Total size:")} ${String(filesize(totalSize))}`
|
|
1546
|
-
);
|
|
1587
|
+
const files = chunks.map((chunk) => resolve13(config.outDir, chunk.fileName));
|
|
1588
|
+
await printFileList(config.logger.log, config.outDir, files);
|
|
1547
1589
|
}
|
|
1548
1590
|
var DEFAULT_SORT_WEIGHT = 100;
|
|
1549
1591
|
var CHUNK_SORT_WEIGHTS = {
|
|
@@ -1558,16 +1600,6 @@ function getChunkSortWeight(filename) {
|
|
|
1558
1600
|
([key]) => filename.endsWith(key)
|
|
1559
1601
|
)?.[1] ?? DEFAULT_SORT_WEIGHT;
|
|
1560
1602
|
}
|
|
1561
|
-
var DEFAULT_COLOR = pc.blue;
|
|
1562
|
-
var CHUNK_COLORS = {
|
|
1563
|
-
".js.map": pc.gray,
|
|
1564
|
-
".html": pc.green,
|
|
1565
|
-
".css": pc.magenta,
|
|
1566
|
-
".js": pc.cyan
|
|
1567
|
-
};
|
|
1568
|
-
function getChunkColor(filename) {
|
|
1569
|
-
return Object.entries(CHUNK_COLORS).find(([key]) => filename.endsWith(key))?.[1] ?? DEFAULT_COLOR;
|
|
1570
|
-
}
|
|
1571
1603
|
|
|
1572
1604
|
// src/core/build.ts
|
|
1573
1605
|
async function buildInternal(config) {
|
|
@@ -1579,8 +1611,8 @@ async function buildInternal(config) {
|
|
|
1579
1611
|
)}`
|
|
1580
1612
|
);
|
|
1581
1613
|
const startTime = Date.now();
|
|
1582
|
-
await
|
|
1583
|
-
await
|
|
1614
|
+
await fs12.rm(config.outDir, { recursive: true, force: true });
|
|
1615
|
+
await fs12.ensureDir(config.outDir);
|
|
1584
1616
|
const entrypoints = await findEntrypoints(config);
|
|
1585
1617
|
const groups = groupEntrypoints(entrypoints);
|
|
1586
1618
|
const { output } = await rebuild(config, groups);
|
|
@@ -1771,7 +1803,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1771
1803
|
}
|
|
1772
1804
|
|
|
1773
1805
|
// package.json
|
|
1774
|
-
var version2 = "0.2.
|
|
1806
|
+
var version2 = "0.2.4";
|
|
1775
1807
|
|
|
1776
1808
|
// src/core/utils/defineConfig.ts
|
|
1777
1809
|
function defineConfig(config) {
|
|
@@ -1815,11 +1847,11 @@ async function createServer2(config) {
|
|
|
1815
1847
|
if (changes.type === "no-change")
|
|
1816
1848
|
return;
|
|
1817
1849
|
internalConfig.logger.info(
|
|
1818
|
-
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => pc3.dim(
|
|
1850
|
+
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => pc3.dim(relative5(internalConfig.root, file))).join(", ")}`
|
|
1819
1851
|
);
|
|
1820
1852
|
const rebuiltNames = changes.rebuildGroups.flat().map((entry) => {
|
|
1821
1853
|
return pc3.cyan(
|
|
1822
|
-
|
|
1854
|
+
relative5(internalConfig.outDir, getEntrypointOutputFile(entry, ""))
|
|
1823
1855
|
);
|
|
1824
1856
|
}).join(pc3.dim(", "));
|
|
1825
1857
|
internalConfig = await getLatestInternalConfig();
|