Skip to content

Commit

Permalink
Merge pull request #675 from orbitdb/fix/webpack
Browse files Browse the repository at this point in the history
Ensure webpack compiles in downstream projects
  • Loading branch information
aphelionz committed Sep 3, 2019
2 parents 83cacff + a74c3f9 commit cdc4fc3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
17 changes: 14 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -30,7 +30,7 @@
"orbit-db-keystore": "next",
"orbit-db-kvstore": "next",
"orbit-db-pubsub": "~0.5.5",
"orbit-db-storage-adapter": "^0.4.2",
"orbit-db-storage-adapter": "^0.5.0",
"orbit-db-store": "next"
},
"devDependencies": {
Expand Down
8 changes: 5 additions & 3 deletions src/OrbitDB.js
@@ -1,6 +1,6 @@
'use strict'

const fs = require('fs')
const fs = require('./fs-shim')
const path = require('path')
const EventStore = require('orbit-db-eventstore')
const FeedStore = require('orbit-db-feedstore')
Expand All @@ -17,7 +17,6 @@ const createDBManifest = require('./db-manifest')
const exchangeHeads = require('./exchange-heads')
const { isDefined, io } = require('./utils')
const Storage = require('orbit-db-storage-adapter')
const leveldown = require('leveldown')
const migrations = require('./migrations')

const Logger = require('logplease')
Expand Down Expand Up @@ -65,12 +64,15 @@ class OrbitDB {

if (!options.storage) {
let storageOptions = {}

if (fs && fs.mkdirSync) {
storageOptions.preCreate = async (directory) => {
fs.mkdirSync(directory, { recursive: true })
}
}
options.storage = Storage(leveldown, storageOptions)

// Create default `level` store
options.storage = Storage(null, storageOptions)
}

if (!options.keystore) {
Expand Down
4 changes: 4 additions & 0 deletions src/fs-shim.js
@@ -0,0 +1,4 @@
const fs = (typeof window === 'object' || typeof self === 'object') ? null
: eval('require("fs")')

module.exports = fs
2 changes: 1 addition & 1 deletion src/migrations/0.21-0.22.js
@@ -1,5 +1,5 @@
const path = require('path')
const fs = require('fs')
const fs = require('../fs-shim')

const Cache = require('orbit-db-cache')

Expand Down

0 comments on commit cdc4fc3

Please sign in to comment.