diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 428c3044..3ed5179f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -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 diff --git a/.github/workflows/typecheck.yml b/.github/workflows/typecheck.yml new file mode 100644 index 00000000..c20b98a0 --- /dev/null +++ b/.github/workflows/typecheck.yml @@ -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 diff --git a/benchmarks/benchmark.js b/benchmarks/benchmark.js index 4edfda7f..d2c7ba6a 100644 --- a/benchmarks/benchmark.js +++ b/benchmarks/benchmark.js @@ -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"; @@ -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() { diff --git a/benchmarks/fdir-benchmark.ts b/benchmarks/fdir-benchmark.ts index bfa6ea99..1f25c863 100644 --- a/benchmarks/fdir-benchmark.ts +++ b/benchmarks/fdir-benchmark.ts @@ -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"; diff --git a/benchmarks/glob-benchmark.ts b/benchmarks/glob-benchmark.ts index acaac5da..1f50c749 100644 --- a/benchmarks/glob-benchmark.ts +++ b/benchmarks/glob-benchmark.ts @@ -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"; diff --git a/package-lock.json b/package-lock.json index ab6ec006..0448dc83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,7 +41,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" }, @@ -4393,10 +4393,11 @@ } }, "node_modules/typescript": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", - "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", + "version": "5.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", + "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", "dev": true, + "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 70f4d252..6cd0ab75 100644 --- a/package.json +++ b/package.json @@ -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__/", @@ -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" }, diff --git a/src/api/async.ts b/src/api/async.ts index 11bb1add..0af39981 100644 --- a/src/api/async.ts +++ b/src/api/async.ts @@ -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( root: string, diff --git a/src/api/functions/get-array.ts b/src/api/functions/get-array.ts index c870b6a3..6f3d3263 100644 --- a/src/api/functions/get-array.ts +++ b/src/api/functions/get-array.ts @@ -1,4 +1,4 @@ -import { Options } from "../../types"; +import type { Options } from "../../types.ts"; export type GetArrayFunction = (paths: string[]) => string[]; diff --git a/src/api/functions/group-files.ts b/src/api/functions/group-files.ts index f53a04b3..e498258f 100644 --- a/src/api/functions/group-files.ts +++ b/src/api/functions/group-files.ts @@ -1,4 +1,4 @@ -import { Group, Options } from "../../types"; +import type { Group, Options } from "../../types.ts"; export type GroupFilesFunction = ( groups: Group[], diff --git a/src/api/functions/invoke-callback.ts b/src/api/functions/invoke-callback.ts index 9dd66a0c..77f54777 100644 --- a/src/api/functions/invoke-callback.ts +++ b/src/api/functions/invoke-callback.ts @@ -1,4 +1,4 @@ -import { +import type { Output, PathsOutput, OnlyCountsOutput, @@ -6,7 +6,7 @@ import { ResultCallback, WalkerState, Options, -} from "../../types"; +} from "../../types.ts"; export type InvokeCallbackFunction = ( state: WalkerState, diff --git a/src/api/functions/join-path.ts b/src/api/functions/join-path.ts index d103cb2c..2870a0f8 100644 --- a/src/api/functions/join-path.ts +++ b/src/api/functions/join-path.ts @@ -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; diff --git a/src/api/functions/push-directory.ts b/src/api/functions/push-directory.ts index 2de954b8..0f0f868b 100644 --- a/src/api/functions/push-directory.ts +++ b/src/api/functions/push-directory.ts @@ -1,4 +1,4 @@ -import { FilterPredicate, Options } from "../../types"; +import type { FilterPredicate, Options } from "../../types.ts"; export type PushDirectoryFunction = ( directoryPath: string, diff --git a/src/api/functions/push-file.ts b/src/api/functions/push-file.ts index 18ef77dc..9f3ac58f 100644 --- a/src/api/functions/push-file.ts +++ b/src/api/functions/push-file.ts @@ -1,4 +1,4 @@ -import { FilterPredicate, Options, Counts } from "../../types"; +import type { FilterPredicate, Options, Counts } from "../../types.ts"; export type PushFileFunction = ( directoryPath: string, diff --git a/src/api/functions/resolve-symlink.ts b/src/api/functions/resolve-symlink.ts index b23cdb2b..92fa34ff 100644 --- a/src/api/functions/resolve-symlink.ts +++ b/src/api/functions/resolve-symlink.ts @@ -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, diff --git a/src/api/functions/walk-directory.ts b/src/api/functions/walk-directory.ts index f2b9d368..428dcd71 100644 --- a/src/api/functions/walk-directory.ts +++ b/src/api/functions/walk-directory.ts @@ -1,5 +1,5 @@ -import { WalkerState } from "../../types"; import type { Dirent } from "fs"; +import type { WalkerState } from "../../types.ts"; export type WalkDirectoryFunction = ( state: WalkerState, diff --git a/src/api/queue.ts b/src/api/queue.ts index dfb491ff..f91a8a99 100644 --- a/src/api/queue.ts +++ b/src/api/queue.ts @@ -1,4 +1,4 @@ -import { WalkerState } from "../types"; +import type { WalkerState } from "../types.ts"; type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void; /** @@ -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++; diff --git a/src/api/sync.ts b/src/api/sync.ts index 02a3ea67..6aab2caf 100644 --- a/src/api/sync.ts +++ b/src/api/sync.ts @@ -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( root: string, diff --git a/src/api/walker.ts b/src/api/walker.ts index e6edc0dc..1777edca 100644 --- a/src/api/walker.ts +++ b/src/api/walker.ts @@ -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 { private readonly root: string; diff --git a/src/builder/api-builder.ts b/src/builder/api-builder.ts index 4c1af175..c2972b38 100644 --- a/src/builder/api-builder.ts +++ b/src/builder/api-builder.ts @@ -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 { - 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 { return promise(this.root, this.options); diff --git a/src/builder/index.ts b/src/builder/index.ts index a0fc4be8..12960585 100644 --- a/src/builder/index.ts +++ b/src/builder/index.ts @@ -1,5 +1,5 @@ import { sep } from "path"; -import { +import type { Output, OnlyCountsOutput, GroupOutput, @@ -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; diff --git a/src/index.ts b/src/index.ts index fba8ef8b..28b037d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; diff --git a/src/types.ts b/src/types.ts index da900e01..10d257fa 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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; @@ -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 = { diff --git a/src/utils.ts b/src/utils.ts index 66260cf8..2b2490b7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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); diff --git a/tsconfig.json b/tsconfig.json index e285fa9b..7128bb85 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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,