@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.
- package/README.md +88 -84
- package/build/chunk-4452KFDQ.js +465 -0
- package/build/chunk-JFBQ4OEM.js +434 -0
- package/build/chunk-NAASGAFO.js +478 -0
- package/build/chunk-TIKQQRMX.js +116 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +800 -447
- package/build/src/bundler.d.ts +44 -3
- package/build/src/code_scanners/routes_scanner/main.d.ts +119 -0
- package/build/src/code_scanners/routes_scanner/main.js +8 -0
- package/build/src/code_scanners/routes_scanner/validator_extractor.d.ts +26 -0
- package/build/src/code_transformer/main.d.ts +44 -43
- package/build/src/code_transformer/main.js +123 -101
- package/build/src/code_transformer/rc_file_transformer.d.ts +56 -4
- package/build/src/debug.d.ts +12 -0
- package/build/src/dev_server.d.ts +92 -17
- package/build/src/file_buffer.d.ts +87 -0
- package/build/src/file_system.d.ts +46 -8
- package/build/src/helpers.d.ts +115 -0
- package/build/src/helpers.js +16 -0
- package/build/src/index_generator/main.d.ts +68 -0
- package/build/src/index_generator/main.js +7 -0
- package/build/src/index_generator/source.d.ts +60 -0
- package/build/src/paths_resolver.d.ts +41 -0
- package/build/src/shortcuts_manager.d.ts +43 -28
- package/build/src/test_runner.d.ts +57 -12
- package/build/src/types/code_scanners.d.ts +226 -0
- package/build/src/types/code_transformer.d.ts +61 -19
- package/build/src/types/common.d.ts +270 -51
- package/build/src/types/hooks.d.ts +235 -22
- package/build/src/types/main.d.ts +15 -1
- package/build/src/utils.d.ts +99 -15
- package/build/src/virtual_file_system.d.ts +112 -0
- package/package.json +33 -20
- package/build/chunk-RR4HCA4M.js +0 -7
|
@@ -3,67 +3,280 @@ 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';
|
|
6
9
|
/**
|
|
7
|
-
*
|
|
10
|
+
* Defines a hook that can be either a lazy import or an object with a run method.
|
|
11
|
+
* This type provides flexibility in how hooks are defined and imported, supporting
|
|
12
|
+
* both dynamic imports for code splitting and direct object definitions.
|
|
13
|
+
*
|
|
14
|
+
* @template Fn - The function signature that the hook must conform to
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Using lazy import
|
|
18
|
+
* const hook: DefineHook<(server: DevServer) => void> = () => import('./my-hook')
|
|
19
|
+
*
|
|
20
|
+
* // Using direct object
|
|
21
|
+
* const hook: DefineHook<(server: DevServer) => void> = {
|
|
22
|
+
* run: (server) => console.log('Hook executed')
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
type DefineHook<Fn extends (...args: any) => any> = LazyImport<Fn> | {
|
|
26
|
+
run: Fn;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Common hooks executed by the dev-server, test runner and the bundler.
|
|
30
|
+
* These hooks are shared across all assembler operations and provide
|
|
31
|
+
* lifecycle management for initialization tasks.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const commonHooks: CommonHooks = {
|
|
35
|
+
* init: [
|
|
36
|
+
* () => import('./hooks/create_barrel_files')
|
|
37
|
+
* ]
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
export type CommonHooks = {
|
|
41
|
+
/**
|
|
42
|
+
* The hook is executed as the first step when assembler starts the
|
|
43
|
+
* dev-server, runs tests or creates a build. Use this hook to perform
|
|
44
|
+
* initialization tasks that are common across all operations.
|
|
45
|
+
*
|
|
46
|
+
* @param parent - The parent instance (DevServer, TestRunner, or Bundler)
|
|
47
|
+
*/
|
|
48
|
+
init: DefineHook<(parent: DevServer | TestRunner | Bundler, indexGenerator: IndexGenerator) => AsyncOrSync<void>>[];
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Hooks executed by the dev server around the router.
|
|
52
|
+
* These hooks provide lifecycle management for route scanning and processing.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* const routerHooks: RouterHooks = {
|
|
56
|
+
* routesCommitted: [
|
|
57
|
+
* () => import('./hooks/on_routes_committed')
|
|
58
|
+
* ],
|
|
59
|
+
* routesScanning: [
|
|
60
|
+
* () => import('./hooks/before_routes_scan')
|
|
61
|
+
* ],
|
|
62
|
+
* routesScanned: [
|
|
63
|
+
* () => import('./hooks/after_routes_scan')
|
|
64
|
+
* ]
|
|
65
|
+
* }
|
|
66
|
+
*/
|
|
67
|
+
export type RouterHooks = {
|
|
68
|
+
/**
|
|
69
|
+
* The hook is executed when routes are committed by the dev server child
|
|
70
|
+
* process. Use this hook to react to route changes and perform related tasks.
|
|
71
|
+
*
|
|
72
|
+
* @param parent - The DevServer instance
|
|
73
|
+
* @param routes - Record of routes grouped by domain or method
|
|
74
|
+
*/
|
|
75
|
+
routesCommitted: DefineHook<(parent: DevServer, routes: Record<string, RoutesListItem[]>) => AsyncOrSync<void>>[];
|
|
76
|
+
/**
|
|
77
|
+
* The hook is executed when dev server begins the routes scanning process.
|
|
78
|
+
* Use this hook to prepare for route scanning or modify scanner configuration.
|
|
79
|
+
*
|
|
80
|
+
* @param parent - The DevServer instance
|
|
81
|
+
* @param routesScanner - The RoutesScanner instance being used
|
|
82
|
+
*/
|
|
83
|
+
routesScanning: DefineHook<(parent: DevServer, routesScanner: RoutesScanner) => AsyncOrSync<void>>[];
|
|
84
|
+
/**
|
|
85
|
+
* The hook is executed when routes scanning process has finished.
|
|
86
|
+
* Use this hook to process the scanned routes or clean up resources.
|
|
87
|
+
*
|
|
88
|
+
* @param parent - The DevServer instance
|
|
89
|
+
* @param routesScanner - The RoutesScanner instance that was used
|
|
90
|
+
*/
|
|
91
|
+
routesScanned: DefineHook<(parent: DevServer, routesScanner: RoutesScanner) => AsyncOrSync<void>>[];
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Hooks executed by the file watcher during development and testing.
|
|
8
95
|
*
|
|
9
96
|
* - In HMR mode, assembler will rely on hot-hook to notify about the filesystem changes.
|
|
10
97
|
* - Otherwise, the inbuilt watcher of the DevServer or the TestsRunner will notify.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* const watcherHooks: WatcherHooks = {
|
|
101
|
+
* fileChanged: [
|
|
102
|
+
* () => import('./hooks/on_file_changed')
|
|
103
|
+
* ],
|
|
104
|
+
* fileAdded: [
|
|
105
|
+
* () => import('./hooks/on_file_added')
|
|
106
|
+
* ],
|
|
107
|
+
* fileRemoved: [
|
|
108
|
+
* () => import('./hooks/on_file_removed')
|
|
109
|
+
* ]
|
|
110
|
+
* }
|
|
11
111
|
*/
|
|
12
112
|
export type WatcherHooks = {
|
|
13
113
|
/**
|
|
14
|
-
* The hook is executed after a file has been changed in
|
|
114
|
+
* The hook is executed after a file has been changed in watch mode.
|
|
115
|
+
* Provides information about the change source and reload behavior.
|
|
116
|
+
* Use this hook to react to file changes and trigger custom actions.
|
|
117
|
+
*
|
|
118
|
+
* @param filePath - The relative path to the changed file
|
|
119
|
+
* @param info - Information about the file change
|
|
120
|
+
* @param info.source - Source of the file change notification
|
|
121
|
+
* @param info.hotReloaded - Whether the file was hot reloaded without server restart
|
|
122
|
+
* @param info.fullReload - Whether a full server reload is required
|
|
123
|
+
* @param parent - The parent DevServer or TestRunner instance
|
|
15
124
|
*/
|
|
16
|
-
fileChanged:
|
|
125
|
+
fileChanged: DefineHook<(relativePath: string, absolutePath: string, info: {
|
|
126
|
+
/** Source of the file change notification */
|
|
17
127
|
source: 'hot-hook' | 'watcher';
|
|
128
|
+
/** Whether the file was hot reloaded without server restart */
|
|
18
129
|
hotReloaded: boolean;
|
|
130
|
+
/** Whether a full server reload is required */
|
|
19
131
|
fullReload: boolean;
|
|
20
|
-
},
|
|
132
|
+
}, parent: DevServer | TestRunner) => AsyncOrSync<void>>[];
|
|
21
133
|
/**
|
|
22
|
-
* The hook is executed after a file has been added.
|
|
134
|
+
* The hook is executed after a file has been added to the filesystem.
|
|
135
|
+
* Use this hook to react to new files being added to the project.
|
|
136
|
+
*
|
|
137
|
+
* @param filePath - The absolute path to the added file
|
|
138
|
+
* @param server - The DevServer or TestRunner instance
|
|
23
139
|
*/
|
|
24
|
-
fileAdded:
|
|
140
|
+
fileAdded: DefineHook<(relativePath: string, absolutePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
|
|
25
141
|
/**
|
|
26
|
-
* The hook is executed after a file has been removed.
|
|
142
|
+
* The hook is executed after a file has been removed from the filesystem.
|
|
143
|
+
* Use this hook to clean up resources or update caches when files are deleted.
|
|
144
|
+
*
|
|
145
|
+
* @param filePath - The absolute path to the removed file
|
|
146
|
+
* @param server - The DevServer or TestRunner instance
|
|
27
147
|
*/
|
|
28
|
-
fileRemoved:
|
|
148
|
+
fileRemoved: DefineHook<(relativePath: string, absolutePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
|
|
29
149
|
};
|
|
30
150
|
/**
|
|
31
|
-
* Hooks executed when running the
|
|
151
|
+
* Hooks executed when running the development server.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* const devServerHooks: DevServerHooks = {
|
|
155
|
+
* devServerStarting: [
|
|
156
|
+
* () => import('./hooks/before_dev_server_start')
|
|
157
|
+
* ],
|
|
158
|
+
* devServerStarted: [
|
|
159
|
+
* () => import('./hooks/after_dev_server_start')
|
|
160
|
+
* ]
|
|
161
|
+
* }
|
|
32
162
|
*/
|
|
33
163
|
export type DevServerHooks = {
|
|
34
164
|
/**
|
|
35
|
-
* The hook is executed before the child process for the dev server
|
|
36
|
-
*
|
|
165
|
+
* The hook is executed before the child process for the dev server is started.
|
|
166
|
+
* Use this hook to perform setup tasks or modify server configuration.
|
|
167
|
+
*
|
|
168
|
+
* @param server - The DevServer instance that is about to start
|
|
37
169
|
*/
|
|
38
|
-
devServerStarting:
|
|
170
|
+
devServerStarting: DefineHook<(server: DevServer) => AsyncOrSync<void>>[];
|
|
39
171
|
/**
|
|
40
172
|
* The hook is executed after the child process has been started.
|
|
173
|
+
* Use this hook to display additional information or perform post-startup tasks.
|
|
174
|
+
*
|
|
175
|
+
* @param server - The DevServer instance that has started
|
|
176
|
+
* @param info - Server information containing port and host
|
|
177
|
+
* @param info.port - The port number the server is running on
|
|
178
|
+
* @param info.host - The host address the server is bound to
|
|
179
|
+
* @param uiInstructions - UI instructions for displaying server information
|
|
41
180
|
*/
|
|
42
|
-
devServerStarted:
|
|
181
|
+
devServerStarted: DefineHook<(server: DevServer, info: {
|
|
182
|
+
port: number;
|
|
183
|
+
host: string;
|
|
184
|
+
}, uiInstructions: Instructions) => AsyncOrSync<void>>[];
|
|
43
185
|
};
|
|
44
186
|
/**
|
|
45
187
|
* Hooks executed when the production build is created.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* const bundlerHooks: BundlerHooks = {
|
|
191
|
+
* buildStarting: [
|
|
192
|
+
* () => import('./hooks/before_build')
|
|
193
|
+
* ],
|
|
194
|
+
* buildFinished: [
|
|
195
|
+
* () => import('./hooks/after_build')
|
|
196
|
+
* ]
|
|
197
|
+
* }
|
|
46
198
|
*/
|
|
47
199
|
export type BundlerHooks = {
|
|
48
200
|
/**
|
|
49
|
-
* The hook is executed before we begin creating the production build
|
|
201
|
+
* The hook is executed before we begin creating the production build.
|
|
202
|
+
* Use this hook to perform pre-build tasks like asset optimization.
|
|
203
|
+
*
|
|
204
|
+
* @param server - The Bundler instance that will create the build
|
|
50
205
|
*/
|
|
51
|
-
buildStarting:
|
|
206
|
+
buildStarting: DefineHook<(server: Bundler) => AsyncOrSync<void>>[];
|
|
52
207
|
/**
|
|
53
|
-
* The hook is executed after the production build has been created
|
|
208
|
+
* The hook is executed after the production build has been created.
|
|
209
|
+
* Use this hook to perform post-build tasks or display build statistics.
|
|
210
|
+
*
|
|
211
|
+
* @param server - The Bundler instance that created the build
|
|
212
|
+
* @param uiInstructions - UI instructions for displaying build information
|
|
54
213
|
*/
|
|
55
|
-
buildFinished:
|
|
214
|
+
buildFinished: DefineHook<(server: Bundler, uiInstructions: Instructions) => AsyncOrSync<void>>[];
|
|
56
215
|
};
|
|
57
216
|
/**
|
|
58
|
-
* Hooks executed when running the
|
|
217
|
+
* Hooks executed when running the test suite.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* const testRunnerHooks: TestRunnerHooks = {
|
|
221
|
+
* testsStarting: [
|
|
222
|
+
* () => import('./hooks/before_tests')
|
|
223
|
+
* ],
|
|
224
|
+
* testsFinished: [
|
|
225
|
+
* () => import('./hooks/after_tests')
|
|
226
|
+
* ]
|
|
227
|
+
* }
|
|
59
228
|
*/
|
|
60
229
|
export type TestRunnerHooks = {
|
|
61
230
|
/**
|
|
62
|
-
* The hook is executed before we begin executing the tests
|
|
231
|
+
* The hook is executed before we begin executing the tests.
|
|
232
|
+
* Use this hook to set up test databases or perform pre-test setup.
|
|
233
|
+
*
|
|
234
|
+
* @param server - The TestRunner instance that will execute the tests
|
|
63
235
|
*/
|
|
64
|
-
testsStarting:
|
|
236
|
+
testsStarting: DefineHook<(server: TestRunner) => AsyncOrSync<void>>[];
|
|
65
237
|
/**
|
|
66
|
-
* The hook is executed after the tests have been executed
|
|
238
|
+
* The hook is executed after the tests have been executed.
|
|
239
|
+
* Use this hook to clean up resources or generate test reports.
|
|
240
|
+
*
|
|
241
|
+
* @param server - The TestRunner instance that executed the tests
|
|
67
242
|
*/
|
|
68
|
-
testsFinished:
|
|
243
|
+
testsFinished: DefineHook<(server: TestRunner) => AsyncOrSync<void>>[];
|
|
69
244
|
};
|
|
245
|
+
/**
|
|
246
|
+
* Combined type representing all available hooks across the assembler ecosystem.
|
|
247
|
+
* This intersection type merges all hook categories into a single type for
|
|
248
|
+
* comprehensive hook management and type safety.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```js
|
|
252
|
+
* const allHooks: AllHooks = {
|
|
253
|
+
* init: [() => import('./hooks/init')],
|
|
254
|
+
* fileChanged: [() => import('./hooks/file_changed')],
|
|
255
|
+
* devServerStarted: [() => import('./hooks/dev_server_started')],
|
|
256
|
+
* buildFinished: [() => import('./hooks/build_finished')],
|
|
257
|
+
* testsFinished: [() => import('./hooks/tests_finished')],
|
|
258
|
+
* routesCommitted: [() => import('./hooks/routes_committed')]
|
|
259
|
+
* }
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
export type AllHooks = CommonHooks & WatcherHooks & DevServerHooks & BundlerHooks & TestRunnerHooks & RouterHooks;
|
|
263
|
+
/**
|
|
264
|
+
* Utility type that extracts the parameter types for a specific hook.
|
|
265
|
+
* This type helps maintain type safety when working with hook callbacks
|
|
266
|
+
* by providing the exact parameter signature for any given hook name.
|
|
267
|
+
*
|
|
268
|
+
* @template Hook - The name of the hook to extract parameters for
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```js
|
|
272
|
+
* // Get parameters for the fileChanged hook
|
|
273
|
+
* type FileChangedParams = HookParams<'fileChanged'>
|
|
274
|
+
* // Result: [string, string, {...}, DevServer | TestRunner]
|
|
275
|
+
*
|
|
276
|
+
* // Get parameters for the devServerStarted hook
|
|
277
|
+
* type DevServerStartedParams = HookParams<'devServerStarted')
|
|
278
|
+
* // Result: [DevServer, {port: number, host: string}, Instructions]
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
export type HookParams<Hook extends keyof AllHooks> = AllHooks[Hook][number] extends DefineHook<infer A> ? Parameters<A> : never;
|
|
282
|
+
export {};
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
|
|
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';
|
package/build/src/utils.d.ts
CHANGED
|
@@ -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
|
|
4
|
+
import { type TsConfigResult } from 'get-tsconfig';
|
|
5
5
|
import type { RunScriptOptions } from './types/common.ts';
|
|
6
|
-
import { type
|
|
6
|
+
import { type AllHooks, type HookParams } from './types/hooks.ts';
|
|
7
7
|
/**
|
|
8
|
-
* Parses tsconfig.json and prints errors using typescript compiler
|
|
9
|
-
*
|
|
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,51 +62,110 @@ 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
|
|
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
|
|
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
|
-
*
|
|
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;
|
|
131
|
+
/**
|
|
132
|
+
* Returns a boolean telling if the path value is a relative
|
|
133
|
+
* path starting with "./" or "../"
|
|
134
|
+
*
|
|
135
|
+
* @param pathValue - The path string to check
|
|
136
|
+
* @returns True if the path is relative, false otherwise
|
|
137
|
+
*/
|
|
138
|
+
export declare function isRelative(pathValue: string): boolean;
|
|
75
139
|
/**
|
|
76
140
|
* Imports a selected set of lazy hooks and creates an instance of the
|
|
77
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
|
|
78
150
|
*/
|
|
79
|
-
|
|
80
|
-
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<{ [P in K]: [HookParams<P>, HookParams<P>]; }>>;
|
|
81
152
|
/**
|
|
82
153
|
* Wraps a function inside another function that throttles the concurrent
|
|
83
154
|
* executions of a function. If the function is called too quickly, then
|
|
84
155
|
* it may result in two invocations at max.
|
|
156
|
+
*
|
|
157
|
+
* This utility prevents overwhelming the system with rapid successive calls
|
|
158
|
+
* by ensuring only one execution happens at a time, with at most one queued call.
|
|
159
|
+
*
|
|
160
|
+
* @param fn - Function to throttle
|
|
161
|
+
* @param name - Optional name for debugging purposes
|
|
162
|
+
* @returns Throttled version of the function
|
|
85
163
|
*/
|
|
86
164
|
export declare function throttle<Args extends any[]>(fn: (...args: Args) => PromiseLike<any>, name?: string): (...args: Args) => Promise<void>;
|
|
87
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Removes the file extension from a file path
|
|
167
|
+
*
|
|
168
|
+
* @param filePath - The file path with extension
|
|
169
|
+
* @returns The file path without extension
|
|
170
|
+
*/
|
|
171
|
+
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
|
+
}
|