diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f468993..0bc3b42 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,16 +1,11 @@ version: 2 updates: - - package-ecosystem: 'github-actions' - directory: '/' - schedule: - interval: 'daily' - commit-message: - prefix: 'chore' - include: 'scope' - - package-ecosystem: 'npm' - directory: '/' - schedule: - interval: 'daily' - commit-message: - prefix: 'chore' - include: 'scope' +- package-ecosystem: npm + directory: "/" + schedule: + interval: daily + time: "10:00" + open-pull-requests-limit: 10 + commit-message: + prefix: "deps" + prefix-development: "deps(dev)" diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 0000000..d57c2a0 --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,8 @@ +name: Automerge +on: [ pull_request ] + +jobs: + automerge: + uses: protocol/.github/.github/workflows/automerge.yml@master + with: + job: 'automerge' diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml new file mode 100644 index 0000000..d155996 --- /dev/null +++ b/.github/workflows/js-test-and-release.yml @@ -0,0 +1,145 @@ +name: test & maybe release +on: + push: + branches: + - master # with #262 - ${{{ github.default_branch }}} + pull_request: + branches: + - master # with #262 - ${{{ github.default_branch }}} + +jobs: + + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present lint + - run: npm run --if-present dep-check + + test-node: + needs: check + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + node: [16] + fail-fast: true + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:node + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + with: + flags: node + + test-chrome: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:chrome + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + with: + flags: chrome + + test-chrome-webworker: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:chrome-webworker + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + with: + flags: chrome-webworker + + test-firefox: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:firefox + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + with: + flags: firefox + + test-firefox-webworker: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:firefox-webworker + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + with: + flags: firefox-webworker + + test-electron-main: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npx xvfb-maybe npm run --if-present test:electron-main + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + with: + flags: electron-main + + test-electron-renderer: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npx xvfb-maybe npm run --if-present test:electron-renderer + - uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 + with: + flags: electron-renderer + + release: + needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer] + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/master' # with #262 - 'refs/heads/${{{ github.default_branch }}}' + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - uses: ipfs/aegir/actions/docker-login@master + with: + docker-token: ${{ secrets.DOCKER_TOKEN }} + docker-username: ${{ secrets.DOCKER_USERNAME }} + - run: npm run --if-present release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml deleted file mode 100644 index da72524..0000000 --- a/.github/workflows/test-and-release.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: Test & Maybe Release -on: [push, pull_request] -jobs: - test: - strategy: - fail-fast: false - matrix: - node: [14.x, 16.x] - os: [macos-latest, ubuntu-latest, windows-latest] - runs-on: ${{ matrix.os }} - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node }} - uses: actions/setup-node@v3.5.1 - with: - node-version: ${{ matrix.node }} - - name: Install Dependencies - run: | - npm install --no-progress - - name: Run tests - run: | - npm config set script-shell bash - npm run test:ci - - name: Typecheck - uses: gozala/typescript-error-reporter-action@v1.0.8 - release: - name: Release - needs: test - runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/master' - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3.5.1 - with: - node-version: 14 - - name: Install dependencies - run: | - npm install --no-progress --no-package-lock --no-save - - name: Build - run: | - npm run build - - name: Install plugins - run: | - npm install \ - @semantic-release/commit-analyzer \ - conventional-changelog-conventionalcommits \ - @semantic-release/release-notes-generator \ - @semantic-release/npm \ - @semantic-release/github \ - @semantic-release/git \ - @semantic-release/changelog \ - --no-progress --no-package-lock --no-save - - name: Release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: npx semantic-release diff --git a/.gitignore b/.gitignore index 594cec7..b4f2d40 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ build dist coverage +.coverage package-lock.json node_modules .DS_Store diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 40cae74..0000000 --- a/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -.github -dist/test diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..20ce483 --- /dev/null +++ b/LICENSE @@ -0,0 +1,4 @@ +This project is dual licensed under MIT and Apache-2.0. + +MIT: https://www.opensource.org/licenses/mit +Apache-2.0: https://www.apache.org/licenses/license-2.0 diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..14478a3 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,5 @@ +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 + +http://www.apache.org/licenses/LICENSE-2.0 + +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. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..72dc60d --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index 711e873..36f31ed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,23 @@ -# @multiformats/murmur3 +# @multiformats/murmur3 -Murmur3-32 (x86 32-bit) and Murmur3-128 (x64 128-bit) multihash hashers for [multiformats](https://github.com/multiformats/js-multiformats). +[![multiformats.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://multiformats.io) +[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-murmur3.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-murmur3) +[![CI](https://img.shields.io/github/workflow/status/multiformats/js-murmur3/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/multiformats/js-murmur3/actions/workflows/js-test-and-release.yml) + +> Multiformats Murmur3 implementations + +## Table of contents + +- [Install](#install) +- [Usage](#usage) +- [License](#license) +- [Contribute](#contribute) + +## Install + +```console +$ npm i @multiformats/murmur3 +``` `MultihashHashers`s are exported from this library, they produce `MultihashDigest`s. Details about these can be found in the [multiformats multihash interface definitions](https://github.com/multiformats/js-multiformats/blob/master/src/hashes/interface.ts). @@ -39,9 +56,9 @@ import { murmur3128 } from '@multiformats/murmur3' Licensed under either of - * Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0) - * MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT) +- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](LICENSE-MIT) / ) -### Contribution +## Contribute Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/example.js b/example.js index 9e314a1..a1a5a24 100644 --- a/example.js +++ b/example.js @@ -1,6 +1,8 @@ +/* eslint-disable no-console */ + import * as Block from 'multiformats/block' import * as codec from '@ipld/dag-cbor' -import { murmur3128 as hasher } from '@multiformats/murmur3' +import { murmur3128 as hasher } from 'src' async function run () { const value = { hello: 'world' } diff --git a/package.json b/package.json index 85c29b2..a976a09 100644 --- a/package.json +++ b/package.json @@ -2,77 +2,64 @@ "name": "@multiformats/murmur3", "version": "0.0.0-dev", "description": "Multiformats Murmur3 implementations", - "main": "index.js", - "type": "module", - "types": "types/index.d.ts", - "scripts": { - "lint": "standard", - "build": "npm run build:js && npm run build:types", - "build:js": "ipjs build --tests --main && npm run build:copy", - "build:copy": "cp -a tsconfig.json *.js test dist/", - "build:types": "tsc --build && mv types dist", - "test:cjs": "npm run build && mocha dist/cjs/node-test/test-*.js && npm run test:cjs:browser", - "test:esm": "npm run build && mocha dist/esm/node-test/test-*.js && npm run test:esm:browser", - "test:node": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha test/test-*.js", - "test:cjs:browser": "polendina --cleanup dist/cjs/browser-test/test-*.js", - "test:esm:browser": "polendina --cleanup dist/esm/browser-test/test-*.js", - "test": "npm run lint && npm run test:node && npm run test:esm", - "test:ci": "npm run lint && npm run test:node && npm run test:esm && npm run test:cjs", - "coverage": "c8 --reporter=html mocha test/test-*.js && npm_config_yes=true npx st -d coverage -p 8080" + "author": "Mikeal Rogers (https://www.mikealrogers.com/)", + "license": "Apache-2.0 OR MIT", + "homepage": "https://github.com/multiformats/js-murmur3#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/multiformats/js-murmur3.git" + }, + "bugs": { + "url": "https://github.com/multiformats/js-murmur3/issues" }, "keywords": [ + "hash", "ipfs", "ipld", "multiformats", - "hash", "multihash", "murmur3" ], - "author": "Mikeal Rogers (https://www.mikealrogers.com/)", - "license": "(Apache-2.0 AND MIT)", - "exports": { - "import": "./index.js" + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" }, - "dependencies": { - "multiformats": "^9.5.4", - "murmurhash3js-revisited": "^3.0.0" - }, - "devDependencies": { - "@ipld/dag-cbor": "^7.0.0", - "c8": "^7.10.0", - "chai": "^4.3.4", - "ipjs": "^5.2.0", - "mocha": "^10.0.0", - "polendina": "^3.0.0", - "standard": "^17.0.0", - "typescript": "^4.5.3" - }, - "standard": { - "ignore": [ - "dist" - ] - }, - "directories": { - "test": "test" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/multiformats/js-murmur3.git" - }, - "bugs": { - "url": "https://github.com/multiformats/js-murmur3/issues" - }, - "homepage": "https://github.com/multiformats/js-murmur3#readme", + "type": "module", + "types": "./dist/src/index.d.ts", "typesVersions": { "*": { "*": [ - "types/*" + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ], - "types/*": [ - "types/*" + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ] } }, + "files": [ + "src", + "dist", + "!dist/test", + "!**/*.tsbuildinfo" + ], + "exports": { + ".": { + "types": "./dist/src/index.d.ts", + "import": "./src/index.js" + } + }, + "eslintConfig": { + "extends": "ipfs", + "parserOptions": { + "sourceType": "module" + } + }, "release": { "branches": [ "master" @@ -100,15 +87,15 @@ "release": "patch" }, { - "type": "chore", + "type": "docs", "release": "patch" }, { - "type": "docs", + "type": "test", "release": "patch" }, { - "type": "test", + "type": "deps", "release": "patch" }, { @@ -138,7 +125,11 @@ }, { "type": "docs", - "section": "Trivial Changes" + "section": "Documentation" + }, + { + "type": "deps", + "section": "Dependencies" }, { "type": "test", @@ -149,14 +140,32 @@ } ], "@semantic-release/changelog", - [ - "@semantic-release/npm", - { - "pkgRoot": "dist" - } - ], + "@semantic-release/npm", "@semantic-release/github", "@semantic-release/git" ] + }, + "scripts": { + "clean": "aegir clean", + "lint": "aegir lint", + "build": "aegir build", + "release": "aegir release", + "test": "aegir test -t node -t browser -t webworker -t electron-main", + "test:ts": "npm run test --prefix test/ts-use", + "test:node": "aegir test -t node --cov", + "test:chrome": "aegir test -t browser --cov", + "test:chrome-webworker": "aegir test -t webworker", + "test:firefox": "aegir test -t browser -- --browser firefox", + "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", + "test:electron-main": "aegir test -t electron-main", + "dep-check": "aegir dep-check" + }, + "dependencies": { + "multiformats": "^10.0.1", + "murmurhash3js-revisited": "^3.0.0" + }, + "devDependencies": { + "@ipld/dag-cbor": "^7.0.0", + "aegir": "^37.5.6" } } diff --git a/index.js b/src/index.js similarity index 95% rename from index.js rename to src/index.js index 418b1df..e08a28e 100644 --- a/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ import { from } from 'multiformats/hashes/hasher' import { bytes } from 'multiformats' -// @ts-ignore +// @ts-expect-error no types import mur from 'murmurhash3js-revisited' /** diff --git a/test/test-basics.js b/test/test-basics.spec.js similarity index 89% rename from test/test-basics.js rename to test/test-basics.spec.js index d22f4fb..139cc91 100644 --- a/test/test-basics.js +++ b/test/test-basics.spec.js @@ -1,10 +1,8 @@ /* eslint-env mocha */ -import * as murmur3 from '@multiformats/murmur3' -import chai from 'chai' +import * as murmur3 from '../src/index.js' +import { assert } from 'aegir/chai' import { bytes } from 'multiformats' -const { assert } = chai - const fixtures = [ ['murmur3-32', 'beep boop', '2304243ddb9e'], ['murmur3-128', 'beep boop', '2210acfe9c5bbf88f075c0c4df0464430ead'] @@ -13,6 +11,7 @@ const fixtures = [ describe('Digests', () => { for (const [name, input, expectedDigest] of fixtures) { it(name, async () => { + // @ts-expect-error cannot use string to index murmur3 const hasher = murmur3[name.replace('-', '')] const hash = await hasher.digest(bytes.fromString(input)) assert.strictEqual(hash.code, hasher.code) diff --git a/tsconfig.json b/tsconfig.json index 5c3b5ae..4805fbc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,40 +1,14 @@ { + "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "allowJs": true, - "checkJs": true, - "forceConsistentCasingInFileNames": true, - "noImplicitReturns": false, - "noImplicitAny": true, - "noImplicitThis": true, - "noFallthroughCasesInSwitch": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "strictFunctionTypes": false, - "strictNullChecks": true, - "strictPropertyInitialization": true, - "strictBindCallApply": true, - "strict": true, - "alwaysStrict": true, - "esModuleInterop": true, - "target": "ES2018", - "module": "ESNext", - "moduleResolution": "node", - "declaration": true, - "declarationMap": true, - "outDir": "types", - "skipLibCheck": true, - "stripInternal": true, - "resolveJsonModule": true, - "emitDeclarationOnly": true, - "baseUrl": ".", - "paths": { - "@multiformats/murmur3": [ "index.js" ] - } + "outDir": "dist", + "emitDeclarationOnly": true }, - "exclude": [ - "node_modules", - "test", - "dist" + "include": [ + "src", + "test" ], - "compileOnSave": false + "exclude": [ + "test/ts-use" + ] }