Skip to content

Commit

Permalink
add more types
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed May 18, 2024
1 parent 92d9ee3 commit 06dbe93
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ function makeMatchers({include, exclude, insensitive}: RRDirOpts) {
// with relative paths that start with ./ or .\
// https://github.com/micromatch/picomatch/issues/121
return {
includeMatcher: include?.length ? path => picomatch(include, opts)(resolve(path)) : null,
excludeMatcher: exclude?.length ? path => picomatch(exclude, opts)(resolve(path)) : null,
includeMatcher: include?.length ? (path: string) => picomatch(include, opts)(resolve(path)) : null,
excludeMatcher: exclude?.length ? (path: string) => picomatch(exclude, opts)(resolve(path)) : null,
};
}

Expand All @@ -94,7 +94,7 @@ export async function* rrdir(dir: Dir, opts: RRDirOpts = {}, {includeMatcher, ex
encoding = getEncoding(dir);
}

let dirents = [];
let dirents: Dirent[] = [];
try {
// @ts-ignore -- bug in @types/node
dirents = await readdir(dir as DirNodeCompatible, {encoding, withFileTypes: true});
Expand All @@ -108,10 +108,10 @@ export async function* rrdir(dir: Dir, opts: RRDirOpts = {}, {includeMatcher, ex
const path = makePath(dirent, dir, encoding);
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) continue;

const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
const encodedPath = encoding === "buffer" ? toString(path) : path;
const isIncluded = !includeMatcher || includeMatcher(encodedPath);
let stats;
const isSymbolicLink: boolean = opts.followSymlinks && dirent.isSymbolicLink();
const encodedPath: string = encoding === "buffer" ? toString(path) : path;
const isIncluded: boolean = !includeMatcher || includeMatcher(encodedPath);
let stats: Stats;

if (isIncluded) {
if (opts.stats || isSymbolicLink) {
Expand Down Expand Up @@ -146,8 +146,8 @@ export async function rrdirAsync(dir: Dir, opts: RRDirOpts = {}, {includeMatcher
encoding = getEncoding(dir);
}

const results = [];
let dirents = [];
const results: Entry[] = [];
let dirents: Dirent[] = [];
try {
// @ts-ignore -- bug in @types/node
dirents = await readdir(dir, {encoding, withFileTypes: true});
Expand All @@ -161,10 +161,10 @@ export async function rrdirAsync(dir: Dir, opts: RRDirOpts = {}, {includeMatcher
const path = makePath(dirent, dir, encoding);
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) return;

const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
const encodedPath = encoding === "buffer" ? toString(path) : path;
const isIncluded = !includeMatcher || includeMatcher(encodedPath);
let stats;
const isSymbolicLink: boolean = opts.followSymlinks && dirent.isSymbolicLink();
const encodedPath: string = encoding === "buffer" ? toString(path) : path;
const isIncluded: boolean = !includeMatcher || includeMatcher(encodedPath);
let stats: Stats;

if (isIncluded) {
if (opts.stats || isSymbolicLink) {
Expand Down Expand Up @@ -201,8 +201,8 @@ export function rrdirSync(dir: Dir, opts: RRDirOpts = {}, {includeMatcher, exclu
encoding = getEncoding(dir);
}

const results = [];
let dirents = [];
const results: Entry[] = [];
let dirents: Dirent[] = [];
try {
// @ts-ignore -- bug in @types/node
dirents = readdirSync(dir as DirNodeCompatible, {encoding, withFileTypes: true});
Expand All @@ -216,10 +216,10 @@ export function rrdirSync(dir: Dir, opts: RRDirOpts = {}, {includeMatcher, exclu
const path = makePath(dirent, dir, encoding);
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) continue;

const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink();
const encodedPath = encoding === "buffer" ? toString(path) : path;
const isIncluded = !includeMatcher || includeMatcher(encodedPath);
let stats;
const isSymbolicLink: boolean = opts.followSymlinks && dirent.isSymbolicLink();
const encodedPath: string = encoding === "buffer" ? toString(path) : path;
const isIncluded: boolean = !includeMatcher || includeMatcher(encodedPath);
let stats: Stats;

if (isIncluded) {
if (opts.stats || isSymbolicLink) {
Expand Down

0 comments on commit 06dbe93

Please sign in to comment.