@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
@@ -3,67 +3,283 @@ 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';
9
+ import type Hooks from '@poppinss/hooks';
6
10
  /**
7
- * Hooks executed by the file watcher.
11
+ * Defines a hook that can be either a lazy import or an object with a run method.
12
+ * This type provides flexibility in how hooks are defined and imported, supporting
13
+ * both dynamic imports for code splitting and direct object definitions.
14
+ *
15
+ * @template Fn - The function signature that the hook must conform to
16
+ *
17
+ * @example
18
+ * // Using lazy import
19
+ * const hook: DefineHook<(server: DevServer) => void> = () => import('./my-hook')
20
+ *
21
+ * // Using direct object
22
+ * const hook: DefineHook<(server: DevServer) => void> = {
23
+ * run: (server) => console.log('Hook executed')
24
+ * }
25
+ */
26
+ type DefineHook<Fn extends (...args: any) => any> = LazyImport<Fn> | {
27
+ run: Fn;
28
+ };
29
+ /**
30
+ * Common hooks executed by the dev-server, test runner and the bundler.
31
+ * These hooks are shared across all assembler operations and provide
32
+ * lifecycle management for initialization tasks.
33
+ *
34
+ * @example
35
+ * const commonHooks: CommonHooks = {
36
+ * init: [
37
+ * () => import('./hooks/create_barrel_files')
38
+ * ]
39
+ * }
40
+ */
41
+ export type CommonHooks = {
42
+ /**
43
+ * The hook is executed as the first step when assembler starts the
44
+ * dev-server, runs tests or creates a build. Use this hook to perform
45
+ * initialization tasks that are common across all operations.
46
+ *
47
+ * @param parent - The parent instance (DevServer, TestRunner, or Bundler)
48
+ */
49
+ init: DefineHook<(parent: DevServer | TestRunner | Bundler, hooks: Hooks<{
50
+ [P in keyof AllHooks]: [HookParams<P>, HookParams<P>];
51
+ }>, indexGenerator: IndexGenerator) => AsyncOrSync<void>>[];
52
+ };
53
+ /**
54
+ * Hooks executed by the dev server around the router.
55
+ * These hooks provide lifecycle management for route scanning and processing.
56
+ *
57
+ * @example
58
+ * const routerHooks: RouterHooks = {
59
+ * routesCommitted: [
60
+ * () => import('./hooks/on_routes_committed')
61
+ * ],
62
+ * routesScanning: [
63
+ * () => import('./hooks/before_routes_scan')
64
+ * ],
65
+ * routesScanned: [
66
+ * () => import('./hooks/after_routes_scan')
67
+ * ]
68
+ * }
69
+ */
70
+ export type RouterHooks = {
71
+ /**
72
+ * The hook is executed when routes are committed by the dev server child
73
+ * process. Use this hook to react to route changes and perform related tasks.
74
+ *
75
+ * @param parent - The DevServer instance
76
+ * @param routes - Record of routes grouped by domain or method
77
+ */
78
+ routesCommitted: DefineHook<(parent: DevServer, routes: Record<string, RoutesListItem[]>) => AsyncOrSync<void>>[];
79
+ /**
80
+ * The hook is executed when dev server begins the routes scanning process.
81
+ * Use this hook to prepare for route scanning or modify scanner configuration.
82
+ *
83
+ * @param parent - The DevServer instance
84
+ * @param routesScanner - The RoutesScanner instance being used
85
+ */
86
+ routesScanning: DefineHook<(parent: DevServer, routesScanner: RoutesScanner) => AsyncOrSync<void>>[];
87
+ /**
88
+ * The hook is executed when routes scanning process has finished.
89
+ * Use this hook to process the scanned routes or clean up resources.
90
+ *
91
+ * @param parent - The DevServer instance
92
+ * @param routesScanner - The RoutesScanner instance that was used
93
+ */
94
+ routesScanned: DefineHook<(parent: DevServer, routesScanner: RoutesScanner) => AsyncOrSync<void>>[];
95
+ };
96
+ /**
97
+ * Hooks executed by the file watcher during development and testing.
8
98
  *
9
99
  * - In HMR mode, assembler will rely on hot-hook to notify about the filesystem changes.
10
100
  * - Otherwise, the inbuilt watcher of the DevServer or the TestsRunner will notify.
101
+ *
102
+ * @example
103
+ * const watcherHooks: WatcherHooks = {
104
+ * fileChanged: [
105
+ * () => import('./hooks/on_file_changed')
106
+ * ],
107
+ * fileAdded: [
108
+ * () => import('./hooks/on_file_added')
109
+ * ],
110
+ * fileRemoved: [
111
+ * () => import('./hooks/on_file_removed')
112
+ * ]
113
+ * }
11
114
  */
