@adonisjs/assembler 8.0.0-next.2 → 8.0.0-next.20

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 (35) hide show
  1. package/README.md +88 -84
  2. package/build/chunk-4452KFDQ.js +465 -0
  3. package/build/chunk-JFBQ4OEM.js +434 -0
  4. package/build/chunk-NAASGAFO.js +478 -0
  5. package/build/chunk-TIKQQRMX.js +116 -0
  6. package/build/index.d.ts +3 -0
  7. package/build/index.js +800 -447
  8. package/build/src/bundler.d.ts +44 -3
  9. package/build/src/code_scanners/routes_scanner/main.d.ts +119 -0
  10. package/build/src/code_scanners/routes_scanner/main.js +8 -0
  11. package/build/src/code_scanners/routes_scanner/validator_extractor.d.ts +26 -0
  12. package/build/src/code_transformer/main.d.ts +44 -43
  13. package/build/src/code_transformer/main.js +123 -101
  14. package/build/src/code_transformer/rc_file_transformer.d.ts +56 -4
  15. package/build/src/debug.d.ts +12 -0
  16. package/build/src/dev_server.d.ts +92 -17
  17. package/build/src/file_buffer.d.ts +87 -0
  18. package/build/src/file_system.d.ts +46 -8
  19. package/build/src/helpers.d.ts +115 -0
  20. package/build/src/helpers.js +16 -0
  21. package/build/src/index_generator/main.d.ts +68 -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 +41 -0
  25. package/build/src/shortcuts_manager.d.ts +43 -28
  26. package/build/src/test_runner.d.ts +57 -12
  27. package/build/src/types/code_scanners.d.ts +226 -0
  28. package/build/src/types/code_transformer.d.ts +61 -19
  29. package/build/src/types/common.d.ts +270 -51
  30. package/build/src/types/hooks.d.ts +235 -22
  31. package/build/src/types/main.d.ts +15 -1
  32. package/build/src/utils.d.ts +99 -15
  33. package/build/src/virtual_file_system.d.ts +112 -0
  34. package/package.json +33 -20
  35. package/build/chunk-RR4HCA4M.js +0 -7
@@ -1,13 +1,28 @@
1
1
  import type tsStatic from 'typescript';
2
2
  import type { BundlerOptions } from './types/common.ts';
3
3
  import { type SupportedPackageManager } from './types/code_transformer.ts';
4
+ /**
5
+ * List of package managers we support in order to
6
+ * copy lockfiles
7
+ */
8
+ export declare const SUPPORTED_PACKAGE_MANAGERS: {
9
+ [K in SupportedPackageManager]: {
10
+ packageManagerFiles: string[];
11
+ installCommand: string;
12
+ };
13
+ };
4
14
  /**
5
15
  * The bundler class exposes the API to build an AdonisJS project.
16
+ *
17
+ * @example
18
+ * const bundler = new Bundler(new URL('./'), ts, { hooks: [] })
19
+ * const success = await bundler.bundle()
6
20
  */
