wxt 0.7.1-alpha1 → 0.7.2

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
@@ -404,47 +404,47 @@ interface OptionsEntrypoint extends BaseEntrypoint {
404
404
  type Entrypoint = GenericEntrypoint | BackgroundEntrypoint | ContentScriptEntrypoint | PopupEntrypoint | OptionsEntrypoint;
405
405
  type OnContentScriptStopped = (cb: () => void) => void;
406
406
  interface ContentScriptDefinition extends ExcludableEntrypoint {
407
- matches: Manifest.ContentScript['matches'];
407
+ matches: PerBrowserOption<Manifest.ContentScript['matches']>;
408
408
  /**
409
409
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
410
410
  * @default "documentIdle"
411
411
  */
412
- runAt?: Manifest.ContentScript['run_at'];
412
+ runAt?: PerBrowserOption<Manifest.ContentScript['run_at']>;
413
413
  /**
414
414
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
415
415
  * @default false
416
416
  */
417
- matchAboutBlank?: Manifest.ContentScript['match_about_blank'];
417
+ matchAboutBlank?: PerBrowserOption<Manifest.ContentScript['match_about_blank']>;
418
418
  /**
419
419
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
420
420
  * @default []
421
421
  */
422
- excludeMatches?: Manifest.ContentScript['exclude_matches'];
422
+ excludeMatches?: PerBrowserOption<Manifest.ContentScript['exclude_matches']>;
423
423
  /**
424
424
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
425
425
  * @default []
426
426
  */
427
- includeGlobs?: Manifest.ContentScript['include_globs'];
427
+ includeGlobs?: PerBrowserOption<Manifest.ContentScript['include_globs']>;
428
428
  /**
429
429
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
430
430
  * @default []
431
431
  */
432
- excludeGlobs?: Manifest.ContentScript['exclude_globs'];
432
+ excludeGlobs?: PerBrowserOption<Manifest.ContentScript['exclude_globs']>;
433
433
  /**
434
434
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
435
435
  * @default false
436
436
  */
437
- allFrames?: Manifest.ContentScript['all_frames'];
437
+ allFrames?: PerBrowserOption<Manifest.ContentScript['all_frames']>;
438
438
  /**
439
439
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
440
440
  * @default false
441
441
  */
442
- matchOriginAsFallback?: boolean;
442
+ matchOriginAsFallback?: PerBrowserOption<boolean>;
443
443
  /**
444
444
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
445
445
  * @default "ISOLATED"
446
446
  */
447
- world?: 'ISOLATED' | 'MAIN';
447
+ world?: PerBrowserOption<'ISOLATED' | 'MAIN'>;
448
448
  /**
449
449
  * Customize how imported/generated styles are injected with the content script. Regardless of the
450
450
  * mode selected, CSS will always be built and included in the output directory.
@@ -456,16 +456,20 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
456
456
  *
457
457
  * @default "manifest"
458
458
  */
459
- cssInjectionMode?: 'manifest' | 'manual' | 'ui';
459
+ cssInjectionMode?: PerBrowserOption<'manifest' | 'manual' | 'ui'>;
460
460
  /**
461
461
  * Main function executed when the content script is loaded.
462
462
  */
463
463
  main(ctx: ContentScriptContext): void | Promise<void>;
464
464
  }
465
465
  interface BackgroundScriptDefintition extends ExcludableEntrypoint {
466
- type?: 'module';
466
+ type?: PerBrowserOption<'module'>;
467
+ persistent?: PerBrowserOption<boolean>;
467
468
  main(): void;
468
469
  }
470
+ type PerBrowserOption<T> = T | {
471
+ [browser: TargetBrowser]: T;
472
+ };
469
473
  interface ExcludableEntrypoint {
470
474
  /**
471
475
  * List of target browsers to include this entrypoint in. Defaults to being included in all
@@ -561,7 +565,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
561
565
  */
562
566
  declare function clean(root?: string): Promise<void>;
563
567
 
564
- var version = "0.7.1-alpha1";
568
+ var version = "0.7.2";
565
569
 
566
570
  declare function defineConfig(config: UserConfig): UserConfig;
567
571
 
@@ -577,4 +581,4 @@ declare function build(config: InlineConfig): Promise<BuildOutput>;
577
581
  */
578
582
  declare function createServer(config?: InlineConfig): Promise<WxtDevServer>;
579
583
 
580
- export { BackgroundEntrypoint, BackgroundScriptDefintition, BaseEntrypoint, BaseEntrypointOptions, BuildOutput, BuildStepOutput, ConfigEnv, ContentScriptDefinition, ContentScriptEntrypoint, Entrypoint, ExcludableEntrypoint, ExtensionRunnerConfig, GenericEntrypoint, InlineConfig, Logger, OnContentScriptStopped, OptionsEntrypoint, PopupEntrypoint, TargetBrowser, TargetManifestVersion, UserConfig, UserManifest, UserManifestFn, WxtDevServer, WxtInlineViteConfig, WxtViteConfig, build, clean, createServer, defineConfig, defineRunnerConfig, version };
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 };
package/dist/index.d.ts CHANGED
@@ -404,47 +404,47 @@ interface OptionsEntrypoint extends BaseEntrypoint {
404
404
  type Entrypoint = GenericEntrypoint | BackgroundEntrypoint | ContentScriptEntrypoint | PopupEntrypoint | OptionsEntrypoint;
405
405
  type OnContentScriptStopped = (cb: () => void) => void;
406
406
  interface ContentScriptDefinition extends ExcludableEntrypoint {
407
- matches: Manifest.ContentScript['matches'];
407
+ matches: PerBrowserOption<Manifest.ContentScript['matches']>;
408
408
  /**
409
409
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
410
410
  * @default "documentIdle"
411
411
  */
412
- runAt?: Manifest.ContentScript['run_at'];
412
+ runAt?: PerBrowserOption<Manifest.ContentScript['run_at']>;
413
413
  /**
414
414
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
415
415
  * @default false
416
416
  */
417
- matchAboutBlank?: Manifest.ContentScript['match_about_blank'];
417
+ matchAboutBlank?: PerBrowserOption<Manifest.ContentScript['match_about_blank']>;
418
418
  /**
419
419
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
420
420
  * @default []
421
421
  */
422
- excludeMatches?: Manifest.ContentScript['exclude_matches'];
422
+ excludeMatches?: PerBrowserOption<Manifest.ContentScript['exclude_matches']>;
423
423
  /**
424
424
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
425
425
  * @default []
426
426
  */
427
- includeGlobs?: Manifest.ContentScript['include_globs'];
427
+ includeGlobs?: PerBrowserOption<Manifest.ContentScript['include_globs']>;
428
428
  /**
429
429
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
430
430
  * @default []
431
431
  */
432
- excludeGlobs?: Manifest.ContentScript['exclude_globs'];
432
+ excludeGlobs?: PerBrowserOption<Manifest.ContentScript['exclude_globs']>;
433
433
  /**
434
434
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
435
435
  * @default false
436
436
  */
437
- allFrames?: Manifest.ContentScript['all_frames'];
437
+ allFrames?: PerBrowserOption<Manifest.ContentScript['all_frames']>;
438
438
  /**
439
439
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
440
440
  * @default false
441
441
  */
442
- matchOriginAsFallback?: boolean;
442
+ matchOriginAsFallback?: PerBrowserOption<boolean>;
443
443
  /**
444
444
  * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
445
445
  * @default "ISOLATED"
446
446
  */
447
- world?: 'ISOLATED' | 'MAIN';
447
+ world?: PerBrowserOption<'ISOLATED' | 'MAIN'>;
448
448
  /**
449
449
  * Customize how imported/generated styles are injected with the content script. Regardless of the
450
450
  * mode selected, CSS will always be built and included in the output directory.
@@ -456,16 +456,20 @@ interface ContentScriptDefinition extends ExcludableEntrypoint {
456
456
  *
457
457
  * @default "manifest"
458
458
  */
459
- cssInjectionMode?: 'manifest' | 'manual' | 'ui';
459
+ cssInjectionMode?: PerBrowserOption<'manifest' | 'manual' | 'ui'>;
460
460
  /**
461
461
  * Main function executed when the content script is loaded.
462
462
  */
463
463
  main(ctx: ContentScriptContext): void | Promise<void>;
464
464
  }
465
465
  interface BackgroundScriptDefintition extends ExcludableEntrypoint {
466
- type?: 'module';
466
+ type?: PerBrowserOption<'module'>;
467
+ persistent?: PerBrowserOption<boolean>;
467
468
  main(): void;
468
469
  }
470
+ type PerBrowserOption<T> = T | {
471
+ [browser: TargetBrowser]: T;
472
+ };
469
473
  interface ExcludableEntrypoint {
470
474
  /**
471
475
  * List of target browsers to include this entrypoint in. Defaults to being included in all
@@ -561,7 +565,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
561
565
  */
562
566
  declare function clean(root?: string): Promise<void>;
563
567
 
564
- var version = "0.7.1-alpha1";
568
+ var version = "0.7.2";
565
569
 
566
570
  declare function defineConfig(config: UserConfig): UserConfig;
567
571
 
@@ -577,4 +581,4 @@ declare function build(config: InlineConfig): Promise<BuildOutput>;
577
581
  */
578
582
  declare function createServer(config?: InlineConfig): Promise<WxtDevServer>;
579
583
 
580
- export { BackgroundEntrypoint, BackgroundScriptDefintition, BaseEntrypoint, BaseEntrypointOptions, BuildOutput, BuildStepOutput, ConfigEnv, ContentScriptDefinition, ContentScriptEntrypoint, Entrypoint, ExcludableEntrypoint, ExtensionRunnerConfig, GenericEntrypoint, InlineConfig, Logger, OnContentScriptStopped, OptionsEntrypoint, PopupEntrypoint, TargetBrowser, TargetManifestVersion, UserConfig, UserManifest, UserManifestFn, WxtDevServer, WxtInlineViteConfig, WxtViteConfig, build, clean, createServer, defineConfig, defineRunnerConfig, version };
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 };
package/dist/index.js CHANGED
@@ -940,6 +940,11 @@ function getEntrypointBundlePath(entrypoint, outDir, ext) {
940
940
  relative(outDir, getEntrypointOutputFile(entrypoint, ext))
941
941
  );
942
942
  }
943
+ function resolvePerBrowserOption(option, browser) {
944
+ if (typeof option === "object" && !Array.isArray(option))
945
+ return option[browser];
946
+ return option;
947
+ }
943
948
 
944
949
  // src/core/vite-plugins/devHtmlPrerender.ts
945
950
  import { parseHTML } from "linkedom";
@@ -1363,7 +1368,7 @@ async function getInternalConfig(inlineConfig, command) {
1363
1368
  if (debug)
1364
1369
  logger.level = LogLevels.debug;
1365
1370
  const browser = mergedConfig.browser ?? "chrome";
1366
- const manifestVersion = mergedConfig.manifestVersion ?? (browser == "firefox" ? 2 : 3);
1371
+ const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
1367
1372
  const mode = mergedConfig.mode ?? (command === "build" ? "production" : "development");
1368
1373
  const env = { browser, command, manifestVersion, mode };
1369
1374
  const root = path2.resolve(
@@ -2083,7 +2088,11 @@ async function getBackgroundEntrypoint(config, path9) {
2083
2088
  name: "background",
2084
2089
  inputPath: path9,
2085
2090
  outputDir: config.outDir,
2086
- options
2091
+ options: {
2092
+ ...options,
2093
+ type: resolvePerBrowserOption(options.type, config.browser),
2094
+ persistent: resolvePerBrowserOption(options.persistent, config.browser)
2095
+ }
2087
2096
  };
2088
2097
  }
2089
2098
  async function getContentScriptEntrypoint(config, name, path9) {
@@ -2428,17 +2437,32 @@ function hashContentScriptOptions(options) {
2428
2437
  }).sort((l, r) => l[0].localeCompare(r[0]))
2429
2438
  );
2430
2439
  }
