wxt 0.11.0 → 0.11.2
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-6V4H2CZ4.js → chunk-XTGVY6KL.js} +84 -77
- package/dist/cli.cjs +84 -77
- package/dist/client.d.ts +21 -8
- package/dist/client.js +59 -5
- package/dist/{external-6YqvLCcd.d.ts → external-PmmO6xnl.d.ts} +19 -3
- package/dist/{external-n9SucYhJ.d.cts → external-irU6kFSB.d.cts} +19 -3
- package/dist/{external-n9SucYhJ.d.ts → external-irU6kFSB.d.ts} +19 -3
- package/dist/index.cjs +84 -77
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/sandbox.d.ts +1 -1
- package/dist/testing.cjs +3 -5
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/virtual/content-script-entrypoint.js +59 -5
- package/dist/virtual/mock-browser.js +3 -5
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.11.
|
|
2
|
+
var version = "0.11.2";
|
|
3
3
|
|
|
4
4
|
// src/core/utils/arrays.ts
|
|
5
5
|
function every(array, predicate) {
|
|
@@ -2203,51 +2203,46 @@ async function combineAnalysisStats(config) {
|
|
|
2203
2203
|
// src/core/utils/building/find-entrypoints.ts
|
|
2204
2204
|
import glob3 from "fast-glob";
|
|
2205
2205
|
async function findEntrypoints(config) {
|
|
2206
|
-
const relativePaths = await glob3(
|
|
2206
|
+
const relativePaths = await glob3(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
|
|
2207
2207
|
cwd: config.entrypointsDir
|
|
2208
2208
|
});
|
|
2209
2209
|
relativePaths.sort();
|
|
2210
2210
|
const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
if (matchingGlob == null) {
|
|
2219
|
-
config.logger.warn(
|
|
2220
|
-
`${relativePath} does not match any known entrypoint. Known entrypoints:
|
|
2221
|
-
${JSON.stringify(
|
|
2222
|
-
PATH_GLOB_TO_TYPE_MAP,
|
|
2223
|
-
null,
|
|
2224
|
-
2
|
|
2225
|
-
)}`
|
|
2226
|
-
);
|
|
2227
|
-
return;
|
|
2228
|
-
}
|
|
2211
|
+
const entrypointInfos = relativePaths.reduce((results, relativePath) => {
|
|
2212
|
+
const inputPath = resolve12(config.entrypointsDir, relativePath);
|
|
2213
|
+
const name = getEntrypointName(config.entrypointsDir, inputPath);
|
|
2214
|
+
const matchingGlob = pathGlobs.find(
|
|
2215
|
+
(glob4) => minimatch(relativePath, glob4)
|
|
2216
|
+
);
|
|
2217
|
+
if (matchingGlob) {
|
|
2229
2218
|
const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob];
|
|
2230
|
-
|
|
2231
|
-
|
|
2219
|
+
results.push({ name, inputPath, type });
|
|
2220
|
+
}
|
|
2221
|
+
return results;
|
|
2222
|
+
}, []);
|
|
2223
|
+
preventDuplicateEntrypointNames(config, entrypointInfos);
|
|
2224
|
+
let hasBackground = false;
|
|
2225
|
+
const entrypoints = await Promise.all(
|
|
2226
|
+
entrypointInfos.map(async (info) => {
|
|
2227
|
+
const { type } = info;
|
|
2232
2228
|
switch (type) {
|
|
2233
2229
|
case "popup":
|
|
2234
|
-
return await getPopupEntrypoint(config,
|
|
2230
|
+
return await getPopupEntrypoint(config, info);
|
|
2235
2231
|
case "options":
|
|
2236
|
-
return await getOptionsEntrypoint(config,
|
|
2232
|
+
return await getOptionsEntrypoint(config, info);
|
|
2237
2233
|
case "background":
|
|
2238
2234
|
hasBackground = true;
|
|
2239
|
-
return await getBackgroundEntrypoint(config,
|
|
2235
|
+
return await getBackgroundEntrypoint(config, info);
|
|
2240
2236
|
case "content-script":
|
|
2241
|
-
return await getContentScriptEntrypoint(config,
|
|
2237
|
+
return await getContentScriptEntrypoint(config, info);
|
|
2242
2238
|
case "unlisted-page":
|
|
2243
|
-
return await getUnlistedPageEntrypoint(config,
|
|
2239
|
+
return await getUnlistedPageEntrypoint(config, info);
|
|
2244
2240
|
case "unlisted-script":
|
|
2245
|
-
return await getUnlistedScriptEntrypoint(config,
|
|
2241
|
+
return await getUnlistedScriptEntrypoint(config, info);
|
|
2246
2242
|
case "content-script-style":
|
|
2247
2243
|
return {
|
|
2244
|
+
...info,
|
|
2248
2245
|
type,
|
|
2249
|
-
name: getEntrypointName(config.entrypointsDir, path6),
|
|
2250
|
-
inputPath: path6,
|
|
2251
2246
|
outputDir: resolve12(config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
2252
2247
|
options: {
|
|
2253
2248
|
include: void 0,
|
|
@@ -2256,9 +2251,8 @@ ${JSON.stringify(
|
|
|
2256
2251
|
};
|
|
2257
2252
|
default:
|
|
2258
2253
|
return {
|
|
2254
|
+
...info,
|
|
2259
2255
|
type,
|
|
2260
|
-
name: getEntrypointName(config.entrypointsDir, path6),
|
|
2261
|
-
inputPath: path6,
|
|
2262
2256
|
outputDir: config.outDir,
|
|
2263
2257
|
options: {
|
|
2264
2258
|
include: void 0,
|
|
@@ -2268,25 +2262,13 @@ ${JSON.stringify(
|
|
|
2268
2262
|
}
|
|
2269
2263
|
})
|
|
2270
2264
|
);
|
|
2271
|
-
const entrypoints = possibleEntrypoints.filter(
|
|
2272
|
-
(entry) => !!entry
|
|
2273
|
-
);
|
|
2274
|
-
const existingNames = {};
|
|
2275
|
-
entrypoints.forEach((entrypoint) => {
|
|
2276
|
-
const withSameName = existingNames[entrypoint.name];
|
|
2277
|
-
if (withSameName) {
|
|
2278
|
-
throw Error(
|
|
2279
|
-
`Multiple entrypoints with the name "${entrypoint.name}" detected, but only one is allowed: ${[
|
|
2280
|
-
relative4(config.root, withSameName.inputPath),
|
|
2281
|
-
relative4(config.root, entrypoint.inputPath)
|
|
2282
|
-
].join(", ")}`
|
|
2283
|
-
);
|
|
2284
|
-
}
|
|
2285
|
-
existingNames[entrypoint.name] = entrypoint;
|
|
2286
|
-
});
|
|
2287
2265
|
if (config.command === "serve" && !hasBackground) {
|
|
2288
2266
|
entrypoints.push(
|
|
2289
|
-
await getBackgroundEntrypoint(config,
|
|
2267
|
+
await getBackgroundEntrypoint(config, {
|
|
2268
|
+
inputPath: VIRTUAL_NOOP_BACKGROUND_MODULE_ID,
|
|
2269
|
+
name: "background",
|
|
2270
|
+
type: "background"
|
|
2271
|
+
})
|
|
2290
2272
|
);
|
|
2291
2273
|
}
|
|
2292
2274
|
config.logger.debug("All entrypoints:", entrypoints);
|
|
@@ -2309,6 +2291,36 @@ ${JSON.stringify(
|
|
|
2309
2291
|
config.logger.debug(`${config.browser} entrypoints:`, targetEntrypoints);
|
|
2310
2292
|
return targetEntrypoints;
|
|
2311
2293
|
}
|
|
2294
|
+
function preventDuplicateEntrypointNames(config, files) {
|
|
2295
|
+
const namesToPaths = files.reduce(
|
|
2296
|
+
(map, { name, inputPath }) => {
|
|
2297
|
+
map[name] ??= [];
|
|
2298
|
+
map[name].push(inputPath);
|
|
2299
|
+
return map;
|
|
2300
|
+
},
|
|
2301
|
+
{}
|
|
2302
|
+
);
|
|
2303
|
+
const errorLines = Object.entries(namesToPaths).reduce(
|
|
2304
|
+
(lines, [name, absolutePaths]) => {
|
|
2305
|
+
if (absolutePaths.length > 1) {
|
|
2306
|
+
lines.push(`- ${name}`);
|
|
2307
|
+
absolutePaths.forEach((absolutePath) => {
|
|
2308
|
+
lines.push(` - ${relative4(config.root, absolutePath)}`);
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
return lines;
|
|
2312
|
+
},
|
|
2313
|
+
[]
|
|
2314
|
+
);
|
|
2315
|
+
if (errorLines.length > 0) {
|
|
2316
|
+
const errorContent = errorLines.join("\n");
|
|
2317
|
+
throw Error(
|
|
2318
|
+
`Multiple entrypoints with the same name detected, only one entrypoint for each name is allowed.
|
|
2319
|
+
|
|
2320
|
+
${errorContent}`
|
|
2321
|
+
);
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2312
2324
|
function getHtmlBaseOptions(document) {
|
|
2313
2325
|
const options = {};
|
|
2314
2326
|
const includeContent = document.querySelector("meta[name='manifest.include']")?.getAttribute("content");
|
|
@@ -2321,8 +2333,8 @@ function getHtmlBaseOptions(document) {
|
|
|
2321
2333
|
}
|
|
2322
2334
|
return options;
|
|
2323
2335
|
}
|
|
2324
|
-
async function getPopupEntrypoint(config,
|
|
2325
|
-
const content = await fs12.readFile(
|
|
2336
|
+
async function getPopupEntrypoint(config, { inputPath, name }) {
|
|
2337
|
+
const content = await fs12.readFile(inputPath, "utf-8");
|
|
2326
2338
|
const { document } = parseHTML2(content);
|
|
2327
2339
|
const options = getHtmlBaseOptions(document);
|
|
2328
2340
|
const title = document.querySelector("title");
|
|
@@ -2351,12 +2363,12 @@ async function getPopupEntrypoint(config, path6) {
|
|
|
2351
2363
|
type: "popup",
|
|
2352
2364
|
name: "popup",
|
|
2353
2365
|
options,
|
|
2354
|
-
inputPath
|
|
2366
|
+
inputPath,
|
|
2355
2367
|
outputDir: config.outDir
|
|
2356
2368
|
};
|
|
2357
2369
|
}
|
|
2358
|
-
async function getOptionsEntrypoint(config,
|
|
2359
|
-
const content = await fs12.readFile(
|
|
2370
|
+
async function getOptionsEntrypoint(config, { inputPath, name }) {
|
|
2371
|
+
const content = await fs12.readFile(inputPath, "utf-8");
|
|
2360
2372
|
const { document } = parseHTML2(content);
|
|
2361
2373
|
const options = getHtmlBaseOptions(document);
|
|
2362
2374
|
const openInTabContent = document.querySelector("meta[name='manifest.open_in_tab']")?.getAttribute("content");
|
|
@@ -2375,25 +2387,24 @@ async function getOptionsEntrypoint(config, path6) {
|
|
|
2375
2387
|
type: "options",
|
|
2376
2388
|
name: "options",
|
|
2377
2389
|
options,
|
|
2378
|
-
inputPath
|
|
2390
|
+
inputPath,
|
|
2379
2391
|
outputDir: config.outDir
|
|
2380
2392
|
};
|
|
2381
2393
|
}
|
|
2382
|
-
async function getUnlistedPageEntrypoint(config,
|
|
2383
|
-
const content = await fs12.readFile(
|
|
2394
|
+
async function getUnlistedPageEntrypoint(config, { inputPath, name }) {
|
|
2395
|
+
const content = await fs12.readFile(inputPath, "utf-8");
|
|
2384
2396
|
const { document } = parseHTML2(content);
|
|
2385
2397
|
return {
|
|
2386
2398
|
type: "unlisted-page",
|
|
2387
|
-
name: getEntrypointName(config.entrypointsDir,
|
|
2388
|
-
inputPath
|
|
2399
|
+
name: getEntrypointName(config.entrypointsDir, inputPath),
|
|
2400
|
+
inputPath,
|
|
2389
2401
|
outputDir: config.outDir,
|
|
2390
2402
|
options: getHtmlBaseOptions(document)
|
|
2391
2403
|
};
|
|
2392
2404
|
}
|
|
2393
|
-
async function getUnlistedScriptEntrypoint(config,
|
|
2394
|
-
const name = getEntrypointName(config.entrypointsDir, path6);
|
|
2405
|
+
async function getUnlistedScriptEntrypoint(config, { inputPath, name }) {
|
|
2395
2406
|
const defaultExport = await importEntrypointFile(
|
|
2396
|
-
|
|
2407
|
+
inputPath,
|
|
2397
2408
|
config
|
|
2398
2409
|
);
|
|
2399
2410
|
if (defaultExport == null) {
|
|
@@ -2406,17 +2417,16 @@ async function getUnlistedScriptEntrypoint(config, path6) {
|
|
|
2406
2417
|
return {
|
|
2407
2418
|
type: "unlisted-script",
|
|
2408
2419
|
name,
|
|
2409
|
-
inputPath
|
|
2420
|
+
inputPath,
|
|
2410
2421
|
outputDir: config.outDir,
|
|
2411
2422
|
options
|
|
2412
2423
|
};
|
|
2413
2424
|
}
|
|
2414
|
-
async function getBackgroundEntrypoint(config,
|
|
2415
|
-
const name = "background";
|
|
2425
|
+
async function getBackgroundEntrypoint(config, { inputPath, name }) {
|
|
2416
2426
|
let options = {};
|
|
2417
|
-
if (
|
|
2427
|
+
if (inputPath !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
|
|
2418
2428
|
const defaultExport = await importEntrypointFile(
|
|
2419
|
-
|
|
2429
|
+
inputPath,
|
|
2420
2430
|
config
|
|
2421
2431
|
);
|
|
2422
2432
|
if (defaultExport == null) {
|
|
@@ -2430,7 +2440,7 @@ async function getBackgroundEntrypoint(config, path6) {
|
|
|
2430
2440
|
return {
|
|
2431
2441
|
type: "background",
|
|
2432
2442
|
name,
|
|
2433
|
-
inputPath
|
|
2443
|
+
inputPath,
|
|
2434
2444
|
outputDir: config.outDir,
|
|
2435
2445
|
options: {
|
|
2436
2446
|
...options,
|
|
@@ -2439,9 +2449,8 @@ async function getBackgroundEntrypoint(config, path6) {
|
|
|
2439
2449
|
}
|
|
2440
2450
|
};
|
|
2441
2451
|
}
|
|
2442
|
-
async function getContentScriptEntrypoint(config,
|
|
2443
|
-
const
|
|
2444
|
-
const { main: _, ...options } = await importEntrypointFile(path6, config);
|
|
2452
|
+
async function getContentScriptEntrypoint(config, { inputPath, name }) {
|
|
2453
|
+
const { main: _, ...options } = await importEntrypointFile(inputPath, config);
|
|
2445
2454
|
if (options == null) {
|
|
2446
2455
|
throw Error(
|
|
2447
2456
|
`${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
|
|
@@ -2450,7 +2459,7 @@ async function getContentScriptEntrypoint(config, path6) {
|
|
|
2450
2459
|
return {
|
|
2451
2460
|
type: "content-script",
|
|
2452
2461
|
name,
|
|
2453
|
-
inputPath
|
|
2462
|
+
inputPath,
|
|
2454
2463
|
outputDir: resolve12(config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
2455
2464
|
options
|
|
2456
2465
|
};
|
|
@@ -2489,12 +2498,10 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
2489
2498
|
"options/index.html": "options",
|
|
2490
2499
|
"*.html": "unlisted-page",
|
|
2491
2500
|
"*/index.html": "unlisted-page",
|
|
2492
|
-
"*.[jt]s": "unlisted-script",
|
|
2493
|
-
"*/index.
|
|
2501
|
+
"*.[jt]s?(x)": "unlisted-script",
|
|
2502
|
+
"*/index.[jt]s?(x)": "unlisted-script",
|
|
2494
2503
|
[`*.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
|
|
2495
|
-
[`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
|
|
2496
|
-
// Don't warn about any files in subdirectories, like CSS or JS entrypoints for HTML files or tests
|
|
2497
|
-
"*/**": "ignored"
|
|
2504
|
+
[`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
|
|
2498
2505
|
};
|
|
2499
2506
|
var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|
|
2500
2507
|
|
package/dist/cli.cjs
CHANGED
|
@@ -2415,7 +2415,7 @@ var init_execa = __esm({
|
|
|
2415
2415
|
var import_cac = __toESM(require("cac"), 1);
|
|
2416
2416
|
|
|
2417
2417
|
// package.json
|
|
2418
|
-
var version = "0.11.
|
|
2418
|
+
var version = "0.11.2";
|
|
2419
2419
|
|
|
2420
2420
|
// src/core/utils/fs.ts
|
|
2421
2421
|
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
@@ -2606,51 +2606,46 @@ var VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
|
|
|
2606
2606
|
|
|
2607
2607
|
// src/core/utils/building/find-entrypoints.ts
|
|
2608
2608
|
async function findEntrypoints(config) {
|
|
2609
|
-
const relativePaths = await (0, import_fast_glob2.default)(
|
|
2609
|
+
const relativePaths = await (0, import_fast_glob2.default)(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
|
|
2610
2610
|
cwd: config.entrypointsDir
|
|
2611
2611
|
});
|
|
2612
2612
|
relativePaths.sort();
|
|
2613
2613
|
const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
if (matchingGlob == null) {
|
|
2622
|
-
config.logger.warn(
|
|
2623
|
-
`${relativePath} does not match any known entrypoint. Known entrypoints:
|
|
2624
|
-
${JSON.stringify(
|
|
2625
|
-
PATH_GLOB_TO_TYPE_MAP,
|
|
2626
|
-
null,
|
|
2627
|
-
2
|
|
2628
|
-
)}`
|
|
2629
|
-
);
|
|
2630
|
-
return;
|
|
2631
|
-
}
|
|
2614
|
+
const entrypointInfos = relativePaths.reduce((results, relativePath) => {
|
|
2615
|
+
const inputPath = (0, import_path2.resolve)(config.entrypointsDir, relativePath);
|
|
2616
|
+
const name = getEntrypointName(config.entrypointsDir, inputPath);
|
|
2617
|
+
const matchingGlob = pathGlobs.find(
|
|
2618
|
+
(glob5) => (0, import_minimatch.minimatch)(relativePath, glob5)
|
|
2619
|
+
);
|
|
2620
|
+
if (matchingGlob) {
|
|
2632
2621
|
const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob];
|
|
2633
|
-
|
|
2634
|
-
|
|
2622
|
+
results.push({ name, inputPath, type });
|
|
2623
|
+
}
|
|
2624
|
+
return results;
|
|
2625
|
+
}, []);
|
|
2626
|
+
preventDuplicateEntrypointNames(config, entrypointInfos);
|
|
2627
|
+
let hasBackground = false;
|
|
2628
|
+
const entrypoints = await Promise.all(
|
|
2629
|
+
entrypointInfos.map(async (info) => {
|
|
2630
|
+
const { type } = info;
|
|
2635
2631
|
switch (type) {
|
|
2636
2632
|
case "popup":
|
|
2637
|
-
return await getPopupEntrypoint(config,
|
|
2633
|
+
return await getPopupEntrypoint(config, info);
|
|
2638
2634
|
case "options":
|
|
2639
|
-
return await getOptionsEntrypoint(config,
|
|
2635
|
+
return await getOptionsEntrypoint(config, info);
|
|
2640
2636
|
case "background":
|
|
2641
2637
|
hasBackground = true;
|
|
2642
|
-
return await getBackgroundEntrypoint(config,
|
|
2638
|
+
return await getBackgroundEntrypoint(config, info);
|
|
2643
2639
|
case "content-script":
|
|
2644
|
-
return await getContentScriptEntrypoint(config,
|
|
2640
|
+
return await getContentScriptEntrypoint(config, info);
|
|
2645
2641
|
case "unlisted-page":
|
|
2646
|
-
return await getUnlistedPageEntrypoint(config,
|
|
2642
|
+
return await getUnlistedPageEntrypoint(config, info);
|
|
2647
2643
|
case "unlisted-script":
|
|
2648
|
-
return await getUnlistedScriptEntrypoint(config,
|
|
2644
|
+
return await getUnlistedScriptEntrypoint(config, info);
|
|
2649
2645
|
case "content-script-style":
|
|
2650
2646
|
return {
|
|
2647
|
+
...info,
|
|
2651
2648
|
type,
|
|
2652
|
-
name: getEntrypointName(config.entrypointsDir, path10),
|
|
2653
|
-
inputPath: path10,
|
|
2654
2649
|
outputDir: (0, import_path2.resolve)(config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
2655
2650
|
options: {
|
|
2656
2651
|
include: void 0,
|
|
@@ -2659,9 +2654,8 @@ ${JSON.stringify(
|
|
|
2659
2654
|
};
|
|
2660
2655
|
default:
|
|
2661
2656
|
return {
|
|
2657
|
+
...info,
|
|
2662
2658
|
type,
|
|
2663
|
-
name: getEntrypointName(config.entrypointsDir, path10),
|
|
2664
|
-
inputPath: path10,
|
|
2665
2659
|
outputDir: config.outDir,
|
|
2666
2660
|
options: {
|
|
2667
2661
|
include: void 0,
|
|
@@ -2671,25 +2665,13 @@ ${JSON.stringify(
|
|
|
2671
2665
|
}
|
|
2672
2666
|
})
|
|
2673
2667
|
);
|
|
2674
|
-
const entrypoints = possibleEntrypoints.filter(
|
|
2675
|
-
(entry) => !!entry
|
|
2676
|
-
);
|
|
2677
|
-
const existingNames = {};
|
|
2678
|
-
entrypoints.forEach((entrypoint) => {
|
|
2679
|
-
const withSameName = existingNames[entrypoint.name];
|
|
2680
|
-
if (withSameName) {
|
|
2681
|
-
throw Error(
|
|
2682
|
-
`Multiple entrypoints with the name "${entrypoint.name}" detected, but only one is allowed: ${[
|
|
2683
|
-
(0, import_path2.relative)(config.root, withSameName.inputPath),
|
|
2684
|
-
(0, import_path2.relative)(config.root, entrypoint.inputPath)
|
|
2685
|
-
].join(", ")}`
|
|
2686
|
-
);
|
|
2687
|
-
}
|
|
2688
|
-
existingNames[entrypoint.name] = entrypoint;
|
|
2689
|
-
});
|
|
2690
2668
|
if (config.command === "serve" && !hasBackground) {
|
|
2691
2669
|
entrypoints.push(
|
|
2692
|
-
await getBackgroundEntrypoint(config,
|
|
2670
|
+
await getBackgroundEntrypoint(config, {
|
|
2671
|
+
inputPath: VIRTUAL_NOOP_BACKGROUND_MODULE_ID,
|
|
2672
|
+
name: "background",
|
|
2673
|
+
type: "background"
|
|
2674
|
+
})
|
|
2693
2675
|
);
|
|
2694
2676
|
}
|
|
2695
2677
|
config.logger.debug("All entrypoints:", entrypoints);
|
|
@@ -2712,6 +2694,36 @@ ${JSON.stringify(
|
|
|
2712
2694
|
config.logger.debug(`${config.browser} entrypoints:`, targetEntrypoints);
|
|
2713
2695
|
return targetEntrypoints;
|
|
2714
2696
|
}
|
|
2697
|
+
function preventDuplicateEntrypointNames(config, files) {
|
|
2698
|
+
const namesToPaths = files.reduce(
|
|
2699
|
+
(map, { name, inputPath }) => {
|
|
2700
|
+
map[name] ??= [];
|
|
2701
|
+
map[name].push(inputPath);
|
|
2702
|
+
return map;
|
|
2703
|
+
},
|
|
2704
|
+
{}
|
|
2705
|
+
);
|
|
2706
|
+
const errorLines = Object.entries(namesToPaths).reduce(
|
|
2707
|
+
(lines, [name, absolutePaths]) => {
|
|
2708
|
+
if (absolutePaths.length > 1) {
|
|
2709
|
+
lines.push(`- ${name}`);
|
|
2710
|
+
absolutePaths.forEach((absolutePath) => {
|
|
2711
|
+
lines.push(` - ${(0, import_path2.relative)(config.root, absolutePath)}`);
|
|
2712
|
+
});
|
|
2713
|
+
}
|
|
2714
|
+
return lines;
|
|
2715
|
+
},
|
|
2716
|
+
[]
|
|
2717
|
+
);
|
|
2718
|
+
if (errorLines.length > 0) {
|
|
2719
|
+
const errorContent = errorLines.join("\n");
|
|
2720
|
+
throw Error(
|
|
2721
|
+
`Multiple entrypoints with the same name detected, only one entrypoint for each name is allowed.
|
|
2722
|
+
|
|
2723
|
+
${errorContent}`
|
|
2724
|
+
);
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2715
2727
|
function getHtmlBaseOptions(document) {
|
|
2716
2728
|
const options = {};
|
|
2717
2729
|
const includeContent = document.querySelector("meta[name='manifest.include']")?.getAttribute("content");
|
|
@@ -2724,8 +2736,8 @@ function getHtmlBaseOptions(document) {
|
|
|
2724
2736
|
}
|
|
2725
2737
|
return options;
|
|
2726
2738
|
}
|
|
2727
|
-
async function getPopupEntrypoint(config,
|
|
2728
|
-
const content = await import_fs_extra3.default.readFile(
|
|
2739
|
+
async function getPopupEntrypoint(config, { inputPath, name }) {
|
|
2740
|
+
const content = await import_fs_extra3.default.readFile(inputPath, "utf-8");
|
|
2729
2741
|
const { document } = (0, import_linkedom.parseHTML)(content);
|
|
2730
2742
|
const options = getHtmlBaseOptions(document);
|
|
2731
2743
|
const title = document.querySelector("title");
|
|
@@ -2754,12 +2766,12 @@ async function getPopupEntrypoint(config, path10) {
|
|
|
2754
2766
|
type: "popup",
|
|
2755
2767
|
name: "popup",
|
|
2756
2768
|
options,
|
|
2757
|
-
inputPath
|
|
2769
|
+
inputPath,
|
|
2758
2770
|
outputDir: config.outDir
|
|
2759
2771
|
};
|
|
2760
2772
|
}
|
|
2761
|
-
async function getOptionsEntrypoint(config,
|
|
2762
|
-
const content = await import_fs_extra3.default.readFile(
|
|
2773
|
+
async function getOptionsEntrypoint(config, { inputPath, name }) {
|
|
2774
|
+
const content = await import_fs_extra3.default.readFile(inputPath, "utf-8");
|
|
2763
2775
|
const { document } = (0, import_linkedom.parseHTML)(content);
|
|
2764
2776
|
const options = getHtmlBaseOptions(document);
|
|
2765
2777
|
const openInTabContent = document.querySelector("meta[name='manifest.open_in_tab']")?.getAttribute("content");
|
|
@@ -2778,25 +2790,24 @@ async function getOptionsEntrypoint(config, path10) {
|
|
|
2778
2790
|
type: "options",
|
|
2779
2791
|
name: "options",
|
|
2780
2792
|
options,
|
|
2781
|
-
inputPath
|
|
2793
|
+
inputPath,
|
|
2782
2794
|
outputDir: config.outDir
|
|
2783
2795
|
};
|
|
2784
2796
|
}
|
|
2785
|
-
async function getUnlistedPageEntrypoint(config,
|
|
2786
|
-
const content = await import_fs_extra3.default.readFile(
|
|
2797
|
+
async function getUnlistedPageEntrypoint(config, { inputPath, name }) {
|
|
2798
|
+
const content = await import_fs_extra3.default.readFile(inputPath, "utf-8");
|
|
2787
2799
|
const { document } = (0, import_linkedom.parseHTML)(content);
|
|
2788
2800
|
return {
|
|
2789
2801
|
type: "unlisted-page",
|
|
2790
|
-
name: getEntrypointName(config.entrypointsDir,
|
|
2791
|
-
inputPath
|
|
2802
|
+
name: getEntrypointName(config.entrypointsDir, inputPath),
|
|
2803
|
+
inputPath,
|
|
2792
2804
|
outputDir: config.outDir,
|
|
2793
2805
|
options: getHtmlBaseOptions(document)
|
|
2794
2806
|
};
|
|
2795
2807
|
}
|
|
2796
|
-
async function getUnlistedScriptEntrypoint(config,
|
|
2797
|
-
const name = getEntrypointName(config.entrypointsDir, path10);
|
|
2808
|
+
async function getUnlistedScriptEntrypoint(config, { inputPath, name }) {
|
|
2798
2809
|
const defaultExport = await importEntrypointFile(
|
|
2799
|
-
|
|
2810
|
+
inputPath,
|
|
2800
2811
|
config
|
|
2801
2812
|
);
|
|
2802
2813
|
if (defaultExport == null) {
|
|
@@ -2809,17 +2820,16 @@ async function getUnlistedScriptEntrypoint(config, path10) {
|
|
|
2809
2820
|
return {
|
|
2810
2821
|
type: "unlisted-script",
|
|
2811
2822
|
name,
|
|
2812
|
-
inputPath
|
|
2823
|
+
inputPath,
|
|
2813
2824
|
outputDir: config.outDir,
|
|
2814
2825
|
options
|
|
2815
2826
|
};
|
|
2816
2827
|
}
|
|
2817
|
-
async function getBackgroundEntrypoint(config,
|
|
2818
|
-
const name = "background";
|
|
2828
|
+
async function getBackgroundEntrypoint(config, { inputPath, name }) {
|
|
2819
2829
|
let options = {};
|
|
2820
|
-
if (
|
|
2830
|
+
if (inputPath !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
|
|
2821
2831
|
const defaultExport = await importEntrypointFile(
|
|
2822
|
-
|
|
2832
|
+
inputPath,
|
|
2823
2833
|
config
|
|
2824
2834
|
);
|
|
2825
2835
|
if (defaultExport == null) {
|
|
@@ -2833,7 +2843,7 @@ async function getBackgroundEntrypoint(config, path10) {
|
|
|
2833
2843
|
return {
|
|
2834
2844
|
type: "background",
|
|
2835
2845
|
name,
|
|
2836
|
-
inputPath
|
|
2846
|
+
inputPath,
|
|
2837
2847
|
outputDir: config.outDir,
|
|
2838
2848
|
options: {
|
|
2839
2849
|
...options,
|
|
@@ -2842,9 +2852,8 @@ async function getBackgroundEntrypoint(config, path10) {
|
|
|
2842
2852
|
}
|
|
2843
2853
|
};
|
|
2844
2854
|
}
|
|
2845
|
-
async function getContentScriptEntrypoint(config,
|
|
2846
|
-
const
|
|
2847
|
-
const { main: _, ...options } = await importEntrypointFile(path10, config);
|
|
2855
|
+
async function getContentScriptEntrypoint(config, { inputPath, name }) {
|
|
2856
|
+
const { main: _, ...options } = await importEntrypointFile(inputPath, config);
|
|
2848
2857
|
if (options == null) {
|
|
2849
2858
|
throw Error(
|
|
2850
2859
|
`${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
|
|
@@ -2853,7 +2862,7 @@ async function getContentScriptEntrypoint(config, path10) {
|
|
|
2853
2862
|
return {
|
|
2854
2863
|
type: "content-script",
|
|
2855
2864
|
name,
|
|
2856
|
-
inputPath
|
|
2865
|
+
inputPath,
|
|
2857
2866
|
outputDir: (0, import_path2.resolve)(config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
2858
2867
|
options
|
|
2859
2868
|
};
|
|
@@ -2892,12 +2901,10 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
2892
2901
|
"options/index.html": "options",
|
|
2893
2902
|
"*.html": "unlisted-page",
|
|
2894
2903
|
"*/index.html": "unlisted-page",
|
|
2895
|
-
"*.[jt]s": "unlisted-script",
|
|
2896
|
-
"*/index.
|
|
2904
|
+
"*.[jt]s?(x)": "unlisted-script",
|
|
2905
|
+
"*/index.[jt]s?(x)": "unlisted-script",
|
|
2897
2906
|
[`*.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
|
|
2898
|
-
[`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
|
|
2899
|
-
// Don't warn about any files in subdirectories, like CSS or JS entrypoints for HTML files or tests
|
|
2900
|
-
"*/**": "ignored"
|
|
2907
|
+
[`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
|
|
2901
2908
|
};
|
|
2902
2909
|
var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|
|
2903
2910
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BackgroundDefinition, C as ContentScriptContext, a as ContentScriptDefinition } from './external-
|
|
1
|
+
import { B as BackgroundDefinition, C as ContentScriptContext, a as ContentScriptDefinition } from './external-PmmO6xnl.js';
|
|
2
2
|
import * as wxt_browser from 'wxt/browser';
|
|
3
3
|
import 'webextension-polyfill';
|
|
4
4
|
|
|
@@ -6,10 +6,14 @@ declare function defineBackground(main: () => void): BackgroundDefinition;
|
|
|
6
6
|
declare function defineBackground(definition: BackgroundDefinition): BackgroundDefinition;
|
|
7
7
|
|
|
8
8
|
type ContentScriptOverlayAlignment = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
9
|
+
/**
|
|
10
|
+
* 
|
|
11
|
+
*/
|
|
9
12
|
type ContentScriptAppendMode = 'last' | 'first' | 'replace' | 'before' | 'after' | ((anchor: Element, ui: Element) => void);
|
|
10
|
-
|
|
13
|
+
interface ContentScriptInlinePositioningOptions {
|
|
11
14
|
type: 'inline';
|
|
12
|
-
}
|
|
15
|
+
}
|
|
16
|
+
interface ContentScriptOverlayPositioningOptions {
|
|
13
17
|
type: 'overlay';
|
|
14
18
|
/**
|
|
15
19
|
* The `z-index` used on the `shadowHost`. Set to a positive number to show your UI over website
|
|
@@ -20,17 +24,26 @@ type ContentScriptPositioningOptions = {
|
|
|
20
24
|
* When using `type: "overlay"`, the mounted element is 0px by 0px in size. Alignment specifies
|
|
21
25
|
* which corner is aligned with that 0x0 pixel space.
|
|
22
26
|
*
|
|
27
|
+
* 
|
|
28
|
+
*
|
|
23
29
|
* @default "top-left"
|
|
24
30
|
*/
|
|
25
31
|
alignment?: ContentScriptOverlayAlignment;
|
|
26
|
-
}
|
|
32
|
+
}
|
|
33
|
+
interface ContentScriptModalPositioningOptions {
|
|
27
34
|
type: 'modal';
|
|
28
35
|
/**
|
|
29
36
|
* The `z-index` used on the `shadowHost`. Set to a positive number to show your UI over website
|
|
30
37
|
* content.
|
|
31
38
|
*/
|
|
32
39
|
zIndex?: number;
|
|
33
|
-
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Choose between `"inline"`, `"overlay"`, or `"modal" `types.
|
|
43
|
+
*
|
|
44
|
+
* 
|
|
45
|
+
*/
|
|
46
|
+
type ContentScriptPositioningOptions = ContentScriptInlinePositioningOptions | ContentScriptOverlayPositioningOptions | ContentScriptModalPositioningOptions;
|
|
34
47
|
interface ContentScriptAnchoredOptions {
|
|
35
48
|
/**
|
|
36
49
|
* A CSS selector, element, or function that returns one of the two. Along with `append`, the
|
|
@@ -54,7 +67,7 @@ interface ContentScriptAnchoredOptions {
|
|
|
54
67
|
* Utility for mounting content script UI's with isolated styles. Automatically removed from the DOM
|
|
55
68
|
* when the content script's context is invalidated.
|
|
56
69
|
*
|
|
57
|
-
* See https://wxt.dev/
|
|
70
|
+
* See https://wxt.dev/guide/content-script-ui.html for full documentation.
|
|
58
71
|
*
|
|
59
72
|
* @example
|
|
60
73
|
* // entrypoints/example-ui.content/index.ts
|
|
@@ -129,7 +142,7 @@ type ContentScriptUiOptions<TApp> = ContentScriptPositioningOptions & ContentScr
|
|
|
129
142
|
* set `cssInjectionMode: "ui"`, the imported CSS will be included automatically. You do not need
|
|
130
143
|
* to pass those styles in here. This is for any additional styles not in the imported CSS.
|
|
131
144
|
*
|
|
132
|
-
* See https://wxt.dev/
|
|
145
|
+
* See https://wxt.dev/guide/content-script-ui.html for more info.
|
|
133
146
|
*/
|
|
134
147
|
css?: string;
|
|
135
148
|
};
|
|
@@ -181,4 +194,4 @@ type ContentScriptIframeOptions = ContentScriptPositioningOptions & ContentScrip
|
|
|
181
194
|
|
|
182
195
|
declare function defineContentScript(definition: ContentScriptDefinition): ContentScriptDefinition;
|
|
183
196
|
|
|
184
|
-
export { ContentScriptContext, type ContentScriptIframe, type ContentScriptIframeOptions, type ContentScriptUi, type ContentScriptUiOptions, createContentScriptIframe, createContentScriptUi, defineBackground, defineContentScript };
|
|
197
|
+
export { type ContentScriptAnchoredOptions, type ContentScriptAppendMode, ContentScriptContext, type ContentScriptIframe, type ContentScriptIframeOptions, type ContentScriptInlinePositioningOptions, type ContentScriptModalPositioningOptions, type ContentScriptOverlayAlignment, type ContentScriptOverlayPositioningOptions, type ContentScriptPositioningOptions, type ContentScriptUi, type ContentScriptUiOptions, createContentScriptIframe, createContentScriptUi, defineBackground, defineContentScript };
|