wxt 0.18.4 → 0.18.6

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.
@@ -269,5 +269,6 @@ type PerBrowserOption<T> = T | PerBrowserMap<T>;
269
269
  type PerBrowserMap<T> = {
270
270
  [browser: TargetBrowser]: T;
271
271
  };
272
+ type WxtPlugin = () => void;
272
273
 
273
- export { type BackgroundDefinition as B, type ContentScriptDefinition as C, type UnlistedScriptDefinition as U, ContentScriptContext as a };
274
+ export { type BackgroundDefinition as B, type ContentScriptDefinition as C, type UnlistedScriptDefinition as U, type WxtPlugin as W, ContentScriptContext as a };
@@ -1,6 +1,6 @@
1
1
  import * as vite from 'vite';
2
2
  import { Manifest, Scripting } from 'webextension-polyfill';
3
- import { UnimportOptions } from 'unimport';
3
+ import { UnimportOptions, Import } from 'unimport';
4
4
  import { LogLevel } from 'consola';
5
5
  import { PluginVisualizerOptions } from '@aklinker1/rollup-plugin-visualizer';
6
6
  import { FSWatcher } from 'chokidar';
@@ -155,6 +155,10 @@ interface InlineConfig {
155
155
  * @default "${config.srcDir}/entrypoints"
156
156
  */
157
157
  entrypointsDir?: string;
158
+ /**
159
+ * @default "${config.srcDir}/modules"
160
+ */
161
+ modulesDir?: string;
158
162
  /**
159
163
  * A list of entrypoint names (`"popup"`, `"options"`, etc.) to build. Will speed up the build if
160
164
  * your extension has lots of entrypoints, and you don't need to build all of them to develop a
@@ -467,6 +471,12 @@ interface InlineConfig {
467
471
  * Project hooks for running logic during the build process.
468
472
  */
469
473
  hooks?: NestedHooks<WxtHooks>;
474
+ /**
475
+ * List of WXT module names to include. Can be the full package name
476
+ * ("wxt-module-analytics"), or just the suffix ("analytics" would resolve to
477
+ * "wxt-module-analytics").
478
+ */
479
+ modules?: string[];
470
480
  }
