@adonisjs/assembler 8.0.0-next.3 → 8.0.0-next.30

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 (39) hide show
  1. package/README.md +87 -59
  2. package/build/codemod_exception-vyN1VXuX.js +137 -0
  3. package/build/helpers-DDurYRsZ.js +72 -0
  4. package/build/index.d.ts +4 -0
  5. package/build/index.js +925 -1319
  6. package/build/main-BeV45LeF.js +246 -0
  7. package/build/main-CknPN3rJ.js +188 -0
  8. package/build/src/bundler.d.ts +44 -3
  9. package/build/src/code_scanners/routes_scanner/main.d.ts +63 -11
  10. package/build/src/code_scanners/routes_scanner/main.js +4 -0
  11. package/build/src/code_scanners/routes_scanner/validator_extractor.d.ts +12 -4
  12. package/build/src/code_transformer/main.d.ts +53 -43
  13. package/build/src/code_transformer/main.js +354 -599
  14. package/build/src/code_transformer/rc_file_transformer.d.ts +83 -5
  15. package/build/src/debug.d.ts +13 -1
  16. package/build/src/dev_server.d.ts +92 -17
  17. package/build/src/exceptions/codemod_exception.d.ts +178 -0
  18. package/build/src/file_buffer.d.ts +87 -0
  19. package/build/src/file_system.d.ts +46 -8
  20. package/build/src/helpers.d.ts +79 -4
  21. package/build/src/helpers.js +2 -0
  22. package/build/src/index_generator/main.d.ts +68 -0
  23. package/build/src/index_generator/main.js +3 -0
  24. package/build/src/index_generator/source.d.ts +60 -0
  25. package/build/src/paths_resolver.d.ts +29 -3
  26. package/build/src/shortcuts_manager.d.ts +42 -4
  27. package/build/src/test_runner.d.ts +57 -12
  28. package/build/src/types/code_scanners.d.ts +160 -30
  29. package/build/src/types/code_transformer.d.ts +69 -19
  30. package/build/src/types/common.d.ts +233 -55
  31. package/build/src/types/hooks.d.ts +238 -22
  32. package/build/src/types/main.d.ts +15 -1
  33. package/build/src/types/main.js +1 -0
  34. package/build/src/utils.d.ts +96 -15
  35. package/build/src/virtual_file_system.d.ts +112 -0
  36. package/build/virtual_file_system-bGeoWsK-.js +285 -0
  37. package/package.json +46 -36
  38. package/build/chunk-RR4HCA4M.js +0 -7
  39. package/build/src/ast_file_system.d.ts +0 -17
@@ -1,192 +1,370 @@
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 StringBuilder from '@poppinss/utils/string_builder';
4
+ import { type AllHooks } from './hooks.ts';
5
+ import { type FileBuffer } from '../file_buffer.ts';
6
+ import { type VirtualFileSystem } from '../virtual_file_system.ts';
7
+ import { type FilterPredicate } from 'fdir';
8
+ /**
9
+ * Recursive file tree structure for representing nested directory hierarchies
10
+ */
11
+ export type RecursiveFileTree = {
12
+ [key: string]: string | RecursiveFileTree;
13
+ };
14
+ /**
15
+ * Options accepted by the VirtualFileSystem class
16
+ */
17
+ export type VirtualFileSystemOptions = {
18
+ glob?: string[];
19
+ filter?: FilterPredicate;
20
+ };
21
+ /**
22
+ * Source configuration accepted by the index generator
23
+ */
24
+ export type IndexGeneratorSourceConfig = ({
25
+ exportName: string;
26
+ as: 'barrelFile';
27
+ /**
28
+ * Disable the use of lazy imports and instead import the
29
+ * files using the import expression
30
+ */
31
+ disableLazyImports?: boolean;
32
+ } | {
33
+ as: (vfs: VirtualFileSystem, buffer: FileBuffer, config: IndexGeneratorSourceConfig, helpers: {
34
+ toImportPath(filePath: string): string;
35
+ }) => void;
36
+ }) & {
37
+ computeBaseName?: (baseName: StringBuilder) => StringBuilder;
38
+ source: string;
39
+ output: string;
40
+ importAlias?: string;
41
+ removeSuffix?: string;
42
+ skipSegments?: string[];
43
+ } & VirtualFileSystemOptions;
4
44
  /**
5
45
  * Marks a given optional property as required
46
+ *
47
+ * @template T - The source type
48
+ * @template K - The keys from T that should be made required
49
+ *
50
+ * @example
51
+ * type User = { name?: string; email?: string; age: number }
52
+ * type UserWithName = AsRequired<User, 'name'> // { name: string; email?: string; age: number }
6
53
  */
