wxt 0.18.6 → 0.18.8
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-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/{chunk-QOYT5J6A.js → chunk-Z3C7S5VV.js} +117 -182
- package/dist/cli.js +139 -220
- 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 +2182 -1180
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +24 -38
- package/dist/modules.cjs +8 -12
- package/dist/modules.js +9 -13
- 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 +46 -36
- 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 +38 -31
- package/dist/virtual/unlisted-script-entrypoint.js +1 -2
- package/package.json +33 -32
|
@@ -2,17 +2,17 @@ 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
|
-
var version = "0.18.
|
|
15
|
+
var version = "0.18.7";
|
|
16
16
|
|
|
17
17
|
// src/core/utils/paths.ts
|
|
18
18
|
import systemPath from "node:path";
|
|
@@ -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) {
|
|
@@ -732,10 +713,13 @@ try {
|
|
|
732
713
|
// Use "pre" so the new script is added before vite bundles all the scripts
|
|
733
714
|
order: "pre",
|
|
734
715
|
handler(html, _ctx) {
|
|
716
|
+
const src = config.command === "serve" ? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
|
|
735
717
|
const { document } = parseHTML2(html);
|
|
718
|
+
const existing = document.querySelector(`script[src='${src}']`);
|
|
719
|
+
if (existing) return;
|
|
736
720
|
const script = document.createElement("script");
|
|
737
721
|
script.type = "module";
|
|
738
|
-
script.src =
|
|
722
|
+
script.src = src;
|
|
739
723
|
if (document.head == null) {
|
|
740
724
|
const newHead = document.createElement("head");
|
|
741
725
|
document.documentElement.prepend(newHead);
|
|
@@ -777,8 +761,7 @@ async function writeFileIfDifferent(file, newContents) {
|
|
|
777
761
|
}
|
|
778
762
|
}
|
|
779
763
|
async function getPublicFiles() {
|
|
780
|
-
if (!await fs3.exists(wxt.config.publicDir))
|
|
781
|
-
return [];
|
|
764
|
+
if (!await fs3.exists(wxt.config.publicDir)) return [];
|
|
782
765
|
const files = await glob("**/*", { cwd: wxt.config.publicDir });
|
|
783
766
|
return files.map(unnormalizePath);
|
|
784
767
|
}
|
|
@@ -811,8 +794,7 @@ async function copyPublicDirectory() {
|
|
|
811
794
|
relativeDest: file
|
|
812
795
|
}));
|
|
813
796
|
await wxt.hooks.callHook("build:publicAssets", wxt, files);
|
|
814
|
-
if (files.length === 0)
|
|
815
|
-
return [];
|
|
797
|
+
if (files.length === 0) return [];
|
|
816
798
|
const publicAssets = [];
|
|
817
799
|
for (const { absoluteSrc, relativeDest } of files) {
|
|
818
800
|
const absoluteDest = resolve6(wxt.config.outDir, relativeDest);
|
|
@@ -832,25 +814,36 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
832
814
|
changedFiles,
|
|
833
815
|
(file) => file === wxt.config.userConfigMetadata.configFile
|
|
834
816
|
);
|
|
835
|
-
if (isConfigChange)
|
|
836
|
-
return { type: "full-restart" };
|
|
817
|
+
if (isConfigChange) return { type: "full-restart" };
|
|
837
818
|
const isRunnerChange = some(
|
|
838
819
|
changedFiles,
|
|
839
820
|
(file) => file === wxt.config.runnerConfig.configFile
|
|
840
821
|
);
|
|
841
|
-
if (isRunnerChange)
|
|
842
|
-
return { type: "browser-restart" };
|
|
822
|
+
if (isRunnerChange) return { type: "browser-restart" };
|
|
843
823
|
const changedSteps = new Set(
|
|
844
824
|
changedFiles.flatMap(
|
|
845
825
|
(changedFile) => findEffectedSteps(changedFile, currentOutput)
|
|
846
826
|
)
|
|
847
827
|
);
|
|
848
|
-
if (changedSteps.size === 0)
|
|
849
|
-
|
|
828
|
+
if (changedSteps.size === 0) {
|
|
829
|
+
const hasPublicChange = some(
|
|
830
|
+
changedFiles,
|
|
831
|
+
(file) => file.startsWith(wxt.config.publicDir)
|
|
832
|
+
);
|
|
833
|
+
if (hasPublicChange) {
|
|
834
|
+
return {
|
|
835
|
+
type: "extension-reload",
|
|
836
|
+
rebuildGroups: [],
|
|
837
|
+
cachedOutput: currentOutput
|
|
838
|
+
};
|
|
839
|
+
} else {
|
|
840
|
+
return { type: "no-change" };
|
|
841
|
+
}
|
|
842
|
+
}
|
|
850
843
|
const unchangedOutput = {
|
|
851
844
|
manifest: currentOutput.manifest,
|
|
852
845
|
steps: [],
|
|
853
|
-
publicAssets: []
|
|
846
|
+
publicAssets: [...currentOutput.publicAssets]
|
|
854
847
|
};
|
|
855
848
|
const changedOutput = {
|
|
856
849
|
manifest: currentOutput.manifest,
|
|
@@ -864,13 +857,6 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
864
857
|
unchangedOutput.steps.push(step);
|
|
865
858
|
}
|
|
866
859
|
}
|
|
867
|
-
for (const asset of currentOutput.publicAssets) {
|
|
868
|
-
if (changedSteps.has(asset)) {
|
|
869
|
-
changedOutput.publicAssets.push(asset);
|
|
870
|
-
} else {
|
|
871
|
-
unchangedOutput.publicAssets.push(asset);
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
860
|
const isOnlyHtmlChanges = changedFiles.length > 0 && every(changedFiles, (file) => file.endsWith(".html"));
|
|
875
861
|
if (isOnlyHtmlChanges) {
|
|
876
862
|
return {
|
|
@@ -909,14 +895,8 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
909
895
|
);
|
|
910
896
|
for (const step of currentOutput.steps) {
|
|
911
897
|
const effectedChunk = step.chunks.find((chunk) => isChunkEffected(chunk));
|
|
912
|
-
if (effectedChunk)
|
|
913
|
-
changes.push(step);
|
|
898
|
+
if (effectedChunk) changes.push(step);
|
|
914
899
|
}
|
|
915
|
-
const effectedAsset = currentOutput.publicAssets.find(
|
|
916
|
-
(chunk) => isChunkEffected(chunk)
|
|
917
|
-
);
|
|
918
|
-
if (effectedAsset)
|
|
919
|
-
changes.push(effectedAsset);
|
|
920
900
|
return changes;
|
|
921
901
|
}
|
|
922
902
|
|
|
@@ -1696,8 +1676,7 @@ async function resolveConfig(inlineConfig, command) {
|
|
|
1696
1676
|
const mergedConfig = await mergeInlineConfig(inlineConfig, userConfig);
|
|
1697
1677
|
const debug = mergedConfig.debug ?? false;
|
|
1698
1678
|
const logger = mergedConfig.logger ?? consola;
|
|
1699
|
-
if (debug)
|
|
1700
|
-
logger.level = LogLevels.debug;
|
|
1679
|
+
if (debug) logger.level = LogLevels.debug;
|
|
1701
1680
|
const browser = mergedConfig.browser ?? "chrome";
|
|
1702
1681
|
const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
|
|
1703
1682
|
const mode = mergedConfig.mode ?? COMMAND_MODES[command];
|
|
@@ -1873,8 +1852,7 @@ function resolveAnalysisConfig(root, mergedConfig) {
|
|
|
1873
1852
|
};
|
|
1874
1853
|
}
|
|
1875
1854
|
async function getUnimportOptions(wxtDir, logger, config) {
|
|
1876
|
-
if (config.imports === false)
|
|
1877
|
-
return false;
|
|
1855
|
+
if (config.imports === false) return false;
|
|
1878
1856
|
const enabledConfig = config.imports?.eslintrc?.enabled;
|
|
1879
1857
|
let enabled;
|
|
1880
1858
|
switch (enabledConfig) {
|
|
@@ -2042,8 +2020,7 @@ import { filesize } from "filesize";
|
|
|
2042
2020
|
|
|
2043
2021
|
// src/core/utils/log/printTable.ts
|
|
2044
2022
|
function printTable(log, header, rows, gap = 2) {
|
|
2045
|
-
if (rows.length === 0)
|
|
2046
|
-
return;
|
|
2023
|
+
if (rows.length === 0) return;
|
|
2047
2024
|
const columnWidths = rows.reduce(
|
|
2048
2025
|
(widths, row) => {
|
|
2049
2026
|
for (let i = 0; i < Math.max(widths.length, row.length); i++) {
|
|
@@ -2057,11 +2034,9 @@ function printTable(log, header, rows, gap = 2) {
|
|
|
2057
2034
|
rows.forEach((row, i) => {
|
|
2058
2035
|
row.forEach((col, j) => {
|
|
2059
2036
|
str += col.padEnd(columnWidths[j], " ");
|
|
2060
|
-
if (j !== row.length - 1)
|
|
2061
|
-
str += "".padEnd(gap, " ");
|
|
2037
|
+
if (j !== row.length - 1) str += "".padEnd(gap, " ");
|
|
2062
2038
|
});
|
|
2063
|
-
if (i !== rows.length - 1)
|
|
2064
|
-
str += "\n";
|
|
2039
|
+
if (i !== rows.length - 1) str += "\n";
|
|
2065
2040
|
});
|
|
2066
2041
|
log(`${header}
|
|
2067
2042
|
${str}`);
|
|
@@ -2115,8 +2090,7 @@ async function printBuildSummary(log, header, output) {
|
|
|
2115
2090
|
const lWeight = getChunkSortWeight(l.fileName);
|
|
2116
2091
|
const rWeight = getChunkSortWeight(r.fileName);
|
|
2117
2092
|
const diff = lWeight - rWeight;
|
|
2118
|
-
if (diff !== 0)
|
|
2119
|
-
return diff;
|
|
2093
|
+
if (diff !== 0) return diff;
|
|
2120
2094
|
return l.fileName.localeCompare(r.fileName);
|
|
2121
2095
|
});
|
|
2122
2096
|
const files = chunks.map(
|
|
@@ -2161,8 +2135,7 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
|
2161
2135
|
const sections = csp.split(";").map((section) => section.trim());
|
|
2162
2136
|
this.data = sections.reduce((data, section) => {
|
|
2163
2137
|
const [key, ...values] = section.split(" ").map((item) => item.trim());
|
|
2164
|
-
if (key)
|
|
2165
|
-
data[key] = values;
|
|
2138
|
+
if (key) data[key] = values;
|
|
2166
2139
|
return data;
|
|
2167
2140
|
}, {});
|
|
2168
2141
|
} else {
|
|
@@ -2175,8 +2148,7 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
|
2175
2148
|
add(directive, ...newValues) {
|
|
2176
2149
|
const values = this.data[directive] ?? [];
|
|
2177
2150
|
newValues.forEach((newValue) => {
|
|
2178
|
-
if (!values.includes(newValue))
|
|
2179
|
-
values.push(newValue);
|
|
2151
|
+
if (!values.includes(newValue)) values.push(newValue);
|
|
2180
2152
|
});
|
|
2181
2153
|
this.data[directive] = values;
|
|
2182
2154
|
return this;
|
|
@@ -2199,8 +2171,7 @@ function hashContentScriptOptions(options) {
|
|
|
2199
2171
|
void 0
|
|
2200
2172
|
);
|
|
2201
2173
|
Object.keys(simplifiedOptions).forEach((key) => {
|
|
2202
|
-
if (simplifiedOptions[key] == null)
|
|
2203
|
-
delete simplifiedOptions[key];
|
|
2174
|
+
if (simplifiedOptions[key] == null) delete simplifiedOptions[key];
|
|
2204
2175
|
});
|
|
2205
2176
|
const withDefaults = {
|
|
2206
2177
|
exclude_globs: [],
|
|
@@ -2216,10 +2187,8 @@ function hashContentScriptOptions(options) {
|
|
|
2216
2187
|
};
|
|
2217
2188
|
return JSON.stringify(
|
|
2218
2189
|
Object.entries(withDefaults).map(([key, value]) => {
|
|
2219
|
-
if (Array.isArray(value))
|
|
2220
|
-
|
|
2221
|
-
else
|
|
2222
|
-
return [key, value];
|
|
2190
|
+
if (Array.isArray(value)) return [key, value.sort()];
|
|
2191
|
+
else return [key, value];
|
|
2223
2192
|
}).sort((l, r) => l[0].localeCompare(r[0]))
|
|
2224
2193
|
);
|
|
2225
2194
|
}
|
|
@@ -2309,10 +2278,8 @@ async function generateManifest(entrypoints, buildOutput) {
|
|
|
2309
2278
|
manifest.version_name = // Firefox doesn't support version_name
|
|
2310
2279
|
wxt.config.browser === "firefox" || versionName === version2 ? void 0 : versionName;
|
|
2311
2280
|
addEntrypoints(manifest, entrypoints, buildOutput);
|
|
2312
|
-
if (wxt.config.command === "serve")
|
|
2313
|
-
|
|
2314
|
-
if (wxt.config.command === "serve")
|
|
2315
|
-
addDevModePermissions(manifest);
|
|
2281
|
+
if (wxt.config.command === "serve") addDevModeCsp(manifest);
|
|
2282
|
+
if (wxt.config.command === "serve") addDevModePermissions(manifest);
|
|
2316
2283
|
wxt.config.transformManifest?.(manifest);
|
|
2317
2284
|
await wxt.hooks.callHook("build:manifestGenerated", wxt, manifest);
|
|
2318
2285
|
if (wxt.config.manifestVersion === 2) {
|
|
@@ -2517,10 +2484,8 @@ function addEntrypoints(manifest, entrypoints, buildOutput) {
|
|
|
2517
2484
|
} else {
|
|
2518
2485
|
const hashToEntrypointsMap = contentScripts.filter((cs) => cs.options.registration !== "runtime").reduce((map, script) => {
|
|
2519
2486
|
const hash = hashContentScriptOptions(script.options);
|
|
2520
|
-
if (map.has(hash))
|
|
2521
|
-
|
|
2522
|
-
else
|
|
2523
|
-
map.set(hash, [script]);
|
|
2487
|
+
if (map.has(hash)) map.get(hash)?.push(script);
|
|
2488
|
+
else map.set(hash, [script]);
|
|
2524
2489
|
return map;
|
|
2525
2490
|
}, /* @__PURE__ */ new Map());
|
|
2526
2491
|
const manifestContentScripts = Array.from(
|
|
@@ -2589,8 +2554,7 @@ function discoverIcons(buildOutput) {
|
|
|
2589
2554
|
break;
|
|
2590
2555
|
}
|
|
2591
2556
|
}
|
|
2592
|
-
if (size == null)
|
|
2593
|
-
return;
|
|
2557
|
+
if (size == null) return;
|
|
2594
2558
|
icons.push([size, normalizePath(asset.fileName)]);
|
|
2595
2559
|
});
|
|
2596
2560
|
return icons.length > 0 ? Object.fromEntries(icons) : void 0;
|
|
@@ -2629,8 +2593,7 @@ function addDevModeCsp(manifest) {
|
|
|
2629
2593
|
}
|
|
2630
2594
|
function addDevModePermissions(manifest) {
|
|
2631
2595
|
addPermission(manifest, "tabs");
|
|
2632
|
-
if (wxt.config.manifestVersion === 3)
|
|
2633
|
-
addPermission(manifest, "scripting");
|
|
2596
|
+
if (wxt.config.manifestVersion === 3) addPermission(manifest, "scripting");
|
|
2634
2597
|
}
|
|
2635
2598
|
function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
|
|
2636
2599
|
const css = [];
|
|
@@ -2638,23 +2601,18 @@ function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
|
|
|
2638
2601
|
if (script.options.cssInjectionMode === "manual" || script.options.cssInjectionMode === "ui")
|
|
2639
2602
|
return;
|
|
2640
2603
|
const cssFile = contentScriptCssMap[script.name];
|
|
2641
|
-
if (cssFile == null)
|
|
2642
|
-
|
|
2643
|
-
if (cssFile)
|
|
2644
|
-
css.push(cssFile);
|
|
2604
|
+
if (cssFile == null) return;
|
|
2605
|
+
if (cssFile) css.push(cssFile);
|
|
2645
2606
|
});
|
|
2646
|
-
if (css.length > 0)
|
|
2647
|
-
return css;
|
|
2607
|
+
if (css.length > 0) return css;
|
|
2648
2608
|
return void 0;
|
|
2649
2609
|
}
|
|
2650
2610
|
function getContentScriptCssWebAccessibleResources(contentScripts, contentScriptCssMap) {
|
|
2651
2611
|
const resources = [];
|
|
2652
2612
|
contentScripts.forEach((script) => {
|
|
2653
|
-
if (script.options.cssInjectionMode !== "ui")
|
|
2654
|
-
return;
|
|
2613
|
+
if (script.options.cssInjectionMode !== "ui") return;
|
|
2655
2614
|
const cssFile = contentScriptCssMap[script.name];
|
|
2656
|
-
if (cssFile == null)
|
|
2657
|
-
return;
|
|
2615
|
+
if (cssFile == null) return;
|
|
2658
2616
|
resources.push({
|
|
2659
2617
|
resources: [cssFile],
|
|
2660
2618
|
matches: script.options.matches.map(
|
|
@@ -2671,46 +2629,39 @@ function getContentScriptsCssMap(buildOutput, scripts) {
|
|
|
2671
2629
|
const relatedCss = allChunks.find(
|
|
2672
2630
|
(chunk) => chunk.fileName === `content-scripts/${script.name}.css`
|
|
2673
2631
|
);
|
|
2674
|
-
if (relatedCss != null)
|
|
2675
|
-
map[script.name] = relatedCss.fileName;
|
|
2632
|
+
if (relatedCss != null) map[script.name] = relatedCss.fileName;
|
|
2676
2633
|
});
|
|
2677
2634
|
return map;
|
|
2678
2635
|
}
|
|
2679
2636
|
function addPermission(manifest, permission) {
|
|
2680
2637
|
manifest.permissions ??= [];
|
|
2681
|
-
if (manifest.permissions.includes(permission))
|
|
2682
|
-
return;
|
|
2638
|
+
if (manifest.permissions.includes(permission)) return;
|
|
2683
2639
|
manifest.permissions.push(permission);
|
|
2684
2640
|
}
|
|
2685
2641
|
function addHostPermission(manifest, hostPermission) {
|
|
2686
2642
|
manifest.host_permissions ??= [];
|
|
2687
|
-
if (manifest.host_permissions.includes(hostPermission))
|
|
2688
|
-
return;
|
|
2643
|
+
if (manifest.host_permissions.includes(hostPermission)) return;
|
|
2689
2644
|
manifest.host_permissions.push(hostPermission);
|
|
2690
2645
|
}
|
|
2691
2646
|
function stripPathFromMatchPattern(pattern) {
|
|
2692
2647
|
const protocolSepIndex = pattern.indexOf("://");
|
|
2693
|
-
if (protocolSepIndex === -1)
|
|
2694
|
-
return pattern;
|
|
2648
|
+
if (protocolSepIndex === -1) return pattern;
|
|
2695
2649
|
const startOfPath = pattern.indexOf("/", protocolSepIndex + 3);
|
|
2696
2650
|
return pattern.substring(0, startOfPath) + "/*";
|
|
2697
2651
|
}
|
|
2698
2652
|
function convertWebAccessibleResourcesToMv2(manifest) {
|
|
2699
|
-
if (manifest.web_accessible_resources == null)
|
|
2700
|
-
return;
|
|
2653
|
+
if (manifest.web_accessible_resources == null) return;
|
|
2701
2654
|
manifest.web_accessible_resources = Array.from(
|
|
2702
2655
|
new Set(
|
|
2703
2656
|
manifest.web_accessible_resources.flatMap((item) => {
|
|
2704
|
-
if (typeof item === "string")
|
|
2705
|
-
return item;
|
|
2657
|
+
if (typeof item === "string") return item;
|
|
2706
2658
|
return item.resources;
|
|
2707
2659
|
})
|
|
2708
2660
|
)
|
|
2709
2661
|
);
|
|
2710
2662
|
}
|
|
2711
2663
|
function moveHostPermissionsToPermissions(manifest) {
|
|
2712
|
-
if (!manifest.host_permissions?.length)
|
|
2713
|
-
return;
|
|
2664
|
+
if (!manifest.host_permissions?.length) return;
|
|
2714
2665
|
manifest.host_permissions.forEach(
|
|
2715
2666
|
(permission) => addPermission(manifest, permission)
|
|
2716
2667
|
);
|
|
@@ -2722,8 +2673,7 @@ function convertActionToMv2(manifest) {
|
|
|
2722
2673
|
manifest.browser_action = manifest.action;
|
|
2723
2674
|
}
|
|
2724
2675
|
function validateMv3WebAccessbileResources(manifest) {
|
|
2725
|
-
if (manifest.web_accessible_resources == null)
|
|
2726
|
-
return;
|
|
2676
|
+
if (manifest.web_accessible_resources == null) return;
|
|
2727
2677
|
const stringResources = manifest.web_accessible_resources.filter(
|
|
2728
2678
|
(item) => typeof item === "string"
|
|
2729
2679
|
);
|
|
@@ -2785,8 +2735,7 @@ async function rebuild(allEntrypoints, entrypointGroups, existingOutput = {
|
|
|
2785
2735
|
const spinner = ora(`Preparing...`).start();
|
|
2786
2736
|
await generateTypesDir(allEntrypoints).catch((err) => {
|
|
2787
2737
|
wxt.logger.warn("Failed to update .wxt directory:", err);
|
|
2788
|
-
if (wxt.config.command === "build")
|
|
2789
|
-
throw err;
|
|
2738
|
+
if (wxt.config.command === "build") throw err;
|
|
2790
2739
|
});
|
|
2791
2740
|
const newOutput = await buildEntrypoints(entrypointGroups, spinner);
|
|
2792
2741
|
const mergedOutput = {
|
|
@@ -2830,10 +2779,8 @@ function validateEntrypoints(entrypoints) {
|
|
|
2830
2779
|
let errorCount = 0;
|
|
2831
2780
|
let warningCount = 0;
|
|
2832
2781
|
for (const err of errors) {
|
|
2833
|
-
if (err.type === "warning")
|
|
2834
|
-
|
|
2835
|
-
else
|
|
2836
|
-
errorCount++;
|
|
2782
|
+
if (err.type === "warning") warningCount++;
|
|
2783
|
+
else errorCount++;
|
|
2837
2784
|
}
|
|
2838
2785
|
return {
|
|
2839
2786
|
errors,
|
|
@@ -2995,7 +2942,7 @@ var npm = {
|
|
|
2995
2942
|
overridesKey: "overrides",
|
|
2996
2943
|
async downloadDependency(id, downloadDir) {
|
|
2997
2944
|
await ensureDir3(downloadDir);
|
|
2998
|
-
const { execa } = await import("./execa-
|
|
2945
|
+
const { execa } = await import("./execa-D7CMCKO2.js");
|
|
2999
2946
|
const res = await execa("npm", ["pack", id, "--json"], {
|
|
3000
2947
|
cwd: downloadDir
|
|
3001
2948
|
});
|
|
@@ -3007,7 +2954,7 @@ var npm = {
|
|
|
3007
2954
|
if (options?.all) {
|
|
3008
2955
|
args.push("--depth", "Infinity");
|
|
3009
2956
|
}
|
|
3010
|
-
const { execa } = await import("./execa-
|
|
2957
|
+
const { execa } = await import("./execa-D7CMCKO2.js");
|
|
3011
2958
|
const res = await execa("npm", args, { cwd: options?.cwd });
|
|
3012
2959
|
const project = JSON.parse(res.stdout);
|
|
3013
2960
|
return flattenNpmListOutput([project]);
|
|
@@ -3017,10 +2964,8 @@ function flattenNpmListOutput(projects) {
|
|
|
3017
2964
|
const queue = projects.flatMap(
|
|
3018
2965
|
(project) => {
|
|
3019
2966
|
const acc = [];
|
|
3020
|
-
if (project.dependencies)
|
|
3021
|
-
|
|
3022
|
-
if (project.devDependencies)
|
|
3023
|
-
acc.push(project.devDependencies);
|
|
2967
|
+
if (project.dependencies) acc.push(project.dependencies);
|
|
2968
|
+
if (project.devDependencies) acc.push(project.devDependencies);
|
|
3024
2969
|
return acc;
|
|
3025
2970
|
}
|
|
3026
2971
|
);
|
|
@@ -3031,10 +2976,8 @@ function flattenNpmListOutput(projects) {
|
|
|
3031
2976
|
name,
|
|
3032
2977
|
version: meta.version
|
|
3033
2978
|
});
|
|
3034
|
-
if (meta.dependencies)
|
|
3035
|
-
|
|
3036
|
-
if (meta.devDependencies)
|
|
3037
|
-
queue.push(meta.devDependencies);
|
|
2979
|
+
if (meta.dependencies) queue.push(meta.dependencies);
|
|
2980
|
+
if (meta.devDependencies) queue.push(meta.devDependencies);
|
|
3038
2981
|
});
|
|
3039
2982
|
}
|
|
3040
2983
|
return dedupeDependencies(dependencies);
|
|
@@ -3064,7 +3007,7 @@ var bun = {
|
|
|
3064
3007
|
if (options?.all) {
|
|
3065
3008
|
args.push("--all");
|
|
3066
3009
|
}
|
|
3067
|
-
const { execa } = await import("./execa-
|
|
3010
|
+
const { execa } = await import("./execa-D7CMCKO2.js");
|
|
3068
3011
|
const res = await execa("bun", args, { cwd: options?.cwd });
|
|
3069
3012
|
return dedupeDependencies(
|
|
3070
3013
|
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 +3026,10 @@ var yarn = {
|
|
|
3083
3026
|
if (options?.all) {
|
|
3084
3027
|
args.push("--depth", "Infinity");
|
|
3085
3028
|
}
|
|
3086
|
-
const { execa } = await import("./execa-
|
|
3029
|
+
const { execa } = await import("./execa-D7CMCKO2.js");
|
|
3087
3030
|
const res = await execa("yarn", args, { cwd: options?.cwd });
|
|
3088
3031
|
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");
|
|
3032
|
+
if (tree == null) throw Error("'yarn list --json' did not output a tree");
|
|
3091
3033
|
const queue = [...tree.trees];
|
|
3092
3034
|
const dependencies = [];
|
|
3093
3035
|
while (queue.length > 0) {
|
|
@@ -3120,7 +3062,7 @@ var pnpm = {
|
|
|
3120
3062
|
if (typeof process !== "undefined" && process.env.WXT_PNPM_IGNORE_WORKSPACE === "true") {
|
|
3121
3063
|
args.push("--ignore-workspace");
|
|
3122
3064
|
}
|
|
3123
|
-
const { execa } = await import("./execa-
|
|
3065
|
+
const { execa } = await import("./execa-D7CMCKO2.js");
|
|
3124
3066
|
const res = await execa("pnpm", args, { cwd: options?.cwd });
|
|
3125
3067
|
const projects = JSON.parse(res.stdout);
|
|
3126
3068
|
return flattenNpmListOutput(projects);
|
|
@@ -3133,8 +3075,7 @@ async function createWxtPackageManager(root) {
|
|
|
3133
3075
|
includeParentDirs: true
|
|
3134
3076
|
});
|
|
3135
3077
|
const requirePm = (cb) => {
|
|
3136
|
-
if (pm == null)
|
|
3137
|
-
throw Error("Could not detect package manager");
|
|
3078
|
+
if (pm == null) throw Error("Could not detect package manager");
|
|
3138
3079
|
return cb(pm);
|
|
3139
3080
|
};
|
|
3140
3081
|
return {
|
|
@@ -3296,8 +3237,7 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
3296
3237
|
// Include a hash to prevent conflicts
|
|
3297
3238
|
chunkFileNames: "chunks/[name]-[hash].js",
|
|
3298
3239
|
entryFileNames: ({ name }) => {
|
|
3299
|
-
if (htmlEntrypoints.has(name))
|
|
3300
|
-
return "chunks/[name]-[hash].js";
|
|
3240
|
+
if (htmlEntrypoints.has(name)) return "chunks/[name]-[hash].js";
|
|
3301
3241
|
return "[name].js";
|
|
3302
3242
|
},
|
|
3303
3243
|
// We can't control the "name", so we need a hash to prevent conflicts
|
|
@@ -3350,12 +3290,10 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
3350
3290
|
},
|
|
3351
3291
|
async build(group) {
|
|
3352
3292
|
let entryConfig;
|
|
3353
|
-
if (Array.isArray(group))
|
|
3354
|
-
entryConfig = getMultiPageConfig(group);
|
|
3293
|
+
if (Array.isArray(group)) entryConfig = getMultiPageConfig(group);
|
|
3355
3294
|
else if (group.inputPath.endsWith(".css"))
|
|
3356
3295
|
entryConfig = getCssConfig(group);
|
|
3357
|
-
else
|
|
3358
|
-
entryConfig = getLibModeConfig(group);
|
|
3296
|
+
else entryConfig = getLibModeConfig(group);
|
|
3359
3297
|
const buildConfig = vite.mergeConfig(await getBaseConfig(), entryConfig);
|
|
3360
3298
|
await hooks.callHook(
|
|
3361
3299
|
"vite:build:extendConfig",
|
|
@@ -3406,10 +3344,8 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
3406
3344
|
};
|
|
3407
3345
|
}
|
|
3408
3346
|
function getBuildOutputChunks(result) {
|
|
3409
|
-
if ("on" in result)
|
|
3410
|
-
|
|
3411
|
-
if (Array.isArray(result))
|
|
3412
|
-
return result.flatMap(({ output }) => output);
|
|
3347
|
+
if ("on" in result) throw Error("wxt does not support vite watch mode.");
|
|
3348
|
+
if (Array.isArray(result)) return result.flatMap(({ output }) => output);
|
|
3413
3349
|
return result.output;
|
|
3414
3350
|
}
|
|
3415
3351
|
function getRollupEntry(entrypoint) {
|
|
@@ -3452,8 +3388,7 @@ async function registerWxt(command, inlineConfig = {}, getServer) {
|
|
|
3452
3388
|
server
|
|
3453
3389
|
};
|
|
3454
3390
|
for (const module of config.modules) {
|
|
3455
|
-
if (module.hooks)
|
|
3456
|
-
wxt.hooks.addHooks(module.hooks);
|
|
3391
|
+
if (module.hooks) wxt.hooks.addHooks(module.hooks);
|
|
3457
3392
|
if (wxt.config.imports !== false && module.imports) {
|
|
3458
3393
|
wxt.config.imports.imports ??= [];
|
|
3459
3394
|
wxt.config.imports.imports.push(...module.imports);
|