@adguard/hostlist-compiler 2.1.0 → 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.
Files changed (58) hide show
  1. package/.dockerignore +29 -0
  2. package/.github/workflows/ci.yml +22 -0
  3. package/.github/workflows/mirror.yml +24 -0
  4. package/.github/workflows/prepare-release.yml +26 -0
  5. package/.github/workflows/publish-release.yml +44 -0
  6. package/.markdownlint.json +29 -0
  7. package/.markdownlintignore +1 -0
  8. package/AGENTS.md +314 -103
  9. package/CHANGELOG.md +76 -7
  10. package/DEPLOYMENT.md +171 -0
  11. package/DEVELOPMENT.md +174 -76
  12. package/README.md +240 -140
  13. package/examples/china/README.md +2 -2
  14. package/examples/energized/README.md +4 -2
  15. package/examples/sdn/README.md +2 -2
  16. package/examples/whitelist/README.md +2 -2
  17. package/package.json +29 -24
  18. package/src/cli.js +59 -33
  19. package/src/compile-source.js +4 -3
  20. package/src/configuration.js +132 -2
  21. package/src/download.js +27 -0
  22. package/src/filter.js +2 -2
  23. package/src/index.d.ts +2 -0
  24. package/src/index.js +21 -51
  25. package/src/{transformations/ip-normalize.js → ip-normalize.js} +2 -2
  26. package/src/schemas/configuration.schema.js +137 -0
  27. package/src/source-types.js +17 -0
  28. package/src/transformations/enum.js +49 -0
  29. package/src/transformations/include.js +1 -1
  30. package/src/transformations/transform.js +40 -74
  31. package/src/transformations/validate-allow-ip-and-public-suffix.js +1 -1
  32. package/src/transformations/validate-allow-ip.js +1 -1
  33. package/src/utils.js +1284 -0
  34. package/src/validation-conflicts.js +106 -0
  35. package/test/cli-error-output.test.js +305 -0
  36. package/test/cli.test.js +47 -0
  37. package/test/compile-source.test.js +167 -7
  38. package/test/configuration.test.js +438 -0
  39. package/test/download.test.js +260 -0
  40. package/test/helpers/http-mock.js +94 -0
  41. package/test/index.test.js +497 -4
  42. package/test/{transformations/ip-normalize.test.js → ip-normalize.test.js} +1 -1
  43. package/test/resolve-include.test.js +8 -8
  44. package/test/transformations/covert-to-ascii.test.js +1 -1
  45. package/test/transformations/exclude.test.js +2 -2
  46. package/test/transformations/include.test.js +9 -3
  47. package/test/transformations/ip-alignment.test.js +1 -1
  48. package/test/transformations/transform.test.js +66 -1
  49. package/test/utils.test.js +1559 -0
  50. package/test/validation-conflicts.test.js +230 -0
  51. package/bamboo-specs/bamboo.yaml +0 -14
  52. package/bamboo-specs/build.yaml +0 -92
  53. package/bamboo-specs/deploy.yaml +0 -38
  54. package/bamboo-specs/increment.yaml +0 -54
  55. package/bamboo-specs/permissions.yaml +0 -16
  56. package/bamboo-specs/test.yaml +0 -56
  57. package/src/schemas/configuration.schema.json +0 -369
  58. package/tools/build-txt.js +0 -19
@@ -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/transformations/ip-normalize');
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 { transform } = require('../../src/transformations/transform');
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