wxt 0.2.0 → 0.2.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/cli.cjs +98 -78
- package/dist/client.d.ts +44 -3
- package/dist/index.cjs +95 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +45 -6
- package/dist/index.js +75 -55
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vite from 'vite';
|
|
2
|
-
import { Manifest } from 'webextension-polyfill';
|
|
2
|
+
import { Manifest, Scripting } from 'webextension-polyfill';
|
|
3
3
|
import { UnimportOptions } from 'unimport';
|
|
4
4
|
|
|
5
5
|
interface InlineConfig {
|
|
@@ -146,7 +146,7 @@ interface WxtDevServer extends vite.ViteDevServer {
|
|
|
146
146
|
*
|
|
147
147
|
* @param contentScript The manifest definition for a content script
|
|
148
148
|
*/
|
|
149
|
-
reloadContentScript: (contentScript:
|
|
149
|
+
reloadContentScript: (contentScript: Omit<Scripting.RegisteredContentScript, 'id'>) => void;
|
|
150
150
|
}
|
|
151
151
|
type TargetBrowser = 'chrome' | 'firefox' | 'safari' | 'edge' | 'opera';
|
|
152
152
|
type TargetManifestVersion = 2 | 3;
|
|
@@ -224,11 +224,50 @@ interface OptionsEntrypoint extends BaseEntrypoint {
|
|
|
224
224
|
type Entrypoint = GenericEntrypoint | BackgroundEntrypoint | ContentScriptEntrypoint | PopupEntrypoint | OptionsEntrypoint;
|
|
225
225
|
type OnContentScriptStopped = (cb: () => void) => void;
|
|
226
226
|
interface ContentScriptDefinition {
|
|
227
|
-
matches:
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
matches: Manifest.ContentScript['matches'];
|
|
228
|
+
/**
|
|
229
|
+
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
230
|
+
* @default "documentIdle"
|
|
231
|
+
*/
|
|
232
|
+
runAt?: Manifest.ContentScript['run_at'];
|
|
233
|
+
/**
|
|
234
|
+
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
235
|
+
* @default false
|
|
236
|
+
*/
|
|
237
|
+
matchAboutBlank?: Manifest.ContentScript['match_about_blank'];
|
|
238
|
+
/**
|
|
239
|
+
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
240
|
+
* @default []
|
|
241
|
+
*/
|
|
242
|
+
excludeMatches?: Manifest.ContentScript['exclude_matches'];
|
|
243
|
+
/**
|
|
244
|
+
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
245
|
+
* @default []
|
|
246
|
+
*/
|
|
247
|
+
includeGlobs?: Manifest.ContentScript['include_globs'];
|
|
248
|
+
/**
|
|
249
|
+
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
250
|
+
* @default []
|
|
251
|
+
*/
|
|
252
|
+
excludeGlobs?: Manifest.ContentScript['exclude_globs'];
|
|
253
|
+
/**
|
|
254
|
+
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
255
|
+
* @default false
|
|
256
|
+
*/
|
|
257
|
+
allFrames?: Manifest.ContentScript['all_frames'];
|
|
258
|
+
/**
|
|
259
|
+
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
260
|
+
* @default false
|
|
261
|
+
*/
|
|
230
262
|
matchOriginAsFallback?: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
265
|
+
* @default "ISOLATED"
|
|
266
|
+
*/
|
|
231
267
|
world?: 'ISOLATED' | 'MAIN';
|
|
268
|
+
/**
|
|
269
|
+
* Main function executed when the content script is loaded.
|
|
270
|
+
*/
|
|
232
271
|
main(): void | Promise<void>;
|
|
233
272
|
}
|
|
234
273
|
interface BackgroundScriptDefintition {
|
|
@@ -314,7 +353,7 @@ interface ExtensionRunnerConfig {
|
|
|
314
353
|
|
|
315
354
|
type EntrypointGroup = Entrypoint | Entrypoint[];
|
|
316
355
|
|
|
317
|
-
var version = "0.2.
|
|
356
|
+
var version = "0.2.2";
|
|
318
357
|
|
|
319
358
|
declare function defineConfig(config: UserConfig): UserConfig;
|
|
320
359
|
|
package/dist/index.js
CHANGED
|
@@ -297,23 +297,6 @@ function tsconfigPaths(config) {
|
|
|
297
297
|
});
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
// src/core/vite-plugins/hmrLogger.ts
|
|
301
|
-
import { relative as relative3 } from "path";
|
|
302
|
-
import pc from "picocolors";
|
|
303
|
-
function hmrLogger(config) {
|
|
304
|
-
return {
|
|
305
|
-
name: "wxt:hmr-logger",
|
|
306
|
-
apply: "serve",
|
|
307
|
-
handleHotUpdate(ctx) {
|
|
308
|
-
if (ctx.file.startsWith(config.srcDir) && !ctx.file.startsWith(config.wxtDir) && !ctx.file.endsWith(".html")) {
|
|
309
|
-
config.logger.info(
|
|
310
|
-
"Hot reload: " + pc.dim(relative3(process.cwd(), ctx.file))
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
300
|
// src/core/utils/createFsCache.ts
|
|
318
301
|
import fs3, { ensureDir as ensureDir2 } from "fs-extra";
|
|
319
302
|
import { dirname as dirname3, resolve as resolve5 } from "path";
|
|
@@ -467,7 +450,6 @@ async function getInternalConfig(config, command) {
|
|
|
467
450
|
);
|
|
468
451
|
finalConfig.vite.plugins.push(devServerGlobals(finalConfig));
|
|
469
452
|
finalConfig.vite.plugins.push(tsconfigPaths(finalConfig));
|
|
470
|
-
finalConfig.vite.plugins.push(hmrLogger(finalConfig));
|
|
471
453
|
finalConfig.vite.define ??= {};
|
|
472
454
|
getGlobals(finalConfig).forEach((global) => {
|
|
473
455
|
finalConfig.vite.define[global.name] = JSON.stringify(global.value);
|
|
@@ -479,7 +461,7 @@ async function resolveManifestConfig(env, manifest) {
|
|
|
479
461
|
}
|
|
480
462
|
|
|
481
463
|
// src/index.ts
|
|
482
|
-
import
|
|
464
|
+
import pc3 from "picocolors";
|
|
483
465
|
import * as vite5 from "vite";
|
|
484
466
|
|
|
485
467
|
// src/core/utils/arrays.ts
|
|
@@ -576,7 +558,7 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
576
558
|
// src/index.ts
|
|
577
559
|
import { Mutex } from "async-mutex";
|
|
578
560
|
import { consola as consola2 } from "consola";
|
|
579
|
-
import { relative as
|
|
561
|
+
import { relative as relative6 } from "node:path";
|
|
580
562
|
|
|
581
563
|
// src/core/build/buildEntrypoints.ts
|
|
582
564
|
import * as vite2 from "vite";
|
|
@@ -710,7 +692,7 @@ async function copyPublicDirectory(config) {
|
|
|
710
692
|
}
|
|
711
693
|
|
|
712
694
|
// src/core/build/findEntrypoints.ts
|
|
713
|
-
import { relative as
|
|
695
|
+
import { relative as relative3, resolve as resolve9 } from "path";
|
|
714
696
|
import fs7 from "fs-extra";
|
|
715
697
|
import picomatch from "picomatch";
|
|
716
698
|
import { parseHTML as parseHTML2 } from "linkedom";
|
|
@@ -821,8 +803,8 @@ ${JSON.stringify(
|
|
|
821
803
|
if (withSameName) {
|
|
822
804
|
throw Error(
|
|
823
805
|
`Multiple entrypoints with the name "${entrypoint.name}" detected, but only one is allowed: ${[
|
|
824
|
-
|
|
825
|
-
|
|
806
|
+
relative3(config.root, withSameName.inputPath),
|
|
807
|
+
relative3(config.root, entrypoint.inputPath)
|
|
826
808
|
].join(", ")}`
|
|
827
809
|
);
|
|
828
810
|
}
|
|
@@ -951,7 +933,7 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
951
933
|
// src/core/build/generateTypesDir.ts
|
|
952
934
|
import { createUnimport as createUnimport3 } from "unimport";
|
|
953
935
|
import fs8 from "fs-extra";
|
|
954
|
-
import { relative as
|
|
936
|
+
import { relative as relative4, resolve as resolve10 } from "path";
|
|
955
937
|
async function generateTypesDir(entrypoints, config) {
|
|
956
938
|
await fs8.ensureDir(config.typesDir);
|
|
957
939
|
const references = [];
|
|
@@ -1018,7 +1000,7 @@ async function writeMainDeclarationFile(references, config) {
|
|
|
1018
1000
|
"// Generated by wxt",
|
|
1019
1001
|
`/// <reference types="vite/client" />`,
|
|
1020
1002
|
...references.map(
|
|
1021
|
-
(ref) => `/// <reference types="./${
|
|
1003
|
+
(ref) => `/// <reference types="./${relative4(dir, ref)}" />`
|
|
1022
1004
|
)
|
|
1023
1005
|
].join("\n") + "\n"
|
|
1024
1006
|
);
|
|
@@ -1045,23 +1027,23 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1045
1027
|
"skipLibCheck": true,
|
|
1046
1028
|
|
|
1047
1029
|
/* Aliases */
|
|
1048
|
-
"baseUrl": "${
|
|
1030
|
+
"baseUrl": "${relative4(dir, config.root)}",
|
|
1049
1031
|
"paths": {
|
|
1050
1032
|
"@@": ["."],
|
|
1051
1033
|
"@@/*": ["./*"],
|
|
1052
1034
|
"~~": ["."],
|
|
1053
1035
|
"~~/*": ["./*"],
|
|
1054
|
-
"@": ["${
|
|
1055
|
-
"@/*": ["${
|
|
1056
|
-
"~": ["${
|
|
1057
|
-
"~/*": ["${
|
|
1036
|
+
"@": ["${relative4(config.root, config.srcDir)}"],
|
|
1037
|
+
"@/*": ["${relative4(config.root, config.srcDir)}/*"],
|
|
1038
|
+
"~": ["${relative4(config.root, config.srcDir)}"],
|
|
1039
|
+
"~/*": ["${relative4(config.root, config.srcDir)}/*"]
|
|
1058
1040
|
}
|
|
1059
1041
|
},
|
|
1060
1042
|
"include": [
|
|
1061
|
-
"${
|
|
1062
|
-
"./${
|
|
1043
|
+
"${relative4(dir, config.root)}/**/*",
|
|
1044
|
+
"./${relative4(dir, mainReference)}"
|
|
1063
1045
|
],
|
|
1064
|
-
"exclude": ["${
|
|
1046
|
+
"exclude": ["${relative4(dir, config.outBaseDir)}"]
|
|
1065
1047
|
}`
|
|
1066
1048
|
);
|
|
1067
1049
|
}
|
|
@@ -1113,6 +1095,44 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
|
1113
1095
|
}
|
|
1114
1096
|
};
|
|
1115
1097
|
|
|
1098
|
+
// src/core/utils/content-scripts.ts
|
|
1099
|
+
function hashContentScriptOptions(options) {
|
|
1100
|
+
const withDefaults = {
|
|
1101
|
+
excludeGlobs: [],
|
|
1102
|
+
excludeMatches: [],
|
|
1103
|
+
includeGlobs: [],
|
|
1104
|
+
matchAboutBlank: false,
|
|
1105
|
+
matchOriginAsFallback: false,
|
|
1106
|
+
runAt: "document_idle",
|
|
1107
|
+
allFrames: false,
|
|
1108
|
+
world: "ISOLATED",
|
|
1109
|
+
// TODO: strip undefined fields from options object to improve content script grouping.
|
|
1110
|
+
...options
|
|
1111
|
+
};
|
|
1112
|
+
return JSON.stringify(
|
|
1113
|
+
Object.entries(withDefaults).map(([key, value]) => {
|
|
1114
|
+
if (Array.isArray(value))
|
|
1115
|
+
return [key, value.sort()];
|
|
1116
|
+
else
|
|
1117
|
+
return [key, value];
|
|
1118
|
+
}).sort((l, r) => l[0].localeCompare(r[0]))
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
function mapWxtOptionsToContentScript(options) {
|
|
1122
|
+
return {
|
|
1123
|
+
matches: options.matches,
|
|
1124
|
+
all_frames: options.allFrames,
|
|
1125
|
+
match_about_blank: options.matchAboutBlank,
|
|
1126
|
+
exclude_globs: options.excludeGlobs,
|
|
1127
|
+
exclude_matches: options.excludeMatches,
|
|
1128
|
+
include_globs: options.includeGlobs,
|
|
1129
|
+
run_at: options.runAt,
|
|
1130
|
+
// @ts-expect-error: untyped chrome options
|
|
1131
|
+
match_origin_as_fallback: options.matchOriginAsFallback,
|
|
1132
|
+
world: options.world
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1116
1136
|
// src/core/utils/manifest.ts
|
|
1117
1137
|
async function writeManifest(manifest, output, config) {
|
|
1118
1138
|
const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
@@ -1315,7 +1335,7 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
1315
1335
|
);
|
|
1316
1336
|
} else {
|
|
1317
1337
|
const hashToEntrypointsMap = contentScripts.reduce((map, script) => {
|
|
1318
|
-
const hash =
|
|
1338
|
+
const hash = hashContentScriptOptions(script.options);
|
|
1319
1339
|
if (map.has(hash))
|
|
1320
1340
|
map.get(hash)?.push(script);
|
|
1321
1341
|
else
|
|
@@ -1324,7 +1344,7 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
1324
1344
|
}, /* @__PURE__ */ new Map());
|
|
1325
1345
|
manifest.content_scripts = Array.from(hashToEntrypointsMap.entries()).map(
|
|
1326
1346
|
([, scripts]) => ({
|
|
1327
|
-
...scripts[0].options,
|
|
1347
|
+
...mapWxtOptionsToContentScript(scripts[0].options),
|
|
1328
1348
|
// TOOD: Sorting css and js arrays here so we get consistent test results... but we
|
|
1329
1349
|
// shouldn't have to. Where is the inconsistency coming from?
|
|
1330
1350
|
css: getContentScriptCssFiles(scripts, buildOutput)?.sort(),
|
|
@@ -1393,7 +1413,7 @@ function addHostPermission(manifest, hostPermission) {
|
|
|
1393
1413
|
}
|
|
1394
1414
|
|
|
1395
1415
|
// src/core/build.ts
|
|
1396
|
-
import
|
|
1416
|
+
import pc2 from "picocolors";
|
|
1397
1417
|
import * as vite3 from "vite";
|
|
1398
1418
|
import fs11 from "fs-extra";
|
|
1399
1419
|
|
|
@@ -1443,7 +1463,7 @@ function formatDuration(duration) {
|
|
|
1443
1463
|
}
|
|
1444
1464
|
|
|
1445
1465
|
// src/core/log/printBuildSummary.ts
|
|
1446
|
-
import path4, { relative as
|
|
1466
|
+
import path4, { relative as relative5, resolve as resolve12 } from "path";
|
|
1447
1467
|
|
|
1448
1468
|
// src/core/log/printTable.ts
|
|
1449
1469
|
function printTable(log, rows, gap = 2) {
|
|
@@ -1472,7 +1492,7 @@ function printTable(log, rows, gap = 2) {
|
|
|
1472
1492
|
}
|
|
1473
1493
|
|
|
1474
1494
|
// src/core/log/printBuildSummary.ts
|
|
1475
|
-
import
|
|
1495
|
+
import pc from "picocolors";
|
|
1476
1496
|
import fs10 from "fs-extra";
|
|
1477
1497
|
import { filesize } from "filesize";
|
|
1478
1498
|
async function printBuildSummary(output, config) {
|
|
@@ -1491,7 +1511,7 @@ async function printBuildSummary(output, config) {
|
|
|
1491
1511
|
const chunkRows = await Promise.all(
|
|
1492
1512
|
chunks.map(async (chunk, i) => {
|
|
1493
1513
|
const file = [
|
|
1494
|
-
|
|
1514
|
+
relative5(process.cwd(), config.outDir) + path4.sep,
|
|
1495
1515
|
chunk.fileName
|
|
1496
1516
|
];
|
|
1497
1517
|
const prefix = i === chunks.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
@@ -1500,14 +1520,14 @@ async function printBuildSummary(output, config) {
|
|
|
1500
1520
|
totalSize += stats.size;
|
|
1501
1521
|
const size = String(filesize(stats.size));
|
|
1502
1522
|
return [
|
|
1503
|
-
`${
|
|
1504
|
-
|
|
1523
|
+
`${pc.gray(prefix)} ${pc.dim(file[0])}${color(file[1])}`,
|
|
1524
|
+
pc.dim(size)
|
|
1505
1525
|
];
|
|
1506
1526
|
})
|
|
1507
1527
|
);
|
|
1508
1528
|
printTable(config.logger.log, chunkRows);
|
|
1509
1529
|
config.logger.log(
|
|
1510
|
-
`${
|
|
1530
|
+
`${pc.cyan("\u03A3 Total size:")} ${String(filesize(totalSize))}`
|
|
1511
1531
|
);
|
|
1512
1532
|
}
|
|
1513
1533
|
var DEFAULT_SORT_WEIGHT = 100;
|
|
@@ -1523,12 +1543,12 @@ function getChunkSortWeight(filename) {
|
|
|
1523
1543
|
([key]) => filename.endsWith(key)
|
|
1524
1544
|
)?.[1] ?? DEFAULT_SORT_WEIGHT;
|
|
1525
1545
|
}
|
|
1526
|
-
var DEFAULT_COLOR =
|
|
1546
|
+
var DEFAULT_COLOR = pc.blue;
|
|
1527
1547
|
var CHUNK_COLORS = {
|
|
1528
|
-
".js.map":
|
|
1529
|
-
".html":
|
|
1530
|
-
".css":
|
|
1531
|
-
".js":
|
|
1548
|
+
".js.map": pc.gray,
|
|
1549
|
+
".html": pc.green,
|
|
1550
|
+
".css": pc.magenta,
|
|
1551
|
+
".js": pc.cyan
|
|
1532
1552
|
};
|
|
1533
1553
|
function getChunkColor(filename) {
|
|
1534
1554
|
return Object.entries(CHUNK_COLORS).find(([key]) => filename.endsWith(key))?.[1] ?? DEFAULT_COLOR;
|
|
@@ -1539,7 +1559,7 @@ async function buildInternal(config) {
|
|
|
1539
1559
|
const verb = config.command === "serve" ? "Pre-rendering" : "Building";
|
|
1540
1560
|
const target = `${config.browser}-mv${config.manifestVersion}`;
|
|
1541
1561
|
config.logger.info(
|
|
1542
|
-
`${verb} ${
|
|
1562
|
+
`${verb} ${pc2.cyan(target)} for ${pc2.cyan(config.mode)} with ${pc2.green(
|
|
1543
1563
|
`Vite ${vite3.version}`
|
|
1544
1564
|
)}`
|
|
1545
1565
|
);
|
|
@@ -1741,9 +1761,9 @@ function reloadContentScripts(steps, config, server) {
|
|
|
1741
1761
|
const js = [getEntrypointBundlePath(entry, config.outDir, ".js")];
|
|
1742
1762
|
const css = getContentScriptCssFiles([entry], server.currentOutput);
|
|
1743
1763
|
server.reloadContentScript({
|
|
1764
|
+
...entry.options,
|
|
1744
1765
|
js,
|
|
1745
|
-
css
|
|
1746
|
-
...entry.options
|
|
1766
|
+
css
|
|
1747
1767
|
});
|
|
1748
1768
|
});
|
|
1749
1769
|
} else {
|
|
@@ -1758,7 +1778,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1758
1778
|
}
|
|
1759
1779
|
|
|
1760
1780
|
// package.json
|
|
1761
|
-
var version2 = "0.2.
|
|
1781
|
+
var version2 = "0.2.2";
|
|
1762
1782
|
|
|
1763
1783
|
// src/core/utils/defineConfig.ts
|
|
1764
1784
|
function defineConfig(config) {
|
|
@@ -1802,13 +1822,13 @@ async function createServer2(config) {
|
|
|
1802
1822
|
if (changes.type === "no-change")
|
|
1803
1823
|
return;
|
|
1804
1824
|
internalConfig.logger.info(
|
|
1805
|
-
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) =>
|
|
1825
|
+
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => pc3.dim(relative6(internalConfig.root, file))).join(", ")}`
|
|
1806
1826
|
);
|
|
1807
1827
|
const rebuiltNames = changes.rebuildGroups.flat().map((entry) => {
|
|
1808
|
-
return
|
|
1809
|
-
|
|
1828
|
+
return pc3.cyan(
|
|
1829
|
+
relative6(internalConfig.outDir, getEntrypointOutputFile(entry, ""))
|
|
1810
1830
|
);
|
|
1811
|
-
}).join(
|
|
1831
|
+
}).join(pc3.dim(", "));
|
|
1812
1832
|
internalConfig = await getLatestInternalConfig();
|
|
1813
1833
|
internalConfig.server = server;
|
|
1814
1834
|
const { output: newOutput } = await rebuild(
|