Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
check-latest: true
- run: npm i
cache: npm
- run: npm ci
- run: npm run test:coverage
env:
CI: true
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Typecheck

on:
pull_request:
push:
branches: [master]

jobs:
typecheck:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js 24.x
uses: actions/setup-node@v4
with:
node-version: 24
check-latest: true
cache: npm
- run: npm ci
- run: npm run typecheck
env:
CI: true
4 changes: 2 additions & 2 deletions benchmarks/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fdir } from "../src/index";
import { fdir } from "../src/index.ts";
import { fdir as fdir5 } from "fdir5";
import { fdir as fdir4 } from "fdir4";
import fdir3 from "fdir3";
Expand All @@ -17,7 +17,7 @@ import { getAllFilesSync, getAllFiles } from "get-all-files";
import packageJson from "../package.json";
import { readFileSync, readdirSync, writeFileSync } from "fs";
import CSV2MD from "csv-to-markdown-table";
import { getSystemInfo } from "./export";
import { getSystemInfo } from "./export.ts";
import { readdir } from "fs/promises";

async function benchmark() {
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/fdir-benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import child_process from "child_process";
import { Fdir } from "../src/index";
import { Fdir } from "../src/index.ts";
import b from "benny";

type Version = (typeof versions)[number] | "current";
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/glob-benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fdir } from "../src/index";
import { fdir } from "../src/index.ts";
import { glob, globSync } from "glob";
import fg from "fast-glob";
import tg from "tiny-glob";
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"scripts": {
"prepublishOnly": "npm run test && npm run build",
"build": "tsdown",
"typecheck": "tsc",
"format": "prettier --write src __tests__ benchmarks",
"test": "vitest run __tests__/",
"test:coverage": "vitest run --coverage __tests__/",
Expand Down Expand Up @@ -77,7 +78,7 @@
"tiny-glob": "^0.2.9",
"ts-node": "^10.9.1",
"tsdown": "^0.12.5",
"typescript": "^5.3.2",
"typescript": "^5.8.3",
"vitest": "^0.34.6",
"walk-sync": "^3.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions src/api/async.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Output, Options, ResultCallback } from "../types";
import { Walker } from "./walker";
import type { Output, Options, ResultCallback } from "../types.ts";
import { Walker } from "./walker.ts";

export function promise<TOutput extends Output>(
root: string,
Expand Down
2 changes: 1 addition & 1 deletion src/api/functions/get-array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Options } from "../../types";
import type { Options } from "../../types.ts";

export type GetArrayFunction = (paths: string[]) => string[];

Expand Down
2 changes: 1 addition & 1 deletion src/api/functions/group-files.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Group, Options } from "../../types";
import type { Group, Options } from "../../types.ts";

export type GroupFilesFunction = (
groups: Group[],
Expand Down
4 changes: 2 additions & 2 deletions src/api/functions/invoke-callback.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
import type {
Output,
PathsOutput,
OnlyCountsOutput,
GroupOutput,
ResultCallback,
WalkerState,
Options,
} from "../../types";
} from "../../types.ts";

