wxt 0.18.6 → 0.18.7
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/{chunk-QOYT5J6A.js → chunk-A3R6ZPUA.js} +99 -170
- package/dist/{chunk-5X3S6AWF.js → chunk-BERPNPEZ.js} +2 -4
- package/dist/{chunk-ZZCTFNQ5.js → chunk-BM6QYGAW.js} +1 -1
- package/dist/{chunk-NAMV4VWQ.js → chunk-KPD5J7PZ.js} +1 -1
- package/dist/{chunk-VBXJIVYU.js → chunk-QGM4M3NI.js} +1 -2
- package/dist/{chunk-73I7FAJU.js → chunk-SGKCDMVR.js} +1 -2
- package/dist/cli.js +120 -208
- package/dist/client.js +12 -24
- package/dist/{execa-QQUOQNS3.js → execa-ATHZH2Y4.js} +1576 -610
- package/dist/{execa-5TSWMF32.js → execa-D7CMCKO2.js} +1576 -610
- package/dist/index.cjs +2144 -1149
- package/dist/index.js +23 -38
- package/dist/modules.cjs +3 -6
- package/dist/modules.js +4 -7
- package/dist/{prompt-Y7B5HSD5.js → prompt-25QIVJDC.js} +28 -55
- package/dist/{prompt-TFJ7OLL7.js → prompt-7BMKNSWS.js} +28 -55
- package/dist/sandbox.js +2 -4
- package/dist/storage.cjs +4 -8
- package/dist/storage.js +6 -10
- package/dist/testing.cjs +35 -69
- package/dist/testing.js +4 -4
- package/dist/virtual/background-entrypoint.js +3 -6
- package/dist/virtual/content-script-isolated-world-entrypoint.js +1 -2
- package/dist/virtual/content-script-main-world-entrypoint.js +1 -2
- package/dist/virtual/reload-html.js +1 -2
- package/dist/virtual/unlisted-script-entrypoint.js +1 -2
- package/package.json +33 -32
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
every,
|
|
3
3
|
some,
|
|
4
4
|
toArray
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-BERPNPEZ.js";
|
|
6
6
|
import {
|
|
7
7
|
LogLevels,
|
|
8
8
|
consola
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-BM6QYGAW.js";
|
|
10
10
|
import {
|
|
11
11
|
__require
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-QGM4M3NI.js";
|
|
13
13
|
|
|
14
14
|
// package.json
|
|
15
15
|
var version = "0.18.6";
|
|
@@ -60,12 +60,9 @@ function isHtmlEntrypoint(entrypoint) {
|
|
|
60
60
|
|
|
61
61
|
// src/core/utils/time.ts
|
|
62
62
|
function formatDuration(duration) {
|
|
63
|
-
if (duration < 1e3)
|
|
64
|
-
|
|
65
|
-
if (duration <
|
|
66
|
-
return `${(duration / 1e3).toFixed(3)} s`;
|
|
67
|
-
if (duration < 6e4)
|
|
68
|
-
return `${(duration / 1e3).toFixed(1)} s`;
|
|
63
|
+
if (duration < 1e3) return `${duration} ms`;
|
|
64
|
+
if (duration < 1e4) return `${(duration / 1e3).toFixed(3)} s`;
|
|
65
|
+
if (duration < 6e4) return `${(duration / 1e3).toFixed(1)} s`;
|
|
69
66
|
return `${(duration / 1e3).toFixed(0)} s`;
|
|
70
67
|
}
|
|
71
68
|
function withTimeout(promise, duration) {
|
|
@@ -108,8 +105,7 @@ async function fetchCached(url, config) {
|
|
|
108
105
|
);
|
|
109
106
|
}
|
|
110
107
|
}
|
|
111
|
-
if (!content)
|
|
112
|
-
content = await config.fsCache.get(url) ?? "";
|
|
108
|
+
if (!content) content = await config.fsCache.get(url) ?? "";
|
|
113
109
|
if (!content)
|
|
114
110
|
throw Error(
|
|
115
111
|
`Offline and "${url}" has not been cached. Try again when online.`
|
|
@@ -122,12 +118,10 @@ function download(config) {
|
|
|
122
118
|
return {
|
|
123
119
|
name: "wxt:download",
|
|
124
120
|
resolveId(id) {
|
|
125
|
-
if (id.startsWith("url:"))
|
|
126
|
-
return "\0" + id;
|
|
121
|
+
if (id.startsWith("url:")) return "\0" + id;
|
|
127
122
|
},
|
|
128
123
|
async load(id) {
|
|
129
|
-
if (!id.startsWith("\0url:"))
|
|
130
|
-
return;
|
|
124
|
+
if (!id.startsWith("\0url:")) return;
|
|
131
125
|
const url = id.replace("\0url:", "");
|
|
132
126
|
return await fetchCached(url, config);
|
|
133
127
|
}
|
|
@@ -147,8 +141,7 @@ var ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
147
141
|
]);
|
|
148
142
|
function unimport(config) {
|
|
149
143
|
const options = config.imports;
|
|
150
|
-
if (options === false)
|
|
151
|
-
return [];
|
|
144
|
+
if (options === false) return [];
|
|
152
145
|
const unimport2 = createUnimport(options);
|
|
153
146
|
return {
|
|
154
147
|
name: "wxt:unimport",
|
|
@@ -156,10 +149,8 @@ function unimport(config) {
|
|
|
156
149
|
await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
|
|
157
150
|
},
|
|
158
151
|
async transform(code, id) {
|
|
159
|
-
if (id.includes("node_modules"))
|
|
160
|
-
|
|
161
|
-
if (!ENABLED_EXTENSIONS.has(extname(id)))
|
|
162
|
-
return;
|
|
152
|
+
if (id.includes("node_modules")) return;
|
|
153
|
+
if (!ENABLED_EXTENSIONS.has(extname(id))) return;
|
|
163
154
|
const injected = await unimport2.injectImports(code, id);
|
|
164
155
|
return {
|
|
165
156
|
code: injected.code,
|
|
@@ -282,15 +273,16 @@ function webextensionPolyfillMock(config) {
|
|
|
282
273
|
// src/core/builders/vite/plugins/devHtmlPrerender.ts
|
|
283
274
|
import { parseHTML } from "linkedom";
|
|
284
275
|
import { dirname, relative as relative2, resolve as resolve2 } from "node:path";
|
|
285
|
-
|
|
276
|
+
import { murmurHash } from "ohash";
|
|
277
|
+
var inlineScriptContents = {};
|
|
286
278
|
function devHtmlPrerender(config, server) {
|
|
287
279
|
const htmlReloadId = "@wxt/reload-html";
|
|
288
280
|
const resolvedHtmlReloadId = resolve2(
|
|
289
281
|
config.wxtModuleDir,
|
|
290
282
|
"dist/virtual/reload-html.js"
|
|
291
283
|
);
|
|
292
|
-
const
|
|
293
|
-
const
|
|
284
|
+
const virtualInlineScript = "virtual:wxt-inline-script";
|
|
285
|
+
const resolvedVirtualInlineScript = "\0" + virtualInlineScript;
|
|
294
286
|
return [
|
|
295
287
|
{
|
|
296
288
|
apply: "build",
|
|
@@ -325,23 +317,22 @@ function devHtmlPrerender(config, server) {
|
|
|
325
317
|
},
|
|
326
318
|
// Pass the HTML through the dev server to add dev-mode specific code
|
|
327
319
|
async transformIndexHtml(html, ctx) {
|
|
328
|
-
if (config.command !== "serve" || server == null)
|
|
329
|
-
return;
|
|
320
|
+
if (config.command !== "serve" || server == null) return;
|
|
330
321
|
const originalUrl = `${server.origin}${ctx.path}`;
|
|
331
322
|
const name = getEntrypointName(config.entrypointsDir, ctx.filename);
|
|
332
323
|
const url = `${server.origin}/${name}.html`;
|
|
333
324
|
const serverHtml = await server.transformHtml(url, html, originalUrl);
|
|
334
325
|
const { document } = parseHTML(serverHtml);
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
326
|
+
const inlineScripts = document.querySelectorAll("script:not([src])");
|
|
327
|
+
inlineScripts.forEach((script) => {
|
|
328
|
+
const textContent = script.textContent ?? "";
|
|
329
|
+
const hash = murmurHash(textContent);
|
|
330
|
+
inlineScriptContents[hash] = textContent;
|
|
340
331
|
const virtualScript = document.createElement("script");
|
|
341
332
|
virtualScript.type = "module";
|
|
342
|
-
virtualScript.src = `${server.origin}/${
|
|
343
|
-
|
|
344
|
-
}
|
|
333
|
+
virtualScript.src = `${server.origin}/@id/${virtualInlineScript}?${hash}`;
|
|
334
|
+
script.replaceWith(virtualScript);
|
|
335
|
+
});
|
|
345
336
|
const viteClientScript = document.querySelector(
|
|
346
337
|
"script[src='/@vite/client']"
|
|
347
338
|
);
|
|
@@ -359,16 +350,17 @@ function devHtmlPrerender(config, server) {
|
|
|
359
350
|
name: "wxt:virtualize-react-refresh",
|
|
360
351
|
apply: "serve",
|
|
361
352
|
resolveId(id) {
|
|
362
|
-
if (id
|
|
363
|
-
return
|
|
353
|
+
if (id.startsWith(virtualInlineScript)) {
|
|
354
|
+
return "\0" + id;
|
|
364
355
|
}
|
|
365
356
|
if (id.startsWith("/chunks/")) {
|
|
366
357
|
return "\0noop";
|
|
367
358
|
}
|
|
368
359
|
},
|
|
369
360
|
load(id) {
|
|
370
|
-
if (id
|
|
371
|
-
|
|
361
|
+
if (id.startsWith(resolvedVirtualInlineScript)) {
|
|
362
|
+
const hash = Number(id.substring(id.indexOf("?") + 1));
|
|
363
|
+
return inlineScriptContents[hash];
|
|
372
364
|
}
|
|
373
365
|
if (id === "\0noop") {
|
|
374
366
|
return "";
|
|
@@ -380,8 +372,7 @@ function devHtmlPrerender(config, server) {
|
|
|
380
372
|
function pointToDevServer(config, server, id, document, querySelector, attr) {
|
|
381
373
|
document.querySelectorAll(querySelector).forEach((element) => {
|
|
382
374
|
const src = element.getAttribute(attr);
|
|
383
|
-
if (!src || isUrl(src))
|
|
384
|
-
return;
|
|
375
|
+
if (!src || isUrl(src)) return;
|
|
385
376
|
let resolvedAbsolutePath;
|
|
386
377
|
const matchingAlias = Object.entries(config.alias).find(
|
|
387
378
|
([key]) => src.startsWith(key)
|
|
@@ -401,8 +392,7 @@ function pointToDevServer(config, server, id, document, querySelector, attr) {
|
|
|
401
392
|
);
|
|
402
393
|
if (relativePath.startsWith(".")) {
|
|
403
394
|
let path8 = normalizePath(resolvedAbsolutePath);
|
|
404
|
-
if (!path8.startsWith("/"))
|
|
405
|
-
path8 = "/" + path8;
|
|
395
|
+
if (!path8.startsWith("/")) path8 = "/" + path8;
|
|
406
396
|
element.setAttribute(attr, `${server.origin}/@fs${path8}`);
|
|
407
397
|
} else {
|
|
408
398
|
const url = new URL(relativePath, server.origin);
|
|
@@ -425,8 +415,7 @@ function devServerGlobals(config, server) {
|
|
|
425
415
|
return {
|
|
426
416
|
name: "wxt:dev-server-globals",
|
|
427
417
|
config() {
|
|
428
|
-
if (server == null || config.command == "build")
|
|
429
|
-
return;
|
|
418
|
+
if (server == null || config.command == "build") return;
|
|
430
419
|
return {
|
|
431
420
|
define: {
|
|
432
421
|
__DEV_SERVER_PROTOCOL__: JSON.stringify("ws:"),
|
|
@@ -524,14 +513,12 @@ function resolveVirtualModules(config) {
|
|
|
524
513
|
name: `wxt:resolve-virtual-${name}`,
|
|
525
514
|
resolveId(id) {
|
|
526
515
|
const index = id.indexOf(virtualId);
|
|
527
|
-
if (index === -1)
|
|
528
|
-
return;
|
|
516
|
+
if (index === -1) return;
|
|
529
517
|
const inputPath = normalizePath(id.substring(index + virtualId.length));
|
|
530
518
|
return resolvedVirtualId + inputPath;
|
|
531
519
|
},
|
|
532
520
|
async load(id) {
|
|
533
|
-
if (!id.startsWith(resolvedVirtualId))
|
|
534
|
-
return;
|
|
521
|
+
if (!id.startsWith(resolvedVirtualId)) return;
|
|
535
522
|
const inputPath = id.replace(resolvedVirtualId, "");
|
|
536
523
|
const template = await fs2.readFile(
|
|
537
524
|
resolve4(config.wxtModuleDir, `dist/virtual/${name}.js`),
|
|
@@ -553,8 +540,7 @@ function noopBackground() {
|
|
|
553
540
|
return {
|
|
554
541
|
name: "wxt:noop-background",
|
|
555
542
|
resolveId(id) {
|
|
556
|
-
if (id === virtualModuleId)
|
|
557
|
-
return resolvedVirtualModuleId;
|
|
543
|
+
if (id === virtualModuleId) return resolvedVirtualModuleId;
|
|
558
544
|
},
|
|
559
545
|
load(id) {
|
|
560
546
|
if (id === resolvedVirtualModuleId) {
|
|
@@ -582,8 +568,7 @@ function cssEntrypoints(entrypoint, config) {
|
|
|
582
568
|
},
|
|
583
569
|
generateBundle(_, bundle) {
|
|
584
570
|
Object.keys(bundle).forEach((file) => {
|
|
585
|
-
if (file.endsWith(".js"))
|
|
586
|
-
delete bundle[file];
|
|
571
|
+
if (file.endsWith(".js")) delete bundle[file];
|
|
587
572
|
});
|
|
588
573
|
}
|
|
589
574
|
};
|
|
@@ -609,8 +594,7 @@ function excludeBrowserPolyfill(config) {
|
|
|
609
594
|
return {
|
|
610
595
|
name: "wxt:exclude-browser-polyfill",
|
|
611
596
|
config() {
|
|
612
|
-
if (config.experimental.includeBrowserPolyfill)
|
|
613
|
-
return;
|
|
597
|
+
if (config.experimental.includeBrowserPolyfill) return;
|
|
614
598
|
return {
|
|
615
599
|
resolve: {
|
|
616
600
|
alias: {
|
|
@@ -685,8 +669,7 @@ function removeEntrypointMainFunction(config, path8) {
|
|
|
685
669
|
return {
|
|
686
670
|
name: "wxt:remove-entrypoint-main-function",
|
|
687
671
|
transform(code, id) {
|
|
688
|
-
if (id === absPath)
|
|
689
|
-
return removeMainFunctionCode(code);
|
|
672
|
+
if (id === absPath) return removeMainFunctionCode(code);
|
|
690
673
|
}
|
|
691
674
|
};
|
|
692
675
|
}
|
|
@@ -701,10 +684,8 @@ function wxtPluginLoader(config) {
|
|
|
701
684
|
return {
|
|
702
685
|
name: "wxt:plugin-loader",
|
|
703
686
|
resolveId(id) {
|
|
704
|
-
if (id === virtualModuleId)
|
|
705
|
-
|
|
706
|
-
if (id === virtualHtmlModuleId)
|
|
707
|
-
return resolvedVirtualHtmlModuleId;
|
|
687
|
+
if (id === virtualModuleId) return resolvedVirtualModuleId;
|
|
688
|
+
if (id === virtualHtmlModuleId) return resolvedVirtualHtmlModuleId;
|
|
708
689
|
},
|
|
709
690
|
load(id) {
|
|
710
691
|
if (id === resolvedVirtualModuleId) {
|
|
@@ -735,7 +716,7 @@ try {
|
|
|
735
716
|
const { document } = parseHTML2(html);
|
|
736
717
|
const script = document.createElement("script");
|
|
737
718
|
script.type = "module";
|
|
738
|
-
script.src = "
|
|
719
|
+
script.src = config.command === "serve" ? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
|
|
739
720
|
if (document.head == null) {
|
|
740
721
|
const newHead = document.createElement("head");
|
|
741
722
|
document.documentElement.prepend(newHead);
|
|
@@ -777,8 +758,7 @@ async function writeFileIfDifferent(file, newContents) {
|
|
|
777
758
|
}
|
|
778
759
|
}
|
|
779
760
|
async function getPublicFiles() {
|
|
780
|
-
if (!await fs3.exists(wxt.config.publicDir))
|
|
781
|
-
return [];
|
|
761
|
+
if (!await fs3.exists(wxt.config.publicDir)) return [];
|
|
782
762
|
const files = await glob("**/*", { cwd: wxt.config.publicDir });
|
|
783
763
|
return files.map(unnormalizePath);
|
|
784
764
|
}
|
|
@@ -811,8 +791,7 @@ async function copyPublicDirectory() {
|
|
|
811
791
|
relativeDest: file
|
|
812
792
|
}));
|
|
813
793
|
await wxt.hooks.callHook("build:publicAssets", wxt, files);
|
|
814
|
-
if (files.length === 0)
|
|
815
|
-
return [];
|
|
794
|
+
if (files.length === 0) return [];
|
|
816
795
|
const publicAssets = [];
|
|
817
796
|
for (const { absoluteSrc, relativeDest } of files) {
|
|
818
797
|
const absoluteDest = resolve6(wxt.config.outDir, relativeDest);
|
|
@@ -832,21 +811,18 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
832
811
|
changedFiles,
|
|
833
812
|
(file) => file === wxt.config.userConfigMetadata.configFile
|
|
834
813
|
);
|
|
835
|
-
if (isConfigChange)
|
|
836
|
-
return { type: "full-restart" };
|
|
814
|
+
if (isConfigChange) return { type: "full-restart" };
|
|
837
815
|
const isRunnerChange = some(
|
|
838
816
|
changedFiles,
|
|
839
817
|
(file) => file === wxt.config.runnerConfig.configFile
|
|
840
818
|
);
|
|
841
|
-
if (isRunnerChange)
|
|
842
|
-
return { type: "browser-restart" };
|
|
819
|
+
if (isRunnerChange) return { type: "browser-restart" };
|
|
843
820
|
const changedSteps = new Set(
|
|
844
821
|
changedFiles.flatMap(
|
|
845
822
|
(changedFile) => findEffectedSteps(changedFile, currentOutput)
|
|
846
823
|
)
|
|
847
824
|
);
|
|
848
|
-
if (changedSteps.size === 0)
|
|
849
|
-
return { type: "no-change" };
|
|
825
|
+
if (changedSteps.size === 0) return { type: "no-change" };
|
|
850
826
|
const unchangedOutput = {
|
|
851
827
|
manifest: currentOutput.manifest,
|
|
852
828
|
steps: [],
|
|
@@ -909,14 +885,12 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
909
885
|
);
|
|
910
886
|
for (const step of currentOutput.steps) {
|
|
911
887
|
const effectedChunk = step.chunks.find((chunk) => isChunkEffected(chunk));
|
|
912
|
-
if (effectedChunk)
|
|
913
|
-
changes.push(step);
|
|
888
|
+
if (effectedChunk) changes.push(step);
|
|
914
889
|
}
|
|
915
890
|
const effectedAsset = currentOutput.publicAssets.find(
|
|
916
891
|
(chunk) => isChunkEffected(chunk)
|
|
917
892
|
);
|
|
918
|
-
if (effectedAsset)
|
|
919
|
-
changes.push(effectedAsset);
|
|
893
|
+
if (effectedAsset) changes.push(effectedAsset);
|
|
920
894
|
return changes;
|
|
921
895
|
}
|
|
922
896
|
|
|
@@ -1696,8 +1670,7 @@ async function resolveConfig(inlineConfig, command) {
|
|
|
1696
1670
|
const mergedConfig = await mergeInlineConfig(inlineConfig, userConfig);
|
|
1697
1671
|
const debug = mergedConfig.debug ?? false;
|
|
1698
1672
|
const logger = mergedConfig.logger ?? consola;
|
|
1699
|
-
if (debug)
|
|
1700
|
-
logger.level = LogLevels.debug;
|
|
1673
|
+
if (debug) logger.level = LogLevels.debug;
|
|
1701
1674
|
const browser = mergedConfig.browser ?? "chrome";
|
|
1702
1675
|
const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
|
|
1703
1676
|
const mode = mergedConfig.mode ?? COMMAND_MODES[command];
|
|
@@ -1873,8 +1846,7 @@ function resolveAnalysisConfig(root, mergedConfig) {
|
|
|
1873
1846
|
};
|
|
1874
1847
|
}
|
|
1875
1848
|
async function getUnimportOptions(wxtDir, logger, config) {
|
|
1876
|
-
if (config.imports === false)
|
|
1877
|
-
return false;
|
|
1849
|
+
if (config.imports === false) return false;
|
|
1878
1850
|
const enabledConfig = config.imports?.eslintrc?.enabled;
|
|
1879
1851
|
let enabled;
|
|
1880
1852
|
switch (enabledConfig) {
|
|
@@ -2042,8 +2014,7 @@ import { filesize } from "filesize";
|
|
|
2042
2014
|
|
|
2043
2015
|
// src/core/utils/log/printTable.ts
|
|
2044
2016
|
function printTable(log, header, rows, gap = 2) {
|
|
2045
|
-
if (rows.length === 0)
|
|
2046
|
-
return;
|
|
2017
|
+
if (rows.length === 0) return;
|
|
2047
2018
|
const columnWidths = rows.reduce(
|
|
2048
2019
|
(widths, row) => {
|
|
2049
2020
|
for (let i = 0; i < Math.max(widths.length, row.length); i++) {
|
|
@@ -2057,11 +2028,9 @@ function printTable(log, header, rows, gap = 2) {
|
|
|
2057
2028
|
rows.forEach((row, i) => {
|
|
2058
2029
|
row.forEach((col, j) => {
|
|
2059
2030
|
str += col.padEnd(columnWidths[j], " ");
|
|
2060
|
-
if (j !== row.length - 1)
|
|
2061
|
-
str += "".padEnd(gap, " ");
|
|
2031
|
+
if (j !== row.length - 1) str += "".padEnd(gap, " ");
|
|
2062
2032
|
});
|
|
2063
|
-
if (i !== rows.length - 1)
|
|
2064
|
-
str += "\n";
|
|
2033
|
+
if (i !== rows.length - 1) str += "\n";
|
|
2065
2034
|
});
|
|
2066
2035
|
log(`${header}
|
|
2067
2036
|
${str}`);
|
|
@@ -2115,8 +2084,7 @@ async function printBuildSummary(log, header, output) {
|
|
|
2115
2084
|
const lWeight = getChunkSortWeight(l.fileName);
|
|
2116
2085
|
const rWeight = getChunkSortWeight(r.fileName);
|
|
2117
2086
|
const diff = lWeight - rWeight;
|
|
2118
|
-
if (diff !== 0)
|
|
2119
|
-
return diff;
|
|
2087
|
+
if (diff !== 0) return diff;
|
|
2120
2088
|
return l.fileName.localeCompare(r.fileName);
|
|
2121
2089
|
});
|
|
2122
2090
|
const files = chunks.map(
|
|
@@ -2161,8 +2129,7 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
|
2161
2129
|
const sections = csp.split(";").map((section) => section.trim());
|
|
2162
2130
|
this.data = sections.reduce((data, section) => {
|
|
2163
2131
|
const [key, ...values] = section.split(" ").map((item) => item.trim());
|
|
2164
|
-
if (key)
|
|
2165
|
-
data[key] = values;
|
|
2132
|
+
if (key) data[key] = values;
|
|
2166
2133
|
return data;
|
|
2167
2134
|
}, {});
|
|
2168
2135
|
} else {
|
|
@@ -2175,8 +2142,7 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
|
2175
2142
|
add(directive, ...newValues) {
|
|
2176
2143
|
const values = this.data[directive] ?? [];
|
|
2177
2144
|
newValues.forEach((newValue) => {
|
|
2178
|
-
if (!values.includes(newValue))
|
|
2179
|
-
values.push(newValue);
|
|
2145
|
+
if (!values.includes(newValue)) values.push(newValue);
|
|
2180
2146
|
});
|
|
2181
2147
|
this.data[directive] = values;
|
|
2182
2148
|
return this;
|
|
@@ -2199,8 +2165,7 @@ function hashContentScriptOptions(options) {
|
|
|
2199
2165
|
void 0
|
|
2200
2166
|
);
|
|
2201
2167
|
Object.keys(simplifiedOptions).forEach((key) => {
|
|
2202
|
-
if (simplifiedOptions[key] == null)
|
|
2203
|
-
delete simplifiedOptions[key];
|
|
2168
|
+
if (simplifiedOptions[key] == null) delete simplifiedOptions[key];
|
|
2204
2169
|
});
|
|
2205
2170
|
const withDefaults = {
|
|
2206
2171
|
exclude_globs: [],
|
|
@@ -2216,10 +2181,8 @@ function hashContentScriptOptions(options) {
|
|
|
2216
2181
|
};
|
|
2217
2182
|
return JSON.stringify(
|
|
2218
2183
|
Object.entries(withDefaults).map(([key, value]) => {
|
|
2219
|
-
if (Array.isArray(value))
|
|
2220
|
-
|
|
2221
|
-
else
|
|
2222
|
-
return [key, value];
|
|
2184
|
+
if (Array.isArray(value)) return [key, value.sort()];
|
|
2185
|
+
else return [key, value];
|
|
2223
2186
|
}).sort((l, r) => l[0].localeCompare(r[0]))
|
|
2224
2187
|
);
|
|
2225
2188
|
}
|
|
@@ -2309,10 +2272,8 @@ async function generateManifest(entrypoints, buildOutput) {
|
|
|
2309
2272
|
manifest.version_name = // Firefox doesn't support version_name
|
|
2310
2273
|
wxt.config.browser === "firefox" || versionName === version2 ? void 0 : versionName;
|
|
2311
2274
|
addEntrypoints(manifest, entrypoints, buildOutput);
|
|
2312
|
-
if (wxt.config.command === "serve")
|
|
2313
|
-
|
|
2314
|
-
if (wxt.config.command === "serve")
|
|
2315
|
-
addDevModePermissions(manifest);
|
|
2275
|
+
if (wxt.config.command === "serve") addDevModeCsp(manifest);
|
|
2276
|
+
if (wxt.config.command === "serve") addDevModePermissions(manifest);
|
|
2316
2277
|
wxt.config.transformManifest?.(manifest);
|
|
2317
2278
|
await wxt.hooks.callHook("build:manifestGenerated", wxt, manifest);
|
|
2318
2279
|
if (wxt.config.manifestVersion === 2) {
|
|
@@ -2517,10 +2478,8 @@ function addEntrypoints(manifest, entrypoints, buildOutput) {
|
|
|
2517
2478
|
} else {
|
|
2518
2479
|
const hashToEntrypointsMap = contentScripts.filter((cs) => cs.options.registration !== "runtime").reduce((map, script) => {
|
|
2519
2480
|
const hash = hashContentScriptOptions(script.options);
|
|
2520
|
-
if (map.has(hash))
|
|
2521
|
-
|
|
2522
|
-
else
|
|
2523
|
-
map.set(hash, [script]);
|
|
2481
|
+
if (map.has(hash)) map.get(hash)?.push(script);
|
|
2482
|
+
else map.set(hash, [script]);
|
|
2524
2483
|
return map;
|
|
2525
2484
|
}, /* @__PURE__ */ new Map());
|
|
2526
2485
|
const manifestContentScripts = Array.from(
|
|
@@ -2589,8 +2548,7 @@ function discoverIcons(buildOutput) {
|
|
|
2589
2548
|
break;
|
|
2590
2549
|
}
|
|
2591
2550
|
}
|
|
2592
|
-
if (size == null)
|
|
2593
|
-
return;
|
|
2551
|
+
if (size == null) return;
|
|
2594
2552
|
icons.push([size, normalizePath(asset.fileName)]);
|
|
2595
2553
|
});
|
|
2596
2554
|
return icons.length > 0 ? Object.fromEntries(icons) : void 0;
|
|
@@ -2629,8 +2587,7 @@ function addDevModeCsp(manifest) {
|
|
|
2629
2587
|
}
|
|
2630
2588
|
function addDevModePermissions(manifest) {
|
|
2631
2589
|
addPermission(manifest, "tabs");
|
|
2632
|
-
if (wxt.config.manifestVersion === 3)
|
|
2633
|
-
addPermission(manifest, "scripting");
|
|
2590
|
+
if (wxt.config.manifestVersion === 3) addPermission(manifest, "scripting");
|
|
2634
2591
|
}
|
|
2635
2592
|
function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
|
|
2636
2593
|
const css = [];
|
|
@@ -2638,23 +2595,18 @@ function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
|
|
|
2638
2595
|
if (script.options.cssInjectionMode === "manual" || script.options.cssInjectionMode === "ui")
|
|
2639
2596
|
return;
|
|
2640
2597
|
const cssFile = contentScriptCssMap[script.name];
|
|
2641
|
-
if (cssFile == null)
|
|
2642
|
-
|
|
2643
|
-
if (cssFile)
|
|
2644
|
-
css.push(cssFile);
|
|
2598
|
+
if (cssFile == null) return;
|
|
2599
|
+
if (cssFile) css.push(cssFile);
|
|
2645
2600
|
});
|
|
2646
|
-
if (css.length > 0)
|
|
2647
|
-
return css;
|
|
2601
|
+
if (css.length > 0) return css;
|
|
2648
2602
|
return void 0;
|
|
2649
2603
|
}
|
|
2650
2604
|
function getContentScriptCssWebAccessibleResources(contentScripts, contentScriptCssMap) {
|
|
2651
2605
|
const resources = [];
|
|
2652
2606
|
contentScripts.forEach((script) => {
|
|
2653
|
-
if (script.options.cssInjectionMode !== "ui")
|
|
2654
|
-
return;
|
|
2607
|
+
if (script.options.cssInjectionMode !== "ui") return;
|
|
2655
2608
|
const cssFile = contentScriptCssMap[script.name];
|
|
2656
|
-
if (cssFile == null)
|
|
2657
|
-
return;
|
|
2609
|
+
if (cssFile == null) return;
|
|
2658
2610
|
resources.push({
|
|
2659
2611
|
resources: [cssFile],
|
|
2660
2612
|
matches: script.options.matches.map(
|
|
@@ -2671,46 +2623,39 @@ function getContentScriptsCssMap(buildOutput, scripts) {
|
|
|
2671
2623
|
const relatedCss = allChunks.find(
|
|
2672
2624
|
(chunk) => chunk.fileName === `content-scripts/${script.name}.css`
|
|
2673
2625
|
);
|
|
2674
|
-
if (relatedCss != null)
|
|
2675
|
-
map[script.name] = relatedCss.fileName;
|
|
2626
|
+
if (relatedCss != null) map[script.name] = relatedCss.fileName;
|
|
2676
2627
|
});
|
|
2677
2628
|
return map;
|
|
2678
2629
|
}
|
|
2679
2630
|
function addPermission(manifest, permission) {
|
|
2680
2631
|
manifest.permissions ??= [];
|
|
2681
|
-
if (manifest.permissions.includes(permission))
|
|
2682
|
-
return;
|
|
2632
|
+
if (manifest.permissions.includes(permission)) return;
|
|
2683
2633
|
manifest.permissions.push(permission);
|
|
2684
2634
|
}
|
|
2685
2635
|
function addHostPermission(manifest, hostPermission) {
|
|
2686
2636
|
manifest.host_permissions ??= [];
|
|
2687
|
-
if (manifest.host_permissions.includes(hostPermission))
|
|
2688
|
-
return;
|
|
2637
|
+
if (manifest.host_permissions.includes(hostPermission)) return;
|
|
2689
2638
|
manifest.host_permissions.push(hostPermission);
|
|
2690
2639
|
}
|
|
2691
2640
|
function stripPathFromMatchPattern(pattern) {
|
|
2692
2641
|
const protocolSepIndex = pattern.indexOf("://");
|
|
2693
|
-
if (protocolSepIndex === -1)
|
|
2694
|
-
return pattern;
|
|
2642
|
+
if (protocolSepIndex === -1) return pattern;
|
|
2695
2643
|
const startOfPath = pattern.indexOf("/", protocolSepIndex + 3);
|
|
2696
2644
|
return pattern.substring(0, startOfPath) + "/*";
|
|
2697
2645
|
}
|
|
2698
2646
|
function convertWebAccessibleResourcesToMv2(manifest) {
|
|
2699
|
-
if (manifest.web_accessible_resources == null)
|
|
2700
|
-
return;
|
|
2647
|
+
if (manifest.web_accessible_resources == null) return;
|
|
2701
2648
|
manifest.web_accessible_resources = Array.from(
|
|
2702
2649
|
new Set(
|
|
2703
2650
|
manifest.web_accessible_resources.flatMap((item) => {
|
|
2704
|
-
if (typeof item === "string")
|
|
2705
|
-
return item;
|
|
2651
|
+
if (typeof item === "string") return item;
|
|
2706
2652
|
return item.resources;
|
|
2707
2653
|
})
|
|
2708
2654
|
)
|
|
2709
2655
|
);
|
|
2710
2656
|
}
|
|
2711
2657
|
function moveHostPermissionsToPermissions(manifest) {
|
|
2712
|
-
if (!manifest.host_permissions?.length)
|
|
2713
|
-
return;
|
|
2658
|
+
if (!manifest.host_permissions?.length) return;
|
|
2714
2659
|
manifest.host_permissions.forEach(
|
|
2715
2660
|
(permission) => addPermission(manifest, permission)
|
|
2716
2661
|
);
|
|
@@ -2722,8 +2667,7 @@ function convertActionToMv2(manifest) {
|
|
|
2722
2667
|
manifest.browser_action = manifest.action;
|
|
2723
2668
|
}
|
|
2724
2669
|
function validateMv3WebAccessbileResources(manifest) {
|
|
2725
|
-
if (manifest.web_accessible_resources == null)
|
|
2726
|
-
return;
|
|
2670
|
+
if (manifest.web_accessible_resources == null) return;
|
|
2727
2671
|
const stringResources = manifest.web_accessible_resources.filter(
|
|
2728
2672
|
(item) => typeof item === "string"
|
|
2729
2673
|
);
|
|
@@ -2785,8 +2729,7 @@ async function rebuild(allEntrypoints, entrypointGroups, existingOutput = {
|
|
|
2785
2729
|
const spinner = ora(`Preparing...`).start();
|
|
2786
2730
|
await generateTypesDir(allEntrypoints).catch((err) => {
|
|
2787
2731
|
wxt.logger.warn("Failed to update .wxt directory:", err);
|
|
2788
|
-
if (wxt.config.command === "build")
|
|
2789
|
-
throw err;
|
|
2732
|
+
if (wxt.config.command === "build") throw err;
|
|
2790
2733
|
});
|
|
2791
2734
|
const newOutput = await buildEntrypoints(entrypointGroups, spinner);
|
|
2792
2735
|
const mergedOutput = {
|
|
@@ -2830,10 +2773,8 @@ function validateEntrypoints(entrypoints) {
|
|
|
2830
2773
|
let errorCount = 0;
|
|
2831
2774
|
let warningCount = 0;
|
|
2832
2775
|
for (const err of errors) {
|
|
2833
|
-
if (err.type === "warning")
|
|
2834
|
-
|
|
2835
|
-
else
|
|
2836
|
-
errorCount++;
|
|
2776
|
+
if (err.type === "warning") warningCount++;
|
|
2777
|
+
else errorCount++;
|
|
2837
2778
|
}
|
|
2838
2779
|
return {
|
|
2839
2780
|
errors,
|
|
@@ -2995,7 +2936,7 @@ var npm = {
|
|
|
2995
2936
|
overridesKey: "overrides",
|
|
2996
2937
|
async downloadDependency(id, downloadDir) {
|
|
2997
2938
|
await ensureDir3(downloadDir);
|
|
2998
|
-
const { execa } = await import("./execa-
|
|
2939
|
+
const { execa } = await import("./execa-D7CMCKO2.js");
|
|
2999
2940
|
const res = await execa("npm", ["pack", id, "--json"], {
|
|
3000
2941
|
cwd: downloadDir
|
|
3001
2942
|
});
|
|
@@ -3007,7 +2948,7 @@ var npm = {
|
|
|
3007
2948
|
if (options?.all) {
|
|
3008
2949
|
args.push("--depth", "Infinity");
|
|
3009
2950
|
}
|
|
3010
|
-
const { execa } = await import("./execa-
|
|
2951
|
+
const { execa } = await import("./execa-D7CMCKO2.js");
|
|
3011
2952
|
const res = await execa("npm", args, { cwd: options?.cwd });
|
|
3012
2953
|
const project = JSON.parse(res.stdout);
|
|
3013
2954
|
return flattenNpmListOutput([project]);
|
|
@@ -3017,10 +2958,8 @@ function flattenNpmListOutput(projects) {
|
|
|
3017
2958
|
const queue = projects.flatMap(
|
|
3018
2959
|
(project) => {
|
|
3019
2960
|
const acc = [];
|
|
3020
|
-
if (project.dependencies)
|
|
3021
|
-
|
|
3022
|
-
if (project.devDependencies)
|
|
3023
|
-
acc.push(project.devDependencies);
|
|
2961
|
+
if (project.dependencies) acc.push(project.dependencies);
|
|
2962
|
+
if (project.devDependencies) acc.push(project.devDependencies);
|
|
3024
2963
|
return acc;
|
|
3025
2964
|
}
|
|
3026
2965
|
);
|
|
@@ -3031,10 +2970,8 @@ function flattenNpmListOutput(projects) {
|
|
|
3031
2970
|
name,
|
|
3032
2971
|
version: meta.version
|
|
3033
2972
|
});
|
|
3034
|
-
if (meta.dependencies)
|
|
3035
|
-
|
|
3036
|
-
if (meta.devDependencies)
|
|
3037
|
-
queue.push(meta.devDependencies);
|
|
2973
|
+
if (meta.dependencies) queue.push(meta.dependencies);
|
|
2974
|
+
if (meta.devDependencies) queue.push(meta.devDependencies);
|
|
3038
2975
|
});
|
|
3039
2976
|
}
|
|
3040
2977
|
return dedupeDependencies(dependencies);
|
|
@@ -3064,7 +3001,7 @@ var bun = {
|
|
|
3064
3001
|
if (options?.all) {
|
|
3065
3002
|
args.push("--all");
|
|
3066
3003
|
}
|
|
3067
|
-
const { execa } = await import("./execa-
|
|
3004
|
+
const { execa } = await import("./execa-D7CMCKO2.js");
|
|
3068
3005
|
const res = await execa("bun", args, { cwd: options?.cwd });
|
|
3069
3006
|
return dedupeDependencies(
|
|
3070
3007
|
res.stdout.split("\n").slice(1).map((line) => line.trim()).map((line) => /.* (@?\S+)@(\S+)$/.exec(line)).filter((match) => !!match).map(([_, name, version2]) => ({ name, version: version2 }))
|
|
@@ -3083,11 +3020,10 @@ var yarn = {
|
|
|
3083
3020
|
if (options?.all) {
|
|
3084
3021
|
args.push("--depth", "Infinity");
|
|
3085
3022
|
}
|
|
3086
|
-
const { execa } = await import("./execa-
|
|
3023
|
+
const { execa } = await import("./execa-D7CMCKO2.js");
|
|
3087
3024
|
const res = await execa("yarn", args, { cwd: options?.cwd });
|
|
3088
3025
|
const tree = res.stdout.split("\n").map((line) => JSON.parse(line)).find((line) => line.type === "tree")?.data;
|
|
3089
|
-
if (tree == null)
|
|
3090
|
-
throw Error("'yarn list --json' did not output a tree");
|
|
3026
|
+
if (tree == null) throw Error("'yarn list --json' did not output a tree");
|
|
3091
3027
|
const queue = [...tree.trees];
|
|
3092
3028
|
const dependencies = [];
|
|
3093
3029
|
while (queue.length > 0) {
|
|
@@ -3120,7 +3056,7 @@ var pnpm = {
|
|
|
3120
3056
|
if (typeof process !== "undefined" && process.env.WXT_PNPM_IGNORE_WORKSPACE === "true") {
|
|
3121
3057
|
args.push("--ignore-workspace");
|
|
3122
3058
|
}
|
|
3123
|
-
const { execa } = await import("./execa-
|
|
3059
|
+
const { execa } = await import("./execa-D7CMCKO2.js");
|
|
3124
3060
|
const res = await execa("pnpm", args, { cwd: options?.cwd });
|
|
3125
3061
|
const projects = JSON.parse(res.stdout);
|
|
3126
3062
|
return flattenNpmListOutput(projects);
|
|
@@ -3133,8 +3069,7 @@ async function createWxtPackageManager(root) {
|
|
|
3133
3069
|
includeParentDirs: true
|
|
3134
3070
|
});
|
|
3135
3071
|
const requirePm = (cb) => {
|
|
3136
|
-
if (pm == null)
|
|
3137
|
-
throw Error("Could not detect package manager");
|
|
3072
|
+
if (pm == null) throw Error("Could not detect package manager");
|
|
3138
3073
|
return cb(pm);
|
|
3139
3074
|
};
|
|
3140
3075
|
return {
|
|
@@ -3296,8 +3231,7 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
3296
3231
|
// Include a hash to prevent conflicts
|
|
3297
3232
|
chunkFileNames: "chunks/[name]-[hash].js",
|
|
3298
3233
|
entryFileNames: ({ name }) => {
|
|
3299
|
-
if (htmlEntrypoints.has(name))
|
|
3300
|
-
return "chunks/[name]-[hash].js";
|
|
3234
|
+
if (htmlEntrypoints.has(name)) return "chunks/[name]-[hash].js";
|
|
3301
3235
|
return "[name].js";
|
|
3302
3236
|
},
|
|
3303
3237
|
// We can't control the "name", so we need a hash to prevent conflicts
|
|
@@ -3350,12 +3284,10 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
3350
3284
|
},
|
|
3351
3285
|
async build(group) {
|
|
3352
3286
|
let entryConfig;
|
|
3353
|
-
if (Array.isArray(group))
|
|
3354
|
-
entryConfig = getMultiPageConfig(group);
|
|
3287
|
+
if (Array.isArray(group)) entryConfig = getMultiPageConfig(group);
|
|
3355
3288
|
else if (group.inputPath.endsWith(".css"))
|
|
3356
3289
|
entryConfig = getCssConfig(group);
|
|
3357
|
-
else
|
|
3358
|
-
entryConfig = getLibModeConfig(group);
|
|
3290
|
+
else entryConfig = getLibModeConfig(group);
|
|
3359
3291
|
const buildConfig = vite.mergeConfig(await getBaseConfig(), entryConfig);
|
|
3360
3292
|
await hooks.callHook(
|
|
3361
3293
|
"vite:build:extendConfig",
|
|
@@ -3406,10 +3338,8 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
3406
3338
|
};
|
|
3407
3339
|
}
|
|
3408
3340
|
function getBuildOutputChunks(result) {
|
|
3409
|
-
if ("on" in result)
|
|
3410
|
-
|
|
3411
|
-
if (Array.isArray(result))
|
|
3412
|
-
return result.flatMap(({ output }) => output);
|
|
3341
|
+
if ("on" in result) throw Error("wxt does not support vite watch mode.");
|
|
3342
|
+
if (Array.isArray(result)) return result.flatMap(({ output }) => output);
|
|
3413
3343
|
return result.output;
|
|
3414
3344
|
}
|
|
3415
3345
|
function getRollupEntry(entrypoint) {
|
|
@@ -3452,8 +3382,7 @@ async function registerWxt(command, inlineConfig = {}, getServer) {
|
|
|
3452
3382
|
server
|
|
3453
3383
|
};
|
|
3454
3384
|
for (const module of config.modules) {
|
|
3455
|
-
if (module.hooks)
|
|
3456
|
-
wxt.hooks.addHooks(module.hooks);
|
|
3385
|
+
if (module.hooks) wxt.hooks.addHooks(module.hooks);
|
|
3457
3386
|
if (wxt.config.imports !== false && module.imports) {
|
|
3458
3387
|
wxt.config.imports.imports ??= [];
|
|
3459
3388
|
wxt.config.imports.imports.push(...module.imports);
|