7
54
  export type AsRequired<T, K extends keyof T> = Prettify<Omit<T, K> & Required<{
8
55
  [O in K]: T[K];
9
56
  }>>;
10
57
  /**
11
- * Represents an import statement
58
+ * Represents an import statement parsed from TypeScript/JavaScript code
59
+ *
60
+ * @example
61
+ * // For: import { User } from './models/user'
62
+ * const importInfo: Import = {
63
+ * specifier: './models/user',
64
+ * isConstant: true,
65
+ * clause: { type: 'named', value: 'User' }
66
+ * }
12
67
  */
13
68
  export type Import = {
69
+ /** The module specifier being imported from */
14
70
  specifier: string;
71
+ /** Whether the import specifier is a constant string literal */
15
72
  isConstant: boolean;
73
+ /** The import clause details */
16
74
  clause: {
75
+ /** The type of import clause */
17
76
  type: 'namespace' | 'default' | 'named';
77
+ /** The imported identifier name */
18
78
  value: string;
79
+ /** Optional alias for named imports with 'as' keyword */
19
80
  alias?: string;
20
81
  };
21
82
  };
22
83
  /**
23
84
  * File inspected by the filesystem based upon the provided globs
24
85
  * and the current file path
86
+ *
87
+ * @example
88
+ * const inspectedFile: InspectedFile = {
89
+ * fileType: 'script',
90
+ * reloadServer: true,
91
+ * unixRelativePath: 'app/controllers/users_controller.ts',
92
+ * unixAbsolutePath: '/project/app/controllers/users_controller.ts'
93
+ * }
25
94
  */
26
95
  export type InspectedFile = {
96
+ /** The category of the file based on its purpose */
27
97
  fileType: 'script' | 'meta' | 'test';
98
+ /** Whether changes to this file should trigger server reload */
28
99
  reloadServer: boolean;
100
+ /** Unix-style relative path from project root */
29
101
  unixRelativePath: string;
102
+ /** Unix-style absolute path to the file */
30
103
  unixAbsolutePath: string;
31
104
  };
32
105
  /**
33
106
  * Subset of properties assembler needs from the "adonisrc.ts" file.
107
+ * Contains configuration for file watching, hooks, and test suites.
108
+ *
109
+ * @example
110
+ * const rcFile: AssemblerRcFile = {
111
+ * metaFiles: [
112
+ * { pattern: 'config/**', reloadServer: true }
113
+ * ],
114
+ * hooks: {
115
+ * devServerStarted: [() => import('./hooks/server_started')]
116
+ * },
117
+ * suites: [
118
+ * { name: 'unit', files: ['tests/unit/**\/*.spec.ts'] }
119
+ * ]
120
+ * }
34
121
  */
35
122
  export type AssemblerRcFile = {
36
123
  /**
37
- * An array of metaFiles glob patterns to watch
124
+ * An array of metaFiles glob patterns to watch for changes
38
125
  */
39
126
  metaFiles?: {
127
+ /** Glob pattern to match files */
40
128
  pattern: string;
129
+ /** Whether to reload server when these files change */
41
130
  reloadServer: boolean;
42
131
  }[];
43
132
  /**
44
- * Hooks to execute at different stages.
133
+ * Hooks to execute at different stages of development and build processes
45
134
  */
46
- hooks?: Partial<WatcherHooks & DevServerHooks & BundlerHooks & TestRunnerHooks>;
135
+ hooks?: Partial<AllHooks>;
47
136
  /**
48
- * An array of suites for which to run tests
137
+ * An array of test suites configuration
49
138
  */
50
139
  suites?: {
140
+ /** Name of the test suite */
51
141
  name: string;
142
+ /** Glob pattern(s) for test files in this suite */
52
143
  files: string | string[];
53
144
  }[];
54
145
  };
55
146
  /**
56
- * Options needed to run a script file
147
+ * Options needed to run a script file as a child process
148
+ *
149
+ * @example
150
+ * const options: RunScriptOptions = {
151
+ * script: 'bin/server.ts',
152
+ * scriptArgs: ['--watch'],
153
+ * nodeArgs: ['--loader', 'ts-node/esm'],
154
+ * stdio: 'inherit',
155
+ * env: { NODE_ENV: 'development' },
156
+ * reject: true
157
+ * }
57
158
  */
