wxt 0.1.1-alpha4 → 0.1.2
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 +0 -8
- package/dist/cli.cjs +70 -52
- package/dist/index.cjs +69 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -4
- package/dist/index.js +36 -18
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -277,6 +277,15 @@ function getUnimportOptions(config) {
|
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
// src/core/vite-plugins/unimport.ts
|
|
280
|
+
var import_path2 = require("path");
|
|
281
|
+
var ENABLED_EXTENSIONS = {
|
|
282
|
+
".js": true,
|
|
283
|
+
".jsx": true,
|
|
284
|
+
".ts": true,
|
|
285
|
+
".tsx": true,
|
|
286
|
+
".vue": true,
|
|
287
|
+
".svelte": true
|
|
288
|
+
};
|
|
280
289
|
function unimport(config) {
|
|
281
290
|
const options = getUnimportOptions(config);
|
|
282
291
|
const unimport2 = (0, import_unimport.createUnimport)(options);
|
|
@@ -286,14 +295,16 @@ function unimport(config) {
|
|
|
286
295
|
await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
|
|
287
296
|
},
|
|
288
297
|
async transform(code, id) {
|
|
289
|
-
|
|
298
|
+
const ext = (0, import_path2.extname)(id);
|
|
299
|
+
if (ENABLED_EXTENSIONS[ext])
|
|
300
|
+
return unimport2.injectImports(code, id);
|
|
290
301
|
}
|
|
291
302
|
};
|
|
292
303
|
}
|
|
293
304
|
|
|
294
305
|
// src/core/vite-plugins/virtualEntrypoint.ts
|
|
295
306
|
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
296
|
-
var
|
|
307
|
+
var import_path3 = require("path");
|
|
297
308
|
function virtualEntrypoin(type, config) {
|
|
298
309
|
const virtualId = `virtual:wxt-${type}?`;
|
|
299
310
|
const resolvedVirtualId = `\0${virtualId}`;
|
|
@@ -311,7 +322,7 @@ function virtualEntrypoin(type, config) {
|
|
|
311
322
|
return;
|
|
312
323
|
const inputPath = id.replace(resolvedVirtualId, "");
|
|
313
324
|
const template = await import_fs_extra2.default.readFile(
|
|
314
|
-
(0,
|
|
325
|
+
(0, import_path3.resolve)(
|
|
315
326
|
config.root,
|
|
316
327
|
`node_modules/wxt/dist/virtual-modules/${type}-entrypoint.js`
|
|
317
328
|
),
|
|
@@ -324,13 +335,13 @@ function virtualEntrypoin(type, config) {
|
|
|
324
335
|
|
|
325
336
|
// src/core/utils/createFsCache.ts
|
|
326
337
|
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
327
|
-
var
|
|
338
|
+
var import_path4 = require("path");
|
|
328
339
|
function createFsCache(wxtDir) {
|
|
329
|
-
const getPath = (key) => (0,
|
|
340
|
+
const getPath = (key) => (0, import_path4.resolve)(wxtDir, "cache", encodeURIComponent(key));
|
|
330
341
|
return {
|
|
331
342
|
async set(key, value) {
|
|
332
343
|
const path5 = getPath(key);
|
|
333
|
-
await (0, import_fs_extra3.ensureDir)((0,
|
|
344
|
+
await (0, import_fs_extra3.ensureDir)((0, import_path4.dirname)(path5));
|
|
334
345
|
await import_fs_extra3.default.writeFile(path5, value, "utf-8");
|
|
335
346
|
},
|
|
336
347
|
async get(key) {
|
|
@@ -400,6 +411,12 @@ async function getInternalConfig(config, command) {
|
|
|
400
411
|
const outBaseDir = import_node_path3.default.resolve(root, ".output");
|
|
401
412
|
const outDir = import_node_path3.default.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
|
|
402
413
|
const logger = config.logger ?? import_consola.consola;
|
|
414
|
+
const manifest = await (typeof config.manifest === "function" ? config.manifest({
|
|
415
|
+
browser,
|
|
416
|
+
command,
|
|
417
|
+
manifestVersion,
|
|
418
|
+
mode
|
|
419
|
+
}) : config.manifest ?? {});
|
|
403
420
|
const baseConfig = {
|
|
404
421
|
root,
|
|
405
422
|
outDir,
|
|
@@ -411,7 +428,7 @@ async function getInternalConfig(config, command) {
|
|
|
411
428
|
command,
|
|
412
429
|
logger,
|
|
413
430
|
vite: config.vite ?? {},
|
|
414
|
-
manifest
|
|
431
|
+
manifest,
|
|
415
432
|
imports: config.imports ?? {},
|
|
416
433
|
runnerConfig: await (0, import_c12.loadConfig)({
|
|
417
434
|
name: "web-ext",
|
|
@@ -582,11 +599,11 @@ var vite3 = __toESM(require("vite"), 1);
|
|
|
582
599
|
|
|
583
600
|
// src/core/utils/removeEmptyDirs.ts
|
|
584
601
|
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
585
|
-
var
|
|
602
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
586
603
|
async function removeEmptyDirs(dir) {
|
|
587
604
|
const files = await import_fs_extra4.default.readdir(dir);
|
|
588
605
|
for (const file of files) {
|
|
589
|
-
const filePath =
|
|
606
|
+
const filePath = import_path5.default.join(dir, file);
|
|
590
607
|
const stats = await import_fs_extra4.default.stat(filePath);
|
|
591
608
|
if (stats.isDirectory()) {
|
|
592
609
|
await removeEmptyDirs(filePath);
|
|
@@ -601,7 +618,7 @@ async function removeEmptyDirs(dir) {
|
|
|
601
618
|
// src/core/build/buildEntrypoints.ts
|
|
602
619
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
603
620
|
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
604
|
-
var
|
|
621
|
+
var import_path6 = require("path");
|
|
605
622
|
async function buildEntrypoints(groups, config) {
|
|
606
623
|
const steps = [];
|
|
607
624
|
for (const group of groups) {
|
|
@@ -620,7 +637,7 @@ async function buildSingleEntrypoint(entrypoint, config) {
|
|
|
620
637
|
lib: {
|
|
621
638
|
entry,
|
|
622
639
|
formats: ["iife"],
|
|
623
|
-
name:
|
|
640
|
+
name: "_",
|
|
624
641
|
fileName: entrypoint.name
|
|
625
642
|
},
|
|
626
643
|
rollupOptions: {
|
|
@@ -693,9 +710,9 @@ async function copyPublicDirectory(config) {
|
|
|
693
710
|
return publicAssets;
|
|
694
711
|
const files = await (0, import_fast_glob.default)("**/*", { cwd: config.publicDir });
|
|
695
712
|
for (const file of files) {
|
|
696
|
-
const srcPath = (0,
|
|
697
|
-
const outPath = (0,
|
|
698
|
-
await import_fs_extra5.default.ensureDir((0,
|
|
713
|
+
const srcPath = (0, import_path6.resolve)(config.publicDir, file);
|
|
714
|
+
const outPath = (0, import_path6.resolve)(config.outDir, file);
|
|
715
|
+
await import_fs_extra5.default.ensureDir((0, import_path6.dirname)(outPath));
|
|
699
716
|
await import_fs_extra5.default.copyFile(srcPath, outPath);
|
|
700
717
|
publicAssets.push({
|
|
701
718
|
type: "asset",
|
|
@@ -709,7 +726,7 @@ async function copyPublicDirectory(config) {
|
|
|
709
726
|
}
|
|
710
727
|
|
|
711
728
|
// src/core/build/findEntrypoints.ts
|
|
712
|
-
var
|
|
729
|
+
var import_path8 = require("path");
|
|
713
730
|
var import_fs_extra7 = __toESM(require("fs-extra"), 1);
|
|
714
731
|
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
715
732
|
var import_linkedom2 = require("linkedom");
|
|
@@ -719,10 +736,10 @@ var import_json5 = __toESM(require("json5"), 1);
|
|
|
719
736
|
var import_jiti = __toESM(require("jiti"), 1);
|
|
720
737
|
var import_unimport2 = require("unimport");
|
|
721
738
|
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
722
|
-
var
|
|
739
|
+
var import_path7 = require("path");
|
|
723
740
|
var import_babel = __toESM(require("jiti/dist/babel"), 1);
|
|
724
741
|
async function importTsFile(path5, config) {
|
|
725
|
-
config.logger.
|
|
742
|
+
config.logger.debug("Loading file metadata:", path5);
|
|
726
743
|
const unimport2 = (0, import_unimport2.createUnimport)({
|
|
727
744
|
...getUnimportOptions(config),
|
|
728
745
|
// Only allow specific imports, not all from the project
|
|
@@ -733,7 +750,7 @@ async function importTsFile(path5, config) {
|
|
|
733
750
|
const text = await import_fs_extra6.default.readFile(path5, "utf-8");
|
|
734
751
|
const textNoImports = text.replace(/import.*[\n;]/gm, "");
|
|
735
752
|
const { code } = await unimport2.injectImports(textNoImports);
|
|
736
|
-
config.logger.
|
|
753
|
+
config.logger.debug(
|
|
737
754
|
["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
|
|
738
755
|
);
|
|
739
756
|
const jiti = (0, import_jiti.default)(__filename, {
|
|
@@ -741,7 +758,7 @@ async function importTsFile(path5, config) {
|
|
|
741
758
|
esmResolve: true,
|
|
742
759
|
interopDefault: true,
|
|
743
760
|
alias: {
|
|
744
|
-
"webextension-polyfill": (0,
|
|
761
|
+
"webextension-polyfill": (0, import_path7.resolve)(
|
|
745
762
|
config.root,
|
|
746
763
|
"node_modules/wxt/dist/virtual-modules/fake-browser.js"
|
|
747
764
|
)
|
|
@@ -773,7 +790,7 @@ async function findEntrypoints(config) {
|
|
|
773
790
|
const entrypoints = [];
|
|
774
791
|
await Promise.all(
|
|
775
792
|
relativePaths.map(async (relativePath) => {
|
|
776
|
-
const path5 = (0,
|
|
793
|
+
const path5 = (0, import_path8.resolve)(config.entrypointsDir, relativePath);
|
|
777
794
|
const matchingGlob = pathGlobs.find(
|
|
778
795
|
(glob3) => import_picomatch.default.isMatch(relativePath, glob3)
|
|
779
796
|
);
|
|
@@ -820,8 +837,8 @@ ${JSON.stringify(
|
|
|
820
837
|
if (withSameName) {
|
|
821
838
|
throw Error(
|
|
822
839
|
`Multiple entrypoints with the name "${entrypoint.name}" detected, but only one is allowed: ${[
|
|
823
|
-
(0,
|
|
824
|
-
(0,
|
|
840
|
+
(0, import_path8.relative)(config.root, withSameName.inputPath),
|
|
841
|
+
(0, import_path8.relative)(config.root, entrypoint.inputPath)
|
|
825
842
|
].join(", ")}`
|
|
826
843
|
);
|
|
827
844
|
}
|
|
@@ -910,7 +927,7 @@ async function getContentScriptEntrypoint(config, name, path5) {
|
|
|
910
927
|
type: "content-script",
|
|
911
928
|
name: getEntrypointName(config.entrypointsDir, path5),
|
|
912
929
|
inputPath: path5,
|
|
913
|
-
outputDir: (0,
|
|
930
|
+
outputDir: (0, import_path8.resolve)(config.outDir, "content-scripts"),
|
|
914
931
|
options
|
|
915
932
|
};
|
|
916
933
|
}
|
|
@@ -948,7 +965,7 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
948
965
|
// src/core/build/generateTypesDir.ts
|
|
949
966
|
var import_unimport3 = require("unimport");
|
|
950
967
|
var import_fs_extra8 = __toESM(require("fs-extra"), 1);
|
|
951
|
-
var
|
|
968
|
+
var import_path9 = require("path");
|
|
952
969
|
async function generateTypesDir(entrypoints, config) {
|
|
953
970
|
await import_fs_extra8.default.ensureDir(config.typesDir);
|
|
954
971
|
const references = [];
|
|
@@ -959,7 +976,7 @@ async function generateTypesDir(entrypoints, config) {
|
|
|
959
976
|
await writeTsConfigFile(mainReference, config);
|
|
960
977
|
}
|
|
961
978
|
async function writeImportsDeclarationFile(config) {
|
|
962
|
-
const filePath = (0,
|
|
979
|
+
const filePath = (0, import_path9.resolve)(config.typesDir, "imports.d.ts");
|
|
963
980
|
const unimport2 = (0, import_unimport3.createUnimport)(getUnimportOptions(config));
|
|
964
981
|
await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
|
|
965
982
|
await import_fs_extra8.default.writeFile(
|
|
@@ -971,26 +988,27 @@ async function writeImportsDeclarationFile(config) {
|
|
|
971
988
|
return filePath;
|
|
972
989
|
}
|
|
973
990
|
async function writePathsDeclarationFile(entrypoints, config) {
|
|
974
|
-
const filePath = (0,
|
|
991
|
+
const filePath = (0, import_path9.resolve)(config.typesDir, "paths.d.ts");
|
|
992
|
+
const unions = entrypoints.map((entry) => {
|
|
993
|
+
const path5 = getEntrypointBundlePath(
|
|
994
|
+
entry,
|
|
995
|
+
config.outDir,
|
|
996
|
+
entry.inputPath.endsWith(".html") ? ".html" : ".js"
|
|
997
|
+
);
|
|
998
|
+
return ` | "/${path5}"`;
|
|
999
|
+
}).sort();
|
|
975
1000
|
await import_fs_extra8.default.writeFile(
|
|
976
1001
|
filePath,
|
|
977
1002
|
[
|
|
978
1003
|
"// Generated by wxt",
|
|
979
1004
|
"type EntrypointPath =",
|
|
980
|
-
...
|
|
981
|
-
const path5 = getEntrypointBundlePath(
|
|
982
|
-
entry,
|
|
983
|
-
config.outDir,
|
|
984
|
-
entry.inputPath.endsWith(".html") ? ".html" : ".js"
|
|
985
|
-
);
|
|
986
|
-
return ` | "/${path5}"`;
|
|
987
|
-
}).sort()
|
|
1005
|
+
...unions.length === 0 ? [" never"] : unions
|
|
988
1006
|
].join("\n") + "\n"
|
|
989
1007
|
);
|
|
990
1008
|
return filePath;
|
|
991
1009
|
}
|
|
992
1010
|
async function writeGlobalsDeclarationFile(config) {
|
|
993
|
-
const filePath = (0,
|
|
1011
|
+
const filePath = (0, import_path9.resolve)(config.typesDir, "globals.d.ts");
|
|
994
1012
|
const globals = getGlobals(config);
|
|
995
1013
|
await import_fs_extra8.default.writeFile(
|
|
996
1014
|
filePath,
|
|
@@ -1007,13 +1025,13 @@ async function writeGlobalsDeclarationFile(config) {
|
|
|
1007
1025
|
}
|
|
1008
1026
|
async function writeMainDeclarationFile(references, config) {
|
|
1009
1027
|
const dir = config.wxtDir;
|
|
1010
|
-
const filePath = (0,
|
|
1028
|
+
const filePath = (0, import_path9.resolve)(dir, "wxt.d.ts");
|
|
1011
1029
|
await import_fs_extra8.default.writeFile(
|
|
1012
1030
|
filePath,
|
|
1013
1031
|
[
|
|
1014
1032
|
"// Generated by wxt",
|
|
1015
1033
|
...references.map(
|
|
1016
|
-
(ref) => `/// <reference types="./${(0,
|
|
1034
|
+
(ref) => `/// <reference types="./${(0, import_path9.relative)(dir, ref)}" />`
|
|
1017
1035
|
)
|
|
1018
1036
|
].join("\n") + "\n"
|
|
1019
1037
|
);
|
|
@@ -1022,7 +1040,7 @@ async function writeMainDeclarationFile(references, config) {
|
|
|
1022
1040
|
async function writeTsConfigFile(mainReference, config) {
|
|
1023
1041
|
const dir = config.wxtDir;
|
|
1024
1042
|
await import_fs_extra8.default.writeFile(
|
|
1025
|
-
(0,
|
|
1043
|
+
(0, import_path9.resolve)(dir, "tsconfig.json"),
|
|
1026
1044
|
`{
|
|
1027
1045
|
"compilerOptions": {
|
|
1028
1046
|
"target": "ESNext",
|
|
@@ -1040,17 +1058,17 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1040
1058
|
"skipLibCheck": true
|
|
1041
1059
|
},
|
|
1042
1060
|
"include": [
|
|
1043
|
-
"${(0,
|
|
1044
|
-
"./${(0,
|
|
1061
|
+
"${(0, import_path9.relative)(dir, config.root)}/**/*",
|
|
1062
|
+
"./${(0, import_path9.relative)(dir, mainReference)}"
|
|
1045
1063
|
],
|
|
1046
|
-
"exclude": ["${(0,
|
|
1064
|
+
"exclude": ["${(0, import_path9.relative)(dir, config.outBaseDir)}"]
|
|
1047
1065
|
}`
|
|
1048
1066
|
);
|
|
1049
1067
|
}
|
|
1050
1068
|
|
|
1051
1069
|
// src/core/utils/manifest.ts
|
|
1052
1070
|
var import_fs_extra9 = __toESM(require("fs-extra"), 1);
|
|
1053
|
-
var
|
|
1071
|
+
var import_path10 = require("path");
|
|
1054
1072
|
|
|
1055
1073
|
// src/core/utils/ContentSecurityPolicy.ts
|
|
1056
1074
|
var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
@@ -1099,7 +1117,7 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
|
1099
1117
|
async function writeManifest(manifest, output, config) {
|
|
1100
1118
|
const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
1101
1119
|
await import_fs_extra9.default.ensureDir(config.outDir);
|
|
1102
|
-
await import_fs_extra9.default.writeFile((0,
|
|
1120
|
+
await import_fs_extra9.default.writeFile((0, import_path10.resolve)(config.outDir, "manifest.json"), str, "utf-8");
|
|
1103
1121
|
output.publicAssets.unshift({
|
|
1104
1122
|
type: "asset",
|
|
1105
1123
|
fileName: "manifest.json",
|
|
@@ -1132,7 +1150,7 @@ async function generateMainfest(entrypoints, buildOutput, config) {
|
|
|
1132
1150
|
return manifest;
|
|
1133
1151
|
}
|
|
1134
1152
|
async function getPackageJson(config) {
|
|
1135
|
-
return await import_fs_extra9.default.readJson((0,
|
|
1153
|
+
return await import_fs_extra9.default.readJson((0, import_path10.resolve)(config.root, "package.json"));
|
|
1136
1154
|
}
|
|
1137
1155
|
function simplifyVersion(versionName) {
|
|
1138
1156
|
const version3 = /^((0|[1-9][0-9]{0,8})([.](0|[1-9][0-9]{0,8})){0,3}).*$/.exec(
|
|
@@ -1425,7 +1443,7 @@ function formatDuration(duration) {
|
|
|
1425
1443
|
}
|
|
1426
1444
|
|
|
1427
1445
|
// src/core/log/printBuildSummary.ts
|
|
1428
|
-
var
|
|
1446
|
+
var import_path11 = __toESM(require("path"), 1);
|
|
1429
1447
|
|
|
1430
1448
|
// src/core/log/printTable.ts
|
|
1431
1449
|
function printTable(log, rows, gap = 2) {
|
|
@@ -1462,8 +1480,8 @@ async function printBuildSummary(output, config) {
|
|
|
1462
1480
|
...output.steps.flatMap((step) => step.chunks),
|
|
1463
1481
|
...output.publicAssets
|
|
1464
1482
|
].sort((l, r) => {
|
|
1465
|
-
const lWeight = CHUNK_SORT_WEIGHTS[l.fileName] ?? CHUNK_SORT_WEIGHTS[(0,
|
|
1466
|
-
const rWeight = CHUNK_SORT_WEIGHTS[r.fileName] ?? CHUNK_SORT_WEIGHTS[(0,
|
|
1483
|
+
const lWeight = CHUNK_SORT_WEIGHTS[l.fileName] ?? CHUNK_SORT_WEIGHTS[(0, import_path11.extname)(l.fileName)] ?? DEFAULT_SORT_WEIGHT;
|
|
1484
|
+
const rWeight = CHUNK_SORT_WEIGHTS[r.fileName] ?? CHUNK_SORT_WEIGHTS[(0, import_path11.extname)(r.fileName)] ?? DEFAULT_SORT_WEIGHT;
|
|
1467
1485
|
const diff = lWeight - rWeight;
|
|
1468
1486
|
if (diff !== 0)
|
|
1469
1487
|
return diff;
|
|
@@ -1473,13 +1491,13 @@ async function printBuildSummary(output, config) {
|
|
|
1473
1491
|
const chunkRows = await Promise.all(
|
|
1474
1492
|
chunks.map(async (chunk, i) => {
|
|
1475
1493
|
const file = [
|
|
1476
|
-
(0,
|
|
1494
|
+
(0, import_path11.relative)(process.cwd(), config.outDir) + import_path11.default.sep,
|
|
1477
1495
|
chunk.fileName
|
|
1478
1496
|
];
|
|
1479
|
-
const ext = (0,
|
|
1497
|
+
const ext = (0, import_path11.extname)(chunk.fileName);
|
|
1480
1498
|
const prefix = i === chunks.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1481
1499
|
const color = CHUNK_COLORS[ext] ?? DEFAULT_COLOR;
|
|
1482
|
-
const stats = await import_fs_extra10.default.lstat((0,
|
|
1500
|
+
const stats = await import_fs_extra10.default.lstat((0, import_path11.resolve)(config.outDir, chunk.fileName));
|
|
1483
1501
|
totalSize += stats.size;
|
|
1484
1502
|
const size = String((0, import_filesize.filesize)(stats.size));
|
|
1485
1503
|
return [
|
|
@@ -1731,7 +1749,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1731
1749
|
}
|
|
1732
1750
|
|
|
1733
1751
|
// package.json
|
|
1734
|
-
var version2 = "0.1.
|
|
1752
|
+
var version2 = "0.1.2";
|
|
1735
1753
|
|
|
1736
1754
|
// src/core/utils/defineConfig.ts
|
|
1737
1755
|
function defineConfig(config) {
|