wxt 0.16.1 → 0.16.3

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/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ContentScriptContext } from './external-TYmXqKVq.js';
1
+ import { a as ContentScriptContext } from './index-TYmXqKVq.js';
2
2
  import 'webextension-polyfill';
3
3
 
4
4
  interface IntegratedContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
@@ -4,6 +4,8 @@ import { UnimportOptions } from 'unimport';
4
4
  import { LogLevel } from 'consola';
5
5
  import { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
6
6
  import { FSWatcher } from 'chokidar';
7
+ import { ResolvedConfig as ResolvedConfig$1 } from 'c12';
8
+ import { NestedHooks, Hookable } from 'hookable';
7
9
 
8
10
  declare class WxtLocationChangeEvent extends Event {
9
11
  readonly newUrl: URL;
@@ -266,6 +268,9 @@ interface InlineConfig {
266
268
  excludeSources?: string[];
267
269
  };
268
270
  /**
271
+ * @deprecated Use `hooks.build.manifestGenerated` to modify your manifest instead. This option
272
+ * will be removed in v1.0
273
+ *
269
274
  * Transform the final manifest before it's written to the file system. Edit the `manifest`
270
275
  * parameter directly, do not return a new object. Return values are ignored.
271
276
  *
@@ -354,6 +359,10 @@ interface InlineConfig {
354
359
  */
355
360
  reloadCommand?: string | false;
356
361
  };
362
+ /**
363
+ * Project hooks for running logic during the build process.
364
+ */
365
+ hooks?: NestedHooks<WxtHooks>;
357
366
  }
358
367
  interface InlineConfig {
359
368
  /**
@@ -800,5 +809,115 @@ interface ServerInfo {
800
809
  */
801
810
  origin: string;
802
811
  }
812
+ type HookResult = Promise<void> | void;
813
+ interface WxtHooks {
814
+ /**
815
+ * Called after WXT initialization, when the WXT instance is ready to work.
816
+ * @param wxt The configured WXT object
817
+ * @returns Promise
818
+ */
819
+ ready: (wxt: Wxt) => HookResult;
820
+ /**
821
+ * Called before the build is started in both dev mode and build mode.
822
+ *
823
+ * @param wxt The configured WXT object
824
+ */
825
+ 'build:before': (wxt: Wxt) => HookResult;
826
+ /**
827
+ * Called once the build process has finished.
828
+ * @param wxt The configured WXT object
829
+ * @param output The results of the build
830
+ */
831
+ 'build:done': (wxt: Wxt, output: Readonly<BuildOutput>) => HookResult;
832
+ /**
833
+ * Called once the manifest has been generated. Used to transform the manifest by reference before
834
+ * it is written to the output directory.
835
+ * @param wxt The configured WXT object
836
+ * @param manifest The manifest that was generated
837
+ */
838
+ 'build:manifestGenerated': (wxt: Wxt, manifest: Manifest.WebExtensionManifest) => HookResult;
839
+ /**
840
+ * Called once all entrypoints have been loaded from the `entrypointsDir`.
841
+ * @param wxt The configured WXT object
842
+ * @param entrypoints The list of entrypoints to be built
843
+ */
844
+ 'entrypoints:resolved': (wxt: Wxt, entrypoints: Entrypoint[]) => HookResult;
845
+ /**
846
+ * Called once all entrypoints have been grouped into their build groups.
847
+ * @param wxt The configured WXT object
848
+ * @param entrypoints The list of groups to build in each build step
849
+ */
850
+ 'entrypoints:grouped': (wxt: Wxt, groups: EntrypointGroup[]) => HookResult;
851
+ }
852
+ interface Wxt {
853
+ config: ResolvedConfig;
854
+ hooks: Hookable<WxtHooks>;
855
+ /**
856
+ * Alias for config.logger
857
+ */
858
+ logger: Logger;
859
+ /**
860
+ * Reload config file and update the `config` field with the result.
861
+ */
862
+ reloadConfig: () => Promise<void>;
863
+ }
864
+ interface ResolvedConfig {
865
+ root: string;
866
+ srcDir: string;
867
+ publicDir: string;
868
+ wxtDir: string;
869
+ typesDir: string;
870
+ entrypointsDir: string;
871
+ filterEntrypoints?: Set<string>;
872
+ outBaseDir: string;
873
+ outDir: string;
874
+ debug: boolean;
875
+ mode: string;
876
+ command: 'build' | 'serve';
877
+ browser: TargetBrowser;
878
+ manifestVersion: TargetManifestVersion;
879
+ env: ConfigEnv;
880
+ logger: Logger;
881
+ imports: false | Partial<UnimportOptions>;
882
+ manifest: UserManifest;
883
+ fsCache: FsCache;
884
+ server?: WxtDevServer;
885
+ runnerConfig: ResolvedConfig$1<ExtensionRunnerConfig>;
886
+ zip: {
887
+ name?: string;
888
+ artifactTemplate: string;
889
+ sourcesTemplate: string;
890
+ includeSources: string[];
891
+ excludeSources: string[];
892
+ sourcesRoot: string;
893
+ };
894
+ transformManifest: (manifest: Manifest.WebExtensionManifest) => void;
895
+ analysis: {
896
+ enabled: boolean;
897
+ template: NonNullable<PluginVisualizerOptions['template']>;
898
+ };
899
+ userConfigMetadata: Omit<ResolvedConfig$1<UserConfig>, 'config'>;
900
+ /**
901
+ * Import aliases to absolute paths.
902
+ */
903
+ alias: Record<string, string>;
904
+ experimental: {
905
+ includeBrowserPolyfill: boolean;
906
+ };
907
+ builder: WxtBuilder;
908
+ dev: {
909
+ reloadCommand: string | false;
910
+ };
911
+ hooks: Partial<WxtHooks>;
912
+ }
913
+ interface FsCache {
914
+ set(key: string, value: string): Promise<void>;
915
+ get(key: string): Promise<string | undefined>;
916
+ }
917
+ interface ExtensionRunner {
918
+ openBrowser(): Promise<void>;
919
+ closeBrowser(): Promise<void>;
920
+ }
921
+ type VirtualEntrypointType = 'content-script-main-world' | 'content-script-isolated-world' | 'background' | 'unlisted-script';
803
922
 