471
481
  interface InlineConfig {
472
482
  /**
@@ -734,7 +744,7 @@ interface BaseEntrypoint {
734
744
  */
735
745
  inputPath: string;
736
746
  /**
737
- * Absolute path to the entrypoint's output directory. Can be the`InternalConfg.outDir` or a
747
+ * Absolute path to the entrypoint's output directory. Can be `wxt.config.outDir` or a
738
748
  * subdirectory of it.
739
749
  */
740
750
  outputDir: string;
@@ -1059,6 +1069,13 @@ interface WxtHooks {
1059
1069
  * @param entrypoints The list of groups to build in each build step
1060
1070
  */
1061
1071
  'entrypoints:grouped': (wxt: Wxt, groups: EntrypointGroup[]) => HookResult;
1072
+ /**
1073
+ * Called when public assets are found. You can modify the `files` list by
1074
+ * reference to add or remove public files.
1075
+ * @param wxt The configured WXT object
1076
+ * @param entrypoints The list of files that will be copied into the output directory
1077
+ */
1078
+ 'build:publicAssets': (wxt: Wxt, files: ResolvedPublicFile[]) => HookResult;
1062
1079
  }
1063
1080
  interface Wxt {
1064
1081
  config: ResolvedConfig;
@@ -1091,15 +1108,31 @@ interface ResolvedConfig {
1091
1108
  root: string;
1092
1109
  srcDir: string;
1093
1110
  publicDir: string;
1111
+ /**
1112
+ * Absolute path pointing to `.wxt` directory in project root.
1113
+ * @example
1114
+ * "/path/to/project/.wxt"
1115
+ */
1094
1116
  wxtDir: string;
1095
1117
  typesDir: string;
1096
1118
  entrypointsDir: string;
1119
+ modulesDir: string;
1097
1120
  filterEntrypoints?: Set<string>;
1121
+ /**
1122
+ * Absolute path to the `.output` directory
1123
+ * @example
1124
+ * "/path/to/project/.output"
1125
+ */
1098
1126
  outBaseDir: string;
1127
+ /**
1128
+ * Absolute path to the target output directory.
1129
+ * @example
1130
+ * "/path/to/project/.output/chrome-mv3"
1131
+ */
1099
1132
  outDir: string;
1100
1133
  debug: boolean;
1101
1134
  /**
1102
- * Directory pointing to `node_modules/wxt`, wherever WXT is installed.
1135
+ * Absolute path pointing to the `node_modules/wxt` directory, wherever WXT is installed.
1103
1136
  */
1104
1137
  wxtModuleDir: string;
1105
1138
  mode: string;
@@ -1157,6 +1190,15 @@ interface ResolvedConfig {
1157
1190
  reloadCommand: string | false;
1158
1191
  };
1159
1192
  hooks: NestedHooks<WxtHooks>;
1193
+ modules: WxtModuleWithMetadata<any>[];
1194
+ /**
1195
+ * An array of string to import plugins from. These paths should be
1196
+ * resolvable by vite, and they should `export default defineWxtPlugin(...)`.
1197
+ *
1198
+ * @example
1199
+ * ["@wxt-dev/module-vue/plugin", "wxt-module-google-analytics/plugin"]
1200
+ */
1201
+ plugins: string[];
1160
1202
  }
1161
1203
  interface FsCache {
1162
1204
  set(key: string, value: string): Promise<void>;
@@ -1197,7 +1239,11 @@ interface ResolvedEslintrc {
1197
1239
  }
1198
1240
  type WxtUnimportOptions = Partial<UnimportOptions> & {
1199
1241
  /**
1200
- * When eslint is installed,
1242
+ * When using ESLint, auto-imported variables are linted as "undeclared
1243
+ * globals". This option lets you configure a base eslintrc that, when
1244
+ * extended, fixes these lint errors.
1245
+ *
1246
+ * See <https://wxt.dev/guide/key-concepts/auto-imports.html#eslint>
1201
1247
  */
1202
1248
  eslintrc?: Eslintrc;
1203
1249
  };
@@ -1240,5 +1286,47 @@ interface Dependency {
1240
1286
  name: string;
1241
1287
  version: string;
1242
1288
  }
1289
+ type WxtModuleOptions = Record<string, any>;
1290
+ type WxtModuleSetup<TOptions extends WxtModuleOptions> = (wxt: Wxt, moduleOptions?: TOptions) => void | Promise<void>;
1291
+ interface WxtModule<TOptions extends WxtModuleOptions> {
1292
+ name?: string;
1293
+ /**
1294
+ * Key for users to pass options into your module from their `wxt.config.ts` file.
1295
+ */
1296
+ configKey?: string;
1297
+ /**
1298
+ * Provide a list of imports to add to auto-imports.
1299
+ */
1300
+ imports?: Import[];
1301
+ /**
1302
+ * Alternative to adding hooks in setup function with `wxt.hooks`. Hooks are
1303
+ * added before the `setup` function is called.
1304
+ */
1305
+ hooks?: WxtHooks;
1306
+ /**
1307
+ * A custom function that can be used to setup hooks and call module-specific
1308
+ * APIs.
1309
+ */
1310
+ setup?: WxtModuleSetup<TOptions>;
1311
+ }
1312
+ interface WxtModuleWithMetadata<TOptions extends WxtModuleOptions> extends WxtModule<TOptions> {
1313
+ type: 'local' | 'node_module';
1314
+ id: string;
1315
+ }
1316
+ interface ResolvedPublicFile {
1317
+ /**
1318
+ * The absolute path to the file that will be copied to the output directory.
1319
+ * @example
1320
+ * "/path/to/any/file.css"
1321
+ */
1322
+ absoluteSrc: string;
1323
+ /**
1324
+ * The relative path in the output directory to copy the file to.
1325
+ * @example
1326
+ * "content-scripts/base-styles.css"
1327
+ */
1328
+ relativeDest: string;
1329
+ }
1330
+ type WxtPlugin = () => void;
1243
1331
 
1244
- export type { EslintGlobalsPropValue as $, PerBrowserMap as A, BuildOutput as B, ContentScriptEntrypoint as C, ResolvedPerBrowserOptions as D, ExtensionRunnerConfig as E, UserManifest as F, GenericEntrypoint as G, UserManifestFn as H, InlineConfig as I, ConfigEnv as J, WxtCommand as K, Logger as L, MainWorldContentScriptEntrypointOptions as M, WxtBuilder as N, OutputFile as O, PopupEntrypointOptions as P, WxtBuilderServer as Q, ResolvedConfig as R, SidepanelEntrypointOptions as S, TargetBrowser as T, UserConfig as U, ServerInfo as V, WxtDevServer as W, HookResult as X, Wxt as Y, FsCache as Z, ExtensionRunner as _, WxtViteConfig as a, Eslintrc as a0, ResolvedEslintrc as a1, WxtUnimportOptions as a2, WxtResolvedUnimportOptions as a3, WxtPackageManager as a4, Dependency as a5, WxtHooks as b, OutputChunk as c, OutputAsset as d, BuildStepOutput as e, ReloadContentScriptPayload as f, TargetManifestVersion as g, BaseEntrypointOptions as h, BackgroundEntrypointOptions as i, BaseContentScriptEntrypointOptions as j, IsolatedWorldContentScriptEntrypointOptions as k, OptionsEntrypointOptions as l, BaseEntrypoint as m, BackgroundEntrypoint as n, PopupEntrypoint as o, OptionsEntrypoint as p, SidepanelEntrypoint as q, Entrypoint as r, EntrypointGroup as s, OnContentScriptStopped as t, IsolatedWorldContentScriptDefinition as u, MainWorldContentScriptDefinition as v, ContentScriptDefinition as w, BackgroundDefinition as x, UnlistedScriptDefinition as y, PerBrowserOption as z };
1332
+ export type { EslintGlobalsPropValue as $, PerBrowserMap as A, BuildOutput as B, ContentScriptEntrypoint as C, ResolvedPerBrowserOptions as D, ExtensionRunnerConfig as E, UserManifest as F, GenericEntrypoint as G, UserManifestFn as H, InlineConfig as I, ConfigEnv as J, WxtCommand as K, Logger as L, MainWorldContentScriptEntrypointOptions as M, WxtBuilder as N, OutputFile as O, PopupEntrypointOptions as P, WxtBuilderServer as Q, ResolvedConfig as R, SidepanelEntrypointOptions as S, TargetBrowser as T, UserConfig as U, ServerInfo as V, WxtDevServer as W, HookResult as X, Wxt as Y, FsCache as Z, ExtensionRunner as _, WxtViteConfig as a, Eslintrc as a0, ResolvedEslintrc as a1, WxtUnimportOptions as a2, WxtResolvedUnimportOptions as a3, WxtPackageManager as a4, Dependency as a5, WxtModuleOptions as a6, WxtModuleSetup as a7, WxtModule as a8, WxtModuleWithMetadata as a9, ResolvedPublicFile as aa, WxtPlugin as ab, WxtHooks as b, OutputChunk as c, OutputAsset as d, BuildStepOutput as e, ReloadContentScriptPayload as f, TargetManifestVersion as g, BaseEntrypointOptions as h, BackgroundEntrypointOptions as i, BaseContentScriptEntrypointOptions as j, IsolatedWorldContentScriptEntrypointOptions as k, OptionsEntrypointOptions as l, BaseEntrypoint as m, BackgroundEntrypoint as n, PopupEntrypoint as o, OptionsEntrypoint as p, SidepanelEntrypoint as q, Entrypoint as r, EntrypointGroup as s, OnContentScriptStopped as t, IsolatedWorldContentScriptDefinition as u, MainWorldContentScriptDefinition as v, ContentScriptDefinition as w, BackgroundDefinition as x, UnlistedScriptDefinition as y, PerBrowserOption as z };
@@ -1,6 +1,6 @@
1
1
  import * as vite from 'vite';
2
2
  import { Manifest, Scripting } from 'webextension-polyfill';
3
- import { UnimportOptions } from 'unimport';
3
+ import { UnimportOptions, Import } from 'unimport';
4
4
  import { LogLevel } from 'consola';
5
5
  import { PluginVisualizerOptions } from '@aklinker1/rollup-plugin-visualizer';
6
6
  import { FSWatcher } from 'chokidar';
@@ -155,6 +155,10 @@ interface InlineConfig {
155
155
  * @default "${config.srcDir}/entrypoints"
156
156
  */
157
157
  entrypointsDir?: string;
158
+ /**
159
+ * @default "${config.srcDir}/modules"
160
+ */
161
+ modulesDir?: string;
158
162
  /**
159
163
  * A list of entrypoint names (`"popup"`, `"options"`, etc.) to build. Will speed up the build if
160
164
  * your extension has lots of entrypoints, and you don't need to build all of them to develop a
@@ -467,6 +471,12 @@ interface InlineConfig {
467
471
  * Project hooks for running logic during the build process.
468
472
  */
469
473
  hooks?: NestedHooks<WxtHooks>;
474
+ /**
475
+ * List of WXT module names to include. Can be the full package name
476
+ * ("wxt-module-analytics"), or just the suffix ("analytics" would resolve to
477
+ * "wxt-module-analytics").
478
+ */
479
+ modules?: string[];
470
480
  }
471
481
  interface InlineConfig {
472
482
  /**
@@ -734,7 +744,7 @@ interface BaseEntrypoint {
734
744
  */
735
745
  inputPath: string;
736
746
  /**
737
- * Absolute path to the entrypoint's output directory. Can be the`InternalConfg.outDir` or a
747
+ * Absolute path to the entrypoint's output directory. Can be `wxt.config.outDir` or a
738
748
  * subdirectory of it.
739
749
  */
740
750
  outputDir: string;
@@ -1059,6 +1069,13 @@ interface WxtHooks {
1059
1069
  * @param entrypoints The list of groups to build in each build step
1060
1070
  */
1061
1071
  'entrypoints:grouped': (wxt: Wxt, groups: EntrypointGroup[]) => HookResult;
1072
+ /**
1073
+ * Called when public assets are found. You can modify the `files` list by
1074
+ * reference to add or remove public files.
1075
+ * @param wxt The configured WXT object
1076
+ * @param entrypoints The list of files that will be copied into the output directory
1077
+ */
1078
+ 'build:publicAssets': (wxt: Wxt, files: ResolvedPublicFile[]) => HookResult;
1062
1079
  }
1063
1080
  interface Wxt {
1064
1081
  config: ResolvedConfig;
@@ -1091,15 +1108,31 @@ interface ResolvedConfig {
1091
1108
  root: string;
1092
1109
  srcDir: string;
1093
1110
  publicDir: string;
1111
+ /**
1112
+ * Absolute path pointing to `.wxt` directory in project root.
1113
+ * @example
1114
+ * "/path/to/project/.wxt"
1115
+ */
1094
1116
  wxtDir: string;
1095
1117
  typesDir: string;
1096
1118
  entrypointsDir: string;
1119
+ modulesDir: string;
1097
1120
  filterEntrypoints?: Set<string>;
1121
+ /**
1122
+ * Absolute path to the `.output` directory
1123
+ * @example
1124
+ * "/path/to/project/.output"
1125
+ */
1098
1126
  outBaseDir: string;
1127
+ /**
1128
+ * Absolute path to the target output directory.
1129
+ * @example
1130
+ * "/path/to/project/.output/chrome-mv3"
1131
+ */
1099
1132
  outDir: string;
1100
1133
  debug: boolean;
1101
1134
  /**
1102
- * Directory pointing to `node_modules/wxt`, wherever WXT is installed.
1135
+ * Absolute path pointing to the `node_modules/wxt` directory, wherever WXT is installed.
1103
1136
  */
1104
1137
  wxtModuleDir: string;
1105
1138
  mode: string;
@@ -1157,6 +1190,15 @@ interface ResolvedConfig {
1157
1190
  reloadCommand: string | false;
1158
1191
  };
1159
1192
  hooks: NestedHooks<WxtHooks>;
1193
+ modules: WxtModuleWithMetadata<any>[];
1194
+ /**
1195
+ * An array of string to import plugins from. These paths should be
1196
+ * resolvable by vite, and they should `export default defineWxtPlugin(...)`.
1197
+ *
1198
+ * @example
1199
+ * ["@wxt-dev/module-vue/plugin", "wxt-module-google-analytics/plugin"]
1200
+ */
1201
+ plugins: string[];
1160
1202
  }
1161
1203
  interface FsCache {
1162
1204
  set(key: string, value: string): Promise<void>;
@@ -1197,7 +1239,11 @@ interface ResolvedEslintrc {
1197
1239
  }
1198
1240
  type WxtUnimportOptions = Partial<UnimportOptions> & {
1199
1241
  /**
1200
- * When eslint is installed,
1242
+ * When using ESLint, auto-imported variables are linted as "undeclared
1243
+ * globals". This option lets you configure a base eslintrc that, when
1244
+ * extended, fixes these lint errors.
1245
+ *
1246
+ * See <https://wxt.dev/guide/key-concepts/auto-imports.html#eslint>
1201
1247
  */
1202
1248
  eslintrc?: Eslintrc;
1203
1249
  };
@@ -1240,5 +1286,47 @@ interface Dependency {
1240
1286
  name: string;
1241
1287
  version: string;
1242
1288
  }
1289
+ type WxtModuleOptions = Record<string, any>;
1290
+ type WxtModuleSetup<TOptions extends WxtModuleOptions> = (wxt: Wxt, moduleOptions?: TOptions) => void | Promise<void>;
1291
+ interface WxtModule<TOptions extends WxtModuleOptions> {
1292
+ name?: string;
1293
+ /**
1294
+ * Key for users to pass options into your module from their `wxt.config.ts` file.
1295
+ */
1296
+ configKey?: string;
1297
+ /**
1298
+ * Provide a list of imports to add to auto-imports.
1299
+ */
1300
+ imports?: Import[];
1301
+ /**
1302
+ * Alternative to adding hooks in setup function with `wxt.hooks`. Hooks are
1303
+ * added before the `setup` function is called.
1304
+ */
1305
+ hooks?: WxtHooks;
1306
+ /**
1307
+ * A custom function that can be used to setup hooks and call module-specific
1308
+ * APIs.
1309
+ */
1310
+ setup?: WxtModuleSetup<TOptions>;
1311
+ }
1312
+ interface WxtModuleWithMetadata<TOptions extends WxtModuleOptions> extends WxtModule<TOptions> {
1313
+ type: 'local' | 'node_module';
1314
+ id: string;
1315
+ }
1316
+ interface ResolvedPublicFile {
1317
+ /**
1318
+ * The absolute path to the file that will be copied to the output directory.
1319
+ * @example
1320
+ * "/path/to/any/file.css"
1321
+ */
1322
+ absoluteSrc: string;
1323
+ /**
1324
+ * The relative path in the output directory to copy the file to.
1325
+ * @example
1326
+ * "content-scripts/base-styles.css"
1327
+ */
1328
+ relativeDest: string;
1329
+ }
1330
+ type WxtPlugin = () => void;
1243
1331
 
1244
- export type { EslintGlobalsPropValue as $, PerBrowserMap as A, BuildOutput as B, ContentScriptEntrypoint as C, ResolvedPerBrowserOptions as D, ExtensionRunnerConfig as E, UserManifest as F, GenericEntrypoint as G, UserManifestFn as H, InlineConfig as I, ConfigEnv as J, WxtCommand as K, Logger as L, MainWorldContentScriptEntrypointOptions as M, WxtBuilder as N, OutputFile as O, PopupEntrypointOptions as P, WxtBuilderServer as Q, ResolvedConfig as R, SidepanelEntrypointOptions as S, TargetBrowser as T, UserConfig as U, ServerInfo as V, WxtDevServer as W, HookResult as X, Wxt as Y, FsCache as Z, ExtensionRunner as _, WxtViteConfig as a, Eslintrc as a0, ResolvedEslintrc as a1, WxtUnimportOptions as a2, WxtResolvedUnimportOptions as a3, WxtPackageManager as a4, Dependency as a5, WxtHooks as b, OutputChunk as c, OutputAsset as d, BuildStepOutput as e, ReloadContentScriptPayload as f, TargetManifestVersion as g, BaseEntrypointOptions as h, BackgroundEntrypointOptions as i, BaseContentScriptEntrypointOptions as j, IsolatedWorldContentScriptEntrypointOptions as k, OptionsEntrypointOptions as l, BaseEntrypoint as m, BackgroundEntrypoint as n, PopupEntrypoint as o, OptionsEntrypoint as p, SidepanelEntrypoint as q, Entrypoint as r, EntrypointGroup as s, OnContentScriptStopped as t, IsolatedWorldContentScriptDefinition as u, MainWorldContentScriptDefinition as v, ContentScriptDefinition as w, BackgroundDefinition as x, UnlistedScriptDefinition as y, PerBrowserOption as z };
1332
+ export type { EslintGlobalsPropValue as $, PerBrowserMap as A, BuildOutput as B, ContentScriptEntrypoint as C, ResolvedPerBrowserOptions as D, ExtensionRunnerConfig as E, UserManifest as F, GenericEntrypoint as G, UserManifestFn as H, InlineConfig as I, ConfigEnv as J, WxtCommand as K, Logger as L, MainWorldContentScriptEntrypointOptions as M, WxtBuilder as N, OutputFile as O, PopupEntrypointOptions as P, WxtBuilderServer as Q, ResolvedConfig as R, SidepanelEntrypointOptions as S, TargetBrowser as T, UserConfig as U, ServerInfo as V, WxtDevServer as W, HookResult as X, Wxt as Y, FsCache as Z, ExtensionRunner as _, WxtViteConfig as a, Eslintrc as a0, ResolvedEslintrc as a1, WxtUnimportOptions as a2, WxtResolvedUnimportOptions as a3, WxtPackageManager as a4, Dependency as a5, WxtModuleOptions as a6, WxtModuleSetup as a7, WxtModule as a8, WxtModuleWithMetadata as a9, ResolvedPublicFile as aa, WxtPlugin as ab, WxtHooks as b, OutputChunk as c, OutputAsset as d, BuildStepOutput as e, ReloadContentScriptPayload as f, TargetManifestVersion as g, BaseEntrypointOptions as h, BackgroundEntrypointOptions as i, BaseContentScriptEntrypointOptions as j, IsolatedWorldContentScriptEntrypointOptions as k, OptionsEntrypointOptions as l, BaseEntrypoint as m, BackgroundEntrypoint as n, PopupEntrypoint as o, OptionsEntrypoint as p, SidepanelEntrypoint as q, Entrypoint as r, EntrypointGroup as s, OnContentScriptStopped as t, IsolatedWorldContentScriptDefinition as u, MainWorldContentScriptDefinition as v, ContentScriptDefinition as w, BackgroundDefinition as x, UnlistedScriptDefinition as y, PerBrowserOption as z };