Skip to content

Commit ede8ce0

Browse files
committed
AG-25746: simplify work with constants in mv3 example
Merge in ADGUARD-FILTERS/tsurlfilter from feature/AG-25746 to master Squashed commit of the following: commit 605c937 Author: Dmitriy Seregin <[email protected]> Date: Mon Sep 11 13:46:45 2023 +0300 AG-25746: simplify work with constants in mv3 example
1 parent 6567b41 commit ede8ce0

File tree

5 files changed

+13
-47
lines changed

5 files changed

+13
-47
lines changed
Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,13 @@
1-
import { Configuration } from '@adguard/tswebextension/mv3';
1+
import { type Configuration } from '@adguard/tswebextension/mv3';
2+
import { DEFAULT_EXTENSION_CONFIG } from '../../../scripts/constants';
23

34
/**
45
* Return default configuration with loaded filters content
56
* @param filtersDir directory with filters in txt format
67
* @returns configuration
78
*/
89
export const loadDefaultConfig = (): Configuration => {
9-
console.debug('[LOAD DEFAULT CONFIG]: start');
10+
console.debug('[LOAD DEFAULT CONFIG]');
1011

11-
const defaultConfig: Configuration = {
12-
staticFiltersIds: [1, 2, 3, 4, 9, 14],
13-
customFilters: [],
14-
allowlist: [],
15-
trustedDomains: [],
16-
userrules: [],
17-
verbose: false,
18-
filtersPath: 'filters',
19-
ruleSetsPath: 'filters/declarative',
20-
filteringLogEnabled: false,
21-
settings: {
22-
assistantUrl: '',
23-
collectStats: true,
24-
allowlistInverted: false,
25-
allowlistEnabled: false,
26-
documentBlockingPageUrl: chrome.runtime.getURL('pages/document-blocking.html'),
27-
stealthModeEnabled: true,
28-
filteringEnabled: true,
29-
stealth: {
30-
blockChromeClientData: true,
31-
hideReferrer: true,
32-
hideSearchQueries: true,
33-
sendDoNotTrack: true,
34-
blockWebRTC: true,
35-
selfDestructThirdPartyCookies: true,
36-
selfDestructThirdPartyCookiesTime: 3600,
37-
selfDestructFirstPartyCookies: true,
38-
selfDestructFirstPartyCookiesTime: 3600,
39-
},
40-
},
41-
};
42-
43-
console.debug('[LOAD DEFAULT CONFIG]: end');
44-
45-
return defaultConfig;
12+
return DEFAULT_EXTENSION_CONFIG;
4613
};

packages/examples/tswebextension-mv3/scripts/browser-test/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { chromium } from 'playwright';
22

33
import {
4-
BUILD_PATH,
5-
USER_DATA_PATH,
64
DEFAULT_EXTENSION_CONFIG,
75
TESTCASES_BASE_URL,
86
} from '../constants';
@@ -19,6 +17,7 @@ import { getTestcases, getRuleText } from './requests';
1917
import { filterCompatibleTestcases } from './testcase';
2018
import { logTestResult, logTestTimeout } from './logger';
2119
import { Product } from './product';
20+
import { BUILD_PATH, USER_DATA_PATH } from '../build/constants';
2221

2322
const TESTS_TIMEOUT_MS = 5 * 1000;
2423
const TESTS_TIMEOUT_CODE = 'tests_timeout';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import path from 'path';
2+
3+
export const BUILD_PATH = path.join(__dirname, '../build');
4+
5+
export const USER_DATA_PATH = path.join(__dirname, '../tmp');

packages/examples/tswebextension-mv3/scripts/constants.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
import path from 'path';
2-
31
import { Configuration } from '@adguard/tswebextension/mv3';
42

5-
export const BUILD_PATH = path.join(__dirname, '../build');
6-
7-
export const USER_DATA_PATH = path.join(__dirname, '../tmp');
8-
93
// TODO: can be used as common for examples/tswebextension-mv2 as well
104
export const TESTCASES_BASE_URL = 'https://testcases.agrd.dev';
115

126
export const TESTCASES_DATA_PATH = '/data.json';
137

148
export const DEFAULT_EXTENSION_CONFIG: Configuration = {
15-
staticFiltersIds: [],
9+
staticFiltersIds: [1, 2, 3, 4, 9, 14],
1610
customFilters: [],
1711
allowlist: [],
1812
userrules: [],

packages/examples/tswebextension-mv3/scripts/precompile-rules.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { getFilterName } from '@adguard/tswebextension/mv3/utils';
44
import axios from 'axios';
55
import path from 'path';
66
import { ensureDir } from 'fs-extra';
7+
import { DEFAULT_EXTENSION_CONFIG } from './constants';
78

89
const COMMON_FILTERS_DIR = './extension/filters';
910
const FILTERS_DIR = `${COMMON_FILTERS_DIR}`;
1011
const DEST_RULE_SETS_DIR = `${COMMON_FILTERS_DIR}/declarative`;
1112
const RESOURCES_DIR = '/war/redirects';
1213

13-
const ADGUARD_FILTERS_IDS = [1, 2, 3, 4, 9, 14];
14+
const ADGUARD_FILTERS_IDS = DEFAULT_EXTENSION_CONFIG.staticFiltersIds;
1415

1516
const EXTENSION_FILTERS_SERVER_URL_FORMAT = 'https://filters.adtidy.org/extension/chromium';
1617
const FILTER_DOWNLOAD_URL_FORMAT = `${EXTENSION_FILTERS_SERVER_URL_FORMAT}/filters/%filter.txt`;

0 commit comments

Comments
 (0)