fix(plugins): Migrate filesystem usage to Node fs/fsPromises and upgrade smartfile to v13; add listFileTree helper and update tests
This commit is contained in:
@@ -1,7 +1,33 @@
|
||||
import * as path from 'path';
|
||||
import * as path from 'node:path';
|
||||
import * as fs from 'node:fs';
|
||||
import * as fsPromises from 'node:fs/promises';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
import * as smartstream from '@push.rocks/smartstream';
|
||||
|
||||
export { path, smartpath, smartfile, smartrequest, smartstream };
|
||||
export { path, fs, fsPromises, smartpath, smartfile, smartrequest, smartstream };
|
||||
|
||||
/**
|
||||
* List files in a directory recursively, returning relative paths
|
||||
*/
|
||||
export async function listFileTree(dirPath: string, _pattern: string = '**/*'): Promise<string[]> {
|
||||
const results: string[] = [];
|
||||
|
||||
async function walkDir(currentPath: string, relativePath: string = '') {
|
||||
const entries = await fsPromises.readdir(currentPath, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
const entryRelPath = relativePath ? path.join(relativePath, entry.name) : entry.name;
|
||||
const entryFullPath = path.join(currentPath, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
await walkDir(entryFullPath, entryRelPath);
|
||||
} else if (entry.isFile()) {
|
||||
results.push(entryRelPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await walkDir(dirPath);
|
||||
return results;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user