wxt 0.18.8 → 0.18.10
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/{chunk-Z3C7S5VV.js → chunk-2V7XZSZQ.js} +385 -286
- package/dist/chunk-6XSIWUWF.js +57 -0
- package/dist/cli.js +416 -305
- package/dist/{index-D6lH9OkP.d.cts → index-mz3v4Nde.d.cts} +67 -13
- package/dist/{index-D6lH9OkP.d.ts → index-mz3v4Nde.d.ts} +67 -13
- package/dist/index.cjs +502 -390
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/modules.d.cts +1 -1
- package/dist/modules.d.ts +1 -1
- package/dist/modules.js +8 -49
- package/dist/testing.cjs +207 -116
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +18 -9
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -988,12 +988,12 @@ var require_isexe = __commonJS({
|
|
|
988
988
|
if (typeof Promise !== "function") {
|
|
989
989
|
throw new TypeError("callback not provided");
|
|
990
990
|
}
|
|
991
|
-
return new Promise(function(
|
|
991
|
+
return new Promise(function(resolve17, reject) {
|
|
992
992
|
isexe(path12, options || {}, function(er, is) {
|
|
993
993
|
if (er) {
|
|
994
994
|
reject(er);
|
|
995
995
|
} else {
|
|
996
|
-
|
|
996
|
+
resolve17(is);
|
|
997
997
|
}
|
|
998
998
|
});
|
|
999
999
|
});
|
|
@@ -1060,27 +1060,27 @@ var require_which = __commonJS({
|
|
|
1060
1060
|
opt = {};
|
|
1061
1061
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
1062
1062
|
const found = [];
|
|
1063
|
-
const step = (i2) => new Promise((
|
|
1063
|
+
const step = (i2) => new Promise((resolve17, reject) => {
|
|
1064
1064
|
if (i2 === pathEnv.length)
|
|
1065
|
-
return opt.all && found.length ?
|
|
1065
|
+
return opt.all && found.length ? resolve17(found) : reject(getNotFoundError(cmd));
|
|
1066
1066
|
const ppRaw = pathEnv[i2];
|
|
1067
1067
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
1068
1068
|
const pCmd = path12.join(pathPart, cmd);
|
|
1069
1069
|
const p2 = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
1070
|
-
|
|
1070
|
+
resolve17(subStep(p2, i2, 0));
|
|
1071
1071
|
});
|
|
1072
|
-
const subStep = (p2, i2, ii) => new Promise((
|
|
1072
|
+
const subStep = (p2, i2, ii) => new Promise((resolve17, reject) => {
|
|
1073
1073
|
if (ii === pathExt.length)
|
|
1074
|
-
return
|
|
1074
|
+
return resolve17(step(i2 + 1));
|
|
1075
1075
|
const ext = pathExt[ii];
|
|
1076
1076
|
isexe(p2 + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
1077
1077
|
if (!er && is) {
|
|
1078
1078
|
if (opt.all)
|
|
1079
1079
|
found.push(p2 + ext);
|
|
1080
1080
|
else
|
|
1081
|
-
return
|
|
1081
|
+
return resolve17(p2 + ext);
|
|
1082
1082
|
}
|
|
1083
|
-
return
|
|
1083
|
+
return resolve17(subStep(p2, i2, ii + 1));
|
|
1084
1084
|
});
|
|
1085
1085
|
});
|
|
1086
1086
|
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
@@ -2135,8 +2135,8 @@ var init_deferred = __esm({
|
|
|
2135
2135
|
"use strict";
|
|
2136
2136
|
createDeferred = () => {
|
|
2137
2137
|
const methods = {};
|
|
2138
|
-
const promise = new Promise((
|
|
2139
|
-
Object.assign(methods, { resolve:
|
|
2138
|
+
const promise = new Promise((resolve17, reject) => {
|
|
2139
|
+
Object.assign(methods, { resolve: resolve17, reject });
|
|
2140
2140
|
});
|
|
2141
2141
|
return Object.assign(promise, methods);
|
|
2142
2142
|
};
|
|
@@ -7476,11 +7476,11 @@ var init_concurrent = __esm({
|
|
|
7476
7476
|
const promises = weakMap.get(stream);
|
|
7477
7477
|
const promise = createDeferred();
|
|
7478
7478
|
promises.push(promise);
|
|
7479
|
-
const
|
|
7480
|
-
return { resolve:
|
|
7479
|
+
const resolve17 = promise.resolve.bind(promise);
|
|
7480
|
+
return { resolve: resolve17, promises };
|
|
7481
7481
|
};
|
|
7482
|
-
waitForConcurrentStreams = async ({ resolve:
|
|
7483
|
-
|
|
7482
|
+
waitForConcurrentStreams = async ({ resolve: resolve17, promises }, subprocess) => {
|
|
7483
|
+
resolve17();
|
|
7484
7484
|
const [isSubprocessExit] = await Promise.race([
|
|
7485
7485
|
Promise.allSettled([true, subprocess]),
|
|
7486
7486
|
Promise.all([false, ...promises])
|
|
@@ -8637,7 +8637,7 @@ var init_core2 = __esm({
|
|
|
8637
8637
|
|
|
8638
8638
|
// ../../node_modules/.pnpm/consola@3.2.3/node_modules/consola/dist/shared/consola.06ad8a64.mjs
|
|
8639
8639
|
function parseStack(stack) {
|
|
8640
|
-
const cwd = process.cwd() +
|
|
8640
|
+
const cwd = process.cwd() + import_node_path17.sep;
|
|
8641
8641
|
const lines = stack.split("\n").splice(1).map((l2) => l2.trim().replace("file://", "").replace(cwd, ""));
|
|
8642
8642
|
return lines;
|
|
8643
8643
|
}
|
|
@@ -8645,12 +8645,12 @@ function writeStream(data, stream) {
|
|
|
8645
8645
|
const write = stream.__write || stream.write;
|
|
8646
8646
|
return write.call(stream, data);
|
|
8647
8647
|
}
|
|
8648
|
-
var import_node_util11,
|
|
8648
|
+
var import_node_util11, import_node_path17, bracket, BasicReporter;
|
|
8649
8649
|
var init_consola_06ad8a64 = __esm({
|
|
8650
8650
|
"../../node_modules/.pnpm/consola@3.2.3/node_modules/consola/dist/shared/consola.06ad8a64.mjs"() {
|
|
8651
8651
|
"use strict";
|
|
8652
8652
|
import_node_util11 = require("util");
|
|
8653
|
-
|
|
8653
|
+
import_node_path17 = require("path");
|
|
8654
8654
|
bracket = (x) => x ? `[${x}]` : "";
|
|
8655
8655
|
BasicReporter = class {
|
|
8656
8656
|
formatStack(stack, opts) {
|
|
@@ -9053,7 +9053,7 @@ async function prompt(message, opts = {}) {
|
|
|
9053
9053
|
}
|
|
9054
9054
|
throw new Error(`Unknown prompt type: ${opts.type}`);
|
|
9055
9055
|
}
|
|
9056
|
-
var import_node_process11, import_node_readline, import_node_tty3, import_tty, import_node_util12,
|
|
9056
|
+
var import_node_process11, import_node_readline, import_node_tty3, import_tty, import_node_util12, import_node_path18, ESC, CSI, beep, cursor, scroll, erase, src, picocolors, tty4, isColorSupported2, formatter, replaceClose2, createColors2, picocolorsExports, l, m, G, K, Y, v, L, M, T, r, Z, H, q, p, J, b, W, Q, I, w, N, j, X, _, DD, uD, R, V, tD, h2, sD, iD, ED, oD, unicode, s, S_STEP_ACTIVE, S_STEP_CANCEL, S_STEP_ERROR, S_STEP_SUBMIT, S_BAR, S_BAR_END, S_RADIO_ACTIVE, S_RADIO_INACTIVE, S_CHECKBOX_ACTIVE, S_CHECKBOX_SELECTED, S_CHECKBOX_INACTIVE, symbol, text, confirm, select, multiselect;
|
|
9057
9057
|
var init_prompt = __esm({
|
|
9058
9058
|
"../../node_modules/.pnpm/consola@3.2.3/node_modules/consola/dist/chunks/prompt.mjs"() {
|
|
9059
9059
|
"use strict";
|
|
@@ -9066,7 +9066,7 @@ var init_prompt = __esm({
|
|
|
9066
9066
|
init_core2();
|
|
9067
9067
|
init_consola_06ad8a64();
|
|
9068
9068
|
import_node_util12 = require("util");
|
|
9069
|
-
|
|
9069
|
+
import_node_path18 = require("path");
|
|
9070
9070
|
ESC = "\x1B";
|
|
9071
9071
|
CSI = `${ESC}[`;
|
|
9072
9072
|
beep = "\x07";
|
|
@@ -10083,7 +10083,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
10083
10083
|
|
|
10084
10084
|
// src/core/utils/fs.ts
|
|
10085
10085
|
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
10086
|
-
var
|
|
10086
|
+
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
10087
10087
|
|
|
10088
10088
|
// src/core/utils/paths.ts
|
|
10089
10089
|
var import_node_path = __toESM(require("path"), 1);
|
|
@@ -10612,38 +10612,6 @@ async function removeEmptyDirs(dir) {
|
|
|
10612
10612
|
}
|
|
10613
10613
|
}
|
|
10614
10614
|
|
|
10615
|
-
// src/core/builders/vite/plugins/unimport.ts
|
|
10616
|
-
var import_unimport = require("unimport");
|
|
10617
|
-
var import_path = require("path");
|
|
10618
|
-
var ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
10619
|
-
".js",
|
|
10620
|
-
".jsx",
|
|
10621
|
-
".ts",
|
|
10622
|
-
".tsx",
|
|
10623
|
-
".vue",
|
|
10624
|
-
".svelte"
|
|
10625
|
-
]);
|
|
10626
|
-
function unimport(config) {
|
|
10627
|
-
const options = config.imports;
|
|
10628
|
-
if (options === false) return [];
|
|
10629
|
-
const unimport2 = (0, import_unimport.createUnimport)(options);
|
|
10630
|
-
return {
|
|
10631
|
-
name: "wxt:unimport",
|
|
10632
|
-
async config() {
|
|
10633
|
-
await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
|
|
10634
|
-
},
|
|
10635
|
-
async transform(code, id) {
|
|
10636
|
-
if (id.includes("node_modules")) return;
|
|
10637
|
-
if (!ENABLED_EXTENSIONS.has((0, import_path.extname)(id))) return;
|
|
10638
|
-
const injected = await unimport2.injectImports(code, id);
|
|
10639
|
-
return {
|
|
10640
|
-
code: injected.code,
|
|
10641
|
-
map: injected.s.generateMap({ hires: "boundary", source: id })
|
|
10642
|
-
};
|
|
10643
|
-
}
|
|
10644
|
-
};
|
|
10645
|
-
}
|
|
10646
|
-
|
|
10647
10615
|
// src/core/utils/virtual-modules.ts
|
|
10648
10616
|
var virtualEntrypointTypes = [
|
|
10649
10617
|
"content-script-main-world",
|
|
@@ -10662,7 +10630,7 @@ var virtualModuleNames = [
|
|
|
10662
10630
|
|
|
10663
10631
|
// src/core/builders/vite/plugins/resolveVirtualModules.ts
|
|
10664
10632
|
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
10665
|
-
var
|
|
10633
|
+
var import_path = require("path");
|
|
10666
10634
|
function resolveVirtualModules(config) {
|
|
10667
10635
|
return virtualModuleNames.map((name) => {
|
|
10668
10636
|
const virtualId = `virtual:wxt-${name}?`;
|
|
@@ -10679,7 +10647,7 @@ function resolveVirtualModules(config) {
|
|
|
10679
10647
|
if (!id.startsWith(resolvedVirtualId)) return;
|
|
10680
10648
|
const inputPath = id.replace(resolvedVirtualId, "");
|
|
10681
10649
|
const template = await import_fs_extra3.default.readFile(
|
|
10682
|
-
(0,
|
|
10650
|
+
(0, import_path.resolve)(config.wxtModuleDir, `dist/virtual/${name}.js`),
|
|
10683
10651
|
"utf-8"
|
|
10684
10652
|
);
|
|
10685
10653
|
return template.replace(`virtual:user-${name}`, inputPath);
|
|
@@ -11035,8 +11003,11 @@ ${noImports}`;
|
|
|
11035
11003
|
}
|
|
11036
11004
|
|
|
11037
11005
|
// src/core/builders/vite/index.ts
|
|
11006
|
+
var import_server = require("vite-node/server");
|
|
11007
|
+
var import_client = require("vite-node/client");
|
|
11008
|
+
var import_source_map = require("vite-node/source-map");
|
|
11038
11009
|
async function createViteBuilder(wxtConfig, hooks, server) {
|
|
11039
|
-
const
|
|
11010
|
+
const vite2 = await import("vite");
|
|
11040
11011
|
const getBaseConfig = async () => {
|
|
11041
11012
|
const config = await wxtConfig.vite(wxtConfig.env);
|
|
11042
11013
|
config.root = wxtConfig.root;
|
|
@@ -11058,7 +11029,6 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
11058
11029
|
config.plugins.push(
|
|
11059
11030
|
download(wxtConfig),
|
|
11060
11031
|
devHtmlPrerender(wxtConfig, server),
|
|
11061
|
-
unimport(wxtConfig),
|
|
11062
11032
|
resolveVirtualModules(wxtConfig),
|
|
11063
11033
|
devServerGlobals(wxtConfig, server),
|
|
11064
11034
|
tsconfigPaths(wxtConfig),
|
|
@@ -11181,22 +11151,65 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
11181
11151
|
};
|
|
11182
11152
|
return {
|
|
11183
11153
|
name: "Vite",
|
|
11184
|
-
version:
|
|
11185
|
-
async importEntrypoint(
|
|
11186
|
-
|
|
11187
|
-
|
|
11188
|
-
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
|
|
11193
|
-
|
|
11194
|
-
|
|
11195
|
-
|
|
11196
|
-
|
|
11197
|
-
|
|
11198
|
-
|
|
11199
|
-
|
|
11154
|
+
version: vite2.version,
|
|
11155
|
+
async importEntrypoint(path12) {
|
|
11156
|
+
switch (wxtConfig.experimental.entrypointImporter) {
|
|
11157
|
+
default:
|
|
11158
|
+
case "jiti": {
|
|
11159
|
+
return await importEntrypointFile(path12);
|
|
11160
|
+
}
|
|
11161
|
+
case "vite-runtime": {
|
|
11162
|
+
const baseConfig = await getBaseConfig();
|
|
11163
|
+
const envConfig = {
|
|
11164
|
+
plugins: [
|
|
11165
|
+
webextensionPolyfillMock(wxtConfig),
|
|
11166
|
+
removeEntrypointMainFunction(wxtConfig, path12)
|
|
11167
|
+
]
|
|
11168
|
+
};
|
|
11169
|
+
const config = vite2.mergeConfig(baseConfig, envConfig);
|
|
11170
|
+
const server2 = await vite2.createServer(config);
|
|
11171
|
+
await server2.listen();
|
|
11172
|
+
const runtime = await vite2.createViteRuntime(server2, { hmr: false });
|
|
11173
|
+
const module2 = await runtime.executeUrl(path12);
|
|
11174
|
+
await server2.close();
|
|
11175
|
+
return module2.default;
|
|
11176
|
+
}
|
|
11177
|
+
case "vite-node": {
|
|
11178
|
+
const baseConfig = await getBaseConfig();
|
|
11179
|
+
baseConfig.optimizeDeps ??= {};
|
|
11180
|
+
baseConfig.optimizeDeps.noDiscovery = true;
|
|
11181
|
+
baseConfig.optimizeDeps.include = [];
|
|
11182
|
+
const envConfig = {
|
|
11183
|
+
plugins: [
|
|
11184
|
+
webextensionPolyfillMock(wxtConfig),
|
|
11185
|
+
removeEntrypointMainFunction(wxtConfig, path12)
|
|
11186
|
+
]
|
|
11187
|
+
};
|
|
11188
|
+
const config = vite2.mergeConfig(baseConfig, envConfig);
|
|
11189
|
+
const server2 = await vite2.createServer(config);
|
|
11190
|
+
await server2.pluginContainer.buildStart({});
|
|
11191
|
+
const node = new import_server.ViteNodeServer(server2);
|
|
11192
|
+
(0, import_source_map.installSourcemapsSupport)({
|
|
11193
|
+
getSourceMap: (source) => node.getSourceMap(source)
|
|
11194
|
+
});
|
|
11195
|
+
const runner = new import_client.ViteNodeRunner({
|
|
11196
|
+
root: server2.config.root,
|
|
11197
|
+
base: server2.config.base,
|
|
11198
|
+
// when having the server and runner in a different context,
|
|
11199
|
+
// you will need to handle the communication between them
|
|
11200
|
+
// and pass to this function
|
|
11201
|
+
fetchModule(id) {
|
|
11202
|
+
return node.fetchModule(id);
|
|
11203
|
+
},
|
|
11204
|
+
resolveId(id, importer) {
|
|
11205
|
+
return node.resolveId(id, importer);
|
|
11206
|
+
}
|
|
11207
|
+
});
|
|
11208
|
+
const res = await runner.executeFile(path12);
|
|
11209
|
+
await server2.close();
|
|
11210
|
+
return res.default;
|
|
11211
|
+
}
|
|
11212
|
+
}
|
|
11200
11213
|
},
|
|
11201
11214
|
async build(group) {
|
|
11202
11215
|
let entryConfig;
|
|
@@ -11204,13 +11217,13 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
11204
11217
|
else if (group.inputPath.endsWith(".css"))
|
|
11205
11218
|
entryConfig = getCssConfig(group);
|
|
11206
11219
|
else entryConfig = getLibModeConfig(group);
|
|
11207
|
-
const buildConfig =
|
|
11220
|
+
const buildConfig = vite2.mergeConfig(await getBaseConfig(), entryConfig);
|
|
11208
11221
|
await hooks.callHook(
|
|
11209
11222
|
"vite:build:extendConfig",
|
|
11210
11223
|
toArray(group),
|
|
11211
11224
|
buildConfig
|
|
11212
11225
|
);
|
|
11213
|
-
const result = await
|
|
11226
|
+
const result = await vite2.build(buildConfig);
|
|
11214
11227
|
return {
|
|
11215
11228
|
entrypoints: group,
|
|
11216
11229
|
chunks: getBuildOutputChunks(result)
|
|
@@ -11226,9 +11239,9 @@ async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
11226
11239
|
}
|
|
11227
11240
|
};
|
|
11228
11241
|
const baseConfig = await getBaseConfig();
|
|
11229
|
-
const finalConfig =
|
|
11242
|
+
const finalConfig = vite2.mergeConfig(baseConfig, serverConfig);
|
|
11230
11243
|
await hooks.callHook("vite:devServer:extendConfig", finalConfig);
|
|
11231
|
-
const viteServer = await
|
|
11244
|
+
const viteServer = await vite2.createServer(finalConfig);
|
|
11232
11245
|
const server2 = {
|
|
11233
11246
|
async listen() {
|
|
11234
11247
|
await viteServer.listen(info.port);
|
|
@@ -11276,6 +11289,108 @@ function getRollupEntry(entrypoint) {
|
|
|
11276
11289
|
return entrypoint.inputPath;
|
|
11277
11290
|
}
|
|
11278
11291
|
|
|
11292
|
+
// src/modules.ts
|
|
11293
|
+
var vite = __toESM(require("vite"), 1);
|
|
11294
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
11295
|
+
var import_node_path13 = require("path");
|
|
11296
|
+
function defineWxtModule(module2) {
|
|
11297
|
+
if (typeof module2 === "function") return { setup: module2 };
|
|
11298
|
+
return module2;
|
|
11299
|
+
}
|
|
11300
|
+
function addViteConfig(wxt2, viteConfig) {
|
|
11301
|
+
wxt2.hooks.hook("ready", (wxt3) => {
|
|
11302
|
+
const userVite = wxt3.config.vite;
|
|
11303
|
+
wxt3.config.vite = async (env2) => {
|
|
11304
|
+
const fromUser = await userVite(env2);
|
|
11305
|
+
const fromModule = viteConfig(env2) ?? {};
|
|
11306
|
+
return vite.mergeConfig(fromModule, fromUser);
|
|
11307
|
+
};
|
|
11308
|
+
});
|
|
11309
|
+
}
|
|
11310
|
+
|
|
11311
|
+
// src/builtin-modules/unimport.ts
|
|
11312
|
+
var import_unimport = require("unimport");
|
|
11313
|
+
var import_node_path14 = require("path");
|
|
11314
|
+
var unimport_default = defineWxtModule({
|
|
11315
|
+
name: "wxt:built-in:unimport",
|
|
11316
|
+
setup(wxt2) {
|
|
11317
|
+
const options = wxt2.config.imports;
|
|
11318
|
+
if (options === false) return;
|
|
11319
|
+
let unimport;
|
|
11320
|
+
wxt2.hooks.hook("ready", () => {
|
|
11321
|
+
const addModuleImports = (module2) => {
|
|
11322
|
+
if (!module2.imports) return;
|
|
11323
|
+
options.imports ??= [];
|
|
11324
|
+
options.imports.push(...module2.imports);
|
|
11325
|
+
};
|
|
11326
|
+
wxt2.config.builtinModules.forEach(addModuleImports);
|
|
11327
|
+
wxt2.config.userModules.forEach(addModuleImports);
|
|
11328
|
+
});
|
|
11329
|
+
wxt2.hooks.afterEach((event) => {
|
|
11330
|
+
if (event.name === "ready") {
|
|
11331
|
+
unimport = (0, import_unimport.createUnimport)(options);
|
|
11332
|
+
}
|
|
11333
|
+
});
|
|
11334
|
+
wxt2.hooks.hook("prepare:types", async (_2, entries) => {
|
|
11335
|
+
await unimport.init();
|
|
11336
|
+
entries.push(await getImportsDeclarationEntry(unimport));
|
|
11337
|
+
if (!options.eslintrc.enabled) return;
|
|
11338
|
+
entries.push(await getImportsEslintEntry(unimport, options));
|
|
11339
|
+
});
|
|
11340
|
+
addViteConfig(wxt2, () => ({
|
|
11341
|
+
plugins: [vitePlugin(unimport)]
|
|
11342
|
+
}));
|
|
11343
|
+
}
|
|
11344
|
+
});
|
|
11345
|
+
function vitePlugin(unimport) {
|
|
11346
|
+
const ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
11347
|
+
".js",
|
|
11348
|
+
".jsx",
|
|
11349
|
+
".ts",
|
|
11350
|
+
".tsx",
|
|
11351
|
+
".vue",
|
|
11352
|
+
".svelte"
|
|
11353
|
+
]);
|
|
11354
|
+
return {
|
|
11355
|
+
name: "wxt:unimport",
|
|
11356
|
+
async transform(code, id) {
|
|
11357
|
+
if (id.includes("node_modules")) return;
|
|
11358
|
+
if (!ENABLED_EXTENSIONS.has((0, import_node_path14.extname)(id))) return;
|
|
11359
|
+
const injected = await unimport.injectImports(code, id);
|
|
11360
|
+
return {
|
|
11361
|
+
code: injected.code,
|
|
11362
|
+
map: injected.s.generateMap({ hires: "boundary", source: id })
|
|
11363
|
+
};
|
|
11364
|
+
}
|
|
11365
|
+
};
|
|
11366
|
+
}
|
|
11367
|
+
async function getImportsDeclarationEntry(unimport) {
|
|
11368
|
+
await unimport.init();
|
|
11369
|
+
return {
|
|
11370
|
+
path: "types/imports.d.ts",
|
|
11371
|
+
text: [
|
|
11372
|
+
"// Generated by wxt",
|
|
11373
|
+
await unimport.generateTypeDeclarations(),
|
|
11374
|
+
""
|
|
11375
|
+
].join("\n"),
|
|
11376
|
+
tsReference: true
|
|
11377
|
+
};
|
|
11378
|
+
}
|
|
11379
|
+
async function getImportsEslintEntry(unimport, options) {
|
|
11380
|
+
const globals2 = {};
|
|
11381
|
+
const eslintrc = { globals: globals2 };
|
|
11382
|
+
(await unimport.getImports()).map((i2) => i2.as ?? i2.name).filter(Boolean).sort().forEach((name) => {
|
|
11383
|
+
eslintrc.globals[name] = options.eslintrc.globalsPropValue;
|
|
11384
|
+
});
|
|
11385
|
+
return {
|
|
11386
|
+
path: options.eslintrc.filePath,
|
|
11387
|
+
text: JSON.stringify(eslintrc, null, 2) + "\n"
|
|
11388
|
+
};
|
|
11389
|
+
}
|
|
11390
|
+
|
|
11391
|
+
// src/builtin-modules/index.ts
|
|
11392
|
+
var builtinModules = [unimport_default];
|
|
11393
|
+
|
|
11279
11394
|
// src/core/wxt.ts
|
|
11280
11395
|
var wxt;
|
|
11281
11396
|
async function registerWxt(command, inlineConfig = {}, getServer) {
|
|
@@ -11297,18 +11412,16 @@ async function registerWxt(command, inlineConfig = {}, getServer) {
|
|
|
11297
11412
|
builder,
|
|
11298
11413
|
server
|
|
11299
11414
|
};
|
|
11300
|
-
|
|
11415
|
+
const initModule = async (module2) => {
|
|
11301
11416
|
if (module2.hooks) wxt.hooks.addHooks(module2.hooks);
|
|
11302
|
-
if (wxt.config.imports !== false && module2.imports) {
|
|
11303
|
-
wxt.config.imports.imports ??= [];
|
|
11304
|
-
wxt.config.imports.imports.push(...module2.imports);
|
|
11305
|
-
}
|
|
11306
11417
|
await module2.setup?.(
|
|
11307
11418
|
wxt,
|
|
11308
11419
|
// @ts-expect-error: Untyped configKey field
|
|
11309
11420
|
module2.configKey ? config[module2.configKey] : void 0
|
|
11310
11421
|
);
|
|
11311
|
-
}
|
|
11422
|
+
};
|
|
11423
|
+
for (const builtinModule of builtinModules) await initModule(builtinModule);
|
|
11424
|
+
for (const userModule of config.userModules) await initModule(userModule);
|
|
11312
11425
|
wxt.hooks.addHooks(config.hooks);
|
|
11313
11426
|
await wxt.hooks.callHook("ready", wxt);
|
|
11314
11427
|
}
|
|
@@ -11322,13 +11435,13 @@ async function writeFileIfDifferent(file, newContents) {
|
|
|
11322
11435
|
}
|
|
11323
11436
|
async function getPublicFiles() {
|
|
11324
11437
|
if (!await import_fs_extra4.default.exists(wxt.config.publicDir)) return [];
|
|
11325
|
-
const files = await (0,
|
|
11438
|
+
const files = await (0, import_fast_glob2.default)("**/*", { cwd: wxt.config.publicDir });
|
|
11326
11439
|
return files.map(unnormalizePath);
|
|
11327
11440
|
}
|
|
11328
11441
|
|
|
11329
11442
|
// src/core/utils/building/build-entrypoints.ts
|
|
11330
11443
|
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
11331
|
-
var
|
|
11444
|
+
var import_path2 = require("path");
|
|
11332
11445
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
11333
11446
|
async function buildEntrypoints(groups, spinner) {
|
|
11334
11447
|
const steps = [];
|
|
@@ -11350,19 +11463,23 @@ async function buildEntrypoints(groups, spinner) {
|
|
|
11350
11463
|
}
|
|
11351
11464
|
async function copyPublicDirectory() {
|
|
11352
11465
|
const files = (await getPublicFiles()).map((file) => ({
|
|
11353
|
-
absoluteSrc: (0,
|
|
11466
|
+
absoluteSrc: (0, import_path2.resolve)(wxt.config.publicDir, file),
|
|
11354
11467
|
relativeDest: file
|
|
11355
11468
|
}));
|
|
11356
11469
|
await wxt.hooks.callHook("build:publicAssets", wxt, files);
|
|
11357
11470
|
if (files.length === 0) return [];
|
|
11358
11471
|
const publicAssets = [];
|
|
11359
|
-
for (const
|
|
11360
|
-
const absoluteDest = (0,
|
|
11361
|
-
await import_fs_extra5.default.ensureDir((0,
|
|
11362
|
-
|
|
11472
|
+
for (const file of files) {
|
|
11473
|
+
const absoluteDest = (0, import_path2.resolve)(wxt.config.outDir, file.relativeDest);
|
|
11474
|
+
await import_fs_extra5.default.ensureDir((0, import_path2.dirname)(absoluteDest));
|
|
11475
|
+
if ("absoluteSrc" in file) {
|
|
11476
|
+
await import_fs_extra5.default.copyFile(file.absoluteSrc, absoluteDest);
|
|
11477
|
+
} else {
|
|
11478
|
+
await import_fs_extra5.default.writeFile(absoluteDest, file.contents, "utf8");
|
|
11479
|
+
}
|
|
11363
11480
|
publicAssets.push({
|
|
11364
11481
|
type: "asset",
|
|
11365
|
-
fileName: relativeDest
|
|
11482
|
+
fileName: file.relativeDest
|
|
11366
11483
|
});
|
|
11367
11484
|
}
|
|
11368
11485
|
return publicAssets;
|
|
@@ -11461,118 +11578,26 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
11461
11578
|
}
|
|
11462
11579
|
|
|
11463
11580
|
// src/core/utils/building/find-entrypoints.ts
|
|
11464
|
-
var
|
|
11465
|
-
var
|
|
11581
|
+
var import_path3 = require("path");
|
|
11582
|
+
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
11466
11583
|
var import_minimatch = require("minimatch");
|
|
11467
11584
|
var import_linkedom3 = require("linkedom");
|
|
11468
11585
|
var import_json5 = __toESM(require("json5"), 1);
|
|
11469
|
-
var
|
|
11586
|
+
var import_fast_glob3 = __toESM(require("fast-glob"), 1);
|
|
11470
11587
|
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
11471
|
-
|
|
11472
|
-
// src/core/utils/building/import-entrypoint.ts
|
|
11473
|
-
var import_jiti = __toESM(require("jiti"), 1);
|
|
11474
|
-
var import_unimport2 = require("unimport");
|
|
11475
|
-
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
11476
|
-
var import_node_path13 = require("path");
|
|
11477
|
-
var import_esbuild = require("esbuild");
|
|
11478
|
-
var import_node_url3 = require("url");
|
|
11479
|
-
var import_meta = {};
|
|
11480
|
-
async function importEntrypointFile(path12) {
|
|
11481
|
-
wxt.logger.debug("Loading file metadata:", path12);
|
|
11482
|
-
const normalPath = normalizePath(path12);
|
|
11483
|
-
const unimport2 = (0, import_unimport2.createUnimport)({
|
|
11484
|
-
...wxt.config.imports,
|
|
11485
|
-
// Only allow specific imports, not all from the project
|
|
11486
|
-
dirs: []
|
|
11487
|
-
});
|
|
11488
|
-
await unimport2.init();
|
|
11489
|
-
const text2 = await import_fs_extra6.default.readFile(path12, "utf-8");
|
|
11490
|
-
const textNoImports = removeProjectImportStatements(text2);
|
|
11491
|
-
const { code } = await unimport2.injectImports(textNoImports);
|
|
11492
|
-
wxt.logger.debug(
|
|
11493
|
-
["Text:", text2, "No imports:", textNoImports, "Code:", code].join("\n")
|
|
11494
|
-
);
|
|
11495
|
-
const jiti = (0, import_jiti.default)(
|
|
11496
|
-
typeof __filename !== "undefined" ? __filename : (0, import_node_url3.fileURLToPath)(import_meta.url),
|
|
11497
|
-
{
|
|
11498
|
-
cache: false,
|
|
11499
|
-
debug: wxt.config.debug,
|
|
11500
|
-
esmResolve: true,
|
|
11501
|
-
alias: {
|
|
11502
|
-
"webextension-polyfill": (0, import_node_path13.resolve)(
|
|
11503
|
-
wxt.config.wxtModuleDir,
|
|
11504
|
-
"dist/virtual/mock-browser.js"
|
|
11505
|
-
)
|
|
11506
|
-
},
|
|
11507
|
-
// Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
|
|
11508
|
-
// respect the custom transform function when using it's native bun option.
|
|
11509
|
-
experimentalBun: false,
|
|
11510
|
-
// List of extensions to transform with esbuild
|
|
11511
|
-
extensions: [
|
|
11512
|
-
".ts",
|
|
11513
|
-
".cts",
|
|
11514
|
-
".mts",
|
|
11515
|
-
".tsx",
|
|
11516
|
-
".js",
|
|
11517
|
-
".cjs",
|
|
11518
|
-
".mjs",
|
|
11519
|
-
".jsx"
|
|
11520
|
-
],
|
|
11521
|
-
transform(opts) {
|
|
11522
|
-
const isEntrypoint = opts.filename === normalPath;
|
|
11523
|
-
return (0, import_esbuild.transformSync)(
|
|
11524
|
-
// Use modified source code for entrypoints
|
|
11525
|
-
isEntrypoint ? code : opts.source,
|
|
11526
|
-
getEsbuildOptions(opts)
|
|
11527
|
-
);
|
|
11528
|
-
}
|
|
11529
|
-
}
|
|
11530
|
-
);
|
|
11531
|
-
try {
|
|
11532
|
-
const res = await jiti(path12);
|
|
11533
|
-
return res.default;
|
|
11534
|
-
} catch (err) {
|
|
11535
|
-
const filePath = (0, import_node_path13.relative)(wxt.config.root, path12);
|
|
11536
|
-
if (err instanceof ReferenceError) {
|
|
11537
|
-
const variableName = err.message.replace(" is not defined", "");
|
|
11538
|
-
throw Error(
|
|
11539
|
-
`${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/go-further/entrypoint-side-effects.html`,
|
|
11540
|
-
{ cause: err }
|
|
11541
|
-
);
|
|
11542
|
-
} else {
|
|
11543
|
-
wxt.logger.error(err);
|
|
11544
|
-
throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
|
|
11545
|
-
}
|
|
11546
|
-
}
|
|
11547
|
-
}
|
|
11548
|
-
function getEsbuildOptions(opts) {
|
|
11549
|
-
const isJsx = opts.filename?.endsWith("x");
|
|
11550
|
-
return {
|
|
11551
|
-
format: "cjs",
|
|
11552
|
-
loader: isJsx ? "tsx" : "ts",
|
|
11553
|
-
...isJsx ? {
|
|
11554
|
-
// `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
|
|
11555
|
-
// grabbing the entrypoint's options.
|
|
11556
|
-
jsxFactory: "h",
|
|
11557
|
-
jsxFragment: "Fragment"
|
|
11558
|
-
} : void 0
|
|
11559
|
-
};
|
|
11560
|
-
}
|
|
11561
|
-
|
|
11562
|
-
// src/core/utils/building/find-entrypoints.ts
|
|
11563
11588
|
async function findEntrypoints() {
|
|
11564
|
-
await
|
|
11565
|
-
await
|
|
11566
|
-
const relativePaths = await (0,
|
|
11589
|
+
await import_fs_extra6.default.mkdir(wxt.config.wxtDir, { recursive: true });
|
|
11590
|
+
await import_fs_extra6.default.writeJson((0, import_path3.resolve)(wxt.config.wxtDir, "tsconfig.json"), {});
|
|
11591
|
+
const relativePaths = await (0, import_fast_glob3.default)(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
|
|
11567
11592
|
cwd: wxt.config.entrypointsDir
|
|
11568
11593
|
});
|
|
11569
11594
|
relativePaths.sort();
|
|
11570
11595
|
const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
|
|
11571
11596
|
const entrypointInfos = relativePaths.reduce((results, relativePath) => {
|
|
11572
|
-
const inputPath = (0,
|
|
11597
|
+
const inputPath = (0, import_path3.resolve)(wxt.config.entrypointsDir, relativePath);
|
|
11573
11598
|
const name = getEntrypointName(wxt.config.entrypointsDir, inputPath);
|
|
11574
11599
|
const matchingGlob = pathGlobs.find(
|
|
11575
|
-
(
|
|
11600
|
+
(glob8) => (0, import_minimatch.minimatch)(relativePath, glob8)
|
|
11576
11601
|
);
|
|
11577
11602
|
if (matchingGlob) {
|
|
11578
11603
|
const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob];
|
|
@@ -11611,7 +11636,7 @@ async function findEntrypoints() {
|
|
|
11611
11636
|
return {
|
|
11612
11637
|
...info,
|
|
11613
11638
|
type,
|
|
11614
|
-
outputDir: (0,
|
|
11639
|
+
outputDir: (0, import_path3.resolve)(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
11615
11640
|
options: {
|
|
11616
11641
|
include: void 0,
|
|
11617
11642
|
exclude: void 0
|
|
@@ -11685,7 +11710,7 @@ function preventDuplicateEntrypointNames(files) {
|
|
|
11685
11710
|
if (absolutePaths.length > 1) {
|
|
11686
11711
|
lines.push(`- ${name}`);
|
|
11687
11712
|
absolutePaths.forEach((absolutePath) => {
|
|
11688
|
-
lines.push(` - ${(0,
|
|
11713
|
+
lines.push(` - ${(0, import_path3.relative)(wxt.config.root, absolutePath)}`);
|
|
11689
11714
|
});
|
|
11690
11715
|
}
|
|
11691
11716
|
return lines;
|
|
@@ -11773,7 +11798,7 @@ async function getUnlistedScriptEntrypoint({
|
|
|
11773
11798
|
name,
|
|
11774
11799
|
skipped
|
|
11775
11800
|
}) {
|
|
11776
|
-
const defaultExport = await importEntrypoint(inputPath);
|
|
11801
|
+
const defaultExport = await wxt.builder.importEntrypoint(inputPath);
|
|
11777
11802
|
if (defaultExport == null) {
|
|
11778
11803
|
throw Error(
|
|
11779
11804
|
`${name}: Default export not found, did you forget to call "export default defineUnlistedScript(...)"?`
|
|
@@ -11796,7 +11821,7 @@ async function getBackgroundEntrypoint({
|
|
|
11796
11821
|
}) {
|
|
11797
11822
|
let options = {};
|
|
11798
11823
|
if (inputPath !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
|
|
11799
|
-
const defaultExport = await importEntrypoint(inputPath);
|
|
11824
|
+
const defaultExport = await wxt.builder.importEntrypoint(inputPath);
|
|
11800
11825
|
if (defaultExport == null) {
|
|
11801
11826
|
throw Error(
|
|
11802
11827
|
`${name}: Default export not found, did you forget to call "export default defineBackground(...)"?`
|
|
@@ -11822,7 +11847,13 @@ async function getContentScriptEntrypoint({
|
|
|
11822
11847
|
name,
|
|
11823
11848
|
skipped
|
|
11824
11849
|
}) {
|
|
11825
|
-
const
|
|
11850
|
+
const defaultExport = await wxt.builder.importEntrypoint(inputPath);
|
|
11851
|
+
if (defaultExport == null) {
|
|
11852
|
+
throw Error(
|
|
11853
|
+
`${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
|
|
11854
|
+
);
|
|
11855
|
+
}
|
|
11856
|
+
const { main: _2, ...options } = defaultExport;
|
|
11826
11857
|
if (options == null) {
|
|
11827
11858
|
throw Error(
|
|
11828
11859
|
`${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
|
|
@@ -11832,7 +11863,7 @@ async function getContentScriptEntrypoint({
|
|
|
11832
11863
|
type: "content-script",
|
|
11833
11864
|
name,
|
|
11834
11865
|
inputPath,
|
|
11835
|
-
outputDir: (0,
|
|
11866
|
+
outputDir: (0, import_path3.resolve)(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
11836
11867
|
options: resolvePerBrowserOptions(options, wxt.config.browser),
|
|
11837
11868
|
skipped
|
|
11838
11869
|
};
|
|
@@ -11865,7 +11896,7 @@ async function getSidepanelEntrypoint(info) {
|
|
|
11865
11896
|
};
|
|
11866
11897
|
}
|
|
11867
11898
|
async function getHtmlEntrypointOptions(info, keyMap, queries, parsers) {
|
|
11868
|
-
const content = await
|
|
11899
|
+
const content = await import_fs_extra6.default.readFile(info.inputPath, "utf-8");
|
|
11869
11900
|
const { document } = (0, import_linkedom3.parseHTML)(content);
|
|
11870
11901
|
const options = {};
|
|
11871
11902
|
const defaultQuery = (manifestKey) => document.querySelector(`meta[name='manifest.${manifestKey}']`)?.getAttribute("content");
|
|
@@ -11925,15 +11956,11 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
11925
11956
|
[`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
|
|
11926
11957
|
};
|
|
11927
11958
|
var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|
|
11928
|
-
function importEntrypoint(path12) {
|
|
11929
|
-
return wxt.config.experimental.viteRuntime ? wxt.builder.importEntrypoint(path12) : importEntrypointFile(path12);
|
|
11930
|
-
}
|
|
11931
11959
|
|
|
11932
11960
|
// src/core/utils/building/generate-wxt-dir.ts
|
|
11933
|
-
var
|
|
11934
|
-
var
|
|
11935
|
-
var
|
|
11936
|
-
var import_node_path14 = __toESM(require("path"), 1);
|
|
11961
|
+
var import_fs_extra7 = __toESM(require("fs-extra"), 1);
|
|
11962
|
+
var import_node_path15 = require("path");
|
|
11963
|
+
var import_node_path16 = __toESM(require("path"), 1);
|
|
11937
11964
|
|
|
11938
11965
|
// src/core/utils/i18n.ts
|
|
11939
11966
|
var predefinedMessages = {
|
|
@@ -11974,42 +12001,33 @@ function parseI18nMessages(messagesJson) {
|
|
|
11974
12001
|
|
|
11975
12002
|
// src/core/utils/building/generate-wxt-dir.ts
|
|
11976
12003
|
async function generateTypesDir(entrypoints) {
|
|
11977
|
-
await
|
|
11978
|
-
const
|
|
11979
|
-
|
|
11980
|
-
|
|
11981
|
-
|
|
11982
|
-
|
|
11983
|
-
|
|
11984
|
-
|
|
11985
|
-
}
|
|
11986
|
-
references.push(await writePathsDeclarationFile(entrypoints));
|
|
11987
|
-
references.push(await writeI18nDeclarationFile());
|
|
11988
|
-
references.push(await writeGlobalsDeclarationFile());
|
|
11989
|
-
const mainReference = await writeMainDeclarationFile(references);
|
|
11990
|
-
await writeTsConfigFile(mainReference);
|
|
11991
|
-
}
|
|
11992
|
-
async function writeImportsDeclarationFile(unimport2) {
|
|
11993
|
-
const filePath = (0, import_path5.resolve)(wxt.config.typesDir, "imports.d.ts");
|
|
11994
|
-
await unimport2.scanImportsFromDir(void 0, { cwd: wxt.config.srcDir });
|
|
11995
|
-
await writeFileIfDifferent(
|
|
11996
|
-
filePath,
|
|
11997
|
-
["// Generated by wxt", await unimport2.generateTypeDeclarations()].join(
|
|
11998
|
-
"\n"
|
|
11999
|
-
) + "\n"
|
|
12000
|
-
);
|
|
12001
|
-
return filePath;
|
|
12002
|
-
}
|
|
12003
|
-
async function writeImportsEslintFile(unimport2, options) {
|
|
12004
|
-
const globals2 = {};
|
|
12005
|
-
const eslintrc = { globals: globals2 };
|
|
12006
|
-
(await unimport2.getImports()).map((i2) => i2.as ?? i2.name).filter(Boolean).sort().forEach((name) => {
|
|
12007
|
-
eslintrc.globals[name] = options.eslintrc.globalsPropValue;
|
|
12004
|
+
await import_fs_extra7.default.ensureDir(wxt.config.typesDir);
|
|
12005
|
+
const entries = [
|
|
12006
|
+
// Hard-coded entries
|
|
12007
|
+
{ module: "wxt/vite-builder-env" }
|
|
12008
|
+
];
|
|
12009
|
+
wxt.config.userModules.forEach((module2) => {
|
|
12010
|
+
if (module2.type === "node_module" && module2.configKey != null)
|
|
12011
|
+
entries.push({ module: module2.id });
|
|
12008
12012
|
});
|
|
12009
|
-
await
|
|
12013
|
+
entries.push(await getPathsDeclarationEntry(entrypoints));
|
|
12014
|
+
entries.push(await getI18nDeclarationEntry());
|
|
12015
|
+
entries.push(await getGlobalsDeclarationEntry());
|
|
12016
|
+
entries.push(await getTsConfigEntry());
|
|
12017
|
+
await wxt.hooks.callHook("prepare:types", wxt, entries);
|
|
12018
|
+
entries.push(getMainDeclarationEntry(entries));
|
|
12019
|
+
const absoluteFileEntries = entries.filter((entry) => "path" in entry).map((entry) => ({
|
|
12020
|
+
...entry,
|
|
12021
|
+
path: (0, import_node_path15.resolve)(wxt.config.wxtDir, entry.path)
|
|
12022
|
+
}));
|
|
12023
|
+
await Promise.all(
|
|
12024
|
+
absoluteFileEntries.map(async (file) => {
|
|
12025
|
+
await import_fs_extra7.default.ensureDir((0, import_node_path15.dirname)(file.path));
|
|
12026
|
+
await writeFileIfDifferent(file.path, file.text);
|
|
12027
|
+
})
|
|
12028
|
+
);
|
|
12010
12029
|
}
|
|
12011
|
-
async function
|
|
12012
|
-
const filePath = (0, import_path5.resolve)(wxt.config.typesDir, "paths.d.ts");
|
|
12030
|
+
async function getPathsDeclarationEntry(entrypoints) {
|
|
12013
12031
|
const unions = entrypoints.map(
|
|
12014
12032
|
(entry) => getEntrypointBundlePath(
|
|
12015
12033
|
entry,
|
|
@@ -12030,14 +12048,13 @@ declare module "wxt/browser" {
|
|
|
12030
12048
|
}
|
|
12031
12049
|
}
|
|
12032
12050
|
`;
|
|
12033
|
-
|
|
12034
|
-
|
|
12035
|
-
template.replace("{{ union }}", unions || " | never")
|
|
12036
|
-
|
|
12037
|
-
|
|
12051
|
+
return {
|
|
12052
|
+
path: "types/paths.d.ts",
|
|
12053
|
+
text: template.replace("{{ union }}", unions || " | never"),
|
|
12054
|
+
tsReference: true
|
|
12055
|
+
};
|
|
12038
12056
|
}
|
|
12039
|
-
async function
|
|
12040
|
-
const filePath = (0, import_path5.resolve)(wxt.config.typesDir, "i18n.d.ts");
|
|
12057
|
+
async function getI18nDeclarationEntry() {
|
|
12041
12058
|
const defaultLocale = wxt.config.manifest.default_locale;
|
|
12042
12059
|
const template = `// Generated by wxt
|
|
12043
12060
|
import "wxt/browser";
|
|
@@ -12060,13 +12077,13 @@ declare module "wxt/browser" {
|
|
|
12060
12077
|
`;
|
|
12061
12078
|
let messages;
|
|
12062
12079
|
if (defaultLocale) {
|
|
12063
|
-
const defaultLocalePath =
|
|
12080
|
+
const defaultLocalePath = import_node_path16.default.resolve(
|
|
12064
12081
|
wxt.config.publicDir,
|
|
12065
12082
|
"_locales",
|
|
12066
12083
|
defaultLocale,
|
|
12067
12084
|
"messages.json"
|
|
12068
12085
|
);
|
|
12069
|
-
const content = JSON.parse(await
|
|
12086
|
+
const content = JSON.parse(await import_fs_extra7.default.readFile(defaultLocalePath, "utf-8"));
|
|
12070
12087
|
messages = parseI18nMessages(content);
|
|
12071
12088
|
} else {
|
|
12072
12089
|
messages = parseI18nMessages({});
|
|
@@ -12083,18 +12100,17 @@ declare module "wxt/browser" {
|
|
|
12083
12100
|
options?: GetMessageOptions,
|
|
12084
12101
|
): string;`;
|
|
12085
12102
|
});
|
|
12086
|
-
|
|
12087
|
-
|
|
12088
|
-
template.replace("{{ overrides }}", overrides.join("\n"))
|
|
12089
|
-
|
|
12090
|
-
|
|
12103
|
+
return {
|
|
12104
|
+
path: "types/i18n.d.ts",
|
|
12105
|
+
text: template.replace("{{ overrides }}", overrides.join("\n")),
|
|
12106
|
+
tsReference: true
|
|
12107
|
+
};
|
|
12091
12108
|
}
|
|
12092
|
-
async function
|
|
12093
|
-
const filePath = (0, import_path5.resolve)(wxt.config.typesDir, "globals.d.ts");
|
|
12109
|
+
async function getGlobalsDeclarationEntry() {
|
|
12094
12110
|
const globals2 = [...getGlobals(wxt.config), ...getEntrypointGlobals("")];
|
|
12095
|
-
|
|
12096
|
-
|
|
12097
|
-
[
|
|
12111
|
+
return {
|
|
12112
|
+
path: "types/globals.d.ts",
|
|
12113
|
+
text: [
|
|
12098
12114
|
"// Generated by wxt",
|
|
12099
12115
|
"export {}",
|
|
12100
12116
|
"interface ImportMetaEnv {",
|
|
@@ -12102,36 +12118,31 @@ async function writeGlobalsDeclarationFile() {
|
|
|
12102
12118
|
"}",
|
|
12103
12119
|
"interface ImportMeta {",
|
|
12104
12120
|
" readonly env: ImportMetaEnv",
|
|
12105
|
-
"}"
|
|
12106
|
-
|
|
12107
|
-
|
|
12108
|
-
|
|
12121
|
+
"}",
|
|
12122
|
+
""
|
|
12123
|
+
].join("\n"),
|
|
12124
|
+
tsReference: true
|
|
12125
|
+
};
|
|
12109
12126
|
}
|
|
12110
|
-
|
|
12111
|
-
const
|
|
12112
|
-
|
|
12113
|
-
|
|
12114
|
-
|
|
12115
|
-
|
|
12116
|
-
|
|
12117
|
-
|
|
12118
|
-
|
|
12119
|
-
|
|
12120
|
-
|
|
12121
|
-
|
|
12122
|
-
|
|
12123
|
-
|
|
12124
|
-
|
|
12125
|
-
...wxt.config.modules.filter(
|
|
12126
|
-
(module2) => module2.type === "node_module" && module2.configKey != null
|
|
12127
|
-
).map((module2) => `/// <reference types="${module2.id}" />`)
|
|
12128
|
-
].join("\n") + "\n"
|
|
12129
|
-
);
|
|
12130
|
-
return filePath;
|
|
12127
|
+
function getMainDeclarationEntry(references) {
|
|
12128
|
+
const lines = ["// Generated by wxt"];
|
|
12129
|
+
references.forEach((ref) => {
|
|
12130
|
+
if ("module" in ref) {
|
|
12131
|
+
return lines.push(`/// <reference types="${ref.module}" />`);
|
|
12132
|
+
} else if (ref.tsReference) {
|
|
12133
|
+
const absolutePath = (0, import_node_path15.resolve)(wxt.config.wxtDir, ref.path);
|
|
12134
|
+
const relativePath = (0, import_node_path15.relative)(wxt.config.wxtDir, absolutePath);
|
|
12135
|
+
lines.push(`/// <reference types="./${normalizePath(relativePath)}" />`);
|
|
12136
|
+
}
|
|
12137
|
+
});
|
|
12138
|
+
return {
|
|
12139
|
+
path: "wxt.d.ts",
|
|
12140
|
+
text: lines.join("\n") + "\n"
|
|
12141
|
+
};
|
|
12131
12142
|
}
|
|
12132
|
-
async function
|
|
12143
|
+
async function getTsConfigEntry() {
|
|
12133
12144
|
const dir = wxt.config.wxtDir;
|
|
12134
|
-
const getTsconfigPath = (path12) => normalizePath((0,
|
|
12145
|
+
const getTsconfigPath = (path12) => normalizePath((0, import_node_path15.relative)(dir, path12));
|
|
12135
12146
|
const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
|
|
12136
12147
|
const aliasPath = getTsconfigPath(absolutePath);
|
|
12137
12148
|
return [
|
|
@@ -12139,9 +12150,7 @@ async function writeTsConfigFile(mainReference) {
|
|
|
12139
12150
|
` "${alias}/*": ["${aliasPath}/*"]`
|
|
12140
12151
|
];
|
|
12141
12152
|
}).join(",\n");
|
|
12142
|
-
|
|
12143
|
-
(0, import_path5.resolve)(dir, "tsconfig.json"),
|
|
12144
|
-
`{
|
|
12153
|
+
const text2 = `{
|
|
12145
12154
|
"compilerOptions": {
|
|
12146
12155
|
"target": "ESNext",
|
|
12147
12156
|
"module": "ESNext",
|
|
@@ -12158,32 +12167,35 @@ ${paths}
|
|
|
12158
12167
|
},
|
|
12159
12168
|
"include": [
|
|
12160
12169
|
"${getTsconfigPath(wxt.config.root)}/**/*",
|
|
12161
|
-
"
|
|
12170
|
+
"./wxt.d.ts"
|
|
12162
12171
|
],
|
|
12163
12172
|
"exclude": ["${getTsconfigPath(wxt.config.outBaseDir)}"]
|
|
12164
|
-
}
|
|
12165
|
-
|
|
12173
|
+
}`;
|
|
12174
|
+
return {
|
|
12175
|
+
path: "tsconfig.json",
|
|
12176
|
+
text: text2
|
|
12177
|
+
};
|
|
12166
12178
|
}
|
|
12167
12179
|
|
|
12168
12180
|
// src/core/utils/building/resolve-config.ts
|
|
12169
12181
|
var import_c12 = require("c12");
|
|
12170
|
-
var
|
|
12182
|
+
var import_node_path21 = __toESM(require("path"), 1);
|
|
12171
12183
|
|
|
12172
12184
|
// src/core/utils/cache.ts
|
|
12173
|
-
var
|
|
12174
|
-
var
|
|
12185
|
+
var import_fs_extra8 = __toESM(require("fs-extra"), 1);
|
|
12186
|
+
var import_path4 = require("path");
|
|
12175
12187
|
function createFsCache(wxtDir) {
|
|
12176
|
-
const getPath = (key) => (0,
|
|
12188
|
+
const getPath = (key) => (0, import_path4.resolve)(wxtDir, "cache", encodeURIComponent(key));
|
|
12177
12189
|
return {
|
|
12178
12190
|
async set(key, value) {
|
|
12179
12191
|
const path12 = getPath(key);
|
|
12180
|
-
await (0,
|
|
12192
|
+
await (0, import_fs_extra8.ensureDir)((0, import_path4.dirname)(path12));
|
|
12181
12193
|
await writeFileIfDifferent(path12, value);
|
|
12182
12194
|
},
|
|
12183
12195
|
async get(key) {
|
|
12184
12196
|
const path12 = getPath(key);
|
|
12185
12197
|
try {
|
|
12186
|
-
return await
|
|
12198
|
+
return await import_fs_extra8.default.readFile(path12, "utf-8");
|
|
12187
12199
|
} catch {
|
|
12188
12200
|
return void 0;
|
|
12189
12201
|
}
|
|
@@ -12199,18 +12211,18 @@ var import_node_process13 = require("process");
|
|
|
12199
12211
|
init_utils2();
|
|
12200
12212
|
var import_node_tty4 = require("tty");
|
|
12201
12213
|
var import_node_util13 = require("util");
|
|
12202
|
-
var
|
|
12214
|
+
var import_node_path19 = require("path");
|
|
12203
12215
|
|
|
12204
12216
|
// src/core/utils/building/resolve-config.ts
|
|
12205
12217
|
var import_defu = __toESM(require("defu"), 1);
|
|
12206
12218
|
|
|
12207
12219
|
// src/core/utils/package.ts
|
|
12208
|
-
var
|
|
12209
|
-
var
|
|
12220
|
+
var import_node_path20 = require("path");
|
|
12221
|
+
var import_fs_extra9 = __toESM(require("fs-extra"), 1);
|
|
12210
12222
|
async function getPackageJson() {
|
|
12211
|
-
const file = (0,
|
|
12223
|
+
const file = (0, import_node_path20.resolve)(wxt.config.root, "package.json");
|
|
12212
12224
|
try {
|
|
12213
|
-
return await
|
|
12225
|
+
return await import_fs_extra9.default.readJson(file);
|
|
12214
12226
|
} catch (err) {
|
|
12215
12227
|
wxt.logger.debug(
|
|
12216
12228
|
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
@@ -12226,9 +12238,9 @@ function isModuleInstalled(name) {
|
|
|
12226
12238
|
}
|
|
12227
12239
|
|
|
12228
12240
|
// src/core/utils/building/resolve-config.ts
|
|
12229
|
-
var
|
|
12230
|
-
var
|
|
12231
|
-
var
|
|
12241
|
+
var import_fs_extra10 = __toESM(require("fs-extra"), 1);
|
|
12242
|
+
var import_fast_glob4 = __toESM(require("fast-glob"), 1);
|
|
12243
|
+
var import_meta = {};
|
|
12232
12244
|
async function resolveConfig(inlineConfig, command) {
|
|
12233
12245
|
let userConfig = {};
|
|
12234
12246
|
let userConfigMetadata;
|
|
@@ -12253,28 +12265,28 @@ async function resolveConfig(inlineConfig, command) {
|
|
|
12253
12265
|
const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
|
|
12254
12266
|
const mode = mergedConfig.mode ?? COMMAND_MODES[command];
|
|
12255
12267
|
const env2 = { browser, command, manifestVersion, mode };
|
|
12256
|
-
const root =
|
|
12268
|
+
const root = import_node_path21.default.resolve(
|
|
12257
12269
|
inlineConfig.root ?? userConfig.root ?? process.cwd()
|
|
12258
12270
|
);
|
|
12259
|
-
const wxtDir =
|
|
12271
|
+
const wxtDir = import_node_path21.default.resolve(root, ".wxt");
|
|
12260
12272
|
const wxtModuleDir = await resolveWxtModuleDir();
|
|
12261
|
-
const srcDir =
|
|
12262
|
-
const entrypointsDir =
|
|
12273
|
+
const srcDir = import_node_path21.default.resolve(root, mergedConfig.srcDir ?? root);
|
|
12274
|
+
const entrypointsDir = import_node_path21.default.resolve(
|
|
12263
12275
|
srcDir,
|
|
12264
12276
|
mergedConfig.entrypointsDir ?? "entrypoints"
|
|
12265
12277
|
);
|
|
12266
|
-
const modulesDir =
|
|
12278
|
+
const modulesDir = import_node_path21.default.resolve(srcDir, mergedConfig.modulesDir ?? "modules");
|
|
12267
12279
|
if (await isDirMissing(entrypointsDir)) {
|
|
12268
12280
|
logMissingDir(logger, "Entrypoints", entrypointsDir);
|
|
12269
12281
|
}
|
|
12270
12282
|
const filterEntrypoints = !!mergedConfig.filterEntrypoints?.length ? new Set(mergedConfig.filterEntrypoints) : void 0;
|
|
12271
|
-
const publicDir =
|
|
12283
|
+
const publicDir = import_node_path21.default.resolve(srcDir, mergedConfig.publicDir ?? "public");
|
|
12272
12284
|
if (await isDirMissing(publicDir)) {
|
|
12273
12285
|
logMissingDir(logger, "Public", publicDir);
|
|
12274
12286
|
}
|
|
12275
|
-
const typesDir =
|
|
12276
|
-
const outBaseDir =
|
|
12277
|
-
const outDir =
|
|
12287
|
+
const typesDir = import_node_path21.default.resolve(wxtDir, "types");
|
|
12288
|
+
const outBaseDir = import_node_path21.default.resolve(root, mergedConfig.outDir ?? ".output");
|
|
12289
|
+
const outDir = import_node_path21.default.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
|
|
12278
12290
|
const reloadCommand = mergedConfig.dev?.reloadCommand ?? "Alt+R";
|
|
12279
12291
|
const runnerConfig = await (0, import_c12.loadConfig)({
|
|
12280
12292
|
name: "web-ext",
|
|
@@ -12291,7 +12303,7 @@ async function resolveConfig(inlineConfig, command) {
|
|
|
12291
12303
|
"~": srcDir,
|
|
12292
12304
|
"@@": root,
|
|
12293
12305
|
"~~": root
|
|
12294
|
-
}).map(([key, value]) => [key,
|
|
12306
|
+
}).map(([key, value]) => [key, import_node_path21.default.resolve(root, value)])
|
|
12295
12307
|
);
|
|
12296
12308
|
let devServerConfig;
|
|
12297
12309
|
if (command === "serve") {
|
|
@@ -12305,14 +12317,20 @@ async function resolveConfig(inlineConfig, command) {
|
|
|
12305
12317
|
hostname: "localhost"
|
|
12306
12318
|
};
|
|
12307
12319
|
}
|
|
12308
|
-
const
|
|
12309
|
-
|
|
12310
|
-
|
|
12311
|
-
|
|
12312
|
-
|
|
12313
|
-
|
|
12314
|
-
|
|
12315
|
-
|
|
12320
|
+
const userModules = await resolveWxtUserModules(
|
|
12321
|
+
modulesDir,
|
|
12322
|
+
mergedConfig.modules
|
|
12323
|
+
);
|
|
12324
|
+
const moduleOptions = userModules.reduce(
|
|
12325
|
+
(map, module2) => {
|
|
12326
|
+
if (module2.configKey) {
|
|
12327
|
+
map[module2.configKey] = // @ts-expect-error
|
|
12328
|
+
mergedConfig[module2.configKey];
|
|
12329
|
+
}
|
|
12330
|
+
return map;
|
|
12331
|
+
},
|
|
12332
|
+
{}
|
|
12333
|
+
);
|
|
12316
12334
|
return {
|
|
12317
12335
|
browser,
|
|
12318
12336
|
command,
|
|
@@ -12322,7 +12340,7 @@ async function resolveConfig(inlineConfig, command) {
|
|
|
12322
12340
|
filterEntrypoints,
|
|
12323
12341
|
env: env2,
|
|
12324
12342
|
fsCache: createFsCache(wxtDir),
|
|
12325
|
-
imports: await getUnimportOptions(wxtDir, logger, mergedConfig),
|
|
12343
|
+
imports: await getUnimportOptions(wxtDir, srcDir, logger, mergedConfig),
|
|
12326
12344
|
logger,
|
|
12327
12345
|
manifest: await resolveManifestConfig(env2, mergedConfig.manifest),
|
|
12328
12346
|
manifestVersion,
|
|
@@ -12343,7 +12361,7 @@ async function resolveConfig(inlineConfig, command) {
|
|
|
12343
12361
|
alias,
|
|
12344
12362
|
experimental: (0, import_defu.default)(mergedConfig.experimental, {
|
|
12345
12363
|
includeBrowserPolyfill: true,
|
|
12346
|
-
|
|
12364
|
+
entrypointImporter: "jiti"
|
|
12347
12365
|
}),
|
|
12348
12366
|
dev: {
|
|
12349
12367
|
server: devServerConfig,
|
|
@@ -12351,7 +12369,8 @@ async function resolveConfig(inlineConfig, command) {
|
|
|
12351
12369
|
},
|
|
12352
12370
|
hooks: mergedConfig.hooks ?? {},
|
|
12353
12371
|
vite: mergedConfig.vite ?? (() => ({})),
|
|
12354
|
-
|
|
12372
|
+
builtinModules,
|
|
12373
|
+
userModules,
|
|
12355
12374
|
plugins: [],
|
|
12356
12375
|
...moduleOptions
|
|
12357
12376
|
};
|
|
@@ -12381,7 +12400,7 @@ async function mergeInlineConfig(inlineConfig, userConfig) {
|
|
|
12381
12400
|
};
|
|
12382
12401
|
}
|
|
12383
12402
|
function resolveZipConfig(root, mergedConfig) {
|
|
12384
|
-
const downloadedPackagesDir =
|
|
12403
|
+
const downloadedPackagesDir = import_node_path21.default.resolve(root, ".wxt/local_modules");
|
|
12385
12404
|
return {
|
|
12386
12405
|
name: void 0,
|
|
12387
12406
|
sourcesTemplate: "{{name}}-{{version}}-sources.zip",
|
|
@@ -12407,12 +12426,12 @@ function resolveZipConfig(root, mergedConfig) {
|
|
|
12407
12426
|
};
|
|
12408
12427
|
}
|
|
12409
12428
|
function resolveAnalysisConfig(root, mergedConfig) {
|
|
12410
|
-
const analysisOutputFile =
|
|
12429
|
+
const analysisOutputFile = import_node_path21.default.resolve(
|
|
12411
12430
|
root,
|
|
12412
12431
|
mergedConfig.analysis?.outputFile ?? "stats.html"
|
|
12413
12432
|
);
|
|
12414
|
-
const analysisOutputDir =
|
|
12415
|
-
const analysisOutputName =
|
|
12433
|
+
const analysisOutputDir = import_node_path21.default.dirname(analysisOutputFile);
|
|
12434
|
+
const analysisOutputName = import_node_path21.default.parse(analysisOutputFile).name;
|
|
12416
12435
|
return {
|
|
12417
12436
|
enabled: mergedConfig.analysis?.enabled ?? false,
|
|
12418
12437
|
open: mergedConfig.analysis?.open ?? false,
|
|
@@ -12423,17 +12442,17 @@ function resolveAnalysisConfig(root, mergedConfig) {
|
|
|
12423
12442
|
keepArtifacts: mergedConfig.analysis?.keepArtifacts ?? false
|
|
12424
12443
|
};
|
|
12425
12444
|
}
|
|
12426
|
-
async function getUnimportOptions(wxtDir, logger, config) {
|
|
12445
|
+
async function getUnimportOptions(wxtDir, srcDir, logger, config) {
|
|
12427
12446
|
if (config.imports === false) return false;
|
|
12428
|
-
const
|
|
12429
|
-
let
|
|
12430
|
-
switch (
|
|
12447
|
+
const rawEslintEnabled = config.imports?.eslintrc?.enabled;
|
|
12448
|
+
let eslintEnabled;
|
|
12449
|
+
switch (rawEslintEnabled) {
|
|
12431
12450
|
case void 0:
|
|
12432
12451
|
case "auto":
|
|
12433
|
-
|
|
12452
|
+
eslintEnabled = await isModuleInstalled("eslint");
|
|
12434
12453
|
break;
|
|
12435
12454
|
default:
|
|
12436
|
-
|
|
12455
|
+
eslintEnabled = rawEslintEnabled;
|
|
12437
12456
|
}
|
|
12438
12457
|
const defaultOptions = {
|
|
12439
12458
|
debugLog: logger.debug,
|
|
@@ -12449,9 +12468,12 @@ async function getUnimportOptions(wxtDir, logger, config) {
|
|
|
12449
12468
|
],
|
|
12450
12469
|
warn: logger.warn,
|
|
12451
12470
|
dirs: ["components", "composables", "hooks", "utils"],
|
|
12471
|
+
dirsScanOptions: {
|
|
12472
|
+
cwd: srcDir
|
|
12473
|
+
},
|
|
12452
12474
|
eslintrc: {
|
|
12453
|
-
enabled,
|
|
12454
|
-
filePath:
|
|
12475
|
+
enabled: eslintEnabled,
|
|
12476
|
+
filePath: import_node_path21.default.resolve(wxtDir, "eslintrc-auto-import.json"),
|
|
12455
12477
|
globalsPropValue: true
|
|
12456
12478
|
}
|
|
12457
12479
|
};
|
|
@@ -12461,16 +12483,16 @@ async function getUnimportOptions(wxtDir, logger, config) {
|
|
|
12461
12483
|
);
|
|
12462
12484
|
}
|
|
12463
12485
|
async function resolveWxtModuleDir() {
|
|
12464
|
-
const requireResolve = require?.resolve ?? (await import("module")).default.createRequire(
|
|
12465
|
-
return
|
|
12486
|
+
const requireResolve = require?.resolve ?? (await import("module")).default.createRequire(import_meta.url).resolve;
|
|
12487
|
+
return import_node_path21.default.resolve(requireResolve("wxt"), "../..");
|
|
12466
12488
|
}
|
|
12467
12489
|
async function isDirMissing(dir) {
|
|
12468
|
-
return !await
|
|
12490
|
+
return !await import_fs_extra10.default.exists(dir);
|
|
12469
12491
|
}
|
|
12470
12492
|
function logMissingDir(logger, name, expected) {
|
|
12471
12493
|
logger.warn(
|
|
12472
12494
|
`${name} directory not found: ./${normalizePath(
|
|
12473
|
-
|
|
12495
|
+
import_node_path21.default.relative(process.cwd(), expected)
|
|
12474
12496
|
)}`
|
|
12475
12497
|
);
|
|
12476
12498
|
}
|
|
@@ -12479,19 +12501,19 @@ var COMMAND_MODES = {
|
|
|
12479
12501
|
serve: "development"
|
|
12480
12502
|
};
|
|
12481
12503
|
async function mergeBuilderConfig(inlineConfig, userConfig) {
|
|
12482
|
-
const
|
|
12483
|
-
if (
|
|
12504
|
+
const vite2 = await import("vite").catch(() => void 0);
|
|
12505
|
+
if (vite2) {
|
|
12484
12506
|
return {
|
|
12485
12507
|
vite: async (env2) => {
|
|
12486
12508
|
const resolvedInlineConfig = await inlineConfig.vite?.(env2) ?? {};
|
|
12487
12509
|
const resolvedUserConfig = await userConfig.vite?.(env2) ?? {};
|
|
12488
|
-
return
|
|
12510
|
+
return vite2.mergeConfig(resolvedUserConfig, resolvedInlineConfig);
|
|
12489
12511
|
}
|
|
12490
12512
|
};
|
|
12491
12513
|
}
|
|
12492
12514
|
throw Error("Builder not found. Make sure vite is installed.");
|
|
12493
12515
|
}
|
|
12494
|
-
async function
|
|
12516
|
+
async function resolveWxtUserModules(modulesDir, modules = []) {
|
|
12495
12517
|
const npmModules = await Promise.all(
|
|
12496
12518
|
modules.map(async (moduleId) => {
|
|
12497
12519
|
const mod = await import(
|
|
@@ -12508,13 +12530,13 @@ async function resolveWxtModules(modulesDir, modules = []) {
|
|
|
12508
12530
|
};
|
|
12509
12531
|
})
|
|
12510
12532
|
);
|
|
12511
|
-
const localModulePaths = await (0,
|
|
12533
|
+
const localModulePaths = await (0, import_fast_glob4.default)(["*.[tj]s", "*/index.[tj]s"], {
|
|
12512
12534
|
cwd: modulesDir,
|
|
12513
12535
|
onlyFiles: true
|
|
12514
12536
|
}).catch(() => []);
|
|
12515
12537
|
const localModules = await Promise.all(
|
|
12516
12538
|
localModulePaths.map(async (file) => {
|
|
12517
|
-
const absolutePath = normalizePath(
|
|
12539
|
+
const absolutePath = normalizePath(import_node_path21.default.resolve(modulesDir, file));
|
|
12518
12540
|
const { config } = await (0, import_c12.loadConfig)({
|
|
12519
12541
|
configFile: absolutePath,
|
|
12520
12542
|
globalRc: false,
|
|
@@ -12577,15 +12599,105 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
|
|
|
12577
12599
|
"content-script-style": "individual"
|
|
12578
12600
|
};
|
|
12579
12601
|
|
|
12602
|
+
// src/core/utils/building/import-entrypoint.ts
|
|
12603
|
+
var import_jiti = __toESM(require("jiti"), 1);
|
|
12604
|
+
var import_unimport3 = require("unimport");
|
|
12605
|
+
var import_fs_extra11 = __toESM(require("fs-extra"), 1);
|
|
12606
|
+
var import_node_path22 = require("path");
|
|
12607
|
+
var import_esbuild = require("esbuild");
|
|
12608
|
+
var import_node_url3 = require("url");
|
|
12609
|
+
var import_meta2 = {};
|
|
12610
|
+
async function importEntrypointFile(path12) {
|
|
12611
|
+
wxt.logger.debug("Loading file metadata:", path12);
|
|
12612
|
+
const normalPath = normalizePath(path12);
|
|
12613
|
+
const unimport = (0, import_unimport3.createUnimport)({
|
|
12614
|
+
...wxt.config.imports,
|
|
12615
|
+
// Only allow specific imports, not all from the project
|
|
12616
|
+
dirs: []
|
|
12617
|
+
});
|
|
12618
|
+
await unimport.init();
|
|
12619
|
+
const text2 = await import_fs_extra11.default.readFile(path12, "utf-8");
|
|
12620
|
+
const textNoImports = removeProjectImportStatements(text2);
|
|
12621
|
+
const { code } = await unimport.injectImports(textNoImports);
|
|
12622
|
+
wxt.logger.debug(
|
|
12623
|
+
["Text:", text2, "No imports:", textNoImports, "Code:", code].join("\n")
|
|
12624
|
+
);
|
|
12625
|
+
const jiti = (0, import_jiti.default)(
|
|
12626
|
+
typeof __filename !== "undefined" ? __filename : (0, import_node_url3.fileURLToPath)(import_meta2.url),
|
|
12627
|
+
{
|
|
12628
|
+
cache: false,
|
|
12629
|
+
debug: wxt.config.debug,
|
|
12630
|
+
esmResolve: true,
|
|
12631
|
+
alias: {
|
|
12632
|
+
"webextension-polyfill": (0, import_node_path22.resolve)(
|
|
12633
|
+
wxt.config.wxtModuleDir,
|
|
12634
|
+
"dist/virtual/mock-browser.js"
|
|
12635
|
+
)
|
|
12636
|
+
},
|
|
12637
|
+
// Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
|
|
12638
|
+
// respect the custom transform function when using it's native bun option.
|
|
12639
|
+
experimentalBun: false,
|
|
12640
|
+
// List of extensions to transform with esbuild
|
|
12641
|
+
extensions: [
|
|
12642
|
+
".ts",
|
|
12643
|
+
".cts",
|
|
12644
|
+
".mts",
|
|
12645
|
+
".tsx",
|
|
12646
|
+
".js",
|
|
12647
|
+
".cjs",
|
|
12648
|
+
".mjs",
|
|
12649
|
+
".jsx"
|
|
12650
|
+
],
|
|
12651
|
+
transform(opts) {
|
|
12652
|
+
const isEntrypoint = opts.filename === normalPath;
|
|
12653
|
+
return (0, import_esbuild.transformSync)(
|
|
12654
|
+
// Use modified source code for entrypoints
|
|
12655
|
+
isEntrypoint ? code : opts.source,
|
|
12656
|
+
getEsbuildOptions(opts)
|
|
12657
|
+
);
|
|
12658
|
+
}
|
|
12659
|
+
}
|
|
12660
|
+
);
|
|
12661
|
+
try {
|
|
12662
|
+
const res = await jiti(path12);
|
|
12663
|
+
return res.default;
|
|
12664
|
+
} catch (err) {
|
|
12665
|
+
const filePath = (0, import_node_path22.relative)(wxt.config.root, path12);
|
|
12666
|
+
if (err instanceof ReferenceError) {
|
|
12667
|
+
const variableName = err.message.replace(" is not defined", "");
|
|
12668
|
+
throw Error(
|
|
12669
|
+
`${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/go-further/entrypoint-side-effects.html`,
|
|
12670
|
+
{ cause: err }
|
|
12671
|
+
);
|
|
12672
|
+
} else {
|
|
12673
|
+
wxt.logger.error(err);
|
|
12674
|
+
throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
|
|
12675
|
+
}
|
|
12676
|
+
}
|
|
12677
|
+
}
|
|
12678
|
+
function getEsbuildOptions(opts) {
|
|
12679
|
+
const isJsx = opts.filename?.endsWith("x");
|
|
12680
|
+
return {
|
|
12681
|
+
format: "cjs",
|
|
12682
|
+
loader: isJsx ? "tsx" : "ts",
|
|
12683
|
+
...isJsx ? {
|
|
12684
|
+
// `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
|
|
12685
|
+
// grabbing the entrypoint's options.
|
|
12686
|
+
jsxFactory: "h",
|
|
12687
|
+
jsxFragment: "Fragment"
|
|
12688
|
+
} : void 0
|
|
12689
|
+
};
|
|
12690
|
+
}
|
|
12691
|
+
|
|
12580
12692
|
// src/core/utils/building/internal-build.ts
|
|
12581
12693
|
var import_picocolors5 = __toESM(require("picocolors"), 1);
|
|
12582
12694
|
var import_fs_extra14 = __toESM(require("fs-extra"), 1);
|
|
12583
12695
|
|
|
12584
12696
|
// src/core/utils/log/printBuildSummary.ts
|
|
12585
|
-
var
|
|
12697
|
+
var import_path5 = require("path");
|
|
12586
12698
|
|
|
12587
12699
|
// src/core/utils/log/printFileList.ts
|
|
12588
|
-
var
|
|
12700
|
+
var import_node_path23 = __toESM(require("path"), 1);
|
|
12589
12701
|
var import_picocolors3 = __toESM(require("picocolors"), 1);
|
|
12590
12702
|
var import_fs_extra12 = __toESM(require("fs-extra"), 1);
|
|
12591
12703
|
var import_filesize = require("filesize");
|
|
@@ -12620,8 +12732,8 @@ async function printFileList(log, header, baseDir, files) {
|
|
|
12620
12732
|
const fileRows = await Promise.all(
|
|
12621
12733
|
files.map(async (file, i2) => {
|
|
12622
12734
|
const parts = [
|
|
12623
|
-
|
|
12624
|
-
|
|
12735
|
+
import_node_path23.default.relative(process.cwd(), baseDir) + import_node_path23.default.sep,
|
|
12736
|
+
import_node_path23.default.relative(baseDir, file)
|
|
12625
12737
|
];
|
|
12626
12738
|
const prefix = i2 === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
12627
12739
|
const color = getChunkColor(file);
|
|
@@ -12666,7 +12778,7 @@ async function printBuildSummary(log, header, output) {
|
|
|
12666
12778
|
return l2.fileName.localeCompare(r2.fileName);
|
|
12667
12779
|
});
|
|
12668
12780
|
const files = chunks.map(
|
|
12669
|
-
(chunk) => (0,
|
|
12781
|
+
(chunk) => (0, import_path5.resolve)(wxt.config.outDir, chunk.fileName)
|
|
12670
12782
|
);
|
|
12671
12783
|
await printFileList(log, header, wxt.config.outDir, files);
|
|
12672
12784
|
}
|
|
@@ -12688,14 +12800,14 @@ function getChunkSortWeight(filename) {
|
|
|
12688
12800
|
var import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
12689
12801
|
|
|
12690
12802
|
// package.json
|
|
12691
|
-
var version = "0.18.
|
|
12803
|
+
var version = "0.18.9";
|
|
12692
12804
|
|
|
12693
12805
|
// src/core/utils/building/internal-build.ts
|
|
12694
|
-
var
|
|
12806
|
+
var import_fast_glob5 = __toESM(require("fast-glob"), 1);
|
|
12695
12807
|
|
|
12696
12808
|
// src/core/utils/manifest.ts
|
|
12697
12809
|
var import_fs_extra13 = __toESM(require("fs-extra"), 1);
|
|
12698
|
-
var
|
|
12810
|
+
var import_path6 = require("path");
|
|
12699
12811
|
|
|
12700
12812
|
// src/core/utils/content-security-policy.ts
|
|
12701
12813
|
var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
@@ -12804,7 +12916,7 @@ var import_defu2 = __toESM(require("defu"), 1);
|
|
|
12804
12916
|
async function writeManifest(manifest, output) {
|
|
12805
12917
|
const str = wxt.config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
12806
12918
|
await import_fs_extra13.default.ensureDir(wxt.config.outDir);
|
|
12807
|
-
await writeFileIfDifferent((0,
|
|
12919
|
+
await writeFileIfDifferent((0, import_path6.resolve)(wxt.config.outDir, "manifest.json"), str);
|
|
12808
12920
|
output.publicAssets.unshift({
|
|
12809
12921
|
type: "asset",
|
|
12810
12922
|
fileName: "manifest.json"
|
|
@@ -13339,7 +13451,7 @@ async function rebuild(allEntrypoints, entrypointGroups, existingOutput = {
|
|
|
13339
13451
|
}
|
|
13340
13452
|
|
|
13341
13453
|
// src/core/utils/building/internal-build.ts
|
|
13342
|
-
var
|
|
13454
|
+
var import_node_path24 = require("path");
|
|
13343
13455
|
|
|
13344
13456
|
// src/core/utils/validation.ts
|
|
13345
13457
|
function validateEntrypoints(entrypoints) {
|
|
@@ -13438,7 +13550,7 @@ async function internalBuild() {
|
|
|
13438
13550
|
}
|
|
13439
13551
|
if (wxt.config.analysis.enabled) {
|
|
13440
13552
|
await combineAnalysisStats();
|
|
13441
|
-
const statsPath = (0,
|
|
13553
|
+
const statsPath = (0, import_node_path24.relative)(wxt.config.root, wxt.config.analysis.outputFile);
|
|
13442
13554
|
wxt.logger.info(
|
|
13443
13555
|
`Analysis complete:
|
|
13444
13556
|
${import_picocolors5.default.gray("\u2514\u2500")} ${import_picocolors5.default.yellow(statsPath)}`
|
|
@@ -13456,7 +13568,7 @@ async function internalBuild() {
|
|
|
13456
13568
|
return output;
|
|
13457
13569
|
}
|
|
13458
13570
|
async function combineAnalysisStats() {
|
|
13459
|
-
const unixFiles = await (0,
|
|
13571
|
+
const unixFiles = await (0, import_fast_glob5.default)(`${wxt.config.analysis.outputName}-*.json`, {
|
|
13460
13572
|
cwd: wxt.config.analysis.outputDir,
|
|
13461
13573
|
absolute: true
|
|
13462
13574
|
});
|
|
@@ -13486,7 +13598,7 @@ function printValidationResults({
|
|
|
13486
13598
|
return map;
|
|
13487
13599
|
}, /* @__PURE__ */ new Map());
|
|
13488
13600
|
Array.from(entrypointErrors.entries()).forEach(([entrypoint, errors2]) => {
|
|
13489
|
-
consola.log((0,
|
|
13601
|
+
consola.log((0, import_node_path24.relative)(cwd, entrypoint.inputPath));
|
|
13490
13602
|
console.log();
|
|
13491
13603
|
errors2.forEach((err) => {
|
|
13492
13604
|
const type = err.type === "error" ? import_picocolors5.default.red("ERROR") : import_picocolors5.default.yellow("WARN");
|
|
@@ -13504,8 +13616,8 @@ async function build(config) {
|
|
|
13504
13616
|
}
|
|
13505
13617
|
|
|
13506
13618
|
// src/core/clean.ts
|
|
13507
|
-
var
|
|
13508
|
-
var
|
|
13619
|
+
var import_node_path25 = __toESM(require("path"), 1);
|
|
13620
|
+
var import_fast_glob6 = __toESM(require("fast-glob"), 1);
|
|
13509
13621
|
var import_fs_extra15 = __toESM(require("fs-extra"), 1);
|
|
13510
13622
|
var import_picocolors6 = __toESM(require("picocolors"), 1);
|
|
13511
13623
|
async function clean(root = process.cwd()) {
|
|
@@ -13517,8 +13629,8 @@ async function clean(root = process.cwd()) {
|
|
|
13517
13629
|
".output/*"
|
|
13518
13630
|
];
|
|
13519
13631
|
consola.debug("Looking for:", tempDirs.map(import_picocolors6.default.cyan).join(", "));
|
|
13520
|
-
const directories = await (0,
|
|
13521
|
-
cwd:
|
|
13632
|
+
const directories = await (0, import_fast_glob6.default)(tempDirs, {
|
|
13633
|
+
cwd: import_node_path25.default.resolve(root),
|
|
13522
13634
|
absolute: true,
|
|
13523
13635
|
onlyDirectories: true,
|
|
13524
13636
|
deep: 2
|
|
@@ -13529,11 +13641,11 @@ async function clean(root = process.cwd()) {
|
|
|
13529
13641
|
}
|
|
13530
13642
|
consola.debug(
|
|
13531
13643
|
"Found:",
|
|
13532
|
-
directories.map((dir) => import_picocolors6.default.cyan(
|
|
13644
|
+
directories.map((dir) => import_picocolors6.default.cyan(import_node_path25.default.relative(root, dir))).join(", ")
|
|
13533
13645
|
);
|
|
13534
13646
|
for (const directory of directories) {
|
|
13535
13647
|
await import_fs_extra15.default.rm(directory, { force: true, recursive: true });
|
|
13536
|
-
consola.debug("Deleted " + import_picocolors6.default.cyan(
|
|
13648
|
+
consola.debug("Deleted " + import_picocolors6.default.cyan(import_node_path25.default.relative(root, directory)));
|
|
13537
13649
|
}
|
|
13538
13650
|
}
|
|
13539
13651
|
|
|
@@ -13548,12 +13660,12 @@ function defineRunnerConfig(config) {
|
|
|
13548
13660
|
}
|
|
13549
13661
|
|
|
13550
13662
|
// src/core/runners/wsl.ts
|
|
13551
|
-
var
|
|
13663
|
+
var import_node_path26 = require("path");
|
|
13552
13664
|
function createWslRunner() {
|
|
13553
13665
|
return {
|
|
13554
13666
|
async openBrowser() {
|
|
13555
13667
|
wxt.logger.warn(
|
|
13556
|
-
`Cannot open browser when using WSL. Load "${(0,
|
|
13668
|
+
`Cannot open browser when using WSL. Load "${(0, import_node_path26.relative)(
|
|
13557
13669
|
process.cwd(),
|
|
13558
13670
|
wxt.config.outDir
|
|
13559
13671
|
)}" as an unpacked extension manually`
|
|
@@ -13640,12 +13752,12 @@ var DEFAULT_CHROMIUM_PREFS = {
|
|
|
13640
13752
|
};
|
|
13641
13753
|
|
|
13642
13754
|
// src/core/runners/safari.ts
|
|
13643
|
-
var
|
|
13755
|
+
var import_node_path27 = require("path");
|
|
13644
13756
|
function createSafariRunner() {
|
|
13645
13757
|
return {
|
|
13646
13758
|
async openBrowser() {
|
|
13647
13759
|
wxt.logger.warn(
|
|
13648
|
-
`Cannot Safari using web-ext. Load "${(0,
|
|
13760
|
+
`Cannot Safari using web-ext. Load "${(0, import_node_path27.relative)(
|
|
13649
13761
|
process.cwd(),
|
|
13650
13762
|
wxt.config.outDir
|
|
13651
13763
|
)}" as an unpacked extension manually`
|
|
@@ -13657,12 +13769,12 @@ function createSafariRunner() {
|
|
|
13657
13769
|
}
|
|
13658
13770
|
|
|
13659
13771
|
// src/core/runners/manual.ts
|
|
13660
|
-
var
|
|
13772
|
+
var import_node_path28 = require("path");
|
|
13661
13773
|
function createManualRunner() {
|
|
13662
13774
|
return {
|
|
13663
13775
|
async openBrowser() {
|
|
13664
13776
|
wxt.logger.info(
|
|
13665
|
-
`Load "${(0,
|
|
13777
|
+
`Load "${(0, import_node_path28.relative)(
|
|
13666
13778
|
process.cwd(),
|
|
13667
13779
|
wxt.config.outDir
|
|
13668
13780
|
)}" as an unpacked extension manually`
|
|
@@ -13690,7 +13802,7 @@ async function createExtensionRunner() {
|
|
|
13690
13802
|
// src/core/create-server.ts
|
|
13691
13803
|
var import_async_mutex = require("async-mutex");
|
|
13692
13804
|
var import_picocolors7 = __toESM(require("picocolors"), 1);
|
|
13693
|
-
var
|
|
13805
|
+
var import_node_path29 = require("path");
|
|
13694
13806
|
async function createServer(inlineConfig) {
|
|
13695
13807
|
await registerWxt("serve", inlineConfig, async (config) => {
|
|
13696
13808
|
const { port, hostname } = config.dev.server;
|
|
@@ -13792,7 +13904,7 @@ function createFileReloader(server) {
|
|
|
13792
13904
|
return;
|
|
13793
13905
|
}
|
|
13794
13906
|
wxt.logger.info(
|
|
13795
|
-
`Changed: ${Array.from(new Set(fileChanges)).map((file) => import_picocolors7.default.dim((0,
|
|
13907
|
+
`Changed: ${Array.from(new Set(fileChanges)).map((file) => import_picocolors7.default.dim((0, import_node_path29.relative)(wxt.config.root, file))).join(", ")}`
|
|
13796
13908
|
);
|
|
13797
13909
|
const allEntrypoints = await findEntrypoints();
|
|
13798
13910
|
try {
|
|
@@ -13881,7 +13993,7 @@ function getExternalOutputDependencies(server) {
|
|
|
13881
13993
|
var import_prompts = __toESM(require("prompts"), 1);
|
|
13882
13994
|
var import_giget = require("giget");
|
|
13883
13995
|
var import_fs_extra16 = __toESM(require("fs-extra"), 1);
|
|
13884
|
-
var
|
|
13996
|
+
var import_node_path30 = __toESM(require("path"), 1);
|
|
13885
13997
|
var import_picocolors8 = __toESM(require("picocolors"), 1);
|
|
13886
13998
|
async function initialize(options) {
|
|
13887
13999
|
consola.info("Initalizing new project");
|
|
@@ -13933,13 +14045,13 @@ async function initialize(options) {
|
|
|
13933
14045
|
const isEmpty = (await import_fs_extra16.default.readdir(input.directory)).length === 0;
|
|
13934
14046
|
if (!isEmpty) {
|
|
13935
14047
|
consola.error(
|
|
13936
|
-
`The directory ${
|
|
14048
|
+
`The directory ${import_node_path30.default.resolve(input.directory)} is not empty. Aborted.`
|
|
13937
14049
|
);
|
|
13938
14050
|
process.exit(1);
|
|
13939
14051
|
}
|
|
13940
14052
|
}
|
|
13941
14053
|
await cloneProject(input);
|
|
13942
|
-
const cdPath =
|
|
14054
|
+
const cdPath = import_node_path30.default.relative(process.cwd(), import_node_path30.default.resolve(input.directory));
|
|
13943
14055
|
console.log();
|
|
13944
14056
|
consola.log(
|
|
13945
14057
|
`\u2728 WXT project created with the ${TEMPLATE_COLORS[input.template.name]?.(input.template.name) ?? input.template.name} template.`
|
|
@@ -13982,8 +14094,8 @@ async function cloneProject({
|
|
|
13982
14094
|
force: true
|
|
13983
14095
|
});
|
|
13984
14096
|
await import_fs_extra16.default.move(
|
|
13985
|
-
|
|
13986
|
-
|
|
14097
|
+
import_node_path30.default.join(directory, "_gitignore"),
|
|
14098
|
+
import_node_path30.default.join(directory, ".gitignore")
|
|
13987
14099
|
).catch(
|
|
13988
14100
|
(err) => consola.warn("Failed to move _gitignore to .gitignore:", err)
|
|
13989
14101
|
);
|
|
@@ -14015,11 +14127,11 @@ async function prepare(config) {
|
|
|
14015
14127
|
}
|
|
14016
14128
|
|
|
14017
14129
|
// src/core/zip.ts
|
|
14018
|
-
var
|
|
14130
|
+
var import_node_path31 = __toESM(require("path"), 1);
|
|
14019
14131
|
var import_fs_extra17 = __toESM(require("fs-extra"), 1);
|
|
14020
14132
|
var import_minimatch2 = require("minimatch");
|
|
14021
14133
|
var import_jszip = __toESM(require("jszip"), 1);
|
|
14022
|
-
var
|
|
14134
|
+
var import_fast_glob7 = __toESM(require("fast-glob"), 1);
|
|
14023
14135
|
async function zip(config) {
|
|
14024
14136
|
await registerWxt("build", config);
|
|
14025
14137
|
const output = await internalBuild();
|
|
@@ -14027,7 +14139,7 @@ async function zip(config) {
|
|
|
14027
14139
|
wxt.logger.info("Zipping extension...");
|
|
14028
14140
|
const zipFiles = [];
|
|
14029
14141
|
const projectName = wxt.config.zip.name ?? kebabCaseAlphanumeric(
|
|
14030
|
-
(await getPackageJson())?.name ||
|
|
14142
|
+
(await getPackageJson())?.name || import_node_path31.default.dirname(process.cwd())
|
|
14031
14143
|
);
|
|
14032
14144
|
const applyTemplate = (template) => template.replaceAll("{{name}}", projectName).replaceAll("{{browser}}", wxt.config.browser).replaceAll(
|
|
14033
14145
|
"{{version}}",
|
|
@@ -14035,13 +14147,13 @@ async function zip(config) {
|
|
|
14035
14147
|
).replaceAll("{{mode}}", wxt.config.mode).replaceAll("{{manifestVersion}}", `mv${wxt.config.manifestVersion}`);
|
|
14036
14148
|
await import_fs_extra17.default.ensureDir(wxt.config.outBaseDir);
|
|
14037
14149
|
const outZipFilename = applyTemplate(wxt.config.zip.artifactTemplate);
|
|
14038
|
-
const outZipPath =
|
|
14150
|
+
const outZipPath = import_node_path31.default.resolve(wxt.config.outBaseDir, outZipFilename);
|
|
14039
14151
|
await zipDir(wxt.config.outDir, outZipPath);
|
|
14040
14152
|
zipFiles.push(outZipPath);
|
|
14041
14153
|
if (wxt.config.browser === "firefox") {
|
|
14042
14154
|
const { overrides, files: downloadedPackages } = await downloadPrivatePackages();
|
|
14043
14155
|
const sourcesZipFilename = applyTemplate(wxt.config.zip.sourcesTemplate);
|
|
14044
|
-
const sourcesZipPath =
|
|
14156
|
+
const sourcesZipPath = import_node_path31.default.resolve(
|
|
14045
14157
|
wxt.config.outBaseDir,
|
|
14046
14158
|
sourcesZipFilename
|
|
14047
14159
|
);
|
|
@@ -14067,7 +14179,7 @@ async function zip(config) {
|
|
|
14067
14179
|
}
|
|
14068
14180
|
async function zipDir(directory, outputPath, options) {
|
|
14069
14181
|
const archive = new import_jszip.default();
|
|
14070
|
-
const files = (await (0,
|
|
14182
|
+
const files = (await (0, import_fast_glob7.default)("**/*", {
|
|
14071
14183
|
cwd: directory,
|
|
14072
14184
|
// Ignore node_modules, otherwise this glob step takes forever
|
|
14073
14185
|
ignore: ["**/node_modules"],
|
|
@@ -14080,11 +14192,11 @@ async function zipDir(directory, outputPath, options) {
|
|
|
14080
14192
|
const filesToZip = [
|
|
14081
14193
|
...files,
|
|
14082
14194
|
...(options?.additionalFiles ?? []).map(
|
|
14083
|
-
(file) =>
|
|
14195
|
+
(file) => import_node_path31.default.relative(directory, file)
|
|
14084
14196
|
)
|
|
14085
14197
|
];
|
|
14086
14198
|
for (const file of filesToZip) {
|
|
14087
|
-
const absolutePath =
|
|
14199
|
+
const absolutePath = import_node_path31.default.resolve(directory, file);
|
|
14088
14200
|
if (file.endsWith(".json")) {
|
|
14089
14201
|
const content = await import_fs_extra17.default.readFile(absolutePath, "utf-8");
|
|
14090
14202
|
archive.file(
|
|
@@ -14133,14 +14245,14 @@ async function downloadPrivatePackages() {
|
|
|
14133
14245
|
}
|
|
14134
14246
|
function addOverridesToPackageJson(absolutePackageJsonPath, content, overrides) {
|
|
14135
14247
|
if (Object.keys(overrides).length === 0) return content;
|
|
14136
|
-
const packageJsonDir =
|
|
14248
|
+
const packageJsonDir = import_node_path31.default.dirname(absolutePackageJsonPath);
|
|
14137
14249
|
const oldPackage = JSON.parse(content);
|
|
14138
14250
|
const newPackage = {
|
|
14139
14251
|
...oldPackage,
|
|
14140
14252
|
[wxt.pm.overridesKey]: { ...oldPackage[wxt.pm.overridesKey] }
|
|
14141
14253
|
};
|
|
14142
14254
|
Object.entries(overrides).forEach(([key, absolutePath]) => {
|
|
14143
|
-
newPackage[wxt.pm.overridesKey][key] = "file://./" + normalizePath(
|
|
14255
|
+
newPackage[wxt.pm.overridesKey][key] = "file://./" + normalizePath(import_node_path31.default.relative(packageJsonDir, absolutePath));
|
|
14144
14256
|
});
|
|
14145
14257
|
return JSON.stringify(newPackage, null, 2);
|
|
14146
14258
|
}
|