wxt 0.7.2 → 0.7.4

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
@@ -565,7 +565,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
565
565
  */
566
566
  declare function clean(root?: string): Promise<void>;
567
567
 
568
- var version = "0.7.2";
568
+ var version = "0.7.4";
569
569
 
570
570
  declare function defineConfig(config: UserConfig): UserConfig;
571
571
 
package/dist/index.d.ts CHANGED
@@ -565,7 +565,7 @@ type EntrypointGroup = Entrypoint | Entrypoint[];
565
565
  */
566
566
  declare function clean(root?: string): Promise<void>;
567
567
 
568
- var version = "0.7.2";
568
+ var version = "0.7.4";
569
569
 
570
570
  declare function defineConfig(config: UserConfig): UserConfig;
571
571
 
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
@@ -1856,7 +1913,8 @@ async function importEntrypointFile(path9, config) {
1856
1913
  "node_modules/wxt/dist/virtual-modules/fake-browser.js"
1857
1914
  )
1858
1915
  },
1859
- extensions: [".ts", ".tsx", ".cjs", ".js", ".mjs"],
1916
+ // List of extensions to transform with esbuild
1917
+ extensions: [".ts", ".cts", ".mts", ".tsx", ".js", ".cjs", ".mjs", ".jsx"],
1860
1918
  transform(opts) {
1861
1919
  const isEntrypoint = opts.filename === normalPath;
1862
1920
  return transformSync(
@@ -2125,13 +2183,13 @@ var PATH_GLOB_TO_TYPE_MAP = {
2125
2183
  "*.sidepanel/index.html": "sidepanel",
2126
2184
  "devtools.html": "devtools",
2127
2185
  "devtools/index.html": "devtools",
2128
- "background.ts": "background",
2129
- "background/index.ts": "background",
2186
+ "background.[jt]s": "background",
2187
+ "background/index.[jt]s": "background",
2130
2188
  [VIRTUAL_NOOP_BACKGROUND_MODULE_ID]: "background",
2131
- "content.ts?(x)": "content-script",
2132
- "content/index.ts?(x)": "content-script",
2133
- "*.content.ts?(x)": "content-script",
2134
- "*.content/index.ts?(x)": "content-script",
2189
+ "content.[jt]s?(x)": "content-script",
2190
+ "content/index.[jt]s?(x)": "content-script",
2191
+ "*.content.[jt]s?(x)": "content-script",
2192
+ "*.content/index.[jt]s?(x)": "content-script",
2135
2193
  [`content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
2136
2194
  [`*.content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
2137
2195
  [`content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
@@ -2142,7 +2200,7 @@ var PATH_GLOB_TO_TYPE_MAP = {
2142
2200
  "options/index.html": "options",
2143
2201
  "*.html": "unlisted-page",
2144
2202
  "*/index.html": "unlisted-page",
2145
- "*.ts": "unlisted-script",
2203
+ "*.[jt]s": "unlisted-script",
2146
2204
  "*/index.ts": "unlisted-script",
2147
2205
  [`*.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
2148
2206
  [`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
@@ -4495,7 +4553,7 @@ async function clean(root = process.cwd()) {
4495
4553
  }
4496
4554
 
4497
4555
  // package.json
4498
- var version2 = "0.7.2";
4556
+ var version2 = "0.7.4";
4499
4557
 
4500
4558
  // src/core/utils/defineConfig.ts
4501
4559
  function defineConfig(config) {