RangerMauve / hyper-sdk

Make your own hyper apps!
https://www.youtube.com/watch?v=HyHk4aImd_I&list=PL7sG5SCUNyeYx8wnfMOUpsh7rM_g0w_cu&index=20
MIT License
290 stars 46 forks source link

require('dat-sdk/auto') fails to run due to missing directory #44

Closed nornagon closed 4 years ago

nornagon commented 4 years ago

I pulled the Promises example code from the README and ran it on a fresh machine (macOS) and encountered this error:

/Users/nornagon/Source/autowiki/node_modules/node-localstorage/LocalStorage.js:187
            throw e;
            ^

Error: ENOENT: no such file or directory, mkdir '/Users/nornagon/Library/Application Support/dat-nodejs/localStorage'
    at Object.mkdirSync (fs.js:856:3)
    at LocalStorage._init (/Users/nornagon/Source/autowiki/node_modules/node-localstorage/LocalStorage.js:183:14)
    at new LocalStorage (/Users/nornagon/Source/autowiki/node_modules/node-localstorage/LocalStorage.js:124:12)
    at module.exports (/Users/nornagon/Source/autowiki/node_modules/dat-sdk/localstorage.js:13:10)
    at SDK (/Users/nornagon/Source/autowiki/node_modules/dat-sdk/promise.js:36:24)
    at Object.<anonymous> (/Users/nornagon/Source/autowiki/node_modules/dat-sdk/auto.js:9:40)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14) {
  errno: -2,
  syscall: 'mkdir',
  code: 'ENOENT',
  path: '/Users/nornagon/Library/Application Support/dat-nodejs/localStorage'
}

It looks like simply requiring dat-sdk/auto is enough to trigger this error:

const {DatArchive} = require('dat-sdk/auto')
RangerMauve commented 4 years ago

Oh weird. I think it's due to the LocalStorage API not auto-creating that directory.

The local storage API is used to track which archives you created locally to know when to load them and for the selectArchive API.

https://github.com/datproject/sdk/blob/master/localstorage.js#L13

Would you be interested in a PR which uses the ensureDirSync API from fs-extra to ensure that that folder exists before initializing LocalStorage?

RangerMauve commented 4 years ago

This method is going to be deprecated in the latest version. 😅