@adonisjs/assembler 8.0.0-next.5 → 8.0.0-next.7

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 (36) hide show
  1. package/README.md +87 -59
  2. package/build/chunk-25Q3N5JR.js +392 -0
  3. package/build/chunk-PORDZS62.js +391 -0
  4. package/build/chunk-TIKQQRMX.js +116 -0
  5. package/build/index.d.ts +2 -0
  6. package/build/index.js +825 -430
  7. package/build/src/bundler.d.ts +44 -3
  8. package/build/src/code_scanners/routes_scanner/main.d.ts +49 -9
  9. package/build/src/code_scanners/routes_scanner/main.js +445 -0
  10. package/build/src/code_scanners/routes_scanner/validator_extractor.d.ts +12 -4
  11. package/build/src/code_transformer/main.d.ts +44 -43
  12. package/build/src/code_transformer/main.js +123 -101
  13. package/build/src/code_transformer/rc_file_transformer.d.ts +56 -4
  14. package/build/src/debug.d.ts +12 -0
  15. package/build/src/dev_server.d.ts +38 -9
  16. package/build/src/file_buffer.d.ts +67 -0
  17. package/build/src/file_system.d.ts +45 -7
  18. package/build/src/helpers.d.ts +79 -4
  19. package/build/src/helpers.js +16 -0
  20. package/build/src/hooks.d.ts +224 -0
  21. package/build/src/index_generator/main.d.ts +64 -0
  22. package/build/src/index_generator/main.js +7 -0
  23. package/build/src/index_generator/source.d.ts +60 -0
  24. package/build/src/paths_resolver.d.ts +27 -2
  25. package/build/src/shortcuts_manager.d.ts +42 -4
  26. package/build/src/test_runner.d.ts +56 -10
  27. package/build/src/types/code_scanners.d.ts +138 -24
  28. package/build/src/types/code_transformer.d.ts +61 -19
  29. package/build/src/types/common.d.ts +199 -55
  30. package/build/src/types/hooks.d.ts +235 -22
  31. package/build/src/types/main.d.ts +13 -0
  32. package/build/src/utils.d.ts +88 -13
  33. package/build/src/virtual_file_system.d.ts +112 -0
  34. package/package.json +9 -3
  35. package/build/chunk-RR4HCA4M.js +0 -7
  36. package/build/src/ast_file_system.d.ts +0 -17
@@ -1,192 +1,336 @@
1
1
  import type { Logger } from '@poppinss/cliui';
2
2
  import { type Prettify } from '@poppinss/utils/types';
3
- import { type BundlerHooks, type DevServerHooks, type TestRunnerHooks, type WatcherHooks } from './hooks.ts';
3
+ import { type AllHooks } from './hooks.ts';
4
+ import { type FileBuffer } from '../file_buffer.ts';
5
+ import { type VirtualFileSystem } from '../virtual_file_system.ts';
6
+ /**
7
+ * Recursive file tree structure for representing nested directory hierarchies
8
+ */
9
+ export type RecursiveFileTree = {
10
+ [key: string]: string | RecursiveFileTree;
11
+ };
12
+ /**
13
+ * Options accepted by the VirtualFileSystem class
14
+ */
15
+ export type VirtualFileSystemOptions = {
16
+ glob?: string[];
17
+ };
18
+ /**
19
+ * Source configuration accepted by the index generator
20
+ */
21
+ export type IndexGeneratorSourceConfig = ({
22
+ exportName: string;
23
+ as: 'barrelFile';
24
+ } | {
25
+ as: (vfs: VirtualFileSystem, buffer: FileBuffer, config: IndexGeneratorSourceConfig) => void;
26
+ }) & {
27
+ source: string;
28
+ output: string;
29
+ glob?: string[];
30
+ importAlias?: string;
31
+ removeSuffix?: string;
32
+ };
4
33
  /**
5
34
  * Marks a given optional property as required
35
+ *
36
+ * @template T - The source type
37
+ * @template K - The keys from T that should be made required
38
+ *
39
+ * @example
40
+ * type User = { name?: string; email?: string; age: number }
41
+ * type UserWithName = AsRequired<User, 'name'> // { name: string; email?: string; age: number }
6
42
  */
