@adonisjs/assembler 8.0.0-next.9 → 8.0.0
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.
- package/README.md +260 -0
- package/build/codemod_exception-CzQgXAAf.js +137 -0
- package/build/index.d.ts +1 -1
- package/build/index.js +927 -1724
- package/build/source-dVeugJ0e.js +166 -0
- package/build/src/bundler.d.ts +2 -0
- package/build/src/code_scanners/routes_scanner/main.d.ts +16 -2
- package/build/src/code_scanners/routes_scanner/main.js +168 -441
- package/build/src/code_transformer/main.d.ts +14 -1
- package/build/src/code_transformer/main.js +502 -622
- package/build/src/code_transformer/rc_file_transformer.d.ts +28 -2
- package/build/src/debug.d.ts +1 -1
- package/build/src/dev_server.d.ts +60 -12
- package/build/src/exceptions/codemod_exception.d.ts +178 -0
- package/build/src/file_buffer.d.ts +19 -0
- package/build/src/file_system.d.ts +2 -2
- package/build/src/helpers.js +72 -16
- package/build/src/index_generator/main.js +28 -6
- package/build/src/paths_resolver.d.ts +2 -1
- package/build/src/test_runner.d.ts +3 -2
- package/build/src/types/code_scanners.d.ts +29 -13
- package/build/src/types/code_transformer.d.ts +127 -0
- package/build/src/types/common.d.ts +98 -2
- package/build/src/types/hooks.d.ts +4 -1
- package/build/src/types/main.js +1 -0
- package/build/src/utils.d.ts +9 -3
- package/build/src/virtual_file_system.d.ts +1 -1
- package/build/validator_extractor-Ccio_Ndi.js +82 -0
- package/build/virtual_file_system-bGeoWsK-.js +285 -0
- package/package.json +41 -39
- package/build/chunk-7XU453QB.js +0 -418
- package/build/chunk-PORDZS62.js +0 -391
- package/build/chunk-TIKQQRMX.js +0 -116
- package/build/src/hooks.d.ts +0 -224
|
@@ -82,12 +82,38 @@ export declare class RcFileTransformer {
|
|
|
82
82
|
addSuite(suiteName: string, files: string | string[], timeout?: number): this;
|
|
83
83
|
/**
|
|
84
84
|
* Add a new assembler hook
|
|
85
|
+
* The format `thunk` write `() => import(path)`.
|
|
85
86
|
*
|
|
86
87
|
* @param type - The type of hook to add
|
|
87
|
-
* @param
|
|
88
|
+
* @param value - The path to the hook file or value to write
|
|
89
|
+
* @param raw - Wether to write a thunk import or as raw value
|
|
88
90
|
* @returns This RcFileTransformer instance for method chaining
|
|
89
91
|
*/
|
|
90
|
-
addAssemblerHook(type: keyof Exclude<AssemblerRcFile['hooks'], undefined>,
|
|
92
|
+
addAssemblerHook(type: keyof Exclude<AssemblerRcFile['hooks'], undefined>, value: string, raw?: boolean): this;
|
|
93
|
+
/**
|
|
94
|
+
* Add a named import
|
|
95
|
+
*
|
|
96
|
+
* @param specifier - The module specifier to import
|
|
97
|
+
* @param names - Names to import from the module
|
|
98
|
+
* @returns This RcFileTransformer instance for method chaining
|
|
99
|
+
*/
|
|
100
|
+
addNamedImport(specifier: string, names: string[]): this;
|
|
101
|
+
/**
|
|
102
|
+
* Add a default import
|
|
103
|
+
*
|
|
104
|
+
* @param specifier - The module specifier to import
|
|
105
|
+
* @param name - Name of the default import
|
|
106
|
+
* @returns This RcFileTransformer instance for method chaining
|
|
107
|
+
*/
|
|
108
|
+
addDefaultImport(specifier: string, name: string): this;
|
|
109
|
+
/**
|
|
110
|
+
* Get a directory value from the directories configuration.
|
|
111
|
+
*
|
|
112
|
+
* @param key - The directory key to retrieve
|
|
113
|
+
* @param defaultValue - The default value if not configured
|
|
114
|
+
* @returns The configured directory path or the default value
|
|
115
|
+
*/
|
|
116
|
+
getDirectory(key: string, defaultValue: string): string;
|
|
91
117
|
/**
|
|
92
118
|
* Save the adonisrc.ts file with all applied transformations
|
|
93
119
|
*
|
package/build/src/debug.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import type tsStatic from 'typescript';
|
|
2
1
|
import type { DevServerOptions } from './types/common.ts';
|
|
3
2
|
/**
|
|
4
|
-
* Exposes the API to start the development server in HMR, watch or static mode
|
|
3
|
+
* Exposes the API to start the development server in HMR, watch or static mode
|
|
5
4
|
*
|
|
6
5
|
* In HMR mode, the DevServer will exec the "bin/server.ts" file and let hot-hook
|
|
7
6
|
* manage the changes using hot module reloading.
|
|
8
7
|
*
|
|
9
|
-
* In watch mode, the DevServer will start an internal watcher and restarts the
|
|
10
|
-
* every file change. The files must be part of the TypeScript project (via tsconfig.json),
|
|
8
|
+
* In watch mode, the DevServer will start an internal watcher and restarts the server
|
|
9
|
+
* after every file change. The files must be part of the TypeScript project (via tsconfig.json),
|
|
11
10
|
* or registered as metaFiles.
|
|
12
11
|
*
|
|
12
|
+
* In static mode, the server runs without file watching or hot reloading.
|
|
13
|
+
*
|
|
13
14
|
* @example
|
|
14
15
|
* const devServer = new DevServer(cwd, { hmr: true, hooks: [] })
|
|
15
16
|
* await devServer.start(ts)
|
|
@@ -24,6 +25,7 @@ export declare class DevServer {
|
|
|
24
25
|
logger: import("@poppinss/cliui").Logger;
|
|
25
26
|
table: (tableOptions?: Partial<import("@poppinss/cliui/types").TableOptions>) => import("@poppinss/cliui").Table;
|
|
26
27
|
tasks: (tasksOptions?: Partial<import("@poppinss/cliui/types").TaskManagerOptions>) => import("@poppinss/cliui").TaskManager;
|
|
28
|
+
steps: () => import("@poppinss/cliui").Steps;
|
|
27
29
|
icons: {
|
|
28
30
|
tick: string;
|
|
29
31
|
cross: string;
|
|
@@ -33,6 +35,7 @@ export declare class DevServer {
|
|
|
33
35
|
info: string;
|
|
34
36
|
warning: string;
|
|
35
37
|
squareSmallFilled: string;
|
|
38
|
+
borderVertical: string;
|
|
36
39
|
};
|
|
37
40
|
sticker: () => import("@poppinss/cliui").Instructions;
|
|
38
41
|
instructions: () => import("@poppinss/cliui").Instructions;
|
|
@@ -41,7 +44,12 @@ export declare class DevServer {
|
|
|
41
44
|
useColors(colorsToUse: import("@poppinss/colors/types").Colors): void;
|
|
42
45
|
};
|
|
43
46
|
/**
|
|
44
|
-
* The mode in which the DevServer is running
|
|
47
|
+
* The mode in which the DevServer is running
|
|
48
|
+
*
|
|
49
|
+
* Returns the current operating mode of the development server:
|
|
50
|
+
* - 'hmr': Hot Module Reloading enabled
|
|
51
|
+
* - 'watch': File system watching with full restarts
|
|
52
|
+
* - 'static': No file watching or hot reloading
|
|
45
53
|
*/
|
|
46
54
|
get mode(): "hmr" | "watch" | "static";
|
|
47
55
|
/**
|
|
@@ -68,36 +76,76 @@ export declare class DevServer {
|
|
|
68
76
|
*/
|
|
69
77
|
constructor(cwd: URL, options: DevServerOptions);
|
|
70
78
|
/**
|
|
71
|
-
*
|
|
79
|
+
* Adds listener to get notified when dev server is closed
|
|
80
|
+
*
|
|
81
|
+
* Registers a callback function that will be invoked when the development
|
|
82
|
+
* server's child process exits. The callback receives the exit code.
|
|
72
83
|
*
|
|
73
84
|
* @param callback - Function to call when dev server closes
|
|
74
85
|
* @returns This DevServer instance for method chaining
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* devServer.onClose((exitCode) => {
|
|
89
|
+
* console.log(`Server closed with exit code: ${exitCode}`)
|
|
90
|
+
* })
|
|
75
91
|
*/
|
|
76
92
|
onClose(callback: (exitCode: number) => any): this;
|
|
77
93
|
/**
|
|
78
|
-
*
|
|
94
|
+
* Adds listener to get notified when dev server encounters an error
|
|
95
|
+
*
|
|
96
|
+
* Registers a callback function that will be invoked when the development
|
|
97
|
+
* server's child process encounters an error or fails to start.
|
|
79
98
|
*
|
|
80
99
|
* @param callback - Function to call when dev server encounters an error
|
|
81
100
|
* @returns This DevServer instance for method chaining
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* devServer.onError((error) => {
|
|
104
|
+
* console.error('Dev server error:', error.message)
|
|
105
|
+
* })
|
|
82
106
|
*/
|
|
83
107
|
onError(callback: (error: any) => any): this;
|
|
84
108
|
/**
|
|
85
|
-
*
|
|
109
|
+
* Closes watchers and terminates the running child process
|
|
110
|
+
*
|
|
111
|
+
* Cleans up keyboard shortcuts, stops file system watchers, and kills
|
|
112
|
+
* the HTTP server child process. This should be called when shutting down
|
|
113
|
+
* the development server.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* await devServer.close()
|
|
86
117
|
*/
|
|
87
118
|
close(): Promise<void>;
|
|
88
119
|
/**
|
|
89
|
-
*
|
|
120
|
+
* Starts the development server in static or HMR mode
|
|
121
|
+
*
|
|
122
|
+
* Initializes the server and starts the HTTP server. The mode is determined
|
|
123
|
+
* by the `hmr` option in DevServerOptions. In HMR mode, hot-hook is configured
|
|
124
|
+
* to enable hot module reloading.
|
|
90
125
|
*
|
|
91
126
|
* @param ts - TypeScript module reference
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* const devServer = new DevServer(cwd, { hmr: true, hooks: [] })
|
|
130
|
+
* await devServer.start(ts)
|
|
92
131
|
*/
|
|
93
|
-
start(
|
|
132
|
+
start(): Promise<void>;
|
|
94
133
|
/**
|
|
95
|
-
*
|
|
134
|
+
* Starts the development server in watch mode and restarts on file changes
|
|
135
|
+
*
|
|
136
|
+
* Initializes the server, starts the HTTP server, and sets up a file system
|
|
137
|
+
* watcher that monitors for changes. When files are added, modified, or deleted,
|
|
138
|
+
* the server automatically restarts. The watcher respects TypeScript project
|
|
139
|
+
* configuration and metaFiles settings.
|
|
96
140
|
*
|
|
97
141
|
* @param ts - TypeScript module reference
|
|
98
142
|
* @param options - Watch options including polling mode
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* const devServer = new DevServer(cwd, { hooks: [] })
|
|
146
|
+
* await devServer.startAndWatch(ts, { poll: false })
|
|
99
147
|
*/
|
|
100
|
-
startAndWatch(
|
|
148
|
+
startAndWatch(options?: {
|
|
101
149
|
poll: boolean;
|
|
102
150
|
}): Promise<void>;
|
|
103
151
|
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { MiddlewareNode, EnvValidationNode, BouncerPolicyNode } from '../types/code_transformer.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating a CodemodException
|
|
4
|
+
*/
|
|
5
|
+
export interface CodemodExceptionOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Instructions for the user to manually perform the codemod action
|
|
8
|
+
*/
|
|
9
|
+
instructions?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The file path that was being modified
|
|
12
|
+
*/
|
|
13
|
+
filePath?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Custom exception for codemod errors that provides helpful instructions
|
|
17
|
+
* to the user when automatic code transformation fails.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* throw CodemodException.missingEnvFile('start/env.ts', {
|
|
22
|
+
* variables: { MY_VAR: 'Env.schema.string()' }
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class CodemodException extends Error {
|
|
27
|
+
#private;
|
|
28
|
+
/**
|
|
29
|
+
* Instructions for the user to manually perform the codemod action
|
|
30
|
+
*/
|
|
31
|
+
instructions?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The file path that was being modified
|
|
34
|
+
*/
|
|
35
|
+
filePath?: string;
|
|
36
|
+
constructor(message: string, options?: CodemodExceptionOptions);
|
|
37
|
+
/**
|
|
38
|
+
* Creates an exception when start/env.ts file is missing
|
|
39
|
+
*
|
|
40
|
+
* @param filePath - The path to the missing file
|
|
41
|
+
* @param definition - The environment validation definition that was being added
|
|
42
|
+
*/
|
|
43
|
+
static missingEnvFile(filePath: string, definition: EnvValidationNode): CodemodException;
|
|
44
|
+
/**
|
|
45
|
+
* Creates an exception when Env.create is not found in the file
|
|
46
|
+
*
|
|
47
|
+
* @param filePath - The path to the file being modified
|
|
48
|
+
* @param definition - The environment validation definition that was being added
|
|
49
|
+
*/
|
|
50
|
+
static missingEnvCreate(filePath: string, definition: EnvValidationNode): CodemodException;
|
|
51
|
+
/**
|
|
52
|
+
* Creates an exception when Env.create has invalid structure
|
|
53
|
+
*
|
|
54
|
+
* @param filePath - The path to the file being modified
|
|
55
|
+
* @param definition - The environment validation definition that was being added
|
|
56
|
+
*/
|
|
57
|
+
static invalidEnvCreate(filePath: string, definition: EnvValidationNode): CodemodException;
|
|
58
|
+
/**
|
|
59
|
+
* Creates an exception when start/kernel.ts file is missing
|
|
60
|
+
*
|
|
61
|
+
* @param filePath - The path to the missing file
|
|
62
|
+
* @param stack - The middleware stack that was being modified
|
|
63
|
+
* @param middleware - The middleware entries that were being added
|
|
64
|
+
*/
|
|
65
|
+
static missingKernelFile(filePath: string, stack: 'server' | 'router' | 'named', middleware: MiddlewareNode[]): CodemodException;
|
|
66
|
+
/**
|
|
67
|
+
* Creates an exception when server.use/router.use is not found
|
|
68
|
+
*
|
|
69
|
+
* @param filePath - The path to the file being modified
|
|
70
|
+
* @param stack - The middleware stack that was being modified
|
|
71
|
+
* @param middleware - The middleware entries that were being added
|
|
72
|
+
*/
|
|
73
|
+
static missingMiddlewareStack(filePath: string, stack: 'server' | 'router' | 'named', middleware: MiddlewareNode[]): CodemodException;
|
|
74
|
+
/**
|
|
75
|
+
* Creates an exception when middleware array structure is invalid
|
|
76
|
+
*
|
|
77
|
+
* @param filePath - The path to the file being modified
|
|
78
|
+
* @param stack - The middleware stack that was being modified
|
|
79
|
+
* @param middleware - The middleware entries that were being added
|
|
80
|
+
* @param reason - The reason why the structure is invalid
|
|
81
|
+
*/
|
|
82
|
+
static invalidMiddlewareStack(filePath: string, stack: 'server' | 'router' | 'named', middleware: MiddlewareNode[], reason: string): CodemodException;
|
|
83
|
+
/**
|
|
84
|
+
* Creates an exception when app/policies/main.ts file is missing
|
|
85
|
+
*
|
|
86
|
+
* @param filePath - The path to the missing file
|
|
87
|
+
* @param policies - The policies that were being added
|
|
88
|
+
*/
|
|
89
|
+
static missingPoliciesFile(filePath: string, policies: BouncerPolicyNode[]): CodemodException;
|
|
90
|
+
/**
|
|
91
|
+
* Creates an exception when policies structure is invalid
|
|
92
|
+
*
|
|
93
|
+
* @param filePath - The path to the file being modified
|
|
94
|
+
* @param policies - The policies that were being added
|
|
95
|
+
* @param reason - The reason why the structure is invalid
|
|
96
|
+
*/
|
|
97
|
+
static invalidPoliciesFile(filePath: string, policies: BouncerPolicyNode[], reason: string): CodemodException;
|
|
98
|
+
/**
|
|
99
|
+
* Creates an exception when vite.config.ts file is missing
|
|
100
|
+
*
|
|
101
|
+
* @param filePath - The path to the missing file
|
|
102
|
+
* @param pluginCall - The plugin call that was being added
|
|
103
|
+
* @param importDeclarations - The import declarations needed for the plugin
|
|
104
|
+
*/
|
|
105
|
+
static missingViteConfig(filePath: string, pluginCall: string, importDeclarations: {
|
|
106
|
+
isNamed: boolean;
|
|
107
|
+
module: string;
|
|
108
|
+
identifier: string;
|
|
109
|
+
}[]): CodemodException;
|
|
110
|
+
/**
|
|
111
|
+
* Creates an exception when vite.config.ts structure is invalid
|
|
112
|
+
*
|
|
113
|
+
* @param filePath - The path to the file being modified
|
|
114
|
+
* @param pluginCall - The plugin call that was being added
|
|
115
|
+
* @param importDeclarations - The import declarations needed for the plugin
|
|
116
|
+
* @param reason - The reason why the structure is invalid
|
|
117
|
+
*/
|
|
118
|
+
static invalidViteConfig(filePath: string, pluginCall: string, importDeclarations: {
|
|
119
|
+
isNamed: boolean;
|
|
120
|
+
module: string;
|
|
121
|
+
identifier: string;
|
|
122
|
+
}[], reason: string): CodemodException;
|
|
123
|
+
/**
|
|
124
|
+
* Creates an exception when tests/bootstrap.ts file is missing
|
|
125
|
+
*
|
|
126
|
+
* @param filePath - The path to the missing file
|
|
127
|
+
* @param pluginCall - The plugin call that was being added
|
|
128
|
+
* @param importDeclarations - The import declarations needed for the plugin
|
|
129
|
+
*/
|
|
130
|
+
static missingJapaBootstrap(filePath: string, pluginCall: string, importDeclarations: {
|
|
131
|
+
isNamed: boolean;
|
|
132
|
+
module: string;
|
|
133
|
+
identifier: string;
|
|
134
|
+
}[]): CodemodException;
|
|
135
|
+
/**
|
|
136
|
+
* Creates an exception when tests/bootstrap.ts structure is invalid
|
|
137
|
+
*
|
|
138
|
+
* @param filePath - The path to the file being modified
|
|
139
|
+
* @param pluginCall - The plugin call that was being added
|
|
140
|
+
* @param importDeclarations - The import declarations needed for the plugin
|
|
141
|
+
* @param reason - The reason why the structure is invalid
|
|
142
|
+
*/
|
|
143
|
+
static invalidJapaBootstrap(filePath: string, pluginCall: string, importDeclarations: {
|
|
144
|
+
isNamed: boolean;
|
|
145
|
+
module: string;
|
|
146
|
+
identifier: string;
|
|
147
|
+
}[], reason: string): CodemodException;
|
|
148
|
+
/**
|
|
149
|
+
* Creates an exception when adonisrc.ts file is missing
|
|
150
|
+
*
|
|
151
|
+
* @param filePath - The path to the missing file
|
|
152
|
+
* @param codeToAdd - The code that should be added manually
|
|
153
|
+
*/
|
|
154
|
+
static missingRcFile(filePath: string, codeToAdd: string): CodemodException;
|
|
155
|
+
/**
|
|
156
|
+
* Creates an exception when adonisrc.ts structure is invalid
|
|
157
|
+
*
|
|
158
|
+
* @param filePath - The path to the file being modified
|
|
159
|
+
* @param codeToAdd - The code that should be added manually
|
|
160
|
+
* @param reason - The reason why the structure is invalid
|
|
161
|
+
*/
|
|
162
|
+
static invalidRcFile(filePath: string, codeToAdd: string, reason: string): CodemodException;
|
|
163
|
+
/**
|
|
164
|
+
* Creates an exception when a file required for transformation is not found.
|
|
165
|
+
*
|
|
166
|
+
* @param filePath - The path to the missing file
|
|
167
|
+
* @param codeToAdd - The code that should be added manually
|
|
168
|
+
*/
|
|
169
|
+
static E_CODEMOD_FILE_NOT_FOUND(filePath: string, codeToAdd: string): CodemodException;
|
|
170
|
+
/**
|
|
171
|
+
* Creates an exception when the file structure doesn't match expected patterns.
|
|
172
|
+
*
|
|
173
|
+
* @param message - Description of what structure was expected
|
|
174
|
+
* @param filePath - The path to the file being modified
|
|
175
|
+
* @param codeToAdd - The code that should be added manually
|
|
176
|
+
*/
|
|
177
|
+
static E_CODEMOD_INVALID_STRUCTURE(message: string, filePath: string, codeToAdd: string): CodemodException;
|
|
178
|
+
}
|
|
@@ -29,6 +29,17 @@ export declare class FileBuffer {
|
|
|
29
29
|
* @returns The number of lines in the buffer
|
|
30
30
|
*/
|
|
31
31
|
get size(): number;
|
|
32
|
+
/**
|
|
33
|
+
* Enable or disable end-of-line character at the end of output
|
|
34
|
+
*
|
|
35
|
+
* @param enabled - Whether to add EOL character
|
|
36
|
+
* @returns This FileBuffer instance for method chaining
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const buffer = new FileBuffer()
|
|
40
|
+
* buffer.eol(true).writeLine('Hello').flush() // 'Hello\n\n'
|
|
41
|
+
*/
|
|
42
|
+
eol(enabled: boolean): this;
|
|
32
43
|
/**
|
|
33
44
|
* Write a new line to the output with current indentation
|
|
34
45
|
*
|
|
@@ -55,6 +66,14 @@ export declare class FileBuffer {
|
|
|
55
66
|
* @returns This FileBuffer instance for method chaining
|
|
56
67
|
*/
|
|
57
68
|
dedent(): this;
|
|
69
|
+
/**
|
|
70
|
+
* Convert the buffer to a string representation
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const buffer = new FileBuffer()
|
|
74
|
+
* buffer.writeLine('Hello')
|
|
75
|
+
* console.log(buffer.toString())
|
|
76
|
+
*/
|
|
58
77
|
toString(): string;
|
|
59
78
|
/**
|
|
60
79
|
* Return template as a string, joining all buffer lines
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TsConfigResult } from 'get-tsconfig';
|
|
2
2
|
import { type InspectedFile, type AssemblerRcFile } from './types/common.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Exposes an intutive API to run actions when different kind of files
|
|
@@ -83,7 +83,7 @@ export declare class FileSystem {
|
|
|
83
83
|
* @param tsConfig - Parsed TypeScript configuration
|
|
84
84
|
* @param rcFile - AdonisJS RC file configuration
|
|
85
85
|
*/
|
|
86
|
-
constructor(cwd: string, tsConfig:
|
|
86
|
+
constructor(cwd: string, tsConfig: TsConfigResult, rcFile: AssemblerRcFile);
|
|
87
87
|
/**
|
|
88
88
|
* Returns true if the file should be watched. Chokidar sends
|
|
89
89
|
* absolute unix paths to the ignored callback.
|
package/build/src/helpers.js
CHANGED
|
@@ -1,16 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { parseImports } from "parse-imports";
|
|
2
|
+
async function findImport(code, importReference) {
|
|
3
|
+
const importIdentifier = importReference.split(".")[0];
|
|
4
|
+
for (const $import of await parseImports(code, {})) {
|
|
5
|
+
if (!$import.importClause) continue;
|
|
6
|
+
if (!$import.moduleSpecifier.value) continue;
|
|
7
|
+
if ($import.importClause.default === importIdentifier) return {
|
|
8
|
+
specifier: $import.moduleSpecifier.value,
|
|
9
|
+
isConstant: $import.moduleSpecifier.isConstant,
|
|
10
|
+
clause: {
|
|
11
|
+
type: "default",
|
|
12
|
+
value: importIdentifier
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
if ($import.importClause.namespace === importIdentifier) return {
|
|
16
|
+
specifier: $import.moduleSpecifier.value,
|
|
17
|
+
isConstant: $import.moduleSpecifier.isConstant,
|
|
18
|
+
clause: {
|
|
19
|
+
type: "namespace",
|
|
20
|
+
value: importIdentifier
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const namedImport = $import.importClause.named.find(({ binding }) => {
|
|
24
|
+
return binding === importIdentifier;
|
|
25
|
+
});
|
|
26
|
+
if (namedImport) return {
|
|
27
|
+
specifier: $import.moduleSpecifier.value,
|
|
28
|
+
isConstant: $import.moduleSpecifier.isConstant,
|
|
29
|
+
clause: {
|
|
30
|
+
type: "named",
|
|
31
|
+
value: namedImport.specifier,
|
|
32
|
+
...namedImport.binding !== namedImport.specifier ? { alias: namedImport.binding } : {}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
function inspectClass(node) {
|
|
39
|
+
return node.find({ rule: { kind: "class_declaration" } });
|
|
40
|
+
}
|
|
41
|
+
function inspectClassMethods(node) {
|
|
42
|
+
return node.findAll({ rule: { kind: "method_definition" } });
|
|
43
|
+
}
|
|
44
|
+
function nodeToPlainText(node) {
|
|
45
|
+
let out = [];
|
|
46
|
+
function toText(one) {
|
|
47
|
+
const children = one.children();
|
|
48
|
+
if (!children.length) out.push(one.text());
|
|
49
|
+
else children.forEach((child) => toText(child));
|
|
50
|
+
}
|
|
51
|
+
toText(node);
|
|
52
|
+
return out.join("");
|
|
53
|
+
}
|
|
54
|
+
function inspectMethodArguments(node, methodCalls) {
|
|
55
|
+
return node.findAll({ rule: { any: methodCalls.map((methodCall) => {
|
|
56
|
+
return { pattern: {
|
|
57
|
+
context: `${methodCall}($$$ARGUMENTS)`,
|
|
58
|
+
selector: "call_expression"
|
|
59
|
+
} };
|
|
60
|
+
}) } }).flatMap((matchingExpression) => {
|
|
61
|
+
return matchingExpression.findAll({ rule: { kind: "arguments" } });
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function searchValidatorDirectUsage(node) {
|
|
65
|
+
return node.findAll({ rule: { pattern: {
|
|
66
|
+
context: "$$$VALIDATOR.validate($$$)",
|
|
67
|
+
selector: "call_expression"
|
|
68
|
+
} } }).flatMap((expression) => {
|
|
69
|
+
return expression.getMultipleMatches("VALIDATOR");
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export { findImport, inspectClass, inspectClassMethods, inspectMethodArguments, nodeToPlainText, searchValidatorDirectUsage };
|
|
@@ -1,7 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import "../../virtual_file_system-bGeoWsK-.js";
|
|
2
|
+
import { t as IndexGeneratorSource } from "../../source-dVeugJ0e.js";
|
|
3
|
+
var IndexGenerator = class {
|
|
4
|
+
appRoot;
|
|
5
|
+
#sources = {};
|
|
6
|
+
#cliLogger;
|
|
7
|
+
constructor(appRoot, cliLogger) {
|
|
8
|
+
this.appRoot = appRoot;
|
|
9
|
+
this.#cliLogger = cliLogger;
|
|
10
|
+
}
|
|
11
|
+
add(name, config) {
|
|
12
|
+
this.#sources[name] = new IndexGeneratorSource(name, this.appRoot, this.#cliLogger, config);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
async addFile(filePath) {
|
|
16
|
+
const sources = Object.values(this.#sources);
|
|
17
|
+
for (let source of sources) await source.addFile(filePath);
|
|
18
|
+
}
|
|
19
|
+
async removeFile(filePath) {
|
|
20
|
+
const sources = Object.values(this.#sources);
|
|
21
|
+
for (let source of sources) await source.removeFile(filePath);
|
|
22
|
+
}
|
|
23
|
+
async generate() {
|
|
24
|
+
const sources = Object.values(this.#sources);
|
|
25
|
+
for (let source of sources) await source.generate();
|
|
26
|
+
if (sources.length) this.#cliLogger.info(`codegen: created ${sources.length} file(s)`);
|
|
27
|
+
}
|
|
7
28
|
};
|
|
29
|
+
export { IndexGenerator };
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class PathsResolver {
|
|
15
15
|
#private;
|
|
16
|
+
constructor(appRoot: string);
|
|
16
17
|
/**
|
|
17
18
|
* Define a custom resolver that resolves a path
|
|
18
19
|
*
|
|
@@ -36,5 +37,5 @@ export declare class PathsResolver {
|
|
|
36
37
|
* const path = resolver.resolve('#app/models/user')
|
|
37
38
|
* const path2 = resolver.resolve('@/utils/helper')
|
|
38
39
|
*/
|
|
39
|
-
resolve(specifier: string): string;
|
|
40
|
+
resolve(specifier: string, rewriteAliasImportExtension?: boolean): string;
|
|
40
41
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type tsStatic from 'typescript';
|
|
2
1
|
import type { TestRunnerOptions } from './types/common.ts';
|
|
3
2
|
/**
|
|
4
3
|
* Exposes the API to run Japa tests and optionally watch for file
|
|
@@ -33,6 +32,7 @@ export declare class TestRunner {
|
|
|
33
32
|
logger: import("@poppinss/cliui").Logger;
|
|
34
33
|
table: (tableOptions?: Partial<import("@poppinss/cliui/types").TableOptions>) => import("@poppinss/cliui").Table;
|
|
35
34
|
tasks: (tasksOptions?: Partial<import("@poppinss/cliui/types").TaskManagerOptions>) => import("@poppinss/cliui").TaskManager;
|
|
35
|
+
steps: () => import("@poppinss/cliui").Steps;
|
|
36
36
|
icons: {
|
|
37
37
|
tick: string;
|
|
38
38
|
cross: string;
|
|
@@ -42,6 +42,7 @@ export declare class TestRunner {
|
|
|
42
42
|
info: string;
|
|
43
43
|
warning: string;
|
|
44
44
|
squareSmallFilled: string;
|
|
45
|
+
borderVertical: string;
|
|
45
46
|
};
|
|
46
47
|
sticker: () => import("@poppinss/cliui").Instructions;
|
|
47
48
|
instructions: () => import("@poppinss/cliui").Instructions;
|
|
@@ -111,7 +112,7 @@ export declare class TestRunner {
|
|
|
111
112
|
* @param ts - TypeScript module reference for parsing configuration
|
|
112
113
|
* @param options - Watch options including polling mode for file system monitoring
|
|
113
114
|
*/
|
|
114
|
-
runAndWatch(
|
|
115
|
+
runAndWatch(options?: {
|
|
115
116
|
poll: boolean;
|
|
116
117
|
}): Promise<void>;
|
|
117
118
|
}
|
|
@@ -70,8 +70,8 @@ export type ScannedValidator = {
|
|
|
70
70
|
* pattern: '/users',
|
|
71
71
|
* tokens: [{ val: '/users', old: '/users', type: 0, end: '' }],
|
|
72
72
|
* request: {
|
|
73
|
-
* type: '
|
|
74
|
-
* imports: ['import {
|
|
73
|
+
* type: 'InferInput<typeof createUserValidator>',
|
|
74
|
+
* imports: ['import { InferInput } from "@vinejs/vine/types"']
|
|
75
75
|
* },
|
|
76
76
|
* response: {
|
|
77
77
|
* type: 'ReturnType<UsersController["store"]>',
|
|
@@ -174,12 +174,12 @@ export type RoutesListItem = {
|
|
|
174
174
|
domain: string;
|
|
175
175
|
/** HTTP methods accepted by this route */
|
|
176
176
|
methods: string[];
|
|
177
|
-
/**
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
|
|
177
|
+
/** Handler information for controller-based routes */
|
|
178
|
+
handler?: {
|
|
179
|
+
/** The method name to be called on the controller */
|
|
180
|
+
method: string;
|
|
181
|
+
/** Dynamic import expression that loads the controller module */
|
|
182
|
+
importExpression: string | null;
|
|
183
183
|
};
|
|
184
184
|
/** Parsed route tokens for URI construction */
|
|
185
185
|
tokens: {
|
|
@@ -189,6 +189,27 @@ export type RoutesListItem = {
|
|
|
189
189
|
end: string;
|
|
190
190
|
}[];
|
|
191
191
|
};
|
|
192
|
+
/**
|
|
193
|
+
* A filter function to exclude routes from being processed by the routes scanner.
|
|
194
|
+
* Return false to filter out (exclude) the route, or true to include it.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* const filterFn: RoutesScannerFilterFn = (route) => {
|
|
198
|
+
* // Exclude all admin routes
|
|
199
|
+
* if (route.pattern.startsWith('/admin')) {
|
|
200
|
+
* return false
|
|
201
|
+
* }
|
|
202
|
+
*
|
|
203
|
+
* // Exclude health check routes
|
|
204
|
+
* if (route.name === 'health.check') {
|
|
205
|
+
* return false
|
|
206
|
+
* }
|
|
207
|
+
*
|
|
208
|
+
* // Include all other routes
|
|
209
|
+
* return true
|
|
210
|
+
* }
|
|
211
|
+
*/
|
|
212
|
+
export type RoutesScannerFilterFn = (route: RoutesListItem) => boolean;
|
|
192
213
|
/**
|
|
193
214
|
* Configuration rules accepted by the routes scanner to customize
|
|
194
215
|
* the scanning behavior and override type inference.
|
|
@@ -211,11 +232,6 @@ export type RoutesListItem = {
|
|
|
211
232
|
* }
|
|
212
233
|
*/
|
|
213
234
|
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
235
|
/**
|
|
220
236
|
* Define custom response types for specific routes by their name
|
|
221
237
|
* or controller+method path. Overrides automatic type inference.
|