804
- export type { BuildOutput as B, ContentScriptEntrypoint as C, ExtensionRunnerConfig as E, GenericEntrypoint as G, InlineConfig as I, Logger as L, OutputFile as O, PopupEntrypoint as P, ServerInfo as S, TargetBrowser as T, UserConfig as U, WxtDevServer as W, WxtViteConfig as a, OutputChunk as b, OutputAsset as c, BuildStepOutput as d, TargetManifestVersion as e, BaseEntrypointOptions as f, BaseEntrypoint as g, BackgroundEntrypoint as h, OptionsEntrypoint as i, Entrypoint as j, EntrypointGroup as k, OnContentScriptStopped as l, ContentScriptDefinition as m, ContentScriptIsolatedWorldDefinition as n, ContentScriptMainWorldDefinition as o, ContentScriptBaseDefinition as p, BackgroundDefinition as q, UnlistedScriptDefinition as r, PerBrowserOption as s, ExcludableEntrypoint as t, UserManifest as u, UserManifestFn as v, ConfigEnv as w, WxtBuilder as x, WxtBuilderServer as y };
923
+ export type { Wxt as A, BuildOutput as B, ContentScriptEntrypoint as C, ExtensionRunner as D, ExtensionRunnerConfig as E, FsCache as F, GenericEntrypoint as G, HookResult as H, InlineConfig as I, Logger as L, OutputFile as O, PopupEntrypoint as P, ResolvedConfig as R, ServerInfo as S, TargetBrowser as T, UserConfig as U, VirtualEntrypointType as V, WxtDevServer as W, WxtViteConfig as a, OutputChunk as b, OutputAsset as c, BuildStepOutput as d, TargetManifestVersion as e, BaseEntrypointOptions as f, BaseEntrypoint as g, BackgroundEntrypoint as h, OptionsEntrypoint as i, Entrypoint as j, EntrypointGroup as k, OnContentScriptStopped as l, ContentScriptDefinition as m, ContentScriptIsolatedWorldDefinition as n, ContentScriptMainWorldDefinition as o, ContentScriptBaseDefinition as p, BackgroundDefinition as q, UnlistedScriptDefinition as r, PerBrowserOption as s, ExcludableEntrypoint as t, UserManifest as u, UserManifestFn as v, ConfigEnv as w, WxtBuilder as x, WxtBuilderServer as y, WxtHooks as z };
@@ -4,6 +4,8 @@ import { UnimportOptions } from 'unimport';
4
4
  import { LogLevel } from 'consola';
