mkdirSync fails silently
lucaorio opened this issue · comments
It seems like fs.existsSync
doesn't create any folder. No error is returned, either.
import * as fs from '@skpm/fs';
// ...
fs.mkdirSync('~/test/abc', { recursive: true }, err => {
if (err) throw err;
});
fs.mkdirSync
doesn't take a callback as an argument since it's synchronous.- '~/test/abc' is equivalent to
./~/test/abc
which is probably not what you want. If you want to resolve~
, you can use something like https://github.com/sindresorhus/untildify/ - I just don't think it's failing, just that it creates a folder where you don't expect it
@mathieudutour Thanks for helping. The snippet below works well, indeed!
const path = '/Users/myself/test/abc';
!fs.existsSync(path) && fs.mkdirSync(path);
Unfortunately, Untildify returns an empty string :(
Do you have any other advice on how I can resolve that path?
const os = require('os');
const home = os.homedir();
const untiltify = input => {
if (typeof input !== 'string') {
throw new TypeError(`Expected a string, got ${typeof input}`);
}
return home ? input.replace(/^~(?=$|\/|\\)/, home) : input;
};
console.log(untiltify('~/test'))
works fine for me (which is the code of https://github.com/sindresorhus/untildify/). What version of Sketch are you using?
I'm using 53.1!
By the way, untiltify wasn't working when I was trying to run everything from within a plugin. I'm now slowly moving pretty much everything I can outside of it, and I can confirm you that untiltify works well :)