diff --git a/data/build.js b/data/build.js index 7fbeb77..ce9799a 100644 --- a/data/build.js +++ b/data/build.js @@ -5,8 +5,8 @@ // const Fs = require('fs'); const Path = require('path'); +const { Transform } = require('stream'); const Request = require('request'); -const EventStream = require('event-stream'); const JSONStream = require('JSONStream'); @@ -23,51 +23,72 @@ internals.dest = Path.join(__dirname, 'rules.json'); // // Parse line (trim and ignore empty lines and comments). // -internals.parseLine = function (line, cb) { +internals.parseLine = function (line) { const trimmed = line.trim(); // Ignore empty lines and comments. if (!trimmed || (trimmed.charAt(0) === '/' && trimmed.charAt(1) === '/')) { - return cb(); + return; } // Only read up to first whitespace char. const rule = trimmed.split(' ')[0]; - return cb(null, rule); + return rule; + + // const item = [rule]; + // + // const suffix = rule.replace(/^(\*\.|\!)/, ''); + // const wildcard = rule.charAt(0) === '*'; + // const exception = rule.charAt(0) === '!'; + // + // // If rule has no wildcard or exception we can get away with only one + // // element in the `item` array. + // if (suffix === rule && !wildcard && !exception) { + // return cb(null, item); + // } + // + // item.push(suffix); + // + // if (wildcard) { + // item.push(true); + // } + // + // if (exception) { + // item.push(true); + // } + // + // cb(null, item); +}; - const item = [rule]; - const suffix = rule.replace(/^(\*\.|\!)/, ''); - const wildcard = rule.charAt(0) === '*'; - const exception = rule.charAt(0) === '!'; +internals.parse = new Transform({ + objectMode: true, + transform(chunk, encoding, cb) { + if (this._last === undefined) { + this._last = ''; + } - // If rule has no wildcard or exception we can get away with only one - // element in the `item` array. - if (suffix === rule && !wildcard && !exception) { - return cb(null, item); - } + this._last += `${chunk}`; + const list = this._last.split(/\n/); + this._last = list.pop(); - item.push(suffix); + for (let i = 0; i < list.length; i++) { + const parsed = internals.parseLine(list[i]); + if (parsed) { + this.push(parsed); + } + } - if (wildcard) { - item.push(true); + cb(); } - - if (exception) { - item.push(true); - } - - cb(null, item); -}; +}); // // Download rules and create rules.json file. // Request(internals.src) - .pipe(EventStream.split()) - .pipe(EventStream.map(internals.parseLine)) + .pipe(internals.parse) .pipe(JSONStream.stringify('[', ',', ']')) .pipe(Fs.createWriteStream(internals.dest)); - diff --git a/package.json b/package.json index 874dc2a..56b13f2 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "eslint": "^5.10.0", "eslint-config-hapi": "^12.0.0", "eslint-plugin-hapi": "^4.1.0", - "event-stream": "3.3.4", "karma": "^3.1.3", "karma-browserify": "^6.0.0", "karma-mocha": "^1.3.0", diff --git a/yarn.lock b/yarn.lock index 05a8774..9837905 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1107,10 +1107,6 @@ duplexer2@^0.1.2, duplexer2@~0.1.0, duplexer2@~0.1.2: dependencies: readable-stream "^2.0.2" -duplexer@~0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1" - ecc-jsbn@~0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505" @@ -1297,19 +1293,6 @@ esutils@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" -event-stream@3.3.4: - version "3.3.4" - resolved "https://registry.yarnpkg.com/event-stream/-/event-stream-3.3.4.tgz#4ab4c9a0f5a54db9338b4c34d86bfce8f4b35571" - integrity sha1-SrTJoPWlTbkzi0w02Gv86PSzVXE= - dependencies: - duplexer "~0.1.1" - from "~0" - map-stream "~0.1.0" - pause-stream "0.0.11" - split "0.3" - stream-combiner "~0.0.4" - through "~2.3.1" - eventemitter3@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.0.tgz#090b4d6cdbd645ed10bf750d4b5407942d7ba163" @@ -1558,11 +1541,6 @@ fragment-cache@^0.2.1: dependencies: map-cache "^0.2.2" -from@~0: - version "0.1.7" - resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe" - integrity sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4= - fs-extra@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-1.0.0.tgz#cd3ce5f7e7cb6145883fcae3191e9877f8587950" @@ -2392,11 +2370,6 @@ map-cache@^0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf" -map-stream@~0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.1.0.tgz#e56aa94c4c8055a16404a0674b78f215f7c8e194" - integrity sha1-5WqpTEyAVaFkBKBnS3jyFffI4ZQ= - map-visit@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/map-visit/-/map-visit-1.0.0.tgz#ecdca8f13144e660f1b5bd41f12f3479d98dfb8f" @@ -2892,13 +2865,6 @@ path-platform@~0.11.15: version "0.11.15" resolved "https://registry.yarnpkg.com/path-platform/-/path-platform-0.11.15.tgz#e864217f74c36850f0852b78dc7bf7d4a5721bf2" -pause-stream@0.0.11: - version "0.0.11" - resolved "https://registry.yarnpkg.com/pause-stream/-/pause-stream-0.0.11.tgz#fe5a34b0cbce12b5aa6a2b403ee2e73b602f1445" - integrity sha1-/lo0sMvOErWqaitAPuLnO2AvFEU= - dependencies: - through "~2.3" - pbkdf2@^3.0.3: version "3.0.16" resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.16.tgz#7404208ec6b01b62d85bf83853a8064f8d9c2a5c" @@ -3483,13 +3449,6 @@ split-string@^3.0.1, split-string@^3.0.2: dependencies: extend-shallow "^3.0.0" -split@0.3: - version "0.3.3" - resolved "https://registry.yarnpkg.com/split/-/split-0.3.3.tgz#cd0eea5e63a211dfff7eb0f091c4133e2d0dd28f" - integrity sha1-zQ7qXmOiEd//frDwkcQTPi0N0o8= - dependencies: - through "2" - sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" @@ -3537,13 +3496,6 @@ stream-combiner2@^1.1.1: duplexer2 "~0.1.0" readable-stream "^2.0.2" -stream-combiner@~0.0.4: - version "0.0.4" - resolved "https://registry.yarnpkg.com/stream-combiner/-/stream-combiner-0.0.4.tgz#4d5e433c185261dde623ca3f44c586bcf5c4ad14" - integrity sha1-TV5DPBhSYd3mI8o/RMWGvPXErRQ= - dependencies: - duplexer "~0.1.1" - stream-http@^2.0.0: version "2.8.1" resolved "https://registry.yarnpkg.com/stream-http/-/stream-http-2.8.1.tgz#d0441be1a457a73a733a8a7b53570bebd9ef66a4" @@ -3673,7 +3625,7 @@ through2@^2.0.0: readable-stream "^2.1.5" xtend "~4.0.1" -through@2, "through@>=2.2.7 <3", through@^2.3.6, through@~2.3, through@~2.3.1: +"through@>=2.2.7 <3", through@^2.3.6: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"