Skip to content

Commit 40ea7b4

Browse files
authored
feat: esbuild plugin (#1318)
1 parent 3c161af commit 40ea7b4

32 files changed

+8952
-39
lines changed

.github/workflows/node.js.yml

+3-10
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
- name: Setup Node.js
7676
uses: actions/setup-node@v3
7777
with:
78-
node-version: '14.x'
78+
node-version: '18.x'
7979
cache: 'npm'
8080
cache-dependency-path: |
8181
package-lock.json
@@ -115,16 +115,9 @@ jobs:
115115
- name: Setup Node.js
116116
uses: actions/setup-node@v3
117117
with:
118-
node-version: '14.x'
118+
node-version: '18.x'
119119
cache: 'npm'
120-
cache-dependency-path: |
121-
package-lock.json
122-
packages/js/examples/aws-lambda-typescript/package-lock.json
123-
packages/vue/examples/vue2/package-lock.json
124-
packages/vue/examples/vue3/package-lock.json
125-
packages/react-native/example/package-lock.json
126-
packages/nextjs/examples/app-router/package-lock.json
127-
packages/nextjs/examples/pages-router/package-lock.json
120+
cache-dependency-path: package-lock.json
128121

129122
- name: Build
130123
run: npm ci

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ lerna-debug.log
1111
browserstack.err
1212

1313
# for use with direnv
14-
.envrc
14+
.envrc
15+
16+
.rollup.cache

packages/esbuild-plugin/MIT-LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2024 Honeybadger Industries LLC
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

packages/esbuild-plugin/README.md

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Honeybadger's esbuild Source Map Plugin
2+
3+
[esbuild](https://esbuild.github.io/) plugin to upload JavaScript
4+
source maps and optionally send deployment notifications to [Honeybadger](https://docs.honeybadger.io/lib/javascript/guides/using-source-maps/).
5+
6+
## Installation
7+
8+
```
9+
# npm
10+
npm install @honeybadger-io/esbuild-plugin --save-dev
11+
12+
# yarn
13+
yarn add @honeybadger-io/esbuild-plugin --dev
14+
```
15+
16+
17+
## Configuration
18+
19+
### Plugin parameters
20+
21+
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/).
22+
23+
<dl>
24+
<dt><code>apiKey</code> (required)</dt>
25+
<dd>The API key of your Honeybadger project</dd>
26+
27+
<dt><code>assetsUrl</code> (required)</dt>
28+
<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>
29+
30+
<dt><code>endpoint</code> (optional &mdash; default: "https://api.honeybadger.io/v1/source_maps")</dt>
31+
<dd>Where to upload your source maps to. Perhaps you have a self hosted
32+
source map server you would like to upload your source maps to instead
33+
of Honeybadger.</dd>
34+
35+
<dt><code>revision</code> (optional &mdash; default: "main")</dt>
36+
<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>
37+
38+
<dt><code>silent</code> (optional &mdash; default: false)</dt>
39+
<dd>If true, silence logging emitted by the plugin.</dd>
40+
41+
<dt><code>retries</code> (optional &mdash; default: 3, max: 10)</dt>
42+
<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.
43+
</dd>
44+
45+
<dt><code>workerCount</code> (optional &mdash; default: 5, min: 1)</dt>
46+
<dd>Source maps are uploaded in parallel by a configurable number of
47+
workers. Increase or decrease this value to configure how many source maps
48+
are being uploaded in parallel.</br>
49+
Limited parallelism helps with connection issues in Docker environments.</dd>
50+
51+
<dt><code>ignorePaths</code> (optional &mdash; default: [])</dt>
52+
<dd>An array of paths (glob patterns) to ignore when uploading source maps. Uses <a href="https://github.com/micromatch/picomatch">picomatch</a> to match against paths.
53+
</dd>
54+
55+
<dt><code>deployEndpoint</code> (optional &mdash; default: "https://api.honeybadger.io/v1/deploys")</dt>
56+
<dd>Where to send deployment notifications.</dd>
57+
58+
<dt><code>deploy</code> (optional &mdash; default: false)</dt>
59+
<dd>
60+
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 source maps (see above).
61+
62+
<dl>
63+
<dt><code>environment</code></dt>
64+
<dd>The environment name, for example, "production"</dd>
65+
<dt><code>repository</code></dt>
66+
<dd>The base URL of the VCS repository (HTTPS-style), for example, "https://github.com/yourusername/yourrepo"</dd>
67+
<dt><code>localUsername</code></dt>
68+
<dd>The name of the user that triggered this deploy, for example, "Jane"</dd>
69+
</dl>
70+
</dd>
71+
</dl>
72+
73+
### esbuild.config.js
74+
Set `sourcemap` to `true`. Add the honeybadger plugin to the plugins array.
75+
```javascript
76+
import { honeybadgerSourceMapPlugin } from '@honeybadger-io/esbuild-plugin'
77+
78+
// See plugin params above
79+
const hbPluginOptions = {
80+
apiKey: 'your_key_here',
81+
assetsUrl: 'https://yoursite.foo',
82+
revision: 'v1.0.0',
83+
}
84+
85+
esbuild
86+
.build({
87+
entryPoints: ['src/index.ts'],
88+
bundle: true,
89+
minify: true,
90+
format: 'cjs',
91+
sourcemap: true,
92+
outfile: 'dist/output.js',
93+
plugins: [honeybadgerSourceMapPlugin(hbPluginOptions)]
94+
})
95+
.then(() => {
96+
console.log('Build complete')
97+
})
98+
.catch((err) => {
99+
console.error(err)
100+
process.exit(1)
101+
});
102+
```
103+
104+
## Development
105+
106+
1. Run `npm install`
107+
2. Run the tests with `npm test`
108+
3. Build with `npm run build`
109+
110+
See the `/examples` folder for projects to test against.
111+
112+
## License
113+
114+
This package is MIT licensed. See the [MIT-LICENSE](./MIT-LICENSE) file in this folder for details.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"rules": {
3+
// Since these are just examples, the monorepo's linting should not
4+
// fail just because we didn't run `npm install` in the example folders
5+
"import/no-unresolved": ["off"]
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as esbuild from 'esbuild'
2+
import { honeybadgerSourceMapPlugin } from '../../dist/index.js'
3+
4+
const hbOptions = {
5+
apiKey: process.env.HONEYBADGER_API_KEY,
6+
assetsUrl: 'https://example.com/public',
7+
revision: 'esbuild-plugin-react-ssr-example',
8+
}
9+
10+
await esbuild.build({
11+
entryPoints: ['src/app.jsx'],
12+
bundle: true,
13+
minify: true,
14+
sourcemap: true,
15+
target: ['chrome58', 'firefox57', 'safari11', 'edge16'],
16+
outfile: 'dist/out.js',
17+
plugins: [honeybadgerSourceMapPlugin(hbOptions)]
18+
})

0 commit comments

Comments
 (0)