skpm / fs

Drop-in replacement for the fs NodeJS package
MIT License
27 stars 11 forks source link

mkdirSync fails silently #15

Closed lucaorio closed 5 years ago

lucaorio commented 5 years ago

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;
});
mathieudutour commented 5 years ago
  1. fs.mkdirSync doesn't take a callback as an argument since it's synchronous.
  2. '~/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/
  3. I just don't think it's failing, just that it creates a folder where you don't expect it
lucaorio commented 5 years ago

@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?

mathieudutour commented 5 years ago
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?

lucaorio commented 5 years ago

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 :)