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,8 +1,34 @@
|
||||
// node native scope
|
||||
import * as path from 'path';
|
||||
import * as stream from 'stream';
|
||||
import * as path from 'node:path';
|
||||
import * as stream from 'node:stream';
|
||||
import * as fs from 'node:fs';
|
||||
import * as fsPromises from 'node:fs/promises';
|
||||
|
||||
export { path, stream };
|
||||
export { path, stream, fs, fsPromises };
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
|
||||
Reference in New Issue
Block a user