wxt 0.18.10 → 0.18.12
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/README.md +6 -6
- package/dist/{chunk-2V7XZSZQ.js → chunk-6QN6UXBH.js} +161 -91
- package/dist/cli.js +176 -96
- package/dist/client.d.ts +4 -2
- package/dist/client.js +8 -1
- package/dist/{index-Bk-a0SkY.d.ts → define-app-config-bg54F_lV.d.ts} +21 -1
- package/dist/{execa-D7CMCKO2.js → execa-4UBDUBJZ.js} +566 -478
- package/dist/{execa-ATHZH2Y4.js → execa-QLUM2B3W.js} +566 -478
- package/dist/{index-mz3v4Nde.d.cts → index-1N-eQJJh.d.cts} +15 -6
- package/dist/{index-mz3v4Nde.d.ts → index-1N-eQJJh.d.ts} +15 -6
- package/dist/index.cjs +948 -760
- package/dist/index.d.cts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +29 -20
- package/dist/modules.d.cts +1 -1
- package/dist/modules.d.ts +1 -1
- package/dist/sandbox.d.ts +2 -1
- package/dist/sandbox.js +6 -0
- package/dist/testing.cjs +127 -63
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +4 -2
- package/dist/virtual/background-entrypoint.js +9 -1
- package/package.json +10 -10
- package/dist/cli.d.ts +0 -2
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<h1 align="center">
|
|
2
|
-
<img style="vertical-align:middle" width="44" src="
|
|
2
|
+
<img style="vertical-align:middle" width="44" src="https://raw.githubusercontent.com/wxt-dev/wxt/HEAD/docs/public/hero-logo.svg" alt="WXT Logo">
|
|
3
3
|
<span>WXT</span>
|
|
4
4
|
</h1>
|
|
5
5
|
|
|
@@ -22,22 +22,22 @@
|
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
24
|
<p align="center">
|
|
25
|
-
<a href="https://wxt.dev" target="_blank">Get Started</a>
|
|
26
|
-
•
|
|
27
|
-
<a href="https://wxt.dev/guide/installation.html" target="_blank">Installation</a>
|
|
25
|
+
<a href="https://wxt.dev/guide/installation.html" target="_blank">Get Started</a>
|
|
28
26
|
•
|
|
29
27
|
<a href="https://wxt.dev/api/config.html" target="_blank">Configuration</a>
|
|
30
28
|
•
|
|
31
29
|
<a href="https://wxt.dev/examples.html" target="_blank">Examples</a>
|
|
32
30
|
•
|
|
31
|
+
<a href="https://github.com/wxt-dev/wxt/blob/main/packages/wxt/CHANGELOG.md" target="_blank">Changelog</a>
|
|
32
|
+
•
|
|
33
33
|
<a href="https://discord.gg/ZFsZqGery9" target="_blank">Discord</a>
|
|
34
34
|
</p>
|
|
35
35
|
|
|
36
|
-