2431
- function mapWxtOptionsToContentScript(options) {
2440
+ function mapWxtOptionsToContentScript(options, config) {
2432
2441
  return {
2433
- matches: options.matches,
2434
- all_frames: options.allFrames,
2435
- match_about_blank: options.matchAboutBlank,
2436
- exclude_globs: options.excludeGlobs,
2437
- exclude_matches: options.excludeMatches,
2438
- include_globs: options.includeGlobs,
2439
- run_at: options.runAt,
2442
+ matches: resolvePerBrowserOption(options.matches, config.browser),
2443
+ all_frames: resolvePerBrowserOption(options.allFrames, config.browser),
2444
+ match_about_blank: resolvePerBrowserOption(
2445
+ options.matchAboutBlank,
2446
+ config.browser
2447
+ ),
2448
+ exclude_globs: resolvePerBrowserOption(
2449
+ options.excludeGlobs,
2450
+ config.browser
2451
+ ),
2452
+ exclude_matches: resolvePerBrowserOption(
2453
+ options.excludeMatches,
2454
+ config.browser
2455
+ ),
2456
+ include_globs: resolvePerBrowserOption(
2457
+ options.includeGlobs,
2458
+ config.browser
2459
+ ),
2460
+ run_at: resolvePerBrowserOption(options.runAt, config.browser),
2440
2461
  // @ts-expect-error: untyped chrome options
2441
- match_origin_as_fallback: options.matchOriginAsFallback,
2462
+ match_origin_as_fallback: resolvePerBrowserOption(
2463
+ options.matchOriginAsFallback,
2464
+ config.browser
2465
+ ),
2442
2466
  world: options.world
2443
2467
  };
2444
2468
  }
@@ -2662,7 +2686,11 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
2662
2686
  if (config.command === "serve" && config.manifestVersion === 3) {
2663
2687
  const hostPermissions = new Set(manifest.host_permissions ?? []);
2664
2688
  contentScripts.forEach((script) => {
2665
- script.options.matches.forEach((matchPattern) => {
2689
+ const matches = resolvePerBrowserOption(
2690
+ script.options.matches,
2691
+ config.browser
2692
+ );
2693
+ matches.forEach((matchPattern) => {
2666
2694
  hostPermissions.add(matchPattern);
2667
2695
  });
2668
2696
  });
@@ -2680,7 +2708,7 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
2680
2708
  }, /* @__PURE__ */ new Map());
2681
2709
  const newContentScripts = Array.from(hashToEntrypointsMap.entries()).map(
2682
2710
  ([, scripts]) => ({
2683
- ...mapWxtOptionsToContentScript(scripts[0].options),
2711
+ ...mapWxtOptionsToContentScript(scripts[0].options, config),
2684
2712
  // TOOD: Sorting css and js arrays here so we get consistent test results... but we
2685
2713
  // shouldn't have to. Where is the inconsistency coming from?
2686
2714
  css: getContentScriptCssFiles(scripts, cssMap)?.sort(),
@@ -4404,12 +4432,18 @@ function reloadContentScripts(steps, config, server) {
4404
4432
  const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
4405
4433
  const css = getContentScriptCssFiles([entry], cssMap);
4406
4434
  server.reloadContentScript({
4407
- allFrames: entry.options.allFrames,
4408
- excludeMatches: entry.options.excludeMatches,
4409
- matches: entry.options.matches,
4410
- runAt: entry.options.runAt,
4435
+ allFrames: resolvePerBrowserOption(
4436
+ entry.options.allFrames,
4437
+ config.browser
4438
+ ),
4439
+ excludeMatches: resolvePerBrowserOption(
4440
+ entry.options.excludeMatches,
4441
+ config.browser
4442
+ ),
4443
+ matches: resolvePerBrowserOption(entry.options.matches, config.browser),
4444
+ runAt: resolvePerBrowserOption(entry.options.runAt, config.browser),
4411
4445
  // @ts-expect-error: Chrome accepts this, not typed in webextension-polyfill (https://developer.chrome.com/docs/extensions/reference/scripting/#type-RegisteredContentScript)
4412
- world: entry.options.world,
4446
+ world: resolvePerBrowserOption(entry.options.world, config.browser),
4413
4447
  js,
4414
4448
  css
4415
4449
  });
@@ -4461,7 +4495,7 @@ async function clean(root = process.cwd()) {
4461
4495
  }
4462
4496
 
4463
4497
  // package.json
4464
- var version2 = "0.7.1-alpha1";
4498
+ var version2 = "0.7.2";
4465
4499
 
4466
4500
  // src/core/utils/defineConfig.ts
4467
4501
  function defineConfig(config) {