litestar-vite-plugin 0.28.0 → 0.29.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/astro.d.ts +12 -121
- package/dist/js/astro.js +4 -55
- package/dist/js/helpers/csrf.d.ts +3 -1
- package/dist/js/helpers/csrf.js +26 -12
- package/dist/js/helpers/expression.d.ts +3 -0
- package/dist/js/helpers/expression.js +524 -0
- package/dist/js/helpers/htmx.d.ts +1 -1
- package/dist/js/helpers/htmx.js +33 -140
- package/dist/js/helpers/index.d.ts +1 -1
- package/dist/js/helpers/index.js +1 -1
- package/dist/js/index.d.ts +4 -106
- package/dist/js/install-hint.js +8 -15
- package/dist/js/nuxt.d.ts +12 -128
- package/dist/js/nuxt.js +7 -58
- package/dist/js/shared/bridge-schema.d.ts +7 -4
- package/dist/js/shared/bridge-schema.js +6 -0
- package/dist/js/shared/emit-page-props-types.js +22 -6
- package/dist/js/shared/emit-static-props-types.js +6 -2
- package/dist/js/shared/integration-config.d.ts +75 -0
- package/dist/js/shared/integration-config.js +59 -0
- package/dist/js/shared/logger.d.ts +0 -4
- package/dist/js/shared/logger.js +1 -2
- package/dist/js/shared/typegen-core.d.ts +2 -9
- package/dist/js/shared/typegen-core.js +0 -1
- package/dist/js/shared/typegen-plugin.d.ts +84 -0
- package/dist/js/shared/vite-compat.d.ts +0 -4
- package/dist/js/shared/vite-compat.js +1 -3
- package/dist/js/sveltekit.d.ts +12 -128
- package/dist/js/sveltekit.js +4 -55
- package/package.json +2 -2
|
@@ -4,6 +4,8 @@ const allowedTopLevelKeys = /* @__PURE__ */ new Set([
|
|
|
4
4
|
"assetUrl",
|
|
5
5
|
"deployAssetUrl",
|
|
6
6
|
"appUrl",
|
|
7
|
+
"csrfCookieName",
|
|
8
|
+
"csrfHeaderName",
|
|
7
9
|
"litestarPort",
|
|
8
10
|
"bundleDir",
|
|
9
11
|
"resourceDir",
|
|
@@ -174,6 +176,8 @@ function parseBridgeSchema(value) {
|
|
|
174
176
|
const assetUrl = assertString(obj, "assetUrl");
|
|
175
177
|
const deployAssetUrl = assertNullableString(obj, "deployAssetUrl");
|
|
176
178
|
const appUrl = assertOptionalNullableString(obj, "appUrl");
|
|
179
|
+
const csrfCookieName = assertOptionalNullableString(obj, "csrfCookieName");
|
|
180
|
+
const csrfHeaderName = assertOptionalNullableString(obj, "csrfHeaderName");
|
|
177
181
|
const litestarPort = assertOptionalNullableInteger(obj, "litestarPort");
|
|
178
182
|
const bundleDir = assertString(obj, "bundleDir");
|
|
179
183
|
const resourceDir = assertString(obj, "resourceDir");
|
|
@@ -195,6 +199,8 @@ function parseBridgeSchema(value) {
|
|
|
195
199
|
assetUrl,
|
|
196
200
|
deployAssetUrl,
|
|
197
201
|
appUrl,
|
|
202
|
+
csrfCookieName,
|
|
203
|
+
csrfHeaderName,
|
|
198
204
|
litestarPort,
|
|
199
205
|
bundleDir,
|
|
200
206
|
resourceDir,
|
|
@@ -104,12 +104,8 @@ export interface FlashMessages {}
|
|
|
104
104
|
`;
|
|
105
105
|
}
|
|
106
106
|
const defaultGeneratedSharedProps = {
|
|
107
|
-
errors: { type: "Record<string, string[]>", optional: true },
|
|
108
107
|
csrf_token: { type: "string", optional: true },
|
|
109
|
-
...includeDefaultAuth
|
|
110
|
-
auth: { type: "AuthData", optional: true },
|
|
111
|
-
flash: { type: "FlashMessages", optional: true }
|
|
112
|
-
} : {}
|
|
108
|
+
...includeDefaultAuth ? { auth: { type: "AuthData", optional: true } } : {}
|
|
113
109
|
};
|
|
114
110
|
const generatedSharedProps = Object.keys(json.sharedProps ?? {}).length > 0 ? json.sharedProps : defaultGeneratedSharedProps;
|
|
115
111
|
const generatedSharedPropLines = Object.entries(generatedSharedProps).toSorted(([a], [b]) => a.localeCompare(b)).map(([key, def]) => {
|
|
@@ -246,7 +242,8 @@ export interface FlashMessages {}
|
|
|
246
242
|
const propsType = rawType.includes("|") ? `(${rawType})` : rawType;
|
|
247
243
|
pageEntries.push(` "${component}": ${propsType} & FullSharedProps`);
|
|
248
244
|
}
|
|
249
|
-
const
|
|
245
|
+
const flashReference = includeDefaultFlash ? '/// <reference path="./inertia.d.ts" />\n' : "";
|
|
246
|
+
const body = `${flashReference}// AUTO-GENERATED by litestar-vite. Do not edit.
|
|
250
247
|
/* eslint-disable */
|
|
251
248
|
|
|
252
249
|
// Import user-defined type extensions (edit page-props.user.ts to customize)
|
|
@@ -285,6 +282,25 @@ export type InertiaPageProps<C extends ComponentName> = PageProps[C]
|
|
|
285
282
|
export type PagePropsFor<C extends ComponentName> = PageProps[C]
|
|
286
283
|
`;
|
|
287
284
|
const result = await writeIfChanged(outFile, body, { encoding: "utf-8" });
|
|
285
|
+
const declarationFile = path.join(outDir, "inertia.d.ts");
|
|
286
|
+
if (includeDefaultFlash) {
|
|
287
|
+
const declaration = `// AUTO-GENERATED by litestar-vite. Do not edit.
|
|
288
|
+
/* eslint-disable */
|
|
289
|
+
import "@inertiajs/core"
|
|
290
|
+
import type { FlashMessages } from "./page-props"
|
|
291
|
+
|
|
292
|
+
declare module "@inertiajs/core" {
|
|
293
|
+
interface InertiaConfig {
|
|
294
|
+
flashDataType: FlashMessages
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export {}
|
|
299
|
+
`;
|
|
300
|
+
await writeIfChanged(declarationFile, declaration, { encoding: "utf-8" });
|
|
301
|
+
} else if (fs.existsSync(declarationFile)) {
|
|
302
|
+
await fs.promises.rm(declarationFile);
|
|
303
|
+
}
|
|
288
304
|
const userStubFile = path.join(outDir, "page-props.user.ts");
|
|
289
305
|
if (!fs.existsSync(userStubFile)) {
|
|
290
306
|
const userStub = `/**
|
|
@@ -64,8 +64,12 @@ async function emitStaticPropsTypes(outputDir, projectRoot = process.cwd()) {
|
|
|
64
64
|
/* eslint-disable */
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
67
|
+
* Build-time constants from Python ViteConfig.static_props, inlined into the bundle.
|
|
68
|
+
*
|
|
69
|
+
* No static props are configured, so this file is empty. This is not an error.
|
|
70
|
+
*
|
|
71
|
+
* Looking for values sent on every Inertia response? Those come from
|
|
72
|
+
* InertiaConfig.extra_static_page_props and are typed in page-props.ts, not here.
|
|
69
73
|
*
|
|
70
74
|
* @example
|
|
71
75
|
* config = ViteConfig(
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type RequiredTypeGenConfig, type TypesConfigShape } from "./typegen-plugin.js";
|
|
2
|
+
/** JavaScript runtime used to invoke package commands. */
|
|
3
|
+
type IntegrationExecutor = "node" | "bun" | "deno" | "yarn" | "pnpm";
|
|
4
|
+
/** Proxy strategy reported by the Python side in `.litestar.json`. */
|
|
5
|
+
type IntegrationProxyMode = "vite" | "direct" | "proxy" | null;
|
|
6
|
+
/**
|
|
7
|
+
* User-facing options accepted by every framework integration.
|
|
8
|
+
*/
|
|
9
|
+
export interface LitestarIntegrationConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Litestar backend URL that API requests are proxied to.
|
|
12
|
+
*
|
|
13
|
+
* @default 'http://localhost:8000'
|
|
14
|
+
*/
|
|
15
|
+
apiProxy?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Path prefix treated as backend API routes.
|
|
18
|
+
*
|
|
19
|
+
* @default '/api'
|
|
20
|
+
*/
|
|
21
|
+
apiPrefix?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Type generation. `true` enables with defaults, `false` disables, or pass an object
|
|
24
|
+
* to override individual fields.
|
|
25
|
+
*
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
types?: boolean | "auto" | TypesConfigShape;
|
|
29
|
+
/**
|
|
30
|
+
* Log integration activity.
|
|
31
|
+
*
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
verbose?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* JavaScript runtime executor for package commands. Overrides the executor reported by
|
|
37
|
+
* Python in `.litestar.json`.
|
|
38
|
+
*/
|
|
39
|
+
executor?: IntegrationExecutor;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Integration configuration with defaults applied and bridge-file values merged in.
|
|
43
|
+
*/
|
|
44
|
+
export interface ResolvedIntegrationConfig {
|
|
45
|
+
apiProxy: string;
|
|
46
|
+
apiPrefix: string;
|
|
47
|
+
types: RequiredTypeGenConfig | false;
|
|
48
|
+
verbose: boolean;
|
|
49
|
+
hotFile?: string;
|
|
50
|
+
proxyMode: IntegrationProxyMode;
|
|
51
|
+
/** Preferred dev server port (provided by Python via `VITE_PORT` or the bridge file). */
|
|
52
|
+
port?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Litestar dev server port. Used to set `vite.server.ws.clientPort` on Vite
|
|
55
|
+
* 8.1+ (`vite.server.hmr.clientPort` on Vite 7 / 8.0) so the browser opens HMR
|
|
56
|
+
* WebSockets against Litestar (single-port contract).
|
|
57
|
+
*/
|
|
58
|
+
litestarPort?: number;
|
|
59
|
+
/** Asset URL prefix (e.g. `/static`); used to build the HMR path. */
|
|
60
|
+
assetUrl?: string;
|
|
61
|
+
/** JavaScript runtime executor for package commands. */
|
|
62
|
+
executor?: IntegrationExecutor;
|
|
63
|
+
/** Whether `.litestar.json` was found. */
|
|
64
|
+
hasPythonConfig: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Apply defaults and merge `.litestar.json` values into a framework integration's options.
|
|
68
|
+
*
|
|
69
|
+
* @param config - User-supplied integration options.
|
|
70
|
+
* @param defaultOutput - Framework-conventional directory for generated types, used when the
|
|
71
|
+
* user and Python side both leave `types.output` unset.
|
|
72
|
+
* @returns The resolved configuration.
|
|
73
|
+
*/
|
|
74
|
+
export declare function resolveIntegrationConfig(config: LitestarIntegrationConfig, defaultOutput: string): ResolvedIntegrationConfig;
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { readBridgeConfig } from "./bridge-schema.js";
|
|
2
|
+
import { resolveHotFilePath, resolveLitestarPort } from "./network.js";
|
|
3
|
+
import { resolveTypesConfig } from "./typegen-plugin.js";
|
|
4
|
+
function resolvePortFromEnv() {
|
|
5
|
+
const envPort = process.env.VITE_PORT;
|
|
6
|
+
if (!envPort) {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
const parsed = Number.parseInt(envPort, 10);
|
|
10
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
11
|
+
}
|
|
12
|
+
function resolveIntegrationConfig(config, defaultOutput) {
|
|
13
|
+
let hotFile;
|
|
14
|
+
let proxyMode = "vite";
|
|
15
|
+
let port = resolvePortFromEnv();
|
|
16
|
+
let pythonTypesConfig;
|
|
17
|
+
let pythonExecutor;
|
|
18
|
+
let assetUrl;
|
|
19
|
+
let litestarPort;
|
|
20
|
+
let hasPythonConfig = false;
|
|
21
|
+
const runtime = readBridgeConfig();
|
|
22
|
+
if (runtime) {
|
|
23
|
+
hasPythonConfig = true;
|
|
24
|
+
hotFile = resolveHotFilePath(runtime.bundleDir, runtime.hotFile);
|
|
25
|
+
proxyMode = runtime.proxyMode;
|
|
26
|
+
port = runtime.port;
|
|
27
|
+
pythonExecutor = runtime.executor;
|
|
28
|
+
assetUrl = runtime.assetUrl;
|
|
29
|
+
if (runtime.types) {
|
|
30
|
+
pythonTypesConfig = runtime.types;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const resolvedLitestarPort = resolveLitestarPort(runtime?.litestarPort, runtime?.appUrl);
|
|
34
|
+
if (resolvedLitestarPort !== null) {
|
|
35
|
+
litestarPort = resolvedLitestarPort;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
apiProxy: config.apiProxy ?? "http://localhost:8000",
|
|
39
|
+
apiPrefix: config.apiPrefix ?? "/api",
|
|
40
|
+
types: resolveTypesConfig({
|
|
41
|
+
requested: config.types,
|
|
42
|
+
pythonConfig: pythonTypesConfig ?? void 0,
|
|
43
|
+
defaultOutput,
|
|
44
|
+
mergePythonWhenTrue: true,
|
|
45
|
+
mergePythonForObject: true
|
|
46
|
+
}),
|
|
47
|
+
verbose: config.verbose ?? false,
|
|
48
|
+
hotFile,
|
|
49
|
+
proxyMode,
|
|
50
|
+
port,
|
|
51
|
+
litestarPort,
|
|
52
|
+
assetUrl,
|
|
53
|
+
executor: config.executor ?? pythonExecutor,
|
|
54
|
+
hasPythonConfig
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
resolveIntegrationConfig
|
|
59
|
+
};
|
|
@@ -13,10 +13,6 @@ export interface LoggingConfig {
|
|
|
13
13
|
suppressViteBanner: boolean;
|
|
14
14
|
timestamps: boolean;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Default logging configuration.
|
|
18
|
-
*/
|
|
19
|
-
export declare const defaultLoggingConfig: LoggingConfig;
|
|
20
16
|
/**
|
|
21
17
|
* Logger instance with configurable behavior.
|
|
22
18
|
*/
|
package/dist/js/shared/logger.js
CHANGED
|
@@ -53,7 +53,7 @@ export interface TypeGenLogger {
|
|
|
53
53
|
warn(message: string): void;
|
|
54
54
|
error(message: string): void;
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
interface TypeGenCacheHooks {
|
|
57
57
|
shouldRunOpenApiTs(openapiPath: string, configPath: string | null, options: {
|
|
58
58
|
generateSdk: boolean;
|
|
59
59
|
generateZod: boolean;
|
|
@@ -89,14 +89,6 @@ export declare function resolveDefaultSdkClientPlugin(options: {
|
|
|
89
89
|
* Find user's openapi-ts config file.
|
|
90
90
|
*/
|
|
91
91
|
export declare function findOpenApiTsConfig(projectRoot: string): string | null;
|
|
92
|
-
/**
|
|
93
|
-
* Build the list of plugins for @hey-api/openapi-ts.
|
|
94
|
-
*/
|
|
95
|
-
export declare function buildHeyApiPlugins(config: {
|
|
96
|
-
generateSdk: boolean;
|
|
97
|
-
generateZod: boolean;
|
|
98
|
-
sdkClientPlugin: string;
|
|
99
|
-
}): string[];
|
|
100
92
|
/**
|
|
101
93
|
* Resolve the locally installed @hey-api/openapi-ts executable.
|
|
102
94
|
*/
|
|
@@ -125,3 +117,4 @@ export declare function runHeyApiGeneration(config: TypeGenCoreConfig, configPat
|
|
|
125
117
|
* @returns Result with generated files and timing info
|
|
126
118
|
*/
|
|
127
119
|
export declare function runTypeGeneration(config: TypeGenCoreConfig, options?: RunTypeGenOptions): Promise<TypeGenResult>;
|
|
120
|
+
export {};
|
|
@@ -28,20 +28,104 @@ export interface TypeGenPluginOptions {
|
|
|
28
28
|
/** Whether .litestar.json was present (used for buildStart warnings) */
|
|
29
29
|
hasPythonConfig?: boolean;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for TypeScript type generation.
|
|
33
|
+
*
|
|
34
|
+
* This is the single source of truth for the `types` option across the core Vite plugin and
|
|
35
|
+
* every framework integration (Astro, Nuxt, SvelteKit), which re-export it under their own
|
|
36
|
+
* names. Paths default relative to `output`, whose default is framework-specific.
|
|
37
|
+
*
|
|
38
|
+
* Type generation works as follows:
|
|
39
|
+
* 1. Python's Litestar exports openapi.json and routes.json on startup (and reload)
|
|
40
|
+
* 2. The Vite plugin watches these files for changes
|
|
41
|
+
* 3. When they change, it runs @hey-api/openapi-ts to generate TypeScript types
|
|
42
|
+
* 4. An HMR event is sent to notify the client
|
|
43
|
+
*/
|
|
31
44
|
export interface TypesConfigShape {
|
|
45
|
+
/**
|
|
46
|
+
* Enable type generation.
|
|
47
|
+
*
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
32
50
|
enabled?: boolean;
|
|
51
|
+
/** Directory for generated TypeScript output. Framework-specific default. */
|
|
33
52
|
output?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Path where the OpenAPI schema is exported by Litestar. The plugin watches this file
|
|
55
|
+
* and runs @hey-api/openapi-ts when it changes.
|
|
56
|
+
*
|
|
57
|
+
* @default `${output}/openapi.json`
|
|
58
|
+
*/
|
|
34
59
|
openapiPath?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Path where route metadata is exported by Litestar. Watched for route helper generation.
|
|
62
|
+
*
|
|
63
|
+
* @default `${output}/routes.json`
|
|
64
|
+
*/
|
|
35
65
|
routesPath?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Path where Inertia page props metadata is exported by Litestar.
|
|
68
|
+
*
|
|
69
|
+
* @default `${output}/inertia-pages.json`
|
|
70
|
+
*/
|
|
36
71
|
pagePropsPath?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Path for the generated `schemas.ts` helper file.
|
|
74
|
+
*
|
|
75
|
+
* @default `${output}/schemas.ts`
|
|
76
|
+
*/
|
|
37
77
|
schemasTsPath?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Generate Zod schemas in addition to TypeScript types.
|
|
80
|
+
*
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
38
83
|
generateZod?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Generate a typed SDK client in addition to types.
|
|
86
|
+
*
|
|
87
|
+
* @default true
|
|
88
|
+
*/
|
|
39
89
|
generateSdk?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Generate typed `routes.ts` from routes.json metadata. Mirrors Python
|
|
92
|
+
* `TypeGenConfig.generate_routes`.
|
|
93
|
+
*
|
|
94
|
+
* @default true
|
|
95
|
+
*/
|
|
40
96
|
generateRoutes?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Generate Inertia page props types from inertia-pages.json metadata. Mirrors Python
|
|
99
|
+
* `TypeGenConfig.generate_page_props`.
|
|
100
|
+
*
|
|
101
|
+
* @default true
|
|
102
|
+
*/
|
|
41
103
|
generatePageProps?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Generate `schemas.ts` with ergonomic form/response type helpers, such as
|
|
106
|
+
* `FormInput<'api:login'>` and `FormResponse<'api:login', 201>`.
|
|
107
|
+
*
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
42
110
|
generateSchemas?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Register the generated `route()` function on `window`, similar to Laravel's Ziggy,
|
|
113
|
+
* so it can be used without an import.
|
|
114
|
+
*
|
|
115
|
+
* @default false
|
|
116
|
+
*/
|
|
43
117
|
globalRoute?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Fail Vite when type generation fails. Defaults to `true` during `vite build` and
|
|
120
|
+
* `false` during `vite serve`.
|
|
121
|
+
*/
|
|
44
122
|
failOnError?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Debounce window in milliseconds for regeneration, so a burst of file writes triggers
|
|
125
|
+
* a single run.
|
|
126
|
+
*
|
|
127
|
+
* @default 300
|
|
128
|
+
*/
|
|
45
129
|
debounce?: number;
|
|
46
130
|
}
|
|
47
131
|
export interface ResolveTypesConfigOptions {
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/** Parsed major version of the running Vite instance. */
|
|
2
|
-
export declare const viteMajor: number;
|
|
3
|
-
/** Parsed minor version of the running Vite instance. */
|
|
4
|
-
export declare const viteMinor: number;
|
|
5
1
|
/**
|
|
6
2
|
* Whether the running Vite version is 8+, which uses Rolldown and exposes
|
|
7
3
|
* `build.rolldownOptions` in place of Vite 7's `build.rollupOptions`.
|
package/dist/js/sveltekit.d.ts
CHANGED
|
@@ -27,138 +27,22 @@
|
|
|
27
27
|
*
|
|
28
28
|
* @module
|
|
29
29
|
*/
|
|
30
|
+
import { type LitestarIntegrationConfig } from "./shared/integration-config.js";
|
|
31
|
+
import { type TypesConfigShape } from "./shared/typegen-plugin.js";
|
|
30
32
|
/**
|
|
31
|
-
* Configuration for TypeScript type generation
|
|
33
|
+
* Configuration for TypeScript type generation.
|
|
34
|
+
*
|
|
35
|
+
* Alias of the shared {@link TypesConfigShape} so every integration accepts an identical
|
|
36
|
+
* `types` option. Retained as a named export for backwards compatibility.
|
|
32
37
|
*/
|
|
33
|
-
export
|
|
34
|
-
/**
|
|
35
|
-
* Enable type generation.
|
|
36
|
-
*
|
|
37
|
-
* @default false
|
|
38
|
-
*/
|
|
39
|
-
enabled?: boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Path to output generated TypeScript types.
|
|
42
|
-
* Relative to the SvelteKit project root.
|
|
43
|
-
*
|
|
44
|
-
* @default 'src/lib/generated'
|
|
45
|
-
*/
|
|
46
|
-
output?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Path where the OpenAPI schema is exported by Litestar.
|
|
49
|
-
*
|
|
50
|
-
* @default `${output}/openapi.json`
|
|
51
|
-
*/
|
|
52
|
-
openapiPath?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Path where route metadata is exported by Litestar.
|
|
55
|
-
*
|
|
56
|
-
* @default `${output}/routes.json`
|
|
57
|
-
*/
|
|
58
|
-
routesPath?: string;
|
|
59
|
-
/**
|
|
60
|
-
* Optional path for the generated schemas.ts helper file.
|
|
61
|
-
*
|
|
62
|
-
* @default `${output}/schemas.ts`
|
|
63
|
-
*/
|
|
64
|
-
schemasTsPath?: string;
|
|
65
|
-
/**
|
|
66
|
-
* Path where Inertia page props metadata is exported by Litestar.
|
|
67
|
-
*
|
|
68
|
-
* @default `${output}/inertia-pages.json`
|
|
69
|
-
*/
|
|
70
|
-
pagePropsPath?: string;
|
|
71
|
-
/**
|
|
72
|
-
* Generate Zod schemas in addition to TypeScript types.
|
|
73
|
-
*
|
|
74
|
-
* @default false
|
|
75
|
-
*/
|
|
76
|
-
generateZod?: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Generate SDK client functions for API calls.
|
|
79
|
-
*
|
|
80
|
-
* @default true
|
|
81
|
-
*/
|
|
82
|
-
generateSdk?: boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Generate typed routes.ts from routes.json metadata.
|
|
85
|
-
*
|
|
86
|
-
* @default true
|
|
87
|
-
*/
|
|
88
|
-
generateRoutes?: boolean;
|
|
89
|
-
/**
|
|
90
|
-
* Generate Inertia page props types from inertia-pages.json metadata.
|
|
91
|
-
*
|
|
92
|
-
* @default true
|
|
93
|
-
*/
|
|
94
|
-
generatePageProps?: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Generate schemas.ts with ergonomic form/response type helpers.
|
|
97
|
-
*
|
|
98
|
-
* @default true
|
|
99
|
-
*/
|
|
100
|
-
generateSchemas?: boolean;
|
|
101
|
-
/**
|
|
102
|
-
* Register route() globally on window object.
|
|
103
|
-
*
|
|
104
|
-
* @default false
|
|
105
|
-
*/
|
|
106
|
-
globalRoute?: boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Fail Vite when type generation fails.
|
|
109
|
-
*
|
|
110
|
-
* Defaults to true during build and false during dev.
|
|
111
|
-
*/
|
|
112
|
-
failOnError?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Debounce time in milliseconds for type regeneration.
|
|
115
|
-
*
|
|
116
|
-
* @default 300
|
|
117
|
-
*/
|
|
118
|
-
debounce?: number;
|
|
119
|
-
}
|
|
38
|
+
export type SvelteKitTypesConfig = TypesConfigShape;
|
|
120
39
|
/**
|
|
121
|
-
* Configuration options for the Litestar
|
|
40
|
+
* Configuration options for the Litestar integration.
|
|
41
|
+
*
|
|
42
|
+
* Alias of the shared {@link LitestarIntegrationConfig}. Retained as a named export for
|
|
43
|
+
* backwards compatibility.
|
|
122
44
|
*/
|
|
123
|
-
export
|
|
124
|
-
/**
|
|
125
|
-
* URL of the Litestar API backend for proxying requests during development.
|
|
126
|
-
*
|
|
127
|
-
* @example 'http://localhost:8000'
|
|
128
|
-
* @default 'http://localhost:8000'
|
|
129
|
-
*/
|
|
130
|
-
apiProxy?: string;
|
|
131
|
-
/**
|
|
132
|
-
* API route prefix to proxy to the Litestar backend.
|
|
133
|
-
* Requests matching this prefix will be forwarded to the apiProxy URL.
|
|
134
|
-
*
|
|
135
|
-
* @example '/api'
|
|
136
|
-
* @default '/api'
|
|
137
|
-
*/
|
|
138
|
-
apiPrefix?: string;
|
|
139
|
-
/**
|
|
140
|
-
* Enable and configure TypeScript type generation.
|
|
141
|
-
*
|
|
142
|
-
* When set to `true`, enables type generation with default settings.
|
|
143
|
-
* When set to a SvelteKitTypesConfig object, enables type generation with custom settings.
|
|
144
|
-
*
|
|
145
|
-
* @default false
|
|
146
|
-
*/
|
|
147
|
-
types?: boolean | SvelteKitTypesConfig;
|
|
148
|
-
/**
|
|
149
|
-
* Enable verbose logging for debugging.
|
|
150
|
-
*
|
|
151
|
-
* @default false
|
|
152
|
-
*/
|
|
153
|
-
verbose?: boolean;
|
|
154
|
-
/**
|
|
155
|
-
* JavaScript runtime executor for package commands.
|
|
156
|
-
* Used when running tools like @hey-api/openapi-ts.
|
|
157
|
-
*
|
|
158
|
-
* @default undefined (uses LITESTAR_VITE_RUNTIME env or 'node')
|
|
159
|
-
*/
|
|
160
|
-
executor?: "node" | "bun" | "deno" | "yarn" | "pnpm";
|
|
161
|
-
}
|
|
45
|
+
export type LitestarSvelteKitConfig = LitestarIntegrationConfig;
|
|
162
46
|
/**
|
|
163
47
|
* Litestar integration plugin for SvelteKit.
|
|
164
48
|
*
|
package/dist/js/sveltekit.js
CHANGED
|
@@ -1,64 +1,13 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import colors from "picocolors";
|
|
4
|
-
import {
|
|
4
|
+
import { resolveIntegrationConfig } from "./shared/integration-config.js";
|
|
5
5
|
import { installManagedShutdown } from "./shared/managed-shutdown.js";
|
|
6
|
-
import { normalizeHost
|
|
7
|
-
import { createLitestarTypeGenPlugin
|
|
6
|
+
import { normalizeHost } from "./shared/network.js";
|
|
7
|
+
import { createLitestarTypeGenPlugin } from "./shared/typegen-plugin.js";
|
|
8
8
|
import { hmrServerConfig } from "./shared/vite-compat.js";
|
|
9
9
|
function resolveConfig(config = {}) {
|
|
10
|
-
|
|
11
|
-
let proxyMode = "vite";
|
|
12
|
-
let port;
|
|
13
|
-
let pythonTypesConfig;
|
|
14
|
-
let hasPythonConfig = false;
|
|
15
|
-
const envPort = process.env.VITE_PORT;
|
|
16
|
-
if (envPort) {
|
|
17
|
-
port = Number.parseInt(envPort, 10);
|
|
18
|
-
if (Number.isNaN(port)) {
|
|
19
|
-
port = void 0;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
let pythonExecutor;
|
|
23
|
-
let assetUrl;
|
|
24
|
-
let litestarPort;
|
|
25
|
-
const runtime = readBridgeConfig();
|
|
26
|
-
if (runtime) {
|
|
27
|
-
hasPythonConfig = true;
|
|
28
|
-
const hot = runtime.hotFile;
|
|
29
|
-
hotFile = resolveHotFilePath(runtime.bundleDir, hot);
|
|
30
|
-
proxyMode = runtime.proxyMode;
|
|
31
|
-
port = runtime.port;
|
|
32
|
-
pythonExecutor = runtime.executor;
|
|
33
|
-
assetUrl = runtime.assetUrl;
|
|
34
|
-
if (runtime.types) {
|
|
35
|
-
pythonTypesConfig = runtime.types;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const resolvedLitestarPort = resolveLitestarPort(runtime?.litestarPort, runtime?.appUrl);
|
|
39
|
-
if (resolvedLitestarPort !== null) {
|
|
40
|
-
litestarPort = resolvedLitestarPort;
|
|
41
|
-
}
|
|
42
|
-
const typesConfig = resolveTypesConfig({
|
|
43
|
-
requested: config.types,
|
|
44
|
-
pythonConfig: pythonTypesConfig ?? void 0,
|
|
45
|
-
defaultOutput: "src/lib/generated",
|
|
46
|
-
mergePythonWhenTrue: true,
|
|
47
|
-
mergePythonForObject: true
|
|
48
|
-
});
|
|
49
|
-
return {
|
|
50
|
-
apiProxy: config.apiProxy ?? "http://localhost:8000",
|
|
51
|
-
apiPrefix: config.apiPrefix ?? "/api",
|
|
52
|
-
types: typesConfig,
|
|
53
|
-
verbose: config.verbose ?? false,
|
|
54
|
-
hotFile,
|
|
55
|
-
proxyMode,
|
|
56
|
-
port,
|
|
57
|
-
litestarPort,
|
|
58
|
-
assetUrl,
|
|
59
|
-
executor: config.executor ?? pythonExecutor,
|
|
60
|
-
hasPythonConfig
|
|
61
|
-
};
|
|
10
|
+
return resolveIntegrationConfig(config, "src/lib/generated");
|
|
62
11
|
}
|
|
63
12
|
function litestarSvelteKit(userConfig = {}) {
|
|
64
13
|
const config = resolveConfig(userConfig);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "litestar-vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Litestar plugin for Vite.",
|
|
6
6
|
"keywords": [
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"build-plugin": "rm -rf dist/js && npm run build-plugin-types && npm run build-plugin-esm && npm run build-dev-server",
|
|
112
112
|
"build-dev-server": "vite build --config src/js/src/dev-server/vite.config.ts && mv dist/js/index.html dist/js/dev-server-index.html",
|
|
113
113
|
"build-plugin-types": "tsc --project src/js/tsconfig.json --emitDeclarationOnly",
|
|
114
|
-
"build-plugin-esm": "esbuild src/js/src/index.ts --platform=node --format=esm --outfile=dist/js/index.js && esbuild src/js/src/install-hint.ts --platform=node --format=esm --outfile=dist/js/install-hint.js && esbuild src/js/src/litestar-meta.ts --platform=node --format=esm --outfile=dist/js/litestar-meta.js && esbuild src/js/src/typegen-cli.ts --platform=node --format=esm --outfile=dist/js/typegen-cli.js --banner:js='#!/usr/bin/env node' && chmod +x dist/js/typegen-cli.js && mkdir -p dist/js/shared && esbuild src/js/src/shared/bridge-schema.ts src/js/src/shared/constants.ts src/js/src/shared/debounce.ts src/js/src/shared/format-path.ts src/js/src/shared/logger.ts src/js/src/shared/managed-shutdown.ts src/js/src/shared/emit-page-props-types.ts src/js/src/shared/emit-schemas-types.ts src/js/src/shared/emit-static-props-types.ts src/js/src/shared/typegen-plugin.ts src/js/src/shared/typegen-core.ts src/js/src/shared/write-if-changed.ts src/js/src/shared/typegen-cache.ts src/js/src/shared/network.ts src/js/src/shared/vite-compat.ts --platform=node --format=esm --outdir=dist/js/shared",
|
|
114
|
+
"build-plugin-esm": "esbuild src/js/src/index.ts --platform=node --format=esm --outfile=dist/js/index.js && esbuild src/js/src/install-hint.ts --platform=node --format=esm --outfile=dist/js/install-hint.js && esbuild src/js/src/litestar-meta.ts --platform=node --format=esm --outfile=dist/js/litestar-meta.js && esbuild src/js/src/typegen-cli.ts --platform=node --format=esm --outfile=dist/js/typegen-cli.js --banner:js='#!/usr/bin/env node' && chmod +x dist/js/typegen-cli.js && mkdir -p dist/js/shared && esbuild src/js/src/shared/bridge-schema.ts src/js/src/shared/constants.ts src/js/src/shared/debounce.ts src/js/src/shared/format-path.ts src/js/src/shared/integration-config.ts src/js/src/shared/logger.ts src/js/src/shared/managed-shutdown.ts src/js/src/shared/emit-page-props-types.ts src/js/src/shared/emit-schemas-types.ts src/js/src/shared/emit-static-props-types.ts src/js/src/shared/typegen-plugin.ts src/js/src/shared/typegen-core.ts src/js/src/shared/write-if-changed.ts src/js/src/shared/typegen-cache.ts src/js/src/shared/network.ts src/js/src/shared/vite-compat.ts --platform=node --format=esm --outdir=dist/js/shared",
|
|
115
115
|
"build-helpers": "rm -rf dist/js/helpers && tsc --project src/js/tsconfig.helpers.json",
|
|
116
116
|
"build-inertia-helpers": "rm -rf dist/js/inertia-helpers && tsc --project src/js/tsconfig.inertia-helpers.json",
|
|
117
117
|
"build-adapters": "rm -rf dist/js/react dist/js/vue dist/js/svelte && tsc --project src/js/tsconfig.react.json && tsc --project src/js/tsconfig.vue.json && tsc --project src/js/tsconfig.svelte.json",
|