@adonisjs/assembler 8.0.0-next.4 → 8.0.0-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +87 -59
  2. package/build/chunk-F4RAGKQN.js +387 -0
  3. package/build/chunk-MC3FJR62.js +411 -0
  4. package/build/chunk-TIKQQRMX.js +116 -0
  5. package/build/index.d.ts +1 -0
  6. package/build/index.js +606 -410
  7. package/build/src/bundler.d.ts +40 -3
  8. package/build/src/code_scanners/routes_scanner/main.d.ts +49 -9
  9. package/build/src/code_scanners/routes_scanner/main.js +445 -0
  10. package/build/src/code_scanners/routes_scanner/validator_extractor.d.ts +12 -4
  11. package/build/src/code_transformer/main.d.ts +44 -43
  12. package/build/src/code_transformer/main.js +123 -101
  13. package/build/src/code_transformer/rc_file_transformer.d.ts +56 -4
  14. package/build/src/debug.d.ts +12 -0
  15. package/build/src/dev_server.d.ts +40 -30
  16. package/build/src/file_buffer.d.ts +67 -0
  17. package/build/src/file_system.d.ts +45 -7
  18. package/build/src/helpers.d.ts +79 -4
  19. package/build/src/helpers.js +16 -0
  20. package/build/src/index_generator/main.d.ts +73 -0
  21. package/build/src/index_generator/main.js +7 -0
  22. package/build/src/index_generator/source.d.ts +66 -0
  23. package/build/src/paths_resolver.d.ts +27 -2
  24. package/build/src/shortcuts_manager.d.ts +42 -4
  25. package/build/src/test_runner.d.ts +58 -31
  26. package/build/src/types/code_scanners.d.ts +138 -24
  27. package/build/src/types/code_transformer.d.ts +61 -19
  28. package/build/src/types/common.d.ts +199 -55
  29. package/build/src/types/hooks.d.ts +173 -17
  30. package/build/src/types/main.d.ts +13 -0
  31. package/build/src/utils.d.ts +88 -10
  32. package/build/src/virtual_file_system.d.ts +112 -0
  33. package/package.json +9 -3
  34. package/build/chunk-RR4HCA4M.js +0 -7
  35. package/build/src/ast_file_system.d.ts +0 -17
@@ -3,14 +3,29 @@ import type tsStatic from 'typescript';
3
3
  import { type ChokidarOptions } from 'chokidar';
4
4
  import { type UnWrapLazyImport } from '@poppinss/utils/types';
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 CommonHooks, type RouterHooks, type WatcherHooks, type BundlerHooks, type DevServerHooks, type TestRunnerHooks } 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
+ * @param cwd - The current working directory URL or string path
15
+ * @param ts - TypeScript module reference
16
+ * @returns Parsed TypeScript configuration or undefined if parsing failed
10
17
  */
11
18
  export declare function parseConfig(cwd: URL | string, ts: typeof tsStatic): tsStatic.ParsedCommandLine | undefined;
12
19
  /**
13
20
  * Runs a Node.js script as a child process and inherits the stdio streams
21
+ *
22
+ * This function spawns a Node.js child process with TypeScript support enabled
23
+ * by default through ts-exec. It's primarily used for running development
24
+ * servers and test scripts.
25
+ *
26
+ * @param cwd - The current working directory URL or string path
27
+ * @param options - Script execution options including args, environment, etc.
28
+ * @returns Child process instance from execa
14
29
  */
15
30
  export declare function runNode(cwd: string | URL, options: RunScriptOptions): import("execa").ResultPromise<{
16
31
  nodeOptions: string[];
@@ -28,6 +43,13 @@ export declare function runNode(cwd: string | URL, options: RunScriptOptions): i
28
43
  }>;
29
44
  /**
30
45
  * Runs a script as a child process and inherits the stdio streams
46
+ *
47
+ * This function spawns a generic child process for running any executable
48
+ * script. Unlike runNode, this doesn't include TypeScript-specific Node.js arguments.
49
+ *
50
+ * @param cwd - The current working directory URL or string path
51
+ * @param options - Script execution options (excluding nodeArgs)
52
+ * @returns Child process instance from execa
31
53
  */