export type InvokeCallbackFunction<TOutput extends Output> = (
state: WalkerState,
Expand Down
4 changes: 2 additions & 2 deletions src/api/functions/join-path.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { relative } from "path";
import { Options, PathSeparator } from "../../types";
import { convertSlashes } from "../../utils";
import type { Options, PathSeparator } from "../../types.ts";
import { convertSlashes } from "../../utils.ts";

export function joinPathWithBasePath(filename: string, directoryPath: string) {
return directoryPath + filename;
Expand Down
2 changes: 1 addition & 1 deletion src/api/functions/push-directory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FilterPredicate, Options } from "../../types";
import type { FilterPredicate, Options } from "../../types.ts";

export type PushDirectoryFunction = (
directoryPath: string,
Expand Down
2 changes: 1 addition & 1 deletion src/api/functions/push-file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FilterPredicate, Options, Counts } from "../../types";
import type { FilterPredicate, Options, Counts } from "../../types.ts";

export type PushFileFunction = (
directoryPath: string,
Expand Down
2 changes: 1 addition & 1 deletion src/api/functions/resolve-symlink.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Stats } from "fs";
import { WalkerState, Options } from "../../types";
import { dirname } from "path";
import type { WalkerState, Options } from "../../types.ts";

export type ResolveSymlinkFunction = (
path: string,
Expand Down
2 changes: 1 addition & 1 deletion src/api/functions/walk-directory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WalkerState } from "../../types";
import type { Dirent } from "fs";
import type { WalkerState } from "../../types.ts";

export type WalkDirectoryFunction = (
state: WalkerState,
Expand Down
8 changes: 6 additions & 2 deletions src/api/queue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WalkerState } from "../types";
import type { WalkerState } from "../types.ts";

type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void;
/**
Expand All @@ -8,7 +8,11 @@ type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void;
*/
export class Queue {
count: number = 0;
constructor(private onQueueEmpty?: OnQueueEmptyCallback) {}
private onQueueEmpty?: OnQueueEmptyCallback;

constructor(onQueueEmpty?: OnQueueEmptyCallback) {
this.onQueueEmpty = onQueueEmpty;
}

enqueue() {
this.count++;
Expand Down
4 changes: 2 additions & 2 deletions src/api/sync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Output, Options } from "../types";
import { Walker } from "./walker";
import type { Output, Options } from "../types.ts";
import { Walker } from "./walker.ts";

export function sync<TOutput extends Output>(
root: string,
Expand Down
31 changes: 15 additions & 16 deletions src/api/walker.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { basename, dirname } from "path";
import { isRootDirectory, normalizePath } from "../utils";
import { ResultCallback, WalkerState, Options } from "../types";
import * as joinPath from "./functions/join-path";
import * as pushDirectory from "./functions/push-directory";
import * as pushFile from "./functions/push-file";
import * as getArray from "./functions/get-array";
import * as groupFiles from "./functions/group-files";
import * as resolveSymlink from "./functions/resolve-symlink";
import * as invokeCallback from "./functions/invoke-callback";
import * as walkDirectory from "./functions/walk-directory";
import { Queue } from "./queue";
import type { Dirent } from "fs";
import * as nativeFs from "fs";
import { Output } from "../types";
import { Counter } from "./counter";
import { Aborter } from "./aborter";
import nativeFs, { type Dirent } from "fs";
import { isRootDirectory, normalizePath } from "../utils.ts";
import type { ResultCallback, WalkerState, Options } from "../types.ts";
import * as joinPath from "./functions/join-path.ts";
import * as pushDirectory from "./functions/push-directory.ts";
import * as pushFile from "./functions/push-file.ts";
import * as getArray from "./functions/get-array.ts";
import * as groupFiles from "./functions/group-files.ts";
import * as resolveSymlink from "./functions/resolve-symlink.ts";
import * as invokeCallback from "./functions/invoke-callback.ts";
import * as walkDirectory from "./functions/walk-directory.ts";
import { Queue } from "./queue.ts";
import type { Output } from "../types.ts";
import { Counter } from "./counter.ts";
import { Aborter } from "./aborter.ts";

export class Walker<TOutput extends Output> {
private readonly root: string;
Expand Down
17 changes: 10 additions & 7 deletions src/builder/api-builder.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { callback, promise } from "../api/async";
import { sync } from "../api/sync";
import { Options, Output, ResultCallback } from "../types";
import { callback, promise } from "../api/async.ts";
import { sync } from "../api/sync.ts";
import type { Options, Output, ResultCallback } from "../types.ts";

export class APIBuilder<TReturnType extends Output> {
constructor(
private readonly root: string,
private readonly options: Options
) {}
private readonly root: string;
private readonly options: Options;

constructor(root: string, options: Options) {
this.root = root;
this.options = options;
}

withPromise(): Promise<TReturnType> {
return promise(this.root, this.options);
Expand Down
6 changes: 3 additions & 3 deletions src/builder/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sep } from "path";
import {
import type {
Output,
OnlyCountsOutput,
GroupOutput,
Expand All @@ -10,8 +10,8 @@ import {
GlobFunction,
GlobMatcher,
GlobParams,
} from "../types";
import { APIBuilder } from "./api-builder";
} from "../types.ts";
import { APIBuilder } from "./api-builder.ts";
import type picomatch from "picomatch";

let pm: typeof picomatch | null = null;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Builder } from "./builder";
import { Builder } from "./builder/index.ts";

export { Builder as fdir };
export type Fdir = typeof Builder;

export * from "./types";
export * from "./types.ts";
18 changes: 9 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Aborter } from "./api/aborter";
import { Queue } from "./api/queue";
import type * as nativeFs from "fs";
import type fs from 'fs';
import { Aborter } from "./api/aborter.ts";
import { Queue } from "./api/queue.ts";

export type Counts = {
files: number;
Expand Down Expand Up @@ -28,12 +28,12 @@ export type PathsOutput = string[];
export type Output = OnlyCountsOutput | PathsOutput | GroupOutput;

export type FSLike = {
readdir: typeof nativeFs.readdir;
readdirSync: typeof nativeFs.readdirSync;
realpath: typeof nativeFs.realpath;
realpathSync: typeof nativeFs.realpathSync;
stat: typeof nativeFs.stat;
statSync: typeof nativeFs.statSync;
readdir: typeof fs.readdir;
readdirSync: typeof fs.readdirSync;
realpath: typeof fs.realpath;
realpathSync: typeof fs.realpathSync;
stat: typeof fs.stat;
statSync: typeof fs.statSync;
};

export type WalkerState = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sep, normalize, resolve } from "path";
import { PathSeparator } from "./types";
import type { PathSeparator } from "./types.ts";

export function cleanPath(path: string) {
let normalized = normalize(path);
Expand Down
10 changes: 6 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "CommonJS",
"moduleResolution": "node",
"target": "esnext",
"module": "node16",
"lib": ["esnext"],
"declaration": true,
"outDir": "./dist",
"noEmit": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"erasableSyntaxOnly": true,
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true,
Expand Down