diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..9d02bbbc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "submodules/uBlock"] + path = submodules/uBlock + url = https://github.com/brave/uBlock diff --git a/package-lock.json b/package-lock.json index 67a0ed73..2ed8ec48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,11 +40,11 @@ } }, "adblock-rs": { - "version": "0.1.28", - "resolved": "https://registry.npmjs.org/adblock-rs/-/adblock-rs-0.1.28.tgz", - "integrity": "sha512-5Jrn+Dddj7SzwECyyxByMiNQVEgne5IG+jAep/esgZnv+Z6JwnuEeHYeh/TziOMKQNJKe2tNh6wHY6T000e9Gg==", + "version": "0.1.37", + "resolved": "https://registry.npmjs.org/adblock-rs/-/adblock-rs-0.1.37.tgz", + "integrity": "sha512-gQeelsYQSeEt5NigIhdMm2KSyASgYZfj2Y6CItRWe8awzZ9yriN7+Js91FN+30NEiAEOjQPiJiXnepvV48iwJw==", "requires": { - "neon-cli": "^0.2.0" + "neon-cli": "0.3.1" } }, "ajv": { @@ -1263,9 +1263,9 @@ "integrity": "sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==" }, "handlebars": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz", - "integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==", + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.5.1.tgz", + "integrity": "sha512-C29UoFzHe9yM61lOsIlCE5/mQVGrnIOrOq7maQl76L7tYPCgC1og0Ajt6uWnX4ZTxBPnjw+CUvawphwCfJgUnA==", "requires": { "neo-async": "^2.6.0", "optimist": "^0.6.1", @@ -1861,16 +1861,16 @@ "integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==" }, "neon-cli": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/neon-cli/-/neon-cli-0.2.0.tgz", - "integrity": "sha512-IsrxCyUcuAyWiq4Z+JnTXrjurj2SAL2VtWnCXS8iBYGJeIs1NIhFuLaM6fe7+rOyFfDcqUUTWGxZmkvUqwweRA==", + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/neon-cli/-/neon-cli-0.3.1.tgz", + "integrity": "sha512-OBrJbDD0BNDPxWwh88kWd2dJkXWEZ/mrCPF/ADrsLgHmF2qDdbXagli48I7yVl1ngMtItrvI7JqBeiNQNtN1ww==", "requires": { "chalk": "~2.1.0", "command-line-args": "^4.0.2", "command-line-commands": "^2.0.0", "command-line-usage": "^4.0.0", "git-config": "0.0.7", - "handlebars": "^4.0.3", + "handlebars": "^4.1.0", "inquirer": "^3.0.6", "mkdirp": "^0.5.1", "quickly-copy-file": "^1.0.0", @@ -3087,13 +3087,21 @@ "integrity": "sha1-XAgOXWYcu+OCWdLnCjxyU+hziB0=" }, "uglify-js": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", - "integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==", + "version": "3.6.8", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.8.tgz", + "integrity": "sha512-XhHJ3S3ZyMwP8kY1Gkugqx3CJh2C3O0y8NPiSxtm1tyD/pktLAkFZsFGpuNfTZddKDQ/bbDBLAd2YyA1pbi8HQ==", "optional": true, "requires": { - "commander": "~2.20.0", + "commander": "~2.20.3", "source-map": "~0.6.1" + }, + "dependencies": { + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "optional": true + } } }, "uniq": { diff --git a/package.json b/package.json index 30db9e91..e4be7be6 100755 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Packages component and theme extensions used in the Brave browser", "dependencies": { "ad-block": "brave/ad-block", - "adblock-rs": "^0.1.28", + "adblock-rs": "^0.1.36", "ajv": "^6.10.0", "autoplay-whitelist": "github:brave/autoplay-whitelist", "aws-sdk": "^2.449.0", diff --git a/scripts/generateAdBlockRustDataFiles.js b/scripts/generateAdBlockRustDataFiles.js index 2d3f2b95..9d2d5959 100644 --- a/scripts/generateAdBlockRustDataFiles.js +++ b/scripts/generateAdBlockRustDataFiles.js @@ -2,11 +2,34 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -const { Engine, lists } = require('adblock-rs') +const { Engine, lists, uBlockResources } = require('adblock-rs') const path = require('path') const fs = require('fs') const request = require('request') +const uBlockRevision = '978f04219a1f41f3fab7ad5c38ec2a1a021920fe' +const uBlockGitArchiveURL = `https://github.com/gorhill/uBlock/archive/${uBlockRevision}.zip` + +const uBlockLocalRoot = 'submodules/uBlock' +const uBlockWebAccessibleResources = path.join(uBlockLocalRoot, 'src/web_accessible_resources') +const uBlockRedirectEngine = path.join(uBlockLocalRoot, 'src/js/redirect-engine.js') +const uBlockScriptlets = path.join(uBlockLocalRoot, 'assets/resources/scriptlets.js') + +/** + * Returns a promise that generates a resources file from the uBlock Origin + * repo hosted on GitHub + */ +const generateResourcesFile = (uBlockArchiveZip) => { + return new Promise((resolve, reject) => { + const jsonData = JSON.stringify(uBlockResources( + uBlockWebAccessibleResources, + uBlockRedirectEngine, + uBlockScriptlets + )) + fs.writeFileSync(getOutPath('resources.json', 'default'), jsonData, 'utf8') + }) +} + /** * Returns a promise that which resolves with the list data * @@ -47,6 +70,25 @@ const getListFilterFunction = (uuid) => { return undefined } +/** + * Obtains the output path to store a file given the specied name and subdir + */ +const getOutPath = (outputFilename, outSubdir) => { + let outPath = path.join('build') + if (!fs.existsSync(outPath)) { + fs.mkdirSync(outPath) + } + outPath = path.join(outPath, 'ad-block-updater') + if (!fs.existsSync(outPath)) { + fs.mkdirSync(outPath) + } + outPath = path.join(outPath, outSubdir) + if (!fs.existsSync(outPath)) { + fs.mkdirSync(outPath) + } + return path.join(outPath, outputFilename) +} + /** * Parses the passed in filter rule data and serializes a data file to disk. * @@ -62,19 +104,8 @@ const generateDataFileFromString = (filterRuleData, outputDATFilename, outSubdir } const client = new Engine(rules.split('\n')) const arrayBuffer = client.serialize() - let outPath = path.join('build') - if (!fs.existsSync(outPath)) { - fs.mkdirSync(outPath) - } - outPath = path.join(outPath, 'ad-block-updater') - if (!fs.existsSync(outPath)) { - fs.mkdirSync(outPath) - } - outPath = path.join(outPath, outSubdir) - if (!fs.existsSync(outPath)) { - fs.mkdirSync(outPath) - } - fs.writeFileSync(path.join(outPath, outputDATFilename), Buffer.from(arrayBuffer)) + const outPath = getOutPath(outputDATFilename, outSubdir) + fs.writeFileSync(outPath, Buffer.from(arrayBuffer)) } /** @@ -121,7 +152,7 @@ const generateDataFilesForAllRegions = () => { } /** - * Convenience function that generates a DAT file for the default list + * Convenience function that generates a DAT file and resources file for the default list */ const generateDataFilesForList = (lists, filename) => { let promises = [] @@ -134,6 +165,7 @@ const generateDataFilesForList = (lists, filename) => { p = p.then((listBuffers) => { generateDataFileFromString(listBuffers, filename, 'default') }) + p = p.then(generateResourcesFile) return p } diff --git a/submodules/uBlock b/submodules/uBlock new file mode 160000 index 00000000..fcfa83df --- /dev/null +++ b/submodules/uBlock @@ -0,0 +1 @@ +Subproject commit fcfa83dfc645a28a23bf48970bbfa009bad136c9