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

fix mkdir and mkdirSync options #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions src/js/node/Fs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ typedef FsWriteFileOptions = {
autoClose: true
}
**/
/**
* options for `Fs.mkdir` and `Fs.mkdirSync`
*/
typedef FsMakeDirOptions = {
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be called FsMkdirOptions to be consistent with the function names :)

@:optional var recursive:Bool;
@:optional var mode:FsMode;
};

/**
Options for `Fs.createReadStream`.
**/
Expand Down Expand Up @@ -695,12 +703,12 @@ extern class Fs {
`mode` defaults to 0777.
**/
@:overload(function(path:FsPath, callback:Error->Void):Void {})
static function mkdir(path:FsPath, mode:FsMode, callback:Error->Void):Void;
static function mkdir(path:FsPath, options:FsMakeDirOptions, callback:Error->Void):Void;
Copy link
Member

Choose a reason for hiding this comment

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

The optional options argument can be an integer specifying mode (permission and sticky bits), or an object with a mode property and a recursive property indicating whether parent directories should be created.

Shouldn't we do EitherType<FsMode, FsMakeDirOptions>?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, there's more to it:

The callback is given a possible exception and, if recursive is true, the first directory path created, (err, [path]).

and

Returns undefined, or if recursive is true, the first directory path created.

for mkdirSync

It's a bit tricky to have proper typing for this, so we can ignore this for now, but we'll have to look into this at some point. Maybe some @:overload trick can be used for that.


/**
Synchronous mkdir(2).
**/
static function mkdirSync(path:FsPath, ?mode:FsMode):Void;
static function mkdirSync(path:FsPath, ?options:FsMakeDirOptions):Void;

/**
Creates a unique temporary directory.
Expand Down