Skip to content

Commit

Permalink
automate update browsers default scope [wip] sindresorhus#164 sindres…
Browse files Browse the repository at this point in the history
  • Loading branch information
shapkarin committed Jul 6, 2020
1 parent 64a645b commit aad6d7a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava",
"get-jshint-browser": "node ./update/get-browser-globals/jshint.js",
"combine-jshint-browser": "node ./update/get-browser-globals/combine.js"
},
"files": [
"index.js",
Expand Down
68 changes: 68 additions & 0 deletions update/get-browser-globals/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

const blacklist = [
/^webkit/i,
'BeforeInstallPromptEvent',
/^Bluetooth/,
'CDATASection',
'captureEvents',
'InputDeviceCapabilities',
'releaseEvents',
'SyncManager',
/^USB/,

// DevTools globals
'chrome',
'$_',
'$0',
'$1',
'$2',
'$3',
'$4',
'$',
'$$',
'$x',
'clear',
'copy',
'debug',
'dir',
'dirxml',
'getEventListeners',
'inspect',
'keys',
'monitor',
'monitorEvents',
'profile',
'profileEnd',
'queryObjects',
'table',
'undebug',
'unmonitor',
'unmonitorEvents',
'values'
];

const globals = Object.getOwnPropertyNames(window)
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
.filter(global => {
for (const pattern of blacklist) {
if (typeof pattern === 'string') {
if (global === pattern) {
return false;
}
} else {
if (pattern.test(global)) {
return false;
}
}
}

return true;
});

const ret = {};
for (const key of globals) {
ret[key] = key.startsWith('on');
}

copy(JSON.stringify(ret, null, '\t'));
7 changes: 7 additions & 0 deletions update/get-browser-globals/combine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const fs = require('fs');

const file = fs.readFileSync('./browser_vars.json');

console.log(file);
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,4 @@ for (const key of globals) {
ret[key] = key.startsWith('on');
}

fs.writeFile('./browser_vars.json', JSON.stringify(ret, null, '\t'), (error) => {
if (error) {
return console.log(error);
}
});
fs.writeFileSync('./browser_vars.json', `{ "jshint": \n\t${JSON.stringify(ret, null, '\t\t')}}`);
6 changes: 6 additions & 0 deletions update/get-browser-globals/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Usage
- Run `npm run get-jshint-browser'
- Open an Incognito window in Chrome Canary and paste the above into the console.
You'll now have a new object in your clipboard for the `browser` field in `globals.json`.
- You still need to manually filter out items from the `builtin` list.
- Paste the reult to the `globals.json` to the `browser` section.

0 comments on commit aad6d7a

Please sign in to comment.