wxt 0.6.6 → 0.7.1-alpha1
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/README.md +4 -4
- package/dist/cli.cjs +104 -45
- package/dist/client.d.ts +143 -3
- package/dist/client.js +131 -12
- package/dist/index.cjs +103 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +103 -44
- package/dist/index.js.map +1 -1
- package/dist/virtual-modules/content-script-entrypoint.js +12 -7
- package/dist/virtual-modules/content-script-entrypoint.js.map +1 -1
- package/package.json +4 -2
package/dist/index.cjs
CHANGED
|
@@ -1358,13 +1358,15 @@ function getEntrypointGlobals(config, entrypointName) {
|
|
|
1358
1358
|
// src/core/utils/getInternalConfig.ts
|
|
1359
1359
|
async function getInternalConfig(inlineConfig, command) {
|
|
1360
1360
|
let userConfig = {};
|
|
1361
|
+
let userConfigMetadata;
|
|
1361
1362
|
if (inlineConfig.configFile !== false) {
|
|
1362
|
-
const
|
|
1363
|
+
const { config: loadedConfig, ...metadata } = await (0, import_c12.loadConfig)({
|
|
1363
1364
|
name: "wxt",
|
|
1364
1365
|
cwd: inlineConfig.root ?? process.cwd(),
|
|
1365
1366
|
rcFile: false
|
|
1366
1367
|
});
|
|
1367
|
-
userConfig =
|
|
1368
|
+
userConfig = loadedConfig ?? {};
|
|
1369
|
+
userConfigMetadata = metadata;
|
|
1368
1370
|
}
|
|
1369
1371
|
const mergedConfig = mergeInlineConfig(inlineConfig, userConfig);
|
|
1370
1372
|
const debug = mergedConfig.debug ?? false;
|
|
@@ -1426,7 +1428,8 @@ async function getInternalConfig(inlineConfig, command) {
|
|
|
1426
1428
|
analysis: {
|
|
1427
1429
|
enabled: mergedConfig.analysis?.enabled ?? false,
|
|
1428
1430
|
template: mergedConfig.analysis?.template ?? "treemap"
|
|
1429
|
-
}
|
|
1431
|
+
},
|
|
1432
|
+
userConfigMetadata: userConfigMetadata ?? {}
|
|
1430
1433
|
};
|
|
1431
1434
|
finalConfig.vite = (env2) => resolveInternalViteConfig(env2, mergedConfig, finalConfig);
|
|
1432
1435
|
return finalConfig;
|
|
@@ -1712,10 +1715,15 @@ async function buildSingleEntrypoint(entrypoint, config) {
|
|
|
1712
1715
|
config.outDir,
|
|
1713
1716
|
".js"
|
|
1714
1717
|
),
|
|
1715
|
-
// Output content script CSS to
|
|
1716
|
-
//
|
|
1717
|
-
|
|
1718
|
-
|
|
1718
|
+
// Output content script CSS to `content-scripts/`, but all other scripts are written to
|
|
1719
|
+
// `assets/`.
|
|
1720
|
+
assetFileNames: ({ name }) => {
|
|
1721
|
+
if (entrypoint.type === "content-script" && name?.endsWith("css")) {
|
|
1722
|
+
return `content-scripts/${entrypoint.name}.[ext]`;
|
|
1723
|
+
} else {
|
|
1724
|
+
return `assets/${entrypoint.name}.[ext]`;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1719
1727
|
}
|
|
1720
1728
|
}
|
|
1721
1729
|
},
|
|
@@ -2342,14 +2350,14 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
2342
2350
|
"lib": ["DOM", "WebWorker"],
|
|
2343
2351
|
"skipLibCheck": true,
|
|
2344
2352
|
"paths": {
|
|
2345
|
-
"@@": ["${rootPath}"],
|
|
2346
|
-
"@@/*": ["${rootPath}/*"],
|
|
2347
|
-
"~~": ["${rootPath}"],
|
|
2348
|
-
"~~/*": ["${rootPath}/*"],
|
|
2349
2353
|
"@": ["${srcPath}"],
|
|
2350
2354
|
"@/*": ["${srcPath}/*"],
|
|
2351
2355
|
"~": ["${srcPath}"],
|
|
2352
|
-
"~/*": ["${srcPath}/*"]
|
|
2356
|
+
"~/*": ["${srcPath}/*"],
|
|
2357
|
+
"@@": ["${rootPath}"],
|
|
2358
|
+
"@@/*": ["${rootPath}/*"],
|
|
2359
|
+
"~~": ["${rootPath}"],
|
|
2360
|
+
"~~/*": ["${rootPath}/*"]
|
|
2353
2361
|
}
|
|
2354
2362
|
},
|
|
2355
2363
|
"include": [
|
|
@@ -2463,6 +2471,7 @@ async function getPackageJson(config) {
|
|
|
2463
2471
|
|
|
2464
2472
|
// src/core/utils/manifest.ts
|
|
2465
2473
|
var import_immer = require("immer");
|
|
2474
|
+
var vite4 = __toESM(require("vite"), 1);
|
|
2466
2475
|
async function writeManifest(manifest, output, config) {
|
|
2467
2476
|
const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
2468
2477
|
await import_fs_extra12.default.ensureDir(config.outDir);
|
|
@@ -2477,34 +2486,37 @@ async function writeManifest(manifest, output, config) {
|
|
|
2477
2486
|
}
|
|
2478
2487
|
async function generateMainfest(entrypoints, buildOutput, config) {
|
|
2479
2488
|
const pkg = await getPackageJson(config);
|
|
2480
|
-
const
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2489
|
+
const baseManifest = {
|
|
2490
|
+
manifest_version: config.manifestVersion,
|
|
2491
|
+
name: pkg?.name,
|
|
2492
|
+
description: pkg?.description,
|
|
2493
|
+
version: pkg?.version && simplifyVersion(pkg.version),
|
|
2494
|
+
// Only add the version name to chromium and if the user hasn't specified a custom version.
|
|
2495
|
+
version_name: config.browser !== "firefox" && !config.manifest.version ? pkg?.version : void 0,
|
|
2496
|
+
short_name: pkg?.shortName,
|
|
2497
|
+
icons: discoverIcons(buildOutput)
|
|
2498
|
+
};
|
|
2499
|
+
const userManifest = config.manifest;
|
|
2500
|
+
const manifest = vite4.mergeConfig(
|
|
2501
|
+
baseManifest,
|
|
2502
|
+
userManifest
|
|
2492
2503
|
);
|
|
2493
2504
|
addEntrypoints(manifest, entrypoints, buildOutput, config);
|
|
2494
2505
|
if (config.command === "serve")
|
|
2495
2506
|
addDevModeCsp(manifest, config);
|
|
2496
2507
|
if (config.command === "serve")
|
|
2497
2508
|
addDevModePermissions(manifest, config);
|
|
2498
|
-
|
|
2509
|
+
const finalManifest = (0, import_immer.produce)(manifest, config.transformManifest);
|
|
2510
|
+
if (finalManifest.name == null)
|
|
2499
2511
|
throw Error(
|
|
2500
2512
|
"Manifest 'name' is missing. Either:\n1. Set the name in your <rootDir>/package.json\n2. Set a name via the manifest option in your wxt.config.ts"
|
|
2501
2513
|
);
|
|
2502
|
-
if (
|
|
2514
|
+
if (finalManifest.version == null) {
|
|
2503
2515
|
throw Error(
|
|
2504
2516
|
"Manifest 'version' is missing. Either:\n1. Add a version in your <rootDir>/package.json\n2. Pass the version via the manifest option in your wxt.config.ts"
|
|
2505
2517
|
);
|
|
2506
2518
|
}
|
|
2507
|
-
return
|
|
2519
|
+
return finalManifest;
|
|
2508
2520
|
}
|
|
2509
2521
|
function simplifyVersion(versionName) {
|
|
2510
2522
|
const version3 = /^((0|[1-9][0-9]{0,8})([.](0|[1-9][0-9]{0,8})){0,3}).*$/.exec(
|
|
@@ -2657,6 +2669,7 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
2657
2669
|
}
|
|
2658
2670
|
}
|
|
2659
2671
|
if (contentScripts?.length) {
|
|
2672
|
+
const cssMap = getContentScriptsCssMap(buildOutput, contentScripts);
|
|
2660
2673
|
if (config.command === "serve" && config.manifestVersion === 3) {
|
|
2661
2674
|
const hostPermissions = new Set(manifest.host_permissions ?? []);
|
|
2662
2675
|
contentScripts.forEach((script) => {
|
|
@@ -2681,7 +2694,7 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
2681
2694
|
...mapWxtOptionsToContentScript(scripts[0].options),
|
|
2682
2695
|
// TOOD: Sorting css and js arrays here so we get consistent test results... but we
|
|
2683
2696
|
// shouldn't have to. Where is the inconsistency coming from?
|
|
2684
|
-
css: getContentScriptCssFiles(scripts,
|
|
2697
|
+
css: getContentScriptCssFiles(scripts, cssMap)?.sort(),
|
|
2685
2698
|
js: scripts.map(
|
|
2686
2699
|
(entry) => getEntrypointBundlePath(entry, config.outDir, ".js")
|
|
2687
2700
|
).sort()
|
|
@@ -2692,6 +2705,15 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
2692
2705
|
manifest.content_scripts.push(...newContentScripts);
|
|
2693
2706
|
}
|
|
2694
2707
|
}
|
|
2708
|
+
const contentScriptCssResources = getContentScriptCssWebAccessibleResources(
|
|
2709
|
+
config,
|
|
2710
|
+
contentScripts,
|
|
2711
|
+
cssMap
|
|
2712
|
+
);
|
|
2713
|
+
if (contentScriptCssResources.length > 0) {
|
|
2714
|
+
manifest.web_accessible_resources ??= [];
|
|
2715
|
+
manifest.web_accessible_resources.push(...contentScriptCssResources);
|
|
2716
|
+
}
|
|
2695
2717
|
}
|
|
2696
2718
|
}
|
|
2697
2719
|
function discoverIcons(buildOutput) {
|
|
@@ -2756,20 +2778,52 @@ function addDevModePermissions(manifest, config) {
|
|
|
2756
2778
|
if (config.manifestVersion === 3)
|
|
2757
2779
|
addPermission(manifest, "scripting");
|
|
2758
2780
|
}
|
|
2759
|
-
function getContentScriptCssFiles(contentScripts,
|
|
2781
|
+
function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
|
|
2760
2782
|
const css = [];
|
|
2761
|
-
const allChunks = buildOutput.steps.flatMap((step) => step.chunks);
|
|
2762
2783
|
contentScripts.forEach((script) => {
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
if (
|
|
2767
|
-
|
|
2784
|
+
if (script.options.cssInjectionMode === "manual" || script.options.cssInjectionMode === "ui")
|
|
2785
|
+
return;
|
|
2786
|
+
const cssFile = contentScriptCssMap[script.name];
|
|
2787
|
+
if (cssFile == null)
|
|
2788
|
+
return;
|
|
2789
|
+
if (cssFile)
|
|
2790
|
+
css.push(cssFile);
|
|
2768
2791
|
});
|
|
2769
2792
|
if (css.length > 0)
|
|
2770
2793
|
return css;
|
|
2771
2794
|
return void 0;
|
|
2772
2795
|
}
|
|
2796
|
+
function getContentScriptCssWebAccessibleResources(config, contentScripts, contentScriptCssMap) {
|
|
2797
|
+
const resources = [];
|
|
2798
|
+
contentScripts.forEach((script) => {
|
|
2799
|
+
if (script.options.cssInjectionMode !== "ui")
|
|
2800
|
+
return;
|
|
2801
|
+
const cssFile = contentScriptCssMap[script.name];
|
|
2802
|
+
if (cssFile == null)
|
|
2803
|
+
return;
|
|
2804
|
+
if (config.manifestVersion === 2) {
|
|
2805
|
+
resources.push(cssFile);
|
|
2806
|
+
} else {
|
|
2807
|
+
resources.push({
|
|
2808
|
+
resources: [cssFile],
|
|
2809
|
+
matches: script.options.matches
|
|
2810
|
+
});
|
|
2811
|
+
}
|
|
2812
|
+
});
|
|
2813
|
+
return resources;
|
|
2814
|
+
}
|
|
2815
|
+
function getContentScriptsCssMap(buildOutput, scripts) {
|
|
2816
|
+
const map = {};
|
|
2817
|
+
const allChunks = buildOutput.steps.flatMap((step) => step.chunks);
|
|
2818
|
+
scripts.forEach((script) => {
|
|
2819
|
+
const relatedCss = allChunks.find(
|
|
2820
|
+
(chunk) => chunk.fileName === `content-scripts/${script.name}.css`
|
|
2821
|
+
);
|
|
2822
|
+
if (relatedCss != null)
|
|
2823
|
+
map[script.name] = relatedCss.fileName;
|
|
2824
|
+
});
|
|
2825
|
+
return map;
|
|
2826
|
+
}
|
|
2773
2827
|
function addPermission(manifest, permission) {
|
|
2774
2828
|
manifest.permissions ??= [];
|
|
2775
2829
|
if (manifest.permissions.includes(permission))
|
|
@@ -2785,7 +2839,7 @@ function addHostPermission(manifest, hostPermission) {
|
|
|
2785
2839
|
|
|
2786
2840
|
// src/core/build.ts
|
|
2787
2841
|
var import_picocolors3 = __toESM(require("picocolors"), 1);
|
|
2788
|
-
var
|
|
2842
|
+
var vite5 = __toESM(require("vite"), 1);
|
|
2789
2843
|
var import_fs_extra14 = __toESM(require("fs-extra"), 1);
|
|
2790
2844
|
|
|
2791
2845
|
// src/core/utils/groupEntrypoints.ts
|
|
@@ -4089,7 +4143,7 @@ async function buildInternal(config) {
|
|
|
4089
4143
|
const target = `${config.browser}-mv${config.manifestVersion}`;
|
|
4090
4144
|
config.logger.info(
|
|
4091
4145
|
`${verb} ${import_picocolors3.default.cyan(target)} for ${import_picocolors3.default.cyan(config.mode)} with ${import_picocolors3.default.green(
|
|
4092
|
-
`Vite ${
|
|
4146
|
+
`Vite ${vite5.version}`
|
|
4093
4147
|
)}`
|
|
4094
4148
|
);
|
|
4095
4149
|
const startTime = Date.now();
|
|
@@ -4167,7 +4221,7 @@ async function combineAnalysisStats(config) {
|
|
|
4167
4221
|
}
|
|
4168
4222
|
|
|
4169
4223
|
// src/core/server.ts
|
|
4170
|
-
var
|
|
4224
|
+
var vite6 = __toESM(require("vite"), 1);
|
|
4171
4225
|
|
|
4172
4226
|
// src/core/runners/wsl.ts
|
|
4173
4227
|
var import_node_path10 = require("path");
|
|
@@ -4312,8 +4366,8 @@ async function getServerInfo() {
|
|
|
4312
4366
|
}
|
|
4313
4367
|
async function setupServer(serverInfo, config) {
|
|
4314
4368
|
const runner = await createExtensionRunner(config);
|
|
4315
|
-
const viteServer = await
|
|
4316
|
-
|
|
4369
|
+
const viteServer = await vite6.createServer(
|
|
4370
|
+
vite6.mergeConfig(serverInfo, await config.vite(config.env))
|
|
4317
4371
|
);
|
|
4318
4372
|
const start = async () => {
|
|
4319
4373
|
await viteServer.listen(server.port);
|
|
@@ -4358,10 +4412,15 @@ function reloadContentScripts(steps, config, server) {
|
|
|
4358
4412
|
if (Array.isArray(entry) || entry.type !== "content-script")
|
|
4359
4413
|
return;
|
|
4360
4414
|
const js = [getEntrypointBundlePath(entry, config.outDir, ".js")];
|
|
4361
|
-
const
|
|
4362
|
-
const
|
|
4415
|
+
const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
|
|
4416
|
+
const css = getContentScriptCssFiles([entry], cssMap);
|
|
4363
4417
|
server.reloadContentScript({
|
|
4364
|
-
|
|
4418
|
+
allFrames: entry.options.allFrames,
|
|
4419
|
+
excludeMatches: entry.options.excludeMatches,
|
|
4420
|
+
matches: entry.options.matches,
|
|
4421
|
+
runAt: entry.options.runAt,
|
|
4422
|
+
// @ts-expect-error: Chrome accepts this, not typed in webextension-polyfill (https://developer.chrome.com/docs/extensions/reference/scripting/#type-RegisteredContentScript)
|
|
4423
|
+
world: entry.options.world,
|
|
4365
4424
|
js,
|
|
4366
4425
|
css
|
|
4367
4426
|
});
|
|
@@ -4413,7 +4472,7 @@ async function clean(root = process.cwd()) {
|
|
|
4413
4472
|
}
|
|
4414
4473
|
|
|
4415
4474
|
// package.json
|
|
4416
|
-
var version2 = "0.
|
|
4475
|
+
var version2 = "0.7.1-alpha1";
|
|
4417
4476
|
|
|
4418
4477
|
// src/core/utils/defineConfig.ts
|
|
4419
4478
|
function defineConfig(config) {
|