32
54
  export declare function run(cwd: string | URL, options: Omit<RunScriptOptions, 'nodeArgs'>): import("execa").ResultPromise<{
33
55
  preferLocal: true;
@@ -42,51 +64,107 @@ export declare function run(cwd: string | URL, options: Omit<RunScriptOptions, '
42
64
  };
43
65
  }>;
44
66
  /**
45
- * Watches the file system using tsconfig file
67
+ * Watches the file system using chokidar with the provided options
68
+ *
69
+ * Creates a file system watcher that monitors the current directory
70
+ * for changes, supporting various chokidar options for customization.
71
+ *
72
+ * @param options - Chokidar watch options
73
+ * @returns Chokidar FSWatcher instance
46
74
  */
47
75
  export declare function watch(options: ChokidarOptions): import("chokidar").FSWatcher;
48
76
  /**
49
77
  * Check if file is a .env file
78
+ *
79
+ * Determines if a given file path represents an environment file,
80
+ * including .env and .env.* variants.
81
+ *
82
+ * @param filePath - The file path to check
83
+ * @returns True if the file is an environment file
50
84
  */
51
85
  export declare function isDotEnvFile(filePath: string): boolean;
52
86
  /**
53
- * Returns the port to use after inspect the dot-env files inside
87
+ * Returns the port to use after inspecting the dot-env files inside
54
88
  * a given directory.
55
89
  *
56
90
  * A random port is used when the specified port is in use. Following
57
- * is the logic for finding a specified port.
91
+ * is the logic for finding a specified port:
58
92
  *
59
93
  * - The "process.env.PORT" value is used if exists.
60
94
  * - The dot-env files are loaded using the "EnvLoader" and the PORT
61
95
  * value is used by iterating over all the loaded files. The
62
96
  * iteration stops after first find.
97
+ * - Falls back to port 3333 if no PORT is found in environment files.
98
+ *
99
+ * @param cwd - The current working directory URL
100
+ * @returns Promise resolving to an available port number
63
101
  */
64
102
  export declare function getPort(cwd: URL): Promise<number>;
65
103
  /**
66
- * Helper function to copy files from relative paths or glob
67
- * patterns
104
+ * Helper function to copy files from relative paths or glob patterns
105
+ *
106
+ * This function handles copying files and directories while preserving
107
+ * directory structure. It supports both direct file paths and glob patterns,
108
+ * and automatically filters out junk files.
109
+ *
110
+ * @param files - Array of file paths or glob patterns to copy
111
+ * @param cwd - Source directory path
112
+ * @param outDir - Destination directory path
113
+ * @returns Promise resolving when all files are copied
68
114
  */
69
115
  export declare function copyFiles(files: string[], cwd: string, outDir: string): Promise<void[]>;
70
116
  /**
71
117
  * Memoize a function using an LRU cache. The function must accept
72
118
  * only one argument as a string value.
119
+ *
120
+ * This utility provides caching for expensive function calls to improve
121
+ * performance by storing results in memory.
122
+ *
123
+ * @param fn - Function to memoize (only first argument is considered for memoization)
124
+ * @param maxKeys - Optional maximum number of cached keys
125
+ * @returns Memoized version of the function
73
126
  */
74
- export declare function memoize<Result>(fn: (input: string) => any, maxKeys?: number): (input: string) => Result;
127
+ export declare function memoize<T extends any[], Result>(fn: (input: string, ...args: T) => any, maxKeys?: number): (input: string, ...args: T) => Result;
75
128
  /**
76
129
  * Returns a boolean telling if the path value is a relative
77
130
  * path starting with "./" or "../"
131
+ *
132
+ * @param pathValue - The path string to check
133
+ * @returns True if the path is relative, false otherwise
78
134
  */
79
135
  export declare function isRelative(pathValue: string): boolean;
80
136
  /**
81
137
  * Imports a selected set of lazy hooks and creates an instance of the
82
138
  * Hooks class
139
+ *
140
+ * This function dynamically imports and initializes hooks based on the
141
+ * provided configuration, supporting different types of hooks for various
142
+ * assembler operations.
143
+ *
144
+ * @param rcFileHooks - Hook configuration from the RC file
145
+ * @param names - Array of hook names to load
146
+ * @returns Promise resolving to configured Hooks instance
83
147
  */