7
43
  export type AsRequired<T, K extends keyof T> = Prettify<Omit<T, K> & Required<{
8
44
  [O in K]: T[K];
9
45
  }>>;
10
46
  /**
11
- * Represents an import statement
47
+ * Represents an import statement parsed from TypeScript/JavaScript code
48
+ *
49
+ * @example
50
+ * // For: import { User } from './models/user'
51
+ * const importInfo: Import = {
52
+ * specifier: './models/user',
53
+ * isConstant: true,
54
+ * clause: { type: 'named', value: 'User' }
55
+ * }
12
56
  */
13
57
  export type Import = {
58
+ /** The module specifier being imported from */
14
59
  specifier: string;
60
+ /** Whether the import specifier is a constant string literal */
15
61
  isConstant: boolean;
62
+ /** The import clause details */
16
63
  clause: {
64
+ /** The type of import clause */
17
65
  type: 'namespace' | 'default' | 'named';
66
+ /** The imported identifier name */
18
67
  value: string;
68
+ /** Optional alias for named imports with 'as' keyword */
19
69
  alias?: string;
20
70
  };
21
71
  };
22
72
  /**
23
73
  * File inspected by the filesystem based upon the provided globs
24
74
  * and the current file path
75
+ *
76
+ * @example
77
+ * const inspectedFile: InspectedFile = {
78
+ * fileType: 'script',
79
+ * reloadServer: true,
80
+ * unixRelativePath: 'app/controllers/users_controller.ts',
81
+ * unixAbsolutePath: '/project/app/controllers/users_controller.ts'
82
+ * }
25
83
  */
26
84
  export type InspectedFile = {
85
+ /** The category of the file based on its purpose */
27
86
  fileType: 'script' | 'meta' | 'test';
87
+ /** Whether changes to this file should trigger server reload */
28
88
  reloadServer: boolean;
89
+ /** Unix-style relative path from project root */
29
90
  unixRelativePath: string;
91
+ /** Unix-style absolute path to the file */
30
92
  unixAbsolutePath: string;
31
93
  };
32
94
  /**
33
95
  * Subset of properties assembler needs from the "adonisrc.ts" file.
96
+ * Contains configuration for file watching, hooks, and test suites.
97
+ *
98
+ * @example
99
+ * const rcFile: AssemblerRcFile = {
100
+ * metaFiles: [
101
+ * { pattern: 'config/**', reloadServer: true }
102
+ * ],
103
+ * hooks: {
104
+ * devServerStarted: [() => import('./hooks/server_started')]
105
+ * },
106
+ * suites: [
107
+ * { name: 'unit', files: ['tests/unit/**\/*.spec.ts'] }
108
+ * ]
109
+ * }
34
110
  */
35
111
  export type AssemblerRcFile = {
36
112
  /**
37
- * An array of metaFiles glob patterns to watch
113
+ * An array of metaFiles glob patterns to watch for changes
38
114
  */
39
115
  metaFiles?: {
116
+ /** Glob pattern to match files */
40
117
  pattern: string;
118
+ /** Whether to reload server when these files change */
41
119
  reloadServer: boolean;
42
120
  }[];
43
121
  /**
44
- * Hooks to execute at different stages.
122
+ * Hooks to execute at different stages of development and build processes
45
123
  */
46
- hooks?: Partial<WatcherHooks & DevServerHooks & BundlerHooks & TestRunnerHooks>;
124
+ hooks?: Partial<AllHooks>;
47
125
  /**
48
- * An array of suites for which to run tests
126
+ * An array of test suites configuration
49
127
  */
50
128
  suites?: {
129
+ /** Name of the test suite */
51
130
  name: string;
131
+ /** Glob pattern(s) for test files in this suite */
52
132
  files: string | string[];
53
133
  }[];
54
134
  };
