@adonisjs/assembler 8.0.0-next.0 → 8.0.0-next.10

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 (34) hide show
  1. package/README.md +108 -25
  2. package/build/chunk-EWPEL2ET.js +433 -0
  3. package/build/chunk-MVIHDM7A.js +392 -0
  4. package/build/chunk-TIKQQRMX.js +116 -0
  5. package/build/index.d.ts +3 -0
  6. package/build/index.js +743 -381
  7. package/build/src/bundler.d.ts +44 -3
  8. package/build/src/code_scanners/routes_scanner/main.d.ts +119 -0
  9. package/build/src/code_scanners/routes_scanner/main.js +445 -0
  10. package/build/src/code_scanners/routes_scanner/validator_extractor.d.ts +26 -0
  11. package/build/src/code_transformer/main.d.ts +44 -38
  12. package/build/src/code_transformer/main.js +123 -82
  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 +68 -0
  17. package/build/src/file_system.d.ts +45 -7
  18. package/build/src/helpers.d.ts +115 -0
  19. package/build/src/helpers.js +16 -0
  20. package/build/src/index_generator/main.d.ts +68 -0
  21. package/build/src/index_generator/main.js +7 -0
  22. package/build/src/index_generator/source.d.ts +60 -0
  23. package/build/src/paths_resolver.d.ts +40 -0
  24. package/build/src/shortcuts_manager.d.ts +62 -0
  25. package/build/src/test_runner.d.ts +56 -10
  26. package/build/src/types/code_scanners.d.ts +229 -0
  27. package/build/src/types/code_transformer.d.ts +61 -19
  28. package/build/src/types/common.d.ts +247 -51
  29. package/build/src/types/hooks.d.ts +238 -21
  30. package/build/src/types/main.d.ts +15 -1
  31. package/build/src/utils.d.ts +93 -13
  32. package/build/src/virtual_file_system.d.ts +112 -0
  33. package/package.json +37 -21
  34. package/build/chunk-RR4HCA4M.js +0 -7
@@ -4,19 +4,29 @@ import type { TestRunnerOptions } from './types/common.ts';
4
4
  * Exposes the API to run Japa tests and optionally watch for file
5
5
  * changes to re-run the tests.
6
6
  *
7
- * The watch mode functions as follows.
7
+ * The TestRunner provides intelligent test execution with watch mode capabilities.
8
+ * When files change, it can selectively run specific tests or the entire suite
9
+ * based on what changed.
8
10
  *
11
+ * The watch mode functions as follows:
9
12
  * - If the changed file is a test file, then only tests for that file
10
13
  * will be re-run.
11
14
  * - Otherwise, all tests will re-run with respect to the initial
12
15
  * filters applied when running the `node ace test` command.
16
+ *
17
+ * @example
18
+ * const testRunner = new TestRunner(cwd, { suites: [], hooks: [] })
19
+ * await testRunner.run()
20
+ *
21
+ * @example
22
+ * // Run tests in watch mode
23
+ * const testRunner = new TestRunner(cwd, { suites: [], hooks: [] })
24
+ * await testRunner.runAndWatch(ts, { poll: false })
13
25
  */
