Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test

on:
workflow_dispatch:
pull_request:

jobs:
test:
runs-on: ubuntu-slim
steps:
- name: Checkout repo
uses: actions/checkout@v6
with:
fetch-depth: 1

- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 24

- name: Enable corepack
run: corepack enable

- name: Install dependencies
run: yarn

- name: Test
run: yarn test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@adguard/agtree": "^4.0.4",
"@adguard/dead-domains-linter": "^1.0.22",
"@adguard/diff-builder": "1.1.2",
"@adguard/filters-compiler": "3.2.8",
"@adguard/filters-compiler": "AdguardTeam/FiltersCompiler#local_optimization_config",
"add": "^2.0.6",
"crypto-js": "^4.2.0",
"zod": "3"
Expand Down
68 changes: 68 additions & 0 deletions scripts/build/__tests__/optimization-integration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
describe, it, vi, expect, beforeEach, afterEach,
} from 'vitest';
import path from 'path';
import { fileURLToPath } from 'url';

const expectedOptimizationConfigCachePath = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../../../temp/optimization_config',
);

vi.mock('@adguard/filters-compiler', () => ({
compile: vi.fn().mockResolvedValue(undefined),
optimizationConfigLocal: {
setPath: vi.fn(),
generate: vi.fn().mockResolvedValue(undefined),
},
}));

vi.mock('fs', () => ({
default: {
existsSync: vi.fn().mockReturnValue(false),
promises: {
cp: vi.fn().mockResolvedValue(undefined),
rm: vi.fn().mockResolvedValue(undefined),
writeFile: vi.fn().mockResolvedValue(undefined),
},
},
}));

vi.mock('../../utils/find_files.js', () => ({
findFiles: vi.fn().mockResolvedValue([]),
}));

