diff --git a/README.md b/README.md index e61c304fc..85e04ac38 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ You can refer to the README of each package for more information and instruction - [@honeybadger-io/react](./packages/react) [![npm version](https://badge.fury.io/js/%40honeybadger-io%2Freact.svg)](https://badge.fury.io/js/%40honeybadger-io%2Freact) SDK for React integration +- [@honeybadger-io/gatsby-plugin-honeybadger](./packages/gatsby-plugin) + [![npm version](https://badge.fury.io/js/%40honeybadger-io%2Fgatsby-plugin-honeybadger.svg)](https://badge.fury.io/js/%40honeybadger-io%2Fgatsby-plugin-honeybadger) + [Gatsby](https://www.gatsbyjs.com) plugin ## Documentation and Support diff --git a/packages/gatsby-plugin/.gitignore b/packages/gatsby-plugin/.gitignore new file mode 100644 index 000000000..f324aff80 --- /dev/null +++ b/packages/gatsby-plugin/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +node_modules +yarn-error.log diff --git a/packages/gatsby-plugin/CHANGELOG.md b/packages/gatsby-plugin/CHANGELOG.md new file mode 100644 index 000000000..e69de29bb diff --git a/packages/gatsby-plugin/MIT-LICENSE b/packages/gatsby-plugin/MIT-LICENSE new file mode 100644 index 000000000..c89520754 --- /dev/null +++ b/packages/gatsby-plugin/MIT-LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2013, Honeybadger Industries LLC + +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/packages/gatsby-plugin/README.md b/packages/gatsby-plugin/README.md new file mode 100644 index 000000000..f74df4429 --- /dev/null +++ b/packages/gatsby-plugin/README.md @@ -0,0 +1,44 @@ +# @honeybadger-io/gatsby-plugin-honeybadger + +![Node CI](https://github.com/honeybadger-io/honeybadger-js/workflows/Node%20CI/badge.svg) +[![npm version](https://badge.fury.io/js/%40honeybadger-io%2Fgatsby-plugin-honeybadger.svg)](https://badge.fury.io/js/%40honeybadger-io%2Fgatsby-plugin-honeybadger) +[![npm dm](https://img.shields.io/npm/dm/@honeybadger-io/gatsby-plugin-honeybadger)](https://www.npmjs.com/package/@honeybadger-io/gatsby-plugin-honeybadger) +[![npm dt](https://img.shields.io/npm/dt/@honeybadger-io/gatsby-plugin-honeybadger)](https://www.npmjs.com/package/@honeybadger-io/gatsby-plugin-honeybadger) + +Gatsby plugin to add [Honeybadger error tracking](https://www.honeybadger.io/for/javascript/?utm_source=github&utm_medium=readme&utm_campaign=gatsby&utm_content=Honeybadger+error+tracking) to your site. + +## Install + +`npm install --save @honeybadger-io/gatsby-plugin-honeybadger` + +## How to use + +Add your API key in the plugin options in `gatsby-config.js`: + +```js +// gatsby-config.js +module.exports = { + plugins: [ + { + resolve: `@honeybadger-io/gatsby-plugin-honeybadger`, + options: { + apiKey: 'YOUR_API_KEY', + revision: `${Date.now()}`, + assetsUrl: 'https://foobar.com/assets', + environment: process.env.NODE_ENV + } + } + ] +} +``` + +### Options + +- `[apiKey]` _(String)_: the API key of your Honeybadger project. +- `[revision]` _(String)_: `gatsby-plugin-honeybadger` uses [`honeybadger-webpack`](https://github.com/honeybadger-io/honeybadger-webpack) to upload source maps to Honeybadger. `options.revision` needs to be unique as it is the identifier that connects your errors to your source maps. +- `[assetsURL]` _(String)_: The base URL to production assets (scheme://host/path). Used to grab source maps. +- `[environment]` _(String)_: Current environment. Used to indicate the environment where the error occurred. **Optional**, defaults to `process.env.NODE_ENV`. + +## License + +This package is MIT licensed. See the [MIT-LICENSE](./MIT-LICENSE) file in this folder for details. diff --git a/packages/gatsby-plugin/gatsby-browser.js b/packages/gatsby-plugin/gatsby-browser.js new file mode 100644 index 000000000..96b5cf17f --- /dev/null +++ b/packages/gatsby-plugin/gatsby-browser.js @@ -0,0 +1,14 @@ +const Honeybadger = require('honeybadger-js') + +exports.onClientEntry = function(_, { apiKey, revision, environment = process.env.NODE_ENV }) { + if (!apiKey) { + console.warn('gatsby-plugin-honeybadger needs an API key to be configured properly {url for documentation}') + return + } + + Honeybadger.configure({ + apiKey, + revision, + environment + }) +} \ No newline at end of file diff --git a/packages/gatsby-plugin/gatsby-node.js b/packages/gatsby-plugin/gatsby-node.js new file mode 100644 index 000000000..2c8475203 --- /dev/null +++ b/packages/gatsby-plugin/gatsby-node.js @@ -0,0 +1,13 @@ +const HoneybadgerSourceMapPlugin = require('@honeybadger-io/webpack') + +exports.onCreateWebpackConfig = ({ actions }, { apiKey, revision, assetsUrl }) => { + actions.setWebpackConfig({ + plugins: [ + new HoneybadgerSourceMapPlugin({ + apiKey, + revision, + assetsUrl + }) + ] + }) +} diff --git a/packages/gatsby-plugin/index.js b/packages/gatsby-plugin/index.js new file mode 100644 index 000000000..172f1ae6a --- /dev/null +++ b/packages/gatsby-plugin/index.js @@ -0,0 +1 @@ +// noop diff --git a/packages/gatsby-plugin/package.json b/packages/gatsby-plugin/package.json new file mode 100644 index 000000000..7310c8d35 --- /dev/null +++ b/packages/gatsby-plugin/package.json @@ -0,0 +1,21 @@ +{ + "name": "@honeybadger-io/gatsby-plugin-honeybadger", + "description": "Gatsby plugin to add Honeybadger error tracking to your site.", + "version": "0.1.3", + "homepage": "https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/gatsby-plugin", + "repository": { + "type": "git", + "url": "git@github.com:honeybadger-io/honeybadger-js.git" + }, + "keywords": [ + "gatsby", + "gatsby-plugin", + "honeybadger" + ], + "license": "MIT", + "main": "index.js", + "dependencies": { + "@honeybadger-io/webpack": "^4.3.1", + "@honeybadger-io/js": "^4.3.1" + } +}