Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit 8b51f8d

Browse files
committed
fix: remove node globals
This PR add new datastore for browser and remove node glovals Plus
1 parent 767ed70 commit 8b51f8d

File tree

12 files changed

+41
-27
lines changed

12 files changed

+41
-27
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dist
2626
# Dependency directory
2727
node_modules
2828
package-lock.json
29-
29+
yarn.lock
3030
# Tests
3131
test/test-repo-for*
3232
test/sharness/tmp

migrations/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ const emptyMigration = {
77
description: 'Empty migration.',
88
migrate: () => {},
99
revert: () => {},
10-
empty: true,
10+
empty: true
1111
}
1212

1313
module.exports = [
14-
Object.assign({}, emptyMigration, {version: 7, revert: undefined}),
15-
Object.assign({}, emptyMigration, {version: 6, revert: undefined}),
16-
Object.assign({}, emptyMigration, {version: 5, revert: undefined}),
17-
Object.assign({}, emptyMigration, {version: 4, revert: undefined}),
18-
Object.assign({}, emptyMigration, {version: 3, revert: undefined}),
19-
Object.assign({}, emptyMigration, {version: 2, revert: undefined}),
20-
Object.assign({}, emptyMigration, {version: 1, revert: undefined}),
14+
Object.assign({}, emptyMigration, { version: 7, revert: undefined }),
15+
Object.assign({}, emptyMigration, { version: 6, revert: undefined }),
16+
Object.assign({}, emptyMigration, { version: 5, revert: undefined }),
17+
Object.assign({}, emptyMigration, { version: 4, revert: undefined }),
18+
Object.assign({}, emptyMigration, { version: 3, revert: undefined }),
19+
Object.assign({}, emptyMigration, { version: 2, revert: undefined }),
20+
Object.assign({}, emptyMigration, { version: 1, revert: undefined })
2121
]

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"main": "src/index.js",
2121
"browser": {
2222
"./src/repo/lock.js": "./src/repo/lock-memory.js",
23-
"datastore-fs": "datastore-level"
23+
"datastore-fs": "datastore-idb"
2424
},
2525
"bin": {
2626
"jsipfs-migrations": "./src/cli.js"
@@ -44,8 +44,10 @@
4444
"docs": "aegir docs"
4545
},
4646
"dependencies": {
47+
"buffer": "^5.5.0",
4748
"chalk": "^2.4.2",
4849
"datastore-fs": "~0.9.1",
50+
"datastore-idb": "ipfs/js-datastore-idb#master",
4951
"datastore-level": "~0.12.1",
5052
"debug": "^4.1.0",
5153
"interface-datastore": "~0.8.0",
@@ -54,7 +56,7 @@
5456
"yargs-promise": "^1.1.0"
5557
},
5658
"devDependencies": {
57-
"aegir": "^20.4.1",
59+
"aegir": "^21.4.5",
5860
"chai": "^4.2.0",
5961
"chai-as-promised": "^7.1.1",
6062
"dirty-chai": "^2.0.1",

src/repo/init.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exports.isRepoInitialized = async function isRepoInitialized (path) {
1212
let root
1313
try {
1414
root = new Datastore(path, { extension: '', createIfMissing: false })
15-
15+
await root.open()
1616
const versionCheck = await root.has(versionKey)
1717
const configCheck = await root.has(configKey)
1818
if (!versionCheck || !configCheck) {

src/repo/version.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const errors = require('../errors')
45
const repoInit = require('./init')
56
const Datastore = require('datastore-fs')

test/browser.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* eslint-env mocha */
22
'use strict'
33

4+
const { Buffer } = require('buffer')
45
const loadFixture = require('aegir/fixtures')
5-
const Datastore = require('datastore-level')
6+
const Datastore = require('datastore-idb')
67

78
const Key = require('interface-datastore').Key
89
const CONFIG_KEY = new Key('config')

test/init-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const expect = chai.expect
4+
const { Buffer } = require('buffer')
5+
const { expect } = require('./util')
66

77
const Datastore = require('datastore-fs')
88
const Key = require('interface-datastore').Key
@@ -24,7 +24,7 @@ module.exports = (setup, cleanup) => {
2424
const store = new Datastore(dir, { extension: '', createIfMissing: false })
2525
await store.open()
2626
await store.put(versionKey, Buffer.from('7'))
27-
await store.put(configKey, '')
27+
await store.put(configKey, Buffer.from('config'))
2828
await store.close()
2929

3030
expect(await repoInit.isRepoInitialized(dir)).to.be.true()

test/integration-test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const expect = chai.expect
4+
const { expect } = require('./util')
65

76
const migrator = require('../src')
87
const migrations = require('./test-migrations')
@@ -26,7 +25,7 @@ module.exports = (setup, cleanup) => {
2625
await migrator.migrate(dir, migrator.getLatestMigrationVersion(migrations), { migrations: migrations })
2726

2827
const store = new Datastore(dir, { extension: '', createIfMissing: false })
29-
28+
await store.open()
3029
const version = await store.get(VERSION_KEY)
3130
expect(version.toString()).to.be.equal('2')
3231

@@ -42,7 +41,7 @@ module.exports = (setup, cleanup) => {
4241
await migrator.revert(dir, 1, { migrations: migrations })
4342

4443
const store = new Datastore(dir, { extension: '', createIfMissing: false })
45-
44+
await store.open()
4645
const version = await store.get(VERSION_KEY)
4746
expect(version.toString()).to.be.equal('1')
4847

test/lock-test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const expect = chai.expect
4+
const { expect } = require('./util')
65

76
// When new lock mechanism is introduced in new version don't forget to update
87
// the range (from/to) of the previous version test's description

test/test-migrations/migration-2/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const Datastore = require('datastore-fs')
4-
const path = require('path')
55
const Key = require('interface-datastore').Key
66
const _set = require('just-safe-set')
77

@@ -37,7 +37,7 @@ function datastoreFactory (repoPath, options) {
3737
storageBackendOptions = { extension: '' }
3838
}
3939

40-
return new StorageBackend(path.join(repoPath), storageBackendOptions)
40+
return new StorageBackend(repoPath, storageBackendOptions)
4141
}
4242

4343
function addNewApiAddress (config) {
@@ -78,6 +78,7 @@ function removeNewApiAddress (config) {
7878

7979
async function migrate (repoPath, options, isBrowser) {
8080
const store = datastoreFactory(repoPath, options)
81+
await store.open()
8182
try {
8283
const rawConfig = await store.get(CONFIG_KEY)
8384
let config = JSON.parse(rawConfig.toString())
@@ -97,7 +98,7 @@ async function migrate (repoPath, options, isBrowser) {
9798

9899
async function revert (repoPath, options, isBrowser) {
99100
const store = datastoreFactory(repoPath, options)
100-
101+
await store.open()
101102
try {
102103
const rawConfig = await store.get(CONFIG_KEY)
103104
let config = JSON.parse(rawConfig.toString())

test/util.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict'
2+
const chai = require('chai')
3+
const expect = chai.expect
4+
const sinon = require('sinon')
5+
chai.use(require('chai-as-promised'))
6+
chai.use(require('dirty-chai'))
7+
8+
module.exports = {
9+
expect,
10+
sinon
11+
}

test/version-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const expect = chai.expect
4+
const { Buffer } = require('buffer')
5+
const { expect } = require('./util')
66

77
const Datastore = require('datastore-fs')
88
const Key = require('interface-datastore').Key

0 commit comments

Comments
 (0)