|
|
37
37
|
|
|
38
38
|
## Demo
|
|
39
39
|
|
|
40
|
-
https://github.com/wxt-dev/wxt/assets/10101283/4d678939-1bdb-495c-9c36-3aa281d84c94
|
|
40
|
+
<video src="https://github.com/wxt-dev/wxt/assets/10101283/4d678939-1bdb-495c-9c36-3aa281d84c94"></video>
|
|
41
41
|
|
|
42
42
|
## Quick Start
|
|
43
43
|
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from "./chunk-QGM4M3NI.js";
|
|
17
17
|
|
|
18
18
|
// package.json
|
|
19
|
-
var version = "0.18.
|
|
19
|
+
var version = "0.18.11";
|
|
20
20
|
|
|
21
21
|
// src/core/utils/paths.ts
|
|
22
22
|
import systemPath from "node:path";
|
|
@@ -242,14 +242,33 @@ function webextensionPolyfillMock(config) {
|
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
// src/core/builders/vite/plugins/resolveAppConfig.ts
|
|
246
|
+
import { exists } from "fs-extra";
|
|
247
|
+
import { resolve as resolve2 } from "node:path";
|
|
248
|
+
function resolveAppConfig(config) {
|
|
249
|
+
const virtualModuleId = "virtual:app-config";
|
|
250
|
+
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
251
|
+
const appConfigFile = resolve2(config.srcDir, "app.config.ts");
|
|
252
|
+
return {
|
|
253
|
+
name: "wxt:resolve-app-config",
|
|
254
|
+
async resolveId(id) {
|
|
255
|
+
if (id !== virtualModuleId) return;
|
|
256
|
+
return await exists(appConfigFile) ? appConfigFile : resolvedVirtualModuleId;
|
|
257
|
+
},
|
|
258
|
+
load(id) {
|
|
259
|
+
if (id === resolvedVirtualModuleId) return `export default {}`;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
245
264
|
// src/core/builders/vite/plugins/devHtmlPrerender.ts
|
|
246
265
|
import { parseHTML } from "linkedom";
|
|
247
|
-
import { dirname, relative as relative2, resolve as
|
|
266
|
+
import { dirname, relative as relative2, resolve as resolve3 } from "node:path";
|
|
248
267
|
import { murmurHash } from "ohash";
|
|
249
268
|
var inlineScriptContents = {};
|
|
250
269
|
function devHtmlPrerender(config, server) {
|
|
251
270
|
const htmlReloadId = "@wxt/reload-html";
|
|
252
|
-
const resolvedHtmlReloadId =
|
|
271
|
+
const resolvedHtmlReloadId = resolve3(
|
|
253
272
|
config.wxtModuleDir,
|
|
254
273
|
"dist/virtual/reload-html.js"
|
|
255
274
|
);
|
|
@@ -351,12 +370,12 @@ function pointToDevServer(config, server, id, document, querySelector, attr) {
|
|
|
351
370
|
);
|
|
352
371
|
if (matchingAlias) {
|
|
353
372
|
const [alias, replacement] = matchingAlias;
|
|
354
|
-
resolvedAbsolutePath =
|
|
373
|
+
resolvedAbsolutePath = resolve3(
|
|
355
374
|
config.root,
|
|
356
375
|
src.replace(alias, replacement)
|
|
357
376
|
);
|
|
358
377
|
} else {
|
|
359
|
-
resolvedAbsolutePath =
|
|
378
|
+
resolvedAbsolutePath = resolve3(dirname(id), src);
|
|
360
379
|
}
|
|
361
380
|
if (resolvedAbsolutePath) {
|
|
362
381
|
const relativePath = normalizePath(
|
|
@@ -400,7 +419,7 @@ function devServerGlobals(config, server) {
|
|
|
400
419
|
}
|
|
401
420
|
|
|
402
421
|
// src/core/builders/vite/plugins/multipageMove.ts
|
|
403
|
-
import { dirname as dirname2, extname, resolve as
|
|
422
|
+
import { dirname as dirname2, extname, resolve as resolve4, join } from "node:path";
|
|
404
423
|
import fs, { ensureDir } from "fs-extra";
|
|
405
424
|
function multipageMove(entrypoints, config) {
|
|
406
425
|
return {
|
|
@@ -428,8 +447,8 @@ function multipageMove(entrypoints, config) {
|
|
|
428
447
|
);
|
|
429
448
|
continue;
|
|
430
449
|
}
|
|
431
|
-
const oldAbsPath =
|
|
432
|
-
const newAbsPath =
|
|
450
|
+
const oldAbsPath = resolve4(config.outDir, oldBundlePath);
|
|
451
|
+
const newAbsPath = resolve4(config.outDir, newBundlePath);
|
|
433
452
|
await ensureDir(dirname2(newAbsPath));
|
|
434
453
|
await fs.move(oldAbsPath, newAbsPath, { overwrite: true });
|
|
435
454
|
const renamedChunk = {
|
|
@@ -476,7 +495,7 @@ var virtualModuleNames = [
|
|
|
476
495
|
|
|
477
496
|
// src/core/builders/vite/plugins/resolveVirtualModules.ts
|
|
478
497
|
import fs2 from "fs-extra";
|
|
479
|
-
import { resolve as
|
|
498
|
+
import { resolve as resolve5 } from "path";
|
|
480
499
|
function resolveVirtualModules(config) {
|
|
481
500
|
return virtualModuleNames.map((name) => {
|
|
482
501
|
const virtualId = `virtual:wxt-${name}?`;
|
|
@@ -493,7 +512,7 @@ function resolveVirtualModules(config) {
|
|
|
493
512
|
if (!id.startsWith(resolvedVirtualId)) return;
|
|
494
513
|
const inputPath = id.replace(resolvedVirtualId, "");
|
|
495
514
|
const template = await fs2.readFile(
|
|
496
|
-
|
|
515
|
+
resolve5(config.wxtModuleDir, `dist/virtual/${name}.js`),
|
|
497
516
|
"utf-8"
|
|
498
517
|
);
|
|
499
518
|
return template.replace(`virtual:user-${name}`, inputPath);
|
|
@@ -635,9 +654,9 @@ function emptyMainFunction(mod) {
|
|
|
635
654
|
}
|
|
636
655
|
|
|
637
656
|
// src/core/builders/vite/plugins/removeEntrypointMainFunction.ts
|
|
638
|
-
import { resolve as
|
|
657
|
+
import { resolve as resolve6 } from "node:path";
|
|
639
658
|
function removeEntrypointMainFunction(config, path8) {
|
|
640
|
-
const absPath = normalizePath(
|
|
659
|
+
const absPath = normalizePath(resolve6(config.root, path8));
|
|
641
660
|
return {
|
|
642
661
|
name: "wxt:remove-entrypoint-main-function",
|
|
643
662
|
transform(code, id) {
|
|
@@ -749,8 +768,10 @@ var unimport_default = defineWxtModule({
|
|
|
749
768
|
wxt2.hooks.hook("prepare:types", async (_, entries) => {
|
|
750
769
|
await unimport.init();
|
|
751
770
|
entries.push(await getImportsDeclarationEntry(unimport));
|
|
752
|
-
if (
|
|
753
|
-
entries.push(
|
|
771
|
+
if (options.eslintrc.enabled === false) return;
|
|
772
|
+
entries.push(
|
|
773
|
+
await getEslintConfigEntry(unimport, options.eslintrc.enabled, options)
|
|
774
|
+
);
|
|
754
775
|
});
|
|
755
776
|
addViteConfig(wxt2, () => ({
|
|
756
777
|
plugins: [vitePlugin(unimport)]
|
|
@@ -791,15 +812,33 @@ async function getImportsDeclarationEntry(unimport) {
|
|
|
791
812
|
tsReference: true
|
|
792
813
|
};
|
|
793
814
|
}
|
|
794
|
-
async function
|
|
795
|
-
const globals2 = {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
815
|
+
async function getEslintConfigEntry(unimport, version2, options) {
|
|
816
|
+
const globals2 = (await unimport.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().reduce((globals3, name) => {
|
|
817
|
+
globals3[name] = options.eslintrc.globalsPropValue;
|
|
818
|
+
return globals3;
|
|
819
|
+
}, {});
|
|
820
|
+
if (version2 <= 8) return getEslint8ConfigEntry(options, globals2);
|
|
821
|
+
else return getEslint9ConfigEntry(options, globals2);
|
|
822
|
+
}
|
|
823
|
+
function getEslint8ConfigEntry(options, globals2) {
|
|
824
|
+
return {
|
|
825
|
+
path: options.eslintrc.filePath,
|
|
826
|
+
text: JSON.stringify({ globals: globals2 }, null, 2) + "\n"
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
function getEslint9ConfigEntry(options, globals2) {
|
|
800
830
|
return {
|
|
801
831
|
path: options.eslintrc.filePath,
|
|
802
|
-
text: JSON.stringify(
|
|
832
|
+
text: `const globals = ${JSON.stringify(globals2, null, 2)}
|
|
833
|
+
|
|
834
|
+
export default {
|
|
835
|
+
name: "wxt/auto-imports",
|
|
836
|
+
languageOptions: {
|
|
837
|
+
globals,
|
|
838
|
+
sourceType: "module",
|
|
839
|
+
},
|
|
840
|
+
};
|
|
841
|
+
`
|
|
803
842
|
};
|
|
804
843
|
}
|
|
805
844
|
|
|
@@ -820,7 +859,7 @@ async function getPublicFiles() {
|
|
|
820
859
|
|
|
821
860
|
// src/core/utils/building/build-entrypoints.ts
|
|
822
861
|
import fs4 from "fs-extra";
|
|
823
|
-
import { dirname as dirname3, resolve as
|
|
862
|
+
import { dirname as dirname3, resolve as resolve7 } from "path";
|
|
824
863
|
import pc from "picocolors";
|
|
825
864
|
async function buildEntrypoints(groups, spinner) {
|
|
826
865
|
const steps = [];
|
|
@@ -842,14 +881,14 @@ async function buildEntrypoints(groups, spinner) {
|
|
|
842
881
|
}
|
|
843
882
|
async function copyPublicDirectory() {
|
|
844
883
|
const files = (await getPublicFiles()).map((file) => ({
|
|
845
|
-
absoluteSrc:
|
|
884
|
+
absoluteSrc: resolve7(wxt.config.publicDir, file),
|
|
846
885
|
relativeDest: file
|
|
847
886
|
}));
|
|
848
887
|
await wxt.hooks.callHook("build:publicAssets", wxt, files);
|
|
849
888
|
if (files.length === 0) return [];
|
|
850
889
|
const publicAssets = [];
|
|
851
890
|
for (const file of files) {
|
|
852
|
-
const absoluteDest =
|
|
891
|
+
const absoluteDest = resolve7(wxt.config.outDir, file.relativeDest);
|
|
853
892
|
await fs4.ensureDir(dirname3(absoluteDest));
|
|
854
893
|
if ("absoluteSrc" in file) {
|
|
855
894
|
await fs4.copyFile(file.absoluteSrc, absoluteDest);
|
|
@@ -957,7 +996,7 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
957
996
|
}
|
|
958
997
|
|
|
959
998
|
// src/core/utils/building/find-entrypoints.ts
|
|
960
|
-
import { relative as relative3, resolve as
|
|
999
|
+
import { relative as relative3, resolve as resolve8 } from "path";
|
|
961
1000
|
import fs5 from "fs-extra";
|
|
962
1001
|
import { minimatch } from "minimatch";
|
|
963
1002
|
import { parseHTML as parseHTML3 } from "linkedom";
|
|
@@ -966,14 +1005,14 @@ import glob2 from "fast-glob";
|
|
|
966
1005
|
import pc2 from "picocolors";
|
|
967
1006
|
async function findEntrypoints() {
|
|
968
1007
|
await fs5.mkdir(wxt.config.wxtDir, { recursive: true });
|
|
969
|
-
await fs5.writeJson(
|
|
1008
|
+
await fs5.writeJson(resolve8(wxt.config.wxtDir, "tsconfig.json"), {});
|
|
970
1009
|
const relativePaths = await glob2(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
|
|
971
1010
|
cwd: wxt.config.entrypointsDir
|
|
972
1011
|
});
|
|
973
1012
|
relativePaths.sort();
|
|
974
1013
|
const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
|
|
975
1014
|
const entrypointInfos = relativePaths.reduce((results, relativePath) => {
|
|
976
|
-
const inputPath =
|
|
1015
|
+
const inputPath = resolve8(wxt.config.entrypointsDir, relativePath);
|
|
977
1016
|
const name = getEntrypointName(wxt.config.entrypointsDir, inputPath);
|
|
978
1017
|
const matchingGlob = pathGlobs.find(
|
|
979
1018
|
(glob5) => minimatch(relativePath, glob5)
|
|
@@ -1015,7 +1054,7 @@ async function findEntrypoints() {
|
|
|
1015
1054
|
return {
|
|
1016
1055
|
...info,
|
|
1017
1056
|
type,
|
|
1018
|
-
outputDir:
|
|
1057
|
+
outputDir: resolve8(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
1019
1058
|
options: {
|
|
1020
1059
|
include: void 0,
|
|
1021
1060
|
exclude: void 0
|
|
@@ -1242,7 +1281,7 @@ async function getContentScriptEntrypoint({
|
|
|
1242
1281
|
type: "content-script",
|
|
1243
1282
|
name,
|
|
1244
1283
|
inputPath,
|
|
1245
|
-
outputDir:
|
|
1284
|
+
outputDir: resolve8(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
1246
1285
|
options: resolvePerBrowserOptions(options, wxt.config.browser),
|
|
1247
1286
|
skipped
|
|
1248
1287
|
};
|
|
@@ -1338,7 +1377,7 @@ var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|
|
|
1338
1377
|
|
|
1339
1378
|
// src/core/utils/building/generate-wxt-dir.ts
|
|
1340
1379
|
import fs6 from "fs-extra";
|
|
1341
|
-
import { dirname as dirname4, relative as relative4, resolve as
|
|
1380
|
+
import { dirname as dirname4, relative as relative4, resolve as resolve9 } from "node:path";
|
|
1342
1381
|
import path4 from "node:path";
|
|
1343
1382
|
|
|
1344
1383
|
// src/core/utils/i18n.ts
|
|
@@ -1397,7 +1436,7 @@ async function generateTypesDir(entrypoints) {
|
|
|
1397
1436
|
entries.push(getMainDeclarationEntry(entries));
|
|
1398
1437
|
const absoluteFileEntries = entries.filter((entry) => "path" in entry).map((entry) => ({
|
|
1399
1438
|
...entry,
|
|
1400
|
-
path:
|
|
1439
|
+
path: resolve9(wxt.config.wxtDir, entry.path)
|
|
1401
1440
|
}));
|
|
1402
1441
|
await Promise.all(
|
|
1403
1442
|
absoluteFileEntries.map(async (file) => {
|
|
@@ -1509,7 +1548,7 @@ function getMainDeclarationEntry(references) {
|
|
|
1509
1548
|
if ("module" in ref) {
|
|
1510
1549
|
return lines.push(`/// <reference types="${ref.module}" />`);
|
|
1511
1550
|
} else if (ref.tsReference) {
|
|
1512
|
-
const absolutePath =
|
|
1551
|
+
const absolutePath = resolve9(wxt.config.wxtDir, ref.path);
|
|
1513
1552
|
const relativePath = relative4(wxt.config.wxtDir, absolutePath);
|
|
1514
1553
|
lines.push(`/// <reference types="./${normalizePath(relativePath)}" />`);
|
|
1515
1554
|
}
|
|
@@ -1562,9 +1601,9 @@ import path5 from "node:path";
|
|
|
1562
1601
|
|
|
1563
1602
|
// src/core/utils/cache.ts
|
|
1564
1603
|
import fs7, { ensureDir as ensureDir2 } from "fs-extra";
|
|
1565
|
-
import { dirname as dirname5, resolve as
|
|
1604
|
+
import { dirname as dirname5, resolve as resolve10 } from "path";
|
|
1566
1605
|
function createFsCache(wxtDir) {
|
|
1567
|
-
const getPath = (key) =>
|
|
1606
|
+
const getPath = (key) => resolve10(wxtDir, "cache", encodeURIComponent(key));
|
|
1568
1607
|
return {
|
|
1569
1608
|
async set(key, value) {
|
|
1570
1609
|
const path8 = getPath(key);
|
|
@@ -1584,35 +1623,25 @@ function createFsCache(wxtDir) {
|
|
|
1584
1623
|
|
|
1585
1624
|
// src/core/utils/building/resolve-config.ts
|
|
1586
1625
|
import defu from "defu";
|
|
1587
|
-
|
|
1588
|
-
// src/core/utils/package.ts
|
|
1589
|
-
import { resolve as resolve10 } from "node:path";
|
|
1590
1626
|
import fs8 from "fs-extra";
|
|
1591
|
-
async function getPackageJson() {
|
|
1592
|
-
const file = resolve10(wxt.config.root, "package.json");
|
|
1593
|
-
try {
|
|
1594
|
-
return await fs8.readJson(file);
|
|
1595
|
-
} catch (err) {
|
|
1596
|
-
wxt.logger.debug(
|
|
1597
|
-
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
1598
|
-
);
|
|
1599
|
-
return {};
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
function isModuleInstalled(name) {
|
|
1603
|
-
return import(
|
|
1604
|
-
/* @vite-ignore */
|
|
1605
|
-
name
|
|
1606
|
-
).then(() => true).catch(() => false);
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
|
-
// src/core/utils/building/resolve-config.ts
|
|
1610
|
-
import fs9 from "fs-extra";
|
|
1611
1627
|
import glob3 from "fast-glob";
|
|
1612
1628
|
|
|
1613
1629
|
// src/builtin-modules/index.ts
|
|
1614
1630
|
var builtinModules = [unimport_default];
|
|
1615
1631
|
|
|
1632
|
+
// src/core/utils/eslint.ts
|
|
1633
|
+
async function getEslintVersion() {
|
|
1634
|
+
try {
|
|
1635
|
+
const require2 = (await import("node:module")).default.createRequire(
|
|
1636
|
+
import.meta.url
|
|
1637
|
+
);
|
|
1638
|
+
const { ESLint } = require2("eslint");
|
|
1639
|
+
return ESLint.version?.split(".") ?? [];
|
|
1640
|
+
} catch (error) {
|
|
1641
|
+
return [];
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1616
1645
|
// src/core/utils/building/resolve-config.ts
|
|
1617
1646
|
async function resolveConfig(inlineConfig, command) {
|
|
1618
1647
|
let userConfig = {};
|
|
@@ -1727,7 +1756,7 @@ async function resolveConfig(inlineConfig, command) {
|
|
|
1727
1756
|
srcDir,
|
|
1728
1757
|
typesDir,
|
|
1729
1758
|
wxtDir,
|
|
1730
|
-
zip: resolveZipConfig(root, mergedConfig),
|
|
1759
|
+
zip: resolveZipConfig(root, outBaseDir, mergedConfig),
|
|
1731
1760
|
transformManifest: mergedConfig.transformManifest,
|
|
1732
1761
|
analysis: resolveAnalysisConfig(root, mergedConfig),
|
|
1733
1762
|
userConfigMetadata: userConfigMetadata ?? {},
|
|
@@ -1772,7 +1801,7 @@ async function mergeInlineConfig(inlineConfig, userConfig) {
|
|
|
1772
1801
|
...builderConfig
|
|
1773
1802
|
};
|
|
1774
1803
|
}
|
|
1775
|
-
function resolveZipConfig(root, mergedConfig) {
|
|
1804
|
+
function resolveZipConfig(root, outBaseDir, mergedConfig) {
|
|
1776
1805
|
const downloadedPackagesDir = path5.resolve(root, ".wxt/local_modules");
|
|
1777
1806
|
return {
|
|
1778
1807
|
name: void 0,
|
|
@@ -1791,6 +1820,8 @@ function resolveZipConfig(root, mergedConfig) {
|
|
|
1791
1820
|
// Tests
|
|
1792
1821
|
"**/__tests__/**",
|
|
1793
1822
|
"**/*.+(test|spec).?(c|m)+(j|t)s?(x)",
|
|
1823
|
+
// Output directory
|
|
1824
|
+
`${path5.relative(root, outBaseDir)}/**`,
|
|
1794
1825
|
// From user
|
|
1795
1826
|
...mergedConfig.zip?.excludeSources ?? []
|
|
1796
1827
|
],
|
|
@@ -1817,16 +1848,6 @@ function resolveAnalysisConfig(root, mergedConfig) {
|
|
|
1817
1848
|
}
|
|
1818
1849
|
async function getUnimportOptions(wxtDir, srcDir, logger, config) {
|
|
1819
1850
|
if (config.imports === false) return false;
|
|
1820
|
-
const rawEslintEnabled = config.imports?.eslintrc?.enabled;
|
|
1821
|
-
let eslintEnabled;
|
|
1822
|
-
switch (rawEslintEnabled) {
|
|
1823
|
-
case void 0:
|
|
1824
|
-
case "auto":
|
|
1825
|
-
eslintEnabled = await isModuleInstalled("eslint");
|
|
1826
|
-
break;
|
|
1827
|
-
default:
|
|
1828
|
-
eslintEnabled = rawEslintEnabled;
|
|
1829
|
-
}
|
|
1830
1851
|
const defaultOptions = {
|
|
1831
1852
|
debugLog: logger.debug,
|
|
1832
1853
|
imports: [
|
|
@@ -1844,23 +1865,45 @@ async function getUnimportOptions(wxtDir, srcDir, logger, config) {
|
|
|
1844
1865
|
dirsScanOptions: {
|
|
1845
1866
|
cwd: srcDir
|
|
1846
1867
|
},
|
|
1847
|
-
eslintrc:
|
|
1848
|
-
enabled: eslintEnabled,
|
|
1849
|
-
filePath: path5.resolve(wxtDir, "eslintrc-auto-import.json"),
|
|
1850
|
-
globalsPropValue: true
|
|
1851
|
-
}
|
|
1868
|
+
eslintrc: await getUnimportEslintOptions(wxtDir, config.imports?.eslintrc)
|
|
1852
1869
|
};
|
|
1853
1870
|
return defu(
|
|
1854
1871
|
config.imports ?? {},
|
|
1855
1872
|
defaultOptions
|
|
1856
1873
|
);
|
|
1857
1874
|
}
|
|
1875
|
+
async function getUnimportEslintOptions(wxtDir, options) {
|
|
1876
|
+
const rawEslintEnabled = options?.enabled ?? "auto";
|
|
1877
|
+
let eslintEnabled;
|
|
1878
|
+
switch (rawEslintEnabled) {
|
|
1879
|
+
case "auto":
|
|
1880
|
+
const version2 = await getEslintVersion();
|
|
1881
|
+
let major = parseInt(version2[0]);
|
|
1882
|
+
if (major <= 8) eslintEnabled = 8;
|
|
1883
|
+
else if (major >= 9) eslintEnabled = 9;
|
|
1884
|
+
else eslintEnabled = 8;
|
|
1885
|
+
break;
|
|
1886
|
+
case true:
|
|
1887
|
+
eslintEnabled = 8;
|
|
1888
|
+
break;
|
|
1889
|
+
default:
|
|
1890
|
+
eslintEnabled = rawEslintEnabled;
|
|
1891
|
+
}
|
|
1892
|
+
return {
|
|
1893
|
+
enabled: eslintEnabled,
|
|
1894
|
+
filePath: path5.resolve(
|
|
1895
|
+
wxtDir,
|
|
1896
|
+
eslintEnabled === 9 ? "eslint-auto-imports.mjs" : "eslintrc-auto-import.json"
|
|
1897
|
+
),
|
|
1898
|
+
globalsPropValue: true
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1858
1901
|
async function resolveWxtModuleDir() {
|
|
1859
1902
|
const requireResolve = __require?.resolve ?? (await import("node:module")).default.createRequire(import.meta.url).resolve;
|
|
1860
1903
|
return path5.resolve(requireResolve("wxt"), "../..");
|
|
1861
1904
|
}
|
|
1862
1905
|
async function isDirMissing(dir) {
|
|
1863
|
-
return !await
|
|
1906
|
+
return !await fs8.exists(dir);
|
|
1864
1907
|
}
|
|
1865
1908
|
function logMissingDir(logger, name, expected) {
|
|
1866
1909
|
logger.warn(
|
|
@@ -1975,7 +2018,7 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
|
|
|
1975
2018
|
// src/core/utils/building/import-entrypoint.ts
|
|
1976
2019
|
import createJITI from "jiti";
|
|
1977
2020
|
import { createUnimport as createUnimport2 } from "unimport";
|
|
1978
|
-
import
|
|
2021
|
+
import fs9 from "fs-extra";
|
|
1979
2022
|
import { relative as relative5, resolve as resolve11 } from "node:path";
|
|
1980
2023
|
import { transformSync } from "esbuild";
|
|
1981
2024
|
import { fileURLToPath } from "node:url";
|
|
@@ -1988,7 +2031,7 @@ async function importEntrypointFile(path8) {
|
|
|
1988
2031
|
dirs: []
|
|
1989
2032
|
});
|
|
1990
2033
|
await unimport.init();
|
|
1991
|
-
const text = await
|
|
2034
|
+
const text = await fs9.readFile(path8, "utf-8");
|
|
1992
2035
|
const textNoImports = removeProjectImportStatements(text);
|
|
1993
2036
|
const { code } = await unimport.injectImports(textNoImports);
|
|
1994
2037
|
wxt.logger.debug(
|
|
@@ -2004,6 +2047,13 @@ async function importEntrypointFile(path8) {
|
|
|
2004
2047
|
"webextension-polyfill": resolve11(
|
|
2005
2048
|
wxt.config.wxtModuleDir,
|
|
2006
2049
|
"dist/virtual/mock-browser.js"
|
|
2050
|
+
),
|
|
2051
|
+
// TODO: Resolve this virtual module to some file with
|
|
2052
|
+
// `export default {}` instead of this hack of using another file with
|
|
2053
|
+
// a default export.
|
|
2054
|
+
"virtual:app-config": resolve11(
|
|
2055
|
+
wxt.config.wxtModuleDir,
|
|
2056
|
+
"dist/virtual/mock-browser.js"
|
|
2007
2057
|
)
|
|
2008
2058
|
},
|
|
2009
2059
|
// Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
|
|
@@ -2071,7 +2121,7 @@ import { resolve as resolve12 } from "path";
|
|
|
2071
2121
|
// src/core/utils/log/printFileList.ts
|
|
2072
2122
|
import path6 from "node:path";
|
|
2073
2123
|
import pc3 from "picocolors";
|
|
2074
|
-
import
|
|
2124
|
+
import fs10 from "fs-extra";
|
|
2075
2125
|
import { filesize } from "filesize";
|
|
2076
2126
|
|
|
2077
2127
|
// src/core/utils/log/printTable.ts
|
|
@@ -2109,7 +2159,7 @@ async function printFileList(log, header, baseDir, files) {
|
|
|
2109
2159
|
];
|
|
2110
2160
|
const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
2111
2161
|
const color = getChunkColor(file);
|
|
2112
|
-
const stats = await
|
|
2162
|
+
const stats = await fs10.lstat(file);
|
|
2113
2163
|
totalSize += stats.size;
|
|
2114
2164
|
const size = String(filesize(stats.size));
|
|
2115
2165
|
return [
|
|
@@ -2176,7 +2226,7 @@ import glob4 from "fast-glob";
|
|
|
2176
2226
|
|
|
2177
2227
|
// src/core/utils/manifest.ts
|
|
2178
2228
|
import fs12 from "fs-extra";
|
|
2179
|
-
import { resolve as
|
|
2229
|
+
import { resolve as resolve14 } from "path";
|
|
2180
2230
|
|
|
2181
2231
|
// src/core/utils/content-security-policy.ts
|
|
2182
2232
|
var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
@@ -2280,12 +2330,27 @@ function getContentScriptJs(config, entrypoint) {
|
|
|
2280
2330
|
return [getEntrypointBundlePath(entrypoint, config.outDir, ".js")];
|
|
2281
2331
|
}
|
|
2282
2332
|
|
|
2333
|
+
// src/core/utils/package.ts
|
|
2334
|
+
import { resolve as resolve13 } from "node:path";
|
|
2335
|
+
import fs11 from "fs-extra";
|
|
2336
|
+
async function getPackageJson() {
|
|
2337
|
+
const file = resolve13(wxt.config.root, "package.json");
|
|
2338
|
+
try {
|
|
2339
|
+
return await fs11.readJson(file);
|
|
2340
|
+
} catch (err) {
|
|
2341
|
+
wxt.logger.debug(
|
|
2342
|
+
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
2343
|
+
);
|
|
2344
|
+
return {};
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2283
2348
|
// src/core/utils/manifest.ts
|
|
2284
2349
|
import defu2 from "defu";
|
|
2285
2350
|
async function writeManifest(manifest, output) {
|
|
2286
2351
|
const str = wxt.config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
2287
2352
|
await fs12.ensureDir(wxt.config.outDir);
|
|
2288
|
-
await writeFileIfDifferent(
|
|
2353
|
+
await writeFileIfDifferent(resolve14(wxt.config.outDir, "manifest.json"), str);
|
|
2289
2354
|
output.publicAssets.unshift({
|
|
2290
2355
|
type: "asset",
|
|
2291
2356
|
fileName: "manifest.json"
|
|
@@ -2967,12 +3032,12 @@ function printValidationResults({
|
|
|
2967
3032
|
return map;
|
|
2968
3033
|
}, /* @__PURE__ */ new Map());
|
|
2969
3034
|
Array.from(entrypointErrors.entries()).forEach(([entrypoint, errors2]) => {
|
|
2970
|
-
|
|
3035
|
+
wxt.logger.log(relative6(cwd, entrypoint.inputPath));
|
|
2971
3036
|
console.log();
|
|
2972
3037
|
errors2.forEach((err) => {
|
|
2973
3038
|
const type = err.type === "error" ? pc5.red("ERROR") : pc5.yellow("WARN");
|
|
2974
3039
|
const recieved = pc5.dim(`(recieved: ${JSON.stringify(err.value)})`);
|
|
2975
|
-
|
|
3040
|
+
wxt.logger.log(` - ${type} ${err.message} ${recieved}`);
|
|
2976
3041
|
});
|
|
2977
3042
|
console.log();
|
|
2978
3043
|
});
|
|
@@ -2998,7 +3063,7 @@ var npm = {
|
|
|
2998
3063
|
overridesKey: "overrides",
|
|
2999
3064
|
async downloadDependency(id, downloadDir) {
|
|
3000
3065
|
await ensureDir3(downloadDir);
|
|
3001
|
-
const { execa } = await import("./execa-
|
|
3066
|
+
const { execa } = await import("./execa-4UBDUBJZ.js");
|
|
3002
3067
|
const res = await execa("npm", ["pack", id, "--json"], {
|
|
3003
3068
|
cwd: downloadDir
|
|
3004
3069
|
});
|
|
@@ -3010,7 +3075,7 @@ var npm = {
|
|
|
3010
3075
|
if (options?.all) {
|
|
3011
3076
|
args.push("--depth", "Infinity");
|
|
3012
3077
|
}
|
|
3013
|
-
const { execa } = await import("./execa-
|
|
3078
|
+
const { execa } = await import("./execa-4UBDUBJZ.js");
|
|
3014
3079
|
const res = await execa("npm", args, { cwd: options?.cwd });
|
|
3015
3080
|
const project = JSON.parse(res.stdout);
|
|
3016
3081
|
return flattenNpmListOutput([project]);
|
|
@@ -3063,7 +3128,7 @@ var bun = {
|
|
|
3063
3128
|
if (options?.all) {
|
|
3064
3129
|
args.push("--all");
|
|
3065
3130
|
}
|
|
3066
|
-
const { execa } = await import("./execa-
|
|
3131
|
+
const { execa } = await import("./execa-4UBDUBJZ.js");
|
|
3067
3132
|
const res = await execa("bun", args, { cwd: options?.cwd });
|
|
3068
3133
|
return dedupeDependencies(
|
|
3069
3134
|
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 }))
|
|
@@ -3082,7 +3147,7 @@ var yarn = {
|
|
|
3082
3147
|
if (options?.all) {
|
|
3083
3148
|
args.push("--depth", "Infinity");
|
|
3084
3149
|
}
|
|
3085
|
-
const { execa } = await import("./execa-
|
|
3150
|
+
const { execa } = await import("./execa-4UBDUBJZ.js");
|
|
3086
3151
|
const res = await execa("yarn", args, { cwd: options?.cwd });
|
|
3087
3152
|
const tree = res.stdout.split("\n").map((line) => JSON.parse(line)).find((line) => line.type === "tree")?.data;
|
|
3088
3153
|
if (tree == null) throw Error("'yarn list --json' did not output a tree");
|
|
@@ -3118,7 +3183,7 @@ var pnpm = {
|
|
|
3118
3183
|
if (typeof process !== "undefined" && process.env.WXT_PNPM_IGNORE_WORKSPACE === "true") {
|
|
3119
3184
|
args.push("--ignore-workspace");
|
|
3120
3185
|
}
|
|
3121
|
-
const { execa } = await import("./execa-
|
|
3186
|
+
const { execa } = await import("./execa-4UBDUBJZ.js");
|
|
3122
3187
|
const res = await execa("pnpm", args, { cwd: options?.cwd });
|
|
3123
3188
|
const projects = JSON.parse(res.stdout);
|
|
3124
3189
|
return flattenNpmListOutput(projects);
|
|
@@ -3214,7 +3279,8 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
3214
3279
|
globals(wxtConfig),
|
|
3215
3280
|
excludeBrowserPolyfill(wxtConfig),
|
|
3216
3281
|
defineImportMeta(),
|
|
3217
|
-
wxtPluginLoader(wxtConfig)
|
|
3282
|
+
wxtPluginLoader(wxtConfig),
|
|
3283
|
+
resolveAppConfig(wxtConfig)
|
|
3218
3284
|
);
|
|
3219
3285
|
if (wxtConfig.analysis.enabled) {
|
|
3220
3286
|
config.plugins.push(bundleAnalysis(wxtConfig));
|
|
@@ -3366,7 +3432,10 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
3366
3432
|
const config = vite.mergeConfig(baseConfig, envConfig);
|
|
3367
3433
|
const server2 = await vite.createServer(config);
|
|
3368
3434
|
await server2.pluginContainer.buildStart({});
|
|
3369
|
-
const node = new ViteNodeServer(
|
|
3435
|
+
const node = new ViteNodeServer(
|
|
3436
|
+
// @ts-ignore: Some weird type error...
|
|
3437
|
+
server2
|
|
3438
|
+
);
|
|
3370
3439
|
installSourcemapsSupport({
|
|
3371
3440
|
getSourceMap: (source) => node.getSourceMap(source)
|
|
3372
3441
|
});
|
|
@@ -3512,6 +3581,7 @@ export {
|
|
|
3512
3581
|
tsconfigPaths,
|
|
3513
3582
|
globals,
|
|
3514
3583
|
webextensionPolyfillMock,
|
|
3584
|
+
resolveAppConfig,
|
|
3515
3585
|
kebabCaseAlphanumeric,
|
|
3516
3586
|
vitePlugin,
|
|
3517
3587
|
wxt,
|
|
@@ -3519,12 +3589,12 @@ export {
|
|
|
3519
3589
|
detectDevChanges,
|
|
3520
3590
|
findEntrypoints,
|
|
3521
3591
|
generateTypesDir,
|
|
3522
|
-
getPackageJson,
|
|
3523
3592
|
resolveConfig,
|
|
3524
3593
|
printFileList,
|
|
3525
3594
|
version,
|
|
3526
3595
|
mapWxtOptionsToRegisteredContentScript,
|
|
3527
3596
|
getContentScriptJs,
|
|
3597
|
+
getPackageJson,
|
|
3528
3598
|
getContentScriptCssFiles,
|
|
3529
3599
|
getContentScriptsCssMap,
|
|
3530
3600
|
rebuild,
|