5
5
  import { PluginVisualizerOptions } from 'rollup-plugin-visualizer';
6
6
  import { FSWatcher } from 'chokidar';
7
+ import { ResolvedConfig as ResolvedConfig$1 } from 'c12';
8
+ import { NestedHooks, Hookable } from 'hookable';
7
9
 
8
10
  declare class WxtLocationChangeEvent extends Event {
9
11
  readonly newUrl: URL;
@@ -266,6 +268,9 @@ interface InlineConfig {
266
268
  excludeSources?: string[];
267
269
  };
268
270
  /**
271
+ * @deprecated Use `hooks.build.manifestGenerated` to modify your manifest instead. This option
272
+ * will be removed in v1.0
273
+ *
269
274
  * Transform the final manifest before it's written to the file system. Edit the `manifest`
270
275
  * parameter directly, do not return a new object. Return values are ignored.
271
276
  *
@@ -354,6 +359,10 @@ interface InlineConfig {
354
359
  */
355
360
  reloadCommand?: string | false;
356
361
  };
362
+ /**
363
+ * Project hooks for running logic during the build process.
364
+ */
365
+ hooks?: NestedHooks<WxtHooks>;
357
366
  }
358
367
  interface InlineConfig {
359
368
  /**
@@ -800,5 +809,115 @@ interface ServerInfo {
800
809
  */
801
810
  origin: string;
802
811
  }
812
+ type HookResult = Promise<void> | void;
813
+ interface WxtHooks {
814
+ /**
815
+ * Called after WXT initialization, when the WXT instance is ready to work.
816
+ * @param wxt The configured WXT object
817
+ * @returns Promise
818
+ */
819
+ ready: (wxt: Wxt) => HookResult;
820
+ /**
821
+ * Called before the build is started in both dev mode and build mode.
822
+ *
823
+ * @param wxt The configured WXT object
824
+ */
825
+ 'build:before': (wxt: Wxt) => HookResult;
826
+ /**
827
+ * Called once the build process has finished.
828
+ * @param wxt The configured WXT object
829
+ * @param output The results of the build
830
+ */
831
+ 'build:done': (wxt: Wxt, output: Readonly<BuildOutput>) => HookResult;
832
+ /**
833
+ * Called once the manifest has been generated. Used to transform the manifest by reference before
834
+ * it is written to the output directory.
835
+ * @param wxt The configured WXT object
836
+ * @param manifest The manifest that was generated
837
+ */
838
+ 'build:manifestGenerated': (wxt: Wxt, manifest: Manifest.WebExtensionManifest) => HookResult;
839
+ /**
840
+ * Called once all entrypoints have been loaded from the `entrypointsDir`.
841
+ * @param wxt The configured WXT object
842
+ * @param entrypoints The list of entrypoints to be built
843
+ */
844
+ 'entrypoints:resolved': (wxt: Wxt, entrypoints: Entrypoint[]) => HookResult;
845
+ /**
846
+ * Called once all entrypoints have been grouped into their build groups.
847
+ * @param wxt The configured WXT object
848
+ * @param entrypoints The list of groups to build in each build step
849
+ */
850
+ 'entrypoints:grouped': (wxt: Wxt, groups: EntrypointGroup[]) => HookResult;
851
+ }
852
+ interface Wxt {
853
+ config: ResolvedConfig;
854
+ hooks: Hookable<WxtHooks>;
855
+ /**
856
+ * Alias for config.logger
857
+ */
858
+ logger: Logger;
859
+ /**
860
+ * Reload config file and update the `config` field with the result.
861
+ */
862
+ reloadConfig: () => Promise<void>;
863
+ }
864
+ interface ResolvedConfig {
865
+ root: string;
866
+ srcDir: string;
867
+ publicDir: string;
868
+ wxtDir: string;
869
+ typesDir: string;
870
+ entrypointsDir: string;
871
+ filterEntrypoints?: Set<string>;
872
+ outBaseDir: string;
873
+ outDir: string;
874
+ debug: boolean;
875
+ mode: string;
876
+ command: 'build' | 'serve';
877
+ browser: TargetBrowser;
878
+ manifestVersion: TargetManifestVersion;
879
+ env: ConfigEnv;
880
+ logger: Logger;
881
+ imports: false | Partial<UnimportOptions>;
882
+ manifest: UserManifest;
883
+ fsCache: FsCache;
884
+ server?: WxtDevServer;
885
+ runnerConfig: ResolvedConfig$1<ExtensionRunnerConfig>;
886
+ zip: {
887
+ name?: string;
888
+ artifactTemplate: string;
889
+ sourcesTemplate: string;
890
+ includeSources: string[];
891
+ excludeSources: string[];
892
+ sourcesRoot: string;
893
+ };
894
+ transformManifest: (manifest: Manifest.WebExtensionManifest) => void;
895
+ analysis: {
896
+ enabled: boolean;
897
+ template: NonNullable<PluginVisualizerOptions['template']>;
898
+ };
899
+ userConfigMetadata: Omit<ResolvedConfig$1<UserConfig>, 'config'>;
900
+ /**
901
+ * Import aliases to absolute paths.
902
+ */
903
+ alias: Record<string, string>;
904
+ experimental: {
905
+ includeBrowserPolyfill: boolean;
906
+ };
907
+ builder: WxtBuilder;
908
+ dev: {
909
+ reloadCommand: string | false;
910
+ };
911
+ hooks: Partial<WxtHooks>;
912
+ }
913
+ interface FsCache {
914
+ set(key: string, value: string): Promise<void>;
915
+ get(key: string): Promise<string | undefined>;
916
+ }
917
+ interface ExtensionRunner {
918
+ openBrowser(): Promise<void>;
919
+ closeBrowser(): Promise<void>;
920
+ }
921
+ type VirtualEntrypointType = 'content-script-main-world' | 'content-script-isolated-world' | 'background' | 'unlisted-script';
803
922
 
