Skip to content

Commit

Permalink
build a separate file that defines globals in the browser
Browse files Browse the repository at this point in the history
This way axs can be built from npm _and_ be available to execute in the
browser
  • Loading branch information
philschatz committed Sep 28, 2016
1 parent d3e361c commit ddaa402
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Eval = require('./eval')

exports.audit = () => {
return Eval.execute(function () {
const {axs} = window
const {axs} = window.__devtron // defined in browserGlobals.js
const config = new axs.AuditConfiguration({showUnsupportedRulesWarning: false})
const results = axs.Audit.run(config)

Expand Down
8 changes: 8 additions & 0 deletions lib/browserGlobals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This defines globals that will be used in the browser context
// (via the content_scripts definition in manifest.json)
//
// It is generated via `npm run-script prepublish`
const axs = require('accessibility-developer-tools')

window.__devtron = window.__devtron || {}
window.__devtron.axs = axs
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"content_scripts": [
{
"matches": ["*"],
"js": ["node_modules/accessibility-developer-tools/dist/js/axs_testing.js"]
"js": ["out/browserGlobals.js"]
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Electron DevTools Extension",
"main": "./api.js",
"scripts": {
"prepublish": "browserify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js",
"prepublish": "browserify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js && browserify lib/browserGlobals.js -o out/browserGlobals.js",
"start": "watchify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js --verbose",
"test": "mocha test/unit/*-test.js test/integration/*-test.js && standard"
},
Expand Down

0 comments on commit ddaa402

Please sign in to comment.