litestar-vite-plugin 0.23.2 → 0.23.3

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.
Files changed (2) hide show
  1. package/dist/js/index.js +10 -4
  2. package/package.json +1 -1
package/dist/js/index.js CHANGED
@@ -8,6 +8,7 @@ import { checkBackendAvailability, loadLitestarMeta } from "./litestar-meta.js";
8
8
  import { readBridgeConfig } from "./shared/bridge-schema.js";
9
9
  import { DEBOUNCE_MS } from "./shared/constants.js";
10
10
  import { createLogger } from "./shared/logger.js";
11
+ import { resolveLitestarPort } from "./shared/network.js";
11
12
  import { resolveDefaultSdkClientPlugin } from "./shared/typegen-core.js";
12
13
  import { createLitestarTypeGenPlugin } from "./shared/typegen-plugin.js";
13
14
  import { buildInputOptions, resolveUserBuildInput } from "./shared/vite-compat.js";
@@ -59,6 +60,9 @@ function normalizeAppUrl(appUrl, _fallbackPort) {
59
60
  }
60
61
  try {
61
62
  const url = new URL(appUrl);
63
+ if (url.hostname === "0.0.0.0" || url.hostname === "[::]") {
64
+ url.hostname = "localhost";
65
+ }
62
66
  const rebuilt = url.origin + (url.pathname === "/" ? "" : url.pathname) + (url.search ?? "") + (url.hash ?? "");
63
67
  return { url: rebuilt };
64
68
  } catch {
@@ -86,7 +90,8 @@ function resolveLitestarPlugin(pluginConfig) {
86
90
  const runtimeAssetUrl = normalizeAssetUrl(env.ASSET_URL || pluginConfig.assetUrl);
87
91
  const buildAssetUrl = pluginConfig.deployAssetUrl ?? runtimeAssetUrl;
88
92
  const serverConfig = command === "serve" ? resolveDevelopmentEnvironmentServerConfig(pluginConfig.detectTls) ?? resolveEnvironmentServerConfig(env) : void 0;
89
- const effectiveAppUrl = env.APP_URL || pythonDefaults?.appUrl || void 0;
93
+ const effectiveAppUrl = normalizeAppUrl(env.APP_URL || pythonDefaults?.appUrl || void 0).url ?? void 0;
94
+ const proxyHmrClientPort = pythonDefaults?.proxyMode === "vite" ? resolveLitestarPort(pythonDefaults.litestarPort, effectiveAppUrl, process.env) : null;
90
95
  const withProxyErrorSilencer = (proxyConfig) => {
91
96
  if (!proxyConfig) return void 0;
92
97
  return Object.fromEntries(
@@ -118,7 +123,7 @@ function resolveLitestarPlugin(pluginConfig) {
118
123
  };
119
124
  const explicitServerOrigin = typeof userConfig.server?.origin === "string" && userConfig.server.origin.length > 0 ? userConfig.server.origin : void 0;
120
125
  const shouldForceDirectServerOrigin = explicitServerOrigin !== void 0 || pythonDefaults?.proxyMode === "direct";
121
- const proxyOriginDefault = !explicitServerOrigin && pythonDefaults?.proxyMode === "vite" && pythonDefaults.appUrl ? pythonDefaults.appUrl : void 0;
126
+ const proxyOriginDefault = !explicitServerOrigin && pythonDefaults?.proxyMode === "vite" ? effectiveAppUrl : void 0;
122
127
  const devBase = pluginConfig.assetUrl.startsWith("/") ? pluginConfig.assetUrl : pluginConfig.assetUrl.replace(/\/+$/, "");
123
128
  ensureCommandShouldRunInEnvironment(command, env, mode);
124
129
  return {
@@ -139,6 +144,7 @@ function resolveLitestarPlugin(pluginConfig) {
139
144
  // Result: base="/static/" + path="vite-hmr" = "/static/vite-hmr"
140
145
  hmr: userConfig.server?.hmr === false ? false : {
141
146
  path: "vite-hmr",
147
+ ...proxyHmrClientPort ? { clientPort: proxyHmrClientPort } : {},
142
148
  ...serverConfig?.hmr ?? {},
143
149
  ...userConfig.server?.hmr === true ? {} : userConfig.server?.hmr
144
150
  },
@@ -801,8 +807,8 @@ function resolveDevServerUrl(address, config, userConfig) {
801
807
  } else if (host === "::" || host === "[::]") {
802
808
  host = "[::1]";
803
809
  }
804
- const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
805
- const port = configHmrClientPort ?? address.port;
810
+ const userHmrClientPort = typeof userConfig.server?.hmr === "object" ? userConfig.server.hmr.clientPort : null;
811
+ const port = userHmrClientPort ?? address.port;
806
812
  return `${protocol}://${host}:${port}`;
807
813
  }
808
814
  function isIpv6(address) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "litestar-vite-plugin",
3
- "version": "0.23.2",
3
+ "version": "0.23.3",
4
4
  "type": "module",
5
5
  "description": "Litestar plugin for Vite.",
6
6
  "keywords": [