diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..a657cce --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +version: 2 +updates: +- package-ecosystem: npm + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + ignore: + - dependency-name: sinon + versions: + - 10.0.0 + - dependency-name: youch + versions: + - 2.2.0 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..aafa9b3 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,29 @@ +name: Run tests + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [12.x, 14.x, 15.x] + + name: Node ${{ matrix.node-version }} + + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm test + env: + CI: true diff --git a/.travis.yml b/.travis.yml index 6c7bd82..fbebcfa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,6 @@ language: node_js + node_js: - - 8 - - 10 - - 11 + - 12 + - 14 - node - -env: - - HAPI_VERSION="" - -matrix: - include: - - node_js: "8" - env: HAPI_VERSION="@17" - -install: - - npm install - - npm install hapi$HAPI_VERSION diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c25bab..d77cf00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,43 @@ # Changelog +## Version [4.0.0](https://github.com/futurestudio/hapi-dev-errors/compare/v3.3.0...v4.0.0) (2020-01-10) + +### Breaking Changes +- require Node.js v12 + - this change aligns with the hapi ecosystem requiring Node.js v12 with the release of hapi 19 + + +## Version [3.3.0](https://github.com/futurestudio/hapi-dev-errors/compare/v3.2.6...v3.3.0) (2019-10-17) + +### Added +- basic TypeScript declarations in `lib/index.d.ts` + + +## Version [3.2.6](https://github.com/futurestudio/hapi-dev-errors/compare/v3.2.5...v3.2.6) (2019-10-11) + +### Updated +- refine Readme +- bump dependencies +- remove Node.js v11 from Travis testing +- minor refactorings (a mobile app update would say: “performance improvements”) + + +## Version [3.2.5](https://github.com/futurestudio/hapi-dev-errors/compare/v3.2.4...v3.2.5) (2019-05-19) + +### Updated +- fix `.travis.yml` to properly test the hapi version matrix +- fix `@hapi/hapi` import in examples +- minor example refinements +- bump dependencies + + +## Version [3.2.4](https://github.com/futurestudio/hapi-dev-errors/compare/v3.2.3...v3.2.4) (2019-04-27) + +### Updated +- bump dependencies +- update to hapi scoped dependencies + + ## Version [3.2.3](https://github.com/futurestudio/hapi-dev-errors/compare/v3.2.2...v3.2.3) (2019-02-18) ### Updated diff --git a/README.md b/README.md index f9afd0d..cfecf1e 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@
Follow @marcuspoehls for updates!
@@ -47,30 +47,37 @@ Besides the web view, `hapi-dev-errors` prints pretty error details to the termi
## Requirements
-This plugin uses async/await which requires **Node.js v8 or newer**.
+This plugin uses async/await which requires **Node.js v12 or newer**.
+
+
+### Compatibility
+| Major Release | [hapi.js](https://github.com/hapijs/hapi) version | Node.js version |
+| --- | --- | --- |
+| `v4` | `>=17 hapi` | `>=12` |
+| `v3` | `>=17 hapi` | `>=8` |
+| `v2` | `>=17 hapi` | `>=8` |
## Installation
Add `hapi-dev-errors` as a dependency to your project:
```bash
-# NPM 5: this way is yours
npm i hapi-dev-errors
-
-# NPM 4:
-npm i -S hapi-dev-errors
```
-### Do you use hapi v16 (or lower)?
+### Using hapi v17 or v18?
+Use the `3.x` release of `hapi-dev-errors`:
+
+```bash
+npm i hapi-dev-errors@3
+```
+
+### Using hapi v16 (or lower)?
Use the `1.3.2` release of `hapi-dev-errors` with hapi v16. Later versions are only compatible with hapi v17.
```bash
-# NPM 5: this way is yours
npm i hapi-dev-errors@1.3.2
-
-# NPM 4: use NPM shortcuts to (i)nstall and (-S)ave the module as a dependency
-npm i -S hapi-dev-errors@1.3.2
```
@@ -117,7 +124,8 @@ await server.register({
return `
Search hapi-dev-errors on GitHub
- `
+
+ `
}
]
}
diff --git a/examples/default.js b/examples/default.js
index a104e30..39f768c 100644
--- a/examples/default.js
+++ b/examples/default.js
@@ -1,6 +1,6 @@
'use strict'
-const Hapi = require('hapi')
+const Hapi = require('@hapi/hapi')
const server = new Hapi.Server({ host: 'localhost', port: 3000 })
@@ -15,9 +15,7 @@ async function launchIt () {
server.route({
method: '*',
path: '/{path*}',
- handler: (_, h) => {
- return h.notAvailable()
- }
+ handler: (_, h) => h.notAvailable()
})
await server.start()
diff --git a/examples/template.js b/examples/template.js
index 04c8f50..be28dc3 100644
--- a/examples/template.js
+++ b/examples/template.js
@@ -1,6 +1,6 @@
'use strict'
-const Hapi = require('hapi')
+const Hapi = require('@hapi/hapi')
const Path = require('path')
const server = new Hapi.Server({ host: 'localhost', port: 3000 })
@@ -8,7 +8,7 @@ const server = new Hapi.Server({ host: 'localhost', port: 3000 })
async function launchIt () {
await server.register([
{
- plugin: require('vision')
+ plugin: require('@hapi/vision')
},
{
plugin: require('../'),
@@ -20,9 +20,7 @@ async function launchIt () {
])
server.views({
- engines: {
- html: require('handlebars')
- },
+ engines: { html: require('handlebars') },
path: Path.resolve(__dirname, 'views'),
layout: 'layout',
isCached: process.env.NODE_ENV !== 'production'
@@ -31,9 +29,7 @@ async function launchIt () {
server.route({
method: '*',
path: '/{path*}',
- handler: (_, reply) => {
- reply.notAvailable()
- }
+ handler: (_, h) => h.notAvailable()
})
await server.start()
diff --git a/examples/with-links.js b/examples/with-links.js
index 4dd255e..5c29a5b 100644
--- a/examples/with-links.js
+++ b/examples/with-links.js
@@ -1,6 +1,6 @@
'use strict'
-const Hapi = require('hapi')
+const Hapi = require('@hapi/hapi')
const server = new Hapi.Server({ host: 'localhost', port: 3000 })
@@ -23,9 +23,7 @@ async function launchIt () {
server.route({
method: 'GET',
path: '/{path*}',
- handler: (_, h) => {
- h.notAvailable()
- }
+ handler: (_, h) => h.notAvailable()
})
await server.start()
diff --git a/lib/error-handler.js b/lib/error-handler.js
index dbca6f8..1bfb8b9 100644
--- a/lib/error-handler.js
+++ b/lib/error-handler.js
@@ -128,7 +128,9 @@ class ErrorHandler {
* @returns {Response}
*/
async resolveError (request, h) {
- await this.logToTerminal(request)
+ if (this.shouldLogToTerminal()) {
+ await this.logToTerminal(request)
+ }
if (this.wantsJson(request)) {
return this.sendJson(request, h)
@@ -141,18 +143,26 @@ class ErrorHandler {
return this.sendHtml(request, h)
}
+ /**
+ * Returns a boolean whether to log
+ * the error to the terminal.
+ *
+ * @returns {Boolean}
+ */
+ shouldLogToTerminal () {
+ return this.toTerminal
+ }
+
/**
* Logs the error to terminal.
*
* @param {Request} request
*/
async logToTerminal (request) {
- if (this.toTerminal) {
- const youch = this.createYouch(request)
- const json = await youch.toJSON()
+ const youch = this.createYouch(request)
+ const json = await youch.toJSON()
- console.log(ForTerminal(json))
- }
+ console.log(ForTerminal(json))
}
/**
diff --git a/lib/index.d.ts b/lib/index.d.ts
new file mode 100644
index 0000000..d391c4e
--- /dev/null
+++ b/lib/index.d.ts
@@ -0,0 +1 @@
+declare module 'hapi-dev-errors';
diff --git a/package.json b/package.json
index 00e5219..b41bda1 100644
--- a/package.json
+++ b/package.json
@@ -1,33 +1,33 @@
{
"name": "hapi-dev-errors",
"description": "Return better error details and skip the look at command line to catch the issue.",
- "version": "3.2.3",
- "author": "Future Studio