Skip to content

Commit e8a2521

Browse files
authored
chore: switch to esm (#10)
BREAKING CHANGE: deep imports/requires are no longer possible
1 parent b3592d6 commit e8a2521

File tree

6 files changed

+58
-45
lines changed

6 files changed

+58
-45
lines changed

Diff for: .github/workflows/main.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@ jobs:
5050
steps:
5151
- uses: actions/checkout@v2
5252
- run: npm install
53-
- run: npx aegir test -t browser -t webworker --bail -- --browser firefox
53+
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
5454
test-electron-main:
5555
needs: check
5656
runs-on: ubuntu-latest
5757
steps:
5858
- uses: actions/checkout@v2
5959
- run: npm install
60-
- run: npx xvfb-maybe aegir test -t electron-main --bail
60+
- run: npm run pretest
61+
- run: npx xvfb-maybe aegir test -t electron-main --bail -f dist/cjs/node-test/*js
6162
test-electron-renderer:
6263
needs: check
6364
runs-on: ubuntu-latest
6465
steps:
6566
- uses: actions/checkout@v2
6667
- run: npm install
67-
- run: npx xvfb-maybe aegir test -t electron-renderer --bail
68+
- run: npm run pretest
69+
- run: npx xvfb-maybe aegir test -t electron-renderer --bail -f dist/cjs/browser-test/*js

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ node_modules
3737

3838
dist
3939
docs
40+
types

Diff for: package.json

+28-14
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,34 @@
44
"description": "datastore interface",
55
"leadMaintainer": "Alex Potsides <[email protected]>",
66
"main": "src/index.js",
7-
"types": "dist/src/index.d.ts",
7+
"type": "module",
8+
"types": "types/index.d.ts",
89
"files": [
9-
"src",
10-
"dist"
10+
"*",
11+
"!**/*.tsbuildinfo"
1112
],
13+
"exports": {
14+
".": {
15+
"import": "./src/index.js"
16+
}
17+
},
18+
"eslintConfig": {
19+
"extends": "ipfs",
20+
"parserOptions": {
21+
"sourceType": "module"
22+
}
23+
},
1224
"scripts": {
13-
"prepare": "aegir build --no-bundle",
25+
"clean": "rimraf dist types",
26+
"prepare": "aegir build --no-bundle && cp -R types dist",
1427
"lint": "aegir ts -p check && aegir lint",
28+
"build": "aegir build",
29+
"release": "aegir release --target node",
30+
"release-minor": "aegir release --type minor --target node",
31+
"release-major": "aegir release --type major --target node",
32+
"pretest": "aegir build --esm-tests",
1533
"test": "aegir test",
16-
"release": "aegir release",
17-
"release-minor": "aegir release --type minor",
18-
"release-major": "aegir release --type major",
19-
"coverage": "aegir test --cov"
34+
"dep-check": "aegir dep-check -i rimraf"
2035
},
2136
"repository": {
2237
"type": "git",
@@ -35,20 +50,19 @@
3550
"homepage": "https://github.com/ipfs/js-blockstore-datastore-adapter#readme",
3651
"devDependencies": {
3752
"aegir": "^35.0.2",
38-
"interface-blockstore-tests": "^1.0.0",
53+
"datastore-core": "^6.0.6",
54+
"interface-blockstore-tests": "^2.0.1",
3955
"util": "^0.12.4"
4056
},
4157
"dependencies": {
58+
"blockstore-core": "^1.0.0",
4259
"err-code": "^3.0.1",
43-
"interface-blockstore": "^1.0.0",
44-
"interface-datastore": "^5.0.0",
60+
"interface-blockstore": "^2.0.2",
61+
"interface-datastore": "^6.0.2",
4562
"it-drain": "^1.0.1",
4663
"it-pushable": "^1.4.2",
4764
"multiformats": "^9.1.0"
4865
},
49-
"eslintConfig": {
50-
"extends": "ipfs"
51-
},
5266
"contributors": [
5367
"achingbrain <[email protected]>"
5468
]

Diff for: src/index.js

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
'use strict'
2-
3-
const drain = require('it-drain')
4-
const pushable = require('it-pushable')
5-
const { Key } = require('interface-datastore')
6-
const { CID } = require('multiformats/cid')
7-
const raw = require('multiformats/codecs/raw')
8-
const Digest = require('multiformats/hashes/digest')
9-
const { base32, base32pad } = require('multiformats/bases/base32')
10-
const { base58btc } = require('multiformats/bases/base58')
11-
const errcode = require('err-code')
12-
const { BlockstoreAdapter } = require('interface-blockstore')
1+
import drain from 'it-drain'
2+
import pushable from 'it-pushable'
3+
import { Key } from 'interface-datastore/key'
4+
import { CID } from 'multiformats/cid'
5+
import * as raw from 'multiformats/codecs/raw'
6+
import * as Digest from 'multiformats/hashes/digest'
7+
import { base32, base32pad } from 'multiformats/bases/base32'
8+
import { base58btc } from 'multiformats/bases/base58'
9+
import errcode from 'err-code'
10+
import { BaseBlockstore } from 'blockstore-core/base'
1311

1412
/**
1513
* Transform a cid to the appropriate datastore key.
@@ -83,7 +81,7 @@ function convertPrefix (prefix) {
8381
for (let i = 1; i < prefix.length; i++) {
8482
try {
8583
bytes = decoder(prefix.substring(0, i))
86-
} catch (err) {
84+
} catch (/** @type {any} */ err) {
8785
if (err.message !== 'Unexpected end of data') {
8886
throw err
8987
}
@@ -163,7 +161,7 @@ function convertKeyQuery (query) {
163161
/**
164162
* @implements {Blockstore}
165163
*/
166-
class BlockstoreDatastoreAdapter extends BlockstoreAdapter {
164+
export class BlockstoreDatastoreAdapter extends BaseBlockstore {
167165
/**
168166
* @param {Datastore} datastore
169167
*/
@@ -314,5 +312,3 @@ class BlockstoreDatastoreAdapter extends BlockstoreAdapter {
314312
return out
315313
}
316314
}
317-
318-
module.exports = BlockstoreDatastoreAdapter

Diff for: test/index.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* eslint-env mocha */
2-
'use strict'
32

4-
const { MemoryDatastore } = require('interface-datastore')
5-
const BlockstoreDatastoreAdapter = require('../src')
3+
import { MemoryDatastore } from 'datastore-core/memory'
4+
import { BlockstoreDatastoreAdapter } from '../src/index.js'
5+
import { interfaceBlockstoreTests } from 'interface-blockstore-tests'
66

77
describe('Memory', () => {
88
describe('interface-blockstore', () => {
9-
require('interface-blockstore-tests')({
9+
interfaceBlockstoreTests({
1010
setup () {
1111
return new BlockstoreDatastoreAdapter(
1212
new MemoryDatastore()

Diff for: tsconfig.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"extends": "aegir/src/config/tsconfig.aegir.json",
3-
"compilerOptions": {
4-
"outDir": "dist"
5-
},
6-
"include": [
7-
"test",
8-
"src"
9-
]
2+
"extends": "aegir/src/config/tsconfig.aegir.json",
3+
"compilerOptions": {
4+
"outDir": "types"
5+
},
6+
"include": [
7+
"test",
8+
"src"
9+
]
1010
}

0 commit comments

Comments
 (0)