Skip to content
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

Volume implementation of opendir method #1043

Merged
merged 5 commits into from
Jul 27, 2024

Conversation

ddziara
Copy link
Contributor

@ddziara ddziara commented Jul 19, 2024

Implementation of opendir() and fs.Dir

  1. A new file Dir.ts implementing fs.Dir added
  2. In volume.ts opendirSync(), opendir(), opendir(callback) added
  3. in node/options.ts methods getOpendirOptions() & getOpendirOptsAndCb() added.
  4. Tests in __tests__/volume.test.ts added

@G-Rath
Copy link
Collaborator

G-Rath commented Jul 20, 2024

This looks awesome! would you mind running Prettier?

@ddziara
Copy link
Contributor Author

ddziara commented Jul 21, 2024

I run Prettier.

Copy link
Collaborator

@G-Rath G-Rath left a comment

Choose a reason for hiding this comment

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

looking good, just not sure what to do about that constructor...

src/Dir.ts Outdated
* A directory stream, like `fs.Dir`.
*/
export class Dir implements IDir {
static build(link: Link, options: opts.IOpendirOptions) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

fwiw it seems that Dir does have a constructor, though it's not documented

> new fs.Dir()
Uncaught TypeError [ERR_MISSING_ARGS]: The "handle" argument must be specified
    at new Dir (node:internal/fs/dir:49:31) {
  code: 'ERR_MISSING_ARGS'
}

I'm not sure if it's worth trying to figure out it's params though, but I can't decide between marking it as private or if we actually try to use it with our own signature (and maybe mark it as internal...?) - as either way a class always has a constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure... "fs.d.ts" (node:fs) doesn't seem to have constructor signature defined. Then again memfs module Dirent.ts defining Dirent class also doesn't define constructor. The constructor seems to be private... or I'm getting you wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The constructor seems to be private

If you mean the constructor for the native Dirent, yes it is "documented" as private (by way of not being documented) though technically you can call it because JS doesn't have a concept of private constructors at runtime.

Classes in JS always have a constructor, even if you don't define one - and class properties, methods, and constructors are public by default in TypeScript unless you declare them as private.

That's what I'm getting at - we need a way to construct a Dirent ourselves in order to use them, hence why you've implemented ~build which is effectively a constructor; so I'm debating if we should use the constructor since it is always defined anyway and Node doesn't define it themselves...

Pro: we have one less method
Con: even though Node doesn't document a constructor, the native Dirent does have one, and so it might be confusing if we define one with a different signature...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I though we were talking about constructor of Dir. :) I use to think "class factory" about static methods like "build" constructing and returning object of given class.
I believe that undocumented methods should be regarded non-existing in general - it's a little bit risky to use them. And you're right that signature would be different that makes them even less feasible. I would mark private the constructor (Dir)... although actually "build" also should be unavailable (if it would be possible)

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we remove this? it doesn't seem like it should be needed - compileOnSave looks like a vscode specific feature which may or may not exist, and even if it does, it shouldn't be set in tsconfig.json because not everyone uses vscode

Copy link
Contributor Author

@ddziara ddziara Jul 23, 2024

Choose a reason for hiding this comment

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

I've read someone's comment claiming "compileOnSave" didn't matter in VS Code, only in "full Visual Studio". Then again tsconfig.ts in __tests__ directory seems to help - the typings are again available.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be best if you describe more what the actual problem you're having is, that leads you think we need this.

My concern is not everyone uses VS Code so including a file for it specifically means it might not be properly maintained, and other changes could be made that impact that editing experience without realizing it

Copy link
Contributor Author

@ddziara ddziara Jul 24, 2024

Choose a reason for hiding this comment

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

If I am not wrong, when __test__ is excluded in main tsconfig.json then typescript stops to recognize jest types in test files but adding another tsconfig.json to __test__ dir seems to solve the problem.
Actually I followed these instructions:
(https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000432259-Setting-up-a-typescript-compile-scope-to-exclude-tests-folder-from-being-compiled-doesn-t-work)

No need to specify test patterns... I'd suggest excluding "__tests__" from the root tsconfig.json, adding a separate tsconfig.json to __tests__ folder, with

"compileOnSave": false

PS.
I use VS Code so I'm not aware of behaviours in other environments.
PS2.
It also may be my specific configuration, pnp yarn + monorepo with workspaces + yarn plugin for typescript (workspace typescript used)
PS3.
Of course we can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed tsconfig.json from __tests__ directory.

Copy link
Owner

@streamich streamich left a comment

Choose a reason for hiding this comment

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

Thank you, good work!

@streamich streamich merged commit 687e557 into streamich:master Jul 27, 2024
10 checks passed
Copy link

🎉 This PR is included in version 4.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ddziara ddziara deleted the volume-opendir branch July 27, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants