@adguard/filters-compiler 3.2.11 → 3.3.0-beta.1
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/README.md +78 -14
- package/dist/index.cjs +355 -166
- package/dist/index.d.ts +16 -6
- package/dist/index.js +354 -167
- package/dist/main/optimization.d.ts +114 -0
- package/dist/types/src/main/optimization.d.ts +114 -0
- package/dist/types/src/main/utils/concurrent.d.ts +8 -0
- package/dist/types/src/main/utils/log.d.ts +31 -0
- package/dist/types/src/main/utils/webutils.d.ts +11 -0
- package/dist/types/test/optimization.test.d.ts +1 -0
- package/dist/types/test/webutils.test.d.ts +1 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -89,13 +89,14 @@ timestamped log to `logPath`.
|
|
|
89
89
|
|
|
90
90
|
## API Overview
|
|
91
91
|
|
|
92
|
-
The library exports
|
|
92
|
+
The library exports four functions:
|
|
93
93
|
|
|
94
|
-
| Function
|
|
95
|
-
|
|
|
96
|
-
| `compile(...)`
|
|
97
|
-
| `validateJSONSchema(...)`
|
|
98
|
-
| `validateLocales(...)`
|
|
94
|
+
| Function | Purpose |
|
|
95
|
+
| ----------------------------- | ---------------------------------------------------- |
|
|
96
|
+
| `compile(...)` | Compiles filter lists into platform-specific output |
|
|
97
|
+
| `validateJSONSchema(...)` | Validates built platform output against JSON schemas |
|
|
98
|
+
| `validateLocales(...)` | Validates locale translation files for completeness |
|
|
99
|
+
| `localOptimizationStatistics` | Caches optimization statistics for local compilation |
|
|
99
100
|
|
|
100
101
|
### `compile(...)`
|
|
101
102
|
|
|
@@ -104,9 +105,9 @@ function compile(
|
|
|
104
105
|
path: string,
|
|
105
106
|
logPath: string | undefined,
|
|
106
107
|
reportFile: string | undefined,
|
|
107
|
-
platformsPath: string,
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
platformsPath: string | null,
|
|
109
|
+
includedFilterIds?: number[] | null,
|
|
110
|
+
excludedFilterIds?: number[] | null,
|
|
110
111
|
customPlatformsConfig?: CustomPlatformsConfig,
|
|
111
112
|
): Promise<void>;
|
|
112
113
|
```
|
|
@@ -114,9 +115,9 @@ function compile(
|
|
|
114
115
|
Compiles the filter lists in `path` for all configured platforms and
|
|
115
116
|
writes the results to `platformsPath`.
|
|
116
117
|
|
|
117
|
-
- `
|
|
118
|
+
- `includedFilterIds` — compile only the filter IDs listed here (empty array
|
|
118
119
|
compiles all filters).
|
|
119
|
-
- `
|
|
120
|
+
- `excludedFilterIds` — exclude the filter IDs listed here.
|
|
120
121
|
- `customPlatformsConfig` — overrides or extends the built-in platform
|
|
121
122
|
definitions (see [Custom platforms](#custom-platforms)).
|
|
122
123
|
|
|
@@ -162,6 +163,21 @@ found, `data` and `log` contain the per-locale details and `ok` is
|
|
|
162
163
|
`false` only if at least one warning is critical. Throws when the
|
|
163
164
|
locales directory is missing or empty.
|
|
164
165
|
|
|
166
|
+
### `localOptimizationStatistics`
|
|
167
|
+
|
|
168
|
+
A namespace for caching optimization statistics locally so that
|
|
169
|
+
`compile()` reads each filter's `stats.json` from disk instead of
|
|
170
|
+
fetching it from the remote server. `percent.json` (which determines
|
|
171
|
+
which filters are optimizable) is always fetched remotely, even when
|
|
172
|
+
using the local cache.
|
|
173
|
+
|
|
174
|
+
It exposes `download`, `use`, and `reset` methods and throws
|
|
175
|
+
`OptimizationStatsError` (an `Error` subclass carrying `filterId` and
|
|
176
|
+
`sourcePath` fields) when stats for a filter cannot be retrieved.
|
|
177
|
+
|
|
178
|
+
See [Local Optimization Statistics](#local-optimization-statistics)
|
|
179
|
+
for a complete workflow.
|
|
180
|
+
|
|
165
181
|
## Usage Examples
|
|
166
182
|
|
|
167
183
|
### Compiling filter lists
|
|
@@ -176,8 +192,8 @@ await compile(
|
|
|
176
192
|
'./log.txt', // log file (omit to disable logging)
|
|
177
193
|
'./report.txt', // compilation report
|
|
178
194
|
'./platforms', // platform output directory
|
|
179
|
-
[], //
|
|
180
|
-
[], //
|
|
195
|
+
[], // includedFilterIds (empty = compile all)
|
|
196
|
+
[], // excludedFilterIds (empty = exclude none)
|
|
181
197
|
);
|
|
182
198
|
```
|
|
183
199
|
|
|
@@ -386,7 +402,7 @@ const customPlatformsConfig = {
|
|
|
386
402
|
|
|
387
403
|
`replacements[].from` is treated as a regular-expression pattern (it is
|
|
388
404
|
passed to `new RegExp(from, 'g')`), not as literal text. Escape regex
|
|
389
|
-
|
|
405
|
+
meta characters in `from` when a literal match is intended.
|
|
390
406
|
|
|
391
407
|
### Logging
|
|
392
408
|
|
|
@@ -430,6 +446,54 @@ Each writes its output to a subdirectory under `platformsPath`.
|
|
|
430
446
|
| `EXTENSION_ANDROID_CONTENT_BLOCKER` | `extension/android-content-blocker` | AdGuard content blocker (Android) |
|
|
431
447
|
| `EXTENSION_UBLOCK` | `extension/ublock` | uBlock Origin-compatible output |
|
|
432
448
|
|
|
449
|
+
## Local Optimization Statistics
|
|
450
|
+
|
|
451
|
+
`localOptimizationStatistics` provides a workflow for caching optimization statistics
|
|
452
|
+
locally so that `compile()` reads each filter's `stats.json` from disk instead of fetching it
|
|
453
|
+
from the remote server. `percent.json` (which determines which filters are optimizable) is
|
|
454
|
+
always fetched remotely, even when using the local cache.
|
|
455
|
+
|
|
456
|
+
### Directory layout
|
|
457
|
+
|
|
458
|
+
```text
|
|
459
|
+
<basePath>/
|
|
460
|
+
filters/
|
|
461
|
+
<filterId>/
|
|
462
|
+
stats.json # per-filter hit counts (STATS_JSON)
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
### Workflow
|
|
466
|
+
|
|
467
|
+
1. Call `download(basePath, includedFilterIds, excludedFilterIds)` to save
|
|
468
|
+
`stats.json` for filters listed in the remote `percent.json`.
|
|
469
|
+
`includedFilterIds` limits processing to those IDs (default `[]` = all).
|
|
470
|
+
`excludedFilterIds` skips those IDs (default `[]` = none). When both are
|
|
471
|
+
given, a filter is processed only if it is included and not excluded.
|
|
472
|
+
2. Call `use(basePath)` before `compile()` to tell
|
|
473
|
+
`getOptimizationStatistics` to read stats from local files under
|
|
474
|
+
`basePath` instead of fetching from the remote server.
|
|
475
|
+
3. Call `reset(basePath)` when done to remove the cache directory and clear
|
|
476
|
+
in-memory state.
|
|
477
|
+
|
|
478
|
+
If stats for a filter can't be retrieved (missing local file, or a failed remote
|
|
479
|
+
fetch), `getOptimizationStatistics` throws `OptimizationStatsError` — an `Error`
|
|
480
|
+
subclass carrying `filterId` and `sourcePath` fields, so callers can build their
|
|
481
|
+
own actionable message instead of matching on `error.message`.
|
|
482
|
+
|
|
483
|
+
```js
|
|
484
|
+
import { localOptimizationStatistics } from '@adguard/filters-compiler';
|
|
485
|
+
|
|
486
|
+
// 1. Download stats for all optimizable filters to ./stats-cache
|
|
487
|
+
await localOptimizationStatistics.download('./stats-cache');
|
|
488
|
+
|
|
489
|
+
// 2. Tell compile() to read stats from the local cache
|
|
490
|
+
localOptimizationStatistics.use('./stats-cache');
|
|
491
|
+
await compile('./filters', undefined, undefined, './platforms', [], []);
|
|
492
|
+
|
|
493
|
+
// 3. Clean up when done
|
|
494
|
+
await localOptimizationStatistics.reset('./stats-cache');
|
|
495
|
+
```
|
|
496
|
+
|
|
433
497
|
## Documentation
|
|
434
498
|
|
|
435
499
|
- [Development](DEVELOPMENT.md) — setup, build, and contributing workflow
|