55
135
  /**
56
- * Options needed to run a script file
136
+ * Options needed to run a script file as a child process
137
+ *
138
+ * @example
139
+ * const options: RunScriptOptions = {
140
+ * script: 'bin/server.ts',
141
+ * scriptArgs: ['--watch'],
142
+ * nodeArgs: ['--loader', 'ts-node/esm'],
143
+ * stdio: 'inherit',
144
+ * env: { NODE_ENV: 'development' },
145
+ * reject: true
146
+ * }
57
147
  */
58
148
  export type RunScriptOptions = {
59
- /**
60
- * Script to run
61
- */
149
+ /** Path to the script file to run */
62
150
  script: string;
63
- /**
64
- * Arguments to pass to the script
65
- */
151
+ /** Arguments to pass to the script */
66
152
  scriptArgs: string[];
67
- /**
68
- * Arguments to pass to NodeJS CLI
69
- */
153
+ /** Arguments to pass to the Node.js CLI */
70
154
  nodeArgs: string[];
71
- /**
72
- * Standard input ouput stream options
73
- */
155
+ /** Standard input/output stream options */
74
156
  stdio?: 'pipe' | 'inherit';
75
- /**
76
- * Environment variables to pass to the child process
77
- */
157
+ /** Environment variables to pass to the child process */
78
158
  env?: NodeJS.ProcessEnv;
79
- /**
80
- * Whether or not to reject the promise. Defaults
81
- * false
82
- */
159
+ /** Whether to reject the promise on script failure (defaults to false) */
83
160
  reject?: boolean;
84
161
  };
85
162
  /**
86
- * Options accepted when starting the dev server
163
+ * Options accepted when starting the development server
164
+ *
165
+ * @example
166
+ * const devOptions: DevServerOptions = {
167
+ * hmr: true,
168
+ * scriptArgs: [],
169
+ * nodeArgs: ['--inspect'],
170
+ * clearScreen: true,
171
+ * env: { DEBUG: 'adonis:*' },
172
+ * hooks: {
173
+ * devServerStarted: [() => import('./dev_hooks')]
174
+ * }
175
+ * }
87
176
  */
88
177
  export type DevServerOptions = {
89
178
  /**
90
- * If the dev server should use HMR.
91
- *
92
- * Default:true
179
+ * Whether the dev server should use Hot Module Replacement (HMR)
180
+ * @default true
93
181
  */
94
182
  hmr?: boolean;
95
183
  /**
96
- * Arguments to pass to the "bin/server.js" file
97
- * executed a child process
184
+ * Arguments to pass to the "bin/server.js" file executed as a child process
98
185
  */
99
186
  scriptArgs: string[];
100
187
  /**
101
- * Arguments to pass to Node.js CLI when executing
102
- * the "bin/server.js" file
188
+ * Arguments to pass to Node.js CLI when executing the "bin/server.js" file
103
189
  */
104
190
  nodeArgs: string[];
105
191
  /**
106
- * Clear screen after every file change
192
+ * Whether to clear screen after every file change
107
193
  */
108
194
  clearScreen?: boolean;
109
195
  /**
110
- * Environment variables to share with the "bin/server.js"
111
- * file.
196
+ * Environment variables to share with the "bin/server.js" file
112
197
  */
113
198
  env?: NodeJS.ProcessEnv;
114
199
  } & AssemblerRcFile;
