@adguard/hostlist-compiler 1.0.19 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +27 -0
- package/bamboo-specs/build.yaml +1 -2
- package/bamboo-specs/deploy.yaml +1 -2
- package/bamboo-specs/test.yaml +1 -2
- package/jest.config.js +1 -0
- package/package.json +7 -6
- package/src/cli.js +1 -1
- package/src/rule.js +1 -0
- package/src/transformations/remove-modifiers.js +2 -1
- package/src/transformations/transform.js +10 -4
- package/src/transformations/validate.js +1 -0
- package/test/transformations/exclude.test.js +5 -2
- package/test/transformations/remove-modifiers.test.js +19 -12
- package/test/transformations/validate.test.js +4 -0
- package/.eslintrc +0 -16
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: [
|
|
3
|
+
'airbnb-base',
|
|
4
|
+
],
|
|
5
|
+
parser: '@babel/eslint-parser',
|
|
6
|
+
parserOptions: {
|
|
7
|
+
requireConfigFile: false,
|
|
8
|
+
},
|
|
9
|
+
env: {
|
|
10
|
+
browser: false,
|
|
11
|
+
node: true,
|
|
12
|
+
jest: true,
|
|
13
|
+
},
|
|
14
|
+
rules: {
|
|
15
|
+
'max-len': [
|
|
16
|
+
'error',
|
|
17
|
+
{
|
|
18
|
+
code: 120,
|
|
19
|
+
ignoreUrls: true,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
indent: ['error', 4, { SwitchCase: 1 }],
|
|
23
|
+
'import/prefer-default-export': 'off',
|
|
24
|
+
'arrow-body-style': 'off',
|
|
25
|
+
'import/no-extraneous-dependencies': 'off',
|
|
26
|
+
},
|
|
27
|
+
};
|
package/bamboo-specs/build.yaml
CHANGED
|
@@ -92,8 +92,7 @@ notifications:
|
|
|
92
92
|
recipients:
|
|
93
93
|
- webhook:
|
|
94
94
|
name: Build webhook
|
|
95
|
-
|
|
96
|
-
url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo?channel=adguard-qa
|
|
95
|
+
url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo
|
|
97
96
|
|
|
98
97
|
labels: []
|
|
99
98
|
|
package/bamboo-specs/deploy.yaml
CHANGED
package/bamboo-specs/test.yaml
CHANGED
|
@@ -57,8 +57,7 @@ notifications:
|
|
|
57
57
|
recipients:
|
|
58
58
|
- webhook:
|
|
59
59
|
name: Build webhook
|
|
60
|
-
|
|
61
|
-
url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo?channel=adguard-qa
|
|
60
|
+
url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo
|
|
62
61
|
|
|
63
62
|
labels: []
|
|
64
63
|
other:
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adguard/hostlist-compiler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"description": "A simple tool that compiles hosts blocklists from multiple sources",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -12,16 +12,17 @@
|
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"lint": "eslint . --cache",
|
|
15
|
-
"test": "jest --runInBand .",
|
|
15
|
+
"test": "jest --runInBand --detectOpenHandles .",
|
|
16
16
|
"increment": "yarn version --patch --no-git-tag-version",
|
|
17
17
|
"build-txt": "node tools/build-txt.js",
|
|
18
18
|
"compile": "node src/cli.js"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"babel
|
|
22
|
-
"eslint": "^
|
|
23
|
-
"eslint
|
|
24
|
-
"eslint-
|
|
21
|
+
"@babel/core": "^7.21.0",
|
|
22
|
+
"@babel/eslint-parser": "^7.19.1",
|
|
23
|
+
"eslint": "^8.34.0",
|
|
24
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
25
|
+
"eslint-plugin-import": "^2.27.5",
|
|
25
26
|
"jest": "^25.1.0",
|
|
26
27
|
"mock-fs": "^4.11.0",
|
|
27
28
|
"nock": "^12.0.2"
|
package/src/cli.js
CHANGED
|
@@ -26,6 +26,7 @@ const { argv } = require('yargs')
|
|
|
26
26
|
alias: 'i',
|
|
27
27
|
array: true,
|
|
28
28
|
type: 'string',
|
|
29
|
+
// eslint-disable-next-line max-len
|
|
29
30
|
description: 'URL (or path to a file) to convert to an AdGuard-syntax blocklist. Can be specified multiple times.',
|
|
30
31
|
})
|
|
31
32
|
.option('input-type', {
|
|
@@ -128,4 +129,3 @@ async function main() {
|
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
main();
|
|
131
|
-
return 0;
|
package/src/rule.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
2
|
const utils = require('./utils');
|
|
3
3
|
|
|
4
|
+
// eslint-disable-next-line max-len
|
|
4
5
|
const domainRegex = /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/;
|
|
5
6
|
const etcHostsRegex = /^([a-f0-9.:\][]+)(%[a-z0-9]+)?\s+([^#]+)(#.*)?$/;
|
|
6
7
|
|
|
@@ -13,7 +13,8 @@ function removeModifiers(rules) {
|
|
|
13
13
|
const filtered = [];
|
|
14
14
|
|
|
15
15
|
let modifiedCount = 0;
|
|
16
|
-
rules.forEach((
|
|
16
|
+
rules.forEach((rawRuleText) => {
|
|
17
|
+
const ruleText = rawRuleText.trim();
|
|
17
18
|
if (_.isEmpty(ruleText) || ruleUtils.isComment(ruleText)) {
|
|
18
19
|
filtered.push(ruleText);
|
|
19
20
|
return;
|
|
@@ -42,10 +42,16 @@ async function transform(rules, configuration, transformations) {
|
|
|
42
42
|
|
|
43
43
|
let transformed = rules;
|
|
44
44
|
|
|
45
|
-
transformed = await exclude(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
configuration.
|
|
45
|
+
transformed = await exclude(
|
|
46
|
+
transformed,
|
|
47
|
+
configuration.exclusions,
|
|
48
|
+
configuration.exclusions_sources,
|
|
49
|
+
);
|
|
50
|
+
transformed = await include(
|
|
51
|
+
transformed,
|
|
52
|
+
configuration.inclusions,
|
|
53
|
+
configuration.inclusions_sources,
|
|
54
|
+
);
|
|
49
55
|
|
|
50
56
|
if (transformations.indexOf(TRANSFORMATIONS.TrimLines) !== -1) {
|
|
51
57
|
transformed = trimLines(transformed);
|
|
@@ -33,8 +33,11 @@ describe('Exclusions', () => {
|
|
|
33
33
|
const rules = ['rule1', 'rule2', 'rule3', 'rule4', 'rule5', ''];
|
|
34
34
|
|
|
35
35
|
// Exclude!
|
|
36
|
-
const filtered = await exclude(
|
|
37
|
-
|
|
36
|
+
const filtered = await exclude(
|
|
37
|
+
rules,
|
|
38
|
+
['rule4'],
|
|
39
|
+
['https://example.org/exclusions.txt', 'https://example.org/exclusions2.txt', 'test/dir/exclusions.txt'],
|
|
40
|
+
);
|
|
38
41
|
|
|
39
42
|
// Assert
|
|
40
43
|
expect(filtered).toHaveLength(2);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const removeModifiers = require('../../src/transformations/remove-modifiers');
|
|
2
2
|
|
|
3
|
-
describe('
|
|
3
|
+
describe('Remove modifiers', () => {
|
|
4
4
|
it('simple test', () => {
|
|
5
|
-
const
|
|
5
|
+
const actual = `! test comment
|
|
6
|
+
! next line should have whitespaces. do not remove them. AG-23720
|
|
7
|
+
|
|
6
8
|
||example.org$third-party,important
|
|
7
9
|
||example.net$domain=ya.ru,3p
|
|
8
10
|
||islandofadvert.com^$document,popup
|
|
@@ -10,16 +12,21 @@ describe('Strip third-party', () => {
|
|
|
10
12
|
||example.com$doc
|
|
11
13
|
||example.com$all
|
|
12
14
|
||example.org^`.split(/\r?\n/);
|
|
13
|
-
const filtered = removeModifiers(rules);
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
const expected = [
|
|
17
|
+
'! test comment',
|
|
18
|
+
'! next line should have whitespaces. do not remove them. AG-23720',
|
|
19
|
+
// whitespaces should be trimmed
|
|
20
|
+
'',
|
|
21
|
+
'||example.org$important',
|
|
22
|
+
'||example.net$domain=ya.ru',
|
|
23
|
+
'||islandofadvert.com^',
|
|
24
|
+
'||example.com',
|
|
25
|
+
'||example.com',
|
|
26
|
+
'||example.com',
|
|
27
|
+
'||example.org^',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
expect(removeModifiers(actual)).toStrictEqual(expected);
|
|
24
31
|
});
|
|
25
32
|
});
|
|
@@ -44,6 +44,8 @@ describe('Validate', () => {
|
|
|
44
44
|
||org^
|
|
45
45
|
||example.org^$third-party
|
|
46
46
|
||example.org^$important
|
|
47
|
+
||*.ga^$denyallow=example1.ga|example2.ga
|
|
48
|
+
://ww4.$denyallow=ww4.example.com
|
|
47
49
|
://example.org
|
|
48
50
|
||example.org^|
|
|
49
51
|
@@||example.org^|$important
|
|
@@ -57,6 +59,8 @@ describe('Validate', () => {
|
|
|
57
59
|
'||example.org^',
|
|
58
60
|
'||ex*.org^', // valid because contains special characters
|
|
59
61
|
'||example.org^$important',
|
|
62
|
+
'||*.ga^$denyallow=example1.ga|example2.ga',
|
|
63
|
+
'://ww4.$denyallow=ww4.example.com',
|
|
60
64
|
'://example.org',
|
|
61
65
|
'||example.org^|',
|
|
62
66
|
'@@||example.org^|$important',
|
package/.eslintrc
DELETED