describe('build.js optimization config integration', () => {
const originalArgv = process.argv;

beforeEach(() => {
vi.resetModules();
});

afterEach(() => {
process.argv = originalArgv;
vi.clearAllMocks();
});

it('setPath is called with optimizationConfigCacheDir when --use-cache', async () => {
process.argv = ['node', 'build.js', '--use-cache'];
await import('../build.js');

const { optimizationConfigLocal } = await import('@adguard/filters-compiler');
await vi.waitFor(() => {
expect(optimizationConfigLocal.setPath).toHaveBeenCalledWith(expectedOptimizationConfigCachePath);
});
});

it('generate and setPath are called in sequence with optimizationConfigCacheDir '
+ 'when --generate-cache', async () => {
process.argv = ['node', 'build.js', '--generate-cache'];
await import('../build.js');

const { optimizationConfigLocal } = await import('@adguard/filters-compiler');
await vi.waitFor(() => {
expect(optimizationConfigLocal.generate).toHaveBeenCalledWith(expectedOptimizationConfigCachePath);
expect(optimizationConfigLocal.setPath).toHaveBeenCalledWith(expectedOptimizationConfigCachePath);
});
});
});
15 changes: 13 additions & 2 deletions scripts/build/build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { compile } from '@adguard/filters-compiler';
import { compile, optimizationConfigLocal } from '@adguard/filters-compiler';
import { CUSTOM_PLATFORMS_CONFIG } from './custom_platforms.js';
import { formatDate } from '../utils/strings.js';
import {
Expand Down Expand Up @@ -78,7 +78,9 @@ const filtersDir = path.join(__dirname, '../../filters');
const logPath = path.join(__dirname, '../../log.txt');
const platformsPath = path.join(__dirname, '../..', FOLDER_WITH_NEW_FILTERS);
const copyPlatformsPath = path.join(__dirname, '../..', FOLDER_WITH_OLD_FILTERS);
const cachedFiltersDir = path.join(__dirname, '../../temp/filters_cached');
const tempDir = path.join(__dirname, '../../temp');
const cachedFiltersDir = path.join(tempDir, 'filters_cached');
const optimizationConfigCachePath = path.join(tempDir, 'optimization_config');

const reportPath = rawReportPath !== ''
// report-adguard.txt OR report-third-party.txt
Expand Down Expand Up @@ -134,6 +136,12 @@ const buildFilters = async () => {
// When --generate-cache we only need to compile filters (which updates filter.txt),
// skip platform generation, patches preparation, and temp/platforms copying.
if (generateCache) {
await fs.promises.rm(optimizationConfigCachePath, { recursive: true, force: true });
await optimizationConfigLocal.generate(optimizationConfigCachePath);
optimizationConfigLocal.setPath(optimizationConfigCachePath);
// eslint-disable-next-line no-console
console.log(`Using local optimization config from: ${optimizationConfigCachePath}`);

await compile(
filtersDir,
logPath,
Expand Down Expand Up @@ -166,6 +174,9 @@ const buildFilters = async () => {

if (useCache) {
await prepareCachedFiltersDir();
optimizationConfigLocal.setPath(optimizationConfigCachePath);
// eslint-disable-next-line no-console
console.log(`Using local optimization config from: ${optimizationConfigCachePath}`);
}

try {
Expand Down
5 changes: 4 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export default defineConfig({
enabled: true,
tsconfig: './tsconfig.json',
},
include: ['scripts/wildcard-domain-processor/__tests__/*.test.ts'],
include: [
'scripts/wildcard-domain-processor/__tests__/*.test.ts',
'scripts/build/__tests__/*.test.{js,ts}',
],
watch: false,
silent: true,
},
Expand Down
13 changes: 6 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,18 @@
resolved "https://registry.yarnpkg.com/@adguard/extended-css/-/extended-css-2.1.1.tgz#53677a310cf39259f54dfce79b692b0a327a8bb7"
integrity sha512-TsHZ20oUWhbtrzQ4w70B96oHkGBIUZg2FdMfkq4StGfLmXQb+kI7fQb6BtXP2D0bvraIHMq6/mtKExglDJ9vsg==

"@adguard/filters-compiler@3.2.8":
version "3.2.8"
resolved "https://registry.yarnpkg.com/@adguard/filters-compiler/-/filters-compiler-3.2.8.tgz#b3b77419ab062d218a5dd7d8bf161493920f1147"
integrity sha512-5BnIQgawIWb6+sOt1RKZwR76G1a8QjkZOw0JtLK53VInSTppEY+XeVanUOmZtzaiifbpu5Ddz8cTgc70tW7ERA==
"@adguard/filters-compiler@AdguardTeam/FiltersCompiler#local_optimization_config":
version "3.2.6"
resolved "https://codeload.github.com/AdguardTeam/FiltersCompiler/tar.gz/615d6e0880bc46aa81758d4a7b0f334a87a204bc"
dependencies:
"@adguard/agtree" "^4.0.4"
"@adguard/agtree" "^4.0.3"
"@adguard/css-tokenizer" "^1.2.0"
"@adguard/ecss-tree" "^2.0.1"
"@adguard/extended-css" "^2.1.1"
"@adguard/filters-downloader" "^2.4.0"
"@adguard/logger" "^2.0.0"
"@adguard/scriptlets" "^2.3.1"
"@adguard/tsurlfilter" "^4.0.5"
"@adguard/tsurlfilter" "^4.0.4"
"@eslint/css-tree" "3.6.6"
ajv "^8.17.1"
child_process ">=1.0.2"
Expand Down Expand Up @@ -148,7 +147,7 @@
"@types/trusted-types" "^2.0.7"
js-yaml "^3.14.1"

"@adguard/tsurlfilter@^4.0.5":
"@adguard/tsurlfilter@^4.0.4":
version "4.0.5"
resolved "https://registry.yarnpkg.com/@adguard/tsurlfilter/-/tsurlfilter-4.0.5.tgz#2a1438d3da7c0c4b0a98c255c4386ce631eb99ae"
integrity sha512-s/Iv86M9KUXXAfeyps/hmEbX5tismn19lAVqIkFptBujnrV6uEY2bxthzRsBWxY39Y8ZFwrjhe9nyZ3HILbU3g==
Expand Down