Skip to content

Commit ddaa402

Browse files
committed
build a separate file that defines globals in the browser
This way axs can be built from npm _and_ be available to execute in the browser
1 parent d3e361c commit ddaa402

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

lib/accessibility.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const Eval = require('./eval')
22

33
exports.audit = () => {
44
return Eval.execute(function () {
5-
const {axs} = window
5+
const {axs} = window.__devtron // defined in browserGlobals.js
66
const config = new axs.AuditConfiguration({showUnsupportedRulesWarning: false})
77
const results = axs.Audit.run(config)
88

lib/browserGlobals.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This defines globals that will be used in the browser context
2+
// (via the content_scripts definition in manifest.json)
3+
//
4+
// It is generated via `npm run-script prepublish`
5+
const axs = require('accessibility-developer-tools')
6+
7+
window.__devtron = window.__devtron || {}
8+
window.__devtron.axs = axs

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"content_scripts": [
66
{
77
"matches": ["*"],
8-
"js": ["node_modules/accessibility-developer-tools/dist/js/axs_testing.js"]
8+
"js": ["out/browserGlobals.js"]
99
}
1010
]
1111
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Electron DevTools Extension",
55
"main": "./api.js",
66
"scripts": {
7-
"prepublish": "browserify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js",
7+
"prepublish": "browserify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js && browserify lib/browserGlobals.js -o out/browserGlobals.js",
88
"start": "watchify lib/*.js -o out/index.js --ignore-missing --entry lib/index.js --verbose",
99
"test": "mocha test/unit/*-test.js test/integration/*-test.js && standard"
1010
},

0 commit comments

Comments
 (0)