Chore: drop path-scurry & replace w/ fs.opendir

This commit is contained in:
SukkaW
2024-08-14 04:45:53 +08:00
parent 991b192fa7
commit f5a58349cb
3 changed files with 12 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
import type { Path } from 'path-scurry';
import { PathScurry } from 'path-scurry';
import fsp from 'fs/promises';
import { sep } from 'path';
interface TreeFileType {
type: 'file',
@@ -20,29 +20,29 @@ export type TreeTypeArray = TreeType[];
type VoidOrVoidArray = void | VoidOrVoidArray[];
export const treeDir = async (path: string): Promise<TreeTypeArray> => {
const pw = new PathScurry(path);
const tree: TreeTypeArray = [];
const walk = async (entry: Path, node: TreeTypeArray): Promise<VoidOrVoidArray> => {
const walk = async (dir: string, node: TreeTypeArray): Promise<VoidOrVoidArray> => {
const promises: Array<Promise<VoidOrVoidArray>> = [];
for (const child of await pw.readdir(entry)) {
for await (const child of await fsp.opendir(dir)) {
const childFullPath = child.parentPath + sep + child.name;
if (child.isDirectory()) {
const newNode: TreeDirectoryType = {
type: 'directory',
name: child.name,
path: child.relative(),
path: childFullPath,
children: []
};
node.push(newNode);
promises.push(walk(child, newNode.children));
promises.push(walk(childFullPath, newNode.children));
continue;
}
if (child.isFile()) {
const newNode: TreeFileType = {
type: 'file',
name: child.name,
path: child.relative()
path: childFullPath
};
node.push(newNode);
continue;
@@ -51,7 +51,7 @@ export const treeDir = async (path: string): Promise<TreeTypeArray> => {
return Promise.all(promises);
};
await walk(pw.cwd, tree);
await walk(path, tree);
return tree;
};

View File

@@ -32,7 +32,6 @@
"foxact": "^0.2.36",
"json-stringify-pretty-compact": "^3.0.0",
"mnemonist": "^0.39.8",
"path-scurry": "^1.11.1",
"picocolors": "^1.0.1",
"punycode": "^2.3.1",
"table": "^6.8.2",

42
pnpm-lock.yaml generated
View File

@@ -47,9 +47,6 @@ importers:
mnemonist:
specifier: ^0.39.8
version: 0.39.8
path-scurry:
specifier: ^1.11.1
version: 1.11.1
picocolors:
specifier: ^1.0.1
version: 1.0.1
@@ -178,10 +175,6 @@ packages:
resolution: {integrity: sha512-4Bfj15dVJdoy3RfZmmo86RK1Fwzn6SstsvK9JS+BaVKqC6QQQQyXekNaC+g+LKNgkQ+2VhGAzm6hO40AhMR3zQ==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
'@eslint/js@9.8.0':
resolution: {integrity: sha512-MfluB7EUfxXtv3i/++oh89uzAr4PDI4nn201hsp+qaXqsjAWzinlZEHEfPgAX4doIlKvPG/i0A9dpKxOLII8yA==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
'@eslint/js@9.9.0':
resolution: {integrity: sha512-hhetes6ZHP3BlXLxmd8K2SNgkhNSi+UcecbnwWKwpP7kyi/uC75DJ1lOOBO3xrC4jyojtGE3YxKZPHfk4yrgug==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
@@ -749,10 +742,6 @@ packages:
end-of-stream@1.4.4:
resolution: {integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==}
enhanced-resolve@5.17.0:
resolution: {integrity: sha512-dwDPwZL0dmye8Txp2gzFmA6sxALaSvdRDjPH0viLcKrtlOL3tw62nWWweVD1SdILDTJrbrL6tdWVN58Wo6U3eA==}
engines: {node: '>=10.13.0'}
enhanced-resolve@5.17.1:
resolution: {integrity: sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==}
engines: {node: '>=10.13.0'}
@@ -1147,9 +1136,6 @@ packages:
loupe@2.3.7:
resolution: {integrity: sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==}
lru-cache@10.4.3:
resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==}
merge2@1.4.1:
resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
engines: {node: '>= 8'}
@@ -1176,10 +1162,6 @@ packages:
minimist@1.2.8:
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
minipass@7.1.2:
resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==}
engines: {node: '>=16 || 14 >=14.17'}
mitata@0.1.11:
resolution: {integrity: sha512-cs6FiWcnRxn7atVumm8wA8R70XCDmMXgVgb/qWUSjr5dwuIBr7zC+22mbGYPlbyFixlIOjuP//A0e72Q1ZoGDw==}
@@ -1250,10 +1232,6 @@ packages:
path-parse@1.0.7:
resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==}
path-scurry@1.11.1:
resolution: {integrity: sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==}
engines: {node: '>=16 || 14 >=14.18'}
path-type@4.0.0:
resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==}
engines: {node: '>=8'}
@@ -1659,8 +1637,6 @@ snapshots:
transitivePeerDependencies:
- supports-color
'@eslint/js@9.8.0': {}
'@eslint/js@9.9.0': {}
'@eslint/object-schema@2.1.4': {}
@@ -2229,11 +2205,6 @@ snapshots:
dependencies:
once: 1.4.0
enhanced-resolve@5.17.0:
dependencies:
graceful-fs: 4.2.11
tapable: 2.2.1
enhanced-resolve@5.17.1:
dependencies:
graceful-fs: 4.2.11
@@ -2253,7 +2224,7 @@ snapshots:
'@eslint-community/eslint-plugin-eslint-comments': 4.3.0(eslint@9.9.0)
'@eslint-sukka/shared': 6.1.10(eslint@9.9.0)(typescript@5.5.4)
'@eslint/compat': 1.1.1
'@eslint/js': 9.8.0
'@eslint/js': 9.9.0
'@stylistic/eslint-plugin-js': 2.4.0(eslint@9.9.0)
'@stylistic/eslint-plugin-plus': 2.4.0(eslint@9.9.0)(typescript@5.5.4)
'@stylistic/eslint-plugin-ts': 2.4.0(eslint@9.9.0)(typescript@5.5.4)
@@ -2352,7 +2323,7 @@ snapshots:
eslint-plugin-n@17.10.1(eslint@9.9.0):
dependencies:
'@eslint-community/eslint-utils': 4.4.0(eslint@9.9.0)
enhanced-resolve: 5.17.0
enhanced-resolve: 5.17.1
eslint: 9.9.0
eslint-plugin-es-x: 7.8.0(eslint@9.9.0)
get-tsconfig: 4.7.6
@@ -2678,8 +2649,6 @@ snapshots:
dependencies:
get-func-name: 2.0.2
lru-cache@10.4.3: {}
merge2@1.4.1: {}
micromatch@4.0.7:
@@ -2703,8 +2672,6 @@ snapshots:
minimist@1.2.8: {}
minipass@7.1.2: {}
mitata@0.1.11: {}
mkdirp-classic@0.5.3: {}
@@ -2797,11 +2764,6 @@ snapshots:
path-parse@1.0.7: {}
path-scurry@1.11.1:
dependencies:
lru-cache: 10.4.3
minipass: 7.1.2
path-type@4.0.0: {}
pathval@1.1.1: {}