-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: esbuild plugin #1318
feat: esbuild plugin #1318
Changes from 9 commits
c4868a2
d1023fd
b08ae65
37df864
5cd9086
a4a9c20
4080d2f
8d0b3e9
169300f
faa291b
f712187
b83510b
4b47b08
0dc75cb
b93e949
e59cfad
929c0fa
0c9e3e5
f976c10
ca663d9
c22561f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2024 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Honeybadger's esbuild Source Map Plugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of this is a copy-paste from the Rollup README. |
||
|
||
[esbuild](https://esbuild.github.io/) plugin to upload JavaScript | ||
sourcemaps and optionally send deployment notifications to [Honeybadger](https://docs.honeybadger.io/lib/javascript/guides/using-source-maps/). | ||
subzero10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Installation | ||
|
||
``` | ||
# npm | ||
npm install @honeybadger-io/esbuild-plugin --save-dev | ||
|
||
# yarn | ||
yarn add @honeybadger-io/esbuild-plugin --dev | ||
``` | ||
|
||
|
||
## Configuration | ||
|
||
### Plugin parameters | ||
|
||
These plugin parameters correspond to the Honeybadger [Source Map Upload API](https://docs.honeybadger.io/api/reporting-source-maps/) and [Deployments API](https://docs.honeybadger.io/api/reporting-deployments/). | ||
|
||
<dl> | ||
<dt><code>apiKey</code> (required)</dt> | ||
<dd>The API key of your Honeybadger project</dd> | ||
|
||
<dt><code>assetsUrl</code> (required)</dt> | ||
<dd>The base URL to production assets (scheme://host/path)<code>*</code><a href="https://docs.honeybadger.io/api/reporting-source-maps/#wildcards">wildcards</a> are supported. The plugin combines <code>assetsUrl</code> with the generated minified js file name to build the API parameter <code>minified_url</code></dd> | ||
|
||
<dt><code>endpoint</code> (optional — default: "https://api.honeybadger.io/v1/source_maps")</dt> | ||
<dd>Where to upload your sourcemaps to. Perhaps you have a self hosted | ||
sourcemap server you would like to upload your sourcemaps to instead | ||
of Honeybadger.</dd> | ||
|
||
<dt><code>revision</code> (optional — default: "main")</dt> | ||
<dd>The deploy revision (i.e. commit hash) that your source map applies to. This could also be a code version. For best results, set it to something unique every time your code changes. <a href="https://docs.honeybadger.io/lib/javascript/guides/using-source-maps.html#versioning-your-project">See the Honeybadger docs for examples</a>.</dd> | ||
|
||
<dt><code>silent</code> (optional — default: false)</dt> | ||
<dd>If true, silence logging emitted by the plugin.</dd> | ||
|
||
<dt><code>retries</code> (optional — default: 3, max: 10)</dt> | ||
<dd>This package implements fetch retry functionality via the <a href="https://github.com/vercel/fetch-retry">fetch-retry</a> package. Retrying helps fix issues like `ECONNRESET` and `SOCKETTIMEOUT` errors. | ||
</dd> | ||
|
||
<dt><code>workerCount</code> (optional — default: 5, min: 1)</dt> | ||
<dd>Sourcemaps are uploaded in parallel by a configurable number of | ||
workers. Increase or decrease this value to configure how many sourcemaps | ||
are being uploaded in parallel.</br> | ||
Limited parallelism helps with connection issues in Docker environments.</dd> | ||
|
||
<dt><code>ignorePaths</code> (optional — default: [])</dt> | ||
<dd>An array of paths (glob patterns) to ignore when uploading sourcemaps. Uses <a href="https://github.com/micromatch/picomatch">picomatch</a> to match against paths. | ||
</dd> | ||
|
||
<dt><code>deployEndpoint</code> (optional — default: "https://api.honeybadger.io/v1/deploys")</dt> | ||
<dd>Where to send deployment notifications.</dd> | ||
|
||
<dt><code>deploy</code> (optional — default: false)</dt> | ||
<dd> | ||
Configuration for <a href="https://docs.honeybadger.io/api/reporting-deployments/">deployment notifications</a>. To disable deployment notifications, ignore this option. To enable deployment notifications, set this to <code>true</code>, or to an object containing any of the fields below. Your deploy's <code>revision</code> will be set to the same value as for your sourcemaps (see above). | ||
|
||
<dl> | ||
<dt><code>environment</code></dt> | ||
<dd>The environment name, for example, "production"</dd> | ||
<dt><code>repository</code></dt> | ||
<dd>The base URL of the VCS repository (HTTPS-style), for example, "https://github.com/yourusername/yourrepo"</dd> | ||
<dt><code>localUsername</code></dt> | ||
<dd>The name of the user that triggered this deploy, for example, "Jane"</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
|
||
### esbuild.config.js | ||
Set `sourcemap` to `true`. Add the honeybadger plugin to the plugins array. | ||
```javascript | ||
import { honeybadgerSourceMapPlugin } from '@honeybadger-io/esbuild-plugin' | ||
|
||
// See plugin params above | ||
const hbPluginOptions = { | ||
apiKey: 'your_key_here', | ||
assetsUrl: 'https://yoursite.foo' | ||
} | ||
|
||
esbuild | ||
.build({ | ||
entryPoints: ['src/index.ts'], | ||
bundle: true, | ||
minify: true, | ||
format: 'cjs', | ||
sourcemap: true, | ||
outfile: 'dist/output.js', | ||
plugins: [honeybadgerSourceMapPlugin(hbOptions)] | ||
subzero10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
.then(() => { | ||
console.log('Build complete') | ||
}) | ||
.catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}); | ||
``` | ||
|
||
## Development | ||
|
||
1. Run `npm install` | ||
2. Run the tests with `npm test` | ||
3. Build with `npm run build` | ||
|
||
See the `/examples` folder for projects to test against. | ||
|
||
## License | ||
|
||
This package is MIT licensed. See the [MIT-LICENSE](./MIT-LICENSE) file in this folder for details. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are not installing deps in example apps, we need this eslint configuration to ignore the dependency not found error. |
||
"rules": { | ||
// Since these are just examples, the monorepo's linting should not | ||
// fail just because we didn't run `npm install` in the example folders | ||
"import/no-unresolved": ["off"] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as esbuild from 'esbuild' | ||
import { honeybadgerSourceMapPlugin } from '../../dist/index.js' | ||
|
||
const hbOptions = { | ||
apiKey: process.env.HONEYBADGER_API_KEY, | ||
assetsUrl: 'https://example.com/public', | ||
revision: 'esbuild-plugin-react-ssr-example', | ||
} | ||
|
||
await esbuild.build({ | ||
entryPoints: ['src/app.jsx'], | ||
bundle: true, | ||
minify: true, | ||
sourcemap: true, | ||
target: ['chrome58', 'firefox57', 'safari11', 'edge16'], | ||
outfile: 'dist/out.js', | ||
plugins: [honeybadgerSourceMapPlugin(hbOptions)] | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't necessary anymore since we aren't installing packages in the example folders.