@adonisjs/assembler 8.0.0-next.5 → 8.0.0-next.7

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 (36) hide show
  1. package/README.md +87 -59
  2. package/build/chunk-25Q3N5JR.js +392 -0
  3. package/build/chunk-PORDZS62.js +391 -0
  4. package/build/chunk-TIKQQRMX.js +116 -0
  5. package/build/index.d.ts +2 -0
  6. package/build/index.js +825 -430
  7. package/build/src/bundler.d.ts +44 -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 +38 -9
  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/hooks.d.ts +224 -0
  21. package/build/src/index_generator/main.d.ts +64 -0
  22. package/build/src/index_generator/main.js +7 -0
  23. package/build/src/index_generator/source.d.ts +60 -0
  24. package/build/src/paths_resolver.d.ts +27 -2
  25. package/build/src/shortcuts_manager.d.ts +42 -4
  26. package/build/src/test_runner.d.ts +56 -10
  27. package/build/src/types/code_scanners.d.ts +138 -24
  28. package/build/src/types/code_transformer.d.ts +61 -19
  29. package/build/src/types/common.d.ts +199 -55
  30. package/build/src/types/hooks.d.ts +235 -22
  31. package/build/src/types/main.d.ts +13 -0
  32. package/build/src/utils.d.ts +88 -13
  33. package/build/src/virtual_file_system.d.ts +112 -0
  34. package/package.json +9 -3
  35. package/build/chunk-RR4HCA4M.js +0 -7
  36. package/build/src/ast_file_system.d.ts +0 -17
@@ -1,3 +1,16 @@
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
+ */
1
14
  export * from './hooks.ts';
2
15
  export * from './common.ts';
3
16
  export * from './code_scanners.ts';
@@ -1,16 +1,30 @@
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';
5
4
  import type { RunScriptOptions } from './types/common.ts';
6
- import { type WatcherHooks, type BundlerHooks, type DevServerHooks, type TestRunnerHooks } from './types/hooks.ts';
5
+ import { type AllHooks, type HookParams } from './types/hooks.ts';
7
6
  /**
8
- * Parses tsconfig.json and prints errors using typescript compiler
9
- * host
7
+ * Parses tsconfig.json and prints errors using typescript compiler host
8
+ *
9
+ * This function reads and parses the tsconfig.json file from the given directory,
10
+ * handling diagnostic errors and returning a parsed configuration that can be
11
+ * used by other TypeScript operations.
12
+ *
13
+ * @param cwd - The current working directory URL or string path
14
+ * @param ts - TypeScript module reference
15
+ * @returns Parsed TypeScript configuration or undefined if parsing failed
10
16
  */
11
17
  export declare function parseConfig(cwd: URL | string, ts: typeof tsStatic): tsStatic.ParsedCommandLine | undefined;
12
18
  /**
13
19
  * Runs a Node.js script as a child process and inherits the stdio streams
20
+ *
21
+ * This function spawns a Node.js child process with TypeScript support enabled
22
+ * by default through ts-exec. It's primarily used for running development
23
+ * servers and test scripts.
24
+ *
25
+ * @param cwd - The current working directory URL or string path
26
+ * @param options - Script execution options including args, environment, etc.
27
+ * @returns Child process instance from execa
14
28
  */
15
29
  export declare function runNode(cwd: string | URL, options: RunScriptOptions): import("execa").ResultPromise<{
16
30
  nodeOptions: string[];
@@ -28,6 +42,13 @@ export declare function runNode(cwd: string | URL, options: RunScriptOptions): i
28
42
  }>;
29
43
  /**
30
44
  * Runs a script as a child process and inherits the stdio streams
45
+ *
46
+ * This function spawns a generic child process for running any executable
47
+ * script. Unlike runNode, this doesn't include TypeScript-specific Node.js arguments.
48
+ *
49
+ * @param cwd - The current working directory URL or string path
50
+ * @param options - Script execution options (excluding nodeArgs)
51
+ * @returns Child process instance from execa
31
52
  */
32
53
  export declare function run(cwd: string | URL, options: Omit<RunScriptOptions, 'nodeArgs'>): import("execa").ResultPromise<{
33
54
  preferLocal: true;
@@ -42,51 +63,105 @@ export declare function run(cwd: string | URL, options: Omit<RunScriptOptions, '
42
63
  };
43
64
  }>;
44
65
  /**
45
- * Watches the file system using tsconfig file
66
+ * Watches the file system using chokidar with the provided options
67
+ *
68
+ * Creates a file system watcher that monitors the current directory
69
+ * for changes, supporting various chokidar options for customization.
70
+ *
71
+ * @param options - Chokidar watch options
72
+ * @returns Chokidar FSWatcher instance
46
73
  */
