wxt 0.3.2 → 0.4.1
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/browser.d.ts +7 -4
- package/dist/browser.js +1 -1
- package/dist/cli.cjs +455 -514
- package/dist/index.cjs +233 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -3
- package/dist/index.d.ts +20 -3
- package/dist/index.js +229 -78
- package/dist/index.js.map +1 -1
- package/package.json +16 -12
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/core/utils/getInternalConfig.ts
|
|
2
2
|
import path2, { resolve as resolve6 } from "node:path";
|
|
3
3
|
import * as vite2 from "vite";
|
|
4
|
-
import { consola } from "consola";
|
|
4
|
+
import { LogLevels, consola } from "consola";
|
|
5
5
|
|
|
6
6
|
// src/core/utils/entrypoints.ts
|
|
7
7
|
import path, { relative, resolve } from "node:path";
|
|
@@ -9,11 +9,11 @@ import path, { relative, resolve } from "node:path";
|
|
|
9
9
|
// src/core/utils/paths.ts
|
|
10
10
|
import nodePath from "node:path";
|
|
11
11
|
import * as vite from "vite";
|
|
12
|
-
function normalizePath2(
|
|
13
|
-
return vite.normalizePath(
|
|
12
|
+
function normalizePath2(path7) {
|
|
13
|
+
return vite.normalizePath(path7);
|
|
14
14
|
}
|
|
15
|
-
function unnormalizePath(
|
|
16
|
-
return nodePath.normalize(
|
|
15
|
+
function unnormalizePath(path7) {
|
|
16
|
+
return nodePath.normalize(path7);
|
|
17
17
|
}
|
|
18
18
|
var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
|
|
19
19
|
var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
|
|
@@ -195,7 +195,9 @@ function multipageMove(entrypoints, config) {
|
|
|
195
195
|
(entry) => !!normalizePath2(entry.inputPath).endsWith(oldBundlePath)
|
|
196
196
|
);
|
|
197
197
|
if (entrypoint == null) {
|
|
198
|
-
config.logger.debug(
|
|
198
|
+
config.logger.debug(
|
|
199
|
+
`No entrypoint found for ${oldBundlePath}, leaving in chunks directory`
|
|
200
|
+
);
|
|
199
201
|
continue;
|
|
200
202
|
}
|
|
201
203
|
const newBundlePath = getEntrypointBundlePath(
|
|
@@ -302,12 +304,22 @@ function virtualEntrypoin(type, config) {
|
|
|
302
304
|
}
|
|
303
305
|
|
|
304
306
|
// src/core/vite-plugins/tsconfigPaths.ts
|
|
305
|
-
import paths from "vite-tsconfig-paths";
|
|
306
307
|
function tsconfigPaths(config) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
308
|
+
return {
|
|
309
|
+
name: "wxt:aliases",
|
|
310
|
+
async config() {
|
|
311
|
+
return {
|
|
312
|
+
resolve: {
|
|
313
|
+
alias: {
|
|
314
|
+
"@@": config.root,
|
|
315
|
+
"~~": config.root,
|
|
316
|
+
"@": config.srcDir,
|
|
317
|
+
"~": config.srcDir
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
};
|
|
311
323
|
}
|
|
312
324
|
|
|
313
325
|
// src/core/vite-plugins/noopBackground.ts
|
|
@@ -361,14 +373,14 @@ function createFsCache(wxtDir) {
|
|
|
361
373
|
const getPath = (key) => resolve5(wxtDir, "cache", encodeURIComponent(key));
|
|
362
374
|
return {
|
|
363
375
|
async set(key, value) {
|
|
364
|
-
const
|
|
365
|
-
await ensureDir2(dirname3(
|
|
366
|
-
await fs3.writeFile(
|
|
376
|
+
const path7 = getPath(key);
|
|
377
|
+
await ensureDir2(dirname3(path7));
|
|
378
|
+
await fs3.writeFile(path7, value, "utf-8");
|
|
367
379
|
},
|
|
368
380
|
async get(key) {
|
|
369
|
-
const
|
|
381
|
+
const path7 = getPath(key);
|
|
370
382
|
try {
|
|
371
|
-
return await fs3.readFile(
|
|
383
|
+
return await fs3.readFile(path7, "utf-8");
|
|
372
384
|
} catch {
|
|
373
385
|
return void 0;
|
|
374
386
|
}
|
|
@@ -432,6 +444,9 @@ async function getInternalConfig(config, command) {
|
|
|
432
444
|
const outBaseDir = path2.resolve(root, ".output");
|
|
433
445
|
const outDir = path2.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
|
|
434
446
|
const logger = config.logger ?? consola;
|
|
447
|
+
const debug = !!config.debug;
|
|
448
|
+
if (debug)
|
|
449
|
+
logger.level = LogLevels.debug;
|
|
435
450
|
const baseConfig = {
|
|
436
451
|
root,
|
|
437
452
|
outDir,
|
|
@@ -441,6 +456,7 @@ async function getInternalConfig(config, command) {
|
|
|
441
456
|
manifestVersion,
|
|
442
457
|
mode,
|
|
443
458
|
command,
|
|
459
|
+
debug,
|
|
444
460
|
logger,
|
|
445
461
|
vite: config.vite ?? {},
|
|
446
462
|
imports: config.imports ?? {},
|
|
@@ -473,7 +489,7 @@ async function getInternalConfig(config, command) {
|
|
|
473
489
|
userConfig.entrypointsDir ?? "entrypoints"
|
|
474
490
|
);
|
|
475
491
|
const publicDir = resolve6(root, userConfig.publicDir ?? "public");
|
|
476
|
-
const wxtDir = resolve6(
|
|
492
|
+
const wxtDir = resolve6(root, ".wxt");
|
|
477
493
|
const typesDir = resolve6(wxtDir, "types");
|
|
478
494
|
const env = { mode, browser, manifestVersion, command };
|
|
479
495
|
const userManifest = await resolveManifestConfig(env, userConfig.manifest);
|
|
@@ -539,7 +555,7 @@ async function resolveManifestConfig(env, manifest) {
|
|
|
539
555
|
}
|
|
540
556
|
|
|
541
557
|
// src/index.ts
|
|
542
|
-
import
|
|
558
|
+
import pc4 from "picocolors";
|
|
543
559
|
import * as vite6 from "vite";
|
|
544
560
|
|
|
545
561
|
// src/core/utils/arrays.ts
|
|
@@ -636,7 +652,7 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
636
652
|
|
|
637
653
|
// src/index.ts
|
|
638
654
|
import { Mutex } from "async-mutex";
|
|
639
|
-
import { consola as
|
|
655
|
+
import { consola as consola3 } from "consola";
|
|
640
656
|
import { relative as relative5 } from "node:path";
|
|
641
657
|
|
|
642
658
|
// src/core/build/buildEntrypoints.ts
|
|
@@ -809,16 +825,16 @@ function removeImportStatements(text) {
|
|
|
809
825
|
}
|
|
810
826
|
|
|
811
827
|
// src/core/utils/importTsFile.ts
|
|
812
|
-
async function importTsFile(
|
|
813
|
-
config.logger.debug("Loading file metadata:",
|
|
814
|
-
const normalPath = normalizePath2(
|
|
828
|
+
async function importTsFile(path7, config) {
|
|
829
|
+
config.logger.debug("Loading file metadata:", path7);
|
|
830
|
+
const normalPath = normalizePath2(path7);
|
|
815
831
|
const unimport2 = createUnimport2({
|
|
816
832
|
...getUnimportOptions(config),
|
|
817
833
|
// Only allow specific imports, not all from the project
|
|
818
834
|
dirs: []
|
|
819
835
|
});
|
|
820
836
|
await unimport2.init();
|
|
821
|
-
const text = await fs7.readFile(
|
|
837
|
+
const text = await fs7.readFile(path7, "utf-8");
|
|
822
838
|
const textNoImports = removeImportStatements(text);
|
|
823
839
|
const { code } = await unimport2.injectImports(textNoImports);
|
|
824
840
|
config.logger.debug(
|
|
@@ -842,7 +858,7 @@ async function importTsFile(path5, config) {
|
|
|
842
858
|
}
|
|
843
859
|
});
|
|
844
860
|
try {
|
|
845
|
-
return await jiti(
|
|
861
|
+
return await jiti(path7);
|
|
846
862
|
} catch (err) {
|
|
847
863
|
config.logger.error(err);
|
|
848
864
|
throw err;
|
|
@@ -862,9 +878,9 @@ async function findEntrypoints(config) {
|
|
|
862
878
|
let hasBackground = false;
|
|
863
879
|
await Promise.all(
|
|
864
880
|
relativePaths.map(async (relativePath) => {
|
|
865
|
-
const
|
|
881
|
+
const path7 = resolve9(config.entrypointsDir, relativePath);
|
|
866
882
|
const matchingGlob = pathGlobs.find(
|
|
867
|
-
(
|
|
883
|
+
(glob4) => minimatch(relativePath, glob4)
|
|
868
884
|
);
|
|
869
885
|
if (matchingGlob == null) {
|
|
870
886
|
return config.logger.warn(
|
|
@@ -882,35 +898,35 @@ ${JSON.stringify(
|
|
|
882
898
|
let entrypoint;
|
|
883
899
|
switch (type) {
|
|
884
900
|
case "popup":
|
|
885
|
-
entrypoint = await getPopupEntrypoint(config,
|
|
901
|
+
entrypoint = await getPopupEntrypoint(config, path7);
|
|
886
902
|
break;
|
|
887
903
|
case "options":
|
|
888
|
-
entrypoint = await getOptionsEntrypoint(config,
|
|
904
|
+
entrypoint = await getOptionsEntrypoint(config, path7);
|
|
889
905
|
break;
|
|
890
906
|
case "background":
|
|
891
|
-
entrypoint = await getBackgroundEntrypoint(config,
|
|
907
|
+
entrypoint = await getBackgroundEntrypoint(config, path7);
|
|
892
908
|
hasBackground = true;
|
|
893
909
|
break;
|
|
894
910
|
case "content-script":
|
|
895
911
|
entrypoint = await getContentScriptEntrypoint(
|
|
896
912
|
config,
|
|
897
|
-
getEntrypointName(config.entrypointsDir,
|
|
898
|
-
|
|
913
|
+
getEntrypointName(config.entrypointsDir, path7),
|
|
914
|
+
path7
|
|
899
915
|
);
|
|
900
916
|
break;
|
|
901
917
|
case "content-script-style":
|
|
902
918
|
entrypoint = {
|
|
903
919
|
type,
|
|
904
|
-
name: getEntrypointName(config.entrypointsDir,
|
|
905
|
-
inputPath:
|
|
920
|
+
name: getEntrypointName(config.entrypointsDir, path7),
|
|
921
|
+
inputPath: path7,
|
|
906
922
|
outputDir: resolve9(config.outDir, CONTENT_SCRIPT_OUT_DIR)
|
|
907
923
|
};
|
|
908
924
|
break;
|
|
909
925
|
default:
|
|
910
926
|
entrypoint = {
|
|
911
927
|
type,
|
|
912
|
-
name: getEntrypointName(config.entrypointsDir,
|
|
913
|
-
inputPath:
|
|
928
|
+
name: getEntrypointName(config.entrypointsDir, path7),
|
|
929
|
+
inputPath: path7,
|
|
914
930
|
outputDir: config.outDir
|
|
915
931
|
};
|
|
916
932
|
}
|
|
@@ -934,9 +950,9 @@ ${JSON.stringify(
|
|
|
934
950
|
}
|
|
935
951
|
return entrypoints;
|
|
936
952
|
}
|
|
937
|
-
async function getPopupEntrypoint(config,
|
|
953
|
+
async function getPopupEntrypoint(config, path7) {
|
|
938
954
|
const options = {};
|
|
939
|
-
const content = await fs8.readFile(
|
|
955
|
+
const content = await fs8.readFile(path7, "utf-8");
|
|
940
956
|
const { document } = parseHTML2(content);
|
|
941
957
|
const title = document.querySelector("title");
|
|
942
958
|
if (title != null)
|
|
@@ -960,13 +976,13 @@ async function getPopupEntrypoint(config, path5) {
|
|
|
960
976
|
type: "popup",
|
|
961
977
|
name: "popup",
|
|
962
978
|
options,
|
|
963
|
-
inputPath:
|
|
979
|
+
inputPath: path7,
|
|
964
980
|
outputDir: config.outDir
|
|
965
981
|
};
|
|
966
982
|
}
|
|
967
|
-
async function getOptionsEntrypoint(config,
|
|
983
|
+
async function getOptionsEntrypoint(config, path7) {
|
|
968
984
|
const options = {};
|
|
969
|
-
const content = await fs8.readFile(
|
|
985
|
+
const content = await fs8.readFile(path7, "utf-8");
|
|
970
986
|
const { document } = parseHTML2(content);
|
|
971
987
|
const openInTabContent = document.querySelector("meta[name='manifest.open_in_tab']")?.getAttribute("content");
|
|
972
988
|
if (openInTabContent) {
|
|
@@ -984,15 +1000,15 @@ async function getOptionsEntrypoint(config, path5) {
|
|
|
984
1000
|
type: "options",
|
|
985
1001
|
name: "options",
|
|
986
1002
|
options,
|
|
987
|
-
inputPath:
|
|
1003
|
+
inputPath: path7,
|
|
988
1004
|
outputDir: config.outDir
|
|
989
1005
|
};
|
|
990
1006
|
}
|
|
991
|
-
async function getBackgroundEntrypoint(config,
|
|
1007
|
+
async function getBackgroundEntrypoint(config, path7) {
|
|
992
1008
|
let options = {};
|
|
993
|
-
if (
|
|
1009
|
+
if (path7 !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
|
|
994
1010
|
const defaultExport = await importTsFile(
|
|
995
|
-
|
|
1011
|
+
path7,
|
|
996
1012
|
config
|
|
997
1013
|
);
|
|
998
1014
|
if (defaultExport == null) {
|
|
@@ -1004,14 +1020,14 @@ async function getBackgroundEntrypoint(config, path5) {
|
|
|
1004
1020
|
return {
|
|
1005
1021
|
type: "background",
|
|
1006
1022
|
name: "background",
|
|
1007
|
-
inputPath:
|
|
1023
|
+
inputPath: path7,
|
|
1008
1024
|
outputDir: config.outDir,
|
|
1009
1025
|
options
|
|
1010
1026
|
};
|
|
1011
1027
|
}
|
|
1012
|
-
async function getContentScriptEntrypoint(config, name,
|
|
1028
|
+
async function getContentScriptEntrypoint(config, name, path7) {
|
|
1013
1029
|
const { main: _, ...options } = await importTsFile(
|
|
1014
|
-
|
|
1030
|
+
path7,
|
|
1015
1031
|
config
|
|
1016
1032
|
);
|
|
1017
1033
|
if (options == null) {
|
|
@@ -1019,8 +1035,8 @@ async function getContentScriptEntrypoint(config, name, path5) {
|
|
|
1019
1035
|
}
|
|
1020
1036
|
return {
|
|
1021
1037
|
type: "content-script",
|
|
1022
|
-
name: getEntrypointName(config.entrypointsDir,
|
|
1023
|
-
inputPath:
|
|
1038
|
+
name: getEntrypointName(config.entrypointsDir, path7),
|
|
1039
|
+
inputPath: path7,
|
|
1024
1040
|
outputDir: resolve9(config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
1025
1041
|
options
|
|
1026
1042
|
};
|
|
@@ -1071,11 +1087,52 @@ var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|
|
|
1071
1087
|
import { createUnimport as createUnimport3 } from "unimport";
|
|
1072
1088
|
import fs9 from "fs-extra";
|
|
1073
1089
|
import { relative as relative4, resolve as resolve10 } from "path";
|
|
1090
|
+
import path4 from "node:path";
|
|
1091
|
+
|
|
1092
|
+
// src/core/utils/i18n.ts
|
|
1093
|
+
var predefinedMessages = {
|
|
1094
|
+
"@@extension_id": {
|
|
1095
|
+
message: "<browser.runtime.id>",
|
|
1096
|
+
description: "The extension or app ID; you might use this string to construct URLs for resources inside the extension. Even unlocalized extensions can use this message.\nNote: You can't use this message in a manifest file."
|
|
1097
|
+
},
|
|
1098
|
+
"@@ui_locale": {
|
|
1099
|
+
message: "<browser.i18n.getUiLocale()>",
|
|
1100
|
+
description: ""
|
|
1101
|
+
},
|
|
1102
|
+
"@@bidi_dir": {
|
|
1103
|
+
message: "<ltr|rtl>",
|
|
1104
|
+
description: 'The text direction for the current locale, either "ltr" for left-to-right languages such as English or "rtl" for right-to-left languages such as Japanese.'
|
|
1105
|
+
},
|
|
1106
|
+
"@@bidi_reversed_dir": {
|
|
1107
|
+
message: "<rtl|ltr>",
|
|
1108
|
+
description: `If the @@bidi_dir is "ltr", then this is "rtl"; otherwise, it's "ltr".`
|
|
1109
|
+
},
|
|
1110
|
+
"@@bidi_start_edge": {
|
|
1111
|
+
message: "<left|right>",
|
|
1112
|
+
description: `If the @@bidi_dir is "ltr", then this is "left"; otherwise, it's "right".`
|
|
1113
|
+
},
|
|
1114
|
+
"@@bidi_end_edge": {
|
|
1115
|
+
message: "<right|left>",
|
|
1116
|
+
description: `If the @@bidi_dir is "ltr", then this is "right"; otherwise, it's "left".`
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
function parseI18nMessages(messagesJson) {
|
|
1120
|
+
return Object.entries({
|
|
1121
|
+
...predefinedMessages,
|
|
1122
|
+
...messagesJson
|
|
1123
|
+
}).map(([name, details]) => ({
|
|
1124
|
+
name,
|
|
1125
|
+
...details
|
|
1126
|
+
}));
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// src/core/build/generateTypesDir.ts
|
|
1074
1130
|
async function generateTypesDir(entrypoints, config) {
|
|
1075
1131
|
await fs9.ensureDir(config.typesDir);
|
|
1076
1132
|
const references = [];
|
|
1077
1133
|
references.push(await writeImportsDeclarationFile(config));
|
|
1078
1134
|
references.push(await writePathsDeclarationFile(entrypoints, config));
|
|
1135
|
+
references.push(await writeI18nDeclarationFile(config));
|
|
1079
1136
|
references.push(await writeGlobalsDeclarationFile(config));
|
|
1080
1137
|
const mainReference = await writeMainDeclarationFile(references, config);
|
|
1081
1138
|
await writeTsConfigFile(mainReference, config);
|
|
@@ -1100,14 +1157,14 @@ async function writePathsDeclarationFile(entrypoints, config) {
|
|
|
1100
1157
|
config.outDir,
|
|
1101
1158
|
entry.inputPath.endsWith(".html") ? ".html" : ".js"
|
|
1102
1159
|
)
|
|
1103
|
-
).concat(await getPublicFiles(config)).map(normalizePath2).map((
|
|
1160
|
+
).concat(await getPublicFiles(config)).map(normalizePath2).map((path7) => ` | "/${path7}"`).sort().join("\n");
|
|
1104
1161
|
const template = `// Generated by wxt
|
|
1105
1162
|
import "wxt/browser";
|
|
1106
1163
|
|
|
1107
1164
|
declare module "wxt/browser" {
|
|
1108
1165
|
type PublicPath =
|
|
1109
1166
|
{{ union }}
|
|
1110
|
-
export interface
|
|
1167
|
+
export interface WxtRuntime extends Runtime.Static {
|
|
1111
1168
|
getURL(path: PublicPath): string;
|
|
1112
1169
|
}
|
|
1113
1170
|
}
|
|
@@ -1118,6 +1175,59 @@ declare module "wxt/browser" {
|
|
|
1118
1175
|
);
|
|
1119
1176
|
return filePath;
|
|
1120
1177
|
}
|
|
1178
|
+
async function writeI18nDeclarationFile(config) {
|
|
1179
|
+
const filePath = resolve10(config.typesDir, "i18n.d.ts");
|
|
1180
|
+
const defaultLocale = config.manifest.default_locale;
|
|
1181
|
+
const template = `// Generated by wxt
|
|
1182
|
+
import "wxt/browser";
|
|
1183
|
+
|
|
1184
|
+
declare module "wxt/browser" {
|
|
1185
|
+
/**
|
|
1186
|
+
* See https://developer.chrome.com/docs/extensions/reference/i18n/#method-getMessage
|
|
1187
|
+
*/
|
|
1188
|
+
interface GetMessageOptions {
|
|
1189
|
+
/**
|
|
1190
|
+
* See https://developer.chrome.com/docs/extensions/reference/i18n/#method-getMessage
|
|
1191
|
+
*/
|
|
1192
|
+
escapeLt?: boolean
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
export interface WxtI18n extends I18n.Static {
|
|
1196
|
+
{{ overrides }}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
`;
|
|
1200
|
+
let messages;
|
|
1201
|
+
if (defaultLocale) {
|
|
1202
|
+
const defaultLocalePath = path4.resolve(
|
|
1203
|
+
config.publicDir,
|
|
1204
|
+
"_locales",
|
|
1205
|
+
defaultLocale,
|
|
1206
|
+
"messages.json"
|
|
1207
|
+
);
|
|
1208
|
+
const content = JSON.parse(await fs9.readFile(defaultLocalePath, "utf-8"));
|
|
1209
|
+
messages = parseI18nMessages(content);
|
|
1210
|
+
} else {
|
|
1211
|
+
messages = parseI18nMessages({});
|
|
1212
|
+
}
|
|
1213
|
+
const overrides = messages.map((message) => {
|
|
1214
|
+
return ` /**
|
|
1215
|
+
* ${message.description ?? "No message description."}
|
|
1216
|
+
*
|
|
1217
|
+
* "${message.message}"
|
|
1218
|
+
*/
|
|
1219
|
+
getMessage(
|
|
1220
|
+
messageName: "${message.name}",
|
|
1221
|
+
substitutions?: string | string[],
|
|
1222
|
+
options?: GetMessageOptions,
|
|
1223
|
+
): string;`;
|
|
1224
|
+
});
|
|
1225
|
+
await fs9.writeFile(
|
|
1226
|
+
filePath,
|
|
1227
|
+
template.replace("{{ overrides }}", overrides.join("\n"))
|
|
1228
|
+
);
|
|
1229
|
+
return filePath;
|
|
1230
|
+
}
|
|
1121
1231
|
async function writeGlobalsDeclarationFile(config) {
|
|
1122
1232
|
const filePath = resolve10(config.typesDir, "globals.d.ts");
|
|
1123
1233
|
const globals = getGlobals(config);
|
|
@@ -1151,6 +1261,8 @@ async function writeMainDeclarationFile(references, config) {
|
|
|
1151
1261
|
}
|
|
1152
1262
|
async function writeTsConfigFile(mainReference, config) {
|
|
1153
1263
|
const dir = config.wxtDir;
|
|
1264
|
+
const rootPath = normalizePath2(relative4(dir, config.root));
|
|
1265
|
+
const srcPath = normalizePath2(relative4(dir, config.srcDir));
|
|
1154
1266
|
await fs9.writeFile(
|
|
1155
1267
|
resolve10(dir, "tsconfig.json"),
|
|
1156
1268
|
`{
|
|
@@ -1165,16 +1277,15 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1165
1277
|
"strict": true,
|
|
1166
1278
|
"lib": ["DOM", "WebWorker"],
|
|
1167
1279
|
"skipLibCheck": true,
|
|
1168
|
-
"baseUrl": "${normalizePath2(relative4(dir, config.root))}",
|
|
1169
1280
|
"paths": {
|
|
1170
|
-
"@@": ["
|
|
1171
|
-
"@@/*": ["
|
|
1172
|
-
"~~": ["
|
|
1173
|
-
"~~/*": ["
|
|
1174
|
-
"@": ["${
|
|
1175
|
-
"@/*": ["${
|
|
1176
|
-
"~": ["${
|
|
1177
|
-
"~/*": ["${
|
|
1281
|
+
"@@": ["${rootPath}"],
|
|
1282
|
+
"@@/*": ["${rootPath}/*"],
|
|
1283
|
+
"~~": ["${rootPath}"],
|
|
1284
|
+
"~~/*": ["${rootPath}/*"],
|
|
1285
|
+
"@": ["${srcPath}"],
|
|
1286
|
+
"@/*": ["${srcPath}/*"],
|
|
1287
|
+
"~": ["${srcPath}"],
|
|
1288
|
+
"~/*": ["${srcPath}/*"]
|
|
1178
1289
|
}
|
|
1179
1290
|
},
|
|
1180
1291
|
"include": [
|
|
@@ -1500,7 +1611,7 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
1500
1611
|
map.set(hash, [script]);
|
|
1501
1612
|
return map;
|
|
1502
1613
|
}, /* @__PURE__ */ new Map());
|
|
1503
|
-
|
|
1614
|
+
const newContentScripts = Array.from(hashToEntrypointsMap.entries()).map(
|
|
1504
1615
|
([, scripts]) => ({
|
|
1505
1616
|
...mapWxtOptionsToContentScript(scripts[0].options),
|
|
1506
1617
|
// TOOD: Sorting css and js arrays here so we get consistent test results... but we
|
|
@@ -1511,6 +1622,10 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
1511
1622
|
).sort()
|
|
1512
1623
|
})
|
|
1513
1624
|
);
|
|
1625
|
+
if (newContentScripts.length >= 0) {
|
|
1626
|
+
manifest.content_scripts ??= [];
|
|
1627
|
+
manifest.content_scripts.push(...newContentScripts);
|
|
1628
|
+
}
|
|
1514
1629
|
}
|
|
1515
1630
|
}
|
|
1516
1631
|
}
|
|
@@ -1659,7 +1774,7 @@ function formatDuration(duration) {
|
|
|
1659
1774
|
import { resolve as resolve13 } from "path";
|
|
1660
1775
|
|
|
1661
1776
|
// src/core/log/printFileList.ts
|
|
1662
|
-
import
|
|
1777
|
+
import path5 from "node:path";
|
|
1663
1778
|
import pc from "picocolors";
|
|
1664
1779
|
import fs12 from "fs-extra";
|
|
1665
1780
|
import { filesize } from "filesize";
|
|
@@ -1697,8 +1812,8 @@ async function printFileList(log, header, baseDir, files) {
|
|
|
1697
1812
|
const fileRows = await Promise.all(
|
|
1698
1813
|
files.map(async (file, i) => {
|
|
1699
1814
|
const parts = [
|
|
1700
|
-
|
|
1701
|
-
|
|
1815
|
+
path5.relative(process.cwd(), baseDir) + path5.sep,
|
|
1816
|
+
path5.relative(baseDir, file)
|
|
1702
1817
|
];
|
|
1703
1818
|
const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1704
1819
|
const color = getChunkColor(file);
|
|
@@ -1829,7 +1944,7 @@ function createWebExtRunner() {
|
|
|
1829
1944
|
config.logger.warn("Cannot open safari automatically.");
|
|
1830
1945
|
return;
|
|
1831
1946
|
}
|
|
1832
|
-
const webExtLogger = await import("web-ext/util/logger");
|
|
1947
|
+
const webExtLogger = await import("web-ext-run/util/logger");
|
|
1833
1948
|
webExtLogger.consoleStream.write = ({ level, msg, name }) => {
|
|
1834
1949
|
if (level >= ERROR_LOG_LEVEL)
|
|
1835
1950
|
config.logger.error(name, msg);
|
|
@@ -1866,7 +1981,7 @@ function createWebExtRunner() {
|
|
|
1866
1981
|
};
|
|
1867
1982
|
config.logger.debug("web-ext config:", finalConfig);
|
|
1868
1983
|
config.logger.debug("web-ext options:", options);
|
|
1869
|
-
const webExt = await import("web-ext");
|
|
1984
|
+
const webExt = await import("web-ext-run");
|
|
1870
1985
|
runner = await webExt.default.cmd.run(finalConfig, options);
|
|
1871
1986
|
},
|
|
1872
1987
|
async closeBrowser() {
|
|
@@ -1911,8 +2026,8 @@ async function setupServer(serverInfo, config) {
|
|
|
1911
2026
|
const reloadExtension = () => {
|
|
1912
2027
|
viteServer.ws.send("wxt:reload-extension");
|
|
1913
2028
|
};
|
|
1914
|
-
const reloadPage = (
|
|
1915
|
-
viteServer.ws.send("wxt:reload-page",
|
|
2029
|
+
const reloadPage = (path7) => {
|
|
2030
|
+
viteServer.ws.send("wxt:reload-page", path7);
|
|
1916
2031
|
};
|
|
1917
2032
|
const reloadContentScript = (contentScript) => {
|
|
1918
2033
|
viteServer.ws.send("wxt:reload-content-script", contentScript);
|
|
@@ -1958,13 +2073,48 @@ function reloadContentScripts(steps, config, server) {
|
|
|
1958
2073
|
}
|
|
1959
2074
|
function reloadHtmlPages(groups, server, config) {
|
|
1960
2075
|
groups.flat().forEach((entry) => {
|
|
1961
|
-
const
|
|
1962
|
-
server.reloadPage(
|
|
2076
|
+
const path7 = getEntrypointBundlePath(entry, config.outDir, ".html");
|
|
2077
|
+
server.reloadPage(path7);
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
// src/core/clean.ts
|
|
2082
|
+
import path6 from "node:path";
|
|
2083
|
+
import glob3 from "fast-glob";
|
|
2084
|
+
import fs14 from "fs-extra";
|
|
2085
|
+
import { consola as consola2 } from "consola";
|
|
2086
|
+
import pc3 from "picocolors";
|
|
2087
|
+
async function clean(root = process.cwd()) {
|
|
2088
|
+
consola2.info("Cleaning Project");
|
|
2089
|
+
const tempDirs = [
|
|
2090
|
+
"node_modules/.vite",
|
|
2091
|
+
"node_modules/.cache",
|
|
2092
|
+
"**/.wxt",
|
|
2093
|
+
".output/*"
|
|
2094
|
+
];
|
|
2095
|
+
consola2.debug("Looking for:", tempDirs.map(pc3.cyan).join(", "));
|
|
2096
|
+
const directories = await glob3(tempDirs, {
|
|
2097
|
+
cwd: path6.resolve(root),
|
|
2098
|
+
absolute: true,
|
|
2099
|
+
onlyDirectories: true,
|
|
2100
|
+
deep: 2
|
|
1963
2101
|
});
|
|
2102
|
+
if (directories.length === 0) {
|
|
2103
|
+
consola2.debug("No generated files found.");
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
consola2.debug(
|
|
2107
|
+
"Found:",
|
|
2108
|
+
directories.map((dir) => pc3.cyan(path6.relative(root, dir))).join(", ")
|
|
2109
|
+
);
|
|
2110
|
+
for (const directory of directories) {
|
|
2111
|
+
await fs14.rm(directory, { force: true, recursive: true });
|
|
2112
|
+
consola2.debug("Deleted " + pc3.cyan(path6.relative(root, directory)));
|
|
2113
|
+
}
|
|
1964
2114
|
}
|
|
1965
2115
|
|
|
1966
2116
|
// package.json
|
|
1967
|
-
var version2 = "0.
|
|
2117
|
+
var version2 = "0.4.1";
|
|
1968
2118
|
|
|
1969
2119
|
// src/core/utils/defineConfig.ts
|
|
1970
2120
|
function defineConfig(config) {
|
|
@@ -1998,10 +2148,10 @@ async function createServer2(config) {
|
|
|
1998
2148
|
server.ws.on("wxt:background-initialized", () => {
|
|
1999
2149
|
reloadContentScripts(server.currentOutput.steps, internalConfig, server);
|
|
2000
2150
|
});
|
|
2001
|
-
server.watcher.on("all", async (event,
|
|
2002
|
-
if (
|
|
2151
|
+
server.watcher.on("all", async (event, path7, _stats) => {
|
|
2152
|
+
if (path7.startsWith(internalConfig.outBaseDir))
|
|
2003
2153
|
return;
|
|
2004
|
-
changeQueue.push([event,
|
|
2154
|
+
changeQueue.push([event, path7]);
|
|
2005
2155
|
await fileChangedMutex.runExclusive(async () => {
|
|
2006
2156
|
const fileChanges = changeQueue.splice(0, changeQueue.length);
|
|
2007
2157
|
if (fileChanges.length === 0)
|
|
@@ -2010,13 +2160,13 @@ async function createServer2(config) {
|
|
|
2010
2160
|
if (changes.type === "no-change")
|
|
2011
2161
|
return;
|
|
2012
2162
|
internalConfig.logger.info(
|
|
2013
|
-
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) =>
|
|
2163
|
+
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => pc4.dim(relative5(internalConfig.root, file))).join(", ")}`
|
|
2014
2164
|
);
|
|
2015
2165
|
const rebuiltNames = changes.rebuildGroups.flat().map((entry) => {
|
|
2016
|
-
return
|
|
2166
|
+
return pc4.cyan(
|
|
2017
2167
|
relative5(internalConfig.outDir, getEntrypointOutputFile(entry, ""))
|
|
2018
2168
|
);
|
|
2019
|
-
}).join(
|
|
2169
|
+
}).join(pc4.dim(", "));
|
|
2020
2170
|
internalConfig = await getLatestInternalConfig();
|
|
2021
2171
|
internalConfig.server = server;
|
|
2022
2172
|
const { output: newOutput } = await rebuild(
|
|
@@ -2037,13 +2187,14 @@ async function createServer2(config) {
|
|
|
2037
2187
|
reloadContentScripts(changes.changedSteps, internalConfig, server);
|
|
2038
2188
|
break;
|
|
2039
2189
|
}
|
|
2040
|
-
|
|
2190
|
+
consola3.success(`Reloaded: ${rebuiltNames}`);
|
|
2041
2191
|
});
|
|
2042
2192
|
});
|
|
2043
2193
|
return server;
|
|
2044
2194
|
}
|
|
2045
2195
|
export {
|
|
2046
2196
|
build2 as build,
|
|
2197
|
+
clean,
|
|
2047
2198
|
createServer2 as createServer,
|
|
2048
2199
|
defineConfig,
|
|
2049
2200
|
defineRunnerConfig,
|