12
115
  export type WatcherHooks = {
13
116
  /**
14
- * The hook is executed after a file has been changed in the watch mode.
117
+ * The hook is executed after a file has been changed in watch mode.
118
+ * Provides information about the change source and reload behavior.
119
+ * Use this hook to react to file changes and trigger custom actions.
120
+ *
121
+ * @param filePath - The relative path to the changed file
122
+ * @param info - Information about the file change
123
+ * @param info.source - Source of the file change notification
124
+ * @param info.hotReloaded - Whether the file was hot reloaded without server restart
125
+ * @param info.fullReload - Whether a full server reload is required
126
+ * @param parent - The parent DevServer or TestRunner instance
15
127
  */
16
- fileChanged: LazyImport<(filePath: string, info: {
128
+ fileChanged: DefineHook<(relativePath: string, absolutePath: string, info: {
129
+ /** Source of the file change notification */
17
130
  source: 'hot-hook' | 'watcher';
131
+ /** Whether the file was hot reloaded without server restart */
18
132
  hotReloaded: boolean;
133
+ /** Whether a full server reload is required */
19
134
  fullReload: boolean;
20
- }, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
135
+ }, parent: DevServer | TestRunner) => AsyncOrSync<void>>[];
21
136
  /**
22
- * The hook is executed after a file has been added.
137
+ * The hook is executed after a file has been added to the filesystem.
138
+ * Use this hook to react to new files being added to the project.
139
+ *
140
+ * @param filePath - The absolute path to the added file
141
+ * @param server - The DevServer or TestRunner instance
23
142
  */
24
- fileAdded: LazyImport<(filePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
143
+ fileAdded: DefineHook<(relativePath: string, absolutePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
25
144
  /**
26
- * The hook is executed after a file has been removed.
145
+ * The hook is executed after a file has been removed from the filesystem.
146
+ * Use this hook to clean up resources or update caches when files are deleted.
147
+ *
148
+ * @param filePath - The absolute path to the removed file
149
+ * @param server - The DevServer or TestRunner instance
27
150
  */
28
- fileRemoved: LazyImport<(filePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
151
+ fileRemoved: DefineHook<(relativePath: string, absolutePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
29
152
  };
30
153
  /**
31
- * Hooks executed when running the dev server.
154
+ * Hooks executed when running the development server.
155
+ *
156
+ * @example
157
+ * const devServerHooks: DevServerHooks = {
158
+ * devServerStarting: [
159
+ * () => import('./hooks/before_dev_server_start')
160
+ * ],
161
+ * devServerStarted: [
162
+ * () => import('./hooks/after_dev_server_start')
163
+ * ]
164
+ * }
32
165
  */
33
166
  export type DevServerHooks = {
34
167
  /**
35
- * The hook is executed before the child process for the dev server
36
- * is started.
168
+ * The hook is executed before the child process for the dev server is started.
169
+ * Use this hook to perform setup tasks or modify server configuration.
170
+ *
171
+ * @param server - The DevServer instance that is about to start
37
172
  */
38
- devServerStarting: LazyImport<(server: DevServer) => AsyncOrSync<void>>[];
173
+ devServerStarting: DefineHook<(server: DevServer) => AsyncOrSync<void>>[];
39
174
  /**
40
175
  * The hook is executed after the child process has been started.
176
+ * Use this hook to display additional information or perform post-startup tasks.
177
+ *
178
+ * @param server - The DevServer instance that has started
179
+ * @param info - Server information containing port and host
180
+ * @param info.port - The port number the server is running on
181
+ * @param info.host - The host address the server is bound to
182
+ * @param uiInstructions - UI instructions for displaying server information
41
183
  */
42
- devServerStarted: LazyImport<(server: DevServer, uiInstructions: Instructions) => AsyncOrSync<void>>[];
184
+ devServerStarted: DefineHook<(server: DevServer, info: {
185
+ port: number;
186
+ host: string;
187
+ }, uiInstructions: Instructions) => AsyncOrSync<void>>[];
43
188
  };
44
189
  /**
45
190
  * Hooks executed when the production build is created.
191
+ *
192
+ * @example
193
+ * const bundlerHooks: BundlerHooks = {
194
+ * buildStarting: [
195
+ * () => import('./hooks/before_build')
196
+ * ],
197
+ * buildFinished: [
198
+ * () => import('./hooks/after_build')
199
+ * ]
200
+ * }
46
201
  */
47
202
  export type BundlerHooks = {
48
203
  /**
49
- * The hook is executed before we begin creating the production build
204
+ * The hook is executed before we begin creating the production build.
205
+ * Use this hook to perform pre-build tasks like asset optimization.
206
+ *
207
+ * @param server - The Bundler instance that will create the build
50
208
  */
51
- buildStarting: LazyImport<(server: Bundler) => AsyncOrSync<void>>[];
209
+ buildStarting: DefineHook<(server: Bundler) => AsyncOrSync<void>>[];
52
210
  /**
53
- * The hook is executed after the production build has been created
211
+ * The hook is executed after the production build has been created.
212
+ * Use this hook to perform post-build tasks or display build statistics.
213
+ *
214
+ * @param server - The Bundler instance that created the build
215
+ * @param uiInstructions - UI instructions for displaying build information
54
216
  */
55
- buildFinished: LazyImport<(server: Bundler, uiInstructions: Instructions) => AsyncOrSync<void>>[];
217
+ buildFinished: DefineHook<(server: Bundler, uiInstructions: Instructions) => AsyncOrSync<void>>[];
56
218
  };
57
219
  /**
58
- * Hooks executed when running the tests
220
+ * Hooks executed when running the test suite.
221
+ *
222
+ * @example
223
+ * const testRunnerHooks: TestRunnerHooks = {
224
+ * testsStarting: [
225
+ * () => import('./hooks/before_tests')
226
+ * ],
227
+ * testsFinished: [
228
+ * () => import('./hooks/after_tests')
229
+ * ]
230
+ * }
59
231
  */
60
232
  export type TestRunnerHooks = {
61
233
  /**
62
- * The hook is executed before we begin executing the tests
234
+ * The hook is executed before we begin executing the tests.
235
+ * Use this hook to set up test databases or perform pre-test setup.
236
+ *
237
+ * @param server - The TestRunner instance that will execute the tests
63
238
  */
64
- testsStarting: LazyImport<(server: TestRunner) => AsyncOrSync<void>>[];
239
+ testsStarting: DefineHook<(server: TestRunner) => AsyncOrSync<void>>[];
65
240
  /**
66
- * The hook is executed after the tests have been executed
241
+ * The hook is executed after the tests have been executed.
242
+ * Use this hook to clean up resources or generate test reports.
243
+ *
244
+ * @param server - The TestRunner instance that executed the tests
67
245
  */
68
- testsFinished: LazyImport<(server: TestRunner) => AsyncOrSync<void>>[];
246
+ testsFinished: DefineHook<(server: TestRunner) => AsyncOrSync<void>>[];
69
247
  };
248
+ /**
249
+ * Combined type representing all available hooks across the assembler ecosystem.
250
+ * This intersection type merges all hook categories into a single type for
251
+ * comprehensive hook management and type safety.
252
+ *
253
+ * @example
254
+ * ```js
255
+ * const allHooks: AllHooks = {
256
+ * init: [() => import('./hooks/init')],
257
+ * fileChanged: [() => import('./hooks/file_changed')],
258
+ * devServerStarted: [() => import('./hooks/dev_server_started')],
259
+ * buildFinished: [() => import('./hooks/build_finished')],
260
+ * testsFinished: [() => import('./hooks/tests_finished')],
261
+ * routesCommitted: [() => import('./hooks/routes_committed')]
262
+ * }
263
+ * ```
264
+ */
265
+ export type AllHooks = CommonHooks & WatcherHooks & DevServerHooks & BundlerHooks & TestRunnerHooks & RouterHooks;
266
+ /**
267
+ * Utility type that extracts the parameter types for a specific hook.
268
+ * This type helps maintain type safety when working with hook callbacks
269
+ * by providing the exact parameter signature for any given hook name.
270
+ *
271
+ * @template Hook - The name of the hook to extract parameters for
272
+ *
273
+ * @example
274
+ * ```js
275
+ * // Get parameters for the fileChanged hook
276
+ * type FileChangedParams = HookParams<'fileChanged'>
277
+ * // Result: [string, string, {...}, DevServer | TestRunner]
278
+ *
279
+ * // Get parameters for the devServerStarted hook
280
+ * type DevServerStartedParams = HookParams<'devServerStarted')
281
+ * // Result: [DevServer, {port: number, host: string}, Instructions]
282
+ * ```
283
+ */
284
+ export type HookParams<Hook extends keyof AllHooks> = AllHooks[Hook][number] extends DefineHook<infer A> ? Parameters<A> : never;
285
+ export {};
@@ -1,3 +1,17 @@
1
- export * from './common.ts';
1
+ /**
2
+ * Main types module that re-exports all TypeScript type definitions
3
+ * used throughout the AdonisJS Assembler package.
4
+ *
5
+ * This module provides a single entry point for all type definitions including:
6
+ * - Hook types for development server, bundler, test runner, and file watcher
7
+ * - Common configuration types for servers and runners
8
+ * - Code scanner types for route analysis and type generation
9
+ * - Code transformer types for middleware, policies, and environment validation
10
+ *
11
+ * @example
12
+ * import { DevServerOptions, BundlerHooks, ScannedRoute } from '@adonisjs/assembler/types'
13
+ */
2
14
  export * from './hooks.ts';
15
+ export * from './common.ts';
16
+ export * from './code_scanners.ts';
3
17
  export * from './code_transformer.ts';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,16 +1,34 @@
1
1
  import Hooks from '@poppinss/hooks';
2
2
  import type tsStatic from 'typescript';
3
3
  import { type ChokidarOptions } from 'chokidar';
4
- import { type UnWrapLazyImport } from '@poppinss/utils/types';
4
+ import { type TsConfigResult } from 'get-tsconfig';
5
5
  import type { RunScriptOptions } from './types/common.ts';
6
- import { type WatcherHooks, type BundlerHooks, type DevServerHooks, type TestRunnerHooks } from './types/hooks.ts';
6
+ import { type AllHooks, type HookParams } from './types/hooks.ts';
7
7
  /**
8
- * Parses tsconfig.json and prints errors using typescript compiler
9
- * host
8
+ * Parses tsconfig.json and prints errors using typescript compiler host
9
+ *
10
+ * This function reads and parses the tsconfig.json file from the given directory,
11
+ * handling diagnostic errors and returning a parsed configuration that can be
12
+ * used by other TypeScript operations.
13
+ *
14
+ * @deprecated While we are experimenting with the readTsConfig method
15
+ *
16
+ * @param cwd - The current working directory URL or string path
17
+ * @param ts - TypeScript module reference
18
+ * @returns Parsed TypeScript configuration or undefined if parsing failed
10
19
  */
11
20
  export declare function parseConfig(cwd: URL | string, ts: typeof tsStatic): tsStatic.ParsedCommandLine | undefined;
21
+ export declare function readTsConfig(cwd: string): TsConfigResult | null;
12
22
  /**
13
23
  * Runs a Node.js script as a child process and inherits the stdio streams
24
+ *
25
+ * This function spawns a Node.js child process with TypeScript support enabled
26
+ * by default through ts-exec. It's primarily used for running development
27
+ * servers and test scripts.
28
+ *
29
+ * @param cwd - The current working directory URL or string path
30
+ * @param options - Script execution options including args, environment, etc.
31
+ * @returns Child process instance from execa
14
32
  */
15
33
  export declare function runNode(cwd: string | URL, options: RunScriptOptions): import("execa").ResultPromise<{
16
34
  nodeOptions: string[];
@@ -22,12 +40,19 @@ export declare function runNode(cwd: string | URL, options: RunScriptOptions): i
22
40
  buffer: false;
23
41
  stdio: "pipe" | "inherit";
24
42
  env: {
25
- TZ?: string;
43
+ TZ?: string | undefined;
26
44
  FORCE_COLOR?: string | undefined;
27
45
  };
28
46
  }>;
29
47
  /**
30
48
  * Runs a script as a child process and inherits the stdio streams
49
+ *
50
+ * This function spawns a generic child process for running any executable
51
+ * script. Unlike runNode, this doesn't include TypeScript-specific Node.js arguments.
52
+ *
53
+ * @param cwd - The current working directory URL or string path
54
+ * @param options - Script execution options (excluding nodeArgs)
55
+ * @returns Child process instance from execa
31
56
  */
32
57
  export declare function run(cwd: string | URL, options: Omit<RunScriptOptions, 'nodeArgs'>): import("execa").ResultPromise<{
33
58
  preferLocal: true;
@@ -37,56 +62,112 @@ export declare function run(cwd: string | URL, options: Omit<RunScriptOptions, '
37
62
  buffer: false;
38
63
  stdio: "pipe" | "inherit";
39
64
  env: {
40
- TZ?: string;
65
+ TZ?: string | undefined;
41
66
  FORCE_COLOR?: string | undefined;
42
67
  };
43
68
  }>;
44
69
  /**
45
- * Watches the file system using tsconfig file
70
+ * Watches the file system using chokidar with the provided options
71
+ *
72
+ * Creates a file system watcher that monitors the current directory
73
+ * for changes, supporting various chokidar options for customization.
74
+ *
75
+ * @param options - Chokidar watch options
76
+ * @returns Chokidar FSWatcher instance
46
77
  */
47
78
  export declare function watch(options: ChokidarOptions): import("chokidar").FSWatcher;
48
79
  /**
49
80
  * Check if file is a .env file
81
+ *
82
+ * Determines if a given file path represents an environment file,
83
+ * including .env and .env.* variants.
84
+ *
85
+ * @param filePath - The file path to check
86
+ * @returns True if the file is an environment file
50
87
  */
51
88
  export declare function isDotEnvFile(filePath: string): boolean;
52
89
  /**
53
- * Returns the port to use after inspect the dot-env files inside
90
+ * Returns the port to use after inspecting the dot-env files inside
54
91
  * a given directory.
55
92
  *
56
93
  * A random port is used when the specified port is in use. Following
57
- * is the logic for finding a specified port.
94
+ * is the logic for finding a specified port:
58
95
  *
59
96
  * - The "process.env.PORT" value is used if exists.
60
97
  * - The dot-env files are loaded using the "EnvLoader" and the PORT
61
98
  * value is used by iterating over all the loaded files. The
62
99
  * iteration stops after first find.
100
+ * - Falls back to port 3333 if no PORT is found in environment files.
101
+ *
102
+ * @param cwd - The current working directory URL
103
+ * @returns Promise resolving to an available port number
63
104
  */
64
105
  export declare function getPort(cwd: URL): Promise<number>;
65
106
  /**
66
- * Helper function to copy files from relative paths or glob
67
- * patterns
107
+ * Helper function to copy files from relative paths or glob patterns
108
+ *
109
+ * This function handles copying files and directories while preserving
110
+ * directory structure. It supports both direct file paths and glob patterns,
111
+ * and automatically filters out junk files.
112
+ *
113
+ * @param files - Array of file paths or glob patterns to copy
114
+ * @param cwd - Source directory path
115
+ * @param outDir - Destination directory path
116
+ * @returns Promise resolving when all files are copied
68
117
  */
69
118
  export declare function copyFiles(files: string[], cwd: string, outDir: string): Promise<void[]>;
70
119
  /**
71
120
  * Memoize a function using an LRU cache. The function must accept
72
121
  * only one argument as a string value.
122
+ *
123
+ * This utility provides caching for expensive function calls to improve
124
+ * performance by storing results in memory.
125
+ *
126
+ * @param fn - Function to memoize (only first argument is considered for memoization)
127
+ * @param maxKeys - Optional maximum number of cached keys
128
+ * @returns Memoized version of the function
73
129
  */
74
- export declare function memoize<Result>(fn: (input: string) => any, maxKeys?: number): (input: string) => Result;
130
+ export declare function memoize<T extends any[], Result>(fn: (input: string, ...args: T) => any, maxKeys?: number): (input: string, ...args: T) => Result;
75
131
  /**
76
132
  * Returns a boolean telling if the path value is a relative
77
133
  * path starting with "./" or "../"
134
+ *
135
+ * @param pathValue - The path string to check
136
+ * @returns True if the path is relative, false otherwise
78
137
  */
79
138
  export declare function isRelative(pathValue: string): boolean;
80
139
  /**
81
140
  * Imports a selected set of lazy hooks and creates an instance of the
82
141
  * Hooks class
142
+ *
143
+ * This function dynamically imports and initializes hooks based on the
144
+ * provided configuration, supporting different types of hooks for various
145
+ * assembler operations.
146
+ *
147
+ * @param rcFileHooks - Hook configuration from the RC file
148
+ * @param names - Array of hook names to load
149
+ * @returns Promise resolving to configured Hooks instance
83
150
  */
84
- type AllHooks = WatcherHooks & DevServerHooks & BundlerHooks & TestRunnerHooks;
85
- export declare function loadHooks<K extends keyof AllHooks>(rcFileHooks: Partial<AllHooks> | undefined, names: K[]): Promise<Hooks<{ [P in K]: [Parameters<UnWrapLazyImport<AllHooks[K][number]>>, Parameters<UnWrapLazyImport<AllHooks[K][number]>>]; }>>;
151
+ export declare function loadHooks<K extends keyof AllHooks>(rcFileHooks: Partial<AllHooks> | undefined, names: K[]): Promise<Hooks<{
152
+ [P in K]: [HookParams<P>, HookParams<P>];
153
+ }>>;
86
154
  /**
87
155
  * Wraps a function inside another function that throttles the concurrent
88
156
  * executions of a function. If the function is called too quickly, then
89
157
  * it may result in two invocations at max.
158
+ *
159
+ * This utility prevents overwhelming the system with rapid successive calls
160
+ * by ensuring only one execution happens at a time, with at most one queued call.
161
+ *
162
+ * @param fn - Function to throttle
163
+ * @param name - Optional name for debugging purposes
164
+ * @returns Throttled version of the function
90
165
  */
91
166
  export declare function throttle<Args extends any[]>(fn: (...args: Args) => PromiseLike<any>, name?: string): (...args: Args) => Promise<void>;
92
- export {};
167
+ /**
168
+ * Removes the file extension from a file path
169
+ *
170
+ * @param filePath - The file path with extension
171
+ * @returns The file path without extension
172
+ */
173
+ export declare function removeExtension(filePath: string): string;
@@ -0,0 +1,112 @@
1
+ import { type SgNode } from '@ast-grep/napi';
2
+ import { type RecursiveFileTree, type VirtualFileSystemOptions } from './types/common.ts';
3
+ /**
4
+ * Virtual file system for managing and tracking files with AST parsing capabilities.
5
+ *
6
+ * The VirtualFileSystem provides an abstraction layer over the physical file system,
7
+ * allowing efficient file scanning, filtering, and AST parsing with caching. It's
8
+ * designed to work with TypeScript/JavaScript files and provides various output
9
+ * formats for different use cases.
10
+ *
11
+ * @example
12
+ * const vfs = new VirtualFileSystem('/src', { glob: ['**\/*.ts'] })
13
+ * await vfs.scan()
14
+ * const fileTree = vfs.asTree()
15
+ * const astNode = await vfs.get('/src/app.ts')
16
+ */
17
+ export declare class VirtualFileSystem {
18
+ #private;
19
+ /**
20
+ * Create a new VirtualFileSystem instance
21
+ *
22
+ * @param source - Absolute path to the source directory
23
+ * @param options - Optional configuration for file filtering and processing
24
+ */
25
+ constructor(source: string, options?: VirtualFileSystemOptions);
26
+ /**
27
+ * Scans the filesystem to collect the files. Newly files must
28
+ * be added via the ".add" method.
29
+ *
30
+ * This method performs an initial scan of the source directory using
31
+ * the configured glob patterns and populates the internal file list.
32
+ */
33
+ scan(): Promise<void>;
34
+ /**
35
+ * Check if a given file is part of the virtual file system. The method
36
+ * checks for the scanned files as well as glob pattern matches.
37
+ *
38
+ * @param filePath - Absolute file path to check
39
+ * @returns True if the file is tracked or matches the configured patterns
40
+ */
41
+ has(filePath: string): boolean;
42
+ /**
43
+ * Returns the files as a flat list of key-value pairs
44
+ *
45
+ * Converts the tracked files into a flat object where keys are relative
46
+ * paths (without extensions) and values are absolute file paths.
47
+ *
48
+ * @param options - Optional transformation functions for keys and values
49
+ * @returns Object with file mappings
50
+ */
51
+ asList(options?: {
52
+ transformKey?: (key: string) => string;
53
+ transformValue?: (filePath: string) => string;
54
+ }): {
55
+ [key: string]: string;
56
+ };
57
+ /**
58
+ * Returns the files as a nested tree structure
59
+ *
60
+ * Converts the tracked files into a hierarchical object structure that
61
+ * mirrors the directory structure of the source files.
62
+ *
63
+ * @param options - Optional transformation functions for keys and values
64
+ * @returns Nested object representing the file tree
65
+ */
66
+ asTree(options?: {
67
+ transformKey?: (key: string) => string;
68
+ transformValue?: (filePath: string, key: string) => string;
69
+ }): RecursiveFileTree;
70
+ /**
71
+ * Add a new file to the virtual file system. File is only added when it
72
+ * matches the pre-defined filters.
73
+ *
74
+ * @param filePath - Absolute path of the file to add
75
+ * @returns True if the file was added, false if it doesn't match filters
76
+ */
77
+ add(filePath: string): boolean;
78
+ /**
79
+ * Remove a file from the virtual file system
80
+ *
81
+ * @param filePath - Absolute path of the file to remove
82
+ * @returns True if the file was removed, false if it wasn't tracked
83
+ */
84
+ remove(filePath: string): boolean;
85
+ /**
86
+ * Returns the file contents as AST-grep node and caches it
87
+ * forever. Use the "invalidate" method to remove it from the cache.
88
+ *
89
+ * This method reads the file content, parses it into an AST using ast-grep,
90
+ * and caches the result for future requests to improve performance.
91
+ *
92
+ * @param filePath - The absolute path to the file to parse
93
+ * @returns Promise resolving to the AST-grep node
94
+ */
95
+ get(filePath: string): Promise<SgNode>;
96
+ /**
97
+ * Invalidates AST cache for a single file or all files
98
+ *
99
+ * Use this method when files have been modified to ensure fresh
100
+ * AST parsing on subsequent get() calls.
101
+ *
102
+ * @param filePath - Optional file path to clear. If omitted, clears entire cache
103
+ */
104
+ invalidate(filePath?: string): void;
105
+ /**
106
+ * Clear all scanned files from memory
107
+ *
108
+ * Removes all tracked files from the internal file list, effectively
109
+ * resetting the virtual file system.
110
+ */
111
+ clear(): void;
112
+ }