804
- export type { BuildOutput as B, ContentScriptEntrypoint as C, ExtensionRunnerConfig as E, GenericEntrypoint as G, InlineConfig as I, Logger as L, OutputFile as O, PopupEntrypoint as P, ServerInfo as S, TargetBrowser as T, UserConfig as U, WxtDevServer as W, WxtViteConfig as a, OutputChunk as b, OutputAsset as c, BuildStepOutput as d, TargetManifestVersion as e, BaseEntrypointOptions as f, BaseEntrypoint as g, BackgroundEntrypoint as h, OptionsEntrypoint as i, Entrypoint as j, EntrypointGroup as k, OnContentScriptStopped as l, ContentScriptDefinition as m, ContentScriptIsolatedWorldDefinition as n, ContentScriptMainWorldDefinition as o, ContentScriptBaseDefinition as p, BackgroundDefinition as q, UnlistedScriptDefinition as r, PerBrowserOption as s, ExcludableEntrypoint as t, UserManifest as u, UserManifestFn as v, ConfigEnv as w, WxtBuilder as x, WxtBuilderServer as y };
923
+ export type { Wxt as A, BuildOutput as B, ContentScriptEntrypoint as C, ExtensionRunner as D, ExtensionRunnerConfig as E, FsCache as F, GenericEntrypoint as G, HookResult as H, InlineConfig as I, Logger as L, OutputFile as O, PopupEntrypoint as P, ResolvedConfig as R, ServerInfo as S, TargetBrowser as T, UserConfig as U, VirtualEntrypointType as V, WxtDevServer as W, WxtViteConfig as a, OutputChunk as b, OutputAsset as c, BuildStepOutput as d, TargetManifestVersion as e, BaseEntrypointOptions as f, BaseEntrypoint as g, BackgroundEntrypoint as h, OptionsEntrypoint as i, Entrypoint as j, EntrypointGroup as k, OnContentScriptStopped as l, ContentScriptDefinition as m, ContentScriptIsolatedWorldDefinition as n, ContentScriptMainWorldDefinition as o, ContentScriptBaseDefinition as p, BackgroundDefinition as q, UnlistedScriptDefinition as r, PerBrowserOption as s, ExcludableEntrypoint as t, UserManifest as u, UserManifestFn as v, ConfigEnv as w, WxtBuilder as x, WxtBuilderServer as y, WxtHooks as z };