litestar-vite-plugin 0.23.1 → 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.
- package/dist/js/index.js +11 -8
- 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"
|
|
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
|
},
|
|
@@ -243,10 +249,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
243
249
|
const address = server.httpServer?.address();
|
|
244
250
|
const isAddressInfo = (x) => typeof x === "object";
|
|
245
251
|
if (isAddressInfo(address)) {
|
|
246
|
-
|
|
247
|
-
const configuredServerOrigin = typeof server.config.server.origin === "string" && server.config.server.origin.length > 0 && server.config.server.origin !== "__litestar_vite_placeholder__" ? server.config.server.origin : void 0;
|
|
248
|
-
const hotfileOrigin = configuredServerOrigin ?? explicitServerOrigin;
|
|
249
|
-
viteDevServerUrl = hotfileOrigin ? hotfileOrigin : resolveDevServerUrl(address, server.config, userConfig);
|
|
252
|
+
viteDevServerUrl = resolveDevServerUrl(address, server.config, userConfig);
|
|
250
253
|
fs.mkdirSync(path.dirname(pluginConfig.hotFile), { recursive: true });
|
|
251
254
|
fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl);
|
|
252
255
|
setTimeout(async () => {
|
|
@@ -804,8 +807,8 @@ function resolveDevServerUrl(address, config, userConfig) {
|
|
|
804
807
|
} else if (host === "::" || host === "[::]") {
|
|
805
808
|
host = "[::1]";
|
|
806
809
|
}
|
|
807
|
-
const
|
|
808
|
-
const port =
|
|
810
|
+
const userHmrClientPort = typeof userConfig.server?.hmr === "object" ? userConfig.server.hmr.clientPort : null;
|
|
811
|
+
const port = userHmrClientPort ?? address.port;
|
|
809
812
|
return `${protocol}://${host}:${port}`;
|
|
810
813
|
}
|
|
811
814
|
function isIpv6(address) {
|