@adonisjs/vite 5.0.1-next.2 → 5.0.1-next.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.
@@ -17,7 +17,22 @@ var Vite = class {
17
17
  #options;
18
18
  #devServer;
19
19
  #createServerPromise;
20
+ /**
21
+ * Indicates whether the Vite manifest file exists on disk
22
+ */
20
23
  hasManifestFile;
24
+ /**
25
+ * Creates a new Vite instance for managing asset compilation and serving
26
+ *
27
+ * @param options - Configuration options for Vite integration
28
+ *
29
+ * @example
30
+ * const vite = new Vite({
31
+ * buildDirectory: 'build',
32
+ * assetsUrl: '/assets',
33
+ * manifestFile: 'build/manifest.json'
34
+ * })
35
+ */
21
36
  constructor(options) {
22
37
  this.#options = options;
23
38
  this.#options.assetsUrl = (this.#options.assetsUrl || "/").replace(/\/$/, "");
@@ -242,7 +257,24 @@ var Vite = class {
242
257
  return preloadsElements.concat(tags.map(({ tag }) => tag));
243
258
  }
244
259
  /**
245
- * Generate tags for the entry points
260
+ * Generate HTML tags (script and link) for the specified entry points
261
+ *
262
+ * In development mode, includes HMR script and dynamically discovers CSS files.
263
+ * In production mode, uses the manifest file to generate optimized tags with preloading.
264
+ *
265
+ * @param entryPoints - Single entry point or array of entry points to generate tags for
266
+ * @param attributes - Additional HTML attributes to apply to the generated tags
267
+ *
268
+ * @example
269
+ * // Generate tags for a single entry point
270
+ * const tags = await vite.generateEntryPointsTags('app.js')
271
+ *
272
+ * @example
273
+ * // Generate tags for multiple entry points with custom attributes
274
+ * const tags = await vite.generateEntryPointsTags(
275
+ * ['app.js', 'admin.js'],
276
+ * { defer: true }
277
+ * )
246
278
  */
247
279
  async generateEntryPointsTags(entryPoints, attributes) {
248
280
  entryPoints = Array.isArray(entryPoints) ? entryPoints : [entryPoints];
@@ -252,13 +284,27 @@ var Vite = class {
252
284
  return this.#generateEntryPointsTagsWithManifest(entryPoints, attributes);
253
285
  }
254
286
  /**
255
- * Returns the explicitly configured assetsUrl
287
+ * Returns the base URL for serving static assets
288
+ *
289
+ * @example
290
+ * const url = vite.assetsUrl()
291
+ * // Returns: '/assets' or '/build' depending on configuration
256
292
  */
257
293
  assetsUrl() {
258
294
  return this.#options.assetsUrl;
259
295
  }
260
296
  /**
261
- * Returns path to a given asset file using the manifest file
297
+ * Returns the full URL path to a specific asset file
298
+ *
299
+ * In development mode, returns the asset path with leading slash.
300
+ * In production mode, uses the manifest file to return the versioned/hashed asset URL.
301
+ *
302
+ * @param asset - The relative path to the asset file
303
+ *
304
+ * @example
305
+ * const path = vite.assetPath('images/logo.png')
306
+ * // Dev: '/images/logo.png'
307
+ * // Prod: '/assets/images/logo-abc123.png'
262
308
  */
263
309
  assetPath(asset) {
264
310
  if (!this.hasManifestFile) {
@@ -268,9 +314,16 @@ var Vite = class {
268
314
  return this.#generateAssetUrl(chunk.file);
269
315
  }
270
316
  /**
271
- * Returns the manifest file contents
317
+ * Returns the parsed Vite manifest file contents
272
318
  *
273
- * @throws Will throw an exception when running in dev
319
+ * The manifest file contains information about compiled assets including
320
+ * file paths, integrity hashes, and import dependencies.
321
+ *
322
+ * @throws Will throw an exception when running in development mode
323
+ *
324
+ * @example
325
+ * const manifest = vite.manifest()
326
+ * console.log(manifest['app.js'].file) // 'assets/app-abc123.js'
274
327
  */
275
328
  manifest() {
276
329
  if (!this.hasManifestFile) {
@@ -282,10 +335,18 @@ var Vite = class {
282
335
  return this.#manifestCache;
283
336
  }
284
337
  /**
285
- * Create the Vite Dev Server and runtime
338
+ * Creates and initializes the Vite development server
339
+ *
340
+ * Lazy loads Vite APIs to avoid importing them in production.
341
+ * The server runs in middleware mode and is configured for custom app integration.
342
+ *
343
+ * @param options - Additional Vite configuration options to merge with defaults
286
344
  *
287
- * We lazy load the APIs to avoid loading it in production
288
- * since we don't need it
345
+ * @example
346
+ * await vite.createDevServer({
347
+ * root: './src',
348
+ * server: { port: 3000 }
349
+ * })
289
350
  */
290
351
  async createDevServer(options) {
291
352
  const { createServer } = await import("vite");
@@ -297,30 +358,63 @@ var Vite = class {
297
358
  this.#devServer = await this.#createServerPromise;
298
359
  }
299
360
  /**
300
- * Create a serverModuleRunner instance
301
- * Will not be available when running in production since
302
- * it needs the Vite Dev server
361
+ * Creates a server-side module runner for executing modules in Node.js context
362
+ *
363
+ * Only available in development mode as it requires the Vite dev server.
364
+ * Useful for server-side rendering and module transformation.
365
+ *
366
+ * @param options - Configuration options for the module runner
367
+ *
368
+ * @example
369
+ * const runner = await vite.createModuleRunner({
370
+ * hmr: { port: 24678 }
371
+ * })
372
+ * const mod = await runner.import('./app.js')
303
373
  */
304
374
  async createModuleRunner(options = {}) {
305
375
  const { createServerModuleRunner } = await import("vite");
306
376
  return createServerModuleRunner(this.#devServer.environments.ssr, options);
307
377
  }
308
378
  /**
309
- * Stop the Vite Dev server
379
+ * Gracefully stops the Vite development server
380
+ *
381
+ * Waits for the server creation promise to complete before closing.
382
+ *
383
+ * @example
384
+ * await vite.stopDevServer()
310
385
  */
311
386
  async stopDevServer() {
312
387
  await this.#createServerPromise;
313
388
  await this.#devServer?.close();
314
389
  }
315
390
  /**
316
- * Get the Vite Dev server instance
317
- * Will not be available when running in production
391
+ * Returns the Vite development server instance
392
+ *
393
+ * Only available in development mode after calling createDevServer().
394
+ * Returns undefined in production or if the server hasn't been created yet.
395
+ *
396
+ * @example
397
+ * const server = vite.getDevServer()
398
+ * if (server) {
399
+ * console.log('Dev server is running on', server.config.server.port)
400
+ * }
318
401
  */
319
402
  getDevServer() {
320
403
  return this.#devServer;
321
404
  }
322
405
  /**
323
- * Returns the script needed for the HMR working with React
406
+ * Generates the React Hot Module Replacement (HMR) script for development
407
+ *
408
+ * Only returns a script element in development mode. In production mode,
409
+ * returns null since HMR is not needed.
410
+ *
411
+ * @param attributes - Additional HTML attributes to apply to the script tag
412
+ *
413
+ * @example
414
+ * const hmrScript = vite.getReactHmrScript({ async: true })
415
+ * if (hmrScript) {
416
+ * console.log(hmrScript.toString()) // <script type="module" async>...</script>
417
+ * }
324
418
  */
325
419
  getReactHmrScript(attributes) {
326
420
  if (this.hasManifestFile) {
@@ -1,10 +1,28 @@
1
1
  // src/vite_middleware.ts
2
2
  var ViteMiddleware = class {
3
+ /**
4
+ * Creates a new ViteMiddleware instance
5
+ *
6
+ * @param vite - The Vite instance containing the dev server
7
+ *
8
+ * @example
9
+ * const middleware = new ViteMiddleware(viteInstance)
10
+ */
3
11
  constructor(vite) {
4
12
  this.vite = vite;
5
13
  this.#devServer = this.vite.getDevServer();
6
14
  }
7
15
  #devServer;
16
+ /**
17
+ * Handles HTTP requests by proxying them to the Vite dev server when appropriate
18
+ *
19
+ * @param request - The HTTP request object from AdonisJS context
20
+ * @param response - The HTTP response object from AdonisJS context
21
+ * @param next - Function to call the next middleware in the chain
22
+ *
23
+ * @example
24
+ * await middleware.handle(ctx, next)
25
+ */
8
26
  async handle({ request, response }, next) {
9
27
  if (!this.#devServer) {
10
28
  return next();
package/build/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Vite
3
- } from "./chunk-AHFYQLFC.js";
3
+ } from "./chunk-MM7OHCLX.js";
4
4
  import "./chunk-ZCQTQOMI.js";
5
5
 
6
6
  // stubs/main.ts
@@ -5,29 +5,89 @@ declare module '@adonisjs/core/types' {
5
5
  vite: Vite;
6
6
  }
7
7
  }
8
+ /**
9
+ * AdonisJS service provider for integrating Vite build tool and development server
10
+ *
11
+ * Handles lifecycle management of Vite integration including:
12
+ * - Registering Vite service in the container
13
+ * - Setting up Edge.js plugin for template integration
14
+ * - Managing development server startup/shutdown
15
+ * - Configuring CSP keywords for @adonisjs/shield
16
+ */
8
17
  export default class ViteProvider {
9
18
  #private;
10
19
  protected app: ApplicationService;
20
+ /**
21
+ * Creates a new ViteProvider instance
22
+ *
23
+ * @param app - The AdonisJS application service instance
24
+ *
25
+ * @example
26
+ * const provider = new ViteProvider(app)
27
+ */
11
28
  constructor(app: ApplicationService);
12
29
  /**
13
- * Registers edge plugin when edge is installed
30
+ * Registers the Vite Edge.js plugin if Edge.js is available in the application
31
+ *
32
+ * Adds global helpers and custom tags (@vite, @viteReactRefresh) to Edge templates.
33
+ * Only registers the plugin if the application is using Edge.js.
34
+ *
35
+ * @example
36
+ * await provider.registerEdgePlugin()
37
+ * // Enables @vite('app.js') in Edge templates
14
38
  */
15
39
  protected registerEdgePlugin(): Promise<void>;
16
40
  /**
17
- * Registers CSP keywords when @adonisjs/shield is installed
41
+ * Registers Content Security Policy keywords when @adonisjs/shield is installed
42
+ *
43
+ * Adds the '@viteUrl' keyword for CSP directives that returns the Vite assets URL
44
+ * when it's an HTTP/HTTPS URL, or an empty string otherwise.
45
+ *
46
+ * @example
47
+ * await provider.registerShieldKeywords()
48
+ * // Enables @viteUrl in CSP directives
18
49
  */
19
50
  protected registerShieldKeywords(): Promise<void>;
20
51
  /**
21
- * Register Vite bindings
52
+ * Registers Vite service and middleware bindings in the IoC container
53
+ *
54
+ * Creates a Vite instance using configuration and determines whether
55
+ * the development server should run based on environment and manifest file presence.
56
+ *
57
+ * @example
58
+ * provider.register()
59
+ * // Vite service is now available via container.make('vite')
22
60
  */
23
61
  register(): void;
24
62
  /**
25
- * - Register edge tags
26
- * - Start Vite server when running in development or test
63
+ * Boots the Vite provider by registering plugins and integrations
64
+ *
65
+ * Registers Edge.js plugin and Shield CSP keywords if the respective
66
+ * packages are available in the application.
67
+ *
68
+ * @example
69
+ * await provider.boot()
27
70
  */
28
71
  boot(): Promise<void>;
29
72
  /**
30
- * Stop Vite server when running in development or test
73
+ * Starts the Vite development server when the application is ready
74
+ *
75
+ * Only starts the server if running in development/test mode and
76
+ * no manifest file exists (indicating development mode).
77
+ *
78
+ * @example
79
+ * await provider.ready()
80
+ * // Dev server starts on configured port
81
+ */
82
+ ready(): Promise<void>;
83
+ /**
84
+ * Gracefully stops the Vite development server during application shutdown
85
+ *
86
+ * Only attempts to stop the server if it was started during the ready phase.
87
+ * Ensures clean shutdown of the development server and its resources.
88
+ *
89
+ * @example
90
+ * await provider.shutdown()
31
91
  */
32
92
  shutdown(): Promise<void>;
33
93
  }
@@ -1,19 +1,38 @@
1
1
  import {
2
2
  Vite
3
- } from "../chunk-AHFYQLFC.js";
3
+ } from "../chunk-MM7OHCLX.js";
4
4
  import {
5
5
  ViteMiddleware
6
- } from "../chunk-FDN2SRQF.js";
6
+ } from "../chunk-TMXIREUT.js";
7
7
  import "../chunk-ZCQTQOMI.js";
8
8
 
9
9
  // providers/vite_provider.ts
10
10
  var ViteProvider = class {
11
+ /**
12
+ * Creates a new ViteProvider instance
13
+ *
14
+ * @param app - The AdonisJS application service instance
15
+ *
16
+ * @example
17
+ * const provider = new ViteProvider(app)
18
+ */
11
19
  constructor(app) {
12
20
  this.app = app;
13
21
  }
22
+ /**
23
+ * Flag indicating whether the Vite development server should be started
24
+ * Set to true when manifest file doesn't exist and running in web/test environment
25
+ */
14
26
  #shouldRunViteDevServer = false;
15
27
  /**
16
- * Registers edge plugin when edge is installed
28
+ * Registers the Vite Edge.js plugin if Edge.js is available in the application
29
+ *
30
+ * Adds global helpers and custom tags (@vite, @viteReactRefresh) to Edge templates.
31
+ * Only registers the plugin if the application is using Edge.js.
32
+ *
33
+ * @example
34
+ * await provider.registerEdgePlugin()
35
+ * // Enables @vite('app.js') in Edge templates
17
36
  */
18
37
  async registerEdgePlugin() {
19
38
  if (this.app.usingEdgeJS) {
@@ -24,7 +43,14 @@ var ViteProvider = class {
24
43
  }
25
44
  }
26
45
  /**
27
- * Registers CSP keywords when @adonisjs/shield is installed
46
+ * Registers Content Security Policy keywords when @adonisjs/shield is installed
47
+ *
48
+ * Adds the '@viteUrl' keyword for CSP directives that returns the Vite assets URL
49
+ * when it's an HTTP/HTTPS URL, or an empty string otherwise.
50
+ *
51
+ * @example
52
+ * await provider.registerShieldKeywords()
53
+ * // Enables @viteUrl in CSP directives
28
54
  */
29
55
  async registerShieldKeywords() {
30
56
  let cspKeywords = null;
@@ -46,7 +72,14 @@ var ViteProvider = class {
46
72
  });
47
73
  }
48
74
  /**
49
- * Register Vite bindings
75
+ * Registers Vite service and middleware bindings in the IoC container
76
+ *
77
+ * Creates a Vite instance using configuration and determines whether
78
+ * the development server should run based on environment and manifest file presence.
79
+ *
80
+ * @example
81
+ * provider.register()
82
+ * // Vite service is now available via container.make('vite')
50
83
  */
51
84
  register() {
52
85
  const appEnvironment = this.app.getEnvironment();
@@ -57,12 +90,29 @@ var ViteProvider = class {
57
90
  this.app.container.singleton(ViteMiddleware, () => new ViteMiddleware(vite));
58
91
  }
59
92
  /**
60
- * - Register edge tags
61
- * - Start Vite server when running in development or test
93
+ * Boots the Vite provider by registering plugins and integrations
94
+ *
95
+ * Registers Edge.js plugin and Shield CSP keywords if the respective
96
+ * packages are available in the application.
97
+ *
98
+ * @example
99
+ * await provider.boot()
62
100
  */
63
101
  async boot() {
64
102
  await this.registerEdgePlugin();
65
103
  await this.registerShieldKeywords();
104
+ }
105
+ /**
106
+ * Starts the Vite development server when the application is ready
107
+ *
108
+ * Only starts the server if running in development/test mode and
109
+ * no manifest file exists (indicating development mode).
110
+ *
111
+ * @example
112
+ * await provider.ready()
113
+ * // Dev server starts on configured port
114
+ */
115
+ async ready() {
66
116
  if (!this.#shouldRunViteDevServer) {
67
117
  return;
68
118
  }
@@ -70,7 +120,13 @@ var ViteProvider = class {
70
120
  await vite.createDevServer();
71
121
  }
72
122
  /**
73
- * Stop Vite server when running in development or test
123
+ * Gracefully stops the Vite development server during application shutdown
124
+ *
125
+ * Only attempts to stop the server if it was started during the ready phase.
126
+ * Ensures clean shutdown of the development server and its resources.
127
+ *
128
+ * @example
129
+ * await provider.shutdown()
74
130
  */
75
131
  async shutdown() {
76
132
  if (!this.#shouldRunViteDevServer) {
@@ -1,11 +1,26 @@
1
1
  import type { ConfigEnv, Plugin, UserConfig } from 'vite';
2
2
  import type { PluginFullOptions } from './types.ts';
3
3
  /**
4
- * Resolve the `config.base` value
4
+ * Resolves the base URL for Vite configuration based on command and options
5
+ *
6
+ * @param config - User-provided Vite configuration
7
+ * @param options - Plugin options containing assetsUrl
8
+ * @param command - Vite command being executed ('build' or 'serve')
9
+ *
10
+ * @example
11
+ * const base = resolveBase(userConfig, { assetsUrl: '/assets' }, 'build')
12
+ * // Returns: '/assets/' for build, '/' for serve
5
13
  */
6
14
  export declare function resolveBase(config: UserConfig, options: PluginFullOptions, command: 'build' | 'serve'): string;
7
15
  /**
8
- * Vite config hook
16
+ * Merges user Vite configuration with AdonisJS-specific defaults and requirements
17
+ *
18
+ * @param options - Plugin options containing build directory and entry points
19
+ * @param userConfig - User-provided Vite configuration
20
+ * @param command - Vite environment command
21
+ *
22
+ * @example
23
+ * const mergedConfig = configHook(pluginOptions, userViteConfig, { command: 'build' })
9
24
  */
10
25
  export declare function configHook(options: PluginFullOptions, userConfig: UserConfig, { command }: ConfigEnv): UserConfig;
11
26
  /**
@@ -1,5 +1,13 @@
1
1
  import type { ViteOptions } from './types.ts';
2
2
  /**
3
- * Define the backend config for Vite
3
+ * Creates a complete Vite configuration by merging provided options with sensible defaults
4
+ *
5
+ * @param config - Partial Vite configuration options to override defaults
6
+ *
7
+ * @example
8
+ * const viteConfig = defineConfig({
9
+ * assetsUrl: '/static',
10
+ * buildDirectory: 'dist'
11
+ * })
4
12
  */
5
13
  export declare function defineConfig(config: Partial<ViteOptions>): ViteOptions;
@@ -1,7 +1,19 @@
1
1
  import type { PluginFn } from 'edge.js/types';
2
2
  import type { Vite } from '../vite.ts';
3
3
  /**
4
- * The edge plugin for vite to share vite service with edge
5
- * and register custom tags
4
+ * Creates an Edge.js plugin that integrates Vite functionality into templates
5
+ *
6
+ * Registers global helpers and custom tags (@vite, @viteReactRefresh) for use in Edge templates.
7
+ * Provides access to asset paths and HMR functionality within template rendering.
8
+ *
9
+ * @param vite - The Vite instance to integrate with Edge templates
10
+ *
11
+ * @example
12
+ * const plugin = edgePluginVite(viteInstance)
13
+ * edge.use(plugin)
14
+ *
15
+ * // In templates:
16
+ * // @vite('app.js')
17
+ * // @viteReactRefresh({ nonce: 'abc123' })
6
18
  */
7
19
  export declare const edgePluginVite: (vite: Vite) => PluginFn<undefined>;
@@ -1,12 +1,32 @@
1
1
  /**
2
- * Returns a new array with unique items by the given key
2
+ * Returns a new array with unique items filtered by the specified key
3
+ *
4
+ * @param array - The array to filter for unique items
5
+ * @param key - The key to use for uniqueness comparison
6
+ *
7
+ * @example
8
+ * const users = [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 1, name: 'John' }]
9
+ * const unique = uniqBy(users, 'id')
10
+ * // Returns: [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]
3
11
  */
4
12
  export declare function uniqBy<T>(array: T[], key: keyof T): T[];
5
13
  /**
6
- * Convert Record of attributes to a valid HTML string
14
+ * Converts an object of HTML attributes to a valid HTML attribute string
15
+ *
16
+ * @param attributes - Object containing HTML attributes where values can be strings or booleans
17
+ *
18
+ * @example
19
+ * const attrs = makeAttributes({ class: 'btn', disabled: true, hidden: false })
20
+ * // Returns: 'class="btn" disabled'
7
21
  */
8
22
  export declare function makeAttributes(attributes: Record<string, string | boolean>): string;
9
23
  /**
10
- * Add a trailing slash if missing
24
+ * Adds a trailing slash to a URL if it doesn't already have one
25
+ *
26
+ * @param url - The URL string to process
27
+ *
28
+ * @example
29
+ * addTrailingSlash('/api') // Returns: '/api/'
30
+ * addTrailingSlash('/api/') // Returns: '/api/'
11
31
  */
12
32
  export declare const addTrailingSlash: (url: string) => string;
@@ -7,50 +7,144 @@ import type { AdonisViteElement, ViteOptions } from './types.ts';
7
7
  */
8
8
  export declare class Vite {
9
9
  #private;
10
+ /**
11
+ * Indicates whether the Vite manifest file exists on disk
12
+ */
10
13
  hasManifestFile: boolean;
14
+ /**
15
+ * Creates a new Vite instance for managing asset compilation and serving
16
+ *
17
+ * @param options - Configuration options for Vite integration
18
+ *
19
+ * @example
20
+ * const vite = new Vite({
21
+ * buildDirectory: 'build',
22
+ * assetsUrl: '/assets',
23
+ * manifestFile: 'build/manifest.json'
24
+ * })
25
+ */
11
26
  constructor(options: ViteOptions);
12
27
  /**
13
- * Generate tags for the entry points
28
+ * Generate HTML tags (script and link) for the specified entry points
29
+ *
30
+ * In development mode, includes HMR script and dynamically discovers CSS files.
31
+ * In production mode, uses the manifest file to generate optimized tags with preloading.
32
+ *
33
+ * @param entryPoints - Single entry point or array of entry points to generate tags for
34
+ * @param attributes - Additional HTML attributes to apply to the generated tags
35
+ *
36
+ * @example
37
+ * // Generate tags for a single entry point
38
+ * const tags = await vite.generateEntryPointsTags('app.js')
39
+ *
40
+ * @example
41
+ * // Generate tags for multiple entry points with custom attributes
42
+ * const tags = await vite.generateEntryPointsTags(
43
+ * ['app.js', 'admin.js'],
44
+ * { defer: true }
45
+ * )
14
46
  */
15
47
  generateEntryPointsTags(entryPoints: string[] | string, attributes?: Record<string, any>): Promise<AdonisViteElement[]>;
16
48
  /**
17
- * Returns the explicitly configured assetsUrl
49
+ * Returns the base URL for serving static assets
50
+ *
51
+ * @example
52
+ * const url = vite.assetsUrl()
53
+ * // Returns: '/assets' or '/build' depending on configuration
18
54
  */
19
55
  assetsUrl(): string | undefined;
20
56
  /**
21
- * Returns path to a given asset file using the manifest file
57
+ * Returns the full URL path to a specific asset file
58
+ *
59
+ * In development mode, returns the asset path with leading slash.
60
+ * In production mode, uses the manifest file to return the versioned/hashed asset URL.
61
+ *
62
+ * @param asset - The relative path to the asset file
63
+ *
64
+ * @example
65
+ * const path = vite.assetPath('images/logo.png')
66
+ * // Dev: '/images/logo.png'
67
+ * // Prod: '/assets/images/logo-abc123.png'
22
68
  */
23
69
  assetPath(asset: string): string;
24
70
  /**
25
- * Returns the manifest file contents
71
+ * Returns the parsed Vite manifest file contents
26
72
  *
27
- * @throws Will throw an exception when running in dev
73
+ * The manifest file contains information about compiled assets including
74
+ * file paths, integrity hashes, and import dependencies.
75
+ *
76
+ * @throws Will throw an exception when running in development mode
77
+ *
78
+ * @example
79
+ * const manifest = vite.manifest()
80
+ * console.log(manifest['app.js'].file) // 'assets/app-abc123.js'
28
81
  */
29
82
  manifest(): Manifest;
30
83
  /**
31
- * Create the Vite Dev Server and runtime
84
+ * Creates and initializes the Vite development server
85
+ *
86
+ * Lazy loads Vite APIs to avoid importing them in production.
87
+ * The server runs in middleware mode and is configured for custom app integration.
88
+ *
89
+ * @param options - Additional Vite configuration options to merge with defaults
32
90
  *
33
- * We lazy load the APIs to avoid loading it in production
34
- * since we don't need it
91
+ * @example
92
+ * await vite.createDevServer({
93
+ * root: './src',
94
+ * server: { port: 3000 }
95
+ * })
35
96
  */
36
97
  createDevServer(options?: InlineConfig): Promise<void>;
37
98
  /**
38
- * Create a serverModuleRunner instance
39
- * Will not be available when running in production since
40
- * it needs the Vite Dev server
99
+ * Creates a server-side module runner for executing modules in Node.js context
100
+ *
101
+ * Only available in development mode as it requires the Vite dev server.
102
+ * Useful for server-side rendering and module transformation.
103
+ *
104
+ * @param options - Configuration options for the module runner
105
+ *
106
+ * @example
107
+ * const runner = await vite.createModuleRunner({
108
+ * hmr: { port: 24678 }
109
+ * })
110
+ * const mod = await runner.import('./app.js')
41
111
  */
42
112
  createModuleRunner(options?: ServerModuleRunnerOptions): Promise<ModuleRunner>;
43
113
  /**
44
- * Stop the Vite Dev server
114
+ * Gracefully stops the Vite development server
115
+ *
116
+ * Waits for the server creation promise to complete before closing.
117
+ *
118
+ * @example
119
+ * await vite.stopDevServer()
45
120
  */
46
121
  stopDevServer(): Promise<void>;
47
122
  /**
48
- * Get the Vite Dev server instance
49
- * Will not be available when running in production
123
+ * Returns the Vite development server instance
124
+ *
125
+ * Only available in development mode after calling createDevServer().
126
+ * Returns undefined in production or if the server hasn't been created yet.
127
+ *
128
+ * @example
129
+ * const server = vite.getDevServer()
130
+ * if (server) {
131
+ * console.log('Dev server is running on', server.config.server.port)
132
+ * }
50
133
  */
51
134
  getDevServer(): ViteDevServer | undefined;
52
135
  /**
53
- * Returns the script needed for the HMR working with React
136
+ * Generates the React Hot Module Replacement (HMR) script for development
137
+ *
138
+ * Only returns a script element in development mode. In production mode,
139
+ * returns null since HMR is not needed.
140
+ *
141
+ * @param attributes - Additional HTML attributes to apply to the script tag
142
+ *
143
+ * @example
144
+ * const hmrScript = vite.getReactHmrScript({ async: true })
145
+ * if (hmrScript) {
146
+ * console.log(hmrScript.toString()) // <script type="module" async>...</script>
147
+ * }
54
148
  */
55
149
  getReactHmrScript(attributes?: Record<string, any>): AdonisViteElement | null;
56
150
  }
@@ -2,6 +2,8 @@ import type { HttpContext } from '@adonisjs/core/http';
2
2
  import type { NextFn } from '@adonisjs/core/types/http';
3
3
  import type { Vite } from './vite.ts';
4
4
  /**
5
+ * Middleware for proxying requests between AdonisJS and Vite development server
6
+ *
5
7
  * Since Vite dev server is integrated within the AdonisJS process, this
6
8
  * middleware is used to proxy the requests to it.
7
9
  *
@@ -12,6 +14,24 @@ import type { Vite } from './vite.ts';
12
14
  export default class ViteMiddleware {
13
15
  #private;
14
16
  protected vite: Vite;
17
+ /**
18
+ * Creates a new ViteMiddleware instance
19
+ *
20
+ * @param vite - The Vite instance containing the dev server
21
+ *
22
+ * @example
23
+ * const middleware = new ViteMiddleware(viteInstance)
24
+ */
15
25
  constructor(vite: Vite);
26
+ /**
27
+ * Handles HTTP requests by proxying them to the Vite dev server when appropriate
28
+ *
29
+ * @param request - The HTTP request object from AdonisJS context
30
+ * @param response - The HTTP response object from AdonisJS context
31
+ * @param next - Function to call the next middleware in the chain
32
+ *
33
+ * @example
34
+ * await middleware.handle(ctx, next)
35
+ */
16
36
  handle({ request, response }: HttpContext, next: NextFn): Promise<any>;
17
37
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ViteMiddleware
3
- } from "../chunk-FDN2SRQF.js";
3
+ } from "../chunk-TMXIREUT.js";
4
4
  export {
5
5
  ViteMiddleware as default
6
6
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/vite",
3
3
  "description": "Vite plugin for AdonisJS",
4
- "version": "5.0.1-next.2",
4
+ "version": "5.0.1-next.3",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -57,19 +57,19 @@
57
57
  "@japa/snapshot": "^2.0.9",
58
58
  "@poppinss/ts-exec": "^1.4.1",
59
59
  "@release-it/conventional-changelog": "^10.0.1",
60
- "@types/node": "^24.6.2",
60
+ "@types/node": "^24.7.2",
61
61
  "@types/supertest": "^6.0.3",
62
62
  "c8": "^10.1.3",
63
63
  "copyfiles": "^2.4.1",
64
64
  "cross-env": "^10.1.0",
65
65
  "del-cli": "^7.0.0",
66
66
  "edge.js": "^6.3.0",
67
- "eslint": "^9.36.0",
67
+ "eslint": "^9.37.0",
68
68
  "prettier": "^3.6.2",
69
69
  "release-it": "^19.0.5",
70
70
  "supertest": "^7.1.4",
71
71
  "tsup": "^8.5.0",
72
- "typedoc": "^0.28.13",
72
+ "typedoc": "^0.28.14",
73
73
  "typescript": "~5.9.3",
74
74
  "vite": "^7.1.9"
75
75
  },