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.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
build: () => build2,
|
|
34
|
+
clean: () => clean,
|
|
34
35
|
createServer: () => createServer2,
|
|
35
36
|
defineConfig: () => defineConfig,
|
|
36
37
|
defineRunnerConfig: () => defineRunnerConfig,
|
|
@@ -49,11 +50,11 @@ var import_node_path2 = __toESM(require("path"), 1);
|
|
|
49
50
|
// src/core/utils/paths.ts
|
|
50
51
|
var import_node_path = __toESM(require("path"), 1);
|
|
51
52
|
var vite = __toESM(require("vite"), 1);
|
|
52
|
-
function normalizePath2(
|
|
53
|
-
return vite.normalizePath(
|
|
53
|
+
function normalizePath2(path7) {
|
|
54
|
+
return vite.normalizePath(path7);
|
|
54
55
|
}
|
|
55
|
-
function unnormalizePath(
|
|
56
|
-
return import_node_path.default.normalize(
|
|
56
|
+
function unnormalizePath(path7) {
|
|
57
|
+
return import_node_path.default.normalize(path7);
|
|
57
58
|
}
|
|
58
59
|
var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
|
|
59
60
|
var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
|
|
@@ -235,7 +236,9 @@ function multipageMove(entrypoints, config) {
|
|
|
235
236
|
(entry) => !!normalizePath2(entry.inputPath).endsWith(oldBundlePath)
|
|
236
237
|
);
|
|
237
238
|
if (entrypoint == null) {
|
|
238
|
-
config.logger.debug(
|
|
239
|
+
config.logger.debug(
|
|
240
|
+
`No entrypoint found for ${oldBundlePath}, leaving in chunks directory`
|
|
241
|
+
);
|
|
239
242
|
continue;
|
|
240
243
|
}
|
|
241
244
|
const newBundlePath = getEntrypointBundlePath(
|
|
@@ -342,12 +345,22 @@ function virtualEntrypoin(type, config) {
|
|
|
342
345
|
}
|
|
343
346
|
|
|
344
347
|
// src/core/vite-plugins/tsconfigPaths.ts
|
|
345
|
-
var import_vite_tsconfig_paths = __toESM(require("vite-tsconfig-paths"), 1);
|
|
346
348
|
function tsconfigPaths(config) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
349
|
+
return {
|
|
350
|
+
name: "wxt:aliases",
|
|
351
|
+
async config() {
|
|
352
|
+
return {
|
|
353
|
+
resolve: {
|
|
354
|
+
alias: {
|
|
355
|
+
"@@": config.root,
|
|
356
|
+
"~~": config.root,
|
|
357
|
+
"@": config.srcDir,
|
|
358
|
+
"~": config.srcDir
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
};
|
|
351
364
|
}
|
|
352
365
|
|
|
353
366
|
// src/core/vite-plugins/noopBackground.ts
|
|
@@ -401,14 +414,14 @@ function createFsCache(wxtDir) {
|
|
|
401
414
|
const getPath = (key) => (0, import_path4.resolve)(wxtDir, "cache", encodeURIComponent(key));
|
|
402
415
|
return {
|
|
403
416
|
async set(key, value) {
|
|
404
|
-
const
|
|
405
|
-
await (0, import_fs_extra3.ensureDir)((0, import_path4.dirname)(
|
|
406
|
-
await import_fs_extra3.default.writeFile(
|
|
417
|
+
const path7 = getPath(key);
|
|
418
|
+
await (0, import_fs_extra3.ensureDir)((0, import_path4.dirname)(path7));
|
|
419
|
+
await import_fs_extra3.default.writeFile(path7, value, "utf-8");
|
|
407
420
|
},
|
|
408
421
|
async get(key) {
|
|
409
|
-
const
|
|
422
|
+
const path7 = getPath(key);
|
|
410
423
|
try {
|
|
411
|
-
return await import_fs_extra3.default.readFile(
|
|
424
|
+
return await import_fs_extra3.default.readFile(path7, "utf-8");
|
|
412
425
|
} catch {
|
|
413
426
|
return void 0;
|
|
414
427
|
}
|
|
@@ -472,6 +485,9 @@ async function getInternalConfig(config, command) {
|
|
|
472
485
|
const outBaseDir = import_node_path4.default.resolve(root, ".output");
|
|
473
486
|
const outDir = import_node_path4.default.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
|
|
474
487
|
const logger = config.logger ?? import_consola.consola;
|
|
488
|
+
const debug = !!config.debug;
|
|
489
|
+
if (debug)
|
|
490
|
+
logger.level = import_consola.LogLevels.debug;
|
|
475
491
|
const baseConfig = {
|
|
476
492
|
root,
|
|
477
493
|
outDir,
|
|
@@ -481,6 +497,7 @@ async function getInternalConfig(config, command) {
|
|
|
481
497
|
manifestVersion,
|
|
482
498
|
mode,
|
|
483
499
|
command,
|
|
500
|
+
debug,
|
|
484
501
|
logger,
|
|
485
502
|
vite: config.vite ?? {},
|
|
486
503
|
imports: config.imports ?? {},
|
|
@@ -513,7 +530,7 @@ async function getInternalConfig(config, command) {
|
|
|
513
530
|
userConfig.entrypointsDir ?? "entrypoints"
|
|
514
531
|
);
|
|
515
532
|
const publicDir = (0, import_node_path4.resolve)(root, userConfig.publicDir ?? "public");
|
|
516
|
-
const wxtDir = (0, import_node_path4.resolve)(
|
|
533
|
+
const wxtDir = (0, import_node_path4.resolve)(root, ".wxt");
|
|
517
534
|
const typesDir = (0, import_node_path4.resolve)(wxtDir, "types");
|
|
518
535
|
const env = { mode, browser, manifestVersion, command };
|
|
519
536
|
const userManifest = await resolveManifestConfig(env, userConfig.manifest);
|
|
@@ -579,7 +596,7 @@ async function resolveManifestConfig(env, manifest) {
|
|
|
579
596
|
}
|
|
580
597
|
|
|
581
598
|
// src/index.ts
|
|
582
|
-
var
|
|
599
|
+
var import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
583
600
|
var vite6 = __toESM(require("vite"), 1);
|
|
584
601
|
|
|
585
602
|
// src/core/utils/arrays.ts
|
|
@@ -676,8 +693,8 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
676
693
|
|
|
677
694
|
// src/index.ts
|
|
678
695
|
var import_async_mutex = require("async-mutex");
|
|
679
|
-
var
|
|
680
|
-
var
|
|
696
|
+
var import_consola3 = require("consola");
|
|
697
|
+
var import_node_path9 = require("path");
|
|
681
698
|
|
|
682
699
|
// src/core/build/buildEntrypoints.ts
|
|
683
700
|
var vite3 = __toESM(require("vite"), 1);
|
|
@@ -849,16 +866,16 @@ function removeImportStatements(text) {
|
|
|
849
866
|
}
|
|
850
867
|
|
|
851
868
|
// src/core/utils/importTsFile.ts
|
|
852
|
-
async function importTsFile(
|
|
853
|
-
config.logger.debug("Loading file metadata:",
|
|
854
|
-
const normalPath = normalizePath2(
|
|
869
|
+
async function importTsFile(path7, config) {
|
|
870
|
+
config.logger.debug("Loading file metadata:", path7);
|
|
871
|
+
const normalPath = normalizePath2(path7);
|
|
855
872
|
const unimport2 = (0, import_unimport2.createUnimport)({
|
|
856
873
|
...getUnimportOptions(config),
|
|
857
874
|
// Only allow specific imports, not all from the project
|
|
858
875
|
dirs: []
|
|
859
876
|
});
|
|
860
877
|
await unimport2.init();
|
|
861
|
-
const text = await import_fs_extra7.default.readFile(
|
|
878
|
+
const text = await import_fs_extra7.default.readFile(path7, "utf-8");
|
|
862
879
|
const textNoImports = removeImportStatements(text);
|
|
863
880
|
const { code } = await unimport2.injectImports(textNoImports);
|
|
864
881
|
config.logger.debug(
|
|
@@ -882,7 +899,7 @@ async function importTsFile(path5, config) {
|
|
|
882
899
|
}
|
|
883
900
|
});
|
|
884
901
|
try {
|
|
885
|
-
return await jiti(
|
|
902
|
+
return await jiti(path7);
|
|
886
903
|
} catch (err) {
|
|
887
904
|
config.logger.error(err);
|
|
888
905
|
throw err;
|
|
@@ -902,9 +919,9 @@ async function findEntrypoints(config) {
|
|
|
902
919
|
let hasBackground = false;
|
|
903
920
|
await Promise.all(
|
|
904
921
|
relativePaths.map(async (relativePath) => {
|
|
905
|
-
const
|
|
922
|
+
const path7 = (0, import_path8.resolve)(config.entrypointsDir, relativePath);
|
|
906
923
|
const matchingGlob = pathGlobs.find(
|
|
907
|
-
(
|
|
924
|
+
(glob4) => (0, import_minimatch.minimatch)(relativePath, glob4)
|
|
908
925
|
);
|
|
909
926
|
if (matchingGlob == null) {
|
|
910
927
|
return config.logger.warn(
|
|
@@ -922,35 +939,35 @@ ${JSON.stringify(
|
|
|
922
939
|
let entrypoint;
|
|
923
940
|
switch (type) {
|
|
924
941
|
case "popup":
|
|
925
|
-
entrypoint = await getPopupEntrypoint(config,
|
|
942
|
+
entrypoint = await getPopupEntrypoint(config, path7);
|
|
926
943
|
break;
|
|
927
944
|
case "options":
|
|
928
|
-
entrypoint = await getOptionsEntrypoint(config,
|
|
945
|
+
entrypoint = await getOptionsEntrypoint(config, path7);
|
|
929
946
|
break;
|
|
930
947
|
case "background":
|
|
931
|
-
entrypoint = await getBackgroundEntrypoint(config,
|
|
948
|
+
entrypoint = await getBackgroundEntrypoint(config, path7);
|
|
932
949
|
hasBackground = true;
|
|
933
950
|
break;
|
|
934
951
|
case "content-script":
|
|
935
952
|
entrypoint = await getContentScriptEntrypoint(
|
|
936
953
|
config,
|
|
937
|
-
getEntrypointName(config.entrypointsDir,
|
|
938
|
-
|
|
954
|
+
getEntrypointName(config.entrypointsDir, path7),
|
|
955
|
+
path7
|
|
939
956
|
);
|
|
940
957
|
break;
|
|
941
958
|
case "content-script-style":
|
|
942
959
|
entrypoint = {
|
|
943
960
|
type,
|
|
944
|
-
name: getEntrypointName(config.entrypointsDir,
|
|
945
|
-
inputPath:
|
|
961
|
+
name: getEntrypointName(config.entrypointsDir, path7),
|
|
962
|
+
inputPath: path7,
|
|
946
963
|
outputDir: (0, import_path8.resolve)(config.outDir, CONTENT_SCRIPT_OUT_DIR)
|
|
947
964
|
};
|
|
948
965
|
break;
|
|
949
966
|
default:
|
|
950
967
|
entrypoint = {
|
|
951
968
|
type,
|
|
952
|
-
name: getEntrypointName(config.entrypointsDir,
|
|
953
|
-
inputPath:
|
|
969
|
+
name: getEntrypointName(config.entrypointsDir, path7),
|
|
970
|
+
inputPath: path7,
|
|
954
971
|
outputDir: config.outDir
|
|
955
972
|
};
|
|
956
973
|
}
|
|
@@ -974,9 +991,9 @@ ${JSON.stringify(
|
|
|
974
991
|
}
|
|
975
992
|
return entrypoints;
|
|
976
993
|
}
|
|
977
|
-
async function getPopupEntrypoint(config,
|
|
994
|
+
async function getPopupEntrypoint(config, path7) {
|
|
978
995
|
const options = {};
|
|
979
|
-
const content = await import_fs_extra8.default.readFile(
|
|
996
|
+
const content = await import_fs_extra8.default.readFile(path7, "utf-8");
|
|
980
997
|
const { document } = (0, import_linkedom2.parseHTML)(content);
|
|
981
998
|
const title = document.querySelector("title");
|
|
982
999
|
if (title != null)
|
|
@@ -1000,13 +1017,13 @@ async function getPopupEntrypoint(config, path5) {
|
|
|
1000
1017
|
type: "popup",
|
|
1001
1018
|
name: "popup",
|
|
1002
1019
|
options,
|
|
1003
|
-
inputPath:
|
|
1020
|
+
inputPath: path7,
|
|
1004
1021
|
outputDir: config.outDir
|
|
1005
1022
|
};
|
|
1006
1023
|
}
|
|
1007
|
-
async function getOptionsEntrypoint(config,
|
|
1024
|
+
async function getOptionsEntrypoint(config, path7) {
|
|
1008
1025
|
const options = {};
|
|
1009
|
-
const content = await import_fs_extra8.default.readFile(
|
|
1026
|
+
const content = await import_fs_extra8.default.readFile(path7, "utf-8");
|
|
1010
1027
|
const { document } = (0, import_linkedom2.parseHTML)(content);
|
|
1011
1028
|
const openInTabContent = document.querySelector("meta[name='manifest.open_in_tab']")?.getAttribute("content");
|
|
1012
1029
|
if (openInTabContent) {
|
|
@@ -1024,15 +1041,15 @@ async function getOptionsEntrypoint(config, path5) {
|
|
|
1024
1041
|
type: "options",
|
|
1025
1042
|
name: "options",
|
|
1026
1043
|
options,
|
|
1027
|
-
inputPath:
|
|
1044
|
+
inputPath: path7,
|
|
1028
1045
|
outputDir: config.outDir
|
|
1029
1046
|
};
|
|
1030
1047
|
}
|
|
1031
|
-
async function getBackgroundEntrypoint(config,
|
|
1048
|
+
async function getBackgroundEntrypoint(config, path7) {
|
|
1032
1049
|
let options = {};
|
|
1033
|
-
if (
|
|
1050
|
+
if (path7 !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
|
|
1034
1051
|
const defaultExport = await importTsFile(
|
|
1035
|
-
|
|
1052
|
+
path7,
|
|
1036
1053
|
config
|
|
1037
1054
|
);
|
|
1038
1055
|
if (defaultExport == null) {
|
|
@@ -1044,14 +1061,14 @@ async function getBackgroundEntrypoint(config, path5) {
|
|
|
1044
1061
|
return {
|
|
1045
1062
|
type: "background",
|
|
1046
1063
|
name: "background",
|
|
1047
|
-
inputPath:
|
|
1064
|
+
inputPath: path7,
|
|
1048
1065
|
outputDir: config.outDir,
|
|
1049
1066
|
options
|
|
1050
1067
|
};
|
|
1051
1068
|
}
|
|
1052
|
-
async function getContentScriptEntrypoint(config, name,
|
|
1069
|
+
async function getContentScriptEntrypoint(config, name, path7) {
|
|
1053
1070
|
const { main: _, ...options } = await importTsFile(
|
|
1054
|
-
|
|
1071
|
+
path7,
|
|
1055
1072
|
config
|
|
1056
1073
|
);
|
|
1057
1074
|
if (options == null) {
|
|
@@ -1059,8 +1076,8 @@ async function getContentScriptEntrypoint(config, name, path5) {
|
|
|
1059
1076
|
}
|
|
1060
1077
|
return {
|
|
1061
1078
|
type: "content-script",
|
|
1062
|
-
name: getEntrypointName(config.entrypointsDir,
|
|
1063
|
-
inputPath:
|
|
1079
|
+
name: getEntrypointName(config.entrypointsDir, path7),
|
|
1080
|
+
inputPath: path7,
|
|
1064
1081
|
outputDir: (0, import_path8.resolve)(config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
1065
1082
|
options
|
|
1066
1083
|
};
|
|
@@ -1111,11 +1128,52 @@ var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|
|
|
1111
1128
|
var import_unimport3 = require("unimport");
|
|
1112
1129
|
var import_fs_extra9 = __toESM(require("fs-extra"), 1);
|
|
1113
1130
|
var import_path9 = require("path");
|
|
1131
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
1132
|
+
|
|
1133
|
+
// src/core/utils/i18n.ts
|
|
1134
|
+
var predefinedMessages = {
|
|
1135
|
+
"@@extension_id": {
|
|
1136
|
+
message: "<browser.runtime.id>",
|
|
1137
|
+
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."
|
|
1138
|
+
},
|
|
1139
|
+
"@@ui_locale": {
|
|
1140
|
+
message: "<browser.i18n.getUiLocale()>",
|
|
1141
|
+
description: ""
|
|
1142
|
+
},
|
|
1143
|
+
"@@bidi_dir": {
|
|
1144
|
+
message: "<ltr|rtl>",
|
|
1145
|
+
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.'
|
|
1146
|
+
},
|
|
1147
|
+
"@@bidi_reversed_dir": {
|
|
1148
|
+
message: "<rtl|ltr>",
|
|
1149
|
+
description: `If the @@bidi_dir is "ltr", then this is "rtl"; otherwise, it's "ltr".`
|
|
1150
|
+
},
|
|
1151
|
+
"@@bidi_start_edge": {
|
|
1152
|
+
message: "<left|right>",
|
|
1153
|
+
description: `If the @@bidi_dir is "ltr", then this is "left"; otherwise, it's "right".`
|
|
1154
|
+
},
|
|
1155
|
+
"@@bidi_end_edge": {
|
|
1156
|
+
message: "<right|left>",
|
|
1157
|
+
description: `If the @@bidi_dir is "ltr", then this is "right"; otherwise, it's "left".`
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
function parseI18nMessages(messagesJson) {
|
|
1161
|
+
return Object.entries({
|
|
1162
|
+
...predefinedMessages,
|
|
1163
|
+
...messagesJson
|
|
1164
|
+
}).map(([name, details]) => ({
|
|
1165
|
+
name,
|
|
1166
|
+
...details
|
|
1167
|
+
}));
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
// src/core/build/generateTypesDir.ts
|
|
1114
1171
|
async function generateTypesDir(entrypoints, config) {
|
|
1115
1172
|
await import_fs_extra9.default.ensureDir(config.typesDir);
|
|
1116
1173
|
const references = [];
|
|
1117
1174
|
references.push(await writeImportsDeclarationFile(config));
|
|
1118
1175
|
references.push(await writePathsDeclarationFile(entrypoints, config));
|
|
1176
|
+
references.push(await writeI18nDeclarationFile(config));
|
|
1119
1177
|
references.push(await writeGlobalsDeclarationFile(config));
|
|
1120
1178
|
const mainReference = await writeMainDeclarationFile(references, config);
|
|
1121
1179
|
await writeTsConfigFile(mainReference, config);
|
|
@@ -1140,14 +1198,14 @@ async function writePathsDeclarationFile(entrypoints, config) {
|
|
|
1140
1198
|
config.outDir,
|
|
1141
1199
|
entry.inputPath.endsWith(".html") ? ".html" : ".js"
|
|
1142
1200
|
)
|
|
1143
|
-
).concat(await getPublicFiles(config)).map(normalizePath2).map((
|
|
1201
|
+
).concat(await getPublicFiles(config)).map(normalizePath2).map((path7) => ` | "/${path7}"`).sort().join("\n");
|
|
1144
1202
|
const template = `// Generated by wxt
|
|
1145
1203
|
import "wxt/browser";
|
|
1146
1204
|
|
|
1147
1205
|
declare module "wxt/browser" {
|
|
1148
1206
|
type PublicPath =
|
|
1149
1207
|
{{ union }}
|
|
1150
|
-
export interface
|
|
1208
|
+
export interface WxtRuntime extends Runtime.Static {
|
|
1151
1209
|
getURL(path: PublicPath): string;
|
|
1152
1210
|
}
|
|
1153
1211
|
}
|
|
@@ -1158,6 +1216,59 @@ declare module "wxt/browser" {
|
|
|
1158
1216
|
);
|
|
1159
1217
|
return filePath;
|
|
1160
1218
|
}
|
|
1219
|
+
async function writeI18nDeclarationFile(config) {
|
|
1220
|
+
const filePath = (0, import_path9.resolve)(config.typesDir, "i18n.d.ts");
|
|
1221
|
+
const defaultLocale = config.manifest.default_locale;
|
|
1222
|
+
const template = `// Generated by wxt
|
|
1223
|
+
import "wxt/browser";
|
|
1224
|
+
|
|
1225
|
+
declare module "wxt/browser" {
|
|
1226
|
+
/**
|
|
1227
|
+
* See https://developer.chrome.com/docs/extensions/reference/i18n/#method-getMessage
|
|
1228
|
+
*/
|
|
1229
|
+
interface GetMessageOptions {
|
|
1230
|
+
/**
|
|
1231
|
+
* See https://developer.chrome.com/docs/extensions/reference/i18n/#method-getMessage
|
|
1232
|
+
*/
|
|
1233
|
+
escapeLt?: boolean
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
export interface WxtI18n extends I18n.Static {
|
|
1237
|
+
{{ overrides }}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
`;
|
|
1241
|
+
let messages;
|
|
1242
|
+
if (defaultLocale) {
|
|
1243
|
+
const defaultLocalePath = import_node_path5.default.resolve(
|
|
1244
|
+
config.publicDir,
|
|
1245
|
+
"_locales",
|
|
1246
|
+
defaultLocale,
|
|
1247
|
+
"messages.json"
|
|
1248
|
+
);
|
|
1249
|
+
const content = JSON.parse(await import_fs_extra9.default.readFile(defaultLocalePath, "utf-8"));
|
|
1250
|
+
messages = parseI18nMessages(content);
|
|
1251
|
+
} else {
|
|
1252
|
+
messages = parseI18nMessages({});
|
|
1253
|
+
}
|
|
1254
|
+
const overrides = messages.map((message) => {
|
|
1255
|
+
return ` /**
|
|
1256
|
+
* ${message.description ?? "No message description."}
|
|
1257
|
+
*
|
|
1258
|
+
* "${message.message}"
|
|
1259
|
+
*/
|
|
1260
|
+
getMessage(
|
|
1261
|
+
messageName: "${message.name}",
|
|
1262
|
+
substitutions?: string | string[],
|
|
1263
|
+
options?: GetMessageOptions,
|
|
1264
|
+
): string;`;
|
|
1265
|
+
});
|
|
1266
|
+
await import_fs_extra9.default.writeFile(
|
|
1267
|
+
filePath,
|
|
1268
|
+
template.replace("{{ overrides }}", overrides.join("\n"))
|
|
1269
|
+
);
|
|
1270
|
+
return filePath;
|
|
1271
|
+
}
|
|
1161
1272
|
async function writeGlobalsDeclarationFile(config) {
|
|
1162
1273
|
const filePath = (0, import_path9.resolve)(config.typesDir, "globals.d.ts");
|
|
1163
1274
|
const globals = getGlobals(config);
|
|
@@ -1191,6 +1302,8 @@ async function writeMainDeclarationFile(references, config) {
|
|
|
1191
1302
|
}
|
|
1192
1303
|
async function writeTsConfigFile(mainReference, config) {
|
|
1193
1304
|
const dir = config.wxtDir;
|
|
1305
|
+
const rootPath = normalizePath2((0, import_path9.relative)(dir, config.root));
|
|
1306
|
+
const srcPath = normalizePath2((0, import_path9.relative)(dir, config.srcDir));
|
|
1194
1307
|
await import_fs_extra9.default.writeFile(
|
|
1195
1308
|
(0, import_path9.resolve)(dir, "tsconfig.json"),
|
|
1196
1309
|
`{
|
|
@@ -1205,16 +1318,15 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1205
1318
|
"strict": true,
|
|
1206
1319
|
"lib": ["DOM", "WebWorker"],
|
|
1207
1320
|
"skipLibCheck": true,
|
|
1208
|
-
"baseUrl": "${normalizePath2((0, import_path9.relative)(dir, config.root))}",
|
|
1209
1321
|
"paths": {
|
|
1210
|
-
"@@": ["
|
|
1211
|
-
"@@/*": ["
|
|
1212
|
-
"~~": ["
|
|
1213
|
-
"~~/*": ["
|
|
1214
|
-
"@": ["${
|
|
1215
|
-
"@/*": ["${
|
|
1216
|
-
"~": ["${
|
|
1217
|
-
"~/*": ["${
|
|
1322
|
+
"@@": ["${rootPath}"],
|
|
1323
|
+
"@@/*": ["${rootPath}/*"],
|
|
1324
|
+
"~~": ["${rootPath}"],
|
|
1325
|
+
"~~/*": ["${rootPath}/*"],
|
|
1326
|
+
"@": ["${srcPath}"],
|
|
1327
|
+
"@/*": ["${srcPath}/*"],
|
|
1328
|
+
"~": ["${srcPath}"],
|
|
1329
|
+
"~/*": ["${srcPath}/*"]
|
|
1218
1330
|
}
|
|
1219
1331
|
},
|
|
1220
1332
|
"include": [
|
|
@@ -1312,10 +1424,10 @@ function mapWxtOptionsToContentScript(options) {
|
|
|
1312
1424
|
}
|
|
1313
1425
|
|
|
1314
1426
|
// src/core/utils/package.ts
|
|
1315
|
-
var
|
|
1427
|
+
var import_node_path6 = require("path");
|
|
1316
1428
|
var import_fs_extra10 = __toESM(require("fs-extra"), 1);
|
|
1317
1429
|
async function getPackageJson(config) {
|
|
1318
|
-
const file = (0,
|
|
1430
|
+
const file = (0, import_node_path6.resolve)(config.root, "package.json");
|
|
1319
1431
|
try {
|
|
1320
1432
|
return await import_fs_extra10.default.readJson(file);
|
|
1321
1433
|
} catch (err) {
|
|
@@ -1540,7 +1652,7 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
1540
1652
|
map.set(hash, [script]);
|
|
1541
1653
|
return map;
|
|
1542
1654
|
}, /* @__PURE__ */ new Map());
|
|
1543
|
-
|
|
1655
|
+
const newContentScripts = Array.from(hashToEntrypointsMap.entries()).map(
|
|
1544
1656
|
([, scripts]) => ({
|
|
1545
1657
|
...mapWxtOptionsToContentScript(scripts[0].options),
|
|
1546
1658
|
// TOOD: Sorting css and js arrays here so we get consistent test results... but we
|
|
@@ -1551,6 +1663,10 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
1551
1663
|
).sort()
|
|
1552
1664
|
})
|
|
1553
1665
|
);
|
|
1666
|
+
if (newContentScripts.length >= 0) {
|
|
1667
|
+
manifest.content_scripts ??= [];
|
|
1668
|
+
manifest.content_scripts.push(...newContentScripts);
|
|
1669
|
+
}
|
|
1554
1670
|
}
|
|
1555
1671
|
}
|
|
1556
1672
|
}
|
|
@@ -1699,7 +1815,7 @@ function formatDuration(duration) {
|
|
|
1699
1815
|
var import_path11 = require("path");
|
|
1700
1816
|
|
|
1701
1817
|
// src/core/log/printFileList.ts
|
|
1702
|
-
var
|
|
1818
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
1703
1819
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
1704
1820
|
var import_fs_extra12 = __toESM(require("fs-extra"), 1);
|
|
1705
1821
|
var import_filesize = require("filesize");
|
|
@@ -1737,8 +1853,8 @@ async function printFileList(log, header, baseDir, files) {
|
|
|
1737
1853
|
const fileRows = await Promise.all(
|
|
1738
1854
|
files.map(async (file, i) => {
|
|
1739
1855
|
const parts = [
|
|
1740
|
-
|
|
1741
|
-
|
|
1856
|
+
import_node_path7.default.relative(process.cwd(), baseDir) + import_node_path7.default.sep,
|
|
1857
|
+
import_node_path7.default.relative(baseDir, file)
|
|
1742
1858
|
];
|
|
1743
1859
|
const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1744
1860
|
const color = getChunkColor(file);
|
|
@@ -1869,7 +1985,7 @@ function createWebExtRunner() {
|
|
|
1869
1985
|
config.logger.warn("Cannot open safari automatically.");
|
|
1870
1986
|
return;
|
|
1871
1987
|
}
|
|
1872
|
-
const webExtLogger = await import("web-ext/util/logger");
|
|
1988
|
+
const webExtLogger = await import("web-ext-run/util/logger");
|
|
1873
1989
|
webExtLogger.consoleStream.write = ({ level, msg, name }) => {
|
|
1874
1990
|
if (level >= ERROR_LOG_LEVEL)
|
|
1875
1991
|
config.logger.error(name, msg);
|
|
@@ -1906,7 +2022,7 @@ function createWebExtRunner() {
|
|
|
1906
2022
|
};
|
|
1907
2023
|
config.logger.debug("web-ext config:", finalConfig);
|
|
1908
2024
|
config.logger.debug("web-ext options:", options);
|
|
1909
|
-
const webExt = await import("web-ext");
|
|
2025
|
+
const webExt = await import("web-ext-run");
|
|
1910
2026
|
runner = await webExt.default.cmd.run(finalConfig, options);
|
|
1911
2027
|
},
|
|
1912
2028
|
async closeBrowser() {
|
|
@@ -1951,8 +2067,8 @@ async function setupServer(serverInfo, config) {
|
|
|
1951
2067
|
const reloadExtension = () => {
|
|
1952
2068
|
viteServer.ws.send("wxt:reload-extension");
|
|
1953
2069
|
};
|
|
1954
|
-
const reloadPage = (
|
|
1955
|
-
viteServer.ws.send("wxt:reload-page",
|
|
2070
|
+
const reloadPage = (path7) => {
|
|
2071
|
+
viteServer.ws.send("wxt:reload-page", path7);
|
|
1956
2072
|
};
|
|
1957
2073
|
const reloadContentScript = (contentScript) => {
|
|
1958
2074
|
viteServer.ws.send("wxt:reload-content-script", contentScript);
|
|
@@ -1998,13 +2114,48 @@ function reloadContentScripts(steps, config, server) {
|
|
|
1998
2114
|
}
|
|
1999
2115
|
function reloadHtmlPages(groups, server, config) {
|
|
2000
2116
|
groups.flat().forEach((entry) => {
|
|
2001
|
-
const
|
|
2002
|
-
server.reloadPage(
|
|
2117
|
+
const path7 = getEntrypointBundlePath(entry, config.outDir, ".html");
|
|
2118
|
+
server.reloadPage(path7);
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
// src/core/clean.ts
|
|
2123
|
+
var import_node_path8 = __toESM(require("path"), 1);
|
|
2124
|
+
var import_fast_glob3 = __toESM(require("fast-glob"), 1);
|
|
2125
|
+
var import_fs_extra14 = __toESM(require("fs-extra"), 1);
|
|
2126
|
+
var import_consola2 = require("consola");
|
|
2127
|
+
var import_picocolors3 = __toESM(require("picocolors"), 1);
|
|
2128
|
+
async function clean(root = process.cwd()) {
|
|
2129
|
+
import_consola2.consola.info("Cleaning Project");
|
|
2130
|
+
const tempDirs = [
|
|
2131
|
+
"node_modules/.vite",
|
|
2132
|
+
"node_modules/.cache",
|
|
2133
|
+
"**/.wxt",
|
|
2134
|
+
".output/*"
|
|
2135
|
+
];
|
|
2136
|
+
import_consola2.consola.debug("Looking for:", tempDirs.map(import_picocolors3.default.cyan).join(", "));
|
|
2137
|
+
const directories = await (0, import_fast_glob3.default)(tempDirs, {
|
|
2138
|
+
cwd: import_node_path8.default.resolve(root),
|
|
2139
|
+
absolute: true,
|
|
2140
|
+
onlyDirectories: true,
|
|
2141
|
+
deep: 2
|
|
2003
2142
|
});
|
|
2143
|
+
if (directories.length === 0) {
|
|
2144
|
+
import_consola2.consola.debug("No generated files found.");
|
|
2145
|
+
return;
|
|
2146
|
+
}
|
|
2147
|
+
import_consola2.consola.debug(
|
|
2148
|
+
"Found:",
|
|
2149
|
+
directories.map((dir) => import_picocolors3.default.cyan(import_node_path8.default.relative(root, dir))).join(", ")
|
|
2150
|
+
);
|
|
2151
|
+
for (const directory of directories) {
|
|
2152
|
+
await import_fs_extra14.default.rm(directory, { force: true, recursive: true });
|
|
2153
|
+
import_consola2.consola.debug("Deleted " + import_picocolors3.default.cyan(import_node_path8.default.relative(root, directory)));
|
|
2154
|
+
}
|
|
2004
2155
|
}
|
|
2005
2156
|
|
|
2006
2157
|
// package.json
|
|
2007
|
-
var version2 = "0.
|
|
2158
|
+
var version2 = "0.4.1";
|
|
2008
2159
|
|
|
2009
2160
|
// src/core/utils/defineConfig.ts
|
|
2010
2161
|
function defineConfig(config) {
|
|
@@ -2038,10 +2189,10 @@ async function createServer2(config) {
|
|
|
2038
2189
|
server.ws.on("wxt:background-initialized", () => {
|
|
2039
2190
|
reloadContentScripts(server.currentOutput.steps, internalConfig, server);
|
|
2040
2191
|
});
|
|
2041
|
-
server.watcher.on("all", async (event,
|
|
2042
|
-
if (
|
|
2192
|
+
server.watcher.on("all", async (event, path7, _stats) => {
|
|
2193
|
+
if (path7.startsWith(internalConfig.outBaseDir))
|
|
2043
2194
|
return;
|
|
2044
|
-
changeQueue.push([event,
|
|
2195
|
+
changeQueue.push([event, path7]);
|
|
2045
2196
|
await fileChangedMutex.runExclusive(async () => {
|
|
2046
2197
|
const fileChanges = changeQueue.splice(0, changeQueue.length);
|
|
2047
2198
|
if (fileChanges.length === 0)
|
|
@@ -2050,13 +2201,13 @@ async function createServer2(config) {
|
|
|
2050
2201
|
if (changes.type === "no-change")
|
|
2051
2202
|
return;
|
|
2052
2203
|
internalConfig.logger.info(
|
|
2053
|
-
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) =>
|
|
2204
|
+
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => import_picocolors4.default.dim((0, import_node_path9.relative)(internalConfig.root, file))).join(", ")}`
|
|
2054
2205
|
);
|
|
2055
2206
|
const rebuiltNames = changes.rebuildGroups.flat().map((entry) => {
|
|
2056
|
-
return
|
|
2057
|
-
(0,
|
|
2207
|
+
return import_picocolors4.default.cyan(
|
|
2208
|
+
(0, import_node_path9.relative)(internalConfig.outDir, getEntrypointOutputFile(entry, ""))
|
|
2058
2209
|
);
|
|
2059
|
-
}).join(
|
|
2210
|
+
}).join(import_picocolors4.default.dim(", "));
|
|
2060
2211
|
internalConfig = await getLatestInternalConfig();
|
|
2061
2212
|
internalConfig.server = server;
|
|
2062
2213
|
const { output: newOutput } = await rebuild(
|
|
@@ -2077,7 +2228,7 @@ async function createServer2(config) {
|
|
|
2077
2228
|
reloadContentScripts(changes.changedSteps, internalConfig, server);
|
|
2078
2229
|
break;
|
|
2079
2230
|
}
|
|
2080
|
-
|
|
2231
|
+
import_consola3.consola.success(`Reloaded: ${rebuiltNames}`);
|
|
2081
2232
|
});
|
|
2082
2233
|
});
|
|
2083
2234
|
return server;
|
|
@@ -2085,6 +2236,7 @@ async function createServer2(config) {
|
|
|
2085
2236
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2086
2237
|
0 && (module.exports = {
|
|
2087
2238
|
build,
|
|
2239
|
+
clean,
|
|
2088
2240
|
createServer,
|
|
2089
2241
|
defineConfig,
|
|
2090
2242
|
defineRunnerConfig,
|