Skip to content

Commit c04aa80

Browse files
authored
chore: switch to ESM (#39)
- Converts packages to just have interfaces - Fixes circular dependency between datastore and datastore-tests BREAKING CHANGE: deep requires/imports are no longer possible, moves adapters/in-memory impls etc to core packages
1 parent e246d97 commit c04aa80

35 files changed

+139
-1243
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ dist
22
node_modules
33
package-lock.json
44
docs
5+
types
6+
.nyc_output

.nyc_output/coverage-final.json

-1
This file was deleted.

packages/interface-blockstore-tests/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
## Usage
1212

1313
```js
14-
const MyBlockstore = require('./path/to/my-blockstore')
15-
const suite = require('interface-blockstore-tests')
14+
const MyBlockstore from './path/to/my-blockstore')
15+
const suite from 'interface-blockstore-tests')
1616

1717
describe('MyBlockstore', () => {
1818
describe('interface-blockstore compliance tests', () => {

packages/interface-blockstore-tests/package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
"description": "Compliance tests for the blockstore interface",
55
"leadMaintainer": "Alex Potsides <[email protected]>",
66
"main": "src/index.js",
7-
"types": "dist/src/index.d.ts",
7+
"types": "types/src/index.d.ts",
88
"files": [
99
"src",
1010
"dist"
1111
],
1212
"scripts": {
1313
"build": "aegir build",
1414
"lint": "aegir ts -p check && aegir lint",
15-
"test": "echo \"No tests configured\"",
1615
"dep-check": "aegir dep-check"
1716
},
1817
"repository": {
@@ -40,6 +39,12 @@
4039
"uint8arrays": "^3.0.0"
4140
},
4241
"eslintConfig": {
43-
"extends": "ipfs"
42+
"extends": "ipfs",
43+
"parserOptions": {
44+
"sourceType": "module"
45+
}
46+
},
47+
"publishConfig": {
48+
"directory": "dist"
4449
}
4550
}

packages/interface-blockstore-tests/src/index.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/* eslint-env mocha */
2-
'use strict'
3-
4-
const { expect } = require('aegir/utils/chai')
5-
const all = require('it-all')
6-
const drain = require('it-drain')
7-
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
8-
const { CID } = require('multiformats/cid')
9-
const { sha256 } = require('multiformats/hashes/sha2')
10-
const { base32 } = require('multiformats/bases/base32')
11-
const raw = require('multiformats/codecs/raw')
12-
const length = require('it-length')
2+
3+
import { expect } from 'aegir/utils/chai.js'
4+
import all from 'it-all'
5+
import drain from 'it-drain'
6+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
7+
import { CID } from 'multiformats/cid'
8+
import { sha256 } from 'multiformats/hashes/sha2'
9+
import { base32 } from 'multiformats/bases/base32'
10+
import * as raw from 'multiformats/codecs/raw'
11+
import length from 'it-length'
1312

1413
/**
1514
* @typedef {import('interface-blockstore').Blockstore} Blockstore
@@ -43,7 +42,7 @@ async function getKeyValuePairs (count) {
4342
/**
4443
* @param {{ teardown: () => void; setup: () => Blockstore; }} test
4544
*/
46-
module.exports = (test) => {
45+
export function interfaceBlockstoreTests (test) {
4746
/**
4847
* @param {Blockstore} store
4948
*/
@@ -309,7 +308,7 @@ module.exports = (test) => {
309308
try {
310309
base32.decode(keyStr.substring(0, j))
311310
prefix = keyStr.substring(0, j)
312-
} catch (err) {
311+
} catch (/** @type {any} */ err) {
313312
if (err.message !== 'Unexpected end of data') {
314313
throw err
315314
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
{
22
"extends": "aegir/src/config/tsconfig.aegir.json",
33
"compilerOptions": {
4-
"outDir": "dist"
4+
"outDir": "types"
55
},
66
"include": [
7-
"test",
87
"src"
8+
],
9+
"exclude": [
10+
"dist"
11+
],
12+
"references": [
13+
{
14+
"path": "../interface-blockstore"
15+
}
916
]
1017
}

packages/interface-blockstore/package.json

+5-10
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
"name": "interface-blockstore",
33
"version": "1.0.2",
44
"description": "An interface for storing and retrieving blocks",
5-
"main": "src/index.js",
6-
"types": "dist/src/index.d.ts",
5+
"types": "types/src/index.d.ts",
76
"scripts": {
87
"build": "aegir build",
9-
"test": "echo \"No tests configured\"",
10-
"lint": "aegir ts -p check && aegir lint",
11-
"dep-check": "aegir dep-check"
8+
"lint": "aegir ts -p check && aegir lint"
129
},
1310
"license": "(Apache-2.0 OR MIT)",
1411
"homepage": "https://github.com/ipfs/js-ipfs-interfaces/tree/master/packages/interface-blockstore#readme",
@@ -18,15 +15,13 @@
1815
"url": "git+https://github.com/ipfs/js-ipfs-interfaces.git"
1916
},
2017
"dependencies": {
21-
"err-code": "^3.0.1",
2218
"interface-store": "^1.0.2",
23-
"it-all": "^1.0.5",
24-
"it-drain": "^1.0.4",
25-
"it-filter": "^1.0.2",
26-
"it-take": "^1.0.1",
2719
"multiformats": "^9.0.4"
2820
},
2921
"devDependencies": {
3022
"aegir": "^35.0.0"
23+
},
24+
"publishConfig": {
25+
"directory": "dist"
3126
}
3227
}

packages/interface-blockstore/src/adapter.js

-245
This file was deleted.

0 commit comments

Comments
 (0)