14
26
  export declare class TestRunner {
15
27
  #private;
16
- cwd: URL;
17
- options: TestRunnerOptions;
18
28
  /**
19
- * CLI UI to log colorful messages
29
+ * CLI UI instance for displaying colorful messages and progress information
20
30
  */
21
31
  ui: {
22
32
  colors: import("@poppinss/colors/types").Colors;
@@ -43,27 +53,63 @@ export declare class TestRunner {
43
53
  * The script file to run as a child process
44
54
  */
45
55
  scriptFile: string;
56
+ /**
57
+ * The current working directory URL
58
+ */
59
+ cwd: URL;
60
+ /**
61
+ * The current working directory path as a string
62
+ */
63
+ cwdPath: string;
64
+ /**
65
+ * Test runner configuration options including filters, reporters, and hooks
66
+ */
67
+ options: TestRunnerOptions;
68
+ /**
69
+ * Create a new TestRunner instance
70
+ *
71
+ * @param cwd - The current working directory URL
72
+ * @param options - Test runner configuration options
73
+ */
46
74
  constructor(cwd: URL, options: TestRunnerOptions);
47
75
  /**
48
- * Add listener to get notified when dev server is
49
- * closed
76
+ * Add listener to get notified when test runner is closed
77
+ *
78
+ * @param callback - Function to call when test runner closes
79
+ * @returns This TestRunner instance for method chaining
50
80
  */
51
81
  onClose(callback: (exitCode: number) => any): this;
52
82
  /**
53
- * Add listener to get notified when dev server exists
54
- * with an error
83
+ * Add listener to get notified when test runner encounters an error
84
+ *
85
+ * @param callback - Function to call when test runner encounters an error
86
+ * @returns This TestRunner instance for method chaining
55
87
  */
56
88
  onError(callback: (error: any) => any): this;
57
89
  /**
58
90
  * Close watchers and running child processes
91
+ *
92
+ * Cleans up file system watchers and terminates any running test
93
+ * processes to ensure graceful shutdown.
59
94
  */
60
95
  close(): Promise<void>;
61
96
  /**
62
- * Runs tests
97
+ * Runs tests once without watching for file changes
98
+ *
99
+ * Executes the test suite a single time and exits. This is the
100
+ * equivalent of running tests in CI/CD environments.
63
101
  */
64
102
  run(): Promise<void>;
65
103
  /**
66
- * Run tests in watch mode
104
+ * Run tests in watch mode and re-run them when files change
105
+ *
106
+ * Starts the test runner in watch mode, monitoring the file system
107
+ * for changes and automatically re-running tests when relevant files
108
+ * are modified. Uses intelligent filtering to run only affected tests
109
+ * when possible.
110
+ *
111
+ * @param ts - TypeScript module reference for parsing configuration
112
+ * @param options - Watch options including polling mode for file system monitoring
67
113
  */
68
114
  runAndWatch(ts: typeof tsStatic, options?: {
69
115
  poll: boolean;
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Represents a controller that has been scanned and analyzed by the routes scanner.
3
+ * Contains metadata about the controller class and the specific method being called.
4
+ *
5
+ * @example
6
+ * const controller: ScannedController = {
7
+ * name: 'UsersController',
8
+ * path: '/project/app/controllers/users_controller.ts',
9
+ * method: 'index',
10
+ * import: {
11
+ * type: 'default',
12
+ * specifier: '#controllers/users_controller',
13
+ * value: 'UsersController'
14
+ * }
15
+ * }
16
+ */
17
+ export type ScannedController = {
18
+ /** The name of the controller class */
19
+ name: string;
20
+ /** Absolute file path to the controller */
21
+ path: string;
22
+ /** The method name being called on the controller */
23
+ method: string;
24
+ /** Import information for the controller */
25
+ import: {
26
+ /** Import type (always 'default' for controllers) */
27
+ type: 'default';
28
+ /** Import specifier used to import the controller */
29
+ specifier: string;
30
+ /** The imported value name */
31
+ value: string;
32
+ };
33
+ };
34
+ /**
35
+ * Represents a validator that has been extracted from controller methods.
36
+ * Contains information about how the validator is imported and used.
37
+ *
38
+ * @example
39
+ * const validator: ScannedValidator = {
40
+ * name: 'createUserValidator',
41
+ * import: {
42
+ * type: 'named',
43
+ * specifier: '#validators/user_validators',
44
+ * value: 'createUserValidator'
45
+ * }
46
+ * }
47
+ */
48
+ export type ScannedValidator = {
49
+ /** The name/identifier of the validator */
50
+ name: string;
51
+ /** Import information for the validator */
52
+ import: {
53
+ /** The type of import (namespace, default, or named) */
54
+ type: 'namespace' | 'default' | 'named';
55
+ /** The module specifier being imported from */
56
+ specifier: string;
57
+ /** The imported value name */
58
+ value: string;
59
+ };
60
+ };
61
+ /**
62
+ * Output of a scanned route containing all extracted metadata including
63
+ * controller information, validators, request/response types, and route patterns.
64
+ *
65
+ * @example
66
+ * const scannedRoute: ScannedRoute = {
67
+ * name: 'users.store',
68
+ * methods: ['POST'],
69
+ * domain: 'root',
70
+ * pattern: '/users',
71
+ * tokens: [{ val: '/users', old: '/users', type: 0, end: '' }],
72
+ * request: {
73
+ * type: 'Infer<typeof createUserValidator>',
74
+ * imports: ['import { Infer } from "@vinejs/vine/types"']
75
+ * },
76
+ * response: {
77
+ * type: 'ReturnType<UsersController["store"]>',
78
+ * imports: []
79
+ * },
80
+ * validators: [{
81
+ * name: 'createUserValidator',
82
+ * import: { type: 'named', specifier: '#validators/user', value: 'createUserValidator' }
83
+ * }],
84
+ * controller: {
85
+ * name: 'UsersController',
86
+ * method: 'store',
87
+ * path: '/app/controllers/users_controller.ts',
88
+ * import: { type: 'default', specifier: '#controllers/users_controller', value: 'UsersController' }
89
+ * }
90
+ * }
91
+ */
92
+ export type ScannedRoute = {
93
+ /**
94
+ * A unique name for the route provided by AdonisJS http-server.
95
+ * May be duplicate across different domains.
96
+ */
97
+ name: string;
98
+ /**
99
+ * HTTP methods for which the route is defined (GET, POST, PUT, etc.)
100
+ */
101
+ methods: string[];
102
+ /**
103
+ * The domain on which the route is registered (typically 'root')
104
+ */
105
+ domain: string;
106
+ /**
107
+ * The route pattern with parameter placeholders (e.g., '/users/:id')
108
+ */
109
+ pattern: string;
110
+ /**
111
+ * Route tokens that can be used for constructing URIs without parsing the pattern.
112
+ * Contains information about static and dynamic segments.
113
+ */
114
+ tokens: {
115
+ val: string;
116
+ old: string;
117
+ type: 0 | 1 | 2 | 3;
118
+ end: string;
119
+ }[];
120
+ /**
121
+ * Inferred request data type accepted by the route.
122
+ * Generated when the route uses a controller with validators.
123
+ */
124
+ request?: {
125
+ /** TypeScript type definition for the request data */
126
+ type: string;
127
+ /** Import statements needed for the type definition */
128
+ imports: string[];
129
+ };
130
+ /**
131
+ * Inferred response type returned by the route.
132
+ * Generated when the route uses a controller method.
133
+ */
134
+ response?: {
135
+ /** TypeScript type definition for the response data */
136
+ type: string;
137
+ /** Import statements needed for the type definition */
138
+ imports: string[];
139
+ };
140
+ /**
141
+ * Extracted validator information from the controller method.
142
+ * Only present when using controller-based routes with validation.
143
+ */
144
+ validators?: ScannedValidator[];
145
+ /**
146
+ * Extracted controller information including class and method details.
147
+ * Only present when using controller-based routes.
148
+ */
149
+ controller?: ScannedController;
150
+ };
151
+ /**
152
+ * The route data structure accepted by the routes scanner when initiating
153
+ * the scanning process. This represents the raw route definition before analysis.
154
+ *
155
+ * @example
156
+ * const routeItem: RoutesListItem = {
157
+ * name: 'users.store',
158
+ * pattern: '/users',
159
+ * domain: 'root',
160
+ * methods: ['POST'],
161
+ * controllerReference: {
162
+ * importExpression: "() => import('#controllers/users_controller')",
163
+ * method: 'store'
164
+ * },
165
+ * tokens: [{ val: '/users', old: '/users', type: 0, end: '' }]
166
+ * }
167
+ */
168
+ export type RoutesListItem = {
169
+ /** Optional unique name for the route */
170
+ name?: string;
171
+ /** Route pattern with parameter placeholders */
172
+ pattern: string;
173
+ /** Domain on which the route is registered */
174
+ domain: string;
175
+ /** HTTP methods accepted by this route */
176
+ methods: string[];
177
+ /** Controller reference information (if controller-based route) */
178
+ controllerReference?: {
179
+ /** Dynamic import expression for the controller */
180
+ importExpression: string;
181
+ /** Specific controller method to call */
182
+ method?: string;
183
+ };
184
+ /** Parsed route tokens for URI construction */
185
+ tokens: {
186
+ val: string;
187
+ old: string;
188
+ type: 0 | 1 | 2 | 3;
189
+ end: string;
190
+ }[];
191
+ };
192
+ /**
193
+ * Configuration rules accepted by the routes scanner to customize
194
+ * the scanning behavior and override type inference.
195
+ *
196
+ * @example
197
+ * const rules: RoutesScannerRules = {
198
+ * skip: ['admin.dashboard', 'health.check'],
199
+ * response: {
200
+ * 'users.index': {
201
+ * type: 'PaginatedResponse<User[]>',
202
+ * imports: ['import { User } from "#models/user"']
203
+ * }
204
+ * },
205
+ * request: {
206
+ * 'users.store': {
207
+ * type: 'CreateUserRequest',
208
+ * imports: ['import { CreateUserRequest } from "#types/requests"']
209
+ * }
210
+ * }
211
+ * }
212
+ */
213
+ export type RoutesScannerRules = {
214
+ /**
215
+ * An array of route names or controller+method paths to skip from processing.
216
+ * Useful for excluding routes that don't need type generation.
217
+ */
218
+ skip: string[];
219
+ /**
220
+ * Define custom response types for specific routes by their name
221
+ * or controller+method path. Overrides automatic type inference.
222
+ */
223
+ response: Record<string, ScannedRoute['response']>;
224
+ /**
225
+ * Define custom request data types for specific routes by their name
226
+ * or controller+method path. Overrides automatic type inference.
227
+ */
228
+ request: Record<string, ScannedRoute['response']>;
229
+ };
@@ -1,61 +1,103 @@
1
1
  /**
2
- * Entry to add a middleware to a given middleware stack
3
- * via the CodeTransformer
2
+ * Entry to add a middleware to a given middleware stack via the CodeTransformer.
3
+ * Represents middleware configuration for server, router, or named middleware stacks.
4
+ *
5
+ * @example
6
+ * const corsMiddleware: MiddlewareNode = {
7
+ * path: '@adonisjs/cors/cors_middleware',
8
+ * position: 'before'
9
+ * }
10
+ *
11
+ * const namedMiddleware: MiddlewareNode = {
12
+ * name: 'auth',
13
+ * path: '#middleware/auth_middleware',
14
+ * position: 'after'
15
+ * }
4
16
  */
5
17
  export type MiddlewareNode = {
6
18
  /**
7
- * If you are adding a named middleware, then you must
8
- * define the name.
19
+ * Required for named middleware. The key name under which the middleware
20
+ * will be registered in the named middleware collection.
9
21
  */
10
22
  name?: string;
11
23
  /**
12
- * The path to the middleware file
24
+ * The import path to the middleware file. Can be a package import,
25
+ * subpath import, or relative path.
13
26
  *
14
27
  * @example
15
- * `@adonisjs/static/static_middleware`
16
- * `#middlewares/silent_auth.js`
28
+ * '@adonisjs/static/static_middleware'
29
+ * '#middlewares/silent_auth'
30
+ * './middleware/custom_middleware.js'
17
31
  */
18
32
  path: string;
19
33
  /**
20
- * The position to add the middleware. If `before`
21
- * middleware will be added at the first position and
22
- * therefore will be run before all others
34
+ * The position to add the middleware in the stack.
35
+ * 'before' adds at the beginning (runs first), 'after' adds at the end (runs last).
23
36
  *
24
37
  * @default 'after'
25
38
  */
26
39
  position?: 'before' | 'after';
27
40
  };
28
41
  /**
29
- * Policy node to be added to the list of policies.
42
+ * Policy node to be added to the list of Bouncer authorization policies.
43
+ * Used for registering policies in the application's policy registry.
44
+ *
45
+ * @example
46
+ * const userPolicy: BouncerPolicyNode = {
47
+ * name: 'UserPolicy',
48
+ * path: '#policies/user_policy'
49
+ * }
30
50
  */
31
51
  export type BouncerPolicyNode = {
32
52
  /**
33
- * Policy name
53
+ * The name of the policy class (should match the exported class name)
34
54
  */
35
55
  name: string;
36
56
  /**
37
- * Policy import path
57
+ * The import path to the policy file
38
58
  */
39
59
  path: string;
40
60
  };
41
61
  /**
42
- * Defines the structure of an environment variable validation
43
- * definition
62
+ * Defines the structure of an environment variable validation definition.
63
+ * Used to add new environment variable validations to the start/env.ts file.
64
+ *
65
+ * @example
66
+ * const envValidation: EnvValidationNode = {
67
+ * leadingComment: 'Database configuration',
68
+ * variables: {
69
+ * DB_HOST: 'Env.schema.string()',
70
+ * DB_PORT: 'Env.schema.number.optional({ port: 5432 })',
71
+ * DB_PASSWORD: 'Env.schema.string.optional()'
72
+ * }
73
+ * }
44
74
  */
45
75
  export type EnvValidationNode = {
46
76
  /**
47
- * Write a leading comment on top of your variables
77
+ * Optional leading comment to write above the variable definitions.
78
+ * Helps group related environment variables together.
48
79
  */
49
80
  leadingComment?: string;
50
81
  /**
51
- * A key-value pair of env variables and their validation
82
+ * A key-value pair of environment variables and their validation schemas.
83
+ * The key is the environment variable name, the value is the validation code.
52
84
  *
53
85
  * @example
54
- * MY_VAR: 'Env.schema.string.optional()'
86
+ * {
87
+ * MY_VAR: 'Env.schema.string.optional()',
88
+ * API_KEY: 'Env.schema.string()'
89
+ * }
55
90
  */
56
91
  variables: Record<string, string>;
57
92
  };
58
93
  /**
59
- * The supported package managers for installing packages
94
+ * The supported package managers for installing packages and managing lockfiles.
95
+ * Each package manager has specific lockfiles and install commands.
96
+ *
97
+ * @example
98
+ * const packageManager: SupportedPackageManager = 'pnpm'
99
+ *
100
+ * // Used in bundler configuration
101
+ * const bundler = new Bundler(cwd, ts, { packageManager: 'yarn@berry' })
60
102
  */
61
103
  export type SupportedPackageManager = 'npm' | 'yarn' | 'yarn@berry' | 'pnpm' | 'bun';