115
200
  /**
116
- * Options accepted by the test runner
201
+ * Options accepted by the test runner for configuring test execution
202
+ *
203
+ * @example
204
+ * const testOptions: TestRunnerOptions = {
205
+ * scriptArgs: ['--reporter', 'spec'],
206
+ * nodeArgs: ['--max-old-space-size=4096'],
207
+ * clearScreen: true,
208
+ * reporters: ['spec', 'json'],
209
+ * timeout: 30000,
210
+ * retries: 2,
211
+ * failed: false,
212
+ * filters: {
213
+ * suites: ['unit', 'integration'],
214
+ * tags: ['@slow']
215
+ * }
216
+ * }
117
217
  */
118
218
  export type TestRunnerOptions = {
119
219
  /**
120
- * Arguments to pass to the "bin/server.js" file
121
- * executed a child process
220
+ * Arguments to pass to the test script file executed as a child process
122
221
  */
123
222
  scriptArgs: string[];
124
223
  /**
125
- * Arguments to pass to Node.js CLI when executing
126
- * the "bin/server.js" file
224
+ * Arguments to pass to Node.js CLI when executing the test script
127
225
  */
128
226
  nodeArgs: string[];
129
227
  /**
130
- * Clear screen after every file change
228
+ * Whether to clear screen after every file change
131
229
  */
132
230
  clearScreen?: boolean;
133
231
  /**
134
- * Environment variables to share with the "bin/server.js"
135
- * file.
232
+ * Environment variables to share with the test script
136
233
  */
137
234
  env?: NodeJS.ProcessEnv;
138
235
  /**
139
- * Set the tests runner reporter via the CLI flag
236
+ * Test reporters to use (e.g., 'spec', 'json', 'tap')
140
237
  */
141
238
  reporters?: string[];
142
239
  /**
143
- * Set the tests global timeout via the CLI flag
240
+ * Global timeout for tests in milliseconds
144
241
  */
145
242
  timeout?: number;
146
243
  /**
147
- * Define retries via the CLI flag
244
+ * Number of times to retry failed tests
148
245
  */
149
246
  retries?: number;
150
247
  /**
151
- * Run only failed tests
248
+ * Whether to run only previously failed tests
152
249
  */
153
250
  failed?: boolean;
154
251
  /**
155
- * Filter arguments are provided as a key-value
156
- * pair, so that we can mutate them (if needed)
252
+ * Filter options for controlling which tests to run
157
253
  */
158
254
  filters: Partial<{
255
+ /** Specific test names to run */
159
256
  tests: string[];
257
+ /** Test suite names to run */
160
258
  suites: string[];
259
+ /** Test group names to run */
161
260
  groups: string[];
261
+ /** Specific test file patterns to run */
162
262
  files: string[];
263
+ /** Test tags to filter by */
163
264
  tags: string[];
164
265
  }>;
165
266
  } & AssemblerRcFile;
166
267
  /**
167
- * Options accepted by the project bundler
268
+ * Options accepted by the project bundler for production builds
269
+ * Extends AssemblerRcFile to inherit hooks and meta files configuration
270
+ *
271
+ * @example
272
+ * const bundlerOptions: BundlerOptions = {
273
+ * hooks: {
274
+ * buildStarting: [() => import('./build_hooks')]
275
+ * },
276
+ * metaFiles: [
277
+ * { pattern: 'public/**', reloadServer: false }
278
+ * ]
279
+ * }
168
280
  */
169
281
  export type BundlerOptions = AssemblerRcFile;
170
282
  /**
171
- * Keyboard shortcut definition
283
+ * Keyboard shortcut definition for development server interactions
284
+ *
285
+ * @example
286
+ * const shortcut: KeyboardShortcut = {
287
+ * key: 'r',
288
+ * description: 'restart server',
289
+ * handler: () => server.restart()
290
+ * }
172
291
  */
173
292
  export interface KeyboardShortcut {
293
+ /** The keyboard key that triggers this shortcut */
174
294
  key: string;
295
+ /** Human-readable description of what this shortcut does */
175
296
  description: string;
297
+ /** Function to execute when the shortcut is triggered */
176
298
  handler: () => void;
177
299
  }