58
159
  export type RunScriptOptions = {
59
- /**
60
- * Script to run
61
- */
160
+ /** Path to the script file to run */
62
161
  script: string;
63
- /**
64
- * Arguments to pass to the script
65
- */
162
+ /** Arguments to pass to the script */
66
163
  scriptArgs: string[];
67
- /**
68
- * Arguments to pass to NodeJS CLI
69
- */
164
+ /** Arguments to pass to the Node.js CLI */
70
165
  nodeArgs: string[];
71
- /**
72
- * Standard input ouput stream options
73
- */
166
+ /** Standard input/output stream options */
74
167
  stdio?: 'pipe' | 'inherit';
75
- /**
76
- * Environment variables to pass to the child process
77
- */
168
+ /** Environment variables to pass to the child process */
78
169
  env?: NodeJS.ProcessEnv;
79
- /**
80
- * Whether or not to reject the promise. Defaults
81
- * false
82
- */
170
+ /** Whether to reject the promise on script failure (defaults to false) */
83
171
  reject?: boolean;
84
172
  };
85
173
  /**
86
- * Options accepted when starting the dev server
174
+ * Options accepted when starting the development server
175
+ *
176
+ * @example
177
+ * const devOptions: DevServerOptions = {
178
+ * hmr: true,
179
+ * scriptArgs: [],
180
+ * nodeArgs: ['--inspect'],
181
+ * clearScreen: true,
182
+ * env: { DEBUG: 'adonis:*' },
183
+ * hooks: {
184
+ * devServerStarted: [() => import('./dev_hooks')]
185
+ * }
186
+ * }
87
187
  */
88
188
  export type DevServerOptions = {
89
189
  /**
90
- * If the dev server should use HMR.
91
- *
92
- * Default:true
190
+ * Whether the dev server should use Hot Module Replacement (HMR)
191
+ * @default true
93
192
  */
94
193
  hmr?: boolean;
95
194
  /**
96
- * Arguments to pass to the "bin/server.js" file
97
- * executed a child process
195
+ * Arguments to pass to the "bin/server.js" file executed as a child process
98
196
  */
99
197
  scriptArgs: string[];
100
198
  /**
101
- * Arguments to pass to Node.js CLI when executing
102
- * the "bin/server.js" file
199
+ * Arguments to pass to Node.js CLI when executing the "bin/server.js" file
103
200
  */
104
201
  nodeArgs: string[];
105
202
  /**
106
- * Clear screen after every file change
203
+ * Whether to clear screen after every file change
107
204
  */
108
205
  clearScreen?: boolean;
109
206
  /**
110
- * Environment variables to share with the "bin/server.js"
111
- * file.
207
+ * Environment variables to share with the "bin/server.js" file
112
208
  */
113
209
  env?: NodeJS.ProcessEnv;
114
210
  } & AssemblerRcFile;
115
211
  /**
116
- * Options accepted by the test runner
212
+ * Options accepted by the test runner for configuring test execution
213
+ *
214
+ * @example
215
+ * const testOptions: TestRunnerOptions = {
216
+ * scriptArgs: ['--reporter', 'spec'],
217
+ * nodeArgs: ['--max-old-space-size=4096'],
218
+ * clearScreen: true,
219
+ * reporters: ['spec', 'json'],
220
+ * timeout: 30000,
221
+ * retries: 2,
222
+ * failed: false,
223
+ * filters: {
224
+ * suites: ['unit', 'integration'],
225
+ * tags: ['@slow']
226
+ * }
227
+ * }
117
228
  */
118
229
  export type TestRunnerOptions = {
119
230
  /**
120
- * Arguments to pass to the "bin/server.js" file
121
- * executed a child process
231
+ * Arguments to pass to the test script file executed as a child process
122
232
  */
123
233
  scriptArgs: string[];
124
234
  /**
125
- * Arguments to pass to Node.js CLI when executing
126
- * the "bin/server.js" file
235
+ * Arguments to pass to Node.js CLI when executing the test script
127
236
  */
128
237
  nodeArgs: string[];
129
238
  /**
130
- * Clear screen after every file change
239
+ * Whether to clear screen after every file change
131
240
  */
132
241
  clearScreen?: boolean;
133
242
  /**
134
- * Environment variables to share with the "bin/server.js"
135
- * file.
243
+ * Environment variables to share with the test script
136
244
  */
137
245
  env?: NodeJS.ProcessEnv;
138
246
  /**
139
- * Set the tests runner reporter via the CLI flag
247
+ * Test reporters to use (e.g., 'spec', 'json', 'tap')
140
248
  */
141
249
  reporters?: string[];
142
250
  /**
143
- * Set the tests global timeout via the CLI flag
251
+ * Global timeout for tests in milliseconds
144
252
  */
145
253
  timeout?: number;
146
254
  /**
147
- * Define retries via the CLI flag
255
+ * Number of times to retry failed tests
148
256
  */
149
257
  retries?: number;
150
258
  /**
151
- * Run only failed tests
259
+ * Whether to run only previously failed tests
152
260
  */
153
261
  failed?: boolean;
154
262
  /**
155
- * Filter arguments are provided as a key-value
156
- * pair, so that we can mutate them (if needed)
263
+ * Filter options for controlling which tests to run
157
264
  */
158
265
  filters: Partial<{
266
+ /** Specific test names to run */
159
267
  tests: string[];
268
+ /** Test suite names to run */
160
269
  suites: string[];
270
+ /** Test group names to run */
161
271
  groups: string[];
272
+ /** Specific test file patterns to run */
162
273
  files: string[];
274
+ /** Test tags to filter by */
163
275
  tags: string[];
164
276
  }>;
165
277
  } & AssemblerRcFile;
