diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index c2197a1..4334372 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -12,15 +12,15 @@ jobs: matrix: node-version: - 16.x - - 17.x + - 18.x steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - - name: Install Redrun, Lerna - run: npm i redrun lerna -g + - name: Install + run: npm i && npm i redrun -g - name: Lint run: redrun fix:lint - name: Commit fixes @@ -28,7 +28,7 @@ jobs: with: message: chore(${{ env.NAME }}) lint using actions - name: Coverage - run: redrun coverage:ci report + run: redrun coverage report - name: Coveralls uses: coverallsapp/github-action@master with: diff --git a/.madrun.js b/.madrun.js index 0fd6c0c..b900b61 100644 --- a/.madrun.js +++ b/.madrun.js @@ -4,10 +4,11 @@ const {run} = require('madrun'); module.exports = { 'test': () => `tape 'test/*.js'`, - 'watch:test': () => 'nodemon -w lib -w test -x "npm test"', + 'watch:test': async () => await run('watcher', await run('test')), + 'watcher': () => 'nodemon -w test -w lib -w bin --exec', 'lint': () => 'putout .', 'fix:lint': () => run('lint', '--fix'), - 'coverage': () => 'nyc npm test', - 'report': () => 'nyc report --reporter=text-lcov | coveralls', + 'coverage': async () => `c8 ${await run('test')}`, + 'report': () => 'c8 report --reporter=lcov', }; diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9b08e29..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: node_js -node_js: - - 13 - - 12 - - 10 - - 8 - -script: - - npm run lint - - npm run coverage && npm run report - -notifications: - email: - on_success: never - on_failure: change - -sudo: false - diff --git a/README.md b/README.md index ffe0d72..138a091 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Try to Catch [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL] [NPMIMGURL]: https://img.shields.io/npm/v/try-to-catch.svg?style=flat&longCache=true -[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/try-to-catch/master.svg?style=flat&longCache=true [NPMURL]: https://npmjs.org/package/try-to-catch "npm" -[BuildStatusURL]: https://travis-ci.org/coderaiser/try-to-catch "Build Status" [CoverageURL]: https://coveralls.io/github/coderaiser/try-to-catch?branch=master [CoverageIMGURL]: https://coveralls.io/repos/coderaiser/try-to-catch/badge.svg?branch=master&service=github +[BuildStatusURL]: https://github.com/coderaiser/try-to-catch/actions?query=workflow%3A%22Node+CI%22 "Build Status" +[BuildStatusIMGURL]: https://github.com/coderaiser/try-to-catch/workflows/Node%20CI/badge.svg Functional `try-catch` wrapper for `promises`. @@ -26,7 +26,7 @@ Wrap function to avoid `try-catch` block, resolves `[error, result]`; Simplest example with `async-await`: ```js -const tryToCatch = require('try-to-catch'); +import tryToCatch from 'try-to-catch'; const reject = Promise.reject.bind(Promise); await tryToCatch(reject, 'hi'); // returns @@ -36,7 +36,7 @@ await tryToCatch(reject, 'hi'); Can be used with functions: ```js -const tryToCatch = require('try-to-catch'); +import tryToCatch from 'try-to-catch'; await tryToCatch(() => 5); // returns [null, 5]; @@ -45,12 +45,17 @@ await tryToCatch(() => 5); Advanced example: ```js -const {readFile, readdir} = require('fs/promises'); -const tryToCatch = require('try-to-catch'); +import {readFile, readdir} = from 'node:fs/promises'; +import tryToCatch from 'try-to-catch'; -read(process.argv[2]) - .then(console.log) - .catch(console.error); +const [error, data] = await tryToCatch(read, process.argv[2]); + +if (error) { + console.error(error); + process.exit(1); +} + +console.log(data); async function read(path) { const [error, data] = await tryToCatch(readFile, path, 'utf8'); diff --git a/package.json b/package.json index e50bc70..f71c4a7 100644 --- a/package.json +++ b/package.json @@ -30,13 +30,12 @@ "then" ], "devDependencies": { - "coveralls": "^3.0.0", + "c8": "^7.11.2", "eslint": "^8.10.0", "eslint-plugin-node": "^11.0.0", - "eslint-plugin-putout": "^14.4.0", + "eslint-plugin-putout": "^15.1.1", "madrun": "^9.0.0", "nodemon": "^2.0.2", - "nyc": "^15.0.0", "putout": "^25.4.1", "supertape": "^7.2.0" },