Skip to content

Commit 0922f9a

Browse files
committed
AG-39262: reduced size of the bundles
Squashed commit of the following: commit c7aa3f6 Author: Dmitriy Seregin <[email protected]> Date: Thu Jan 30 13:35:43 2025 +0300 undo changes in archives commit 09a25fa Merge: c52a707 6faee5e Author: Dmitriy Seregin <[email protected]> Date: Wed Jan 29 22:19:49 2025 +0300 Merge branch 'master' into feature/AG-39262 commit c52a707 Author: Dmitriy Seregin <[email protected]> Date: Wed Jan 29 22:18:40 2025 +0300 review fixes commit 3d641b5 Author: Dmitriy Seregin <[email protected]> Date: Wed Jan 29 01:00:40 2025 +0300 update archives for tests commit 5caed11 Author: Dmitriy Seregin <[email protected]> Date: Wed Jan 29 00:55:59 2025 +0300 update lock file commit 513023d Author: Dmitriy Seregin <[email protected]> Date: Wed Jan 29 00:51:38 2025 +0300 fixes commit 28fa3a2 Author: Dmitriy Seregin <[email protected]> Date: Wed Jan 29 00:43:32 2025 +0300 update archive for tests commit b839668 Author: Dmitriy Seregin <[email protected]> Date: Wed Jan 29 00:43:17 2025 +0300 undo changes commit 8f3635f Author: Dmitriy Seregin <[email protected]> Date: Mon Jan 27 14:33:12 2025 +0300 fix commit 0b141ab Author: Dmitriy Seregin <[email protected]> Date: Fri Jan 24 01:08:09 2025 +0300 only for tests commit 23b66a4 Author: Dmitriy Seregin <[email protected]> Date: Fri Jan 24 00:04:58 2025 +0300 lock tldts to 5.X version and fixed imports commit 25a0312 Author: Dmitriy Seregin <[email protected]> Date: Wed Jan 22 21:22:12 2025 +0300 fixes commit a8861a4 Author: Dmitriy Seregin <[email protected]> Date: Wed Jan 22 20:17:36 2025 +0300 fixed comment commit 5aae653 Merge: 59080f6 7b84768 Author: Dmitriy Seregin <[email protected]> Date: Wed Jan 22 20:15:39 2025 +0300 Merge branch 'master' into feature/AG-39262 commit 59080f6 Author: Dmitriy Seregin <[email protected]> Date: Wed Jan 22 20:06:11 2025 +0300 AG-39262: moved assistant to common folder, marked tsurlfilter and tswebextension as free of side-effects
1 parent 6faee5e commit 0922f9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+428
-421
lines changed

