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.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -8,25 +8,27 @@ import { consola } from "consola";
|
|
|
8
8
|
import createJITI from "jiti";
|
|
9
9
|
import transform from "jiti/dist/babel";
|
|
10
10
|
import { resolve } from "path";
|
|
11
|
-
import {
|
|
11
|
+
import { createUnimport } from "unimport";
|
|
12
|
+
import fs from "fs-extra";
|
|
12
13
|
async function importTsFile(root, path5) {
|
|
13
|
-
const
|
|
14
|
+
const unimport2 = createUnimport({});
|
|
15
|
+
await unimport2.scanImportsFromFile(
|
|
14
16
|
resolve(root, "node_modules/wxt/dist/client.js")
|
|
15
17
|
);
|
|
18
|
+
const text = await fs.readFile(path5, "utf-8");
|
|
19
|
+
const res = await unimport2.injectImports(text, path5);
|
|
20
|
+
const transformedText = res.code;
|
|
16
21
|
const jiti = createJITI(__filename, {
|
|
17
22
|
cache: false,
|
|
18
23
|
esmResolve: true,
|
|
19
24
|
interopDefault: true,
|
|
25
|
+
alias: {
|
|
26
|
+
"webextension-polyfill": "@webext-core/fake-browser"
|
|
27
|
+
},
|
|
20
28
|
transform(opts) {
|
|
29
|
+
if (opts.filename === path5)
|
|
30
|
+
opts.source = transformedText;
|
|
21
31
|
opts.source = opts.source.replace(/^import ['"].*\.css['"];?$/gm, "");
|
|
22
|
-
opts.source = opts.source.replace(
|
|
23
|
-
/^import\s+.*\s+from ['"]webextension-polyfill['"];?$/gm,
|
|
24
|
-
""
|
|
25
|
-
);
|
|
26
|
-
if (opts.filename === path5) {
|
|
27
|
-
const imports = clientImports.map((i) => `import { ${i.name} } from "${i.from}";`).join("\n") + "\n";
|
|
28
|
-
opts.source = imports + opts.source;
|
|
29
|
-
}
|
|
30
32
|
return transform(opts);
|
|
31
33
|
}
|
|
32
34
|
});
|
|
@@ -209,7 +211,7 @@ function download(config) {
|
|
|
209
211
|
|
|
210
212
|
// src/core/vite-plugins/multipageMove.ts
|
|
211
213
|
import { dirname as dirname2, extname, resolve as resolve4 } from "node:path";
|
|
212
|
-
import
|
|
214
|
+
import fs2, { ensureDir } from "fs-extra";
|
|
213
215
|
function multipageMove(entrypoints, config) {
|
|
214
216
|
return {
|
|
215
217
|
name: "wxt:multipage-move",
|
|
@@ -237,7 +239,7 @@ function multipageMove(entrypoints, config) {
|
|
|
237
239
|
const oldAbsPath = resolve4(config.outDir, oldBundlePath);
|
|
238
240
|
const newAbsPath = resolve4(config.outDir, newBundlePath);
|
|
239
241
|
await ensureDir(dirname2(newAbsPath));
|
|
240
|
-
await
|
|
242
|
+
await fs2.move(oldAbsPath, newAbsPath, { overwrite: true });
|
|
241
243
|
const renamedChunk = {
|
|
242
244
|
...bundle[oldBundlePath],
|
|
243
245
|
fileName: newBundlePath
|
|
@@ -250,7 +252,7 @@ function multipageMove(entrypoints, config) {
|
|
|
250
252
|
}
|
|
251
253
|
|
|
252
254
|
// src/core/vite-plugins/unimport.ts
|
|
253
|
-
import { createUnimport } from "unimport";
|
|
255
|
+
import { createUnimport as createUnimport2 } from "unimport";
|
|
254
256
|
|
|
255
257
|
// src/core/utils/auto-imports.ts
|
|
256
258
|
import { mergeConfig as mergeConfig2 } from "vite";
|
|
@@ -274,7 +276,7 @@ function getUnimportOptions(config) {
|
|
|
274
276
|
// src/core/vite-plugins/unimport.ts
|
|
275
277
|
function unimport(config) {
|
|
276
278
|
const options = getUnimportOptions(config);
|
|
277
|
-
const unimport2 =
|
|
279
|
+
const unimport2 = createUnimport2(options);
|
|
278
280
|
return {
|
|
279
281
|
name: "wxt:unimport",
|
|
280
282
|
async config() {
|
|
@@ -287,7 +289,7 @@ function unimport(config) {
|
|
|
287
289
|
}
|
|
288
290
|
|
|
289
291
|
// src/core/vite-plugins/virtualEntrypoint.ts
|
|
290
|
-
import
|
|
292
|
+
import fs3 from "fs-extra";
|
|
291
293
|
import { resolve as resolve5 } from "path";
|
|
292
294
|
function virtualEntrypoin(type, config) {
|
|
293
295
|
const virtualId = `virtual:wxt-${type}?`;
|
|
@@ -305,7 +307,7 @@ function virtualEntrypoin(type, config) {
|
|
|
305
307
|
if (!id.startsWith(resolvedVirtualId))
|
|
306
308
|
return;
|
|
307
309
|
const inputPath = id.replace(resolvedVirtualId, "");
|
|
308
|
-
const template = await
|
|
310
|
+
const template = await fs3.readFile(
|
|
309
311
|
resolve5(
|
|
310
312
|
config.root,
|
|
311
313
|
`node_modules/wxt/dist/virtual-modules/${type}-entrypoint.js`
|
|
@@ -318,7 +320,7 @@ function virtualEntrypoin(type, config) {
|
|
|
318
320
|
}
|
|
319
321
|
|
|
320
322
|
// src/core/utils/createFsCache.ts
|
|
321
|
-
import
|
|
323
|
+
import fs4, { ensureDir as ensureDir2 } from "fs-extra";
|
|
322
324
|
import { dirname as dirname3, resolve as resolve6 } from "path";
|
|
323
325
|
function createFsCache(wxtDir) {
|
|
324
326
|
const getPath = (key) => resolve6(wxtDir, "cache", encodeURIComponent(key));
|
|
@@ -326,12 +328,12 @@ function createFsCache(wxtDir) {
|
|
|
326
328
|
async set(key, value) {
|
|
327
329
|
const path5 = getPath(key);
|
|
328
330
|
await ensureDir2(dirname3(path5));
|
|
329
|
-
await
|
|
331
|
+
await fs4.writeFile(path5, value, "utf-8");
|
|
330
332
|
},
|
|
331
333
|
async get(key) {
|
|
332
334
|
const path5 = getPath(key);
|
|
333
335
|
try {
|
|
334
|
-
return await
|
|
336
|
+
return await fs4.readFile(path5, "utf-8");
|
|
335
337
|
} catch {
|
|
336
338
|
return void 0;
|
|
337
339
|
}
|
|
@@ -574,26 +576,26 @@ import { relative as relative6 } from "node:path";
|
|
|
574
576
|
import * as vite3 from "vite";
|
|
575
577
|
|
|
576
578
|
// src/core/utils/removeEmptyDirs.ts
|
|
577
|
-
import
|
|
579
|
+
import fs5 from "fs-extra";
|
|
578
580
|
import path3 from "path";
|
|
579
581
|
async function removeEmptyDirs(dir) {
|
|
580
|
-
const files = await
|
|
582
|
+
const files = await fs5.readdir(dir);
|
|
581
583
|
for (const file of files) {
|
|
582
584
|
const filePath = path3.join(dir, file);
|
|
583
|
-
const stats = await
|
|
585
|
+
const stats = await fs5.stat(filePath);
|
|
584
586
|
if (stats.isDirectory()) {
|
|
585
587
|
await removeEmptyDirs(filePath);
|
|
586
588
|
}
|
|
587
589
|
}
|
|
588
590
|
try {
|
|
589
|
-
await
|
|
591
|
+
await fs5.rmdir(dir);
|
|
590
592
|
} catch {
|
|
591
593
|
}
|
|
592
594
|
}
|
|
593
595
|
|
|
594
596
|
// src/core/build/buildEntrypoints.ts
|
|
595
597
|
import glob from "fast-glob";
|
|
596
|
-
import
|
|
598
|
+
import fs6 from "fs-extra";
|
|
597
599
|
import { dirname as dirname4, resolve as resolve8 } from "path";
|
|
598
600
|
async function buildEntrypoints(groups, config) {
|
|
599
601
|
const steps = [];
|
|
@@ -682,20 +684,20 @@ function getBuildOutputChunks(result) {
|
|
|
682
684
|
}
|
|
683
685
|
async function copyPublicDirectory(config) {
|
|
684
686
|
const publicAssets = [];
|
|
685
|
-
if (!await
|
|
687
|
+
if (!await fs6.exists(config.publicDir))
|
|
686
688
|
return publicAssets;
|
|
687
689
|
const files = await glob("**/*", { cwd: config.publicDir });
|
|
688
690
|
for (const file of files) {
|
|
689
691
|
const srcPath = resolve8(config.publicDir, file);
|
|
690
692
|
const outPath = resolve8(config.outDir, file);
|
|
691
|
-
await
|
|
692
|
-
await
|
|
693
|
+
await fs6.ensureDir(dirname4(outPath));
|
|
694
|
+
await fs6.copyFile(srcPath, outPath);
|
|
693
695
|
publicAssets.push({
|
|
694
696
|
type: "asset",
|
|
695
697
|
fileName: file,
|
|
696
698
|
name: file,
|
|
697
699
|
needsCodeReference: false,
|
|
698
|
-
source: await
|
|
700
|
+
source: await fs6.readFile(srcPath)
|
|
699
701
|
});
|
|
700
702
|
}
|
|
701
703
|
return publicAssets;
|
|
@@ -703,7 +705,7 @@ async function copyPublicDirectory(config) {
|
|
|
703
705
|
|
|
704
706
|
// src/core/build/findEntrypoints.ts
|
|
705
707
|
import { relative as relative3, resolve as resolve9 } from "path";
|
|
706
|
-
import
|
|
708
|
+
import fs7 from "fs-extra";
|
|
707
709
|
import picomatch from "picomatch";
|
|
708
710
|
import { parseHTML as parseHTML2 } from "linkedom";
|
|
709
711
|
import JSON5 from "json5";
|
|
@@ -778,7 +780,7 @@ ${JSON.stringify(
|
|
|
778
780
|
}
|
|
779
781
|
async function getPopupEntrypoint(config, path5) {
|
|
780
782
|
const options = {};
|
|
781
|
-
const content = await
|
|
783
|
+
const content = await fs7.readFile(path5, "utf-8");
|
|
782
784
|
const { document } = parseHTML2(content);
|
|
783
785
|
const title = document.querySelector("title");
|
|
784
786
|
if (title != null)
|
|
@@ -808,7 +810,7 @@ async function getPopupEntrypoint(config, path5) {
|
|
|
808
810
|
}
|
|
809
811
|
async function getOptionsEntrypoint(config, path5) {
|
|
810
812
|
const options = {};
|
|
811
|
-
const content = await
|
|
813
|
+
const content = await fs7.readFile(path5, "utf-8");
|
|
812
814
|
const { document } = parseHTML2(content);
|
|
813
815
|
const openInTabContent = document.querySelector("meta[name='manifest.open_in_tab']")?.getAttribute("content");
|
|
814
816
|
if (openInTabContent) {
|
|
@@ -891,11 +893,11 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
891
893
|
};
|
|
892
894
|
|
|
893
895
|
// src/core/build/generateTypesDir.ts
|
|
894
|
-
import { createUnimport as
|
|
895
|
-
import
|
|
896
|
+
import { createUnimport as createUnimport3 } from "unimport";
|
|
897
|
+
import fs8 from "fs-extra";
|
|
896
898
|
import { relative as relative4, resolve as resolve10 } from "path";
|
|
897
899
|
async function generateTypesDir(entrypoints, config) {
|
|
898
|
-
await
|
|
900
|
+
await fs8.ensureDir(config.typesDir);
|
|
899
901
|
const references = [];
|
|
900
902
|
references.push(await writeImportsDeclarationFile(config));
|
|
901
903
|
references.push(await writePathsDeclarationFile(entrypoints, config));
|
|
@@ -905,9 +907,9 @@ async function generateTypesDir(entrypoints, config) {
|
|
|
905
907
|
}
|
|
906
908
|
async function writeImportsDeclarationFile(config) {
|
|
907
909
|
const filePath = resolve10(config.typesDir, "imports.d.ts");
|
|
908
|
-
const unimport2 =
|
|
910
|
+
const unimport2 = createUnimport3(getUnimportOptions(config));
|
|
909
911
|
await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
|
|
910
|
-
await
|
|
912
|
+
await fs8.writeFile(
|
|
911
913
|
filePath,
|
|
912
914
|
["// Generated by wxt", await unimport2.generateTypeDeclarations()].join(
|
|
913
915
|
"\n"
|
|
@@ -917,7 +919,7 @@ async function writeImportsDeclarationFile(config) {
|
|
|
917
919
|
}
|
|
918
920
|
async function writePathsDeclarationFile(entrypoints, config) {
|
|
919
921
|
const filePath = resolve10(config.typesDir, "paths.d.ts");
|
|
920
|
-
await
|
|
922
|
+
await fs8.writeFile(
|
|
921
923
|
filePath,
|
|
922
924
|
[
|
|
923
925
|
"// Generated by wxt",
|
|
@@ -937,7 +939,7 @@ async function writePathsDeclarationFile(entrypoints, config) {
|
|
|
937
939
|
async function writeGlobalsDeclarationFile(config) {
|
|
938
940
|
const filePath = resolve10(config.typesDir, "globals.d.ts");
|
|
939
941
|
const globals = getGlobals(config);
|
|
940
|
-
await
|
|
942
|
+
await fs8.writeFile(
|
|
941
943
|
filePath,
|
|
942
944
|
[
|
|
943
945
|
"// Generated by wxt",
|
|
@@ -953,7 +955,7 @@ async function writeGlobalsDeclarationFile(config) {
|
|
|
953
955
|
async function writeMainDeclarationFile(references, config) {
|
|
954
956
|
const dir = config.wxtDir;
|
|
955
957
|
const filePath = resolve10(dir, "wxt.d.ts");
|
|
956
|
-
await
|
|
958
|
+
await fs8.writeFile(
|
|
957
959
|
filePath,
|
|
958
960
|
[
|
|
959
961
|
"// Generated by wxt",
|
|
@@ -966,7 +968,7 @@ async function writeMainDeclarationFile(references, config) {
|
|
|
966
968
|
}
|
|
967
969
|
async function writeTsConfigFile(mainReference, config) {
|
|
968
970
|
const dir = config.wxtDir;
|
|
969
|
-
await
|
|
971
|
+
await fs8.writeFile(
|
|
970
972
|
resolve10(dir, "tsconfig.json"),
|
|
971
973
|
`{
|
|
972
974
|
"compilerOptions": {
|
|
@@ -994,7 +996,7 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
994
996
|
}
|
|
995
997
|
|
|
996
998
|
// src/core/utils/manifest.ts
|
|
997
|
-
import
|
|
999
|
+
import fs9 from "fs-extra";
|
|
998
1000
|
import { resolve as resolve11 } from "path";
|
|
999
1001
|
|
|
1000
1002
|
// src/core/utils/ContentSecurityPolicy.ts
|
|
@@ -1043,8 +1045,8 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
|
1043
1045
|
// src/core/utils/manifest.ts
|
|
1044
1046
|
async function writeManifest(manifest, output, config) {
|
|
1045
1047
|
const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
1046
|
-
await
|
|
1047
|
-
await
|
|
1048
|
+
await fs9.ensureDir(config.outDir);
|
|
1049
|
+
await fs9.writeFile(resolve11(config.outDir, "manifest.json"), str, "utf-8");
|
|
1048
1050
|
output.publicAssets.unshift({
|
|
1049
1051
|
type: "asset",
|
|
1050
1052
|
fileName: "manifest.json",
|
|
@@ -1077,7 +1079,7 @@ async function generateMainfest(entrypoints, buildOutput, config) {
|
|
|
1077
1079
|
return manifest;
|
|
1078
1080
|
}
|
|
1079
1081
|
async function getPackageJson(config) {
|
|
1080
|
-
return await
|
|
1082
|
+
return await fs9.readJson(resolve11(config.root, "package.json"));
|
|
1081
1083
|
}
|
|
1082
1084
|
function simplifyVersion(versionName) {
|
|
1083
1085
|
const version3 = /^((0|[1-9][0-9]{0,8})([.](0|[1-9][0-9]{0,8})){0,3}).*$/.exec(
|
|
@@ -1322,7 +1324,7 @@ function addHostPermission(manifest, hostPermission) {
|
|
|
1322
1324
|
// src/core/build.ts
|
|
1323
1325
|
import pc2 from "picocolors";
|
|
1324
1326
|
import * as vite4 from "vite";
|
|
1325
|
-
import
|
|
1327
|
+
import fs11 from "fs-extra";
|
|
1326
1328
|
|
|
1327
1329
|
// src/core/utils/groupEntrypoints.ts
|
|
1328
1330
|
function groupEntrypoints(entrypoints) {
|
|
@@ -1400,7 +1402,7 @@ function printTable(log, rows, gap = 2) {
|
|
|
1400
1402
|
|
|
1401
1403
|
// src/core/log/printBuildSummary.ts
|
|
1402
1404
|
import pc from "picocolors";
|
|
1403
|
-
import
|
|
1405
|
+
import fs10 from "fs-extra";
|
|
1404
1406
|
import { filesize } from "filesize";
|
|
1405
1407
|
async function printBuildSummary(output, config) {
|
|
1406
1408
|
const chunks = [
|
|
@@ -1424,7 +1426,7 @@ async function printBuildSummary(output, config) {
|
|
|
1424
1426
|
const ext = extname2(chunk.fileName);
|
|
1425
1427
|
const prefix = i === chunks.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1426
1428
|
const color = CHUNK_COLORS[ext] ?? DEFAULT_COLOR;
|
|
1427
|
-
const stats = await
|
|
1429
|
+
const stats = await fs10.lstat(resolve12(config.outDir, chunk.fileName));
|
|
1428
1430
|
totalSize += stats.size;
|
|
1429
1431
|
const size = String(filesize(stats.size));
|
|
1430
1432
|
return [
|
|
@@ -1462,8 +1464,8 @@ async function buildInternal(config) {
|
|
|
1462
1464
|
)}`
|
|
1463
1465
|
);
|
|
1464
1466
|
const startTime = Date.now();
|
|
1465
|
-
await
|
|
1466
|
-
await
|
|
1467
|
+
await fs11.rm(config.outDir, { recursive: true, force: true });
|
|
1468
|
+
await fs11.ensureDir(config.outDir);
|
|
1467
1469
|
const entrypoints = await findEntrypoints(config);
|
|
1468
1470
|
const groups = groupEntrypoints(entrypoints);
|
|
1469
1471
|
const { output } = await rebuild(config, groups);
|
|
@@ -1676,7 +1678,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1676
1678
|
}
|
|
1677
1679
|
|
|
1678
1680
|
// package.json
|
|
1679
|
-
var version2 = "0.1.
|
|
1681
|
+
var version2 = "0.1.1-alpha2";
|
|
1680
1682
|
|
|
1681
1683
|
// src/core/utils/defineConfig.ts
|
|
1682
1684
|
function defineConfig(config) {
|