47
74
  export declare function watch(options: ChokidarOptions): import("chokidar").FSWatcher;
48
75
  /**
49
76
  * Check if file is a .env file
77
+ *
78
+ * Determines if a given file path represents an environment file,
79
+ * including .env and .env.* variants.
80
+ *
81
+ * @param filePath - The file path to check
82
+ * @returns True if the file is an environment file
50
83
  */
51
84
  export declare function isDotEnvFile(filePath: string): boolean;
52
85
  /**
53
- * Returns the port to use after inspect the dot-env files inside
86
+ * Returns the port to use after inspecting the dot-env files inside
54
87
  * a given directory.
55
88
  *
56
89
  * A random port is used when the specified port is in use. Following
57
- * is the logic for finding a specified port.
90
+ * is the logic for finding a specified port:
58
91
  *
59
92
  * - The "process.env.PORT" value is used if exists.
60
93
  * - The dot-env files are loaded using the "EnvLoader" and the PORT
61
94
  * value is used by iterating over all the loaded files. The
62
95
  * iteration stops after first find.
96
+ * - Falls back to port 3333 if no PORT is found in environment files.
97
+ *
98
+ * @param cwd - The current working directory URL
99
+ * @returns Promise resolving to an available port number
63
100
  */
64
101
  export declare function getPort(cwd: URL): Promise<number>;
65
102
  /**
66
- * Helper function to copy files from relative paths or glob
67
- * patterns
103
+ * Helper function to copy files from relative paths or glob patterns
104
+ *
105
+ * This function handles copying files and directories while preserving
106
+ * directory structure. It supports both direct file paths and glob patterns,
107
+ * and automatically filters out junk files.
108
+ *
109
+ * @param files - Array of file paths or glob patterns to copy
110
+ * @param cwd - Source directory path
111
+ * @param outDir - Destination directory path
112
+ * @returns Promise resolving when all files are copied
68
113
  */
69
114
  export declare function copyFiles(files: string[], cwd: string, outDir: string): Promise<void[]>;
70
115
  /**
71
116
  * Memoize a function using an LRU cache. The function must accept
72
117
  * only one argument as a string value.
118
+ *
119
+ * This utility provides caching for expensive function calls to improve
120
+ * performance by storing results in memory.
121
+ *
122
+ * @param fn - Function to memoize (only first argument is considered for memoization)
123
+ * @param maxKeys - Optional maximum number of cached keys
124
+ * @returns Memoized version of the function
73
125
  */
74
- export declare function memoize<Result>(fn: (input: string) => any, maxKeys?: number): (input: string) => Result;
126
+ export declare function memoize<T extends any[], Result>(fn: (input: string, ...args: T) => any, maxKeys?: number): (input: string, ...args: T) => Result;
75
127
  /**
76
128
  * Returns a boolean telling if the path value is a relative
77
129
  * path starting with "./" or "../"
130
+ *
131
+ * @param pathValue - The path string to check
132
+ * @returns True if the path is relative, false otherwise
78
133
  */
79
134
  export declare function isRelative(pathValue: string): boolean;
80
135
  /**
81
136
  * Imports a selected set of lazy hooks and creates an instance of the
82
137
  * Hooks class
138
+ *
139
+ * This function dynamically imports and initializes hooks based on the
140
+ * provided configuration, supporting different types of hooks for various
141
+ * assembler operations.
142
+ *
143
+ * @param rcFileHooks - Hook configuration from the RC file
144
+ * @param names - Array of hook names to load
145
+ * @returns Promise resolving to configured Hooks instance
83
146
  */
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]>>]; }>>;
147
+ export declare function loadHooks<K extends keyof AllHooks>(rcFileHooks: Partial<AllHooks> | undefined, names: K[]): Promise<Hooks<{ [P in K]: [HookParams<P>, HookParams<P>]; }>>;
86
148
  /**
87
149
  * Wraps a function inside another function that throttles the concurrent
88
150
  * executions of a function. If the function is called too quickly, then
89
151
  * it may result in two invocations at max.
152
+ *
153
+ * This utility prevents overwhelming the system with rapid successive calls
154
+ * by ensuring only one execution happens at a time, with at most one queued call.
155
+ *
156
+ * @param fn - Function to throttle
157
+ * @param name - Optional name for debugging purposes
158
+ * @returns Throttled version of the function
90
159
  */
91
160
  export declare function throttle<Args extends any[]>(fn: (...args: Args) => PromiseLike<any>, name?: string): (...args: Args) => Promise<void>;
92
- export {};
161
+ /**
162
+ * Removes the file extension from a file path
163
+ *
164
+ * @param filePath - The file path with extension
165
+ * @returns The file path without extension
166
+ */
167
+ 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) => 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.5",
4
+ "version": "8.0.0-next.7",
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
- }