@adguard/hostlist-compiler 2.1.1 → 3.0.0-beta.0
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/.markdownlint.json +29 -0
- package/.markdownlintignore +1 -0
- package/AGENTS.md +310 -98
- package/CHANGELOG.md +59 -8
- package/DEPLOYMENT.md +171 -0
- package/DEVELOPMENT.md +171 -72
- package/README.md +238 -143
- package/examples/china/README.md +2 -2
- package/examples/energized/README.md +4 -2
- package/examples/sdn/README.md +2 -2
- package/examples/whitelist/README.md +2 -2
- package/package.json +24 -18
- package/src/cli.js +53 -31
- package/src/compile-source.js +4 -3
- package/src/configuration.js +132 -2
- package/src/download.js +27 -0
- package/src/filter.js +2 -2
- package/src/index.d.ts +2 -0
- package/src/index.js +16 -50
- package/src/{transformations/ip-normalize.js → ip-normalize.js} +2 -2
- package/src/schemas/configuration.schema.js +137 -0
- package/src/source-types.js +17 -0
- package/src/transformations/enum.js +49 -0
- package/src/transformations/include.js +1 -1
- package/src/transformations/transform.js +40 -74
- package/src/transformations/validate-allow-ip-and-public-suffix.js +1 -1
- package/src/transformations/validate-allow-ip.js +1 -1
- package/src/utils.js +1284 -0
- package/src/validation-conflicts.js +106 -0
- package/test/cli-error-output.test.js +305 -0
- package/test/cli.test.js +47 -0
- package/test/compile-source.test.js +167 -7
- package/test/configuration.test.js +438 -0
- package/test/download.test.js +260 -0
- package/test/helpers/http-mock.js +94 -0
- package/test/index.test.js +497 -4
- package/test/{transformations/ip-normalize.test.js → ip-normalize.test.js} +1 -1
- package/test/resolve-include.test.js +8 -8
- package/test/transformations/covert-to-ascii.test.js +1 -1
- package/test/transformations/exclude.test.js +2 -2
- package/test/transformations/include.test.js +9 -3
- package/test/transformations/ip-alignment.test.js +1 -1
- package/test/transformations/transform.test.js +66 -1
- package/test/utils.test.js +1559 -0
- package/test/validation-conflicts.test.js +230 -0
- package/src/schemas/configuration.schema.json +0 -369
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* ValidateAllowIp to ensure all three agree — and to catch any future
|
|
6
6
|
* divergence caused by editing one module without updating the others.
|
|
7
7
|
*/
|
|
8
|
-
const { ACTION, processIpRule } = require('../../src/
|
|
8
|
+
const { ACTION, processIpRule } = require('../../src/ip-normalize');
|
|
9
9
|
const { validate } = require('../../src/transformations/validate');
|
|
10
10
|
const { validateAllowIp } = require('../../src/transformations/validate-allow-ip');
|
|
11
11
|
|
|
@@ -1,6 +1,71 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {
|
|
2
|
+
transform,
|
|
3
|
+
DEFAULT_TRANSFORMATIONS,
|
|
4
|
+
TRANSFORMATIONS_IN_ORDER,
|
|
5
|
+
} = require('../../src/transformations/transform');
|
|
6
|
+
const { TRANSFORMATIONS } = require('../../src/transformations/enum');
|
|
7
|
+
|
|
8
|
+
describe('DEFAULT_TRANSFORMATIONS', () => {
|
|
9
|
+
it('is frozen', () => {
|
|
10
|
+
expect(Object.isFrozen(DEFAULT_TRANSFORMATIONS)).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('contains the default pipeline for the quick conversion mode', () => {
|
|
14
|
+
expect(DEFAULT_TRANSFORMATIONS).toEqual([
|
|
15
|
+
TRANSFORMATIONS.RemoveComments,
|
|
16
|
+
TRANSFORMATIONS.Deduplicate,
|
|
17
|
+
TRANSFORMATIONS.Compress,
|
|
18
|
+
TRANSFORMATIONS.Validate,
|
|
19
|
+
TRANSFORMATIONS.TrimLines,
|
|
20
|
+
TRANSFORMATIONS.InsertFinalNewLine,
|
|
21
|
+
]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('converts /etc/hosts rules to a valid adblock list', async () => {
|
|
25
|
+
const rules = [
|
|
26
|
+
'0.0.0.0 example.com',
|
|
27
|
+
'0.0.0.0 example.com',
|
|
28
|
+
'! comment',
|
|
29
|
+
'',
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const filtered = await transform(rules, {}, DEFAULT_TRANSFORMATIONS);
|
|
33
|
+
|
|
34
|
+
expect(filtered).toEqual(['||example.com^', '']);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
2
37
|
|
|
3
38
|
describe('Transform', () => {
|
|
39
|
+
it('dispatches every transformation declared in the TRANSFORMATIONS enum', () => {
|
|
40
|
+
const dispatched = TRANSFORMATIONS_IN_ORDER.map(([name]) => name);
|
|
41
|
+
|
|
42
|
+
expect(new Set(dispatched)).toEqual(new Set(Object.values(TRANSFORMATIONS)));
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('pins the fixed execution order of TRANSFORMATIONS_IN_ORDER', () => {
|
|
46
|
+
// A literal list, independent of the implementation: the dispatch
|
|
47
|
+
// order IS the execution order and MUST match the order list in
|
|
48
|
+
// README.md. Unlike Set equality, toEqual also catches reorders and
|
|
49
|
+
// duplicate entries.
|
|
50
|
+
const expectedOrder = [
|
|
51
|
+
'ConvertToAscii',
|
|
52
|
+
'TrimLines',
|
|
53
|
+
'RemoveComments',
|
|
54
|
+
'Compress',
|
|
55
|
+
'RemoveModifiers',
|
|
56
|
+
'InvertAllow',
|
|
57
|
+
'Validate',
|
|
58
|
+
'ValidateAllowIp',
|
|
59
|
+
'ValidateAllowPublicSuffix',
|
|
60
|
+
'ValidateAllowIpAndPublicSuffix',
|
|
61
|
+
'Deduplicate',
|
|
62
|
+
'RemoveEmptyLines',
|
|
63
|
+
'InsertFinalNewLine',
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
expect(TRANSFORMATIONS_IN_ORDER.map(([name]) => name)).toEqual(expectedOrder);
|
|
67
|
+
});
|
|
68
|
+
|
|
4
69
|
it('no transformations', async () => {
|
|
5
70
|
const rules = `! test comment
|
|
6
71
|
rule1
|