84
- type AllHooks = WatcherHooks & DevServerHooks & BundlerHooks & TestRunnerHooks;
148
+ type AllHooks = CommonHooks & RouterHooks & WatcherHooks & DevServerHooks & BundlerHooks & TestRunnerHooks;
85
149
  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]>>]; }>>;
86
150
  /**
87
151
  * Wraps a function inside another function that throttles the concurrent
88
152
  * executions of a function. If the function is called too quickly, then
89
153
  * it may result in two invocations at max.
154
+ *
155
+ * This utility prevents overwhelming the system with rapid successive calls
156
+ * by ensuring only one execution happens at a time, with at most one queued call.
157
+ *
158
+ * @param fn - Function to throttle
159
+ * @param name - Optional name for debugging purposes
160
+ * @returns Throttled version of the function
90
161
  */
91
162
  export declare function throttle<Args extends any[]>(fn: (...args: Args) => PromiseLike<any>, name?: string): (...args: Args) => Promise<void>;
163
+ /**
164
+ * Removes the file extension from a file path
165
+ *
166
+ * @param filePath - The file path with extension
167
+ * @returns The file path without extension
168
+ */
169
+ export declare function removeExtension(filePath: string): string;
92
170
  export {};
@@ -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) => 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
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/assembler",
3
3
  "description": "Provides utilities to run AdonisJS development server and build project for production",
4
- "version": "8.0.0-next.4",
4
+ "version": "8.0.0-next.6",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -19,6 +19,8 @@
19
19
  ".": "./build/index.js",
20
20
  "./code_transformer": "./build/src/code_transformer/main.js",
21
21
  "./routes_scanner": "./build/src/code_scanners/routes_scanner/main.js",
22
+ "./index_generator": "./build/src/index_generator/main.js",
23
+ "./helpers": "./build/src/helpers.js",
22
24
  "./types": "./build/src/types/main.js"
23
25
  },
24
26
  "scripts": {
@@ -61,7 +63,7 @@
61
63
  "typescript": "^5.9.2"
62
64
  },
63
65
  "dependencies": {
64
- "@adonisjs/env": "^6.2.0",
66
+ "@adonisjs/env": "^7.0.0-next.1",
65
67
  "@antfu/install-pkg": "^1.1.0",
66
68
  "@ast-grep/napi": "^0.39.4",
67
69
  "@poppinss/cliui": "^6.4.4",
@@ -71,10 +73,11 @@
71
73
  "dedent": "^1.6.0",
72
74
  "execa": "^9.6.0",
73
75
  "fast-glob": "^3.3.3",
76
+ "fdir": "^6.5.0",
74
77
  "get-port": "^7.1.0",
75
78
  "junk": "^4.0.1",
76
79
  "open": "^10.2.0",
77
- "parse-imports": "^2.2.1",
80
+ "parse-imports": "^3.0.0",
78
81
  "picomatch": "^4.0.3",
79
82
  "pretty-hrtime": "^1.0.3",
80
83
  "tmp-cache": "^1.1.0",
@@ -105,6 +108,9 @@
105
108
  "entry": [
106
109
  "./index.ts",
107
110
  "./src/types/main.ts",
111
+ "./src/helpers.ts",
112
+ "./src/code_scanners/routes_scanner/main.ts",
113
+ "./src/index_generator/main.ts",
108
114
  "./src/code_transformer/main.ts"
109
115
  ],
110
116
  "outDir": "./build",
@@ -1,7 +0,0 @@
1
- // src/debug.ts
2
- import { debuglog } from "util";
3
- var debug_default = debuglog("adonisjs:assembler");
4
-
5
- export {
6
- debug_default
7
- };
@@ -1,17 +0,0 @@
1
- import { type SgNode } from '@ast-grep/napi';
2
- /**
3
- * An abstraction around converting files to an AST and caching
4
- * them forever. The cache could be cleared manually.
5
- */
6
- export declare class AstFileSystem {
7
- #private;
8
- /**
9
- * Returns the file contents as AST-grep node and caches it
10
- * forever.
11
- */
12
- get(filePath: string): Promise<SgNode>;
13
- /**
14
- * Clear AST cache for a single file or all the files
15
- */
16
- clear(filePath?: string): void;
17
- }