Skip to content

Commit

Permalink
fix: ensure that including dist/opossum.js works (#341)
Browse files Browse the repository at this point in the history
The node-specific webpack configuration was overwriting the
config for the browser. Thus the distribution had a non-browser
capable implementation that required some work on the user's
part to get working in the browser. The user's webpack.config
required an external declaration for `prom-client`. For example:
lance/elizabethan-insults@ebabdf3#diff-23fce1009af5652674e09470cda3c008R9

Fixes: #338
  • Loading branch information
lance committed Jun 21, 2019
1 parent bd008ad commit 873deb5
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 74 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Click the 'Pull Request' button and fill out the form.

These are mostly notes for myself.

* Be sure you are starting from a clean slate: `npm clean && npm install`
* Be sure you are starting from a clean slate: `npm run clean && npm install`
* Run standard-version: `npm run release` - this will run the `ci` task
* Push to GitHub: `git push --follow-tags origin master`
* Publish to npmjs.com: `npm publish`
Expand Down
66 changes: 0 additions & 66 deletions config/webpack.browser.config.js

This file was deleted.

33 changes: 32 additions & 1 deletion config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,35 @@ const webpack = require('webpack');
const configs = ['opossum', 'opossum.min']
.map(key => generateConfig(key));

// add a webpack for tests
configs.push({
target: 'web',
mode: 'development',
entry: './test/browser/index.js',
node: {
fs: 'empty'
},
output: {
path: path.resolve(__dirname, '..', 'test', 'browser'),
filename: 'webpack-test.js'
},
resolve: {
modules: ['node_modules'],
extensions: ['*', '.js']
},
plugins: [
new webpack.IgnorePlugin(/prom-client/),
new webpack.DefinePlugin({
'process.env': {
WEB: JSON.stringify('web')
}
})
]
});

function generateConfig (name) {
const mode = name.indexOf('min') > -1 ? 'production' : 'development';
const config = {
target: 'node',
mode,
entry: {
circuitBreaker: './index.js'
Expand All @@ -23,8 +48,14 @@ function generateConfig (name) {
console: true
},
plugins: [
new webpack.IgnorePlugin(/prom-client/),
new webpack.ProvidePlugin({
'circuitBreaker': 'opossum'
}),
new webpack.DefinePlugin({
'process.env': {
WEB: JSON.stringify('web')
}
})
],
devtool: 'source-map'
Expand Down
21 changes: 19 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset='utf-8' />
<title>opossum 2.0.0 | Documentation</title>
<title>opossum 2.1.0 | Documentation</title>
<meta name='description' content='A fail-fast circuit breaker for promises and callbacks'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' rel='stylesheet' />
Expand All @@ -15,7 +15,7 @@
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>opossum</h3>
<div class='mb1'><code>2.0.0</code></div>
<div class='mb1'><code>2.1.0</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down Expand Up @@ -681,6 +681,23 @@ <h4>Prometheus</h4>
res.type(<span class="hljs-string">'text/plain'</span>);
res.send(opossum.metrics());
});</pre>
<p>The <code>prometheusRegistry</code> option allows to provide a existing
<a href="https://github.com/siimon/prom-client">prom-client</a> registry.
The metrics about the circuit will be added to the provided registry instead
of the global registry.
The <a href="https://github.com/siimon/prom-client#default-metrics">default metrics</a>
will not be added to the provided registry.</p>
<pre class='hljs'><span class="hljs-keyword">const</span> opossum = <span class="hljs-built_in">require</span>(<span class="hljs-string">'opossum'</span>);
<span class="hljs-keyword">const</span> { Registry } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'prom-client'</span>);

<span class="hljs-comment">// Create a registry</span>
<span class="hljs-keyword">const</span> prometheusRegistry = <span class="hljs-keyword">new</span> Registry();

<span class="hljs-comment">// create a circuit</span>
<span class="hljs-keyword">const</span> circuit = opossum(functionThatMightFail, {
<span class="hljs-attr">usePrometheus</span>: <span class="hljs-literal">true</span>,
prometheusRegistry
});</pre>
<h4>Hystrix</h4>
<p><strong>NOTE: Hystrix metrics are deprecated</strong></p>
<p>A Hystrix Stream is available for use with a Hystrix Dashboard using the <code>circuitBreaker.hystrixStats.getHystrixStream</code> method.</p>
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
},
"scripts": {
"prebuild": "npm run lint",
"build": "npm run build:browser && npm run build:node && npm run build:docs",
"build:node": "webpack --config=config/webpack.config.js",
"build:browser": "webpack --config=config/webpack.browser.config.js",
"build": "./test/browser/generate-index.sh && npm run build:browser && npm run build:docs",
"build:browser": "webpack --config=config/webpack.config.js",
"build:docs": "npm run build:docs:html && npm run build:docs:markdown",
"build:docs:html": "documentation build index.js -f html -o docs --config documentation.yml",
"build:docs:markdown": "documentation build index.js -f md -o docs/opossum.md",
Expand Down
4 changes: 3 additions & 1 deletion test/browser/generate-index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

echo $PWD

file_list=$(ls -1 test/*.js)
cd test
file_list=$(ls -1 --ignore="*prometheus*" | grep .js)
cd ..
requires=""

for f in $file_list ; do
Expand Down
1 change: 1 addition & 0 deletions test/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require('../enable-disable-test.js');
require('../error-filter-test.js');
require('../half-open-test.js');
require('../health-check-test.js');
require('../hystrix-order-test.js');
require('../hystrix-test.js');
require('../semaphore-test.js');
require('../test.js');
Expand Down

0 comments on commit 873deb5

Please sign in to comment.