litestar-vite-plugin 0.8.3 → 0.9.0
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.d.ts +6 -0
- package/dist/js/index.js +30 -4
- package/dist/js/inertia-helpers/index.js +2 -1
- package/package.json +3 -3
package/dist/js/index.d.ts
CHANGED
|
@@ -52,6 +52,12 @@ interface PluginConfig {
|
|
|
52
52
|
* @default null
|
|
53
53
|
*/
|
|
54
54
|
detectTls?: string | boolean | null;
|
|
55
|
+
/**
|
|
56
|
+
* Automatically detect the index.html file.
|
|
57
|
+
*
|
|
58
|
+
* @default true
|
|
59
|
+
*/
|
|
60
|
+
autoDetectIndex?: boolean;
|
|
55
61
|
/**
|
|
56
62
|
* Transform the code while serving.
|
|
57
63
|
*/
|
package/dist/js/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import colors from "picocolors";
|
|
|
5
5
|
import { loadEnv } from "vite";
|
|
6
6
|
import fullReload from "vite-plugin-full-reload";
|
|
7
7
|
let exitHandlersBound = false;
|
|
8
|
-
const refreshPaths = ["
|
|
8
|
+
const refreshPaths = ["src/**", "resources/**", "assets/**"].filter((path2) => fs.existsSync(path2.replace(/\*\*$/, "")));
|
|
9
9
|
function litestar(config) {
|
|
10
10
|
const pluginConfig = resolvePluginConfig(config);
|
|
11
11
|
return [resolveLitestarPlugin(pluginConfig), ...resolveFullReloadConfig(pluginConfig)];
|
|
@@ -83,9 +83,25 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
83
83
|
}
|
|
84
84
|
return void 0;
|
|
85
85
|
},
|
|
86
|
-
configureServer(server) {
|
|
86
|
+
async configureServer(server) {
|
|
87
87
|
const envDir = resolvedConfig.envDir || process.cwd();
|
|
88
88
|
const appUrl = loadEnv(resolvedConfig.mode, envDir, "APP_URL").APP_URL ?? "undefined";
|
|
89
|
+
const shouldServeIndex = () => {
|
|
90
|
+
if (!pluginConfig.autoDetectIndex) return false;
|
|
91
|
+
const possiblePaths = [
|
|
92
|
+
path.join(server.config.root, "index.html"),
|
|
93
|
+
path.join(server.config.root, pluginConfig.resourceDirectory, "index.html"),
|
|
94
|
+
path.join(server.config.root, "public", "index.html")
|
|
95
|
+
];
|
|
96
|
+
for (const indexPath of possiblePaths) {
|
|
97
|
+
try {
|
|
98
|
+
fs.accessSync(indexPath);
|
|
99
|
+
return true;
|
|
100
|
+
} catch {
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
};
|
|
89
105
|
server.httpServer?.once("listening", () => {
|
|
90
106
|
const address = server.httpServer?.address();
|
|
91
107
|
const isAddressInfo = (x) => typeof x === "object";
|
|
@@ -93,11 +109,20 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
93
109
|
viteDevServerUrl = userConfig.server?.origin ? userConfig.server.origin : resolveDevServerUrl(address, server.config, userConfig);
|
|
94
110
|
fs.mkdirSync(path.dirname(pluginConfig.hotFile), { recursive: true });
|
|
95
111
|
fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl);
|
|
112
|
+
const hasIndex = shouldServeIndex();
|
|
96
113
|
setTimeout(() => {
|
|
97
114
|
server.config.logger.info(`
|
|
98
115
|
${colors.red(`${colors.bold("LITESTAR")} ${litestarVersion()}`)} ${colors.dim("plugin")} ${colors.bold(`v${pluginVersion()}`)}`);
|
|
99
116
|
server.config.logger.info("");
|
|
100
|
-
|
|
117
|
+
if (hasIndex) {
|
|
118
|
+
server.config.logger.info(` ${colors.green("\u279C")} ${colors.bold("Serve Index")}: Serving application index with Vite`);
|
|
119
|
+
server.config.logger.info(` ${colors.green("\u279C")} ${colors.bold("DEV URL")}: ${colors.cyan(viteDevServerUrl)}`);
|
|
120
|
+
server.config.logger.info(` ${colors.green("\u279C")} ${colors.bold("APP_URL")}: ${colors.cyan(appUrl.replace(/:(\d+)/, (_, port) => `:${colors.bold(port)}`))}`);
|
|
121
|
+
} else {
|
|
122
|
+
server.config.logger.info(` ${colors.green("\u279C")} ${colors.bold("Serve Index")}: Serving Litestar index with Vite`);
|
|
123
|
+
server.config.logger.info(` ${colors.green("\u279C")} ${colors.bold("DEV URL")}: ${colors.cyan(viteDevServerUrl)}`);
|
|
124
|
+
server.config.logger.info(` ${colors.green("\u279C")} ${colors.bold("APP_URL")}: ${colors.cyan(appUrl.replace(/:(\d+)/, (_, port) => `:${colors.bold(port)}`))}`);
|
|
125
|
+
}
|
|
101
126
|
}, 100);
|
|
102
127
|
}
|
|
103
128
|
});
|
|
@@ -114,7 +139,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
114
139
|
exitHandlersBound = true;
|
|
115
140
|
}
|
|
116
141
|
return () => server.middlewares.use((req, res, next) => {
|
|
117
|
-
if (req.url === "/index.html") {
|
|
142
|
+
if (!shouldServeIndex() && req.url === "/index.html") {
|
|
118
143
|
res.statusCode = 404;
|
|
119
144
|
res.end(
|
|
120
145
|
fs.readFileSync(path.join(dirname(), "dev-server-index.html")).toString().replace(/{{ APP_URL }}/g, appUrl)
|
|
@@ -187,6 +212,7 @@ function resolvePluginConfig(config) {
|
|
|
187
212
|
refresh: resolvedConfig.refresh ?? false,
|
|
188
213
|
hotFile: resolvedConfig.hotFile ?? path.join(resolvedConfig.bundleDirectory ?? "public", "hot"),
|
|
189
214
|
detectTls: resolvedConfig.detectTls ?? false,
|
|
215
|
+
autoDetectIndex: resolvedConfig.autoDetectIndex ?? true,
|
|
190
216
|
transformOnServe: resolvedConfig.transformOnServe ?? ((code) => code)
|
|
191
217
|
};
|
|
192
218
|
}
|
|
@@ -105,8 +105,9 @@ export function isRoute(url, routeName) {
|
|
|
105
105
|
const regexPattern = routePattern.replace(/\//g, "\\/").replace(/\{([^}]+):([^}]+)\}/g, (match, paramName, paramType) => {
|
|
106
106
|
switch (paramType) {
|
|
107
107
|
case "str":
|
|
108
|
-
case "path":
|
|
109
108
|
return "([^/]+)";
|
|
109
|
+
case "path":
|
|
110
|
+
return "(.*)";
|
|
110
111
|
case "uuid":
|
|
111
112
|
return "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
112
113
|
default:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "litestar-vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Litestar plugin for Vite.",
|
|
6
6
|
"keywords": ["litestar", "vite", "vite-plugin"],
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"vitest": "^2.1.6"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"vite": "
|
|
48
|
+
"vite": "^5.0.0 || ^6.0.0"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
|
-
"node": "^18.0.0 ||
|
|
51
|
+
"node": "^18.0.0 || ^20.0.0 || >=22.0.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"picocolors": "^1.1.1",
|