@adguard/hostlist-compiler 1.0.32 → 1.0.34

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/CHANGELOG.md CHANGED
@@ -5,11 +5,27 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.34] - 2025-01-10
9
+
10
+ ### Removed
11
+
12
+ - Calculation of checksum for filters. [#76]
13
+
14
+ [1.0.34]: https://github.com/AdguardTeam/HostlistCompiler/compare/v1.0.33...v1.0.34
15
+
16
+ ## [1.0.33] - 2024-12-27
17
+
18
+ ### Fixed
19
+
20
+ - Bug with checksum calculation. Leave blank lines when counting. [#76]
21
+
22
+ [1.0.33]: https://github.com/AdguardTeam/HostlistCompiler/compare/v1.0.32...v1.0.33
23
+
8
24
  ## [1.0.32] - 2024-12-27
9
25
 
10
26
  ### Fixed
11
27
 
12
- - Bug with checksum calculation [#63]
28
+ - Bug with checksum calculation. Additional line start. [#76]
13
29
 
14
30
  [1.0.32]: https://github.com/AdguardTeam/HostlistCompiler/compare/v1.0.31...v1.0.32
15
31
 
@@ -25,7 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
25
41
 
26
42
  [1.0.31]: https://github.com/AdguardTeam/HostlistCompiler/compare/v1.0.29...v1.0.31
27
43
  [#63]: https://github.com/AdguardTeam/HostlistCompiler/issues/63
28
- [#76]: https://github.com/AdguardTeam/FiltersCompiler/issues/76
44
+ [#76]: https://github.com/AdguardTeam/HostlistCompiler/issues/76
29
45
 
30
46
  ## [1.0.29] - 2024-09-26
31
47
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adguard/hostlist-compiler",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
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",
package/src/index.js CHANGED
@@ -4,7 +4,6 @@ const config = require('./configuration');
4
4
  const compileSource = require('./compile-source');
5
5
  const { transform } = require('./transformations/transform');
6
6
  const packageJson = require('../package.json');
7
- const { calculateChecksum } = require('./utils');
8
7
 
9
8
  /**
10
9
  * Prepares list header
@@ -15,6 +14,7 @@ const { calculateChecksum } = require('./utils');
15
14
  */
16
15
  function prepareHeader(configuration) {
17
16
  const lines = [
17
+ '!',
18
18
  `! Title: ${configuration.name}`,
19
19
  ];
20
20
 
@@ -101,12 +101,8 @@ async function compile(configuration) {
101
101
 
102
102
  // Now prepend the list header and we're good to go
103
103
  const header = prepareHeader(configuration);
104
- // Calculate checksum
105
- const checksum = calculateChecksum(header, finalList);
106
- // Concat everything together
107
- const data = [checksum, ...header, ...finalList];
108
- consola.info(`Final length of the list is ${data.length}`);
109
- return data;
104
+ consola.info(`Final length of the list is ${header.length + finalList.length}`);
105
+ return header.concat(finalList);
110
106
  }
111
107
 
112
108
  module.exports = compile;
package/src/utils.js CHANGED
@@ -1,49 +1,7 @@
1
1
  const _ = require('lodash');
2
2
  const fs = require('fs').promises;
3
- const crypto = require('crypto');
4
3
  const axios = require('axios');
5
4
 
6
- /**
7
- * Strips specified character from the end of a string.
8
- *
9
- * @param {string} string - The string to strip.
10
- * @param {string} char - The character to strip.
11
- * @returns {string} - The stripped string.
12
- */
13
- const stripEnd = (str, char) => {
14
- let result = str;
15
- while (result.endsWith(char)) {
16
- result = result.slice(0, -1);
17
- }
18
- return result;
19
- };
20
-
21
- /**
22
- * Normalizes data by replacing newlines.
23
- *
24
- * @param {string} message - The message to normalize.
25
- * @returns {string} - The normalized message.
26
- */
27
- const normalizeData = (message) => {
28
- return message.replace(/\r/g, '').replace(/\n+/g, '\n');
29
- };
30
-
31
- /**
32
- * Calculates checksum for the given header and rules.
33
- * See:
34
- * https://adblockplus.org/en/filters#special-comments
35
- * https://hg.adblockplus.org/adblockplus/file/tip/addChecksum.py
36
- *
37
- * @param {Array<string>} header - The header lines.
38
- * @param {Array<string>} rules - The rules lines.
39
- * @returns {string} - The calculated checksum.
40
- */
41
- const calculateChecksum = (header, rules) => {
42
- const content = normalizeData(header.concat(rules).join('\n'));
43
- const checksum = crypto.createHash('md5').update(content).digest('base64');
44
- return `! Checksum: ${stripEnd(checksum.trim(), '=')}`;
45
- };
46
-
47
5
  function isURL(str) {
48
6
  try {
49
7
  // eslint-disable-next-line no-unused-vars
@@ -211,7 +169,6 @@ class Wildcard {
211
169
  }
212
170
 
213
171
  module.exports = {
214
- calculateChecksum,
215
172
  download,
216
173
  Wildcard,
217
174
  splitByDelimiterWithEscapeCharacter,
@@ -1,7 +1,6 @@
1
1
  const nock = require('nock');
2
2
  const consola = require('consola');
3
3
  const compile = require('../src/index');
4
- const { calculateChecksum } = require('../src/utils');
5
4
 
6
5
  describe('Hostlist compiler', () => {
7
6
  it('compile from multiple sources', async () => {
@@ -33,7 +32,6 @@ describe('Hostlist compiler', () => {
33
32
  const list = await compile(configuration);
34
33
 
35
34
  // assert
36
- expect(list[0].startsWith('! Checksum:')).toBe(true);
37
35
  expect(list).toContain('||example.org');
38
36
  expect(list).toContain('||example.com');
39
37
  expect(list).toContain('! Version: 1.0.0.9');
@@ -43,39 +41,4 @@ describe('Hostlist compiler', () => {
43
41
 
44
42
  scope.done();
45
43
  });
46
-
47
- it('calculates checksum correctly', async () => {
48
- // Prepare source
49
- const scope = nock('https://example.org')
50
- .get('/source1.txt')
51
- .reply(200, '||example.org');
52
-
53
- // compiler configuration
54
- const configuration = {
55
- name: 'Test filter',
56
- description: 'Checksum test filter',
57
- version: '1.0.0.1',
58
- sources: [
59
- {
60
- name: 'source 1',
61
- source: 'https://example.org/source1.txt',
62
- },
63
- ],
64
- };
65
-
66
- // compile the final list
67
- const list = await compile(configuration);
68
-
69
- // assert
70
- const checksumLine = list[0];
71
- expect(checksumLine.startsWith('! Checksum:')).toBe(true);
72
-
73
- const header = list.slice(1, list.indexOf('||example.org'));
74
- const finalList = list.slice(list.indexOf('||example.org'));
75
-
76
- const expectedChecksum = calculateChecksum(header, finalList);
77
- expect(checksumLine).toBe(expectedChecksum);
78
-
79
- scope.done();
80
- });
81
44
  });
@@ -34,32 +34,3 @@ describe('substringBetween', () => {
34
34
  expect(substr).toBe(null);
35
35
  });
36
36
  });
37
-
38
- describe('calculateChecksum', () => {
39
- it('calculates checksum with multiple headers and rules', () => {
40
- const header = ['! Title: AdGuard DNS filter', '! Title: Example filter list'];
41
- const rules = ['||example.com^', '||test.com^'];
42
- const expectedChecksum = '! Checksum: VSbHtv4WyU405Fks327CsA';
43
-
44
- const checksum = utils.calculateChecksum(header, rules);
45
- expect(checksum).toBe(expectedChecksum);
46
- });
47
-
48
- it('calculates checksum with empty rules', () => {
49
- const header = ['[Adblock Plus 2.0]'];
50
- const rules = [];
51
- const expectedChecksum = '! Checksum: 87GLA4VsMnV9PiusIkPkEg';
52
-
53
- const checksum = utils.calculateChecksum(header, rules);
54
- expect(checksum).toBe(expectedChecksum);
55
- });
56
-
57
- it('calculates checksum with empty header and rules', () => {
58
- const header = [];
59
- const rules = [];
60
- const expectedChecksum = '! Checksum: 1B2M2Y8AsgTpgAmY7PhCfg';
61
-
62
- const checksum = utils.calculateChecksum(header, rules);
63
- expect(checksum).toBe(expectedChecksum);
64
- });
65
- });