Skip to content

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

Merged
merged 2 commits into from
Jul 4, 2025
Merged

feat: support custom fs #136

merged 2 commits into from
Jul 4, 2025

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Mar 10, 2025

Adds a new fs option for specifying your own fs implementation.

Fixes #134

@@ -25,13 +26,23 @@ export type PathsOutput = string[];

export type Output = OnlyCountsOutput | PathsOutput | GroupOutput;

export type FSLike = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is purposely explicit rather than just FSLike = typeof nativeFs since the fs module has all sorts of exports (both types and actual exports) which we don't want to have to stub out to satisfy the type when bringing our own fs-like object

@SuperchupuDev
Copy link
Contributor

was about to start working on this, then saw you had already implemented and pr'd it!! thanks a lot. hopefully @thecodrr can review soon 🙏

@michaelangeloio
Copy link

This is awesome!

@SuperchupuDev
Copy link
Contributor

it truly is

Comment on lines +13 to +14
import type { Dirent } from "fs";
import * as nativeFs from "fs";
Copy link
Contributor

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

@benmccann
Copy link
Contributor

I noticed there aren't any docs being updated as part of this PR. That would probably be nice to add

@SuperchupuDev
Copy link
Contributor

this probably needs a rebase so that it can get formatted with prettier 👀

@43081j
Copy link
Contributor Author

43081j commented May 7, 2025

i have rebased and run the formatter

@thecodrr can you take another look when you get time?

@SuperchupuDev
Copy link
Contributor

@43081j it looks like this needs a rebase again 👀

@@ -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";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't import fs anywhere in the project (importing the types are okay since they are stripped). It needs to be imported conditionally otherwise anyone trying to use fdir outside node won't be able to use it - defeating the whole point of this PR.

Perhaps we can use require but if we generate esm builds, that won't work afaik. await import is also not an option since build options are synchronous.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have this problem - the walker imports path

are we sure that's the point of this PR? afaik nobody is expecting to run fdir in browsers (which is the only place that doesn't have path and fs, since all node-like runtimes provide them)

if we want to avoid depending on any node built ins, its a bigger job since we'd need to pull in pathe or something (agnostic path library) instead of path

@SuperchupuDev what does tinyglobby need this for?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't import fs anywhere in the project (importing the types are okay since they are stripped). It needs to be imported conditionally otherwise anyone trying to use fdir outside node won't be able to use it - defeating the whole point of this PR.

Perhaps we can use require but if we generate esm builds, that won't work afaik. await import is also not an option since build options are synchronous.

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 import { createRequire } from 'node:module'; createRequire(import.meta.url) for esm builds

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have this problem - the walker imports path

are we sure that's the point of this PR? afaik nobody is expecting to run fdir in browsers (which is the only place that doesn't have path and fs, since all node-like runtimes provide them)

if we want to avoid depending on any node built ins, its a bigger job since we'd need to pull in pathe or something (agnostic path library) instead of path

@SuperchupuDev what does tinyglobby need this for?

iirc the library that requested the feature wants it so that they can use when globbing their custom fs wrapper that does caching

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 require calls 😅

fdir currently relies on Node libraries (it imports path)

we can do this with fs too and satisfy the feature request with the PR in its current state afaict

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree, not using require would be ideal

@thecodrr
Copy link
Owner

thecodrr commented Jul 3, 2025

@43081j can you resolve the conflicts so I can merge this?

43081j added 2 commits July 3, 2025 09:55
Adds a new `fs` option for specifying your own `fs` implementation.
@43081j
Copy link
Contributor Author

43081j commented Jul 3, 2025

should be all good now 👍

@thecodrr thecodrr merged commit f1630d1 into thecodrr:master Jul 4, 2025
8 checks passed
@43081j 43081j deleted the custom-fs branch July 4, 2025 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fs option
5 participants