Skip to content

Commit

Permalink
chore: switch to ESM (#136)
Browse files Browse the repository at this point in the history
Also replaces travis with gh actions

BREAKING CHANGE: deep imports/requires are no longer possible
  • Loading branch information
achingbrain authored Sep 10, 2021
1 parent c872b27 commit e4175cc
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 188 deletions.
File renamed without changes.
76 changes: 76 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: ci
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 16
- run: npm install
- run: npm run build
- run: npm run lint
- run: npm run dep-check
test-node:
needs: check
runs-on: ${{ matrix.os }}
name: test node ${{ matrix.node }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [14, 16]
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm run test -- --cov -t node
test-browser:
needs: check
runs-on: ubuntu-latest
name: test ${{ matrix.browser }} ${{ matrix.type }}
strategy:
matrix:
browser:
- chromium
- firefox
type:
- browser
- webworker
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 16
- run: npm install
- run: npm run test -- -t ${{ matrix.type }} -- --browser ${{ matrix.browser }}
test-electron:
needs: check
runs-on: ubuntu-latest
name: test ${{ matrix.type }}
strategy:
matrix:
type:
- electron-main
- electron-renderer
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 16
- run: npm install
- uses: GabrielBB/xvfb-action@v1
with:
run: npm run test -- -t ${{ matrix.type }} --bail -f dist/cjs/node-test/*js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ typings/
# while testing npm5
package-lock.json
yarn.lock
types
51 changes: 0 additions & 51 deletions .travis.yml

This file was deleted.

16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ This module contains all the necessary code for creating, understanding and vali
#### Create record

```js
const ipns = require('ipns')
const ipns from 'ipns')

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

#### Validate record

```js
const ipns = require('ipns')
const ipns from 'ipns')

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

```js
const ipns = require('ipns')
const ipns from 'ipns')

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

#### Extract public key from record

```js
const ipns = require('ipns')
const ipns from 'ipns')

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

#### Datastore key

```js
const ipns = require('ipns')
const ipns from 'ipns')

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

```js
const ipns = require('ipns')
const ipns from 'ipns')

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

```js
const ipns = require('ipns')
const ipns from 'ipns')

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

```js
const ipns = require('ipns')
const ipns from 'ipns')

const validator = ipns.validator
```
Expand Down
52 changes: 27 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,35 @@
"description": "ipns record definitions",
"leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>",
"main": "src/index.js",
"types": "dist/src/index.d.ts",
"types": "types/src/index.d.ts",
"type": "module",
"files": [
"*",
"!**/*.tsbuildinfo"
],
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"sourceType": "module"
},
"ignorePatterns": [
"src/pb/ipns.d.ts"
]
},
"scripts": {
"prepare": "run-s prepare:*",
"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",
"prepare:proto-types": "pbts -o src/pb/ipns.d.ts src/pb/ipns.js",
"prepare:types": "aegir build --no-bundle",
"generate": "run-s generate:*",
"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",
"generate:proto-types": "pbts -o src/pb/ipns.d.ts src/pb/ipns.js",
"build": "aegir build",
"clean": "rimraf dist types",
"lint": "aegir ts -p check && aegir lint",
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"release": "aegir release --target node",
"release-minor": "aegir release --type minor --target node",
"release-major": "aegir release --type major --target node",
"pretest": "aegir build --esm-tests",
"test": "aegir test",
"test:browser": "aegir test -t browser -t webworker",
"test:node": "aegir test -t node"
"dep-check": "aegir dep-check -i rimraf"
},
"files": [
"src",
"dist"
],
"pre-push": [
"lint",
"test"
],
"repository": {
"type": "git",
"url": "git+https://github.com/ipfs/js-ipns.git"
Expand All @@ -44,7 +51,7 @@
"cborg": "^1.3.3",
"debug": "^4.2.0",
"err-code": "^3.0.1",
"interface-datastore": "^5.1.1",
"interface-datastore": "^6.0.2",
"libp2p-crypto": "^0.19.5",
"long": "^4.0.0",
"multiformats": "^9.4.5",
Expand All @@ -57,14 +64,9 @@
"@types/debug": "^4.1.5",
"aegir": "^35.0.1",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"util": "^0.12.3"
},
"eslintConfig": {
"extends": "ipfs",
"ignorePatterns": [
"src/pb/ipns.d.ts"
]
},
"contributors": [
"Vasco Santos <vasco.santos@moxy.studio>",
"Alex Potsides <alex@achingbrain.net>",
Expand Down
21 changes: 10 additions & 11 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use strict'

exports.ERR_IPNS_EXPIRED_RECORD = 'ERR_IPNS_EXPIRED_RECORD'
exports.ERR_UNRECOGNIZED_VALIDITY = 'ERR_UNRECOGNIZED_VALIDITY'
exports.ERR_SIGNATURE_CREATION = 'ERR_SIGNATURE_CREATION'
exports.ERR_SIGNATURE_VERIFICATION = 'ERR_SIGNATURE_VERIFICATION'
exports.ERR_UNRECOGNIZED_FORMAT = 'ERR_UNRECOGNIZED_FORMAT'
exports.ERR_PEER_ID_FROM_PUBLIC_KEY = 'ERR_PEER_ID_FROM_PUBLIC_KEY'
exports.ERR_PUBLIC_KEY_FROM_ID = 'ERR_PUBLIC_KEY_FROM_ID'
exports.ERR_UNDEFINED_PARAMETER = 'ERR_UNDEFINED_PARAMETER'
exports.ERR_INVALID_RECORD_DATA = 'ERR_INVALID_RECORD_DATA'
exports.ERR_INVALID_EMBEDDED_KEY = 'ERR_INVALID_EMBEDDED_KEY'
export const ERR_IPNS_EXPIRED_RECORD = 'ERR_IPNS_EXPIRED_RECORD'
export const ERR_UNRECOGNIZED_VALIDITY = 'ERR_UNRECOGNIZED_VALIDITY'
export const ERR_SIGNATURE_CREATION = 'ERR_SIGNATURE_CREATION'
export const ERR_SIGNATURE_VERIFICATION = 'ERR_SIGNATURE_VERIFICATION'
export const ERR_UNRECOGNIZED_FORMAT = 'ERR_UNRECOGNIZED_FORMAT'
export const ERR_PEER_ID_FROM_PUBLIC_KEY = 'ERR_PEER_ID_FROM_PUBLIC_KEY'
export const ERR_PUBLIC_KEY_FROM_ID = 'ERR_PUBLIC_KEY_FROM_ID'
export const ERR_UNDEFINED_PARAMETER = 'ERR_UNDEFINED_PARAMETER'
export const ERR_INVALID_RECORD_DATA = 'ERR_INVALID_RECORD_DATA'
export const ERR_INVALID_EMBEDDED_KEY = 'ERR_INVALID_EMBEDDED_KEY'
Loading

0 comments on commit e4175cc

Please sign in to comment.