* Find the first .deepnote file in a directory (sorted alphabetically).
( dirPath: string, options: ResolveDeepnoteFileOptions )
| 125 | * Find the first .deepnote file in a directory (sorted alphabetically). |
| 126 | */ |
| 127 | async function findDeepnoteFileInDirectory( |
| 128 | dirPath: string, |
| 129 | options: ResolveDeepnoteFileOptions |
| 130 | ): Promise<ResolvedFile> { |
| 131 | const entries = await readdir(dirPath, { withFileTypes: true }).catch((err: unknown) => { |
| 132 | const code = (err as NodeJS.ErrnoException | undefined)?.code |
| 133 | if (code === 'ENOENT') { |
| 134 | throw new FileResolutionError(`Directory not found: ${dirPath}`) |
| 135 | } |
| 136 | throw err |
| 137 | }) |
| 138 | |
| 139 | // Filter for actual files (not directories) with .deepnote extension |
| 140 | const deepnoteFiles = entries |
| 141 | .filter(entry => entry.isFile() && entry.name.toLowerCase().endsWith('.deepnote')) |
| 142 | .map(entry => entry.name) |
| 143 | .sort() |
| 144 | |
| 145 | if (deepnoteFiles.length === 0) { |
| 146 | const defaultMessage = `No .deepnote files found in: ${dirPath}\n\nCreate a .deepnote file or specify a path to one.` |
| 147 | throw new FileResolutionError(options.noFilesFoundMessage ?? defaultMessage) |
| 148 | } |
| 149 | |
| 150 | const selectedFile = deepnoteFiles[0] |
| 151 | const absolutePath = resolve(dirPath, selectedFile) |
| 152 | |
| 153 | debug(`Auto-selected .deepnote file: ${absolutePath}`) |
| 154 | |
| 155 | if (deepnoteFiles.length > 1) { |
| 156 | debug(`Note: ${deepnoteFiles.length} .deepnote files found, using first alphabetically: ${selectedFile}`) |
| 157 | } |
| 158 | |
| 159 | return { absolutePath } |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Suggest similar files if the specified file doesn't exist. |
no test coverage detected