wxt 0.7.3 → 0.7.5

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
  */
@@ -565,7 +568,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
565
568
  */
566
569
  declare function clean(root?: string): Promise<void>;
567
570
 
568
- var version = "0.7.3";
571
+ var version = "0.7.5";
569
572
 
570
573
  declare function defineConfig(config: UserConfig): UserConfig;
571
574
 
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
  */
@@ -565,7 +568,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
565
568
  */
566
569
  declare function clean(root?: string): Promise<void>;
567
570
 
568
- var version = "0.7.3";
571
+ var version = "0.7.5";
569
572
 
570
573
  declare function defineConfig(config: UserConfig): UserConfig;
571
574
 
package/dist/index.js CHANGED
@@ -949,62 +949,119 @@ function resolvePerBrowserOption(option, browser) {
949
949
  // src/core/vite-plugins/devHtmlPrerender.ts
950
950
  import { parseHTML } from "linkedom";
951
951
  import { dirname as dirname2, isAbsolute, relative as relative2, resolve as resolve3 } from "path";
952
+ var reactRefreshPreamble = "";
952
953
  function devHtmlPrerender(config) {
953
- return {
954
- apply: "build",
955
- name: "wxt:dev-html-prerender",
956
- config() {
957
- return {
958
- resolve: {
959
- alias: {
960
- "@wxt/reload-html": resolve3(
961
- config.root,
962
- "node_modules/wxt/dist/virtual-modules/reload-html.js"
963
- )
954
+ const htmlReloadId = "@wxt/reload-html";
955
+ const resolvedHtmlReloadId = resolve3(
956
+ config.root,
957
+ "node_modules/wxt/dist/virtual-modules/reload-html.js"
958
+ );
959
+ const virtualReactRefreshId = "@wxt/virtual-react-refresh";
960
+ const resolvedVirtualReactRefreshId = "\0" + virtualReactRefreshId;
961
+ return [
962
+ {
963
+ apply: "build",
964
+ name: "wxt:dev-html-prerender",
965
+ config() {
966
+ return {
967
+ resolve: {
968
+ alias: {
969
+ [htmlReloadId]: resolvedHtmlReloadId
970
+ }
964
971
  }
972
+ };
973
+ },
974
+ // Convert scripts like src="./main.tsx" -> src="http://localhost:3000/entrypoints/popup/main.tsx"
975
+ // before the paths are replaced with their bundled path
976
+ transform(code, id) {
977
+ const server = config.server;
978
+ if (config.command !== "serve" || server == null || !id.endsWith(".html"))
979
+ return;
980
+ const { document } = parseHTML(code);
981
+ const pointToDevServer = (querySelector, attr) => {
982
+ document.querySelectorAll(querySelector).forEach((element) => {
983
+ const src = element.getAttribute(attr);
984
+ if (!src)
985
+ return;
986
+ if (isAbsolute(src)) {
987
+ element.setAttribute(attr, server.origin + src);
988
+ } else if (src.startsWith(".")) {
989
+ const abs = resolve3(dirname2(id), src);
990
+ const pathname = relative2(config.root, abs);
991
+ element.setAttribute(attr, `${server.origin}/${pathname}`);
992
+ }
993
+ });
994
+ };
995
+ pointToDevServer("script[type=module]", "src");
996
+ pointToDevServer("link[rel=stylesheet]", "href");
997
+ const reloader = document.createElement("script");
998
+ reloader.src = htmlReloadId;
999
+ reloader.type = "module";
1000
+ document.head.appendChild(reloader);
1001
+ const newHtml = document.toString();
1002
+ config.logger.debug("transform " + id);
1003
+ config.logger.debug("Old HTML:\n" + code);
1004
+ config.logger.debug("New HTML:\n" + newHtml);
1005
+ return newHtml;
1006
+ },
1007
+ // Pass the HTML through the dev server to add dev-mode specific code
1008
+ async transformIndexHtml(html, ctx) {
1009
+ const server = config.server;
1010
+ if (config.command !== "serve" || server == null)
1011
+ return;
1012
+ const originalUrl = `${server.origin}${ctx.path}`;
1013
+ const name = getEntrypointName(config.entrypointsDir, ctx.filename);
1014
+ const url2 = `${server.origin}/${name}.html`;
1015
+ const serverHtml = await server.transformIndexHtml(
1016
+ url2,
1017
+ html,
1018
+ originalUrl
1019
+ );
1020
+ const { document } = parseHTML(serverHtml);
1021
+ const reactRefreshScript = Array.from(
1022
+ document.querySelectorAll("script[type=module]")
1023
+ ).find((script) => script.innerHTML.includes("@react-refresh"));
1024
+ if (reactRefreshScript) {
1025
+ reactRefreshPreamble = reactRefreshScript.innerHTML;
1026
+ const virtualScript = document.createElement("script");
1027
+ virtualScript.type = "module";
1028
+ virtualScript.src = `${server.origin}/${virtualReactRefreshId}`;
1029
+ reactRefreshScript.replaceWith(virtualScript);
965
1030
  }
966
- };
1031
+ const viteClientScript = document.querySelector(
1032
+ "script[src='/@vite/client']"
1033
+ );
1034
+ if (viteClientScript) {
1035
+ viteClientScript.src = `${server.origin}${viteClientScript.src}`;
1036
+ }
1037
+ const newHtml = document.toString();
1038
+ config.logger.debug("transformIndexHtml " + ctx.filename);
1039
+ config.logger.debug("Old HTML:\n" + html);
1040
+ config.logger.debug("New HTML:\n" + newHtml);
1041
+ return newHtml;
1042
+ }
967
1043
  },
968
- async transform(html, id) {
969
- const server = config.server;
970
- if (config.command !== "serve" || server == null || !id.endsWith(".html"))
971
- return;
972
- const originalUrl = `${server.origin}${id}`;
973
- const name = getEntrypointName(config.entrypointsDir, id);
974
- const url2 = `${server.origin}/${name}.html`;
975
- const serverHtml = await server.transformIndexHtml(
976
- url2,
977
- html,
978
- originalUrl
979
- );
980
- const { document } = parseHTML(serverHtml);
981
- const pointToDevServer = (querySelector, attr) => {
982
- document.querySelectorAll(querySelector).forEach((element) => {
983
- const src = element.getAttribute(attr);
984
- if (!src)
985
- return;
986
- if (isAbsolute(src)) {
987
- element.setAttribute(attr, server.origin + src);
988
- } else if (src.startsWith(".")) {
989
- const abs = resolve3(dirname2(id), src);
990
- const pathname = relative2(config.root, abs);
991
- element.setAttribute(attr, `${server.origin}/${pathname}`);
992
- }
993
- });
994
- };
995
- pointToDevServer("script[type=module]", "src");
996
- pointToDevServer("link[rel=stylesheet]", "href");
997
- const reloader = document.createElement("script");
998
- reloader.src = "@wxt/reload-html";
999
- reloader.type = "module";
1000
- document.head.appendChild(reloader);
1001
- const newHtml = document.toString();
1002
- config.logger.debug("Transformed " + id);
1003
- config.logger.debug("Old HTML:\n" + html);
1004
- config.logger.debug("New HTML:\n" + newHtml);
1005
- return newHtml;
1044
+ {
1045
+ name: "wxt:virtualize-react-refresh",
1046
+ apply: "serve",
1047
+ resolveId(id) {
1048
+ if (id === `/${virtualReactRefreshId}`) {
1049
+ return resolvedVirtualReactRefreshId;
1050
+ }
1051
+ if (id.startsWith("/chunks/")) {
1052
+ return "\0noop";
1053
+ }
1054
+ },
1055
+ load(id) {
1056
+ if (id === resolvedVirtualReactRefreshId) {
1057
+ return reactRefreshPreamble;
1058
+ }
1059
+ if (id === "\0noop") {
1060
+ return "";
1061
+ }
1062
+ }
1006
1063
  }
1007
- };
1064
+ ];
1008
1065
  }
1009
1066
 
1010
1067
  // src/core/vite-plugins/devServerGlobals.ts
@@ -2027,9 +2084,13 @@ async function getPopupEntrypoint(config, path9) {
2027
2084
  );
2028
2085
  }
2029
2086
  }
2030
- const mv2KeyContent = document.querySelector("meta[name='manifest.type']")?.getAttribute("content");
2031
- if (mv2KeyContent) {
2032
- options.mv2Key = mv2KeyContent === "page_action" ? "page_action" : "browser_action";
2087
+ const mv2TypeContent = document.querySelector("meta[name='manifest.type']")?.getAttribute("content");
2088
+ if (mv2TypeContent) {
2089
+ options.mv2Key = mv2TypeContent === "page_action" ? "page_action" : "browser_action";
2090
+ }
2091
+ const browserStyleContent = document.querySelector("meta[name='manifest.browser_style']")?.getAttribute("content");
2092
+ if (browserStyleContent) {
2093
+ options.browserStyle = browserStyleContent === "true";
2033
2094
  }
2034
2095
  return {
2035
2096
  type: "popup",
@@ -2416,18 +2477,23 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
2416
2477
  };
2417
2478
 
2418
2479
  // src/core/utils/content-scripts.ts
2419
- function hashContentScriptOptions(options) {
2480
+ function hashContentScriptOptions(options, config) {
2481
+ const simplifiedOptions = mapWxtOptionsToContentScript(options, config);
2482
+ Object.keys(simplifiedOptions).forEach((key) => {
2483
+ if (simplifiedOptions[key] == null)
2484
+ delete simplifiedOptions[key];
2485
+ });
2420
2486
  const withDefaults = {
2421
- excludeGlobs: [],
2422
- excludeMatches: [],
2423
- includeGlobs: [],
2424
- matchAboutBlank: false,
2425
- matchOriginAsFallback: false,
2426
- runAt: "document_idle",
2427
- allFrames: false,
2487
+ exclude_globs: [],
2488
+ exclude_matches: [],
2489
+ include_globs: [],
2490
+ match_about_blank: false,
2491
+ run_at: "document_idle",
2492
+ all_frames: false,
2493
+ // @ts-expect-error - not in type
2494
+ match_origin_as_fallback: false,
2428
2495
  world: "ISOLATED",
2429
- // TODO: strip undefined fields from options object to improve content script grouping.
2430
- ...options
2496
+ ...simplifiedOptions
2431
2497
  };
2432
2498
  return JSON.stringify(
2433
2499
  Object.entries(withDefaults).map(([key, value]) => {
@@ -2500,13 +2566,17 @@ async function writeManifest(manifest, output, config) {
2500
2566
  }
2501
2567
  async function generateMainfest(entrypoints, buildOutput, config) {
2502
2568
  const pkg = await getPackageJson(config);
2569
+ const versionName = config.manifest.version_name ?? pkg?.version;
2570
+ const version3 = config.manifest.version ?? simplifyVersion(pkg?.version);
2503
2571
  const baseManifest = {
2504
2572
  manifest_version: config.manifestVersion,
2505
2573
  name: pkg?.name,
2506
2574
  description: pkg?.description,
2507
- version: pkg?.version && simplifyVersion(pkg.version),
2508
- // Only add the version name to chromium and if the user hasn't specified a custom version.
2509
- version_name: config.browser !== "firefox" && !config.manifest.version ? pkg?.version : void 0,
2575
+ version: version3,
2576
+ version_name: (
2577
+ // Firefox doesn't support version_name
2578
+ config.browser === "firefox" || versionName === version3 ? void 0 : versionName
2579
+ ),
2510
2580
  short_name: pkg?.shortName,
2511
2581
  icons: discoverIcons(buildOutput)
2512
2582
  };
@@ -2700,7 +2770,7 @@ function addEntrypoints(manifest, entrypoints, buildOutput, config) {
2700
2770
  );
2701
2771
  } else {
2702
2772
  const hashToEntrypointsMap = contentScripts.reduce((map, script) => {
2703
- const hash = hashContentScriptOptions(script.options);
2773
+ const hash = hashContentScriptOptions(script.options, config);
2704
2774
  if (map.has(hash))
2705
2775
  map.get(hash)?.push(script);
2706
2776
  else
@@ -4496,7 +4566,7 @@ async function clean(root = process.cwd()) {
4496
4566
  }
4497
4567
 
4498
4568
  // package.json
4499
- var version2 = "0.7.3";
4569
+ var version2 = "0.7.5";
4500
4570
 
4501
4571
  // src/core/utils/defineConfig.ts
4502
4572
  function defineConfig(config) {