-
Notifications
You must be signed in to change notification settings - Fork 69
feat: support custom fs #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,8 @@ 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 { Dirent } from "fs"; | ||
| import type { Dirent } from "fs"; | ||
| import * as nativeFs from "fs"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't import Perhaps we can use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we already have this problem - the walker imports are we sure that's the point of this PR? afaik nobody is expecting to run if we want to avoid depending on any node built ins, its a bigger job since we'd need to pull in @SuperchupuDev what does tinyglobby need this for?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
we can try to use require for conditionally importing it like we already do with picomatch. tsdown (the tool thats used in the dual build pr) automatically defines a require function with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
iirc the library that requested the feature wants it so that they can use when globbing their custom fs wrapper that does caching
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah lets not go down a rabbit hole trying to hack in some fdir currently relies on Node libraries (it imports we can do this with nobody can use fdir in a browser right now without bundling it. so we haven't changed that let me know if im missing something though
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i agree, not using |
||
| import { Output } from "../types"; | ||
| import { Counter } from "./counter"; | ||
| import { Aborter } from "./aborter"; | ||
|
|
@@ -50,6 +51,7 @@ export class Walker<TOutput extends Output> { | |
| symlinks: new Map(), | ||
| visited: [""].slice(0, 0), | ||
| controller: new Aborter(), | ||
| fs: options.fs ?? nativeFs, | ||
| }; | ||
|
|
||
| /* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { Aborter } from "./api/aborter"; | ||
| import { Queue } from "./api/queue"; | ||
| import type * as nativeFs from "fs"; | ||
|
|
||
| export type Counts = { | ||
| files: number; | ||
|
|
@@ -26,6 +27,15 @@ export type PathsOutput = string[]; | |
|
|
||
| export type Output = OnlyCountsOutput | PathsOutput | GroupOutput; | ||
|
|
||
| export type FSLike = { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is purposely explicit rather than just |
||
| readdir: typeof nativeFs.readdir; | ||
| readdirSync: typeof nativeFs.readdirSync; | ||
| realpath: typeof nativeFs.realpath; | ||
| realpathSync: typeof nativeFs.realpathSync; | ||
| stat: typeof nativeFs.stat; | ||
| statSync: typeof nativeFs.statSync; | ||
| }; | ||
|
|
||
| export type WalkerState = { | ||
| root: string; | ||
| paths: string[]; | ||
|
|
@@ -34,6 +44,7 @@ export type WalkerState = { | |
| options: Options; | ||
| queue: Queue; | ||
| controller: Aborter; | ||
| fs: FSLike; | ||
|
|
||
| symlinks: Map<string, string>; | ||
| visited: string[]; | ||
|
|
@@ -67,6 +78,7 @@ export type Options<TGlobFunction = unknown> = { | |
| pathSeparator: PathSeparator; | ||
| signal?: AbortSignal; | ||
| globFunction?: TGlobFunction; | ||
| fs?: FSLike; | ||
| }; | ||
|
|
||
| export type GlobMatcher = (test: string) => boolean; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a style question probably for @thecodrr, but I wonder if these two lines should be combined into a single line