wxt 0.1.0 → 0.1.1-alpha2
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/cli.cjs +50 -48
- package/dist/index.cjs +49 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +52 -50
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -49,24 +49,26 @@ var import_jiti = __toESM(require("jiti"), 1);
|
|
|
49
49
|
var import_babel = __toESM(require("jiti/dist/babel"), 1);
|
|
50
50
|
var import_path = require("path");
|
|
51
51
|
var import_unimport = require("unimport");
|
|
52
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
52
53
|
async function importTsFile(root, path5) {
|
|
53
|
-
const
|
|
54
|
+
const unimport2 = (0, import_unimport.createUnimport)({});
|
|
55
|
+
await unimport2.scanImportsFromFile(
|
|
54
56
|
(0, import_path.resolve)(root, "node_modules/wxt/dist/client.js")
|
|
55
57
|
);
|
|
58
|
+
const text = await import_fs_extra.default.readFile(path5, "utf-8");
|
|
59
|
+
const res = await unimport2.injectImports(text, path5);
|
|
60
|
+
const transformedText = res.code;
|
|
56
61
|
const jiti = (0, import_jiti.default)(__filename, {
|
|
57
62
|
cache: false,
|
|
58
63
|
esmResolve: true,
|
|
59
64
|
interopDefault: true,
|
|
65
|
+
alias: {
|
|
66
|
+
"webextension-polyfill": "@webext-core/fake-browser"
|
|
67
|
+
},
|
|
60
68
|
transform(opts) {
|
|
69
|
+
if (opts.filename === path5)
|
|
70
|
+
opts.source = transformedText;
|
|
61
71
|
opts.source = opts.source.replace(/^import ['"].*\.css['"];?$/gm, "");
|
|
62
|
-
opts.source = opts.source.replace(
|
|
63
|
-
/^import\s+.*\s+from ['"]webextension-polyfill['"];?$/gm,
|
|
64
|
-
""
|
|
65
|
-
);
|
|
66
|
-
if (opts.filename === path5) {
|
|
67
|
-
const imports = clientImports.map((i) => `import { ${i.name} } from "${i.from}";`).join("\n") + "\n";
|
|
68
|
-
opts.source = imports + opts.source;
|
|
69
|
-
}
|
|
70
72
|
return (0, import_babel.default)(opts);
|
|
71
73
|
}
|
|
72
74
|
});
|
|
@@ -249,7 +251,7 @@ function download(config) {
|
|
|
249
251
|
|
|
250
252
|
// src/core/vite-plugins/multipageMove.ts
|
|
251
253
|
var import_node_path2 = require("path");
|
|
252
|
-
var
|
|
254
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
253
255
|
function multipageMove(entrypoints, config) {
|
|
254
256
|
return {
|
|
255
257
|
name: "wxt:multipage-move",
|
|
@@ -276,8 +278,8 @@ function multipageMove(entrypoints, config) {
|
|
|
276
278
|
}
|
|
277
279
|
const oldAbsPath = (0, import_node_path2.resolve)(config.outDir, oldBundlePath);
|
|
278
280
|
const newAbsPath = (0, import_node_path2.resolve)(config.outDir, newBundlePath);
|
|
279
|
-
await (0,
|
|
280
|
-
await
|
|
281
|
+
await (0, import_fs_extra2.ensureDir)((0, import_node_path2.dirname)(newAbsPath));
|
|
282
|
+
await import_fs_extra2.default.move(oldAbsPath, newAbsPath, { overwrite: true });
|
|
281
283
|
const renamedChunk = {
|
|
282
284
|
...bundle[oldBundlePath],
|
|
283
285
|
fileName: newBundlePath
|
|
@@ -327,7 +329,7 @@ function unimport(config) {
|
|
|
327
329
|
}
|
|
328
330
|
|
|
329
331
|
// src/core/vite-plugins/virtualEntrypoint.ts
|
|
330
|
-
var
|
|
332
|
+
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
331
333
|
var import_path3 = require("path");
|
|
332
334
|
function virtualEntrypoin(type, config) {
|
|
333
335
|
const virtualId = `virtual:wxt-${type}?`;
|
|
@@ -345,7 +347,7 @@ function virtualEntrypoin(type, config) {
|
|
|
345
347
|
if (!id.startsWith(resolvedVirtualId))
|
|
346
348
|
return;
|
|
347
349
|
const inputPath = id.replace(resolvedVirtualId, "");
|
|
348
|
-
const template = await
|
|
350
|
+
const template = await import_fs_extra3.default.readFile(
|
|
349
351
|
(0, import_path3.resolve)(
|
|
350
352
|
config.root,
|
|
351
353
|
`node_modules/wxt/dist/virtual-modules/${type}-entrypoint.js`
|
|
@@ -358,20 +360,20 @@ function virtualEntrypoin(type, config) {
|
|
|
358
360
|
}
|
|
359
361
|
|
|
360
362
|
// src/core/utils/createFsCache.ts
|
|
361
|
-
var
|
|
363
|
+
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
362
364
|
var import_path4 = require("path");
|
|
363
365
|
function createFsCache(wxtDir) {
|
|
364
366
|
const getPath = (key) => (0, import_path4.resolve)(wxtDir, "cache", encodeURIComponent(key));
|
|
365
367
|
return {
|
|
366
368
|
async set(key, value) {
|
|
367
369
|
const path5 = getPath(key);
|
|
368
|
-
await (0,
|
|
369
|
-
await
|
|
370
|
+
await (0, import_fs_extra4.ensureDir)((0, import_path4.dirname)(path5));
|
|
371
|
+
await import_fs_extra4.default.writeFile(path5, value, "utf-8");
|
|
370
372
|
},
|
|
371
373
|
async get(key) {
|
|
372
374
|
const path5 = getPath(key);
|
|
373
375
|
try {
|
|
374
|
-
return await
|
|
376
|
+
return await import_fs_extra4.default.readFile(path5, "utf-8");
|
|
375
377
|
} catch {
|
|
376
378
|
return void 0;
|
|
377
379
|
}
|
|
@@ -614,26 +616,26 @@ var import_node_path4 = require("path");
|
|
|
614
616
|
var vite3 = __toESM(require("vite"), 1);
|
|
615
617
|
|
|
616
618
|
// src/core/utils/removeEmptyDirs.ts
|
|
617
|
-
var
|
|
619
|
+
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
618
620
|
var import_path5 = __toESM(require("path"), 1);
|
|
619
621
|
async function removeEmptyDirs(dir) {
|
|
620
|
-
const files = await
|
|
622
|
+
const files = await import_fs_extra5.default.readdir(dir);
|
|
621
623
|
for (const file of files) {
|
|
622
624
|
const filePath = import_path5.default.join(dir, file);
|
|
623
|
-
const stats = await
|
|
625
|
+
const stats = await import_fs_extra5.default.stat(filePath);
|
|
624
626
|
if (stats.isDirectory()) {
|
|
625
627
|
await removeEmptyDirs(filePath);
|
|
626
628
|
}
|
|
627
629
|
}
|
|
628
630
|
try {
|
|
629
|
-
await
|
|
631
|
+
await import_fs_extra5.default.rmdir(dir);
|
|
630
632
|
} catch {
|
|
631
633
|
}
|
|
632
634
|
}
|
|
633
635
|
|
|
634
636
|
// src/core/build/buildEntrypoints.ts
|
|
635
637
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
636
|
-
var
|
|
638
|
+
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
637
639
|
var import_path6 = require("path");
|
|
638
640
|
async function buildEntrypoints(groups, config) {
|
|
639
641
|
const steps = [];
|
|
@@ -722,20 +724,20 @@ function getBuildOutputChunks(result) {
|
|
|
722
724
|
}
|
|
723
725
|
async function copyPublicDirectory(config) {
|
|
724
726
|
const publicAssets = [];
|
|
725
|
-
if (!await
|
|
727
|
+
if (!await import_fs_extra6.default.exists(config.publicDir))
|
|
726
728
|
return publicAssets;
|
|
727
729
|
const files = await (0, import_fast_glob.default)("**/*", { cwd: config.publicDir });
|
|
728
730
|
for (const file of files) {
|
|
729
731
|
const srcPath = (0, import_path6.resolve)(config.publicDir, file);
|
|
730
732
|
const outPath = (0, import_path6.resolve)(config.outDir, file);
|
|
731
|
-
await
|
|
732
|
-
await
|
|
733
|
+
await import_fs_extra6.default.ensureDir((0, import_path6.dirname)(outPath));
|
|
734
|
+
await import_fs_extra6.default.copyFile(srcPath, outPath);
|
|
733
735
|
publicAssets.push({
|
|
734
736
|
type: "asset",
|
|
735
737
|
fileName: file,
|
|
736
738
|
name: file,
|
|
737
739
|
needsCodeReference: false,
|
|
738
|
-
source: await
|
|
740
|
+
source: await import_fs_extra6.default.readFile(srcPath)
|
|
739
741
|
});
|
|
740
742
|
}
|
|
741
743
|
return publicAssets;
|
|
@@ -743,7 +745,7 @@ async function copyPublicDirectory(config) {
|
|
|
743
745
|
|
|
744
746
|
// src/core/build/findEntrypoints.ts
|
|
745
747
|
var import_path7 = require("path");
|
|
746
|
-
var
|
|
748
|
+
var import_fs_extra7 = __toESM(require("fs-extra"), 1);
|
|
747
749
|
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
748
750
|
var import_linkedom2 = require("linkedom");
|
|
749
751
|
var import_json5 = __toESM(require("json5"), 1);
|
|
@@ -818,7 +820,7 @@ ${JSON.stringify(
|
|
|
818
820
|
}
|
|
819
821
|
async function getPopupEntrypoint(config, path5) {
|
|
820
822
|
const options = {};
|
|
821
|
-
const content = await
|
|
823
|
+
const content = await import_fs_extra7.default.readFile(path5, "utf-8");
|
|
822
824
|
const { document } = (0, import_linkedom2.parseHTML)(content);
|
|
823
825
|
const title = document.querySelector("title");
|
|
824
826
|
if (title != null)
|
|
@@ -848,7 +850,7 @@ async function getPopupEntrypoint(config, path5) {
|
|
|
848
850
|
}
|
|
849
851
|
async function getOptionsEntrypoint(config, path5) {
|
|
850
852
|
const options = {};
|
|
851
|
-
const content = await
|
|
853
|
+
const content = await import_fs_extra7.default.readFile(path5, "utf-8");
|
|
852
854
|
const { document } = (0, import_linkedom2.parseHTML)(content);
|
|
853
855
|
const openInTabContent = document.querySelector("meta[name='manifest.open_in_tab']")?.getAttribute("content");
|
|
854
856
|
if (openInTabContent) {
|
|
@@ -932,10 +934,10 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
932
934
|
|
|
933
935
|
// src/core/build/generateTypesDir.ts
|
|
934
936
|
var import_unimport3 = require("unimport");
|
|
935
|
-
var
|
|
937
|
+
var import_fs_extra8 = __toESM(require("fs-extra"), 1);
|
|
936
938
|
var import_path8 = require("path");
|
|
937
939
|
async function generateTypesDir(entrypoints, config) {
|
|
938
|
-
await
|
|
940
|
+
await import_fs_extra8.default.ensureDir(config.typesDir);
|
|
939
941
|
const references = [];
|
|
940
942
|
references.push(await writeImportsDeclarationFile(config));
|
|
941
943
|
references.push(await writePathsDeclarationFile(entrypoints, config));
|
|
@@ -947,7 +949,7 @@ async function writeImportsDeclarationFile(config) {
|
|
|
947
949
|
const filePath = (0, import_path8.resolve)(config.typesDir, "imports.d.ts");
|
|
948
950
|
const unimport2 = (0, import_unimport3.createUnimport)(getUnimportOptions(config));
|
|
949
951
|
await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
|
|
950
|
-
await
|
|
952
|
+
await import_fs_extra8.default.writeFile(
|
|
951
953
|
filePath,
|
|
952
954
|
["// Generated by wxt", await unimport2.generateTypeDeclarations()].join(
|
|
953
955
|
"\n"
|
|
@@ -957,7 +959,7 @@ async function writeImportsDeclarationFile(config) {
|
|
|
957
959
|
}
|
|
958
960
|
async function writePathsDeclarationFile(entrypoints, config) {
|
|
959
961
|
const filePath = (0, import_path8.resolve)(config.typesDir, "paths.d.ts");
|
|
960
|
-
await
|
|
962
|
+
await import_fs_extra8.default.writeFile(
|
|
961
963
|
filePath,
|
|
962
964
|
[
|
|
963
965
|
"// Generated by wxt",
|
|
@@ -977,7 +979,7 @@ async function writePathsDeclarationFile(entrypoints, config) {
|
|
|
977
979
|
async function writeGlobalsDeclarationFile(config) {
|
|
978
980
|
const filePath = (0, import_path8.resolve)(config.typesDir, "globals.d.ts");
|
|
979
981
|
const globals = getGlobals(config);
|
|
980
|
-
await
|
|
982
|
+
await import_fs_extra8.default.writeFile(
|
|
981
983
|
filePath,
|
|
982
984
|
[
|
|
983
985
|
"// Generated by wxt",
|
|
@@ -993,7 +995,7 @@ async function writeGlobalsDeclarationFile(config) {
|
|
|
993
995
|
async function writeMainDeclarationFile(references, config) {
|
|
994
996
|
const dir = config.wxtDir;
|
|
995
997
|
const filePath = (0, import_path8.resolve)(dir, "wxt.d.ts");
|
|
996
|
-
await
|
|
998
|
+
await import_fs_extra8.default.writeFile(
|
|
997
999
|
filePath,
|
|
998
1000
|
[
|
|
999
1001
|
"// Generated by wxt",
|
|
@@ -1006,7 +1008,7 @@ async function writeMainDeclarationFile(references, config) {
|
|
|
1006
1008
|
}
|
|
1007
1009
|
async function writeTsConfigFile(mainReference, config) {
|
|
1008
1010
|
const dir = config.wxtDir;
|
|
1009
|
-
await
|
|
1011
|
+
await import_fs_extra8.default.writeFile(
|
|
1010
1012
|
(0, import_path8.resolve)(dir, "tsconfig.json"),
|
|
1011
1013
|
`{
|
|
1012
1014
|
"compilerOptions": {
|
|
@@ -1034,7 +1036,7 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1034
1036
|
}
|
|
1035
1037
|
|
|
1036
1038
|
// src/core/utils/manifest.ts
|
|
1037
|
-
var
|
|
1039
|
+
var import_fs_extra9 = __toESM(require("fs-extra"), 1);
|
|
1038
1040
|
var import_path9 = require("path");
|
|
1039
1041
|
|
|
1040
1042
|
// src/core/utils/ContentSecurityPolicy.ts
|
|
@@ -1083,8 +1085,8 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
|
1083
1085
|
// src/core/utils/manifest.ts
|
|
1084
1086
|
async function writeManifest(manifest, output, config) {
|
|
1085
1087
|
const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
1086
|
-
await
|
|
1087
|
-
await
|
|
1088
|
+
await import_fs_extra9.default.ensureDir(config.outDir);
|
|
1089
|
+
await import_fs_extra9.default.writeFile((0, import_path9.resolve)(config.outDir, "manifest.json"), str, "utf-8");
|
|
1088
1090
|
output.publicAssets.unshift({
|
|
1089
1091
|
type: "asset",
|
|
1090
1092
|
fileName: "manifest.json",
|
|
@@ -1117,7 +1119,7 @@ async function generateMainfest(entrypoints, buildOutput, config) {
|
|
|
1117
1119
|
return manifest;
|
|
1118
1120
|
}
|
|
1119
1121
|
async function getPackageJson(config) {
|
|
1120
|
-
return await
|
|
1122
|
+
return await import_fs_extra9.default.readJson((0, import_path9.resolve)(config.root, "package.json"));
|
|
1121
1123
|
}
|
|
1122
1124
|
function simplifyVersion(versionName) {
|
|
1123
1125
|
const version3 = /^((0|[1-9][0-9]{0,8})([.](0|[1-9][0-9]{0,8})){0,3}).*$/.exec(
|
|
@@ -1362,7 +1364,7 @@ function addHostPermission(manifest, hostPermission) {
|
|
|
1362
1364
|
// src/core/build.ts
|
|
1363
1365
|
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
1364
1366
|
var vite4 = __toESM(require("vite"), 1);
|
|
1365
|
-
var
|
|
1367
|
+
var import_fs_extra11 = __toESM(require("fs-extra"), 1);
|
|
1366
1368
|
|
|
1367
1369
|
// src/core/utils/groupEntrypoints.ts
|
|
1368
1370
|
function groupEntrypoints(entrypoints) {
|
|
@@ -1440,7 +1442,7 @@ function printTable(log, rows, gap = 2) {
|
|
|
1440
1442
|
|
|
1441
1443
|
// src/core/log/printBuildSummary.ts
|
|
1442
1444
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
1443
|
-
var
|
|
1445
|
+
var import_fs_extra10 = __toESM(require("fs-extra"), 1);
|
|
1444
1446
|
var import_filesize = require("filesize");
|
|
1445
1447
|
async function printBuildSummary(output, config) {
|
|
1446
1448
|
const chunks = [
|
|
@@ -1464,7 +1466,7 @@ async function printBuildSummary(output, config) {
|
|
|
1464
1466
|
const ext = (0, import_path10.extname)(chunk.fileName);
|
|
1465
1467
|
const prefix = i === chunks.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1466
1468
|
const color = CHUNK_COLORS[ext] ?? DEFAULT_COLOR;
|
|
1467
|
-
const stats = await
|
|
1469
|
+
const stats = await import_fs_extra10.default.lstat((0, import_path10.resolve)(config.outDir, chunk.fileName));
|
|
1468
1470
|
totalSize += stats.size;
|
|
1469
1471
|
const size = String((0, import_filesize.filesize)(stats.size));
|
|
1470
1472
|
return [
|
|
@@ -1502,8 +1504,8 @@ async function buildInternal(config) {
|
|
|
1502
1504
|
)}`
|
|
1503
1505
|
);
|
|
1504
1506
|
const startTime = Date.now();
|
|
1505
|
-
await
|
|
1506
|
-
await
|
|
1507
|
+
await import_fs_extra11.default.rm(config.outDir, { recursive: true, force: true });
|
|
1508
|
+
await import_fs_extra11.default.ensureDir(config.outDir);
|
|
1507
1509
|
const entrypoints = await findEntrypoints(config);
|
|
1508
1510
|
const groups = groupEntrypoints(entrypoints);
|
|
1509
1511
|
const { output } = await rebuild(config, groups);
|
|
@@ -1716,7 +1718,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1716
1718
|
}
|
|
1717
1719
|
|
|
1718
1720
|
// package.json
|
|
1719
|
-
var version2 = "0.1.
|
|
1721
|
+
var version2 = "0.1.1-alpha2";
|
|
1720
1722
|
|
|
1721
1723
|
// src/core/utils/defineConfig.ts
|
|
1722
1724
|
function defineConfig(config) {
|