wxt 0.4.1 → 0.5.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/README.md +34 -11
- package/dist/cli.cjs +63 -52
- package/dist/index.cjs +55 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +54 -43
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -408,20 +408,31 @@ function cssEntrypoints(entrypoint, config) {
|
|
|
408
408
|
}
|
|
409
409
|
|
|
410
410
|
// src/core/utils/createFsCache.ts
|
|
411
|
-
var
|
|
411
|
+
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
412
412
|
var import_path4 = require("path");
|
|
413
|
+
|
|
414
|
+
// src/core/utils/fs.ts
|
|
415
|
+
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
416
|
+
async function writeFileIfDifferent(file, newContents) {
|
|
417
|
+
const existingContents = await import_fs_extra3.default.readFile(file, "utf-8").catch(() => void 0);
|
|
418
|
+
if (existingContents !== newContents) {
|
|
419
|
+
await import_fs_extra3.default.writeFile(file, newContents);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// src/core/utils/createFsCache.ts
|
|
413
424
|
function createFsCache(wxtDir) {
|
|
414
425
|
const getPath = (key) => (0, import_path4.resolve)(wxtDir, "cache", encodeURIComponent(key));
|
|
415
426
|
return {
|
|
416
427
|
async set(key, value) {
|
|
417
428
|
const path7 = getPath(key);
|
|
418
|
-
await (0,
|
|
419
|
-
await
|
|
429
|
+
await (0, import_fs_extra4.ensureDir)((0, import_path4.dirname)(path7));
|
|
430
|
+
await writeFileIfDifferent(path7, value);
|
|
420
431
|
},
|
|
421
432
|
async get(key) {
|
|
422
433
|
const path7 = getPath(key);
|
|
423
434
|
try {
|
|
424
|
-
return await
|
|
435
|
+
return await import_fs_extra4.default.readFile(path7, "utf-8");
|
|
425
436
|
} catch {
|
|
426
437
|
return void 0;
|
|
427
438
|
}
|
|
@@ -529,7 +540,7 @@ async function getInternalConfig(config, command) {
|
|
|
529
540
|
srcDir,
|
|
530
541
|
userConfig.entrypointsDir ?? "entrypoints"
|
|
531
542
|
);
|
|
532
|
-
const publicDir = (0, import_node_path4.resolve)(
|
|
543
|
+
const publicDir = (0, import_node_path4.resolve)(srcDir, userConfig.publicDir ?? "public");
|
|
533
544
|
const wxtDir = (0, import_node_path4.resolve)(root, ".wxt");
|
|
534
545
|
const typesDir = (0, import_node_path4.resolve)(wxtDir, "types");
|
|
535
546
|
const env = { mode, browser, manifestVersion, command };
|
|
@@ -700,32 +711,32 @@ var import_node_path9 = require("path");
|
|
|
700
711
|
var vite3 = __toESM(require("vite"), 1);
|
|
701
712
|
|
|
702
713
|
// src/core/utils/removeEmptyDirs.ts
|
|
703
|
-
var
|
|
714
|
+
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
704
715
|
var import_path5 = __toESM(require("path"), 1);
|
|
705
716
|
async function removeEmptyDirs(dir) {
|
|
706
|
-
const files = await
|
|
717
|
+
const files = await import_fs_extra5.default.readdir(dir);
|
|
707
718
|
for (const file of files) {
|
|
708
719
|
const filePath = import_path5.default.join(dir, file);
|
|
709
|
-
const stats = await
|
|
720
|
+
const stats = await import_fs_extra5.default.stat(filePath);
|
|
710
721
|
if (stats.isDirectory()) {
|
|
711
722
|
await removeEmptyDirs(filePath);
|
|
712
723
|
}
|
|
713
724
|
}
|
|
714
725
|
try {
|
|
715
|
-
await
|
|
726
|
+
await import_fs_extra5.default.rmdir(dir);
|
|
716
727
|
} catch {
|
|
717
728
|
}
|
|
718
729
|
}
|
|
719
730
|
|
|
720
731
|
// src/core/build/buildEntrypoints.ts
|
|
721
|
-
var
|
|
732
|
+
var import_fs_extra7 = __toESM(require("fs-extra"), 1);
|
|
722
733
|
var import_path6 = require("path");
|
|
723
734
|
|
|
724
735
|
// src/core/utils/public.ts
|
|
725
|
-
var
|
|
736
|
+
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
726
737
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
727
738
|
async function getPublicFiles(config) {
|
|
728
|
-
if (!await
|
|
739
|
+
if (!await import_fs_extra6.default.exists(config.publicDir))
|
|
729
740
|
return [];
|
|
730
741
|
const files = await (0, import_fast_glob.default)("**/*", { cwd: config.publicDir });
|
|
731
742
|
return files.map(unnormalizePath);
|
|
@@ -830,14 +841,14 @@ async function copyPublicDirectory(config) {
|
|
|
830
841
|
for (const file of files) {
|
|
831
842
|
const srcPath = (0, import_path6.resolve)(config.publicDir, file);
|
|
832
843
|
const outPath = (0, import_path6.resolve)(config.outDir, file);
|
|
833
|
-
await
|
|
834
|
-
await
|
|
844
|
+
await import_fs_extra7.default.ensureDir((0, import_path6.dirname)(outPath));
|
|
845
|
+
await import_fs_extra7.default.copyFile(srcPath, outPath);
|
|
835
846
|
publicAssets.push({
|
|
836
847
|
type: "asset",
|
|
837
848
|
fileName: file,
|
|
838
849
|
name: file,
|
|
839
850
|
needsCodeReference: false,
|
|
840
|
-
source: await
|
|
851
|
+
source: await import_fs_extra7.default.readFile(srcPath)
|
|
841
852
|
});
|
|
842
853
|
}
|
|
843
854
|
return publicAssets;
|
|
@@ -845,7 +856,7 @@ async function copyPublicDirectory(config) {
|
|
|
845
856
|
|
|
846
857
|
// src/core/build/findEntrypoints.ts
|
|
847
858
|
var import_path8 = require("path");
|
|
848
|
-
var
|
|
859
|
+
var import_fs_extra9 = __toESM(require("fs-extra"), 1);
|
|
849
860
|
var import_minimatch = require("minimatch");
|
|
850
861
|
var import_linkedom2 = require("linkedom");
|
|
851
862
|
var import_json5 = __toESM(require("json5"), 1);
|
|
@@ -853,7 +864,7 @@ var import_json5 = __toESM(require("json5"), 1);
|
|
|
853
864
|
// src/core/utils/importTsFile.ts
|
|
854
865
|
var import_jiti = __toESM(require("jiti"), 1);
|
|
855
866
|
var import_unimport2 = require("unimport");
|
|
856
|
-
var
|
|
867
|
+
var import_fs_extra8 = __toESM(require("fs-extra"), 1);
|
|
857
868
|
var import_path7 = require("path");
|
|
858
869
|
var import_babel = __toESM(require("jiti/dist/babel"), 1);
|
|
859
870
|
|
|
@@ -875,7 +886,7 @@ async function importTsFile(path7, config) {
|
|
|
875
886
|
dirs: []
|
|
876
887
|
});
|
|
877
888
|
await unimport2.init();
|
|
878
|
-
const text = await
|
|
889
|
+
const text = await import_fs_extra8.default.readFile(path7, "utf-8");
|
|
879
890
|
const textNoImports = removeImportStatements(text);
|
|
880
891
|
const { code } = await unimport2.injectImports(textNoImports);
|
|
881
892
|
config.logger.debug(
|
|
@@ -993,7 +1004,7 @@ ${JSON.stringify(
|
|
|
993
1004
|
}
|
|
994
1005
|
async function getPopupEntrypoint(config, path7) {
|
|
995
1006
|
const options = {};
|
|
996
|
-
const content = await
|
|
1007
|
+
const content = await import_fs_extra9.default.readFile(path7, "utf-8");
|
|
997
1008
|
const { document } = (0, import_linkedom2.parseHTML)(content);
|
|
998
1009
|
const title = document.querySelector("title");
|
|
999
1010
|
if (title != null)
|
|
@@ -1023,7 +1034,7 @@ async function getPopupEntrypoint(config, path7) {
|
|
|
1023
1034
|
}
|
|
1024
1035
|
async function getOptionsEntrypoint(config, path7) {
|
|
1025
1036
|
const options = {};
|
|
1026
|
-
const content = await
|
|
1037
|
+
const content = await import_fs_extra9.default.readFile(path7, "utf-8");
|
|
1027
1038
|
const { document } = (0, import_linkedom2.parseHTML)(content);
|
|
1028
1039
|
const openInTabContent = document.querySelector("meta[name='manifest.open_in_tab']")?.getAttribute("content");
|
|
1029
1040
|
if (openInTabContent) {
|
|
@@ -1126,7 +1137,7 @@ var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|
|
|
1126
1137
|
|
|
1127
1138
|
// src/core/build/generateTypesDir.ts
|
|
1128
1139
|
var import_unimport3 = require("unimport");
|
|
1129
|
-
var
|
|
1140
|
+
var import_fs_extra10 = __toESM(require("fs-extra"), 1);
|
|
1130
1141
|
var import_path9 = require("path");
|
|
1131
1142
|
var import_node_path5 = __toESM(require("path"), 1);
|
|
1132
1143
|
|
|
@@ -1169,7 +1180,7 @@ function parseI18nMessages(messagesJson) {
|
|
|
1169
1180
|
|
|
1170
1181
|
// src/core/build/generateTypesDir.ts
|
|
1171
1182
|
async function generateTypesDir(entrypoints, config) {
|
|
1172
|
-
await
|
|
1183
|
+
await import_fs_extra10.default.ensureDir(config.typesDir);
|
|
1173
1184
|
const references = [];
|
|
1174
1185
|
references.push(await writeImportsDeclarationFile(config));
|
|
1175
1186
|
references.push(await writePathsDeclarationFile(entrypoints, config));
|
|
@@ -1182,7 +1193,7 @@ async function writeImportsDeclarationFile(config) {
|
|
|
1182
1193
|
const filePath = (0, import_path9.resolve)(config.typesDir, "imports.d.ts");
|
|
1183
1194
|
const unimport2 = (0, import_unimport3.createUnimport)(getUnimportOptions(config));
|
|
1184
1195
|
await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
|
|
1185
|
-
await
|
|
1196
|
+
await writeFileIfDifferent(
|
|
1186
1197
|
filePath,
|
|
1187
1198
|
["// Generated by wxt", await unimport2.generateTypeDeclarations()].join(
|
|
1188
1199
|
"\n"
|
|
@@ -1210,7 +1221,7 @@ declare module "wxt/browser" {
|
|
|
1210
1221
|
}
|
|
1211
1222
|
}
|
|
1212
1223
|
`;
|
|
1213
|
-
await
|
|
1224
|
+
await writeFileIfDifferent(
|
|
1214
1225
|
filePath,
|
|
1215
1226
|
template.replace("{{ union }}", unions || " | never")
|
|
1216
1227
|
);
|
|
@@ -1246,7 +1257,7 @@ declare module "wxt/browser" {
|
|
|
1246
1257
|
defaultLocale,
|
|
1247
1258
|
"messages.json"
|
|
1248
1259
|
);
|
|
1249
|
-
const content = JSON.parse(await
|
|
1260
|
+
const content = JSON.parse(await import_fs_extra10.default.readFile(defaultLocalePath, "utf-8"));
|
|
1250
1261
|
messages = parseI18nMessages(content);
|
|
1251
1262
|
} else {
|
|
1252
1263
|
messages = parseI18nMessages({});
|
|
@@ -1263,7 +1274,7 @@ declare module "wxt/browser" {
|
|
|
1263
1274
|
options?: GetMessageOptions,
|
|
1264
1275
|
): string;`;
|
|
1265
1276
|
});
|
|
1266
|
-
await
|
|
1277
|
+
await writeFileIfDifferent(
|
|
1267
1278
|
filePath,
|
|
1268
1279
|
template.replace("{{ overrides }}", overrides.join("\n"))
|
|
1269
1280
|
);
|
|
@@ -1272,7 +1283,7 @@ declare module "wxt/browser" {
|
|
|
1272
1283
|
async function writeGlobalsDeclarationFile(config) {
|
|
1273
1284
|
const filePath = (0, import_path9.resolve)(config.typesDir, "globals.d.ts");
|
|
1274
1285
|
const globals = getGlobals(config);
|
|
1275
|
-
await
|
|
1286
|
+
await writeFileIfDifferent(
|
|
1276
1287
|
filePath,
|
|
1277
1288
|
[
|
|
1278
1289
|
"// Generated by wxt",
|
|
@@ -1280,15 +1291,14 @@ async function writeGlobalsDeclarationFile(config) {
|
|
|
1280
1291
|
"declare global {",
|
|
1281
1292
|
...globals.map((global) => ` const ${global.name}: ${global.type};`),
|
|
1282
1293
|
"}"
|
|
1283
|
-
].join("\n") + "\n"
|
|
1284
|
-
"utf-8"
|
|
1294
|
+
].join("\n") + "\n"
|
|
1285
1295
|
);
|
|
1286
1296
|
return filePath;
|
|
1287
1297
|
}
|
|
1288
1298
|
async function writeMainDeclarationFile(references, config) {
|
|
1289
1299
|
const dir = config.wxtDir;
|
|
1290
1300
|
const filePath = (0, import_path9.resolve)(dir, "wxt.d.ts");
|
|
1291
|
-
await
|
|
1301
|
+
await writeFileIfDifferent(
|
|
1292
1302
|
filePath,
|
|
1293
1303
|
[
|
|
1294
1304
|
"// Generated by wxt",
|
|
@@ -1304,7 +1314,7 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1304
1314
|
const dir = config.wxtDir;
|
|
1305
1315
|
const rootPath = normalizePath2((0, import_path9.relative)(dir, config.root));
|
|
1306
1316
|
const srcPath = normalizePath2((0, import_path9.relative)(dir, config.srcDir));
|
|
1307
|
-
await
|
|
1317
|
+
await writeFileIfDifferent(
|
|
1308
1318
|
(0, import_path9.resolve)(dir, "tsconfig.json"),
|
|
1309
1319
|
`{
|
|
1310
1320
|
"compilerOptions": {
|
|
@@ -1339,7 +1349,7 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1339
1349
|
}
|
|
1340
1350
|
|
|
1341
1351
|
// src/core/utils/manifest.ts
|
|
1342
|
-
var
|
|
1352
|
+
var import_fs_extra12 = __toESM(require("fs-extra"), 1);
|
|
1343
1353
|
var import_path10 = require("path");
|
|
1344
1354
|
|
|
1345
1355
|
// src/core/utils/ContentSecurityPolicy.ts
|
|
@@ -1425,11 +1435,11 @@ function mapWxtOptionsToContentScript(options) {
|
|
|
1425
1435
|
|
|
1426
1436
|
// src/core/utils/package.ts
|
|
1427
1437
|
var import_node_path6 = require("path");
|
|
1428
|
-
var
|
|
1438
|
+
var import_fs_extra11 = __toESM(require("fs-extra"), 1);
|
|
1429
1439
|
async function getPackageJson(config) {
|
|
1430
1440
|
const file = (0, import_node_path6.resolve)(config.root, "package.json");
|
|
1431
1441
|
try {
|
|
1432
|
-
return await
|
|
1442
|
+
return await import_fs_extra11.default.readJson(file);
|
|
1433
1443
|
} catch (err) {
|
|
1434
1444
|
config.logger.debug(
|
|
1435
1445
|
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
@@ -1441,8 +1451,8 @@ async function getPackageJson(config) {
|
|
|
1441
1451
|
// src/core/utils/manifest.ts
|
|
1442
1452
|
async function writeManifest(manifest, output, config) {
|
|
1443
1453
|
const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
1444
|
-
await
|
|
1445
|
-
await
|
|
1454
|
+
await import_fs_extra12.default.ensureDir(config.outDir);
|
|
1455
|
+
await writeFileIfDifferent((0, import_path10.resolve)(config.outDir, "manifest.json"), str);
|
|
1446
1456
|
output.publicAssets.unshift({
|
|
1447
1457
|
type: "asset",
|
|
1448
1458
|
fileName: "manifest.json",
|
|
@@ -1762,7 +1772,7 @@ function addHostPermission(manifest, hostPermission) {
|
|
|
1762
1772
|
// src/core/build.ts
|
|
1763
1773
|
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
1764
1774
|
var vite4 = __toESM(require("vite"), 1);
|
|
1765
|
-
var
|
|
1775
|
+
var import_fs_extra14 = __toESM(require("fs-extra"), 1);
|
|
1766
1776
|
|
|
1767
1777
|
// src/core/utils/groupEntrypoints.ts
|
|
1768
1778
|
function groupEntrypoints(entrypoints) {
|
|
@@ -1817,7 +1827,7 @@ var import_path11 = require("path");
|
|
|
1817
1827
|
// src/core/log/printFileList.ts
|
|
1818
1828
|
var import_node_path7 = __toESM(require("path"), 1);
|
|
1819
1829
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
1820
|
-
var
|
|
1830
|
+
var import_fs_extra13 = __toESM(require("fs-extra"), 1);
|
|
1821
1831
|
var import_filesize = require("filesize");
|
|
1822
1832
|
|
|
1823
1833
|
// src/core/log/printTable.ts
|
|
@@ -1858,7 +1868,7 @@ async function printFileList(log, header, baseDir, files) {
|
|
|
1858
1868
|
];
|
|
1859
1869
|
const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1860
1870
|
const color = getChunkColor(file);
|
|
1861
|
-
const stats = await
|
|
1871
|
+
const stats = await import_fs_extra13.default.lstat(file);
|
|
1862
1872
|
totalSize += stats.size;
|
|
1863
1873
|
const size = String((0, import_filesize.filesize)(stats.size));
|
|
1864
1874
|
return [
|
|
@@ -1922,9 +1932,10 @@ async function buildInternal(config) {
|
|
|
1922
1932
|
)}`
|
|
1923
1933
|
);
|
|
1924
1934
|
const startTime = Date.now();
|
|
1925
|
-
await
|
|
1926
|
-
await
|
|
1935
|
+
await import_fs_extra14.default.rm(config.outDir, { recursive: true, force: true });
|
|
1936
|
+
await import_fs_extra14.default.ensureDir(config.outDir);
|
|
1927
1937
|
const entrypoints = await findEntrypoints(config);
|
|
1938
|
+
config.logger.debug("Detected entrypoints:", entrypoints);
|
|
1928
1939
|
const groups = groupEntrypoints(entrypoints);
|
|
1929
1940
|
const { output } = await rebuild(config, groups, void 0);
|
|
1930
1941
|
await printBuildSummary(
|
|
@@ -2122,7 +2133,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
2122
2133
|
// src/core/clean.ts
|
|
2123
2134
|
var import_node_path8 = __toESM(require("path"), 1);
|
|
2124
2135
|
var import_fast_glob3 = __toESM(require("fast-glob"), 1);
|
|
2125
|
-
var
|
|
2136
|
+
var import_fs_extra15 = __toESM(require("fs-extra"), 1);
|
|
2126
2137
|
var import_consola2 = require("consola");
|
|
2127
2138
|
var import_picocolors3 = __toESM(require("picocolors"), 1);
|
|
2128
2139
|
async function clean(root = process.cwd()) {
|
|
@@ -2149,13 +2160,13 @@ async function clean(root = process.cwd()) {
|
|
|
2149
2160
|
directories.map((dir) => import_picocolors3.default.cyan(import_node_path8.default.relative(root, dir))).join(", ")
|
|
2150
2161
|
);
|
|
2151
2162
|
for (const directory of directories) {
|
|
2152
|
-
await
|
|
2163
|
+
await import_fs_extra15.default.rm(directory, { force: true, recursive: true });
|
|
2153
2164
|
import_consola2.consola.debug("Deleted " + import_picocolors3.default.cyan(import_node_path8.default.relative(root, directory)));
|
|
2154
2165
|
}
|
|
2155
2166
|
}
|
|
2156
2167
|
|
|
2157
2168
|
// package.json
|
|
2158
|
-
var version2 = "0.
|
|
2169
|
+
var version2 = "0.5.0";
|
|
2159
2170
|
|
|
2160
2171
|
// src/core/utils/defineConfig.ts
|
|
2161
2172
|
function defineConfig(config) {
|