Skip to content

Commit e4175cc

Browse files
authored
chore: switch to ESM (#136)
Also replaces travis with gh actions BREAKING CHANGE: deep imports/requires are no longer possible
1 parent c872b27 commit e4175cc

File tree

13 files changed

+180
-188
lines changed

13 files changed

+180
-188
lines changed

.aegir.js renamed to .aegir.cjs

File renamed without changes.

.github/workflows/main.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: ci
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
10+
jobs:
11+
check:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-node@v1
16+
with:
17+
node-version: 16
18+
- run: npm install
19+
- run: npm run build
20+
- run: npm run lint
21+
- run: npm run dep-check
22+
test-node:
23+
needs: check
24+
runs-on: ${{ matrix.os }}
25+
name: test node ${{ matrix.node }}
26+
strategy:
27+
matrix:
28+
os: [windows-latest, ubuntu-latest, macos-latest]
29+
node: [14, 16]
30+
fail-fast: true
31+
steps:
32+
- uses: actions/checkout@v2
33+
- uses: actions/setup-node@v1
34+
with:
35+
node-version: ${{ matrix.node }}
36+
- run: npm install
37+
- run: npm run test -- --cov -t node
38+
test-browser:
39+
needs: check
40+
runs-on: ubuntu-latest
41+
name: test ${{ matrix.browser }} ${{ matrix.type }}
42+
strategy:
43+
matrix:
44+
browser:
45+
- chromium
46+
- firefox
47+
type:
48+
- browser
49+
- webworker
50+
fail-fast: true
51+
steps:
52+
- uses: actions/checkout@v2
53+
- uses: actions/setup-node@v1
54+
with:
55+
node-version: 16
56+
- run: npm install
57+
- run: npm run test -- -t ${{ matrix.type }} -- --browser ${{ matrix.browser }}
58+
test-electron:
59+
needs: check
60+
runs-on: ubuntu-latest
61+
name: test ${{ matrix.type }}
62+
strategy:
63+
matrix:
64+
type:
65+
- electron-main
66+
- electron-renderer
67+
fail-fast: true
68+
steps:
69+
- uses: actions/checkout@v2
70+
- uses: actions/setup-node@v1
71+
with:
72+
node-version: 16
73+
- run: npm install
74+
- uses: GabrielBB/xvfb-action@v1
75+
with:
76+
run: npm run test -- -t ${{ matrix.type }} --bail -f dist/cjs/node-test/*js

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ typings/
6363
# while testing npm5
6464
package-lock.json
6565
yarn.lock
66+
types

.travis.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ This module contains all the necessary code for creating, understanding and vali
4848
#### Create record
4949

5050
```js
51-
const ipns = require('ipns')
51+
const ipns from 'ipns')
5252

5353
const entryData = await ipns.create(privateKey, value, sequenceNumber, lifetime)
5454
```
5555

5656
#### Validate record
5757

5858
```js
59-
const ipns = require('ipns')
59+
const ipns from 'ipns')
6060

6161
await ipns.validate(publicKey, ipnsEntry)
6262
// if no error thrown, the record is valid
@@ -65,23 +65,23 @@ await ipns.validate(publicKey, ipnsEntry)
6565
#### Embed public key to record
6666

6767
```js
68-
const ipns = require('ipns')
68+
const ipns from 'ipns')
6969

7070
const ipnsEntryWithEmbedPublicKey = await ipns.embedPublicKey(publicKey, ipnsEntry)
7171
```
7272

7373
#### Extract public key from record
7474

7575
```js
76-
const ipns = require('ipns')
76+
const ipns from 'ipns')
7777

7878
const publicKey = ipns.extractPublicKey(peerId, ipnsEntry)
7979
```
8080

8181
#### Datastore key
8282

8383
```js
84-
const ipns = require('ipns')
84+
const ipns from 'ipns')
8585

8686
ipns.getLocalKey(peerId)
8787
```
@@ -95,7 +95,7 @@ Returns a key to be used for storing the ipns entry locally, that is:
9595
#### Marshal data with proto buffer
9696

9797
```js
98-
const ipns = require('ipns')
98+
const ipns from 'ipns')
9999

100100
const entryData = await ipns.create(privateKey, value, sequenceNumber, lifetime)
101101
// ...
@@ -108,7 +108,7 @@ Returns the entry data serialized.
108108
#### Unmarshal data from proto buffer
109109

110110
```js
111-
const ipns = require('ipns')
111+
const ipns from 'ipns')
112112

113113
const data = ipns.unmarshal(storedData)
114114
```
@@ -118,7 +118,7 @@ Returns the entry data structure after being serialized.
118118
#### Validator
119119

120120
```js
121-
const ipns = require('ipns')
121+
const ipns from 'ipns')
122122

123123
const validator = ipns.validator
124124
```

package.json

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,35 @@
44
"description": "ipns record definitions",
55
"leadMaintainer": "Vasco Santos <[email protected]>",
66
"main": "src/index.js",
7-
"types": "dist/src/index.d.ts",
7+
"types": "types/src/index.d.ts",
8+
"type": "module",
9+
"files": [
10+
"*",
11+
"!**/*.tsbuildinfo"
12+
],
13+
"eslintConfig": {
14+
"extends": "ipfs",
15+
"parserOptions": {
16+
"sourceType": "module"
17+
},
18+
"ignorePatterns": [
19+
"src/pb/ipns.d.ts"
20+
]
21+
},
822
"scripts": {
9-
"prepare": "run-s prepare:*",
10-
"prepare:proto": "pbjs -t static-module -w commonjs -r ipfs-ipns --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/pb/ipns.js src/pb/ipns.proto",
11-
"prepare:proto-types": "pbts -o src/pb/ipns.d.ts src/pb/ipns.js",
12-
"prepare:types": "aegir build --no-bundle",
23+
"generate": "run-s generate:*",
24+
"generate:proto": "pbjs -t static-module -w es6 -r ipfs-ipns --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/pb/ipns.js src/pb/ipns.proto",
25+
"generate:proto-types": "pbts -o src/pb/ipns.d.ts src/pb/ipns.js",
26+
"build": "aegir build",
27+
"clean": "rimraf dist types",
1328
"lint": "aegir ts -p check && aegir lint",
14-
"release": "aegir release",
15-
"release-minor": "aegir release --type minor",
16-
"release-major": "aegir release --type major",
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",
1733
"test": "aegir test",
18-
"test:browser": "aegir test -t browser -t webworker",
19-
"test:node": "aegir test -t node"
34+
"dep-check": "aegir dep-check -i rimraf"
2035
},
21-
"files": [
22-
"src",
23-
"dist"
24-
],
25-
"pre-push": [
26-
"lint",
27-
"test"
28-
],
2936
"repository": {
3037
"type": "git",
3138
"url": "git+https://github.com/ipfs/js-ipns.git"
@@ -44,7 +51,7 @@
4451
"cborg": "^1.3.3",
4552
"debug": "^4.2.0",
4653
"err-code": "^3.0.1",
47-
"interface-datastore": "^5.1.1",
54+
"interface-datastore": "^6.0.2",
4855
"libp2p-crypto": "^0.19.5",
4956
"long": "^4.0.0",
5057
"multiformats": "^9.4.5",
@@ -57,14 +64,9 @@
5764
"@types/debug": "^4.1.5",
5865
"aegir": "^35.0.1",
5966
"npm-run-all": "^4.1.5",
67+
"rimraf": "^3.0.2",
6068
"util": "^0.12.3"
6169
},
62-
"eslintConfig": {
63-
"extends": "ipfs",
64-
"ignorePatterns": [
65-
"src/pb/ipns.d.ts"
66-
]
67-
},
6870
"contributors": [
6971
"Vasco Santos <[email protected]>",
7072
"Alex Potsides <[email protected]>",

src/errors.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
'use strict'
21

3-
exports.ERR_IPNS_EXPIRED_RECORD = 'ERR_IPNS_EXPIRED_RECORD'
4-
exports.ERR_UNRECOGNIZED_VALIDITY = 'ERR_UNRECOGNIZED_VALIDITY'
5-
exports.ERR_SIGNATURE_CREATION = 'ERR_SIGNATURE_CREATION'
6-
exports.ERR_SIGNATURE_VERIFICATION = 'ERR_SIGNATURE_VERIFICATION'
7-
exports.ERR_UNRECOGNIZED_FORMAT = 'ERR_UNRECOGNIZED_FORMAT'
8-
exports.ERR_PEER_ID_FROM_PUBLIC_KEY = 'ERR_PEER_ID_FROM_PUBLIC_KEY'
9-
exports.ERR_PUBLIC_KEY_FROM_ID = 'ERR_PUBLIC_KEY_FROM_ID'
10-
exports.ERR_UNDEFINED_PARAMETER = 'ERR_UNDEFINED_PARAMETER'
11-
exports.ERR_INVALID_RECORD_DATA = 'ERR_INVALID_RECORD_DATA'
12-
exports.ERR_INVALID_EMBEDDED_KEY = 'ERR_INVALID_EMBEDDED_KEY'
2+
export const ERR_IPNS_EXPIRED_RECORD = 'ERR_IPNS_EXPIRED_RECORD'
3+
export const ERR_UNRECOGNIZED_VALIDITY = 'ERR_UNRECOGNIZED_VALIDITY'
4+
export const ERR_SIGNATURE_CREATION = 'ERR_SIGNATURE_CREATION'
5+
export const ERR_SIGNATURE_VERIFICATION = 'ERR_SIGNATURE_VERIFICATION'
6+
export const ERR_UNRECOGNIZED_FORMAT = 'ERR_UNRECOGNIZED_FORMAT'
7+
export const ERR_PEER_ID_FROM_PUBLIC_KEY = 'ERR_PEER_ID_FROM_PUBLIC_KEY'
8+
export const ERR_PUBLIC_KEY_FROM_ID = 'ERR_PUBLIC_KEY_FROM_ID'
9+
export const ERR_UNDEFINED_PARAMETER = 'ERR_UNDEFINED_PARAMETER'
10+
export const ERR_INVALID_RECORD_DATA = 'ERR_INVALID_RECORD_DATA'
11+
export const ERR_INVALID_EMBEDDED_KEY = 'ERR_INVALID_EMBEDDED_KEY'

0 commit comments

Comments
 (0)