wxt 0.7.4 → 0.8.0

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
@@ -391,6 +391,7 @@ interface PopupEntrypoint extends BaseEntrypoint {
391
391
  mv2Key?: 'browser_action' | 'page_action';
392
392
  defaultIcon?: Record<string, string>;
393
393
  defaultTitle?: string;
394
+ browserStyle?: boolean;
394
395
  } & BaseEntrypointOptions;
395
396
  }
396
397
  interface OptionsEntrypoint extends BaseEntrypoint {
@@ -453,6 +454,8 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
453
454
  * - `"manual"` - Exclude the CSS from the manifest. You are responsible for manually loading it
454
455
  * onto the page. Use `browser.runtime.getURL("content-scripts/<name>.css")` to get the file's
455
456
  * URL
457
+ * - `"ui"` - Exclude the CSS from the manifest. CSS will be automatically added to your UI when
458
+ * calling `createContentScriptUi`
456
459
  *
457
460
  * @default "manifest"
458
461
  */
@@ -462,11 +465,17 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
462
465
  */
463
466
  main(ctx: ContentScriptContext): void | Promise<void>;
464
467
  }
465
- interface BackgroundScriptDefintition extends ExcludableEntrypoint {
468
+ interface BackgroundDefinition extends ExcludableEntrypoint {
466
469
  type?: PerBrowserOption<'module'>;
467
470
  persistent?: PerBrowserOption<boolean>;
468
471
  main(): void;
469
472
  }
473
+ interface UnlistedScriptDefinition extends ExcludableEntrypoint {
474
+ /**
475
+ * Main function executed when the unlisted script is ran.
476
+ */
477
+ main(): void | Promise<void>;
478
+ }
470
479
  type PerBrowserOption<T> = T | {
471
480
  [browser: TargetBrowser]: T;
472
481
  };
@@ -565,7 +574,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
565
574
  */
566
575
  declare function clean(root?: string): Promise<void>;
567
576
 
568
- var version = "0.7.4";
577
+ var version = "0.8.0";
569
578
 
570
579
  declare function defineConfig(config: UserConfig): UserConfig;
571
580
 
@@ -581,4 +590,4 @@ declare function build(config: InlineConfig): Promise<BuildOutput>;
581
590
  */
582
591
  declare function createServer(config?: InlineConfig): Promise<WxtDevServer>;
583
592
 
584
- 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 };
593
+ 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
@@ -391,6 +391,7 @@ interface PopupEntrypoint extends BaseEntrypoint {
391
391
  mv2Key?: 'browser_action' | 'page_action';
392
392
  defaultIcon?: Record<string, string>;
393
393
  defaultTitle?: string;
394
+ browserStyle?: boolean;
394
395
  } & BaseEntrypointOptions;
395
396
  }
396
397
  interface OptionsEntrypoint extends BaseEntrypoint {
@@ -453,6 +454,8 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
453
454
  * - `"manual"` - Exclude the CSS from the manifest. You are responsible for manually loading it
454
455
  * onto the page. Use `browser.runtime.getURL("content-scripts/<name>.css")` to get the file's
455
456
  * URL
457
+ * - `"ui"` - Exclude the CSS from the manifest. CSS will be automatically added to your UI when
458
+ * calling `createContentScriptUi`
456
459
  *
457
460
  * @default "manifest"
458
461
  */
@@ -462,11 +465,17 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
462
465
  */
463
466
  main(ctx: ContentScriptContext): void | Promise<void>;
464
467
  }
465
- interface BackgroundScriptDefintition extends ExcludableEntrypoint {
468
+ interface BackgroundDefinition extends ExcludableEntrypoint {
466
469
  type?: PerBrowserOption<'module'>;
467
470
  persistent?: PerBrowserOption<boolean>;
468
471
  main(): void;
469
472
  }
473
+ interface UnlistedScriptDefinition extends ExcludableEntrypoint {
474
+ /**
475
+ * Main function executed when the unlisted script is ran.
476
+ */
477
+ main(): void | Promise<void>;
478
+ }
470
479
  type PerBrowserOption<T> = T | {
471
480
  [browser: TargetBrowser]: T;
472
481
  };
@@ -565,7 +574,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
565
574
  */
566
575
  declare function clean(root?: string): Promise<void>;
567
576
 
568
- var version = "0.7.4";
577
+ var version = "0.8.0";
569
578
 
570
579
  declare function defineConfig(config: UserConfig): UserConfig;
571
580
 
@@ -581,4 +590,4 @@ declare function build(config: InlineConfig): Promise<BuildOutput>;
581
590
  */
582
591
  declare function createServer(config?: InlineConfig): Promise<WxtDevServer>;
583
592
 
584
- 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 };
593
+ 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,
@@ -2084,9 +2095,13 @@ async function getPopupEntrypoint(config, path9) {
2084
2095
  );
2085
2096
  }
2086
2097
  }
