From aad6d7a8e565d22229c68999ca15b86d0343120e Mon Sep 17 00:00:00 2001 From: Yury Shapkarin Date: Mon, 6 Jul 2020 03:57:12 +0300 Subject: [PATCH] automate update browsers default scope [wip] #164 #166 --- package.json | 4 +- update/get-browser-globals/browser.js | 68 +++++++++++++++++++ update/get-browser-globals/combine.js | 7 ++ .../get-browser-globals/jshint.js | 6 +- update/get-browser-globals/readme.md | 6 ++ 5 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 update/get-browser-globals/browser.js create mode 100644 update/get-browser-globals/combine.js rename get-browser-globals.js => update/get-browser-globals/jshint.js (88%) create mode 100644 update/get-browser-globals/readme.md diff --git a/package.json b/package.json index 5ad1fc7..cec5dac 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/update/get-browser-globals/browser.js b/update/get-browser-globals/browser.js new file mode 100644 index 0000000..18fdd5b --- /dev/null +++ b/update/get-browser-globals/browser.js @@ -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')); diff --git a/update/get-browser-globals/combine.js b/update/get-browser-globals/combine.js new file mode 100644 index 0000000..e66ebe7 --- /dev/null +++ b/update/get-browser-globals/combine.js @@ -0,0 +1,7 @@ +'use strict'; + +const fs = require('fs'); + +const file = fs.readFileSync('./browser_vars.json'); + +console.log(file); diff --git a/get-browser-globals.js b/update/get-browser-globals/jshint.js similarity index 88% rename from get-browser-globals.js rename to update/get-browser-globals/jshint.js index 9fd6dfa..d106546 100644 --- a/get-browser-globals.js +++ b/update/get-browser-globals/jshint.js @@ -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')}}`); diff --git a/update/get-browser-globals/readme.md b/update/get-browser-globals/readme.md new file mode 100644 index 0000000..c072f60 --- /dev/null +++ b/update/get-browser-globals/readme.md @@ -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.