178
300
  /**
179
- * Callbacks for keyboard shortcuts actions
301
+ * Callbacks for keyboard shortcuts actions in the development server
302
+ *
303
+ * @example
304
+ * const callbacks: KeyboardShortcutsCallbacks = {
305
+ * onRestart: () => devServer.restart(),
306
+ * onClear: () => process.stdout.write('\u001B[2J\u001B[0;0f'),
307
+ * onQuit: () => process.exit(0)
308
+ * }
180
309
  */
181
310
  export interface KeyboardShortcutsCallbacks {
311
+ /** Callback to restart the development server */
182
312
  onRestart: () => void;
313
+ /** Callback to clear the console screen */
183
314
  onClear: () => void;
315
+ /** Callback to quit the development server */
184
316
  onQuit: () => void;
185
317
  }
186
318
  /**
187
- * Shortcuts manager options
319
+ * Configuration options for the keyboard shortcuts manager
320
+ *
321
+ * @example
322
+ * const options: ShortcutsManagerOptions = {
323
+ * logger: cliui().logger,
324
+ * callbacks: {
325
+ * onRestart: () => devServer.restart(),
326
+ * onClear: () => console.clear(),
327
+ * onQuit: () => process.exit()
328
+ * }
329
+ * }
188
330
  */
189
331
  export interface ShortcutsManagerOptions {
332
+ /** Logger instance for displaying messages */
190
333
  logger: Logger;
334
+ /** Callback functions for different shortcut actions */
191
335
  callbacks: KeyboardShortcutsCallbacks;
192
336
  }
@@ -3,67 +3,280 @@ import { type AsyncOrSync, type LazyImport } from '@poppinss/utils/types';
3
3
  import { type Bundler } from '../bundler.ts';
4
4
  import { type DevServer } from '../dev_server.ts';
5
5
  import { type TestRunner } from '../test_runner.ts';
