Skip to content

Commit

Permalink
Replace Browserify with ES modules
Browse files Browse the repository at this point in the history
bouncer has only a small amount of JavaScript and used Browserify purely
as a module system provider. With our currently supported browsers and
current version of Karma we can just use native ES modules instead.
Removing Browserify usage will allow us to trim the project's
dependencies.

 - Convert `redirect.js` and `redirect-test.js` to ES modules

 - Update Karma configuration to load JS files as modules and remove
   Browserify usage
  • Loading branch information
robertknight committed Oct 5, 2021
1 parent 3b8c1f2 commit 6d9c598
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "hypothesis"
"extends": "hypothesis",
"parserOptions": {
"sourceType": "module"
}
}
11 changes: 2 additions & 9 deletions bouncer/scripts/redirect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

/**
* Configuration information for the client-side code that detects the best way
* to route the user to a URL with Hypothesis activated and specified
Expand Down Expand Up @@ -43,7 +41,7 @@ function defaultNavigateTo(url) {
* @param {(url: string) => void} [navigateTo]
* @param {Settings} [settings]
*/
function redirect(navigateTo, settings) {
export function redirect(navigateTo, settings) {
navigateTo = navigateTo || defaultNavigateTo; // Test seam
settings = settings || getSettings(document); // Test seam

Expand Down Expand Up @@ -84,11 +82,6 @@ function redirect(navigateTo, settings) {
}
}

if (typeof module === 'object') {
// Browserify is present, this file must be being run by the tests.
module.exports = redirect;
} else {
// Browserify is not present, this file must be being run in development or
// production.
if (!('__karma__' in window)) { // Check if in test environment
redirect();
}
4 changes: 1 addition & 3 deletions bouncer/scripts/test/redirect-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

var redirect = require('../redirect.js');
import { redirect } from '../redirect.js';

describe('#redirect', function () {
var settings;
Expand Down
2 changes: 1 addition & 1 deletion bouncer/templates/annotation.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<script class="js-bouncer-settings" type="application/json">
{{ data | safe }}
</script>
<script>
<script type="module">
{% include '../scripts/redirect.js' %}
</script>
{% endblock %}
11 changes: 3 additions & 8 deletions karma.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
module.exports = function (config) {
config.set({
browserify: {
debug: true
},
basePath: '',
frameworks: ['browserify', 'chai', 'mocha', 'sinon'],
frameworks: ['chai', 'mocha', 'sinon'],
files: [
'bouncer/**/*-test.js'
{ pattern: 'bouncer/scripts/*.js', type: 'module', included: false },
{ pattern: 'bouncer/**/*-test.js', type: 'module' },
],
preprocessors: {
'**/*-test.js': ['browserify']
},
reporters: ['progress'],
port: 9876,
colors: true,
Expand Down

0 comments on commit 6d9c598

Please sign in to comment.