-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DEBUG=1 flag #2156
Add DEBUG=1 flag #2156
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ const requests = require('./requests.json'); | |
const ENGINE = process.argv[2]; | ||
const FLAGS = process.argv.slice(3).filter(arg => arg.startsWith('--')); | ||
|
||
const DEBUG = FLAGS.includes('--debug'); | ||
const HOSTS_ONLY = FLAGS.includes('--hosts-only'); | ||
|
||
// Mute info-level output from uBlock Origin | ||
|
@@ -127,6 +128,39 @@ async function memoryUsage(base = { heapUsed: 0, heapTotal: 0, }) { | |
return ({ heapUsed, heapTotal, }); | ||
} | ||
|
||
async function debug(moduleId, rawLists) { | ||
const output = []; | ||
|
||
const Cls = require(moduleId); | ||
|
||
if (Cls.initialize) { | ||
await Cls.initialize({ hostsOnly: HOSTS_ONLY }); | ||
} | ||
|
||
const engine = await Cls.parse(rawLists); | ||
|
||
for (let index = 0; index < requests.length; index += 1) { | ||
const { url, frameUrl, cpt } = requests[index]; | ||
|
||
if (!isSupportedUrl(url) || !isSupportedUrl(frameUrl)) { | ||
continue; | ||
} | ||
|
||
const match = engine.match({ type: WEBREQUEST_OPTIONS[cpt], frameUrl, url }); | ||
|
||
let matchDebug = null; | ||
if (engine.matchDebug) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the engine does not implement |
||
matchDebug = engine.matchDebug({ type: WEBREQUEST_OPTIONS[cpt], frameUrl, url }); | ||
} | ||
|
||
output.push({ index, url, frameUrl, cpt, match, matchDebug }); | ||
} | ||
|
||
fs.writeFileSync(`./${ENGINE}.debug.json`, JSON.stringify(output, null, 2)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Output is pretty so it can be used with tools like |
||
|
||
console.log(`./${ENGINE}.debug.json`); | ||
} | ||
|
||
async function main() { | ||
const rawLists = loadLists(); | ||
|
||
|
@@ -176,6 +210,10 @@ async function main() { | |
process.exit(1); | ||
} | ||
|
||
if (DEBUG) { | ||
return debug(moduleId, rawLists); | ||
} | ||
|
||
const baseMemory = await memoryUsage(); | ||
|
||
// Initialize | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that
matchDebug()
returns something more useful than just a boolean value. In both the cases here (adblockplus and tsurlfilter) it returns the filter text.