wxt 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/cli.cjs +73 -29
- package/dist/client.d.ts +132 -4
- package/dist/client.js +131 -12
- package/dist/index.cjs +72 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +72 -28
- 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.d.cts
CHANGED
|
@@ -14,8 +14,9 @@ import { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
|
|
|
14
14
|
declare class ContentScriptContext extends AbortController {
|
|
15
15
|
#private;
|
|
16
16
|
private readonly contentScriptName;
|
|
17
|
+
readonly options?: Omit<ContentScriptDefinition, "main"> | undefined;
|
|
17
18
|
static SCRIPT_STARTED_MESSAGE_TYPE: string;
|
|
18
|
-
constructor(contentScriptName: string);
|
|
19
|
+
constructor(contentScriptName: string, options?: Omit<ContentScriptDefinition, "main"> | undefined);
|
|
19
20
|
get isInvalid(): boolean;
|
|
20
21
|
get isValid(): boolean;
|
|
21
22
|
/**
|
|
@@ -455,7 +456,7 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
|
|
|
455
456
|
*
|
|
456
457
|
* @default "manifest"
|
|
457
458
|
*/
|
|
458
|
-
cssInjectionMode?: 'manifest' | 'manual';
|
|
459
|
+
cssInjectionMode?: 'manifest' | 'manual' | 'ui';
|
|
459
460
|
/**
|
|
460
461
|
* Main function executed when the content script is loaded.
|
|
461
462
|
*/
|
|
@@ -560,7 +561,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
|
|
|
560
561
|
*/
|
|
561
562
|
declare function clean(root?: string): Promise<void>;
|
|
562
563
|
|
|
563
|
-
var version = "0.7.
|
|
564
|
+
var version = "0.7.1";
|
|
564
565
|
|
|
565
566
|
declare function defineConfig(config: UserConfig): UserConfig;
|
|
566
567
|
|
package/dist/index.d.ts
CHANGED
|
@@ -14,8 +14,9 @@ import { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
|
|
|
14
14
|
declare class ContentScriptContext extends AbortController {
|
|
15
15
|
#private;
|
|
16
16
|
private readonly contentScriptName;
|
|
17
|
+
readonly options?: Omit<ContentScriptDefinition, "main"> | undefined;
|
|
17
18
|
static SCRIPT_STARTED_MESSAGE_TYPE: string;
|
|
18
|
-
constructor(contentScriptName: string);
|
|
19
|
+
constructor(contentScriptName: string, options?: Omit<ContentScriptDefinition, "main"> | undefined);
|
|
19
20
|
get isInvalid(): boolean;
|
|
20
21
|
get isValid(): boolean;
|
|
21
22
|
/**
|
|
@@ -455,7 +456,7 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
|
|
|
455
456
|
*
|
|
456
457
|
* @default "manifest"
|
|
457
458
|
*/
|
|
458
|
-
cssInjectionMode?: 'manifest' | 'manual';
|
|
459
|
+
cssInjectionMode?: 'manifest' | 'manual' | 'ui';
|
|
459
460
|
/**
|
|
460
461
|
* Main function executed when the content script is loaded.
|
|
461
462
|
*/
|
|
@@ -560,7 +561,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
|
|
|
560
561
|
*/
|
|
561
562
|
declare function clean(root?: string): Promise<void>;
|
|
562
563
|
|
|
563
|
-
var version = "0.7.
|
|
564
|
+
var version = "0.7.1";
|
|
564
565
|
|
|
565
566
|
declare function defineConfig(config: UserConfig): UserConfig;
|
|
566
567
|
|
package/dist/index.js
CHANGED
|
@@ -2460,6 +2460,7 @@ async function getPackageJson(config) {
|
|
|
2460
2460
|
|
|
2461
2461
|
// src/core/utils/manifest.ts
|
|
2462
2462
|
import { produce } from "immer";
|
|
2463
|
+
import * as vite4 from "vite";
|
|
2463
2464
|
async function writeManifest(manifest, output, config) {
|
|
2464
2465
|
const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
2465
2466
|
await fs12.ensureDir(config.outDir);
|
|
@@ -2474,18 +2475,20 @@ async function writeManifest(manifest, output, config) {
|
|
|
2474
2475
|
}
|
|
2475
2476
|
async function generateMainfest(entrypoints, buildOutput, config) {
|
|
2476
2477
|
const pkg = await getPackageJson(config);
|
|
2477
|
-
const
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2478
|
+
const baseManifest = {
|
|
2479
|
+
manifest_version: config.manifestVersion,
|
|
2480
|
+
name: pkg?.name,
|
|
2481
|
+
description: pkg?.description,
|
|
2482
|
+
version: pkg?.version && simplifyVersion(pkg.version),
|
|
2483
|
+
// Only add the version name to chromium and if the user hasn't specified a custom version.
|
|
2484
|
+
version_name: config.browser !== "firefox" && !config.manifest.version ? pkg?.version : void 0,
|
|
2485
|
+
short_name: pkg?.shortName,
|
|
2486
|
+
icons: discoverIcons(buildOutput)
|
|
2487
|
+
};
|
|
2488
|
+
const userManifest = config.manifest;
|
|
2489
|
+
const manifest = vite4.mergeConfig(
|
|
2490
|
+
baseManifest,
|
|
2491
|
+
userManifest
|
|
2489
2492
|
);
|
|
2490
2493
|
addEntrypoints(manifest, entrypoints, buildOutput, config);
|
|
2491
2494
|
if (config.command === "serve")
|
|
@@ -2655,6 +2658,7 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
2655
2658
|
}
|
|
2656
2659
|
}
|
|
2657
2660
|
if (contentScripts?.length) {
|
|
2661
|
+
const cssMap = getContentScriptsCssMap(buildOutput, contentScripts);
|
|
2658
2662
|
if (config.command === "serve" && config.manifestVersion === 3) {
|
|
2659
2663
|
const hostPermissions = new Set(manifest.host_permissions ?? []);
|
|
2660
2664
|
contentScripts.forEach((script) => {
|
|
@@ -2679,7 +2683,7 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
2679
2683
|
...mapWxtOptionsToContentScript(scripts[0].options),
|
|
2680
2684
|
// TOOD: Sorting css and js arrays here so we get consistent test results... but we
|
|
2681
2685
|
// shouldn't have to. Where is the inconsistency coming from?
|
|
2682
|
-
css: getContentScriptCssFiles(scripts,
|
|
2686
|
+
css: getContentScriptCssFiles(scripts, cssMap)?.sort(),
|
|
2683
2687
|
js: scripts.map(
|
|
2684
2688
|
(entry) => getEntrypointBundlePath(entry, config.outDir, ".js")
|
|
2685
2689
|
).sort()
|
|
@@ -2690,6 +2694,15 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
|
|
|
2690
2694
|
manifest.content_scripts.push(...newContentScripts);
|
|
2691
2695
|
}
|
|
2692
2696
|
}
|
|
2697
|
+
const contentScriptCssResources = getContentScriptCssWebAccessibleResources(
|
|
2698
|
+
config,
|
|
2699
|
+
contentScripts,
|
|
2700
|
+
cssMap
|
|
2701
|
+
);
|
|
2702
|
+
if (contentScriptCssResources.length > 0) {
|
|
2703
|
+
manifest.web_accessible_resources ??= [];
|
|
2704
|
+
manifest.web_accessible_resources.push(...contentScriptCssResources);
|
|
2705
|
+
}
|
|
2693
2706
|
}
|
|
2694
2707
|
}
|
|
2695
2708
|
function discoverIcons(buildOutput) {
|
|
@@ -2754,22 +2767,52 @@ function addDevModePermissions(manifest, config) {
|
|
|
2754
2767
|
if (config.manifestVersion === 3)
|
|
2755
2768
|
addPermission(manifest, "scripting");
|
|
2756
2769
|
}
|
|
2757
|
-
function getContentScriptCssFiles(contentScripts,
|
|
2770
|
+
function getContentScriptCssFiles(contentScripts, contentScriptCssMap) {
|
|
2758
2771
|
const css = [];
|
|
2759
|
-
const allChunks = buildOutput.steps.flatMap((step) => step.chunks);
|
|
2760
2772
|
contentScripts.forEach((script) => {
|
|
2761
|
-
if (script.options.cssInjectionMode === "manual")
|
|
2773
|
+
if (script.options.cssInjectionMode === "manual" || script.options.cssInjectionMode === "ui")
|
|
2762
2774
|
return;
|
|
2763
|
-
const
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
if (
|
|
2767
|
-
css.push(
|
|
2775
|
+
const cssFile = contentScriptCssMap[script.name];
|
|
2776
|
+
if (cssFile == null)
|
|
2777
|
+
return;
|
|
2778
|
+
if (cssFile)
|
|
2779
|
+
css.push(cssFile);
|
|
2768
2780
|
});
|
|
2769
2781
|
if (css.length > 0)
|
|
2770
2782
|
return css;
|
|
2771
2783
|
return void 0;
|
|
2772
2784
|
}
|
|
2785
|
+
function getContentScriptCssWebAccessibleResources(config, contentScripts, contentScriptCssMap) {
|
|
2786
|
+
const resources = [];
|
|
2787
|
+
contentScripts.forEach((script) => {
|
|
2788
|
+
if (script.options.cssInjectionMode !== "ui")
|
|
2789
|
+
return;
|
|
2790
|
+
const cssFile = contentScriptCssMap[script.name];
|
|
2791
|
+
if (cssFile == null)
|
|
2792
|
+
return;
|
|
2793
|
+
if (config.manifestVersion === 2) {
|
|
2794
|
+
resources.push(cssFile);
|
|
2795
|
+
} else {
|
|
2796
|
+
resources.push({
|
|
2797
|
+
resources: [cssFile],
|
|
2798
|
+
matches: script.options.matches
|
|
2799
|
+
});
|
|
2800
|
+
}
|
|
2801
|
+
});
|
|
2802
|
+
return resources;
|
|
2803
|
+
}
|
|
2804
|
+
function getContentScriptsCssMap(buildOutput, scripts) {
|
|
2805
|
+
const map = {};
|
|
2806
|
+
const allChunks = buildOutput.steps.flatMap((step) => step.chunks);
|
|
2807
|
+
scripts.forEach((script) => {
|
|
2808
|
+
const relatedCss = allChunks.find(
|
|
2809
|
+
(chunk) => chunk.fileName === `content-scripts/${script.name}.css`
|
|
2810
|
+
);
|
|
2811
|
+
if (relatedCss != null)
|
|
2812
|
+
map[script.name] = relatedCss.fileName;
|
|
2813
|
+
});
|
|
2814
|
+
return map;
|
|
2815
|
+
}
|
|
2773
2816
|
function addPermission(manifest, permission) {
|
|
2774
2817
|
manifest.permissions ??= [];
|
|
2775
2818
|
if (manifest.permissions.includes(permission))
|
|
@@ -2785,7 +2828,7 @@ function addHostPermission(manifest, hostPermission) {
|
|
|
2785
2828
|
|
|
2786
2829
|
// src/core/build.ts
|
|
2787
2830
|
import pc3 from "picocolors";
|
|
2788
|
-
import * as
|
|
2831
|
+
import * as vite5 from "vite";
|
|
2789
2832
|
import fs14 from "fs-extra";
|
|
2790
2833
|
|
|
2791
2834
|
// src/core/utils/groupEntrypoints.ts
|
|
@@ -4089,7 +4132,7 @@ async function buildInternal(config) {
|
|
|
4089
4132
|
const target = `${config.browser}-mv${config.manifestVersion}`;
|
|
4090
4133
|
config.logger.info(
|
|
4091
4134
|
`${verb} ${pc3.cyan(target)} for ${pc3.cyan(config.mode)} with ${pc3.green(
|
|
4092
|
-
`Vite ${
|
|
4135
|
+
`Vite ${vite5.version}`
|
|
4093
4136
|
)}`
|
|
4094
4137
|
);
|
|
4095
4138
|
const startTime = Date.now();
|
|
@@ -4167,7 +4210,7 @@ async function combineAnalysisStats(config) {
|
|
|
4167
4210
|
}
|
|
4168
4211
|
|
|
4169
4212
|
// src/core/server.ts
|
|
4170
|
-
import * as
|
|
4213
|
+
import * as vite6 from "vite";
|
|
4171
4214
|
|
|
4172
4215
|
// src/core/runners/wsl.ts
|
|
4173
4216
|
import { relative as relative5 } from "node:path";
|
|
@@ -4312,8 +4355,8 @@ async function getServerInfo() {
|
|
|
4312
4355
|
}
|
|
4313
4356
|
async function setupServer(serverInfo, config) {
|
|
4314
4357
|
const runner = await createExtensionRunner(config);
|
|
4315
|
-
const viteServer = await
|
|
4316
|
-
|
|
4358
|
+
const viteServer = await vite6.createServer(
|
|
4359
|
+
vite6.mergeConfig(serverInfo, await config.vite(config.env))
|
|
4317
4360
|
);
|
|
4318
4361
|
const start = async () => {
|
|
4319
4362
|
await viteServer.listen(server.port);
|
|
@@ -4358,7 +4401,8 @@ function reloadContentScripts(steps, config, server) {
|
|
|
4358
4401
|
if (Array.isArray(entry) || entry.type !== "content-script")
|
|
4359
4402
|
return;
|
|
4360
4403
|
const js = [getEntrypointBundlePath(entry, config.outDir, ".js")];
|
|
4361
|
-
const
|
|
4404
|
+
const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
|
|
4405
|
+
const css = getContentScriptCssFiles([entry], cssMap);
|
|
4362
4406
|
server.reloadContentScript({
|
|
4363
4407
|
allFrames: entry.options.allFrames,
|
|
4364
4408
|
excludeMatches: entry.options.excludeMatches,
|
|
@@ -4417,7 +4461,7 @@ async function clean(root = process.cwd()) {
|
|
|
4417
4461
|
}
|
|
4418
4462
|
|
|
4419
4463
|
// package.json
|
|
4420
|
-
var version2 = "0.7.
|
|
4464
|
+
var version2 = "0.7.1";
|
|
4421
4465
|
|
|
4422
4466
|
// src/core/utils/defineConfig.ts
|
|
4423
4467
|
function defineConfig(config) {
|