packages/adguard-api-mv3/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
"author": "Adguard Software Ltd.",
3737
"license": "GPL-3.0-only",
3838
"dependencies": {
39-
"@adguard/logger": "1.1.0",
40-
"@adguard/tswebextension": "3.0.0-alpha.0",
39+
"@adguard/tswebextension": "workspace:^",
4140
"zod": "3.22.4"
4241
},
4342
"devDependencies": {

packages/adguard-api-mv3/rollup.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const backgroundConfig = {
4242
include: 'src/background/**',
4343
},
4444
external: [
45-
'@adguard/logger',
4645
'@adguard/tswebextension/mv3',
4746
'zod',
4847
],

packages/adguard-api-mv3/src/background/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import {
2020
TsWebExtension,
2121
type Configuration as TsWebExtensionConfiguration,
22-
type MessagesHandlerMV3,
22+
type MessageHandler,
2323
FilterListPreprocessor,
2424
LF,
2525
} from '@adguard/tswebextension/mv3';
@@ -66,7 +66,7 @@ export class AdguardApi {
6666
* for example, message for get computed css for content-script.
6767
* @returns Message handler.
6868
*/
69-
public getMessageHandler(): MessagesHandlerMV3 {
69+
public getMessageHandler(): MessageHandler {
7070
return this.tswebextension.getMessageHandler();
7171
}
7272

packages/adguard-api/src/background/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import {
2020
type TsWebExtension,
2121
type ConfigurationMV2 as TsWebExtensionConfiguration,
22-
type MessageHandlerMV2,
22+
type MessageHandler,
2323
EventChannel,
2424
createTsWebExtension,
2525
BasicFilterValidator,
@@ -129,7 +129,7 @@ export class AdguardApi {
129129
* for example, message for get computed css for content-script.
130130
* @returns Message handler.
131131
*/
132-
public getMessageHandler(): MessageHandlerMV2 {
132+
public getMessageHandler(): MessageHandler {
133133
return this.tswebextension.getMessageHandler();
134134
}
135135

packages/agtree/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@adguard/agtree",
3-
"version": "3.0.0-alpha.2",
3+
"version": "3.0.0-alpha.3",
44
"description": "Tool set for working with adblock filter lists",
55
"keywords": [
66
"adblock",

packages/agtree/src/parser/network/host-rule-parser.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-param-reassign */
2-
import * as tldts from 'tldts';
2+
import { getHostname, getDomain } from 'tldts';
33
import isIp from 'is-ip';
44

55
import { StringUtils } from '../../utils/string';
@@ -93,7 +93,7 @@ export class HostRuleParser extends BaseParser {
9393
if (partsLength === 1) {
9494
// "Just domain" syntax, e.g. `example.org`
9595
// In this case, domain should be valid and IP will be set to 0.0.0.0 by default
96-
if (tldts.getDomain(parts[0].value) !== parts[0].value) {
96+
if (getDomain(parts[0].value) !== parts[0].value) {
9797
throw new Error(`Not a valid domain: ${parts[0].value}`);
9898
}
9999

@@ -115,7 +115,7 @@ export class HostRuleParser extends BaseParser {
115115
}
116116

117117
for (const { value } of hostnames) {
118-
if (tldts.getHostname(value) !== value) {
118+
if (getHostname(value) !== value) {
119119
throw new Error(`Not a valid hostname: ${value}`);
120120
}
121121
}

packages/tsurlfilter/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "@adguard/tsurlfilter",
3-
"version": "3.1.0-alpha.7",
3+
"version": "3.1.0-alpha.8",
44
"description": "This is a TypeScript library that implements AdGuard's content blocking rules",
55
"main": "dist/es/index.js",
66
"module": "dist/es/index.js",
77
"iife": "dist/tsurlfilter.iife.js",
88
"types": "dist/types/src/index.d.ts",
99
"type": "module",
10+
"sideEffects": false,
1011
"files": [
1112
"dist",
1213
"!dist/build.txt"
@@ -115,14 +116,14 @@
115116
"dependencies": {
116117
"@adguard/agtree": "workspace:^",
117118
"@adguard/css-tokenizer": "workspace:^",
118-
"@adguard/scriptlets": "^2.1.3-alpha.1",
119+
"@adguard/scriptlets": "^2.1.4",
119120
"cidr-tools": "^6.4.1",
120121
"commander": "9.4.1",
121122
"is-cidr": "4.0.2",
122123
"is-ip": "3.1.0",
123124
"lru-cache": "^11.0.2",
124125
"punycode": "2.3.1",
125-
"tldts": "5.6.45",
126+
"tldts": "^5.7.112",
126127
"zod": "3.21.4"
127128
},
128129
"devDependencies": {

packages/tsurlfilter/src/modifiers/remove-param-modifier.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as utils from '../utils/url';
1+
import { cleanUrlParamByRegExp } from '../utils/url';
22
import { type IAdvancedModifier } from './advanced-modifier';
33
import { SimpleRegex } from '../rules/simple-regex';
44

@@ -95,9 +95,9 @@ export class RemoveParamModifier implements IAdvancedModifier {
9595
}
9696

9797
if (this.value.startsWith('~')) {
98-
return utils.cleanUrlParamByRegExp(url, this.valueRegExp, true);
98+
return cleanUrlParamByRegExp(url, this.valueRegExp, true);
9999
}
100100

101-
return utils.cleanUrlParamByRegExp(url, this.valueRegExp);
101+
return cleanUrlParamByRegExp(url, this.valueRegExp);
102102
}
103103
}

packages/tsurlfilter/src/request.ts

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export class Request {
143143
this.sourceUrl = Request.compactUrl(sourceUrl);
144144

145145
const tldResult = parse(url);
146+
// We suppose that request always has a hostname and a domain.
146147
this.hostname = tldResult.hostname!;
147148
this.domain = tldResult.domain!;
148149
this.subdomains = Request.getSubdomains(tldResult);

packages/tsurlfilter/src/rules/cosmetic-rule.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from '@adguard/agtree';
1717

1818
import { CosmeticRuleBodyGenerator } from '@adguard/agtree/generator';
19-
import * as rule from './rule';
19+
import { type IRule, RULE_INDEX_NONE } from './rule';
2020
import { DomainModifier } from '../modifiers/domain-modifier';
2121
import { getRelativeUrl } from '../utils/url';
2222
import { SimpleRegex } from './simple-regex';
@@ -178,7 +178,7 @@ interface ProcessedModifiers {
178178
* * `example.org#%#//scriptlet('scriptlet-name')` -- Scriptlet rule
179179
* * `example.org$$div[id="test"]` -- HTML filtering rule
180180
*/
181-
export class CosmeticRule implements rule.IRule {
181+
export class CosmeticRule implements IRule {
182182
private readonly ruleIndex: number;
183183

184184
private readonly filterListId: number;
@@ -562,7 +562,7 @@ export class CosmeticRule implements rule.IRule {
562562
*
563563
* @throws error if it fails to parse the rule.
564564
*/
565-
constructor(node: AnyCosmeticRule, filterListId: number, ruleIndex: number = rule.RULE_INDEX_NONE) {
565+
constructor(node: AnyCosmeticRule, filterListId: number, ruleIndex: number = RULE_INDEX_NONE) {
566566
this.ruleIndex = ruleIndex;
567567
this.filterListId = filterListId;
568568

packages/tsurlfilter/src/rules/declarative-converter/network-indexed-rule-with-hash.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { type AnyRule, RuleConverter } from '@adguard/agtree';
1+
import { type AnyRule } from '@adguard/agtree';
2+
import { RuleConverter } from '@adguard/agtree/converter';
23

34
import { getErrorMessage } from '../../common/error';
45
import { fastHash } from '../../utils/string-utils';

packages/tsurlfilter/src/rules/declarative-converter/rule-set.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z as zod } from 'zod';
2-
import { RuleParser } from '@adguard/agtree';
2+
import { RuleParser } from '@adguard/agtree/parser';
33

44
import type { NetworkRule } from '../network-rule';
55
import { getErrorMessage } from '../../common/error';

packages/tsurlfilter/src/rules/host-rule.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type HostRule as HostRuleNode } from '@adguard/agtree';
2-
3-
import * as rule from './rule';
2+
import { type IRule, RULE_INDEX_NONE } from './rule';
43

54
/**
65
* Implements a host rule.
@@ -20,7 +19,7 @@ import * as rule from './rule';
2019
* * `::1 localhost ip6-localhost ip6-loopback` -- ipv6 aliases
2120
* * `example.org` -- "just domain" syntax
2221
*/
23-
export class HostRule implements rule.IRule {
22+
export class HostRule implements IRule {
2423
private readonly ruleIndex: number;
2524

2625
private readonly filterListId: number;
@@ -41,7 +40,7 @@ export class HostRule implements rule.IRule {
4140
*
4241
* @throws error if it fails to parse the rule.
4342
*/
44-
constructor(node: HostRuleNode, filterListId: number, ruleIndex = rule.RULE_INDEX_NONE) {
43+
constructor(node: HostRuleNode, filterListId: number, ruleIndex = RULE_INDEX_NONE) {
4544
this.ruleIndex = ruleIndex;
4645
this.filterListId = filterListId;
4746

packages/tsurlfilter/src/rules/network-rule.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type ModifierList, type NetworkRule as NetworkRuleNode } from '@adguard/agtree';
22
import { RuleGenerator } from '@adguard/agtree/generator';
33

4-
import * as rule from './rule';
4+
import { type IRule, RULE_INDEX_NONE } from './rule';
55
import { SimpleRegex } from './simple-regex';
66
import { type Request } from '../request';
77
import { DomainModifier, PIPE_SEPARATOR } from '../modifiers/domain-modifier';
@@ -202,7 +202,7 @@ export enum NetworkRuleGroupOptions {
202202
* Basic network filtering rule.
203203
* https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#basic-rules
204204
*/
205-
export class NetworkRule implements rule.IRule {
205+
export class NetworkRule implements IRule {
206206
private readonly ruleIndex: number;
207207

208208
private readonly filterListId: number;
@@ -1055,7 +1055,7 @@ export class NetworkRule implements rule.IRule {
10551055
*
10561056
* @throws error if it fails to parse the rule.
10571057
*/
1058-
constructor(node: NetworkRuleNode, filterListId: number, ruleIndex = rule.RULE_INDEX_NONE) {
1058+
constructor(node: NetworkRuleNode, filterListId: number, ruleIndex = RULE_INDEX_NONE) {
10591059
this.ruleIndex = ruleIndex;
10601060
// TODO: Remove this completely
10611061
this.ruleText = RuleGenerator.generate(node);

packages/tsurlfilter/test/utils/string-utils.test.ts

+31-25
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
1-
import * as stringUtils from '../../src/utils/string-utils';
1+
import {
2+
splitByDelimiterWithEscapeCharacter,
3+
startsAtIndexWith,
4+
hasUnquotedSubstring,
5+
fastHash,
6+
replaceAll,
7+
} from '../../src/utils/string-utils';
28

39
describe('splitByDelimiterWithEscapeCharacter', () => {
410
it('works if splits plain strings with and w/o preserving all tokens', () => {
5-
let result = stringUtils.splitByDelimiterWithEscapeCharacter('example.org,,,example.com', ',', '\\', false);
11+
let result = splitByDelimiterWithEscapeCharacter('example.org,,,example.com', ',', '\\', false);
612
let expected = ['example.org', 'example.com'];
713
expect(result).toEqual(expected);
814

915
// Empty tokens must be preserved correctly
10-
result = stringUtils.splitByDelimiterWithEscapeCharacter('example.org,,,example.com', ',', '\\', true);
16+
result = splitByDelimiterWithEscapeCharacter('example.org,,,example.com', ',', '\\', true);
1117
expected = ['example.org', '', '', 'example.com'];
1218
expect(result).toEqual(expected);
1319

1420
// Delimiters must be escaped correctly, with escape character removed
15-
result = stringUtils.splitByDelimiterWithEscapeCharacter('example.org\\,\\,\\,example.com', ',', '\\', true);
21+
result = splitByDelimiterWithEscapeCharacter('example.org\\,\\,\\,example.com', ',', '\\', true);
1622
expected = ['example.org,,,example.com'];
1723
expect(result).toEqual(expected);
1824

1925
// Empty string must return empty array
20-
result = stringUtils.splitByDelimiterWithEscapeCharacter('', ',', '\\', true);
26+
result = splitByDelimiterWithEscapeCharacter('', ',', '\\', true);
2127
expected = [];
2228
expect(result).toEqual(expected);
2329

2430
// Check if index 0 delimiter is trimmed correctly
25-
result = stringUtils.splitByDelimiterWithEscapeCharacter(',example.org,example.com', ',', '\\', false);
31+
result = splitByDelimiterWithEscapeCharacter(',example.org,example.com', ',', '\\', false);
2632
expected = ['example.org', 'example.com'];
2733
expect(result).toEqual(expected);
2834

2935
// Forward slash splitting
30-
result = stringUtils.splitByDelimiterWithEscapeCharacter('/text-to-be-replaced/new-text/i', '/', '\\', true);
36+
result = splitByDelimiterWithEscapeCharacter('/text-to-be-replaced/new-text/i', '/', '\\', true);
3137
expected = ['text-to-be-replaced', 'new-text', 'i'];
3238
expect(result).toEqual(expected);
3339

3440
// Keep empty token after ending delimiter
35-
result = stringUtils.splitByDelimiterWithEscapeCharacter(
41+
result = splitByDelimiterWithEscapeCharacter(
3642
'/(<VAST[\\s\\S]*?>)[\\s\\S]*<\\/VAST>/$1<\\/VAST>/',
3743
'/',
3844
'\\',
@@ -42,7 +48,7 @@ describe('splitByDelimiterWithEscapeCharacter', () => {
4248
expect(result).toEqual(expected);
4349

4450
// Remove empty token after ending delimiter
45-
result = stringUtils.splitByDelimiterWithEscapeCharacter(
51+
result = splitByDelimiterWithEscapeCharacter(
4652
'/(<VAST[\\s\\S]*?>)[\\s\\S]*<\\/VAST>/$1<\\/VAST>/',
4753
'/',
4854
'\\',
@@ -52,12 +58,12 @@ describe('splitByDelimiterWithEscapeCharacter', () => {
5258
expect(result).toEqual(expected);
5359

5460
// Keep empty token after delimiter for comma
55-
result = stringUtils.splitByDelimiterWithEscapeCharacter('example.org,,,example.com,', ',', '\\', true);
61+
result = splitByDelimiterWithEscapeCharacter('example.org,,,example.com,', ',', '\\', true);
5662
expected = ['example.org', '', '', 'example.com', ''];
5763
expect(result).toEqual(expected);
5864

5965
// Escape character should be kept if specified
60-
result = stringUtils.splitByDelimiterWithEscapeCharacter('qwe\\,rty,1,2,3', ',', '\\', false, false);
66+
result = splitByDelimiterWithEscapeCharacter('qwe\\,rty,1,2,3', ',', '\\', false, false);
6167
expected = ['qwe\\,rty', '1', '2', '3'];
6268
expect(result).toEqual(expected);
6369
});
@@ -69,10 +75,10 @@ describe('splitByDelimiterWithEscapeCharacter', () => {
6975
while (count < 2000) {
7076
count += 1;
7177

72-
let parts = stringUtils.splitByDelimiterWithEscapeCharacter('example.org,,,example.com', ',', '\\', false);
78+
let parts = splitByDelimiterWithEscapeCharacter('example.org,,,example.com', ',', '\\', false);
7379
expect(parts.length).toEqual(2);
7480

75-
parts = stringUtils.splitByDelimiterWithEscapeCharacter('example.org,,,example.com', ',', '\\', true);
81+
parts = splitByDelimiterWithEscapeCharacter('example.org,,,example.com', ',', '\\', true);
7682
expect(parts.length).toEqual(4);
7783
}
7884

@@ -83,41 +89,41 @@ describe('splitByDelimiterWithEscapeCharacter', () => {
8389

8490
describe('startsAtIndexWith', () => {
8591
it('works if it can check simple strings', () => {
86-
expect(stringUtils.startsAtIndexWith('example', 0, 'ex')).toEqual(true);
87-
expect(stringUtils.startsAtIndexWith('example', 1, 'xa')).toEqual(true);
88-
expect(stringUtils.startsAtIndexWith('example', 6, 'e')).toEqual(true);
92+
expect(startsAtIndexWith('example', 0, 'ex')).toEqual(true);
93+
expect(startsAtIndexWith('example', 1, 'xa')).toEqual(true);
94+
expect(startsAtIndexWith('example', 6, 'e')).toEqual(true);
8995
});
9096
});
9197

9298
describe('hasUnquotedSubstring', () => {
9399
it('works if it can check simple strings', () => {
94-
expect(stringUtils.hasUnquotedSubstring('example', 'ex')).toEqual(true);
95-
expect(stringUtils.hasUnquotedSubstring('"example"', 'ex')).toEqual(false);
96-
expect(stringUtils.hasUnquotedSubstring('\\"example\\"', 'ex')).toEqual(true);
100+
expect(hasUnquotedSubstring('example', 'ex')).toEqual(true);
101+
expect(hasUnquotedSubstring('"example"', 'ex')).toEqual(false);
102+
expect(hasUnquotedSubstring('\\"example\\"', 'ex')).toEqual(true);
97103
});
98104
});
99105

100106
describe('replaceAll', () => {
101107
it('works if it can replace simple strings', () => {
102-
expect(stringUtils.replaceAll('example_example', 'ex', 'EX')).toEqual('EXample_EXample');
108+
expect(replaceAll('example_example', 'ex', 'EX')).toEqual('EXample_EXample');
103109
});
104110
});
105111

106112
describe('fastHash', () => {
107113
it('works if it can fastHash', () => {
108-
expect(stringUtils.fastHash('')).toEqual(0);
114+
expect(fastHash('')).toEqual(0);
109115
});
110116

111117
it('creates unique hashes', () => {
112-
const hashOne = stringUtils.fastHash('example.com');
113-
const hashTwo = stringUtils.fastHash('example.net');
118+
const hashOne = fastHash('example.com');
119+
const hashTwo = fastHash('example.net');
114120

115121
expect(hashOne).not.toBe(hashTwo);
116122
});
117123

118124
it('prevent overflow for too long strings', () => {
119-
const hashOne = stringUtils.fastHash('verylongstringverylongstringverylongstring');
120-
const hashTwo = stringUtils.fastHash('anotherverylongstringverylongstringverylongstring');
125+
const hashOne = fastHash('verylongstringverylongstringverylongstring');
126+
const hashTwo = fastHash('anotherverylongstringverylongstringverylongstring');
121127

122128
expect(hashOne).toBeLessThan(2 ** 32);
123129
expect(hashTwo).toBeLessThan(2 ** 32);

0 commit comments

Comments
 (0)