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

Node v10.13.0 fs.mkdir recursive option not supported #257

Closed
anthify opened this issue Nov 21, 2018 · 5 comments · Fixed by #268
Closed

Node v10.13.0 fs.mkdir recursive option not supported #257

anthify opened this issue Nov 21, 2018 · 5 comments · Fixed by #268

Comments

@anthify
Copy link

anthify commented Nov 21, 2018

Hey,

It appears there is no support for the seemingly new fs.mkdir option recursive which recursively builds paths.

// Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
fs.mkdir('/tmp/a/apple', { recursive: true }, (err) => {
  if (err) throw err;
}); 

Going by this issues #254 (comment) I guess this might not be implemented as it's a node v10+ feature?

Thanks 😃

@csomakk
Copy link

csomakk commented Apr 11, 2019

have the same issue... :/

@csomakk
Copy link

csomakk commented Apr 11, 2019

so instead using

fs.mkdirSync(foldersToCreate[i], {recursive: true});

you can use

var parentFolder = destinationDir.replace(/\/[^\/]+\/?$/, '');
var foldersToCreate = [destinationDir];
while (!fs.existsSync(parentFolder)) {
                        foldersToCreate.push(parentFolder);
                        parentFolder = parentFolder.replace(/\/[^\/]+\/?$/, '');
}
foldersToCreate = foldersToCreate.reverse();
for (var i = 0; i < foldersToCreate.length; i++) {
                        fs.mkdirSync(foldersToCreate[i], {recursive: true});
}

@hsiwkin
Copy link

hsiwkin commented May 20, 2019

Hi, I've noticed that the new version with this commit wasn't published on npm.
To get this fix one has to install it from github (this line in package.json will do the trick: "mock-fs": "git+https://github.com/tschaub/mock-fs.git")

@tschaub
Copy link
Owner

tschaub commented May 20, 2019

Fix published with [email protected] (thanks @3cp).

@3cp
Copy link
Collaborator

3cp commented May 21, 2019

"mock-fs": "git+https://github.com/tschaub/mock-fs.git")

FYI, npm/yarn/pnpm all support short-cut of github repo "mock-fs": "tschaub/mock-fs" or "mock-fs": "github:tschaub/mock-fs".

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 a pull request may close this issue.

5 participants