166
278
  /**
167
- * Options accepted by the project bundler
279
+ * Options accepted by the project bundler for production builds
280
+ * Extends AssemblerRcFile to inherit hooks and meta files configuration
281
+ *
282
+ * @example
283
+ * const bundlerOptions: BundlerOptions = {
284
+ * hooks: {
285
+ * buildStarting: [() => import('./build_hooks')]
286
+ * },
287
+ * metaFiles: [
288
+ * { pattern: 'public/**', reloadServer: false }
289
+ * ]
290
+ * }
168
291
  */
169
292
  export type BundlerOptions = AssemblerRcFile;
170
293
  /**
171
- * Keyboard shortcut definition
294
+ * Keyboard shortcut definition for development server interactions
295
+ *
296
+ * @example
297
+ * const shortcut: KeyboardShortcut = {
298
+ * key: 'r',
299
+ * description: 'restart server',
300
+ * handler: () => server.restart()
301
+ * }
172
302
  */
173
303
  export interface KeyboardShortcut {
304
+ /** The keyboard key that triggers this shortcut */
174
305
  key: string;
306
+ /** Human-readable description of what this shortcut does */
175
307
  description: string;
308
+ /** Function to execute when the shortcut is triggered */
176
309
  handler: () => void;
177
310
  }
178
311
  /**
179
- * Callbacks for keyboard shortcuts actions
312
+ * Callbacks for keyboard shortcuts actions in the development server
313
+ *
314
+ * @example
315
+ * const callbacks: KeyboardShortcutsCallbacks = {
316
+ * onRestart: () => devServer.restart(),
317
+ * onClear: () => process.stdout.write('\u001B[2J\u001B[0;0f'),
318
+ * onQuit: () => process.exit(0)
319
+ * }
180
320
  */
181
321
  export interface KeyboardShortcutsCallbacks {
322
+ /** Callback to restart the development server */
182
323
  onRestart: () => void;
324
+ /** Callback to clear the console screen */
183
325
  onClear: () => void;
326
+ /** Callback to quit the development server */
184
327
  onQuit: () => void;
185
328
  }
186
329
  /**
187
- * Shortcuts manager options
330
+ * Configuration options for the keyboard shortcuts manager
331
+ *
332
+ * @example
333
+ * const options: ShortcutsManagerOptions = {
334
+ * logger: cliui().logger,
335
+ * callbacks: {
336
+ * onRestart: () => devServer.restart(),
337
+ * onClear: () => console.clear(),
338
+ * onQuit: () => process.exit()
339
+ * }
340
+ * }
188
341
  */
189
342
  export interface ShortcutsManagerOptions {
343
+ /** Logger instance for displaying messages */
190
344
  logger: Logger;
345
+ /** Callback functions for different shortcut actions */
191
346
  callbacks: KeyboardShortcutsCallbacks;
192
347
  }
348
+ export type AdonisJSServerReadyMessage = {
349
+ isAdonisJS: true;
350
+ environment: 'web';
351
+ port: number;
352
+ host: string;
353
+ duration?: [number, number];
354
+ };
355
+ export type AdonisJSRoutesSharedMessage = {
356
+ isAdonisJS: true;
357
+ routesFileLocation: string;
358
+ };
359
+ export type HotHookMessage = {
360
+ type: 'hot-hook:full-reload';
361
+ path: string;
362
+ shouldBeReloadable?: boolean;
363
+ } | {
364
+ type: 'hot-hook:invalidated';
365
+ paths: string[];
366
+ } | {
367
+ type: 'hot-hook:file-changed';
368
+ path: string;
369
+ action: 'change' | 'add' | 'unlink';
370
+ };