7
21
  export declare class Bundler {
8
22
  #private;
9
- cwd: URL;
10
- options: BundlerOptions;
23
+ /**
24
+ * CLI UI instance for displaying colorful messages and progress information
25
+ */
11
26
  ui: {
12
27
  colors: import("@poppinss/colors/types").Colors;
13
28
  logger: import("@poppinss/cliui").Logger;
@@ -30,12 +45,38 @@ export declare class Bundler {
30
45
  useColors(colorsToUse: import("@poppinss/colors/types").Colors): void;
31
46
  };
32
47
  /**
33
- * Package manager detect from the project environment
48
+ * Package manager detected from the project environment
34
49
  */
35
50
  packageManager: SupportedPackageManager;
51
+ /**
52
+ * The current working directory URL
53
+ */
54
+ cwd: URL;
55
+ /**
56
+ * The current working project directory path as string
57
+ */
58
+ cwdPath: string;
59
+ /**
60
+ * Bundler configuration options including hooks and meta files
61
+ */
62
+ options: BundlerOptions;
63
+ /**
64
+ * Create a new bundler instance
65
+ *
66
+ * @param cwd - The current working directory URL
67
+ * @param ts - TypeScript module reference
68
+ * @param options - Bundler configuration options
69
+ */
36
70
  constructor(cwd: URL, ts: typeof tsStatic, options: BundlerOptions);
37
71
  /**
38
72
  * Bundles the application to be run in production
73
+ *
74
+ * @param stopOnError - Whether to stop the build process on TypeScript errors
75
+ * @param client - Override the detected package manager
76
+ * @returns Promise that resolves to true if build succeeded, false otherwise
77
+ *
78
+ * @example
79
+ * const success = await bundler.bundle(true, 'npm')
39
80
  */
40
81
  bundle(stopOnError?: boolean, client?: SupportedPackageManager): Promise<boolean>;
41
82
  }
@@ -0,0 +1,119 @@
1
+ import { type AsyncOrSync } from '@poppinss/utils/types';
2
+ import { PathsResolver } from '../../paths_resolver.ts';
3
+ import { type ScannedRoute, type RoutesListItem, type ScannedController, type RoutesScannerRules } from '../../types/code_scanners.ts';
4
+ /**
5
+ * RoutesScanner is responsible for scanning application routes,
6
+ * extracting their controllers, validators, request and response types.
7
+ *
8
+ * The RoutesScanner analyzes route definitions to extract TypeScript type information
9
+ * for request validation, response types, and controller methods. It supports custom
10
+ * rules for overriding default behavior and provides hooks for extending functionality.
11
+ *
12
+ * @example
13
+ * const scanner = new RoutesScanner(appRoot, [rules])
14
+ * scanner.defineResponse((route, controller) => {
15
+ * return { type: 'CustomResponseType', imports: [] }
16
+ * })
17
+ * await scanner.scan(routes)
18
+ * const scannedRoutes = scanner.getScannedRoutes()
19
+ */
20
+ export declare class RoutesScanner {
21
+ #private;
22
+ /**
23
+ * CLI UI instance to log colorful messages and progress information
24
+ */
25
+ ui: {
26
+ colors: import("@poppinss/colors/types").Colors;
27
+ logger: import("@poppinss/cliui").Logger;
28
+ table: (tableOptions?: Partial<import("@poppinss/cliui/types").TableOptions>) => import("@poppinss/cliui").Table;
29
+ tasks: (tasksOptions?: Partial<import("@poppinss/cliui/types").TaskManagerOptions>) => import("@poppinss/cliui").TaskManager;
30
+ icons: {
31
+ tick: string;
32
+ cross: string;
33
+ bullet: string;
34
+ nodejs: string;
35
+ pointer: string;
36
+ info: string;
37
+ warning: string;
38
+ squareSmallFilled: string;
39
+ };
40
+ sticker: () => import("@poppinss/cliui").Instructions;
41
+ instructions: () => import("@poppinss/cliui").Instructions;
42
+ switchMode(modeToUse: "raw" | "silent" | "normal"): void;
43
+ useRenderer(rendererToUse: import("@poppinss/cliui/types").RendererContract): void;
44
+ useColors(colorsToUse: import("@poppinss/colors/types").Colors): void;
45
+ };
46
+ /**
47
+ * The paths resolver is used to convert subpath and package
48
+ * imports to absolute paths
49
+ */
50
+ pathsResolver: PathsResolver;
51
+ /**
52
+ * The rules to apply when scanning routes
53
+ */
54
+ rules: RoutesScannerRules;
55
+ /**
56
+ * Create a new RoutesScanner instance
57
+ *
58
+ * @param appRoot - The root directory of the application
59
+ * @param rulesCollection - Collection of rules to apply during scanning
60
+ */
61
+ constructor(appRoot: string, rulesCollection: RoutesScannerRules[]);
62
+ /**
63
+ * Register a callback to self compute the response types for
64
+ * a given route. The callback will be executed for all
65
+ * the routes and you must return undefined to fallback
66
+ * to the default behavior of detecting types
67
+ *
68
+ * @param callback - Function to compute response types for routes
69
+ * @returns This RoutesScanner instance for method chaining
70
+ */
71
+ defineResponse(callback: (route: ScannedRoute, controller: ScannedController, scanner: RoutesScanner) => AsyncOrSync<ScannedRoute['response']>): this;
72
+ /**
73
+ * Register a callback to self compute the request types for
74
+ * a given route. The callback will be executed for all
75
+ * the routes and you must return undefined to fallback
76
+ * to the default behavior of detecting types
77
+ *
78
+ * @param callback - Function to compute request types for routes
79
+ * @returns This RoutesScanner instance for method chaining
80
+ */
81
+ defineRequest(callback: (route: ScannedRoute, controller: ScannedController, scanner: RoutesScanner) => AsyncOrSync<ScannedRoute['request']>): this;
82
+ /**
83
+ * Register a callback to extract validators from the route controller
84
+ *
85
+ * @param callback - Function to extract validators from controllers
86
+ * @returns This RoutesScanner instance for method chaining
87
+ */
88
+ extractValidators(callback: (route: ScannedRoute, controller: ScannedController, scanner: RoutesScanner) => AsyncOrSync<ScannedRoute['validators']>): this;
89
+ /**
90
+ * Returns the scanned routes
91
+ *
92
+ * @returns Array of scanned routes with their metadata
93
+ */
94
+ getScannedRoutes(): ScannedRoute[];
95
+ /**
96
+ * Returns an array of controllers bound to the provided
97
+ * routes
98
+ *
99
+ * @returns Array of controller's absolute paths
100
+ */
101
+ getControllers(): string[];
102
+ /**
103
+ * Invalidating a controller will trigger computing the validators,
104
+ * request types and the response types.
105
+ *
106
+ * @param controllerPath - Path to the controller file to invalidate
107
+ */
108
+ invalidate(controllerPath: string): Promise<boolean>;
109
+ /**
110
+ * Scans an array of Route list items and fetches their validators,
111
+ * controllers, and request/response types.
112
+ *
113
+ * This is the main method that processes all routes and extracts
114
+ * their type information for code generation purposes.
115
+ *
116
+ * @param routes - Array of route list items to scan
117
+ */
118
+ scan(routes: RoutesListItem[]): Promise<void>;
119
+ }
@@ -0,0 +1,8 @@
1
+ import {
2
+ RoutesScanner
3
+ } from "../../../chunk-NAASGAFO.js";
4
+ import "../../../chunk-TIKQQRMX.js";
5
+ import "../../../chunk-JFBQ4OEM.js";
6
+ export {
7
+ RoutesScanner
8
+ };
@@ -0,0 +1,26 @@
1
+ import { type VirtualFileSystem } from '../../virtual_file_system.ts';
2
+ import { type ScannedController, type ScannedRoute } from '../../types/code_scanners.ts';
3
+ /**
4
+ * Extracts the VineJS validator usage from within a controller method.
5
+ *
6
+ * This function analyzes controller method code to detect validator usage patterns
7
+ * and extracts the validator references along with their import information.
8
+ * The following syntaxes are supported:
9
+ *
10
+ * - `request.validateUsing(validatorReference)`
11
+ * - `vine.validate(validatorReference)`
12
+ * - `validatorReference.validate(request.all())`
13
+ *
14
+ * - `request.validateUsing(ControllerReference.validator)`
15
+ * - `vine.validate(ControllerReference.validator)`
16
+ * - `ControllerReference.validator.validate(request.all())`
17
+ *
18
+ * The app root is needed to create relative validator imports in case
19
+ * a relative import was used within the controller file.
20
+ *
21
+ * @param appRoot - The root directory of the application
22
+ * @param vfs - Virtual file system instance for code analysis
23
+ * @param controller - The controller to analyze for validator usage
24
+ * @returns Promise resolving to array of validator information or undefined
25
+ */
26
+ export declare function extractValidators(appRoot: string, vfs: VirtualFileSystem, controller: ScannedController): Promise<ScannedRoute['validators']>;
@@ -1,44 +1,72 @@
1
- import { type OneOrMore } from '@poppinss/utils/types';
2
1
  import { installPackage, detectPackageManager } from '@antfu/install-pkg';
3
2
  import { Project } from 'ts-morph';
4
3
  import { RcFileTransformer } from './rc_file_transformer.ts';
5
4
  import type { MiddlewareNode, EnvValidationNode, BouncerPolicyNode } from '../types/code_transformer.ts';
6
5
  /**
7
- * This class is responsible for updating
6
+ * This class is responsible for transforming AdonisJS project code,
7
+ * including updating middleware, environment validations, and other
8
+ * code generation tasks.
9
+ *
10
+ * The CodeTransformer provides methods for modifying various AdonisJS
11
+ * configuration files and code structures using AST manipulation through
12
+ * ts-morph. It can update middleware stacks, add environment validations,
13
+ * register plugins, and modify RC file configurations.
14
+ *
15
+ * @example
16
+ * const transformer = new CodeTransformer(cwd)
17
+ * await transformer.addMiddlewareToStack('server', [{
18
+ * path: '#middleware/cors_middleware',
19
+ * position: 'before'
20
+ * }])
8
21
  */
9
22
  export declare class CodeTransformer {
10
23
  #private;
11
24
  /**
12
- * Exporting utilities to install package and detect
13
- * the package manager
25
+ * Utility function for installing packages
14
26
  */
15
27
  installPackage: typeof installPackage;
28
+ /**
29
+ * Utility function for detecting the package manager
30
+ */
16
31
  detectPackageManager: typeof detectPackageManager;
17
32
  /**
18
- * The TsMorph project
33
+ * The TsMorph project instance for AST manipulation
19
34
  */
20
35
  project: Project;
36
+ /**
37
+ * Create a new CodeTransformer instance
38
+ *
39
+ * @param cwd - The current working directory URL
40
+ */
21
41
  constructor(cwd: URL);
22
42
  /**
23
- * Add new env variable validation in the
24
- * `env.ts` file
43
+ * Add new env variable validation in the `env.ts` file
44
+ *
45
+ * @param definition - Environment validation definition containing variables and comment
25
46
  */
26
47
  defineEnvValidations(definition: EnvValidationNode): Promise<void>;
27
48
  /**
28
- * Define new middlewares inside the `start/kernel.ts`
29
- * file
49
+ * Define new middlewares inside the `start/kernel.ts` file
30
50
  *
31
51
  * This function is highly based on some assumptions
32
52
  * and will not work if you significantly tweaked
33
53
  * your `start/kernel.ts` file.
54
+ *
55
+ * @param stack - The middleware stack to add to ('server', 'router', or 'named')
56
+ * @param middleware - Array of middleware entries to add
34
57
  */
35
58
  addMiddlewareToStack(stack: 'server' | 'router' | 'named', middleware: MiddlewareNode[]): Promise<void>;
36
59
  /**
37
- * Update the `adonisrc.ts` file
60
+ * Update the `adonisrc.ts` file using the provided callback
61
+ *
62
+ * @param callback - Function that receives the RcFileTransformer for modifications
38
63
  */
39
64
  updateRcFile(callback: (transformer: RcFileTransformer) => void): Promise<void>;
40
65
  /**
41
66
  * Add a new Japa plugin in the `tests/bootstrap.ts` file
67
+ *
68
+ * @param pluginCall - The plugin function call to add
69
+ * @param importDeclarations - Import declarations needed for the plugin
42
70
  */
43
71
  addJapaPlugin(pluginCall: string, importDeclarations: {
44
72
  isNamed: boolean;
@@ -46,7 +74,10 @@ export declare class CodeTransformer {
46
74
  identifier: string;
47
75
  }[]): Promise<void>;
48
76
  /**
49
- * Add a new Vite plugin
77
+ * Add a new Vite plugin to the `vite.config.ts` file
78
+ *
79
+ * @param pluginCall - The plugin function call to add
80
+ * @param importDeclarations - Import declarations needed for the plugin
50
81
  */
51
82
  addVitePlugin(pluginCall: string, importDeclarations: {
52
83
  isNamed: boolean;
@@ -56,38 +87,8 @@ export declare class CodeTransformer {
56
87
  /**
57
88
  * Adds a policy to the list of `policies` object configured
58
89
  * inside the `app/policies/main.ts` file.
59
- */
60
- addPolicies(policies: BouncerPolicyNode[]): Promise<void>;
61
- /**
62
- * Creates an index file that exports an object in which the key is the PascalCase
63
- * name of the entity and the value is a dynamic import.
64
- *
65
- * For example, in case of controllers, the index file will be the list of controller
66
- * names pointing a dynamically imported controller file.
67
90
  *
68
- * ```ts
69
- * export const controllers = {
70
- * LoginController: () => import('#controllers/login_controller'),
71
- * LogoutController: () => import('#controllers/logout_controller'),
72
- * }
73
- * ```
74
- *
75
- * @param source
76
- * @param outputPath
77
- * @param importAlias
91
+ * @param policies - Array of bouncer policy entries to add
78
92
  */
79
- makeEntityIndex(input: OneOrMore<{
80
- source: string;
81
- importAlias?: string;
82
- allowedExtensions?: string[];
83
- }>, output: {
84
- destination: string;
85
- exportName?: string;
86
- removeNameSuffix?: string;
87
- computeBaseName?: (filePath: string, sourcePath: string) => string;
88
- computeOutput?: (entries: {
89
- name: string;
90
- importPath: string;
91
- }[]) => string;
92
- }): Promise<void>;
93
+ addPolicies(policies: BouncerPolicyNode[]): Promise<void>;
93
94
  }