6
+ import { type RoutesListItem } from './code_scanners.ts';
7
+ import { type IndexGenerator } from '../index_generator/main.ts';
8
+ import { type RoutesScanner } from '../code_scanners/routes_scanner/main.ts';
6
9
  /**
7
- * Hooks executed by the file watcher.
10
+ * Defines a hook that can be either a lazy import or an object with a run method.
11
+ * This type provides flexibility in how hooks are defined and imported, supporting
12
+ * both dynamic imports for code splitting and direct object definitions.
13
+ *
14
+ * @template Fn - The function signature that the hook must conform to
15
+ *
16
+ * @example
17
+ * // Using lazy import
18
+ * const hook: DefineHook<(server: DevServer) => void> = () => import('./my-hook')
19
+ *
20
+ * // Using direct object
21
+ * const hook: DefineHook<(server: DevServer) => void> = {
22
+ * run: (server) => console.log('Hook executed')
23
+ * }
24
+ */
25
+ type DefineHook<Fn extends (...args: any) => any> = LazyImport<Fn> | {
26
+ run: Fn;
27
+ };
28
+ /**
29
+ * Common hooks executed by the dev-server, test runner and the bundler.
30
+ * These hooks are shared across all assembler operations and provide
31
+ * lifecycle management for initialization tasks.
32
+ *
33
+ * @example
34
+ * const commonHooks: CommonHooks = {
35
+ * init: [
36
+ * () => import('./hooks/create_barrel_files')
37
+ * ]
38
+ * }
39
+ */
40
+ export type CommonHooks = {
41
+ /**
42
+ * The hook is executed as the first step when assembler starts the
43
+ * dev-server, runs tests or creates a build. Use this hook to perform
44
+ * initialization tasks that are common across all operations.
45
+ *
46
+ * @param parent - The parent instance (DevServer, TestRunner, or Bundler)
47
+ */
48
+ init: DefineHook<(parent: DevServer | TestRunner | Bundler, indexGenerator: IndexGenerator) => AsyncOrSync<void>>[];
49
+ };
50
+ /**
51
+ * Hooks executed by the dev server around the router.
52
+ * These hooks provide lifecycle management for route scanning and processing.
53
+ *
54
+ * @example
55
+ * const routerHooks: RouterHooks = {
56
+ * routesCommitted: [
57
+ * () => import('./hooks/on_routes_committed')
58
+ * ],
59
+ * routesScanning: [
60
+ * () => import('./hooks/before_routes_scan')
61
+ * ],
62
+ * routesScanned: [
63
+ * () => import('./hooks/after_routes_scan')
64
+ * ]
65
+ * }
66
+ */
67
+ export type RouterHooks = {
68
+ /**
69
+ * The hook is executed when routes are committed by the dev server child
70
+ * process. Use this hook to react to route changes and perform related tasks.
71
+ *
72
+ * @param parent - The DevServer instance
73
+ * @param routes - Record of routes grouped by domain or method
74
+ */
75
+ routesCommitted: DefineHook<(parent: DevServer, routes: Record<string, RoutesListItem[]>) => AsyncOrSync<void>>[];
76
+ /**
77
+ * The hook is executed when dev server begins the routes scanning process.
78
+ * Use this hook to prepare for route scanning or modify scanner configuration.
79
+ *
80
+ * @param parent - The DevServer instance
81
+ * @param routesScanner - The RoutesScanner instance being used
82
+ */
83
+ routesScanning: DefineHook<(parent: DevServer, routesScanner: RoutesScanner) => AsyncOrSync<void>>[];
84
+ /**
85
+ * The hook is executed when routes scanning process has finished.
86
+ * Use this hook to process the scanned routes or clean up resources.
87
+ *
88
+ * @param parent - The DevServer instance
89
+ * @param routesScanner - The RoutesScanner instance that was used
90
+ */
91
+ routesScanned: DefineHook<(parent: DevServer, routesScanner: RoutesScanner) => AsyncOrSync<void>>[];
92
+ };
93
+ /**
94
+ * Hooks executed by the file watcher during development and testing.
8
95
  *
9
96
  * - In HMR mode, assembler will rely on hot-hook to notify about the filesystem changes.
10
97
  * - Otherwise, the inbuilt watcher of the DevServer or the TestsRunner will notify.
98
+ *
99
+ * @example
100
+ * const watcherHooks: WatcherHooks = {
101
+ * fileChanged: [
102
+ * () => import('./hooks/on_file_changed')
103
+ * ],
104
+ * fileAdded: [
105
+ * () => import('./hooks/on_file_added')
106
+ * ],
107
+ * fileRemoved: [
108
+ * () => import('./hooks/on_file_removed')
109
+ * ]
110
+ * }
11
111
  */
