wxt 0.17.13-alpha1 → 0.18.0
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-YWGLK5GM.js → chunk-A7YRDAFI.js} +214 -145
- package/dist/chunk-NAMV4VWQ.js +1065 -0
- package/dist/chunk-ZZCTFNQ5.js +1063 -0
- package/dist/cli.js +319 -229
- package/dist/client.d.ts +1 -1
- package/dist/{execa-Y2EWTC4S.js → execa-6HO2IY2B.js} +62 -62
- package/dist/{execa-4F7CCWCA.js → execa-VDW6HLFV.js} +62 -62
- package/dist/{index-INepal5k.d.cts → index-DKN-8I90.d.cts} +14 -0
- package/dist/{index-INepal5k.d.ts → index-DKN-8I90.d.ts} +14 -0
- package/dist/index.cjs +2363 -400
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +15 -15
- package/dist/prompt-TFJ7OLL7.js +781 -0
- package/dist/prompt-Y7B5HSD5.js +782 -0
- package/dist/sandbox.d.ts +1 -1
- package/dist/testing.cjs +1950 -57
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +2 -1
- package/package.json +6 -40
- /package/dist/{index-Aan1uu3v.d.ts → index-CiL7hzu6.d.ts} +0 -0
|
@@ -3,12 +3,16 @@ import {
|
|
|
3
3
|
some,
|
|
4
4
|
toArray
|
|
5
5
|
} from "./chunk-5X3S6AWF.js";
|
|
6
|
+
import {
|
|
7
|
+
LogLevels,
|
|
8
|
+
consola
|
|
9
|
+
} from "./chunk-ZZCTFNQ5.js";
|
|
6
10
|
import {
|
|
7
11
|
__require
|
|
8
12
|
} from "./chunk-VBXJIVYU.js";
|
|
9
13
|
|
|
10
14
|
// package.json
|
|
11
|
-
var version = "0.17.
|
|
15
|
+
var version = "0.17.12";
|
|
12
16
|
|
|
13
17
|
// src/core/utils/paths.ts
|
|
14
18
|
import systemPath from "node:path";
|
|
@@ -655,12 +659,44 @@ function defineImportMeta() {
|
|
|
655
659
|
};
|
|
656
660
|
}
|
|
657
661
|
|
|
662
|
+
// src/core/utils/transform.ts
|
|
663
|
+
import { parseModule } from "magicast";
|
|
664
|
+
function removeMainFunctionCode(code) {
|
|
665
|
+
const mod = parseModule(code);
|
|
666
|
+
emptyMainFunction(mod);
|
|
667
|
+
return mod.generate();
|
|
668
|
+
}
|
|
669
|
+
function emptyMainFunction(mod) {
|
|
670
|
+
if (mod.exports?.default?.$type === "function-call") {
|
|
671
|
+
if (mod.exports.default.$ast?.arguments?.[0]?.body) {
|
|
672
|
+
mod.exports.default.$ast.arguments[0].body.body = [];
|
|
673
|
+
} else if (mod.exports.default.$ast?.arguments?.[0]?.properties) {
|
|
674
|
+
mod.exports.default.$ast.arguments[0].properties = mod.exports.default.$ast.arguments[0].properties.filter(
|
|
675
|
+
(prop) => prop.key.name !== "main"
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// src/core/builders/vite/plugins/removeEntrypointMainFunction.ts
|
|
682
|
+
import { resolve as resolve5 } from "node:path";
|
|
683
|
+
function removeEntrypointMainFunction(config, path8) {
|
|
684
|
+
const absPath = normalizePath(resolve5(config.root, path8));
|
|
685
|
+
return {
|
|
686
|
+
name: "wxt:remove-entrypoint-main-function",
|
|
687
|
+
transform(code, id) {
|
|
688
|
+
if (id === absPath)
|
|
689
|
+
return removeMainFunctionCode(code);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
|
|
658
694
|
// src/core/utils/strings.ts
|
|
659
695
|
function kebabCaseAlphanumeric(str) {
|
|
660
696
|
return str.toLowerCase().replace(/[^a-z0-9-\s]/g, "").replace(/\s+/g, "-");
|
|
661
697
|
}
|
|
662
698
|
function safeVarName(str) {
|
|
663
|
-
return "_" + kebabCaseAlphanumeric(str).replace("-", "_");
|
|
699
|
+
return "_" + kebabCaseAlphanumeric(str.trim()).replace("-", "_");
|
|
664
700
|
}
|
|
665
701
|
function removeImportStatements(text) {
|
|
666
702
|
return text.replace(
|
|
@@ -693,7 +729,7 @@ async function getPublicFiles() {
|
|
|
693
729
|
|
|
694
730
|
// src/core/utils/building/build-entrypoints.ts
|
|
695
731
|
import fs4 from "fs-extra";
|
|
696
|
-
import { dirname as dirname3, resolve as
|
|
732
|
+
import { dirname as dirname3, resolve as resolve6 } from "path";
|
|
697
733
|
import pc from "picocolors";
|
|
698
734
|
async function buildEntrypoints(groups, spinner) {
|
|
699
735
|
const steps = [];
|
|
@@ -719,8 +755,8 @@ async function copyPublicDirectory() {
|
|
|
719
755
|
return [];
|
|
720
756
|
const publicAssets = [];
|
|
721
757
|
for (const file of files) {
|
|
722
|
-
const srcPath =
|
|
723
|
-
const outPath =
|
|
758
|
+
const srcPath = resolve6(wxt.config.publicDir, file);
|
|
759
|
+
const outPath = resolve6(wxt.config.outDir, file);
|
|
724
760
|
await fs4.ensureDir(dirname3(outPath));
|
|
725
761
|
await fs4.copyFile(srcPath, outPath);
|
|
726
762
|
publicAssets.push({
|
|
@@ -826,21 +862,114 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
826
862
|
}
|
|
827
863
|
|
|
828
864
|
// src/core/utils/building/find-entrypoints.ts
|
|
829
|
-
import { relative as
|
|
830
|
-
import
|
|
865
|
+
import { relative as relative4, resolve as resolve8 } from "path";
|
|
866
|
+
import fs6 from "fs-extra";
|
|
831
867
|
import { minimatch } from "minimatch";
|
|
832
868
|
import { parseHTML as parseHTML2 } from "linkedom";
|
|
833
869
|
import JSON5 from "json5";
|
|
834
870
|
import glob2 from "fast-glob";
|
|
835
871
|
import pc2 from "picocolors";
|
|
872
|
+
|
|
873
|
+
// src/core/utils/building/import-entrypoint.ts
|
|
874
|
+
import createJITI from "jiti";
|
|
875
|
+
import { createUnimport as createUnimport2 } from "unimport";
|
|
876
|
+
import fs5 from "fs-extra";
|
|
877
|
+
import { relative as relative3, resolve as resolve7 } from "node:path";
|
|
878
|
+
import { transformSync } from "esbuild";
|
|
879
|
+
import { fileURLToPath } from "node:url";
|
|
880
|
+
async function importEntrypointFile(path8) {
|
|
881
|
+
wxt.logger.debug("Loading file metadata:", path8);
|
|
882
|
+
const normalPath = normalizePath(path8);
|
|
883
|
+
const unimport2 = createUnimport2({
|
|
884
|
+
...wxt.config.imports,
|
|
885
|
+
// Only allow specific imports, not all from the project
|
|
886
|
+
dirs: []
|
|
887
|
+
});
|
|
888
|
+
await unimport2.init();
|
|
889
|
+
const text = await fs5.readFile(path8, "utf-8");
|
|
890
|
+
const textNoImports = removeProjectImportStatements(text);
|
|
891
|
+
const { code } = await unimport2.injectImports(textNoImports);
|
|
892
|
+
wxt.logger.debug(
|
|
893
|
+
["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
|
|
894
|
+
);
|
|
895
|
+
const jiti = createJITI(
|
|
896
|
+
typeof __filename !== "undefined" ? __filename : fileURLToPath(import.meta.url),
|
|
897
|
+
{
|
|
898
|
+
cache: false,
|
|
899
|
+
debug: wxt.config.debug,
|
|
900
|
+
esmResolve: true,
|
|
901
|
+
alias: {
|
|
902
|
+
"webextension-polyfill": resolve7(
|
|
903
|
+
wxt.config.wxtModuleDir,
|
|
904
|
+
"dist/virtual/mock-browser.js"
|
|
905
|
+
)
|
|
906
|
+
},
|
|
907
|
+
// Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
|
|
908
|
+
// respect the custom transform function when using it's native bun option.
|
|
909
|
+
experimentalBun: false,
|
|
910
|
+
// List of extensions to transform with esbuild
|
|
911
|
+
extensions: [
|
|
912
|
+
".ts",
|
|
913
|
+
".cts",
|
|
914
|
+
".mts",
|
|
915
|
+
".tsx",
|
|
916
|
+
".js",
|
|
917
|
+
".cjs",
|
|
918
|
+
".mjs",
|
|
919
|
+
".jsx"
|
|
920
|
+
],
|
|
921
|
+
transform(opts) {
|
|
922
|
+
const isEntrypoint = opts.filename === normalPath;
|
|
923
|
+
return transformSync(
|
|
924
|
+
// Use modified source code for entrypoints
|
|
925
|
+
isEntrypoint ? code : opts.source,
|
|
926
|
+
getEsbuildOptions(opts)
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
);
|
|
931
|
+
try {
|
|
932
|
+
const res = await jiti(path8);
|
|
933
|
+
return res.default;
|
|
934
|
+
} catch (err) {
|
|
935
|
+
const filePath = relative3(wxt.config.root, path8);
|
|
936
|
+
if (err instanceof ReferenceError) {
|
|
937
|
+
const variableName = err.message.replace(" is not defined", "");
|
|
938
|
+
throw Error(
|
|
939
|
+
`${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/entrypoints.html#side-effects`,
|
|
940
|
+
{ cause: err }
|
|
941
|
+
);
|
|
942
|
+
} else {
|
|
943
|
+
wxt.logger.error(err);
|
|
944
|
+
throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
function getEsbuildOptions(opts) {
|
|
949
|
+
const isJsx = opts.filename?.endsWith("x");
|
|
950
|
+
return {
|
|
951
|
+
format: "cjs",
|
|
952
|
+
loader: isJsx ? "tsx" : "ts",
|
|
953
|
+
...isJsx ? {
|
|
954
|
+
// `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
|
|
955
|
+
// grabbing the entrypoint's options.
|
|
956
|
+
jsxFactory: "h",
|
|
957
|
+
jsxFragment: "Fragment"
|
|
958
|
+
} : void 0
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// src/core/utils/building/find-entrypoints.ts
|
|
836
963
|
async function findEntrypoints() {
|
|
964
|
+
await fs6.mkdir(wxt.config.wxtDir, { recursive: true });
|
|
965
|
+
await fs6.writeJson(resolve8(wxt.config.wxtDir, "tsconfig.json"), {});
|
|
837
966
|
const relativePaths = await glob2(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
|
|
838
967
|
cwd: wxt.config.entrypointsDir
|
|
839
968
|
});
|
|
840
969
|
relativePaths.sort();
|
|
841
970
|
const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
|
|
842
971
|
const entrypointInfos = relativePaths.reduce((results, relativePath) => {
|
|
843
|
-
const inputPath =
|
|
972
|
+
const inputPath = resolve8(wxt.config.entrypointsDir, relativePath);
|
|
844
973
|
const name = getEntrypointName(wxt.config.entrypointsDir, inputPath);
|
|
845
974
|
const matchingGlob = pathGlobs.find(
|
|
846
975
|
(glob4) => minimatch(relativePath, glob4)
|
|
@@ -882,7 +1011,7 @@ async function findEntrypoints() {
|
|
|
882
1011
|
return {
|
|
883
1012
|
...info,
|
|
884
1013
|
type,
|
|
885
|
-
outputDir:
|
|
1014
|
+
outputDir: resolve8(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
886
1015
|
options: {
|
|
887
1016
|
include: void 0,
|
|
888
1017
|
exclude: void 0
|
|
@@ -956,7 +1085,7 @@ function preventDuplicateEntrypointNames(files) {
|
|
|
956
1085
|
if (absolutePaths.length > 1) {
|
|
957
1086
|
lines.push(`- ${name}`);
|
|
958
1087
|
absolutePaths.forEach((absolutePath) => {
|
|
959
|
-
lines.push(` - ${
|
|
1088
|
+
lines.push(` - ${relative4(wxt.config.root, absolutePath)}`);
|
|
960
1089
|
});
|
|
961
1090
|
}
|
|
962
1091
|
return lines;
|
|
@@ -1044,7 +1173,7 @@ async function getUnlistedScriptEntrypoint({
|
|
|
1044
1173
|
name,
|
|
1045
1174
|
skipped
|
|
1046
1175
|
}) {
|
|
1047
|
-
const defaultExport = await
|
|
1176
|
+
const defaultExport = await importEntrypoint(inputPath);
|
|
1048
1177
|
if (defaultExport == null) {
|
|
1049
1178
|
throw Error(
|
|
1050
1179
|
`${name}: Default export not found, did you forget to call "export default defineUnlistedScript(...)"?`
|
|
@@ -1067,7 +1196,7 @@ async function getBackgroundEntrypoint({
|
|
|
1067
1196
|
}) {
|
|
1068
1197
|
let options = {};
|
|
1069
1198
|
if (inputPath !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
|
|
1070
|
-
const defaultExport = await
|
|
1199
|
+
const defaultExport = await importEntrypoint(inputPath);
|
|
1071
1200
|
if (defaultExport == null) {
|
|
1072
1201
|
throw Error(
|
|
1073
1202
|
`${name}: Default export not found, did you forget to call "export default defineBackground(...)"?`
|
|
@@ -1093,7 +1222,7 @@ async function getContentScriptEntrypoint({
|
|
|
1093
1222
|
name,
|
|
1094
1223
|
skipped
|
|
1095
1224
|
}) {
|
|
1096
|
-
const { main: _, ...options } = await
|
|
1225
|
+
const { main: _, ...options } = await importEntrypoint(inputPath);
|
|
1097
1226
|
if (options == null) {
|
|
1098
1227
|
throw Error(
|
|
1099
1228
|
`${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
|
|
@@ -1103,7 +1232,7 @@ async function getContentScriptEntrypoint({
|
|
|
1103
1232
|
type: "content-script",
|
|
1104
1233
|
name,
|
|
1105
1234
|
inputPath,
|
|
1106
|
-
outputDir:
|
|
1235
|
+
outputDir: resolve8(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
1107
1236
|
options: resolvePerBrowserOptions(options, wxt.config.browser),
|
|
1108
1237
|
skipped
|
|
1109
1238
|
};
|
|
@@ -1136,7 +1265,7 @@ async function getSidepanelEntrypoint(info) {
|
|
|
1136
1265
|
};
|
|
1137
1266
|
}
|
|
1138
1267
|
async function getHtmlEntrypointOptions(info, keyMap, queries, parsers) {
|
|
1139
|
-
const content = await
|
|
1268
|
+
const content = await fs6.readFile(info.inputPath, "utf-8");
|
|
1140
1269
|
const { document } = parseHTML2(content);
|
|
1141
1270
|
const options = {};
|
|
1142
1271
|
const defaultQuery = (manifestKey) => document.querySelector(`meta[name='manifest.${manifestKey}']`)?.getAttribute("content");
|
|
@@ -1196,11 +1325,14 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
1196
1325
|
[`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
|
|
1197
1326
|
};
|
|
1198
1327
|
var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|
|
1328
|
+
function importEntrypoint(path8) {
|
|
1329
|
+
return wxt.config.experimental.viteRuntime ? wxt.builder.importEntrypoint(path8) : importEntrypointFile(path8);
|
|
1330
|
+
}
|
|
1199
1331
|
|
|
1200
1332
|
// src/core/utils/building/generate-wxt-dir.ts
|
|
1201
|
-
import { createUnimport as
|
|
1202
|
-
import
|
|
1203
|
-
import { relative as
|
|
1333
|
+
import { createUnimport as createUnimport3 } from "unimport";
|
|
1334
|
+
import fs7 from "fs-extra";
|
|
1335
|
+
import { relative as relative5, resolve as resolve9 } from "path";
|
|
1204
1336
|
import path4 from "node:path";
|
|
1205
1337
|
|
|
1206
1338
|
// src/core/utils/i18n.ts
|
|
@@ -1242,10 +1374,10 @@ function parseI18nMessages(messagesJson) {
|
|
|
1242
1374
|
|
|
1243
1375
|
// src/core/utils/building/generate-wxt-dir.ts
|
|
1244
1376
|
async function generateTypesDir(entrypoints) {
|
|
1245
|
-
await
|
|
1377
|
+
await fs7.ensureDir(wxt.config.typesDir);
|
|
1246
1378
|
const references = [];
|
|
1247
1379
|
if (wxt.config.imports !== false) {
|
|
1248
|
-
const unimport2 =
|
|
1380
|
+
const unimport2 = createUnimport3(wxt.config.imports);
|
|
1249
1381
|
references.push(await writeImportsDeclarationFile(unimport2));
|
|
1250
1382
|
if (wxt.config.imports.eslintrc.enabled) {
|
|
1251
1383
|
await writeImportsEslintFile(unimport2, wxt.config.imports);
|
|
@@ -1258,7 +1390,7 @@ async function generateTypesDir(entrypoints) {
|
|
|
1258
1390
|
await writeTsConfigFile(mainReference);
|
|
1259
1391
|
}
|
|
1260
1392
|
async function writeImportsDeclarationFile(unimport2) {
|
|
1261
|
-
const filePath =
|
|
1393
|
+
const filePath = resolve9(wxt.config.typesDir, "imports.d.ts");
|
|
1262
1394
|
await unimport2.scanImportsFromDir(void 0, { cwd: wxt.config.srcDir });
|
|
1263
1395
|
await writeFileIfDifferent(
|
|
1264
1396
|
filePath,
|
|
@@ -1274,10 +1406,10 @@ async function writeImportsEslintFile(unimport2, options) {
|
|
|
1274
1406
|
(await unimport2.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().forEach((name) => {
|
|
1275
1407
|
eslintrc.globals[name] = options.eslintrc.globalsPropValue;
|
|
1276
1408
|
});
|
|
1277
|
-
await
|
|
1409
|
+
await fs7.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
|
|
1278
1410
|
}
|
|
1279
1411
|
async function writePathsDeclarationFile(entrypoints) {
|
|
1280
|
-
const filePath =
|
|
1412
|
+
const filePath = resolve9(wxt.config.typesDir, "paths.d.ts");
|
|
1281
1413
|
const unions = entrypoints.map(
|
|
1282
1414
|
(entry) => getEntrypointBundlePath(
|
|
1283
1415
|
entry,
|
|
@@ -1305,7 +1437,7 @@ declare module "wxt/browser" {
|
|
|
1305
1437
|
return filePath;
|
|
1306
1438
|
}
|
|
1307
1439
|
async function writeI18nDeclarationFile() {
|
|
1308
|
-
const filePath =
|
|
1440
|
+
const filePath = resolve9(wxt.config.typesDir, "i18n.d.ts");
|
|
1309
1441
|
const defaultLocale = wxt.config.manifest.default_locale;
|
|
1310
1442
|
const template = `// Generated by wxt
|
|
1311
1443
|
import "wxt/browser";
|
|
@@ -1334,7 +1466,7 @@ declare module "wxt/browser" {
|
|
|
1334
1466
|
defaultLocale,
|
|
1335
1467
|
"messages.json"
|
|
1336
1468
|
);
|
|
1337
|
-
const content = JSON.parse(await
|
|
1469
|
+
const content = JSON.parse(await fs7.readFile(defaultLocalePath, "utf-8"));
|
|
1338
1470
|
messages = parseI18nMessages(content);
|
|
1339
1471
|
} else {
|
|
1340
1472
|
messages = parseI18nMessages({});
|
|
@@ -1358,7 +1490,7 @@ declare module "wxt/browser" {
|
|
|
1358
1490
|
return filePath;
|
|
1359
1491
|
}
|
|
1360
1492
|
async function writeGlobalsDeclarationFile() {
|
|
1361
|
-
const filePath =
|
|
1493
|
+
const filePath = resolve9(wxt.config.typesDir, "globals.d.ts");
|
|
1362
1494
|
const globals2 = [...getGlobals(wxt.config), ...getEntrypointGlobals("")];
|
|
1363
1495
|
await writeFileIfDifferent(
|
|
1364
1496
|
filePath,
|
|
@@ -1377,14 +1509,14 @@ async function writeGlobalsDeclarationFile() {
|
|
|
1377
1509
|
}
|
|
1378
1510
|
async function writeMainDeclarationFile(references) {
|
|
1379
1511
|
const dir = wxt.config.wxtDir;
|
|
1380
|
-
const filePath =
|
|
1512
|
+
const filePath = resolve9(dir, "wxt.d.ts");
|
|
1381
1513
|
await writeFileIfDifferent(
|
|
1382
1514
|
filePath,
|
|
1383
1515
|
[
|
|
1384
1516
|
"// Generated by wxt",
|
|
1385
1517
|
`/// <reference types="wxt/vite-builder-env" />`,
|
|
1386
1518
|
...references.map(
|
|
1387
|
-
(ref) => `/// <reference types="./${normalizePath(
|
|
1519
|
+
(ref) => `/// <reference types="./${normalizePath(relative5(dir, ref))}" />`
|
|
1388
1520
|
)
|
|
1389
1521
|
].join("\n") + "\n"
|
|
1390
1522
|
);
|
|
@@ -1392,7 +1524,7 @@ async function writeMainDeclarationFile(references) {
|
|
|
1392
1524
|
}
|
|
1393
1525
|
async function writeTsConfigFile(mainReference) {
|
|
1394
1526
|
const dir = wxt.config.wxtDir;
|
|
1395
|
-
const getTsconfigPath = (path8) => normalizePath(
|
|
1527
|
+
const getTsconfigPath = (path8) => normalizePath(relative5(dir, path8));
|
|
1396
1528
|
const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
|
|
1397
1529
|
const aliasPath = getTsconfigPath(absolutePath);
|
|
1398
1530
|
return [
|
|
@@ -1401,7 +1533,7 @@ async function writeTsConfigFile(mainReference) {
|
|
|
1401
1533
|
];
|
|
1402
1534
|
}).join(",\n");
|
|
1403
1535
|
await writeFileIfDifferent(
|
|
1404
|
-
|
|
1536
|
+
resolve9(dir, "tsconfig.json"),
|
|
1405
1537
|
`{
|
|
1406
1538
|
"compilerOptions": {
|
|
1407
1539
|
"target": "ESNext",
|
|
@@ -1431,10 +1563,10 @@ import { loadConfig } from "c12";
|
|
|
1431
1563
|
import path5 from "node:path";
|
|
1432
1564
|
|
|
1433
1565
|
// src/core/utils/cache.ts
|
|
1434
|
-
import
|
|
1435
|
-
import { dirname as dirname4, resolve as
|
|
1566
|
+
import fs8, { ensureDir as ensureDir2 } from "fs-extra";
|
|
1567
|
+
import { dirname as dirname4, resolve as resolve10 } from "path";
|
|
1436
1568
|
function createFsCache(wxtDir) {
|
|
1437
|
-
const getPath = (key) =>
|
|
1569
|
+
const getPath = (key) => resolve10(wxtDir, "cache", encodeURIComponent(key));
|
|
1438
1570
|
return {
|
|
1439
1571
|
async set(key, value) {
|
|
1440
1572
|
const path8 = getPath(key);
|
|
@@ -1444,7 +1576,7 @@ function createFsCache(wxtDir) {
|
|
|
1444
1576
|
async get(key) {
|
|
1445
1577
|
const path8 = getPath(key);
|
|
1446
1578
|
try {
|
|
1447
|
-
return await
|
|
1579
|
+
return await fs8.readFile(path8, "utf-8");
|
|
1448
1580
|
} catch {
|
|
1449
1581
|
return void 0;
|
|
1450
1582
|
}
|
|
@@ -1453,16 +1585,15 @@ function createFsCache(wxtDir) {
|
|
|
1453
1585
|
}
|
|
1454
1586
|
|
|
1455
1587
|
// src/core/utils/building/resolve-config.ts
|
|
1456
|
-
import consola, { LogLevels } from "consola";
|
|
1457
1588
|
import defu from "defu";
|
|
1458
1589
|
|
|
1459
1590
|
// src/core/utils/package.ts
|
|
1460
|
-
import { resolve as
|
|
1461
|
-
import
|
|
1591
|
+
import { resolve as resolve11 } from "node:path";
|
|
1592
|
+
import fs9 from "fs-extra";
|
|
1462
1593
|
async function getPackageJson() {
|
|
1463
|
-
const file =
|
|
1594
|
+
const file = resolve11(wxt.config.root, "package.json");
|
|
1464
1595
|
try {
|
|
1465
|
-
return await
|
|
1596
|
+
return await fs9.readJson(file);
|
|
1466
1597
|
} catch (err) {
|
|
1467
1598
|
wxt.logger.debug(
|
|
1468
1599
|
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
@@ -1471,11 +1602,14 @@ async function getPackageJson() {
|
|
|
1471
1602
|
}
|
|
1472
1603
|
}
|
|
1473
1604
|
function isModuleInstalled(name) {
|
|
1474
|
-
return import(
|
|
1605
|
+
return import(
|
|
1606
|
+
/* @vite-ignore */
|
|
1607
|
+
name
|
|
1608
|
+
).then(() => true).catch(() => false);
|
|
1475
1609
|
}
|
|
1476
1610
|
|
|
1477
1611
|
// src/core/utils/building/resolve-config.ts
|
|
1478
|
-
import
|
|
1612
|
+
import fs10 from "fs-extra";
|
|
1479
1613
|
async function resolveConfig(inlineConfig, command) {
|
|
1480
1614
|
let userConfig = {};
|
|
1481
1615
|
let userConfigMetadata;
|
|
@@ -1580,7 +1714,8 @@ async function resolveConfig(inlineConfig, command) {
|
|
|
1580
1714
|
userConfigMetadata: userConfigMetadata ?? {},
|
|
1581
1715
|
alias,
|
|
1582
1716
|
experimental: defu(mergedConfig.experimental, {
|
|
1583
|
-
includeBrowserPolyfill: true
|
|
1717
|
+
includeBrowserPolyfill: true,
|
|
1718
|
+
viteRuntime: false
|
|
1584
1719
|
}),
|
|
1585
1720
|
dev: {
|
|
1586
1721
|
server: devServerConfig,
|
|
@@ -1700,7 +1835,7 @@ async function resolveWxtModuleDir() {
|
|
|
1700
1835
|
return path5.resolve(requireResolve("wxt"), "../..");
|
|
1701
1836
|
}
|
|
1702
1837
|
async function isDirMissing(dir) {
|
|
1703
|
-
return !await
|
|
1838
|
+
return !await fs10.exists(dir);
|
|
1704
1839
|
}
|
|
1705
1840
|
function logMissingDir(logger, name, expected) {
|
|
1706
1841
|
logger.warn(
|
|
@@ -1766,101 +1901,12 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
|
|
|
1766
1901
|
"content-script-style": "individual"
|
|
1767
1902
|
};
|
|
1768
1903
|
|
|
1769
|
-
// src/core/utils/building/import-entrypoint.ts
|
|
1770
|
-
import createJITI from "jiti";
|
|
1771
|
-
import { createUnimport as createUnimport3 } from "unimport";
|
|
1772
|
-
import fs10 from "fs-extra";
|
|
1773
|
-
import { relative as relative5, resolve as resolve10 } from "node:path";
|
|
1774
|
-
import { transformSync } from "esbuild";
|
|
1775
|
-
import { fileURLToPath } from "node:url";
|
|
1776
|
-
async function importEntrypointFile(path8) {
|
|
1777
|
-
wxt.logger.debug("Loading file metadata:", path8);
|
|
1778
|
-
const normalPath = normalizePath(path8);
|
|
1779
|
-
const unimport2 = createUnimport3({
|
|
1780
|
-
...wxt.config.imports,
|
|
1781
|
-
// Only allow specific imports, not all from the project
|
|
1782
|
-
dirs: []
|
|
1783
|
-
});
|
|
1784
|
-
await unimport2.init();
|
|
1785
|
-
const text = await fs10.readFile(path8, "utf-8");
|
|
1786
|
-
const textNoImports = removeProjectImportStatements(text);
|
|
1787
|
-
const { code } = await unimport2.injectImports(textNoImports);
|
|
1788
|
-
wxt.logger.debug(
|
|
1789
|
-
["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
|
|
1790
|
-
);
|
|
1791
|
-
const jiti = createJITI(
|
|
1792
|
-
typeof __filename !== "undefined" ? __filename : fileURLToPath(import.meta.url),
|
|
1793
|
-
{
|
|
1794
|
-
cache: false,
|
|
1795
|
-
debug: wxt.config.debug,
|
|
1796
|
-
esmResolve: true,
|
|
1797
|
-
alias: {
|
|
1798
|
-
"webextension-polyfill": resolve10(
|
|
1799
|
-
wxt.config.wxtModuleDir,
|
|
1800
|
-
"dist/virtual/mock-browser.js"
|
|
1801
|
-
)
|
|
1802
|
-
},
|
|
1803
|
-
// Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
|
|
1804
|
-
// respect the custom transform function when using it's native bun option.
|
|
1805
|
-
experimentalBun: false,
|
|
1806
|
-
// List of extensions to transform with esbuild
|
|
1807
|
-
extensions: [
|
|
1808
|
-
".ts",
|
|
1809
|
-
".cts",
|
|
1810
|
-
".mts",
|
|
1811
|
-
".tsx",
|
|
1812
|
-
".js",
|
|
1813
|
-
".cjs",
|
|
1814
|
-
".mjs",
|
|
1815
|
-
".jsx"
|
|
1816
|
-
],
|
|
1817
|
-
transform(opts) {
|
|
1818
|
-
const isEntrypoint = opts.filename === normalPath;
|
|
1819
|
-
return transformSync(
|
|
1820
|
-
// Use modified source code for entrypoints
|
|
1821
|
-
isEntrypoint ? code : opts.source,
|
|
1822
|
-
getEsbuildOptions(opts)
|
|
1823
|
-
);
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
);
|
|
1827
|
-
try {
|
|
1828
|
-
const res = await jiti(path8);
|
|
1829
|
-
return res.default;
|
|
1830
|
-
} catch (err) {
|
|
1831
|
-
const filePath = relative5(wxt.config.root, path8);
|
|
1832
|
-
if (err instanceof ReferenceError) {
|
|
1833
|
-
const variableName = err.message.replace(" is not defined", "");
|
|
1834
|
-
throw Error(
|
|
1835
|
-
`${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/entrypoints.html#side-effects`,
|
|
1836
|
-
{ cause: err }
|
|
1837
|
-
);
|
|
1838
|
-
} else {
|
|
1839
|
-
wxt.logger.error(err);
|
|
1840
|
-
throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
function getEsbuildOptions(opts) {
|
|
1845
|
-
const isJsx = opts.filename?.endsWith("x");
|
|
1846
|
-
return {
|
|
1847
|
-
format: "cjs",
|
|
1848
|
-
loader: isJsx ? "tsx" : "ts",
|
|
1849
|
-
...isJsx ? {
|
|
1850
|
-
// `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
|
|
1851
|
-
// grabbing the entrypoint's options.
|
|
1852
|
-
jsxFactory: "h",
|
|
1853
|
-
jsxFragment: "Fragment"
|
|
1854
|
-
} : void 0
|
|
1855
|
-
};
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
1904
|
// src/core/utils/building/internal-build.ts
|
|
1859
1905
|
import pc5 from "picocolors";
|
|
1860
1906
|
import fs13 from "fs-extra";
|
|
1861
1907
|
|
|
1862
1908
|
// src/core/utils/log/printBuildSummary.ts
|
|
1863
|
-
import { resolve as
|
|
1909
|
+
import { resolve as resolve12 } from "path";
|
|
1864
1910
|
|
|
1865
1911
|
// src/core/utils/log/printFileList.ts
|
|
1866
1912
|
import path6 from "node:path";
|
|
@@ -1948,7 +1994,7 @@ async function printBuildSummary(log, header, output) {
|
|
|
1948
1994
|
return l.fileName.localeCompare(r.fileName);
|
|
1949
1995
|
});
|
|
1950
1996
|
const files = chunks.map(
|
|
1951
|
-
(chunk) =>
|
|
1997
|
+
(chunk) => resolve12(wxt.config.outDir, chunk.fileName)
|
|
1952
1998
|
);
|
|
1953
1999
|
await printFileList(log, header, wxt.config.outDir, files);
|
|
1954
2000
|
}
|
|
@@ -1968,14 +2014,13 @@ function getChunkSortWeight(filename) {
|
|
|
1968
2014
|
|
|
1969
2015
|
// src/core/utils/log/printHeader.ts
|
|
1970
2016
|
import pc4 from "picocolors";
|
|
1971
|
-
import { consola as consola2 } from "consola";
|
|
1972
2017
|
|
|
1973
2018
|
// src/core/utils/building/internal-build.ts
|
|
1974
2019
|
import glob3 from "fast-glob";
|
|
1975
2020
|
|
|
1976
2021
|
// src/core/utils/manifest.ts
|
|
1977
2022
|
import fs12 from "fs-extra";
|
|
1978
|
-
import { resolve as
|
|
2023
|
+
import { resolve as resolve13 } from "path";
|
|
1979
2024
|
|
|
1980
2025
|
// src/core/utils/content-security-policy.ts
|
|
1981
2026
|
var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
@@ -2089,7 +2134,7 @@ import defu2 from "defu";
|
|
|
2089
2134
|
async function writeManifest(manifest, output) {
|
|
2090
2135
|
const str = wxt.config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
2091
2136
|
await fs12.ensureDir(wxt.config.outDir);
|
|
2092
|
-
await writeFileIfDifferent(
|
|
2137
|
+
await writeFileIfDifferent(resolve13(wxt.config.outDir, "manifest.json"), str);
|
|
2093
2138
|
output.publicAssets.unshift({
|
|
2094
2139
|
type: "asset",
|
|
2095
2140
|
fileName: "manifest.json"
|
|
@@ -2147,6 +2192,7 @@ async function generateManifest(entrypoints, buildOutput) {
|
|
|
2147
2192
|
if (wxt.config.manifestVersion === 2) {
|
|
2148
2193
|
convertWebAccessibleResourcesToMv2(manifest);
|
|
2149
2194
|
convertActionToMv2(manifest);
|
|
2195
|
+
moveHostPermissionsToPermissions(manifest);
|
|
2150
2196
|
}
|
|
2151
2197
|
if (wxt.config.manifestVersion === 3) {
|
|
2152
2198
|
validateMv3WebAccessbileResources(manifest);
|
|
@@ -2527,6 +2573,14 @@ function convertWebAccessibleResourcesToMv2(manifest) {
|
|
|
2527
2573
|
)
|
|
2528
2574
|
);
|
|
2529
2575
|
}
|
|
2576
|
+
function moveHostPermissionsToPermissions(manifest) {
|
|
2577
|
+
if (!manifest.host_permissions?.length)
|
|
2578
|
+
return;
|
|
2579
|
+
manifest.host_permissions.forEach(
|
|
2580
|
+
(permission) => addPermission(manifest, permission)
|
|
2581
|
+
);
|
|
2582
|
+
delete manifest.host_permissions;
|
|
2583
|
+
}
|
|
2530
2584
|
function convertActionToMv2(manifest) {
|
|
2531
2585
|
if (manifest.action == null || manifest.browser_action != null || manifest.page_action != null)
|
|
2532
2586
|
return;
|
|
@@ -2688,7 +2742,6 @@ var ValidationError = class extends Error {
|
|
|
2688
2742
|
};
|
|
2689
2743
|
|
|
2690
2744
|
// src/core/utils/building/internal-build.ts
|
|
2691
|
-
import consola3 from "consola";
|
|
2692
2745
|
import { mergeJsonOutputs } from "@aklinker1/rollup-plugin-visualizer";
|
|
2693
2746
|
import { isCI } from "ci-info";
|
|
2694
2747
|
async function internalBuild() {
|
|
@@ -2776,12 +2829,12 @@ function printValidationResults({
|
|
|
2776
2829
|
return map;
|
|
2777
2830
|
}, /* @__PURE__ */ new Map());
|
|
2778
2831
|
Array.from(entrypointErrors.entries()).forEach(([entrypoint, errors2]) => {
|
|
2779
|
-
|
|
2832
|
+
consola.log(relative6(cwd, entrypoint.inputPath));
|
|
2780
2833
|
console.log();
|
|
2781
2834
|
errors2.forEach((err) => {
|
|
2782
2835
|
const type = err.type === "error" ? pc5.red("ERROR") : pc5.yellow("WARN");
|
|
2783
2836
|
const recieved = pc5.dim(`(recieved: ${JSON.stringify(err.value)})`);
|
|
2784
|
-
|
|
2837
|
+
consola.log(` - ${type} ${err.message} ${recieved}`);
|
|
2785
2838
|
});
|
|
2786
2839
|
console.log();
|
|
2787
2840
|
});
|
|
@@ -2807,7 +2860,7 @@ var npm = {
|
|
|
2807
2860
|
overridesKey: "overrides",
|
|
2808
2861
|
async downloadDependency(id, downloadDir) {
|
|
2809
2862
|
await ensureDir3(downloadDir);
|
|
2810
|
-
const { execa } = await import("./execa-
|
|
2863
|
+
const { execa } = await import("./execa-VDW6HLFV.js");
|
|
2811
2864
|
const res = await execa("npm", ["pack", id, "--json"], {
|
|
2812
2865
|
cwd: downloadDir
|
|
2813
2866
|
});
|
|
@@ -2819,7 +2872,7 @@ var npm = {
|
|
|
2819
2872
|
if (options?.all) {
|
|
2820
2873
|
args.push("--depth", "Infinity");
|
|
2821
2874
|
}
|
|
2822
|
-
const { execa } = await import("./execa-
|
|
2875
|
+
const { execa } = await import("./execa-VDW6HLFV.js");
|
|
2823
2876
|
const res = await execa("npm", args, { cwd: options?.cwd });
|
|
2824
2877
|
const project = JSON.parse(res.stdout);
|
|
2825
2878
|
return flattenNpmListOutput([project]);
|
|
@@ -2876,7 +2929,7 @@ var bun = {
|
|
|
2876
2929
|
if (options?.all) {
|
|
2877
2930
|
args.push("--all");
|
|
2878
2931
|
}
|
|
2879
|
-
const { execa } = await import("./execa-
|
|
2932
|
+
const { execa } = await import("./execa-VDW6HLFV.js");
|
|
2880
2933
|
const res = await execa("bun", args, { cwd: options?.cwd });
|
|
2881
2934
|
return dedupeDependencies(
|
|
2882
2935
|
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 }))
|
|
@@ -2895,7 +2948,7 @@ var yarn = {
|
|
|
2895
2948
|
if (options?.all) {
|
|
2896
2949
|
args.push("--depth", "Infinity");
|
|
2897
2950
|
}
|
|
2898
|
-
const { execa } = await import("./execa-
|
|
2951
|
+
const { execa } = await import("./execa-VDW6HLFV.js");
|
|
2899
2952
|
const res = await execa("yarn", args, { cwd: options?.cwd });
|
|
2900
2953
|
const tree = res.stdout.split("\n").map((line) => JSON.parse(line)).find((line) => line.type === "tree")?.data;
|
|
2901
2954
|
if (tree == null)
|
|
@@ -2932,7 +2985,7 @@ var pnpm = {
|
|
|
2932
2985
|
if (typeof process !== "undefined" && process.env.WXT_PNPM_IGNORE_WORKSPACE === "true") {
|
|
2933
2986
|
args.push("--ignore-workspace");
|
|
2934
2987
|
}
|
|
2935
|
-
const { execa } = await import("./execa-
|
|
2988
|
+
const { execa } = await import("./execa-VDW6HLFV.js");
|
|
2936
2989
|
const res = await execa("pnpm", args, { cwd: options?.cwd });
|
|
2937
2990
|
const projects = JSON.parse(res.stdout);
|
|
2938
2991
|
return flattenNpmListOutput(projects);
|
|
@@ -3143,6 +3196,22 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
3143
3196
|
return {
|
|
3144
3197
|
name: "Vite",
|
|
3145
3198
|
version: vite.version,
|
|
3199
|
+
async importEntrypoint(url) {
|
|
3200
|
+
const baseConfig = await getBaseConfig();
|
|
3201
|
+
const envConfig = {
|
|
3202
|
+
plugins: [
|
|
3203
|
+
webextensionPolyfillMock(wxtConfig),
|
|
3204
|
+
removeEntrypointMainFunction(wxtConfig, url)
|
|
3205
|
+
]
|
|
3206
|
+
};
|
|
3207
|
+
const config = vite.mergeConfig(baseConfig, envConfig);
|
|
3208
|
+
const server2 = await vite.createServer(config);
|
|
3209
|
+
await server2.listen();
|
|
3210
|
+
const runtime = await vite.createViteRuntime(server2, { hmr: false });
|
|
3211
|
+
const module = await runtime.executeUrl(url);
|
|
3212
|
+
await server2.close();
|
|
3213
|
+
return module.default;
|
|
3214
|
+
},
|
|
3146
3215
|
async build(group) {
|
|
3147
3216
|
let entryConfig;
|
|
3148
3217
|
if (Array.isArray(group))
|