wxt 0.7.5 → 0.8.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/dist/index.d.cts CHANGED
@@ -15,7 +15,7 @@ declare class ContentScriptContext extends AbortController {
15
15
  #private;
16
16
  private readonly contentScriptName;
17
17
  readonly options?: Omit<ContentScriptDefinition, "main"> | undefined;
18
- static SCRIPT_STARTED_MESSAGE_TYPE: string;
18
+ private static SCRIPT_STARTED_MESSAGE_TYPE;
19
19
  constructor(contentScriptName: string, options?: Omit<ContentScriptDefinition, "main"> | undefined);
20
20
  get isInvalid(): boolean;
21
21
  get isValid(): boolean;
@@ -76,6 +76,7 @@ declare class ContentScriptContext extends AbortController {
76
76
  */
77
77
  addEventListener(target: any, type: string, handler: (event: Event) => void, options?: AddEventListenerOptions): void;
78
78
  /**
79
+ * @internal
79
80
  * Abort the abort controller and execute all `onInvalidated` listeners.
80
81
  */
81
82
  notifyInvalidated(): void;
@@ -185,12 +186,12 @@ interface InlineConfig {
185
186
  *
186
187
  * Available template variables:
187
188
  *
188
- * - `{name}` - The project's name converted to kebab-case
189
- * - `{version}` - The version_name or version from the manifest
190
- * - `{browser}` - The target browser from the `--browser` CLI flag
191
- * - `{manifestVersion}` - Either "2" or "3"
189
+ * - `{{name}}` - The project's name converted to kebab-case
190
+ * - `{{version}}` - The version_name or version from the manifest
191
+ * - `{{browser}}` - The target browser from the `--browser` CLI flag
192
+ * - `{{manifestVersion}}` - Either "2" or "3"
192
193
  *
193
- * @default "{name}-{version}-{browser}.zip"
194
+ * @default "{{name}}-{{version}}-{{browser}}.zip"
194
195
  */
195
196
  artifactTemplate?: string;
196
197
  /**
@@ -198,12 +199,12 @@ interface InlineConfig {
198
199
  *
199
200
  * Available template variables:
200
201
  *
201
- * - `{name}` - The project's name converted to kebab-case
202
- * - `{version}` - The version_name or version from the manifest
203
- * - `{browser}` - The target browser from the `--browser` CLI flag
204
- * - `{manifestVersion}` - Either "2" or "3"
202
+ * - `{{name}}` - The project's name converted to kebab-case
203
+ * - `{{version}}` - The version_name or version from the manifest
204
+ * - `{{browser}}` - The target browser from the `--browser` CLI flag
205
+ * - `{{manifestVersion}}` - Either "2" or "3"
205
206
  *
206
- * @default "{name}-{version}-sources.zip"
207
+ * @default "{{name}}-{{version}}-sources.zip"
207
208
  */
208
209
  sourcesTemplate?: string;
209
210
  /**
@@ -465,11 +466,17 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
465
466
  */
466
467
  main(ctx: ContentScriptContext): void | Promise<void>;
467
468
  }
468
- interface BackgroundScriptDefintition extends ExcludableEntrypoint {
469
+ interface BackgroundDefinition extends ExcludableEntrypoint {
469
470
  type?: PerBrowserOption<'module'>;
470
471
  persistent?: PerBrowserOption<boolean>;
471
472
  main(): void;
472
473
  }
474
+ interface UnlistedScriptDefinition extends ExcludableEntrypoint {
475
+ /**
476
+ * Main function executed when the unlisted script is ran.
477
+ */
478
+ main(): void | Promise<void>;
479
+ }
473
480
  type PerBrowserOption<T> = T | {
474
481
  [browser: TargetBrowser]: T;
475
482
  };
@@ -565,23 +572,40 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
565
572
  * Remove generated/temp files from the directory.
566
573
  *
567
574
  * @param root The directory to look for generated/temp files in. Defaults to `process.cwd()`. Can be relative to `process.cwd()` or absolute.
575
+ *
576
+ * @example
577
+ * await clean();
568
578
  */
569
579
  declare function clean(root?: string): Promise<void>;
570
580
 
571
- var version = "0.7.5";
581
+ var version = "0.8.1";
572
582
 
573
583
  declare function defineConfig(config: UserConfig): UserConfig;
574
584
 
575
585
  declare function defineRunnerConfig(config: ExtensionRunnerConfig): ExtensionRunnerConfig;
576
586
 
587
+ /**
588
+ * @module wxt
589
+ */
590
+
577
591
  /**
578
592
  * Bundles the extension for production. Returns a promise of the build result.
593
+ *
594
+ * @example
595
+ * const res = await build({
596
+ * // Enter config...
597
+ * })
579
598
  */
580
599
  declare function build(config: InlineConfig): Promise<BuildOutput>;
581
600
  /**
582
- * Creates a dev server, pre-builds all the files that need to exist to load the extension, and open
583
- * the browser with the extension installed.
601
+ * Creates a dev server and pre-builds all the files that need to exist before loading the extension.
602
+ *
603
+ * @example
604
+ * const server = await wxt.createServer({
605
+ * // Enter config...
606
+ * });
607
+ * await server.start();
584
608
  */
585
609
  declare function createServer(config?: InlineConfig): Promise<WxtDevServer>;
586
610
 
587
- export { BackgroundEntrypoint, BackgroundScriptDefintition, BaseEntrypoint, BaseEntrypointOptions, BuildOutput, BuildStepOutput, ConfigEnv, ContentScriptDefinition, ContentScriptEntrypoint, Entrypoint, ExcludableEntrypoint, ExtensionRunnerConfig, GenericEntrypoint, InlineConfig, Logger, OnContentScriptStopped, OptionsEntrypoint, PerBrowserOption, PopupEntrypoint, TargetBrowser, TargetManifestVersion, UserConfig, UserManifest, UserManifestFn, WxtDevServer, WxtInlineViteConfig, WxtViteConfig, build, clean, createServer, defineConfig, defineRunnerConfig, version };
611
+ export { BackgroundDefinition, BackgroundEntrypoint, BaseEntrypoint, BaseEntrypointOptions, BuildOutput, BuildStepOutput, ConfigEnv, ContentScriptDefinition, ContentScriptEntrypoint, Entrypoint, ExcludableEntrypoint, ExtensionRunnerConfig, GenericEntrypoint, InlineConfig, Logger, OnContentScriptStopped, OptionsEntrypoint, PerBrowserOption, PopupEntrypoint, TargetBrowser, TargetManifestVersion, UnlistedScriptDefinition, UserConfig, UserManifest, UserManifestFn, WxtDevServer, WxtInlineViteConfig, WxtViteConfig, build, clean, createServer, defineConfig, defineRunnerConfig, version };
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ declare class ContentScriptContext extends AbortController {
15
15
  #private;
16
16
  private readonly contentScriptName;
17
17
  readonly options?: Omit<ContentScriptDefinition, "main"> | undefined;
18
- static SCRIPT_STARTED_MESSAGE_TYPE: string;
18
+ private static SCRIPT_STARTED_MESSAGE_TYPE;
19
19
  constructor(contentScriptName: string, options?: Omit<ContentScriptDefinition, "main"> | undefined);
20
20
  get isInvalid(): boolean;
21
21
  get isValid(): boolean;
@@ -76,6 +76,7 @@ declare class ContentScriptContext extends AbortController {
76
76
  */
77
77
  addEventListener(target: any, type: string, handler: (event: Event) => void, options?: AddEventListenerOptions): void;
78
78
  /**
79
+ * @internal
79
80
  * Abort the abort controller and execute all `onInvalidated` listeners.
80
81
  */
81
82
  notifyInvalidated(): void;
@@ -185,12 +186,12 @@ interface InlineConfig {
185
186
  *
186
187
  * Available template variables:
187
188
  *
188
- * - `{name}` - The project's name converted to kebab-case
189
- * - `{version}` - The version_name or version from the manifest
190
- * - `{browser}` - The target browser from the `--browser` CLI flag
191
- * - `{manifestVersion}` - Either "2" or "3"
189
+ * - `{{name}}` - The project's name converted to kebab-case
190
+ * - `{{version}}` - The version_name or version from the manifest
191
+ * - `{{browser}}` - The target browser from the `--browser` CLI flag
192
+ * - `{{manifestVersion}}` - Either "2" or "3"
192
193
  *
193
- * @default "{name}-{version}-{browser}.zip"
194
+ * @default "{{name}}-{{version}}-{{browser}}.zip"
194
195
  */
195
196
  artifactTemplate?: string;
196
197
  /**
@@ -198,12 +199,12 @@ interface InlineConfig {
198
199
  *
199
200
  * Available template variables:
200
201
  *
201
- * - `{name}` - The project's name converted to kebab-case
202
- * - `{version}` - The version_name or version from the manifest
203
- * - `{browser}` - The target browser from the `--browser` CLI flag
204
- * - `{manifestVersion}` - Either "2" or "3"
202
+ * - `{{name}}` - The project's name converted to kebab-case
203
+ * - `{{version}}` - The version_name or version from the manifest
204
+ * - `{{browser}}` - The target browser from the `--browser` CLI flag
205
+ * - `{{manifestVersion}}` - Either "2" or "3"
205
206
  *
206
- * @default "{name}-{version}-sources.zip"
207
+ * @default "{{name}}-{{version}}-sources.zip"
207
208
  */
208
209
  sourcesTemplate?: string;
209
210
  /**
@@ -465,11 +466,17 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
465
466
  */
466
467
  main(ctx: ContentScriptContext): void | Promise<void>;
467
468
  }
468
- interface BackgroundScriptDefintition extends ExcludableEntrypoint {
469
+ interface BackgroundDefinition extends ExcludableEntrypoint {
469
470
  type?: PerBrowserOption<'module'>;
470
471
  persistent?: PerBrowserOption<boolean>;
471
472
  main(): void;
472
473
  }
474
+ interface UnlistedScriptDefinition extends ExcludableEntrypoint {
475
+ /**
476
+ * Main function executed when the unlisted script is ran.
477
+ */
478
+ main(): void | Promise<void>;
479
+ }
473
480
  type PerBrowserOption<T> = T | {
474
481
  [browser: TargetBrowser]: T;
475
482
  };
@@ -565,23 +572,40 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
565
572
  * Remove generated/temp files from the directory.
566
573
  *
567
574
  * @param root The directory to look for generated/temp files in. Defaults to `process.cwd()`. Can be relative to `process.cwd()` or absolute.
575
+ *
576
+ * @example
577
+ * await clean();
568
578
  */
569
579
  declare function clean(root?: string): Promise<void>;
570
580
 
571
- var version = "0.7.5";
581
+ var version = "0.8.1";
572
582
 
573
583
  declare function defineConfig(config: UserConfig): UserConfig;
574
584
 
575
585
  declare function defineRunnerConfig(config: ExtensionRunnerConfig): ExtensionRunnerConfig;
576
586
 
587
+ /**
588
+ * @module wxt
589
+ */
590
+
577
591
  /**
578
592
  * Bundles the extension for production. Returns a promise of the build result.
593
+ *
594
+ * @example
595
+ * const res = await build({
596
+ * // Enter config...
597
+ * })
579
598
  */
580
599
  declare function build(config: InlineConfig): Promise<BuildOutput>;
581
600
  /**
582
- * Creates a dev server, pre-builds all the files that need to exist to load the extension, and open
583
- * the browser with the extension installed.
601
+ * Creates a dev server and pre-builds all the files that need to exist before loading the extension.
602
+ *
603
+ * @example
604
+ * const server = await wxt.createServer({
605
+ * // Enter config...
606
+ * });
607
+ * await server.start();
584
608
  */
585
609
  declare function createServer(config?: InlineConfig): Promise<WxtDevServer>;
586
610
 
587
- export { BackgroundEntrypoint, BackgroundScriptDefintition, BaseEntrypoint, BaseEntrypointOptions, BuildOutput, BuildStepOutput, ConfigEnv, ContentScriptDefinition, ContentScriptEntrypoint, Entrypoint, ExcludableEntrypoint, ExtensionRunnerConfig, GenericEntrypoint, InlineConfig, Logger, OnContentScriptStopped, OptionsEntrypoint, PerBrowserOption, PopupEntrypoint, TargetBrowser, TargetManifestVersion, UserConfig, UserManifest, UserManifestFn, WxtDevServer, WxtInlineViteConfig, WxtViteConfig, build, clean, createServer, defineConfig, defineRunnerConfig, version };
611
+ export { BackgroundDefinition, BackgroundEntrypoint, BaseEntrypoint, BaseEntrypointOptions, BuildOutput, BuildStepOutput, ConfigEnv, ContentScriptDefinition, ContentScriptEntrypoint, Entrypoint, ExcludableEntrypoint, ExtensionRunnerConfig, GenericEntrypoint, InlineConfig, Logger, OnContentScriptStopped, OptionsEntrypoint, PerBrowserOption, PopupEntrypoint, TargetBrowser, TargetManifestVersion, UnlistedScriptDefinition, UserConfig, UserManifest, UserManifestFn, WxtDevServer, WxtInlineViteConfig, WxtViteConfig, build, clean, createServer, defineConfig, defineRunnerConfig, version };
package/dist/index.js CHANGED
@@ -1208,7 +1208,11 @@ function getUnimportOptions(config) {
1208
1208
  const defaultOptions = {
1209
1209
  debugLog: config.logger.debug,
1210
1210
  imports: [{ name: "defineConfig", from: "wxt" }],
1211
- presets: [{ package: "wxt/client" }, { package: "wxt/browser" }],
1211
+ presets: [
1212
+ { package: "wxt/client" },
1213
+ { package: "wxt/browser" },
1214
+ { package: "wxt/sandbox" }
1215
+ ],
1212
1216
  warn: config.logger.warn,
1213
1217
  dirs: ["components", "composables", "hooks", "utils"]
1214
1218
  };
@@ -1249,7 +1253,7 @@ function unimport(config) {
1249
1253
  // src/core/vite-plugins/virtualEntrypoint.ts
1250
1254
  import fs4 from "fs-extra";
1251
1255
  import { resolve as resolve5 } from "path";
1252
- function virtualEntrypoin(type, config) {
1256
+ function virtualEntrypoint(type, config) {
1253
1257
  const virtualId = `virtual:wxt-${type}?`;
1254
1258
  const resolvedVirtualId = `\0${virtualId}`;
1255
1259
  return {
@@ -1574,10 +1578,13 @@ async function resolveInternalViteConfig(env, mergedConfig, finalConfig) {
1574
1578
  internalVite.plugins.push(devHtmlPrerender(finalConfig));
1575
1579
  internalVite.plugins.push(unimport(finalConfig));
1576
1580
  internalVite.plugins.push(
1577
- virtualEntrypoin("background", finalConfig)
1581
+ virtualEntrypoint("background", finalConfig)
1578
1582
  );
1579
1583
  internalVite.plugins.push(
1580
- virtualEntrypoin("content-script", finalConfig)
1584
+ virtualEntrypoint("content-script", finalConfig)
1585
+ );
1586
+ internalVite.plugins.push(
1587
+ virtualEntrypoint("unlisted-script", finalConfig)
1581
1588
  );
1582
1589
  internalVite.plugins.push(devServerGlobals(finalConfig));
1583
1590
  internalVite.plugins.push(tsconfigPaths(finalConfig));
@@ -1742,7 +1749,11 @@ async function buildEntrypoints(groups, config, spinner) {
1742
1749
  return { publicAssets, steps };
1743
1750
  }
1744
1751
  async function buildSingleEntrypoint(entrypoint, config) {
1745
- const isVirtual = ["background", "content-script"].includes(entrypoint.type);
1752
+ const isVirtual = [
1753
+ "background",
1754
+ "content-script",
1755
+ "unlisted-script"
1756
+ ].includes(entrypoint.type);
1746
1757
  const entry = isVirtual ? `virtual:wxt-${entrypoint.type}?${entrypoint.inputPath}` : entrypoint.inputPath;
1747
1758
  const plugins = [];
1748
1759
  if (entrypoint.type === "content-script-style" || entrypoint.type === "unlisted-style") {
@@ -1881,6 +1892,7 @@ function removeImportStatements(text) {
1881
1892
  function removeProjectImportStatements(text) {
1882
1893
  const noImports = removeImportStatements(text);
1883
1894
  return `import { defineContentScript, defineBackground } from 'wxt/client';
1895
+ import { defineUnlistedScript } from 'wxt/sandbox';
1884
1896
 
1885
1897
  ${noImports}`;
1886
1898
  }
@@ -1906,7 +1918,6 @@ async function importEntrypointFile(path9, config) {
1906
1918
  cache: false,
1907
1919
  debug: config.debug,
1908
1920
  esmResolve: true,
1909
- interopDefault: true,
1910
1921
  alias: {
1911
1922
  "webextension-polyfill": resolve7(
1912
1923
  config.root,
@@ -1925,7 +1936,8 @@ async function importEntrypointFile(path9, config) {
1925
1936
  }
1926
1937
  });
1927
1938
  try {
1928
- return await jiti(path9);
1939
+ const res = await jiti(path9);
1940
+ return res.default;
1929
1941
  } catch (err) {
1930
1942
  config.logger.error(err);
1931
1943
  throw err;
@@ -1983,15 +1995,14 @@ ${JSON.stringify(
1983
1995
  hasBackground = true;
1984
1996
  break;
1985
1997
  case "content-script":
1986
- entrypoint = await getContentScriptEntrypoint(
1987
- config,
1988
- getEntrypointName(config.entrypointsDir, path9),
1989
- path9
1990
- );
1998
+ entrypoint = await getContentScriptEntrypoint(config, path9);
1991
1999
  break;
1992
2000
  case "unlisted-page":
1993
2001
  entrypoint = await getUnlistedPageEntrypoint(config, path9);
1994
2002
  break;
2003
+ case "unlisted-script":
2004
+ entrypoint = await getUnlistedScriptEntrypoint(config, path9);
2005
+ break;
1995
2006
  case "content-script-style":
1996
2007
  entrypoint = {
1997
2008
  type,
@@ -2135,19 +2146,46 @@ async function getUnlistedPageEntrypoint(config, path9) {
2135
2146
  options: getHtmlBaseOptions(document)
2136
2147
  };
2137
2148
  }
2149
+ async function getUnlistedScriptEntrypoint(config, path9) {
2150
+ const name = getEntrypointName(config.entrypointsDir, path9);
2151
+ const defaultExport = await importEntrypointFile(
2152
+ path9,
2153
+ config
2154
+ );
2155
+ if (defaultExport == null) {
2156
+ throw Error(
2157
+ `${name}: Default export not found, did you forget to call "export default defineUnlistedScript(...)"?`
2158
+ );
2159
+ }
2160
+ const { main: _, ...moduleOptions } = defaultExport;
2161
+ const options = moduleOptions;
2162
+ return {
2163
+ type: "unlisted-script",
2164
+ name,
2165
+ inputPath: path9,
2166
+ outputDir: config.outDir,
2167
+ options
2168
+ };
2169
+ }
2138
2170
  async function getBackgroundEntrypoint(config, path9) {
2171
+ const name = "background";
2139
2172
  let options = {};
2140
2173
  if (path9 !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
2141
- const defaultExport = await importEntrypointFile(path9, config);
2174
+ const defaultExport = await importEntrypointFile(
2175
+ path9,
2176
+ config
2177
+ );
2142
2178
  if (defaultExport == null) {
2143
- throw Error("Background script does not have a default export");
2179
+ throw Error(
2180
+ `${name}: Default export not found, did you forget to call "export default defineBackground(...)"?`
2181
+ );
2144
2182
  }
2145
2183
  const { main: _, ...moduleOptions } = defaultExport;
2146
2184
  options = moduleOptions;
2147
2185
  }
2148
2186
  return {
2149
2187
  type: "background",
2150
- name: "background",
2188
+ name,
2151
2189
  inputPath: path9,
2152
2190
  outputDir: config.outDir,
2153
2191
  options: {
@@ -2157,14 +2195,17 @@ async function getBackgroundEntrypoint(config, path9) {
2157
2195
  }
2158
2196
  };
2159
2197
  }
2160
- async function getContentScriptEntrypoint(config, name, path9) {
2198
+ async function getContentScriptEntrypoint(config, path9) {
2199
+ const name = getEntrypointName(config.entrypointsDir, path9);
2161
2200
  const { main: _, ...options } = await importEntrypointFile(path9, config);
2162
2201
  if (options == null) {
2163
- throw Error(`Content script ${name} does not have a default export`);
2202
+ throw Error(
2203
+ `${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
2204
+ );
2164
2205
  }
2165
2206
  return {
2166
2207
  type: "content-script",
2167
- name: getEntrypointName(config.entrypointsDir, path9),
2208
+ name,
2168
2209
  inputPath: path9,
2169
2210
  outputDir: resolve8(config.outDir, CONTENT_SCRIPT_OUT_DIR),
2170
2211
  options
@@ -2686,7 +2727,8 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
2686
2727
  );
2687
2728
  const options2 = {
2688
2729
  default_icon: popup.options.defaultIcon,
2689
- default_title: popup.options.defaultTitle
2730
+ default_title: popup.options.defaultTitle,
2731
+ browser_style: popup.options.browserStyle
2690
2732
  };
2691
2733
  if (manifest.manifest_version === 3) {
2692
2734
  manifest.action = {
@@ -4566,7 +4608,7 @@ async function clean(root = process.cwd()) {
4566
4608
  }
4567
4609
 
4568
4610
  // package.json
4569
- var version2 = "0.7.5";
4611
+ var version2 = "0.8.1";
4570
4612
 
4571
4613
  // src/core/utils/defineConfig.ts
4572
4614
  function defineConfig(config) {