Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit 25f4dce

Browse files
authored
chore: switch to esm (#37)
Also adds gh actions instead of travis BREAKING CHANGE: only uses named exports
1 parent c14d484 commit 25f4dce

File tree

16 files changed

+201
-175
lines changed

16 files changed

+201
-175
lines changed

.aegir.js renamed to .aegir.cjs

File renamed without changes.

.github/workflows/main.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
- run: npm install
16+
- run: npx aegir lint
17+
- uses: gozala/typescript-error-reporter-action@v1.0.8
18+
- run: npx aegir build
19+
- run: npx aegir dep-check
20+
- uses: ipfs/aegir/actions/bundle-size@master
21+
name: size
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
test-node:
25+
needs: check
26+
runs-on: ${{ matrix.os }}
27+
strategy:
28+
matrix:
29+
os: [windows-latest, ubuntu-latest, macos-latest]
30+
node: [14, 16]
31+
fail-fast: true
32+
steps:
33+
- uses: actions/checkout@v2
34+
- uses: actions/setup-node@v1
35+
with:
36+
node-version: ${{ matrix.node }}
37+
- run: npm install
38+
- run: npx aegir test -t node --cov --bail
39+
- uses: codecov/codecov-action@v1
40+
test-chrome:
41+
needs: check
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v2
45+
- run: npm install
46+
- run: npx aegir test -t browser -t webworker --bail
47+
test-firefox:
48+
needs: check
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v2
52+
- run: npm install
53+
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
54+
test-electron-main:
55+
needs: check
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v2
59+
- run: npm install
60+
- run: npm run pretest
61+
- run: npx xvfb-maybe aegir test -t electron-main --bail -f dist/cjs/node-test/*js
62+
test-electron-renderer:
63+
needs: check
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v2
67+
- run: npm install
68+
- run: npm run pretest
69+
- run: npx xvfb-maybe aegir test -t electron-renderer --bail -f dist/cjs/browser-test/*js

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ node_modules
3636
lib
3737
dist
3838
docs
39+
types

.travis.yml

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

LICENSE-APACHE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
2+
3+
http://www.apache.org/licenses/LICENSE-2.0
4+
5+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

LICENSE renamed to LICENSE-MIT

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
MIT License
2-
3-
Copyright (c) 2017 IPFS
1+
The MIT License (MIT)
42

53
Permission is hereby granted, free of charge, to any person obtaining a copy
64
of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +7,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
97
copies of the Software, and to permit persons to whom the Software is
108
furnished to do so, subject to the following conditions:
119

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
1412

1513
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1614
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1715
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1816
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1917
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ $ npm install datastore-s3
3131
If the flag `createIfMissing` is not set or is false, then the bucket must be created prior to using datastore-s3. Please see the AWS docs for information on how to configure the S3 instance. A bucket name is required to be set at the s3 instance level, see the below example.
3232

3333
```js
34-
const S3 = require('aws-sdk').S3
34+
import S3 from 'aws-sdk/clients/s3.js'
35+
import { S3Datastore } from 'datastore-s3'
36+
3537
const s3Instance = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
36-
const S3Store = require('datastore-s3')
37-
const store = new S3Store('.ipfs/datastore', {
38+
const store = new S3Datastore('.ipfs/datastore', {
3839
s3: s3Instance
3940
createIfMissing: false
4041
})
@@ -55,4 +56,4 @@ Small note: If editing the Readme, please conform to the [standard-readme](https
5556

5657
## License
5758

58-
MIT 2018 © IPFS
59+
[Apache-2.0](LICENSE-APACHE) OR [MIT](LICENSE-MIT)

examples/full-s3-repo/create-s3-repo.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
'use strict'
1+
import { S3Datastore } from 'datastore-s3'
2+
import { createRepo } from 'ipfs-repo'
3+
import { BlockstoreDatastoreAdapter } from 'blockstore-datastore-adapter'
4+
import { ShardingDatastore } from 'datastore-core/sharding'
5+
import { NextToLast } from 'datastore-core/shard'
6+
import * as raw from 'multiformats/codecs/raw'
7+
import * as json from 'multiformats/codecs/json'
8+
import * as dagPb from '@ipld/dag-pb'
9+
import * as dagCbor from '@ipld/dag-cbor'
210

3-
4-
const DatastoreS3 = require('datastore-s3')
5-
const { createRepo } = require('ipfs-repo')
6-
const BlockstoreDatastoreAdapter = require('blockstore-datastore-adapter')
7-
const { ShardingDatastore, shard: { NextToLast } } = require('datastore-core')
8-
const { codecs: { raw, json } } = require('multiformats/basics')
9-
const dagPb = require('@ipld/dag-pb')
10-
const dagCbor = require('@ipld/dag-cbor')
11+
/**
12+
* @typedef {import('multiformats/codecs/interface').BlockCodec<any, any>} BlockCodec
13+
*/
1114

1215
/**
1316
* A convenience method for creating an S3 backed IPFS repo
@@ -16,13 +19,17 @@ const dagCbor = require('@ipld/dag-cbor')
1619
* @param {import('aws-sdk/clients/s3')} s3
1720
* @param {import('ipfs-repo').RepoLock} repoLock
1821
*/
19-
const createS3Repo = (path, s3, repoLock) => {
22+
export const createS3Repo = (path, s3, repoLock) => {
2023
const storeConfig = {
2124
s3,
2225
createIfMissing: true
2326
}
2427

25-
// These are the codecs we want to support, you may wish to add others
28+
/**
29+
* These are the codecs we want to support, you may wish to add others
30+
*
31+
* @type {Record<string | number, BlockCodec>}
32+
*/
2633
const codecs = {
2734
[raw.code]: raw,
2835
[raw.name]: raw,
@@ -47,30 +54,28 @@ const createS3Repo = (path, s3, repoLock) => {
4754

4855
return createRepo(path, loadCodec, {
4956
root: new ShardingDatastore(
50-
new DatastoreS3(path, storeConfig),
57+
new S3Datastore(path, storeConfig),
5158
new NextToLast(2)
5259
),
5360
blocks: new BlockstoreDatastoreAdapter(
5461
new ShardingDatastore(
55-
new DatastoreS3(`${path}blocks`, storeConfig),
62+
new S3Datastore(`${path}blocks`, storeConfig),
5663
new NextToLast(2)
5764
)
5865
),
5966
datastore: new ShardingDatastore(
60-
new DatastoreS3(`${path}datastore`, storeConfig),
67+
new S3Datastore(`${path}datastore`, storeConfig),
6168
new NextToLast(2)
6269
),
6370
keys: new ShardingDatastore(
64-
new DatastoreS3(`${path}keys`, storeConfig),
71+
new S3Datastore(`${path}keys`, storeConfig),
6572
new NextToLast(2)
6673
),
6774
pins: new ShardingDatastore(
68-
new DatastoreS3(`${path}pins`, storeConfig),
75+
new S3Datastore(`${path}pins`, storeConfig),
6976
new NextToLast(2)
7077
)
7178
}, {
7279
repoLock
7380
})
7481
}
75-
76-
module.exports = createS3Repo

examples/full-s3-repo/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict'
2-
3-
const IPFS = require('ipfs')
4-
const toBuffer = require('it-to-buffer')
5-
const createRepo = require('./create-s3-repo')
6-
const S3 = require('aws-sdk/clients/s3')
7-
const S3Lock = require('./s3-lock')
1+
import IPFS from 'ipfs-core'
2+
import toBuffer from 'it-to-buffer'
3+
import { createS3Repo } from './create-s3-repo'
4+
import S3 from 'aws-sdk/clients/s3.js'
5+
import { S3Lock } from './s3-lock'
86

97
async function main () {
108
// Configure S3 as normal
@@ -22,7 +20,7 @@ async function main () {
2220
const repoLock = new S3Lock(s3)
2321

2422
// Create the repo
25-
const s3Repo = createRepo('/', s3, repoLock)
23+
const s3Repo = createS3Repo('/', s3, repoLock)
2624

2725
// Create a new IPFS node with our S3 backed Repo
2826
console.log('Start ipfs')

examples/full-s3-repo/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
"@ipld/dag-cbor": "^6.0.9",
1414
"@ipld/dag-pb": "^2.1.9",
1515
"aws-sdk": "^2.885.0",
16-
"blockstore-datastore-adapter": "^1.0.0",
17-
"datastore-core": "^5.0.1",
16+
"blockstore-datastore-adapter": "^2.0.1",
17+
"datastore-core": "^6.0.6",
1818
"datastore-s3": "../../",
19-
"ipfs": "^0.58.1",
20-
"ipfs-repo": "^11.0.1",
19+
"ipfs-core": "^0.10.6",
20+
"ipfs-repo": "^12.0.0",
2121
"it-to-buffer": "^2.0.0",
2222
"multiformats": "^9.4.5"
2323
}

examples/full-s3-repo/s3-lock.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
const PATH = require('path')
4-
const { fromString: uint8ArrayFromString } = require('uint8arrays')
3+
import PATH from 'path'
4+
import { fromString as uint8ArrayFromString } from 'uint8arrays'
55

66
/**
77
* Uses an object in an S3 bucket as a lock to signal that an IPFS repo is in use.
@@ -13,7 +13,7 @@ const { fromString: uint8ArrayFromString } = require('uint8arrays')
1313
* @typedef {import('ipfs-repo').LockCloser} LockCloser
1414
*/
1515

16-
class S3Lock {
16+
export class S3Lock {
1717
/**
1818
* @param {import('aws-sdk/clients/s3')} s3
1919
*/
@@ -153,5 +153,3 @@ class S3Lock {
153153
return true
154154
}
155155
}
156-
157-
module.exports = S3Lock

package.json

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@
44
"description": "IPFS datastore implementation backed by s3",
55
"leadMaintainer": "Jacob Heun<jacobheun@gmail.com>",
66
"main": "src/index.js",
7-
"types": "dist/src/index.d.ts",
7+
"type": "module",
8+
"types": "types/src/index.d.ts",
89
"files": [
9-
"dist",
10-
"src"
10+
"*",
11+
"!**/*.tsbuildinfo"
1112
],
13+
"exports": {
14+
".": {
15+
"import": "./src/index.js"
16+
}
17+
},
1218
"scripts": {
19+
"clean": "rimraf dist types",
20+
"prepare": "aegir build --no-bundle && cp -R types dist",
1321
"lint": "aegir ts -p check && aegir lint",
22+
"build": "aegir build",
23+
"release": "aegir release --target node",
24+
"release-minor": "aegir release --type minor --target node",
25+
"release-major": "aegir release --type major --target node",
26+
"pretest": "aegir build --esm-tests",
1427
"test": "aegir test",
15-
"test:node": "aegir test --target node",
16-
"release": "aegir release --target node --docs",
17-
"release-minor": "aegir release --type minor --target node --docs",
18-
"release-major": "aegir release --type major --target node --docs",
19-
"coverage": "nyc --reporter=text --reporter=lcov npm run test:node",
20-
"docs": "aegir docs"
28+
"dep-check": "aegir dep-check -i rimraf"
2129
},
2230
"repository": {
2331
"type": "git",
@@ -30,15 +38,21 @@
3038
"datastore",
3139
"s3"
3240
],
33-
"license": "MIT",
41+
"license": "(Apache-2.0 OR MIT)",
3442
"bugs": {
3543
"url": "https://github.com/ipfs/js-datastore-s3/issues"
3644
},
3745
"homepage": "https://github.com/ipfs/js-datastore-s3#readme",
46+
"eslintConfig": {
47+
"extends": "ipfs",
48+
"parserOptions": {
49+
"sourceType": "module"
50+
}
51+
},
3852
"dependencies": {
3953
"buffer": "^6.0.3",
40-
"datastore-core": "^5.0.0",
41-
"interface-datastore": "^5.1.1",
54+
"datastore-core": "^6.0.5",
55+
"interface-datastore": "^6.0.2",
4256
"it-filter": "^1.0.2",
4357
"it-to-buffer": "^2.0.0",
4458
"uint8arrays": "^3.0.0"
@@ -47,7 +61,7 @@
4761
"aegir": "^35.0.2",
4862
"assert": "^2.0.0",
4963
"aws-sdk": "^2.579.0",
50-
"interface-datastore-tests": "^1.0.0",
64+
"interface-datastore-tests": "^2.0.3",
5165
"sinon": "^11.1.2",
5266
"util": "^0.12.3"
5367
},

0 commit comments

Comments
 (0)