12
112
  export type WatcherHooks = {
13
113
  /**
14
- * The hook is executed after a file has been changed in the watch mode.
114
+ * The hook is executed after a file has been changed in watch mode.
115
+ * Provides information about the change source and reload behavior.
116
+ * Use this hook to react to file changes and trigger custom actions.
117
+ *
118
+ * @param filePath - The relative path to the changed file
119
+ * @param info - Information about the file change
120
+ * @param info.source - Source of the file change notification
121
+ * @param info.hotReloaded - Whether the file was hot reloaded without server restart
122
+ * @param info.fullReload - Whether a full server reload is required
123
+ * @param parent - The parent DevServer or TestRunner instance
15
124
  */
16
- fileChanged: LazyImport<(filePath: string, info: {
125
+ fileChanged: DefineHook<(relativePath: string, absolutePath: string, info: {
126
+ /** Source of the file change notification */
17
127
  source: 'hot-hook' | 'watcher';
128
+ /** Whether the file was hot reloaded without server restart */
18
129
  hotReloaded: boolean;
130
+ /** Whether a full server reload is required */
19
131
  fullReload: boolean;
20
- }, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
132
+ }, parent: DevServer | TestRunner) => AsyncOrSync<void>>[];
21
133
  /**
22
- * The hook is executed after a file has been added.
134
+ * The hook is executed after a file has been added to the filesystem.
135
+ * Use this hook to react to new files being added to the project.
136
+ *
137
+ * @param filePath - The absolute path to the added file
138
+ * @param server - The DevServer or TestRunner instance
23
139
  */
24
- fileAdded: LazyImport<(filePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
140
+ fileAdded: DefineHook<(relativePath: string, absolutePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
25
141
  /**
26
- * The hook is executed after a file has been removed.
142
+ * The hook is executed after a file has been removed from the filesystem.
143
+ * Use this hook to clean up resources or update caches when files are deleted.
144
+ *
145
+ * @param filePath - The absolute path to the removed file
146
+ * @param server - The DevServer or TestRunner instance
27
147
  */
28
- fileRemoved: LazyImport<(filePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
148
+ fileRemoved: DefineHook<(relativePath: string, absolutePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
29
149
  };
30
150
  /**
31
- * Hooks executed when running the dev server.
151
+ * Hooks executed when running the development server.
152
+ *
153
+ * @example
154
+ * const devServerHooks: DevServerHooks = {
155
+ * devServerStarting: [
156
+ * () => import('./hooks/before_dev_server_start')
157
+ * ],
158
+ * devServerStarted: [
159
+ * () => import('./hooks/after_dev_server_start')
160
+ * ]
161
+ * }
32
162
  */
33
163
  export type DevServerHooks = {
34
164
  /**
35
- * The hook is executed before the child process for the dev server
36
- * is started.
165
+ * The hook is executed before the child process for the dev server is started.
166
+ * Use this hook to perform setup tasks or modify server configuration.
167
+ *
168
+ * @param server - The DevServer instance that is about to start
37
169
  */
38
- devServerStarting: LazyImport<(server: DevServer) => AsyncOrSync<void>>[];
170
+ devServerStarting: DefineHook<(server: DevServer) => AsyncOrSync<void>>[];
39
171
  /**
40
172
  * The hook is executed after the child process has been started.
173
+ * Use this hook to display additional information or perform post-startup tasks.
174
+ *
175
+ * @param server - The DevServer instance that has started
176
+ * @param info - Server information containing port and host
177
+ * @param info.port - The port number the server is running on
178
+ * @param info.host - The host address the server is bound to
179
+ * @param uiInstructions - UI instructions for displaying server information
41
180
  */
42
- devServerStarted: LazyImport<(server: DevServer, uiInstructions: Instructions) => AsyncOrSync<void>>[];
181
+ devServerStarted: DefineHook<(server: DevServer, info: {
182
+ port: number;
183
+ host: string;
184
+ }, uiInstructions: Instructions) => AsyncOrSync<void>>[];
43
185
  };
44
186
  /**
45
187
  * Hooks executed when the production build is created.
188
+ *
189
+ * @example
190
+ * const bundlerHooks: BundlerHooks = {
191
+ * buildStarting: [
192
+ * () => import('./hooks/before_build')
193
+ * ],
194
+ * buildFinished: [
195
+ * () => import('./hooks/after_build')
196
+ * ]
197
+ * }
46
198
  */
47
199
  export type BundlerHooks = {
48
200
  /**
49
- * The hook is executed before we begin creating the production build
201
+ * The hook is executed before we begin creating the production build.
202
+ * Use this hook to perform pre-build tasks like asset optimization.
203
+ *
204
+ * @param server - The Bundler instance that will create the build
50
205
  */
51
- buildStarting: LazyImport<(server: Bundler) => AsyncOrSync<void>>[];
206
+ buildStarting: DefineHook<(server: Bundler) => AsyncOrSync<void>>[];
52
207
  /**
53
- * The hook is executed after the production build has been created
208
+ * The hook is executed after the production build has been created.
209
+ * Use this hook to perform post-build tasks or display build statistics.
210
+ *
211
+ * @param server - The Bundler instance that created the build
212
+ * @param uiInstructions - UI instructions for displaying build information
54
213
  */
55
- buildFinished: LazyImport<(server: Bundler, uiInstructions: Instructions) => AsyncOrSync<void>>[];
214
+ buildFinished: DefineHook<(server: Bundler, uiInstructions: Instructions) => AsyncOrSync<void>>[];
56
215
  };
57
216
  /**
58
- * Hooks executed when running the tests
217
+ * Hooks executed when running the test suite.
218
+ *
219
+ * @example
220
+ * const testRunnerHooks: TestRunnerHooks = {
221
+ * testsStarting: [
222
+ * () => import('./hooks/before_tests')
223
+ * ],
224
+ * testsFinished: [
225
+ * () => import('./hooks/after_tests')
226
+ * ]
227
+ * }
59
228
  */
60
229
  export type TestRunnerHooks = {
61
230
  /**
62
- * The hook is executed before we begin executing the tests
231
+ * The hook is executed before we begin executing the tests.
232
+ * Use this hook to set up test databases or perform pre-test setup.
233
+ *
234
+ * @param server - The TestRunner instance that will execute the tests
63
235
  */
64
- testsStarting: LazyImport<(server: TestRunner) => AsyncOrSync<void>>[];
236
+ testsStarting: DefineHook<(server: TestRunner) => AsyncOrSync<void>>[];
65
237
  /**
66
- * The hook is executed after the tests have been executed
238
+ * The hook is executed after the tests have been executed.
239
+ * Use this hook to clean up resources or generate test reports.
240
+ *
241
+ * @param server - The TestRunner instance that executed the tests
67
242
  */
68
- testsFinished: LazyImport<(server: TestRunner) => AsyncOrSync<void>>[];
243
+ testsFinished: DefineHook<(server: TestRunner) => AsyncOrSync<void>>[];
69
244
  };
245
+ /**
246
+ * Combined type representing all available hooks across the assembler ecosystem.
247
+ * This intersection type merges all hook categories into a single type for
248
+ * comprehensive hook management and type safety.
249
+ *
250
+ * @example
251
+ * ```js
252
+ * const allHooks: AllHooks = {
253
+ * init: [() => import('./hooks/init')],
254
+ * fileChanged: [() => import('./hooks/file_changed')],
255
+ * devServerStarted: [() => import('./hooks/dev_server_started')],
256
+ * buildFinished: [() => import('./hooks/build_finished')],
257
+ * testsFinished: [() => import('./hooks/tests_finished')],
258
+ * routesCommitted: [() => import('./hooks/routes_committed')]
259
+ * }
260
+ * ```
261
+ */
262
+ export type AllHooks = CommonHooks & WatcherHooks & DevServerHooks & BundlerHooks & TestRunnerHooks & RouterHooks;
263
+ /**
264
+ * Utility type that extracts the parameter types for a specific hook.
265
+ * This type helps maintain type safety when working with hook callbacks
266
+ * by providing the exact parameter signature for any given hook name.
267
+ *
268
+ * @template Hook - The name of the hook to extract parameters for
269
+ *
270
+ * @example
271
+ * ```js
272
+ * // Get parameters for the fileChanged hook
273
+ * type FileChangedParams = HookParams<'fileChanged'>
274
+ * // Result: [string, string, {...}, DevServer | TestRunner]
275
+ *
276
+ * // Get parameters for the devServerStarted hook
277
+ * type DevServerStartedParams = HookParams<'devServerStarted')
278
+ * // Result: [DevServer, {port: number, host: string}, Instructions]
279
+ * ```
280
+ */
281
+ export type HookParams<Hook extends keyof AllHooks> = AllHooks[Hook][number] extends DefineHook<infer A> ? Parameters<A> : never;
282
+ export {};