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

fix: remove node globals #6

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dist
# Dependency directory
node_modules
package-lock.json

yarn.lock
# Tests
test/test-repo-for*
test/sharness/tmp
16 changes: 8 additions & 8 deletions migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ const emptyMigration = {
description: 'Empty migration.',
migrate: () => {},
revert: () => {},
empty: true,
empty: true
}

module.exports = [
Object.assign({}, emptyMigration, {version: 7, revert: undefined}),
Object.assign({}, emptyMigration, {version: 6, revert: undefined}),
Object.assign({}, emptyMigration, {version: 5, revert: undefined}),
Object.assign({}, emptyMigration, {version: 4, revert: undefined}),
Object.assign({}, emptyMigration, {version: 3, revert: undefined}),
Object.assign({}, emptyMigration, {version: 2, revert: undefined}),
Object.assign({}, emptyMigration, {version: 1, revert: undefined}),
Object.assign({}, emptyMigration, { version: 7, revert: undefined }),
Object.assign({}, emptyMigration, { version: 6, revert: undefined }),
Object.assign({}, emptyMigration, { version: 5, revert: undefined }),
Object.assign({}, emptyMigration, { version: 4, revert: undefined }),
Object.assign({}, emptyMigration, { version: 3, revert: undefined }),
Object.assign({}, emptyMigration, { version: 2, revert: undefined }),
Object.assign({}, emptyMigration, { version: 1, revert: undefined })
]
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"main": "src/index.js",
"browser": {
"./src/repo/lock.js": "./src/repo/lock-memory.js",
"datastore-fs": "datastore-level"
"datastore-fs": "datastore-idb"
},
"bin": {
"jsipfs-migrations": "./src/cli.js"
Expand All @@ -44,17 +44,19 @@
"docs": "aegir docs"
},
"dependencies": {
"chalk": "^2.4.2",
"buffer": "^5.5.0",
"chalk": "^4.0.0",
"datastore-fs": "~0.9.1",
"datastore-level": "~0.12.1",
"datastore-idb": "^1.0.0",
"datastore-level": "~0.14.1",
"debug": "^4.1.0",
"interface-datastore": "~0.8.0",
"interface-datastore": "~0.8.3",
"proper-lockfile": "^4.1.1",
"yargs": "^14.2.0",
"yargs-promise": "^1.1.0"
},
"devDependencies": {
"aegir": "^20.4.1",
"aegir": "^21.4.5",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"dirty-chai": "^2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/repo/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports.isRepoInitialized = async function isRepoInitialized (path) {
let root
try {
root = new Datastore(path, { extension: '', createIfMissing: false })

await root.open()
const versionCheck = await root.has(versionKey)
const configCheck = await root.has(configKey)
if (!versionCheck || !configCheck) {
Expand Down
1 change: 1 addition & 0 deletions src/repo/version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const { Buffer } = require('buffer')
const errors = require('../errors')
const repoInit = require('./init')
const Datastore = require('datastore-fs')
Expand Down
3 changes: 2 additions & 1 deletion test/browser.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-env mocha */
'use strict'

const { Buffer } = require('buffer')
const loadFixture = require('aegir/fixtures')
const Datastore = require('datastore-level')
const Datastore = require('datastore-idb')

const Key = require('interface-datastore').Key
const CONFIG_KEY = new Key('config')
Expand Down
6 changes: 3 additions & 3 deletions test/init-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const expect = chai.expect
const { Buffer } = require('buffer')
const { expect } = require('./util')

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

expect(await repoInit.isRepoInitialized(dir)).to.be.true()
Expand Down
7 changes: 3 additions & 4 deletions test/integration-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const expect = chai.expect
const { expect } = require('./util')

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

const store = new Datastore(dir, { extension: '', createIfMissing: false })

await store.open()
const version = await store.get(VERSION_KEY)
expect(version.toString()).to.be.equal('2')

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

const store = new Datastore(dir, { extension: '', createIfMissing: false })

await store.open()
const version = await store.get(VERSION_KEY)
expect(version.toString()).to.be.equal('1')

Expand Down
3 changes: 1 addition & 2 deletions test/lock-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const expect = chai.expect
const { expect } = require('./util')

// When new lock mechanism is introduced in new version don't forget to update
// the range (from/to) of the previous version test's description
Expand Down
7 changes: 4 additions & 3 deletions test/test-migrations/migration-2/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { Buffer } = require('buffer')
const Datastore = require('datastore-fs')
const path = require('path')
const Key = require('interface-datastore').Key
const _set = require('just-safe-set')

Expand Down Expand Up @@ -37,7 +37,7 @@ function datastoreFactory (repoPath, options) {
storageBackendOptions = { extension: '' }
}

return new StorageBackend(path.join(repoPath), storageBackendOptions)
return new StorageBackend(repoPath, storageBackendOptions)
}

function addNewApiAddress (config) {
Expand Down Expand Up @@ -78,6 +78,7 @@ function removeNewApiAddress (config) {

async function migrate (repoPath, options, isBrowser) {
const store = datastoreFactory(repoPath, options)
await store.open()
try {
const rawConfig = await store.get(CONFIG_KEY)
let config = JSON.parse(rawConfig.toString())
Expand All @@ -97,7 +98,7 @@ async function migrate (repoPath, options, isBrowser) {

async function revert (repoPath, options, isBrowser) {
const store = datastoreFactory(repoPath, options)

await store.open()
try {
const rawConfig = await store.get(CONFIG_KEY)
let config = JSON.parse(rawConfig.toString())
Expand Down
11 changes: 11 additions & 0 deletions test/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'
const chai = require('chai')
const expect = chai.expect
const sinon = require('sinon')
chai.use(require('chai-as-promised'))
chai.use(require('dirty-chai'))

module.exports = {
expect,
sinon
}
4 changes: 2 additions & 2 deletions test/version-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const expect = chai.expect
const { Buffer } = require('buffer')
const { expect } = require('./util')

const Datastore = require('datastore-fs')
const Key = require('interface-datastore').Key
Expand Down