Skip to content

Commit 495a2c4

Browse files
committed
fix: cleanup up utils
1 parent 70f4729 commit 495a2c4

File tree

1 file changed

+0
-136
lines changed

1 file changed

+0
-136
lines changed

src/utils.ts

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -75,142 +75,6 @@ export function createDirnameFromTask(suiteOrTest: RunnerTask | SuiteCollector):
7575
return dirName.replace(/-{2,}/g, "-").replace(/-+$/, "");
7676
}
7777

78-
/**
79-
* Checks if the provided path points to a directory.
80-
*
81-
* @param {string} path - The file system path to check
82-
* @returns {Promise<boolean>} A promise that resolves to true if the path is a directory, false otherwise
83-
* @throws Never - Catches and handles any filesystem errors by returning false
84-
*
85-
* @example
86-
* ```ts
87-
* const isDir = await isDirectory("/path/to/check");
88-
* if (isDir) {
89-
* console.log("Path is a directory");
90-
* }
91-
* ```
92-
*/
93-
export async function isDirectory(path: string): Promise<boolean> {
94-
try {
95-
const result = await stat(path);
96-
return result.isDirectory();
97-
} catch {
98-
return false;
99-
}
100-
}
101-
102-
/**
103-
* Synchronously checks if the given path is a directory.
104-
*
105-
* @param {string} path - The file system path to check
106-
* @returns {boolean} `true` if the path is a directory, `false` if it's not or if there was an error accessing the path
107-
*
108-
* @example
109-
* ```ts
110-
* // Check if a path is a directory
111-
* const isDir = isDirectorySync('./some/path');
112-
* if (isDir) {
113-
* // Handle directory case
114-
* }
115-
* ```
116-
*/
117-
export function isDirectorySync(path: string): boolean {
118-
try {
119-
const result = statSync(path);
120-
return result.isDirectory();
121-
} catch {
122-
return false;
123-
}
124-
}
125-
126-
/**
127-
* Processes a directory and its contents recursively, creating a JSON representation of the file system.
128-
*
129-
* @param {string} path - The absolute path to the directory to process
130-
* @param {Required<Omit<FromFileSystemOptions, "extras">>} options - Configuration options for processing the directory
131-
*
132-
* @returns {Promise<DirectoryJSON>} A Promise that resolves to a DirectoryJSON object representing the directory structure
133-
* where keys are file/directory names and values are either:
134-
* - A string containing file contents for regular files
135-
* - A DirectoryJSON object for subdirectories
136-
* - A symbolic link representation for symlinks (when followLinks is true)
137-
*
138-
* @throws {Error} If there are issues reading the directory or its contents
139-
*/
140-
export async function processDirectory(
141-
path: string,
142-
options: Required<Omit<FromFileSystemOptions, "extras">>,
143-
): Promise<DirectoryJSON> {
144-
const files: DirectoryJSON = {
145-
[FIXTURE_ORIGINAL_PATH_SYMBOL]: normalize(path),
146-
};
147-
148-
const dirFiles = await readdir(path, {
149-
withFileTypes: true,
150-
});
151-
152-
const filteredFiles = dirFiles.filter((file) => !options.ignore.includes(file.name));
153-
154-
for (const file of filteredFiles) {
155-
const filePath = file.name;
156-
const fullPath = `${path}/${filePath}`;
157-
158-
if (file.isDirectory()) {
159-
files[filePath] = await processDirectory(fullPath, options);
160-
} else if (options.followLinks && file.isSymbolicLink()) {
161-
files[filePath] = symlink(await readlink(fullPath));
162-
} else {
163-
files[filePath] = await readFile(fullPath, options.getEncodingForFile(fullPath));
164-
}
165-
}
166-
167-
return files;
168-
}
169-
170-
/**
171-
* Recursively processes a directory and returns its structure as a JSON object.
172-
*
173-
* @param {string} path - The absolute path to the directory to process
174-
* @param {Required<Omit<FromFileSystemOptions, "extras">>} options - Configuration options for processing the directory
175-
*
176-
* @returns {DirectoryJSON} A DirectoryJSON object representing the directory structure where:
177-
* - Keys are file/directory names
178-
* - Values are either:
179-
* - String content for files
180-
* - Nested DirectoryJSON objects for directories
181-
* - Symlink objects for symbolic links (when followLinks is true)
182-
* - Special key [FIXTURE_ORIGINAL_PATH] contains the normalized original path
183-
*/
184-
export function processDirectorySync(
185-
path: string,
186-
options: Required<Omit<FromFileSystemOptions, "extras">>,
187-
): DirectoryJSON {
188-
const files: DirectoryJSON = {
189-
[FIXTURE_ORIGINAL_PATH_SYMBOL]: normalize(path),
190-
};
191-
192-
const dirFiles = readdirSync(path, {
193-
withFileTypes: true,
194-
});
195-
196-
const filteredFiles = dirFiles.filter((file) => !options.ignore.includes(file.name));
197-
198-
for (const file of filteredFiles) {
199-
const filePath = file.name;
200-
const fullPath = `${path}/${filePath}`;
201-
202-
if (file.isDirectory()) {
203-
files[filePath] = processDirectorySync(fullPath, options);
204-
} else if (options.followLinks && file.isSymbolicLink()) {
205-
files[filePath] = symlink(readlinkSync(fullPath));
206-
} else {
207-
files[filePath] = readFileSync(fullPath, options.getEncodingForFile(fullPath));
208-
}
209-
}
210-
211-
return files;
212-
}
213-
21478
/**
21579
* Generates a normalized directory path based on the provided dirname or the current test/suite context.
21680
* This function must be called within a Vitest context.

0 commit comments

Comments
 (0)