2087
- const mv2KeyContent = document.querySelector("meta[name='manifest.type']")?.getAttribute("content");
2088
- if (mv2KeyContent) {
2089
- options.mv2Key = mv2KeyContent === "page_action" ? "page_action" : "browser_action";
2098
+ const mv2TypeContent = document.querySelector("meta[name='manifest.type']")?.getAttribute("content");
2099
+ if (mv2TypeContent) {
2100
+ options.mv2Key = mv2TypeContent === "page_action" ? "page_action" : "browser_action";
2101
+ }
2102
+ const browserStyleContent = document.querySelector("meta[name='manifest.browser_style']")?.getAttribute("content");
2103
+ if (browserStyleContent) {
2104
+ options.browserStyle = browserStyleContent === "true";
2090
2105
  }
2091
2106
  return {
2092
2107
  type: "popup",
@@ -2131,19 +2146,46 @@ async function getUnlistedPageEntrypoint(config, path9) {
2131
2146
  options: getHtmlBaseOptions(document)
2132
2147
  };
2133
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
+ }
2134
2170
  async function getBackgroundEntrypoint(config, path9) {
2171
+ const name = "background";
2135
2172
  let options = {};
2136
2173
  if (path9 !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
2137
- const defaultExport = await importEntrypointFile(path9, config);
2174
+ const defaultExport = await importEntrypointFile(
2175
+ path9,
2176
+ config
2177
+ );
2138
2178
  if (defaultExport == null) {
2139
- 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
+ );
2140
2182
  }
2141
2183
  const { main: _, ...moduleOptions } = defaultExport;
2142
2184
  options = moduleOptions;
2143
2185
  }
2144
2186
  return {
2145
2187
  type: "background",
2146
- name: "background",
2188
+ name,
2147
2189
  inputPath: path9,
2148
2190
  outputDir: config.outDir,
2149
2191
  options: {
@@ -2153,14 +2195,17 @@ async function getBackgroundEntrypoint(config, path9) {
2153
2195
  }
2154
2196
  };
2155
2197
  }
2156
- async function getContentScriptEntrypoint(config, name, path9) {
2198
+ async function getContentScriptEntrypoint(config, path9) {
2199
+ const name = getEntrypointName(config.entrypointsDir, path9);
2157
2200
  const { main: _, ...options } = await importEntrypointFile(path9, config);
2158
2201
  if (options == null) {
2159
- 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
+ );
2160
2205
  }
2161
2206
  return {
2162
2207
  type: "content-script",
2163
- name: getEntrypointName(config.entrypointsDir, path9),
2208
+ name,
2164
2209
  inputPath: path9,
2165
2210
  outputDir: resolve8(config.outDir, CONTENT_SCRIPT_OUT_DIR),
2166
2211
  options
@@ -2473,18 +2518,23 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
2473
2518
  };
2474
2519
 
2475
2520
  // src/core/utils/content-scripts.ts
2476
- function hashContentScriptOptions(options) {
2521
+ function hashContentScriptOptions(options, config) {
2522
+ const simplifiedOptions = mapWxtOptionsToContentScript(options, config);
2523
+ Object.keys(simplifiedOptions).forEach((key) => {
2524
+ if (simplifiedOptions[key] == null)
2525
+ delete simplifiedOptions[key];
2526
+ });
2477
2527
  const withDefaults = {
2478
- excludeGlobs: [],
2479
- excludeMatches: [],
2480
- includeGlobs: [],
2481
- matchAboutBlank: false,
2482
- matchOriginAsFallback: false,
2483
- runAt: "document_idle",
2484
- allFrames: false,
2528
+ exclude_globs: [],
2529
+ exclude_matches: [],
2530
+ include_globs: [],
2531
+ match_about_blank: false,
2532
+ run_at: "document_idle",
2533
+ all_frames: false,
2534
+ // @ts-expect-error - not in type
2535
+ match_origin_as_fallback: false,
2485
2536
  world: "ISOLATED",
2486
- // TODO: strip undefined fields from options object to improve content script grouping.
2487
- ...options
2537
+ ...simplifiedOptions
2488
2538
  };
2489
2539
  return JSON.stringify(
2490
2540
  Object.entries(withDefaults).map(([key, value]) => {
@@ -2557,13 +2607,17 @@ async function writeManifest(manifest, output, config) {
2557
2607
  }
2558
2608
  async function generateMainfest(entrypoints, buildOutput, config) {
2559
2609
  const pkg = await getPackageJson(config);
2610
+ const versionName = config.manifest.version_name ?? pkg?.version;
2611
+ const version3 = config.manifest.version ?? simplifyVersion(pkg?.version);
2560
2612
  const baseManifest = {
2561
2613
  manifest_version: config.manifestVersion,
2562
2614
  name: pkg?.name,
2563
2615
  description: pkg?.description,
2564
- version: pkg?.version && simplifyVersion(pkg.version),
2565
- // Only add the version name to chromium and if the user hasn't specified a custom version.
2566
- version_name: config.browser !== "firefox" && !config.manifest.version ? pkg?.version : void 0,
2616
+ version: version3,
2617
+ version_name: (
2618
+ // Firefox doesn't support version_name
2619
+ config.browser === "firefox" || versionName === version3 ? void 0 : versionName
2620
+ ),
2567
2621
  short_name: pkg?.shortName,
2568
2622
  icons: discoverIcons(buildOutput)
2569
2623
  };
@@ -2757,7 +2811,7 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
2757
2811
  );
2758
2812
  } else {
2759
2813
  const hashToEntrypointsMap = contentScripts.reduce((map, script) => {
2760
- const hash = hashContentScriptOptions(script.options);
2814
+ const hash = hashContentScriptOptions(script.options, config);
2761
2815
  if (map.has(hash))
2762
2816
  map.get(hash)?.push(script);
2763
2817
  else
@@ -4553,7 +4607,7 @@ async function clean(root = process.cwd()) {
4553
4607
  }
4554
4608
 
4555
4609
  // package.json
4556
- var version2 = "0.7.4";
4610
+ var version2 = "0.8.0";
4557
4611
 
4558
4612
  // src/core/utils/defineConfig.ts
4559
4613
  function defineConfig(config) {