From ede8ce00fe09f3fff4e7b96e24d922b89de49dd2 Mon Sep 17 00:00:00 2001 From: Dmitry Seregin Date: Mon, 11 Sep 2023 15:19:37 +0300 Subject: [PATCH] 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 605c93704f66662987e993ef9ca8fe55dd54d4b1 Author: Dmitriy Seregin Date: Mon Sep 11 13:46:45 2023 +0300 AG-25746: simplify work with constants in mv3 example --- .../src/background/loadDefaultConfig.ts | 41 ++----------------- .../scripts/browser-test/index.ts | 3 +- .../scripts/build/constants.ts | 5 +++ .../tswebextension-mv3/scripts/constants.ts | 8 +--- .../scripts/precompile-rules.ts | 3 +- 5 files changed, 13 insertions(+), 47 deletions(-) create mode 100644 packages/examples/tswebextension-mv3/scripts/build/constants.ts diff --git a/packages/examples/tswebextension-mv3/extension/src/background/loadDefaultConfig.ts b/packages/examples/tswebextension-mv3/extension/src/background/loadDefaultConfig.ts index 478132665..42716a68a 100644 --- a/packages/examples/tswebextension-mv3/extension/src/background/loadDefaultConfig.ts +++ b/packages/examples/tswebextension-mv3/extension/src/background/loadDefaultConfig.ts @@ -1,4 +1,5 @@ -import { Configuration } from '@adguard/tswebextension/mv3'; +import { type Configuration } from '@adguard/tswebextension/mv3'; +import { DEFAULT_EXTENSION_CONFIG } from '../../../scripts/constants'; /** * Return default configuration with loaded filters content @@ -6,41 +7,7 @@ import { Configuration } from '@adguard/tswebextension/mv3'; * @returns configuration */ export const loadDefaultConfig = (): Configuration => { - console.debug('[LOAD DEFAULT CONFIG]: start'); + console.debug('[LOAD DEFAULT CONFIG]'); - const defaultConfig: Configuration = { - staticFiltersIds: [1, 2, 3, 4, 9, 14], - customFilters: [], - allowlist: [], - trustedDomains: [], - userrules: [], - verbose: false, - filtersPath: 'filters', - ruleSetsPath: 'filters/declarative', - filteringLogEnabled: false, - settings: { - assistantUrl: '', - collectStats: true, - allowlistInverted: false, - allowlistEnabled: false, - documentBlockingPageUrl: chrome.runtime.getURL('pages/document-blocking.html'), - stealthModeEnabled: true, - filteringEnabled: true, - stealth: { - blockChromeClientData: true, - hideReferrer: true, - hideSearchQueries: true, - sendDoNotTrack: true, - blockWebRTC: true, - selfDestructThirdPartyCookies: true, - selfDestructThirdPartyCookiesTime: 3600, - selfDestructFirstPartyCookies: true, - selfDestructFirstPartyCookiesTime: 3600, - }, - }, - }; - - console.debug('[LOAD DEFAULT CONFIG]: end'); - - return defaultConfig; + return DEFAULT_EXTENSION_CONFIG; }; diff --git a/packages/examples/tswebextension-mv3/scripts/browser-test/index.ts b/packages/examples/tswebextension-mv3/scripts/browser-test/index.ts index 7b72de0c5..f6ce8d50f 100644 --- a/packages/examples/tswebextension-mv3/scripts/browser-test/index.ts +++ b/packages/examples/tswebextension-mv3/scripts/browser-test/index.ts @@ -1,8 +1,6 @@ import { chromium } from 'playwright'; import { - BUILD_PATH, - USER_DATA_PATH, DEFAULT_EXTENSION_CONFIG, TESTCASES_BASE_URL, } from '../constants'; @@ -19,6 +17,7 @@ import { getTestcases, getRuleText } from './requests'; import { filterCompatibleTestcases } from './testcase'; import { logTestResult, logTestTimeout } from './logger'; import { Product } from './product'; +import { BUILD_PATH, USER_DATA_PATH } from '../build/constants'; const TESTS_TIMEOUT_MS = 5 * 1000; const TESTS_TIMEOUT_CODE = 'tests_timeout'; diff --git a/packages/examples/tswebextension-mv3/scripts/build/constants.ts b/packages/examples/tswebextension-mv3/scripts/build/constants.ts new file mode 100644 index 000000000..825e76f3c --- /dev/null +++ b/packages/examples/tswebextension-mv3/scripts/build/constants.ts @@ -0,0 +1,5 @@ +import path from 'path'; + +export const BUILD_PATH = path.join(__dirname, '../build'); + +export const USER_DATA_PATH = path.join(__dirname, '../tmp'); diff --git a/packages/examples/tswebextension-mv3/scripts/constants.ts b/packages/examples/tswebextension-mv3/scripts/constants.ts index 01c3cf68a..72cc29c03 100644 --- a/packages/examples/tswebextension-mv3/scripts/constants.ts +++ b/packages/examples/tswebextension-mv3/scripts/constants.ts @@ -1,18 +1,12 @@ -import path from 'path'; - import { Configuration } from '@adguard/tswebextension/mv3'; -export const BUILD_PATH = path.join(__dirname, '../build'); - -export const USER_DATA_PATH = path.join(__dirname, '../tmp'); - // TODO: can be used as common for examples/tswebextension-mv2 as well export const TESTCASES_BASE_URL = 'https://testcases.agrd.dev'; export const TESTCASES_DATA_PATH = '/data.json'; export const DEFAULT_EXTENSION_CONFIG: Configuration = { - staticFiltersIds: [], + staticFiltersIds: [1, 2, 3, 4, 9, 14], customFilters: [], allowlist: [], userrules: [], diff --git a/packages/examples/tswebextension-mv3/scripts/precompile-rules.ts b/packages/examples/tswebextension-mv3/scripts/precompile-rules.ts index 3bf80f524..ba4364afe 100644 --- a/packages/examples/tswebextension-mv3/scripts/precompile-rules.ts +++ b/packages/examples/tswebextension-mv3/scripts/precompile-rules.ts @@ -4,13 +4,14 @@ import { getFilterName } from '@adguard/tswebextension/mv3/utils'; import axios from 'axios'; import path from 'path'; import { ensureDir } from 'fs-extra'; +import { DEFAULT_EXTENSION_CONFIG } from './constants'; const COMMON_FILTERS_DIR = './extension/filters'; const FILTERS_DIR = `${COMMON_FILTERS_DIR}`; const DEST_RULE_SETS_DIR = `${COMMON_FILTERS_DIR}/declarative`; const RESOURCES_DIR = '/war/redirects'; -const ADGUARD_FILTERS_IDS = [1, 2, 3, 4, 9, 14]; +const ADGUARD_FILTERS_IDS = DEFAULT_EXTENSION_CONFIG.staticFiltersIds; const EXTENSION_FILTERS_SERVER_URL_FORMAT = 'https://filters.adtidy.org/extension/chromium'; const FILTER_DOWNLOAD_URL_FORMAT = `${EXTENSION_FILTERS_SERVER_URL_FORMAT}/filters/%filter.txt`;