@adguard/filters-compiler 3.1.0 → 3.1.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 +23 -0
- package/dist/build.txt +1 -1
- package/dist/index.cjs +198 -116
- package/dist/index.js +198 -116
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var path = require('path');
|
|
3
|
+
var path$1 = require('path');
|
|
4
4
|
var tsurlfilter = require('@adguard/tsurlfilter');
|
|
5
|
-
var fs = require('fs');
|
|
5
|
+
var fs$1 = require('fs');
|
|
6
6
|
var md5 = require('md5');
|
|
7
7
|
var filtersDownloader = require('@adguard/filters-downloader');
|
|
8
8
|
var agtree = require('@adguard/agtree');
|
|
9
|
+
var fs = require('node:fs');
|
|
10
|
+
var os = require('node:os');
|
|
11
|
+
var path = require('node:path');
|
|
9
12
|
var logger$1 = require('@adguard/logger');
|
|
10
13
|
var parser = require('@adguard/agtree/parser');
|
|
11
14
|
var ecssTree = require('@adguard/ecss-tree');
|
|
@@ -72,24 +75,103 @@ const version = {
|
|
|
72
75
|
};
|
|
73
76
|
|
|
74
77
|
/**
|
|
75
|
-
*
|
|
78
|
+
* Extend logger implementation
|
|
76
79
|
*/
|
|
77
|
-
|
|
80
|
+
class CompilerLogger extends logger$1.Logger {
|
|
81
|
+
/**
|
|
82
|
+
* File descriptor
|
|
83
|
+
*
|
|
84
|
+
* @type {number | null}
|
|
85
|
+
*
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
#fd = null;
|
|
78
89
|
|
|
79
|
-
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Helper to append message to log file
|
|
92
|
+
*
|
|
93
|
+
* @param {string} message
|
|
94
|
+
* @param {'INFO'|'WARN'|'ERROR'} level
|
|
95
|
+
*
|
|
96
|
+
* @private
|
|
97
|
+
*/
|
|
98
|
+
#append(message, level) {
|
|
99
|
+
if (this.#fd == null) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const line = `[${new Date().toLocaleTimeString()}] [${level}]: ${message}${os.EOL}`;
|
|
104
|
+
|
|
105
|
+
// Using appendFileSync with an fd ensures atomic append semantics.
|
|
106
|
+
fs.appendFileSync(this.#fd, line, 'utf8');
|
|
90
107
|
}
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
|
|
109
|
+
/** @inheritdoc */
|
|
110
|
+
info(message) {
|
|
111
|
+
super.info(message);
|
|
112
|
+
this.#append(message, 'INFO');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** @inheritdoc */
|
|
116
|
+
error(message) {
|
|
117
|
+
super.error(message);
|
|
118
|
+
this.#append(message, 'ERROR');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** @inheritdoc */
|
|
122
|
+
warn(message) {
|
|
123
|
+
super.warn(message);
|
|
124
|
+
this.#append(message, 'WARN');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Initializes logger
|
|
129
|
+
*
|
|
130
|
+
* @param {string} logFilePath - log file path
|
|
131
|
+
*
|
|
132
|
+
* The log file is opened with 'w' (truncate/create). Subsequent writes are appended.
|
|
133
|
+
*/
|
|
134
|
+
initialize(logFilePath) {
|
|
135
|
+
if (!logFilePath) {
|
|
136
|
+
/* eslint-disable no-console */
|
|
137
|
+
console.warn('Log file is not specified');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Ensure the directory exists before creating the log file
|
|
142
|
+
const dir = path.dirname(logFilePath);
|
|
143
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
144
|
+
|
|
145
|
+
// Close any previous descriptor to avoid leaks
|
|
146
|
+
if (this.#fd != null) {
|
|
147
|
+
try {
|
|
148
|
+
fs.closeSync(this.#fd);
|
|
149
|
+
} catch {
|
|
150
|
+
/* noop */
|
|
151
|
+
}
|
|
152
|
+
this.#fd = null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Open (truncate) now; we’ll append to the same fd later.
|
|
156
|
+
this.#fd = fs.openSync(logFilePath, 'w');
|
|
157
|
+
this.logFile = logFilePath;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Optional: call to close the file descriptor when done (e.g., on shutdown)
|
|
162
|
+
*/
|
|
163
|
+
close() {
|
|
164
|
+
if (this.#fd != null) {
|
|
165
|
+
try {
|
|
166
|
+
fs.closeSync(this.#fd);
|
|
167
|
+
} finally {
|
|
168
|
+
this.#fd = null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const logger = new CompilerLogger();
|
|
93
175
|
|
|
94
176
|
// TODO: a lot of these masks can be imported from @adguard/agtree
|
|
95
177
|
/**
|
|
@@ -157,7 +239,7 @@ const convertRulesToAdgSyntax = (rulesList, excluded) => {
|
|
|
157
239
|
}
|
|
158
240
|
} catch (e) {
|
|
159
241
|
const message = `Unable to convert rule to AdGuard syntax: "${rule}" due to error: ${e.message}`;
|
|
160
|
-
logger.
|
|
242
|
+
logger.error(message);
|
|
161
243
|
excludeRule$1(rule, excluded, message);
|
|
162
244
|
}
|
|
163
245
|
}
|
|
@@ -221,7 +303,7 @@ const convertToUbo = (rules) => {
|
|
|
221
303
|
// https://github.com/AdguardTeam/Scriptlets#trusted-scriptlets-restriction
|
|
222
304
|
// does not work in other blockers
|
|
223
305
|
const message = `Trusted scriptlets should not be converted to uBO syntax. Rule: "${rule}"`;
|
|
224
|
-
logger.
|
|
306
|
+
logger.warn(message);
|
|
225
307
|
modified.push('');
|
|
226
308
|
return;
|
|
227
309
|
}
|
|
@@ -231,7 +313,7 @@ const convertToUbo = (rules) => {
|
|
|
231
313
|
modified.push(...convertedRules);
|
|
232
314
|
} catch (e) {
|
|
233
315
|
const message = `Unable to convert rule to Ubo syntax: "${rule}" due to error: ${e.message}`;
|
|
234
|
-
logger.
|
|
316
|
+
logger.error(message);
|
|
235
317
|
}
|
|
236
318
|
} else {
|
|
237
319
|
modified.push('');
|
|
@@ -1257,7 +1339,7 @@ const cleanupAndOptimizeRules = function (rules, config, optimizationConfig, fil
|
|
|
1257
1339
|
|
|
1258
1340
|
/* eslint-disable global-require */
|
|
1259
1341
|
|
|
1260
|
-
const __dirname$4 = path.dirname(new URL((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname);
|
|
1342
|
+
const __dirname$4 = path$1.dirname(new URL((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname);
|
|
1261
1343
|
|
|
1262
1344
|
const RULES_SEPARATOR = '\r\n';
|
|
1263
1345
|
let filterIdsPool = [];
|
|
@@ -1326,7 +1408,7 @@ let adguardFiltersServerUrl = null;
|
|
|
1326
1408
|
*/
|
|
1327
1409
|
const readFile$2 = function (path) {
|
|
1328
1410
|
try {
|
|
1329
|
-
return fs.readFileSync(path, { encoding: 'utf-8' });
|
|
1411
|
+
return fs$1.readFileSync(path, { encoding: 'utf-8' });
|
|
1330
1412
|
} catch (e) {
|
|
1331
1413
|
return null;
|
|
1332
1414
|
}
|
|
@@ -1431,15 +1513,15 @@ const calculateChecksum = function (header, rules) {
|
|
|
1431
1513
|
* @throws {Error} Throws an error if there is a permission issue or if the directory cannot be created.
|
|
1432
1514
|
*/
|
|
1433
1515
|
const createDir = (dir) => {
|
|
1434
|
-
const { sep } = path;
|
|
1435
|
-
const initDir = path.isAbsolute(dir) ? sep : '';
|
|
1516
|
+
const { sep } = path$1;
|
|
1517
|
+
const initDir = path$1.isAbsolute(dir) ? sep : '';
|
|
1436
1518
|
// eslint-disable-next-line no-undef
|
|
1437
1519
|
const baseDir = __dirname$4;
|
|
1438
1520
|
|
|
1439
1521
|
return dir.split(sep).reduce((parentDir, childDir) => {
|
|
1440
|
-
const curDir = path.resolve(baseDir, parentDir, childDir);
|
|
1522
|
+
const curDir = path$1.resolve(baseDir, parentDir, childDir);
|
|
1441
1523
|
try {
|
|
1442
|
-
fs.mkdirSync(curDir);
|
|
1524
|
+
fs$1.mkdirSync(curDir);
|
|
1443
1525
|
} catch (err) {
|
|
1444
1526
|
if (err.code === 'EEXIST') { // curDir already exists!
|
|
1445
1527
|
return curDir;
|
|
@@ -1451,7 +1533,7 @@ const createDir = (dir) => {
|
|
|
1451
1533
|
}
|
|
1452
1534
|
|
|
1453
1535
|
const caughtErr = ['EACCES', 'EPERM', 'EISDIR'].indexOf(err.code) > -1;
|
|
1454
|
-
if ((!caughtErr || caughtErr) && (curDir === path.resolve(dir))) {
|
|
1536
|
+
if ((!caughtErr || caughtErr) && (curDir === path$1.resolve(dir))) {
|
|
1455
1537
|
throw err; // Throw if it's just the last created dir.
|
|
1456
1538
|
}
|
|
1457
1539
|
}
|
|
@@ -1710,12 +1792,12 @@ const loadLocales = function (dir) {
|
|
|
1710
1792
|
filters: {},
|
|
1711
1793
|
};
|
|
1712
1794
|
|
|
1713
|
-
const locales = fs.readdirSync(dir);
|
|
1795
|
+
const locales = fs$1.readdirSync(dir);
|
|
1714
1796
|
// eslint-disable-next-line no-restricted-syntax
|
|
1715
1797
|
for (const directory of locales) {
|
|
1716
|
-
const localeDir = path.join(dir, directory);
|
|
1717
|
-
if (fs.lstatSync(localeDir).isDirectory()) {
|
|
1718
|
-
const groups = JSON.parse(readFile$2(path.join(localeDir, 'groups.json')));
|
|
1798
|
+
const localeDir = path$1.join(dir, directory);
|
|
1799
|
+
if (fs$1.lstatSync(localeDir).isDirectory()) {
|
|
1800
|
+
const groups = JSON.parse(readFile$2(path$1.join(localeDir, 'groups.json')));
|
|
1719
1801
|
if (groups) {
|
|
1720
1802
|
// eslint-disable-next-line no-restricted-syntax
|
|
1721
1803
|
for (const group of groups) {
|
|
@@ -1734,7 +1816,7 @@ const loadLocales = function (dir) {
|
|
|
1734
1816
|
}
|
|
1735
1817
|
}
|
|
1736
1818
|
|
|
1737
|
-
const tags = JSON.parse(readFile$2(path.join(localeDir, 'tags.json')));
|
|
1819
|
+
const tags = JSON.parse(readFile$2(path$1.join(localeDir, 'tags.json')));
|
|
1738
1820
|
if (tags) {
|
|
1739
1821
|
// eslint-disable-next-line no-restricted-syntax
|
|
1740
1822
|
for (const tag of tags) {
|
|
@@ -1753,7 +1835,7 @@ const loadLocales = function (dir) {
|
|
|
1753
1835
|
}
|
|
1754
1836
|
}
|
|
1755
1837
|
|
|
1756
|
-
const filters = JSON.parse(readFile$2(path.join(localeDir, 'filters.json')));
|
|
1838
|
+
const filters = JSON.parse(readFile$2(path$1.join(localeDir, 'filters.json')));
|
|
1757
1839
|
if (filters) {
|
|
1758
1840
|
// eslint-disable-next-line no-restricted-syntax
|
|
1759
1841
|
for (const filter of filters) {
|
|
@@ -1889,13 +1971,13 @@ const removeGroupDescriptions = (inputGroups) => {
|
|
|
1889
1971
|
const writeFiltersMetadata = function (platformsPath, filtersDir, filtersMetadata, obsoleteFilters) {
|
|
1890
1972
|
logger.info('Writing filters metadata');
|
|
1891
1973
|
|
|
1892
|
-
const groups = JSON.parse(readFile$2(path.join(filtersDir, '../groups', 'metadata.json')));
|
|
1974
|
+
const groups = JSON.parse(readFile$2(path$1.join(filtersDir, '../groups', 'metadata.json')));
|
|
1893
1975
|
if (!groups) {
|
|
1894
1976
|
logger.error('Error reading groups metadata');
|
|
1895
1977
|
return;
|
|
1896
1978
|
}
|
|
1897
1979
|
|
|
1898
|
-
const tags = JSON.parse(readFile$2(path.join(filtersDir, '../tags', 'metadata.json')));
|
|
1980
|
+
const tags = JSON.parse(readFile$2(path$1.join(filtersDir, '../tags', 'metadata.json')));
|
|
1899
1981
|
if (!tags) {
|
|
1900
1982
|
logger.error('Error reading tags metadata');
|
|
1901
1983
|
return;
|
|
@@ -1905,17 +1987,17 @@ const writeFiltersMetadata = function (platformsPath, filtersDir, filtersMetadat
|
|
|
1905
1987
|
const parsedLangTagsFiltersMetadata = processFiltersFromMetadata(filtersMetadata);
|
|
1906
1988
|
const replacedTagKeywordsFiltersMetadata = replaceTagKeywords(parsedLangTagsFiltersMetadata, tags);
|
|
1907
1989
|
|
|
1908
|
-
const localizations = loadLocales(path.join(filtersDir, '../locales'));
|
|
1990
|
+
const localizations = loadLocales(path$1.join(filtersDir, '../locales'));
|
|
1909
1991
|
|
|
1910
1992
|
// eslint-disable-next-line guard-for-in,no-restricted-syntax
|
|
1911
1993
|
for (const platform in platformPathsConfig) {
|
|
1912
1994
|
const config = platformPathsConfig[platform];
|
|
1913
|
-
const platformDir = path.join(platformsPath, config.path);
|
|
1995
|
+
const platformDir = path$1.join(platformsPath, config.path);
|
|
1914
1996
|
createDir(platformDir);
|
|
1915
1997
|
|
|
1916
1998
|
logger.info(`Writing filters metadata: ${config.path}`);
|
|
1917
|
-
const filtersFileJson = path.join(platformDir, FILTERS_METADATA_FILE_JSON);
|
|
1918
|
-
const filtersFileJs = path.join(platformDir, FILTERS_METADATA_FILE_JS);
|
|
1999
|
+
const filtersFileJson = path$1.join(platformDir, FILTERS_METADATA_FILE_JSON);
|
|
2000
|
+
const filtersFileJs = path$1.join(platformDir, FILTERS_METADATA_FILE_JS);
|
|
1919
2001
|
|
|
1920
2002
|
const replacedExpiresFiltersMetadata = replaceExpires(replacedTagKeywordsFiltersMetadata, config.expires);
|
|
1921
2003
|
|
|
@@ -1939,12 +2021,12 @@ const writeFiltersMetadata = function (platformsPath, filtersDir, filtersMetadat
|
|
|
1939
2021
|
|
|
1940
2022
|
const filtersContent = JSON.stringify(sortMetadataFilters(metadata), null, '\t');
|
|
1941
2023
|
|
|
1942
|
-
fs.writeFileSync(filtersFileJson, filtersContent, 'utf8');
|
|
1943
|
-
fs.writeFileSync(filtersFileJs, filtersContent, 'utf8');
|
|
2024
|
+
fs$1.writeFileSync(filtersFileJson, filtersContent, 'utf8');
|
|
2025
|
+
fs$1.writeFileSync(filtersFileJs, filtersContent, 'utf8');
|
|
1944
2026
|
|
|
1945
2027
|
logger.info(`Writing filters localizations: ${config.path}`);
|
|
1946
|
-
const filtersI18nFileJson = path.join(platformDir, FILTERS_I18N_METADATA_FILE_JSON);
|
|
1947
|
-
const filtersI18nFileJs = path.join(platformDir, FILTERS_I18N_METADATA_FILE_JS);
|
|
2028
|
+
const filtersI18nFileJson = path$1.join(platformDir, FILTERS_I18N_METADATA_FILE_JSON);
|
|
2029
|
+
const filtersI18nFileJs = path$1.join(platformDir, FILTERS_I18N_METADATA_FILE_JS);
|
|
1948
2030
|
|
|
1949
2031
|
let localizedFilters = { ...localizations.filters };
|
|
1950
2032
|
|
|
@@ -1981,8 +2063,8 @@ const writeFiltersMetadata = function (platformsPath, filtersDir, filtersMetadat
|
|
|
1981
2063
|
|
|
1982
2064
|
const i18nContent = JSON.stringify(i18nMetadata, null, '\t');
|
|
1983
2065
|
|
|
1984
|
-
fs.writeFileSync(filtersI18nFileJson, i18nContent, 'utf8');
|
|
1985
|
-
fs.writeFileSync(filtersI18nFileJs, i18nContent, 'utf8');
|
|
2066
|
+
fs$1.writeFileSync(filtersI18nFileJson, i18nContent, 'utf8');
|
|
2067
|
+
fs$1.writeFileSync(filtersI18nFileJs, i18nContent, 'utf8');
|
|
1986
2068
|
}
|
|
1987
2069
|
|
|
1988
2070
|
logger.info('Writing filters metadata done');
|
|
@@ -1999,7 +2081,7 @@ const writeLocalScriptRules = function (platformsPath) {
|
|
|
1999
2081
|
// eslint-disable-next-line guard-for-in,no-restricted-syntax
|
|
2000
2082
|
for (const platform in platformPathsConfig) {
|
|
2001
2083
|
const config = platformPathsConfig[platform];
|
|
2002
|
-
const platformDir = path.join(platformsPath, config.path);
|
|
2084
|
+
const platformDir = path$1.join(platformsPath, config.path);
|
|
2003
2085
|
|
|
2004
2086
|
const rulesTxt = [];
|
|
2005
2087
|
const rulesJson = {
|
|
@@ -2011,7 +2093,7 @@ const writeLocalScriptRules = function (platformsPath) {
|
|
|
2011
2093
|
// because AdGuard Chinese filter has id 224
|
|
2012
2094
|
// https://github.com/AdguardTeam/FiltersRegistry/blob/master/filters/filter_224_Chinese/metadata.json
|
|
2013
2095
|
for (let i = 1; i <= LAST_ADGUARD_FILTER_ID; i += 1) {
|
|
2014
|
-
const filterRules = readFile$2(path.join(platformDir, PLATFORM_FILTERS_DIR, `${i}.txt`));
|
|
2096
|
+
const filterRules = readFile$2(path$1.join(platformDir, PLATFORM_FILTERS_DIR, `${i}.txt`));
|
|
2015
2097
|
if (!filterRules) {
|
|
2016
2098
|
continue;
|
|
2017
2099
|
}
|
|
@@ -2042,13 +2124,13 @@ const writeLocalScriptRules = function (platformsPath) {
|
|
|
2042
2124
|
// remove scriptlet rules in local_script_rules.json
|
|
2043
2125
|
rulesJson.rules = removeScriptletRules(rulesJson.rules);
|
|
2044
2126
|
|
|
2045
|
-
fs.writeFileSync(
|
|
2046
|
-
path.join(platformDir, LOCAL_SCRIPT_RULES_FILE),
|
|
2127
|
+
fs$1.writeFileSync(
|
|
2128
|
+
path$1.join(platformDir, LOCAL_SCRIPT_RULES_FILE),
|
|
2047
2129
|
rulesTxt.join(RULES_SEPARATOR),
|
|
2048
2130
|
'utf8',
|
|
2049
2131
|
);
|
|
2050
|
-
fs.writeFileSync(
|
|
2051
|
-
path.join(platformDir, LOCAL_SCRIPT_RULES_FILE_JSON),
|
|
2132
|
+
fs$1.writeFileSync(
|
|
2133
|
+
path$1.join(platformDir, LOCAL_SCRIPT_RULES_FILE_JSON),
|
|
2052
2134
|
JSON.stringify(rulesJson, null, 4),
|
|
2053
2135
|
'utf8',
|
|
2054
2136
|
);
|
|
@@ -2067,13 +2149,13 @@ const writeLocalScriptRules = function (platformsPath) {
|
|
|
2067
2149
|
* @throws {Error} If the metadata or revision file cannot be read.
|
|
2068
2150
|
*/
|
|
2069
2151
|
const loadFilterMetadata = function (filterDir, whitelist, blacklist) {
|
|
2070
|
-
const metadataFilePath = path.join(filterDir, metadataFile);
|
|
2152
|
+
const metadataFilePath = path$1.join(filterDir, metadataFile);
|
|
2071
2153
|
const metadataString = readFile$2(metadataFilePath);
|
|
2072
2154
|
if (!metadataString) {
|
|
2073
2155
|
throw new Error(`Error reading filter metadata:${filterDir}`);
|
|
2074
2156
|
}
|
|
2075
2157
|
|
|
2076
|
-
const revisionFilePath = path.join(filterDir, revisionFile);
|
|
2158
|
+
const revisionFilePath = path$1.join(filterDir, revisionFile);
|
|
2077
2159
|
const revisionString = readFile$2(revisionFilePath);
|
|
2078
2160
|
if (!revisionString) {
|
|
2079
2161
|
throw new Error(`Error reading filter revision:${filterDir}`);
|
|
@@ -2134,7 +2216,7 @@ const writeFilterFile = function (filterFile, adbHeader, rulesHeader, rules) {
|
|
|
2134
2216
|
data = [adbHeader].concat(data);
|
|
2135
2217
|
}
|
|
2136
2218
|
|
|
2137
|
-
fs.writeFileSync(filterFile, data.join(RULES_SEPARATOR), 'utf8');
|
|
2219
|
+
fs$1.writeFileSync(filterFile, data.join(RULES_SEPARATOR), 'utf8');
|
|
2138
2220
|
};
|
|
2139
2221
|
|
|
2140
2222
|
/**
|
|
@@ -2143,7 +2225,7 @@ const writeFilterFile = function (filterFile, adbHeader, rulesHeader, rules) {
|
|
|
2143
2225
|
const writeFilterRules = function (filterId, dir, config, rulesHeader, rules, optimized) {
|
|
2144
2226
|
createDir(dir);
|
|
2145
2227
|
|
|
2146
|
-
const filterFile = path.join(dir, `${filterId}${optimized ? '_optimized' : ''}.txt`);
|
|
2228
|
+
const filterFile = path$1.join(dir, `${filterId}${optimized ? '_optimized' : ''}.txt`);
|
|
2147
2229
|
let rulesList = rules;
|
|
2148
2230
|
|
|
2149
2231
|
// Convert Adguard scriptlets and redirect rules to UBlock syntax.
|
|
@@ -2165,7 +2247,7 @@ const writeFilterRules = function (filterId, dir, config, rulesHeader, rules, op
|
|
|
2165
2247
|
const correctedHeader = rewriteHeader(rulesHeader);
|
|
2166
2248
|
const correctedRules = rewriteRules(rulesList);
|
|
2167
2249
|
|
|
2168
|
-
const correctedFile = path.join(dir, `${filterId}_without_easylist.txt`);
|
|
2250
|
+
const correctedFile = path$1.join(dir, `${filterId}_without_easylist.txt`);
|
|
2169
2251
|
writeFilterFile(correctedFile, config.configuration.adbHeader, correctedHeader, correctedRules);
|
|
2170
2252
|
}
|
|
2171
2253
|
};
|
|
@@ -2218,10 +2300,10 @@ const removeRuleDuplicates = function (list) {
|
|
|
2218
2300
|
* @param blacklist - Array of filter ids to blacklist
|
|
2219
2301
|
*/
|
|
2220
2302
|
const buildFilter$1 = async (filterDir, platformsPath, whitelist, blacklist) => {
|
|
2221
|
-
const originalRules = readFile$2(path.join(filterDir, filterFile)).split('\r\n');
|
|
2303
|
+
const originalRules = readFile$2(path$1.join(filterDir, filterFile)).split('\r\n');
|
|
2222
2304
|
|
|
2223
|
-
const metadataFilePath = path.join(filterDir, metadataFile);
|
|
2224
|
-
const revisionFilePath = path.join(filterDir, revisionFile);
|
|
2305
|
+
const metadataFilePath = path$1.join(filterDir, metadataFile);
|
|
2306
|
+
const revisionFilePath = path$1.join(filterDir, revisionFile);
|
|
2225
2307
|
|
|
2226
2308
|
const metadata = JSON.parse(readFile$2(metadataFilePath));
|
|
2227
2309
|
const { filterId } = metadata;
|
|
@@ -2277,7 +2359,7 @@ const buildFilter$1 = async (filterDir, platformsPath, whitelist, blacklist) =>
|
|
|
2277
2359
|
|
|
2278
2360
|
const header = makeHeader(metadataFilePath, revisionFilePath, config.expires);
|
|
2279
2361
|
|
|
2280
|
-
const platformDir = path.join(platformsPath, config.path, PLATFORM_FILTERS_DIR);
|
|
2362
|
+
const platformDir = path$1.join(platformsPath, config.path, PLATFORM_FILTERS_DIR);
|
|
2281
2363
|
writeFilterRules(filterId, platformDir, config, header, rules, false);
|
|
2282
2364
|
|
|
2283
2365
|
// add '(Optimized)' to the '! Title:' for optimized filters
|
|
@@ -2343,13 +2425,13 @@ const parseDirectory$1 = async (
|
|
|
2343
2425
|
blacklist,
|
|
2344
2426
|
obsoleteFiltersMetadata,
|
|
2345
2427
|
) => {
|
|
2346
|
-
const items = fs.readdirSync(filtersDir);
|
|
2428
|
+
const items = fs$1.readdirSync(filtersDir);
|
|
2347
2429
|
// eslint-disable-next-line no-restricted-syntax
|
|
2348
2430
|
for (const directory of items) {
|
|
2349
|
-
const filterDir = path.join(filtersDir, directory);
|
|
2350
|
-
if (fs.lstatSync(filterDir).isDirectory()) {
|
|
2351
|
-
const metadataFilePath = path.join(filterDir, metadataFile);
|
|
2352
|
-
if (fs.existsSync(metadataFilePath)) {
|
|
2431
|
+
const filterDir = path$1.join(filtersDir, directory);
|
|
2432
|
+
if (fs$1.lstatSync(filterDir).isDirectory()) {
|
|
2433
|
+
const metadataFilePath = path$1.join(filterDir, metadataFile);
|
|
2434
|
+
if (fs$1.existsSync(metadataFilePath)) {
|
|
2353
2435
|
logger.info(`Building filter platforms: ${directory}`);
|
|
2354
2436
|
// eslint-disable-next-line no-await-in-loop
|
|
2355
2437
|
await buildFilter$1(filterDir, platformsPath, whitelist, blacklist);
|
|
@@ -2467,7 +2549,7 @@ const skipFilter = (metadata) => {
|
|
|
2467
2549
|
*/
|
|
2468
2550
|
const create = (reportPath) => {
|
|
2469
2551
|
if (reportPath) {
|
|
2470
|
-
fs.writeFileSync(reportPath, reportData, 'utf8');
|
|
2552
|
+
fs$1.writeFileSync(reportPath, reportData, 'utf8');
|
|
2471
2553
|
return;
|
|
2472
2554
|
}
|
|
2473
2555
|
log(reportData);
|
|
@@ -2629,7 +2711,7 @@ const optimizeDomainBlockingRules = async (lines) => {
|
|
|
2629
2711
|
/* eslint-disable global-require */
|
|
2630
2712
|
|
|
2631
2713
|
|
|
2632
|
-
const __dirname$3 = path.dirname(new URL((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname);
|
|
2714
|
+
const __dirname$3 = path$1.dirname(new URL((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname);
|
|
2633
2715
|
|
|
2634
2716
|
const TEMPLATE_FILE = 'template.txt';
|
|
2635
2717
|
const FILTER_FILE = 'filter.txt';
|
|
@@ -2670,11 +2752,11 @@ const DIFF_PATH_TAG = 'Diff-Path:';
|
|
|
2670
2752
|
* @returns {*}
|
|
2671
2753
|
*/
|
|
2672
2754
|
const readFile$1 = function (path) {
|
|
2673
|
-
if (!fs.existsSync(path)) {
|
|
2755
|
+
if (!fs$1.existsSync(path)) {
|
|
2674
2756
|
return null;
|
|
2675
2757
|
}
|
|
2676
2758
|
|
|
2677
|
-
return fs.readFileSync(path, { encoding: 'utf-8' });
|
|
2759
|
+
return fs$1.readFileSync(path, { encoding: 'utf-8' });
|
|
2678
2760
|
};
|
|
2679
2761
|
|
|
2680
2762
|
/**
|
|
@@ -2684,7 +2766,7 @@ const readFile$1 = function (path) {
|
|
|
2684
2766
|
* @param data
|
|
2685
2767
|
*/
|
|
2686
2768
|
const writeFile = function (path, data) {
|
|
2687
|
-
fs.writeFileSync(path, data, 'utf8');
|
|
2769
|
+
fs$1.writeFileSync(path, data, 'utf8');
|
|
2688
2770
|
};
|
|
2689
2771
|
|
|
2690
2772
|
/**
|
|
@@ -2839,7 +2921,7 @@ const exclude = function (lines, exclusionsFile, excluded) {
|
|
|
2839
2921
|
|
|
2840
2922
|
exclusions = splitLines(exclusions);
|
|
2841
2923
|
|
|
2842
|
-
const exclusionsFileName = path.parse(exclusionsFile).base;
|
|
2924
|
+
const exclusionsFileName = path$1.parse(exclusionsFile).base;
|
|
2843
2925
|
const result = [];
|
|
2844
2926
|
|
|
2845
2927
|
lines.forEach((line, pos) => {
|
|
@@ -2982,7 +3064,7 @@ const include = async (filterDir, directiveLine, excluded) => {
|
|
|
2982
3064
|
|
|
2983
3065
|
const included = externalInclude
|
|
2984
3066
|
? downloadFile(url)
|
|
2985
|
-
: readFile$1(path.join(filterDir, url));
|
|
3067
|
+
: readFile$1(path$1.join(filterDir, url));
|
|
2986
3068
|
|
|
2987
3069
|
if (included) {
|
|
2988
3070
|
includedLines = splitLines(included);
|
|
@@ -3003,7 +3085,7 @@ const include = async (filterDir, directiveLine, excluded) => {
|
|
|
3003
3085
|
let optionsExcludePath;
|
|
3004
3086
|
switch (name) {
|
|
3005
3087
|
case EXCLUDE_OPTION:
|
|
3006
|
-
optionsExcludePath = path.join(filterDir, value);
|
|
3088
|
+
optionsExcludePath = path$1.join(filterDir, value);
|
|
3007
3089
|
includedLines = exclude(includedLines, optionsExcludePath, excluded);
|
|
3008
3090
|
break;
|
|
3009
3091
|
case STRIP_COMMENTS_OPTION:
|
|
@@ -3062,7 +3144,7 @@ const getResolvedPreprocessorIncludes = async function (filterDir, filterName, l
|
|
|
3062
3144
|
try {
|
|
3063
3145
|
rules = await filtersDownloader.FiltersDownloader.resolveIncludes(lines, filterDir);
|
|
3064
3146
|
} catch (e) {
|
|
3065
|
-
logger.
|
|
3147
|
+
logger.error(`Error resolving includes in ${filterName}: ${e.message}`);
|
|
3066
3148
|
}
|
|
3067
3149
|
return rules;
|
|
3068
3150
|
};
|
|
@@ -3178,7 +3260,7 @@ const compile$1 = async function (filterDir, filterName, templateContent, trustL
|
|
|
3178
3260
|
|
|
3179
3261
|
result = result.filter((line) => !isDiffPathHeaderTag(line));
|
|
3180
3262
|
|
|
3181
|
-
const excludeFilePath = path.join(filterDir, EXCLUDE_FILE);
|
|
3263
|
+
const excludeFilePath = path$1.join(filterDir, EXCLUDE_FILE);
|
|
3182
3264
|
result = exclude(result, excludeFilePath, excluded);
|
|
3183
3265
|
|
|
3184
3266
|
result = validateAndFilterRules(result, excluded, invalid, filterName);
|
|
@@ -3234,15 +3316,22 @@ const makeRevision = function (path, hash) {
|
|
|
3234
3316
|
* @returns {Promise<void>} A promise that resolves when all filters and its subdirectories have been processed.
|
|
3235
3317
|
*/
|
|
3236
3318
|
const buildFilter = async function (filterDir, whitelist, blacklist) {
|
|
3237
|
-
const templateContent = readFile$1(path.join(filterDir, TEMPLATE_FILE));
|
|
3319
|
+
const templateContent = readFile$1(path$1.join(filterDir, TEMPLATE_FILE));
|
|
3238
3320
|
if (!templateContent) {
|
|
3239
3321
|
throw new Error('Invalid template');
|
|
3240
3322
|
}
|
|
3241
3323
|
|
|
3242
|
-
const metadata = JSON.parse(readFile$1(path.join(filterDir, METADATA_FILE)));
|
|
3324
|
+
const metadata = JSON.parse(readFile$1(path$1.join(filterDir, METADATA_FILE)));
|
|
3243
3325
|
|
|
3244
3326
|
const { filterId } = metadata;
|
|
3245
3327
|
|
|
3328
|
+
// check whether the filter is disabled after other checks to avoid unnecessary logging
|
|
3329
|
+
if (metadata.disabled) {
|
|
3330
|
+
logger.warn(`Filter ${filterId} skipped as disabled`);
|
|
3331
|
+
skipFilter(metadata);
|
|
3332
|
+
return;
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3246
3335
|
if (whitelist && whitelist.length > 0 && whitelist.indexOf(filterId) < 0) {
|
|
3247
3336
|
logger.info(`Filter ${filterId} skipped due to '--include' option`);
|
|
3248
3337
|
return;
|
|
@@ -3253,16 +3342,9 @@ const buildFilter = async function (filterDir, whitelist, blacklist) {
|
|
|
3253
3342
|
return;
|
|
3254
3343
|
}
|
|
3255
3344
|
|
|
3256
|
-
// check whether the filter is disabled after other checks to avoid unnecessary logging
|
|
3257
|
-
if (metadata.disabled) {
|
|
3258
|
-
logger.warn(`Filter ${filterId} skipped as disabled`);
|
|
3259
|
-
skipFilter(metadata);
|
|
3260
|
-
return;
|
|
3261
|
-
}
|
|
3262
|
-
|
|
3263
3345
|
const trustLevel = metadata.trustLevel ? metadata.trustLevel : DEFAULT_TRUST_LEVEL;
|
|
3264
3346
|
// eslint-disable-next-line no-undef
|
|
3265
|
-
const trustLevelSettings = path.resolve(__dirname$3, TRUST_LEVEL_DIR, `exclusions-${trustLevel}.txt`);
|
|
3347
|
+
const trustLevelSettings = path$1.resolve(__dirname$3, TRUST_LEVEL_DIR, `exclusions-${trustLevel}.txt`);
|
|
3266
3348
|
|
|
3267
3349
|
const { name: filterName } = metadata;
|
|
3268
3350
|
logger.info(`Compiling ${filterName}`);
|
|
@@ -3282,14 +3364,14 @@ const buildFilter = async function (filterDir, whitelist, blacklist) {
|
|
|
3282
3364
|
const compiledData = compiled.join('\r\n');
|
|
3283
3365
|
|
|
3284
3366
|
logger.info(`Writing filter file, lines:${compiled.length}`);
|
|
3285
|
-
writeFile(path.join(filterDir, FILTER_FILE), compiledData);
|
|
3367
|
+
writeFile(path$1.join(filterDir, FILTER_FILE), compiledData);
|
|
3286
3368
|
logger.info(`Writing excluded file, lines:${excluded.length}`);
|
|
3287
|
-
writeFile(path.join(filterDir, EXCLUDED_LINES_FILE), excluded.join('\r\n'));
|
|
3369
|
+
writeFile(path$1.join(filterDir, EXCLUDED_LINES_FILE), excluded.join('\r\n'));
|
|
3288
3370
|
logger.info('Writing revision file..');
|
|
3289
3371
|
|
|
3290
3372
|
// eslint-disable-next-line no-buffer-constructor
|
|
3291
3373
|
const hash = Buffer.from(md5(compiledData, { asString: true })).toString('base64').trim();
|
|
3292
|
-
const revisionFile = path.join(filterDir, REVISION_FILE);
|
|
3374
|
+
const revisionFile = path$1.join(filterDir, REVISION_FILE);
|
|
3293
3375
|
const revision = makeRevision(revisionFile, hash);
|
|
3294
3376
|
writeFile(revisionFile, JSON.stringify(revision, null, '\t'));
|
|
3295
3377
|
};
|
|
@@ -3303,15 +3385,15 @@ const buildFilter = async function (filterDir, whitelist, blacklist) {
|
|
|
3303
3385
|
* @returns {Promise<void>} A promise that resolves when all filters and its subdirectories have been processed.
|
|
3304
3386
|
*/
|
|
3305
3387
|
const parseDirectory = async function (filtersDir, whitelist, blacklist) {
|
|
3306
|
-
const items = fs.readdirSync(filtersDir)
|
|
3388
|
+
const items = fs$1.readdirSync(filtersDir)
|
|
3307
3389
|
.sort((a, b) => getFilterIdFromDirName(a) - getFilterIdFromDirName(b));
|
|
3308
3390
|
|
|
3309
3391
|
// eslint-disable-next-line no-restricted-syntax
|
|
3310
3392
|
for (const directory of items) {
|
|
3311
|
-
const filterDir = path.join(filtersDir, directory);
|
|
3312
|
-
if (fs.lstatSync(filterDir).isDirectory()) {
|
|
3313
|
-
const template = path.join(filterDir, TEMPLATE_FILE);
|
|
3314
|
-
if (fs.existsSync(template)) {
|
|
3393
|
+
const filterDir = path$1.join(filtersDir, directory);
|
|
3394
|
+
if (fs$1.lstatSync(filterDir).isDirectory()) {
|
|
3395
|
+
const template = path$1.join(filterDir, TEMPLATE_FILE);
|
|
3396
|
+
if (fs$1.existsSync(template)) {
|
|
3315
3397
|
logger.info(`Building filter ${directory}...`);
|
|
3316
3398
|
// eslint-disable-next-line no-await-in-loop
|
|
3317
3399
|
await buildFilter(filterDir, whitelist, blacklist);
|
|
@@ -3374,14 +3456,14 @@ const OLD_MAC_V2_PLATFORM = 'mac_v2';
|
|
|
3374
3456
|
const loadSchemas = (dir) => {
|
|
3375
3457
|
const schemas = {};
|
|
3376
3458
|
|
|
3377
|
-
const items = fs.readdirSync(dir);
|
|
3459
|
+
const items = fs$1.readdirSync(dir);
|
|
3378
3460
|
// eslint-disable-next-line no-restricted-syntax
|
|
3379
3461
|
for (const f of items) {
|
|
3380
3462
|
if (f.endsWith(SCHEMA_EXTENSION)) {
|
|
3381
3463
|
const validationFileName = f.substr(0, f.indexOf(SCHEMA_EXTENSION));
|
|
3382
3464
|
|
|
3383
3465
|
logger.info(`Loading schema for ${validationFileName}`);
|
|
3384
|
-
schemas[validationFileName] = JSON.parse(fs.readFileSync(path.join(dir, f)));
|
|
3466
|
+
schemas[validationFileName] = JSON.parse(fs$1.readFileSync(path$1.join(dir, f)));
|
|
3385
3467
|
}
|
|
3386
3468
|
}
|
|
3387
3469
|
|
|
@@ -3401,30 +3483,30 @@ const loadSchemas = (dir) => {
|
|
|
3401
3483
|
const validateDir = (dir, validator, schemas, oldSchemas, filtersRequiredAmount) => {
|
|
3402
3484
|
let items;
|
|
3403
3485
|
try {
|
|
3404
|
-
items = fs.readdirSync(dir);
|
|
3486
|
+
items = fs$1.readdirSync(dir);
|
|
3405
3487
|
} catch (e) {
|
|
3406
3488
|
logger.info(e.message);
|
|
3407
3489
|
return false;
|
|
3408
3490
|
}
|
|
3409
3491
|
// eslint-disable-next-line no-restricted-syntax
|
|
3410
3492
|
for (const f of items) {
|
|
3411
|
-
const item = path.join(dir, f);
|
|
3412
|
-
if (fs.lstatSync(item).isDirectory()) {
|
|
3493
|
+
const item = path$1.join(dir, f);
|
|
3494
|
+
if (fs$1.lstatSync(item).isDirectory()) {
|
|
3413
3495
|
if (!validateDir(item, validator, schemas, oldSchemas)) {
|
|
3414
3496
|
return false;
|
|
3415
3497
|
}
|
|
3416
3498
|
} else {
|
|
3417
|
-
const fileName = path.basename(item, '.json');
|
|
3499
|
+
const fileName = path$1.basename(item, '.json');
|
|
3418
3500
|
let schema = schemas[fileName];
|
|
3419
3501
|
|
|
3420
3502
|
// Validate `mac` (mac v1) dir with old schemas
|
|
3421
|
-
if (path.basename(path.dirname(item)) === OLD_MAC_V1_PLATFORM) {
|
|
3503
|
+
if (path$1.basename(path$1.dirname(item)) === OLD_MAC_V1_PLATFORM) {
|
|
3422
3504
|
logger.info('Look up old schemas for mac directory');
|
|
3423
3505
|
schema = oldSchemas[OLD_MAC_V1_PLATFORM][fileName];
|
|
3424
3506
|
}
|
|
3425
3507
|
|
|
3426
3508
|
// Validate `mac_v2` dir with old schemas
|
|
3427
|
-
if (path.basename(path.dirname(item)) === OLD_MAC_V2_PLATFORM) {
|
|
3509
|
+
if (path$1.basename(path$1.dirname(item)) === OLD_MAC_V2_PLATFORM) {
|
|
3428
3510
|
logger.info('Look up old schemas for mac_v2 directory');
|
|
3429
3511
|
schema = oldSchemas[OLD_MAC_V2_PLATFORM][fileName];
|
|
3430
3512
|
}
|
|
@@ -3432,7 +3514,7 @@ const validateDir = (dir, validator, schemas, oldSchemas, filtersRequiredAmount)
|
|
|
3432
3514
|
if (schema) {
|
|
3433
3515
|
logger.info(`Validating ${item}`);
|
|
3434
3516
|
|
|
3435
|
-
const json = JSON.parse(fs.readFileSync(item));
|
|
3517
|
+
const json = JSON.parse(fs$1.readFileSync(item));
|
|
3436
3518
|
|
|
3437
3519
|
// Validate filters amount
|
|
3438
3520
|
if (fileName === 'filters') {
|
|
@@ -3446,12 +3528,12 @@ const validateDir = (dir, validator, schemas, oldSchemas, filtersRequiredAmount)
|
|
|
3446
3528
|
const valid = validate(json);
|
|
3447
3529
|
|
|
3448
3530
|
// json can be updated with default values
|
|
3449
|
-
fs.writeFileSync(item, JSON.stringify(json, null, '\t'));
|
|
3531
|
+
fs$1.writeFileSync(item, JSON.stringify(json, null, '\t'));
|
|
3450
3532
|
|
|
3451
3533
|
// duplicate to .js file as well
|
|
3452
3534
|
const jsFileName = `${fileName}.js`;
|
|
3453
|
-
fs.writeFileSync(
|
|
3454
|
-
path.join(path.dirname(item), jsFileName),
|
|
3535
|
+
fs$1.writeFileSync(
|
|
3536
|
+
path$1.join(path$1.dirname(item), jsFileName),
|
|
3455
3537
|
JSON.stringify(json, null, '\t'),
|
|
3456
3538
|
);
|
|
3457
3539
|
|
|
@@ -3479,8 +3561,8 @@ const validate$1 = (platformsPath, jsonSchemasConfigDir, filtersRequiredAmount)
|
|
|
3479
3561
|
|
|
3480
3562
|
const schemas = loadSchemas(jsonSchemasConfigDir);
|
|
3481
3563
|
|
|
3482
|
-
const oldSchemasMacV1 = loadSchemas(path.join(jsonSchemasConfigDir, OLD_MAC_V1_PLATFORM));
|
|
3483
|
-
const oldSchemasMacV2 = loadSchemas(path.join(jsonSchemasConfigDir, OLD_MAC_V2_PLATFORM));
|
|
3564
|
+
const oldSchemasMacV1 = loadSchemas(path$1.join(jsonSchemasConfigDir, OLD_MAC_V1_PLATFORM));
|
|
3565
|
+
const oldSchemasMacV2 = loadSchemas(path$1.join(jsonSchemasConfigDir, OLD_MAC_V2_PLATFORM));
|
|
3484
3566
|
const oldSchemas = {
|
|
3485
3567
|
[OLD_MAC_V1_PLATFORM]: oldSchemasMacV1,
|
|
3486
3568
|
[OLD_MAC_V2_PLATFORM]: oldSchemasMacV2,
|
|
@@ -3503,7 +3585,7 @@ const schemaValidator = { validate: validate$1 };
|
|
|
3503
3585
|
|
|
3504
3586
|
/* eslint-disable global-require */
|
|
3505
3587
|
|
|
3506
|
-
const __dirname$2 = path.dirname(new URL((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname);
|
|
3588
|
+
const __dirname$2 = path$1.dirname(new URL((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname);
|
|
3507
3589
|
|
|
3508
3590
|
/**
|
|
3509
3591
|
* Each filter, group, tag should have two keys.
|
|
@@ -3541,13 +3623,13 @@ const WARNING_TYPES = {
|
|
|
3541
3623
|
* Sync reads file content
|
|
3542
3624
|
* @param filePath - path to locales file
|
|
3543
3625
|
*/
|
|
3544
|
-
const readFile = (filePath) => fs.readFileSync(path.resolve(__dirname$2, filePath), 'utf8');
|
|
3626
|
+
const readFile = (filePath) => fs$1.readFileSync(path$1.resolve(__dirname$2, filePath), 'utf8');
|
|
3545
3627
|
|
|
3546
3628
|
/**
|
|
3547
3629
|
* Sync reads directory content
|
|
3548
3630
|
* @param dirPath - path to directory
|
|
3549
3631
|
*/
|
|
3550
|
-
const readDir = (dirPath) => fs.readdirSync(path.resolve(__dirname$2, dirPath), 'utf8');
|
|
3632
|
+
const readDir = (dirPath) => fs$1.readdirSync(path$1.resolve(__dirname$2, dirPath), 'utf8');
|
|
3551
3633
|
|
|
3552
3634
|
/**
|
|
3553
3635
|
* Validates messages keys
|
|
@@ -3592,11 +3674,11 @@ const prepareWarningDetails = (obj) => Object.entries(obj).map(([key, value]) =>
|
|
|
3592
3674
|
const getBaseLocaleKeys = (dirPath) => {
|
|
3593
3675
|
const baseLocaleKeys = {};
|
|
3594
3676
|
|
|
3595
|
-
const baseLocalePath = path.join(dirPath, BASE_LOCALE);
|
|
3677
|
+
const baseLocalePath = path$1.join(dirPath, BASE_LOCALE);
|
|
3596
3678
|
const baseLocaleFiles = readDir(baseLocalePath);
|
|
3597
3679
|
|
|
3598
3680
|
baseLocaleFiles.forEach((fileName) => {
|
|
3599
|
-
const baseLocaleData = JSON.parse(readFile(path.join(baseLocalePath, fileName)));
|
|
3681
|
+
const baseLocaleData = JSON.parse(readFile(path$1.join(baseLocalePath, fileName)));
|
|
3600
3682
|
baseLocaleKeys[fileName] = baseLocaleData.flatMap((entry) => Object.keys(entry));
|
|
3601
3683
|
});
|
|
3602
3684
|
return baseLocaleKeys;
|
|
@@ -3692,7 +3774,7 @@ const validate = (dirPath, requiredLocales) => {
|
|
|
3692
3774
|
|
|
3693
3775
|
locales.forEach((locale) => {
|
|
3694
3776
|
const localeWarnings = [];
|
|
3695
|
-
const filesList = readDir(path.join(dirPath, locale));
|
|
3777
|
+
const filesList = readDir(path$1.join(dirPath, locale));
|
|
3696
3778
|
// checks all needed files presence
|
|
3697
3779
|
const missedFiles = REQUIRED_FILES
|
|
3698
3780
|
.filter((el) => !filesList.includes(el));
|
|
@@ -3710,7 +3792,7 @@ const validate = (dirPath, requiredLocales) => {
|
|
|
3710
3792
|
|
|
3711
3793
|
// iterate over existent files
|
|
3712
3794
|
presentFiles.forEach((fileName) => {
|
|
3713
|
-
const messagesPath = path.join(dirPath, locale, fileName);
|
|
3795
|
+
const messagesPath = path$1.join(dirPath, locale, fileName);
|
|
3714
3796
|
let messagesData;
|
|
3715
3797
|
try {
|
|
3716
3798
|
messagesData = JSON.parse(readFile(messagesPath));
|
|
@@ -4637,9 +4719,9 @@ const platformsConfig = {
|
|
|
4637
4719
|
// Sets configuration compatibility
|
|
4638
4720
|
tsurlfilter.setConfiguration({ compatibility: tsurlfilter.CompatibilityTypes.Corelibs });
|
|
4639
4721
|
|
|
4640
|
-
const __dirname$1 = path.dirname(new URL((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname);
|
|
4722
|
+
const __dirname$1 = path$1.dirname(new URL((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname);
|
|
4641
4723
|
|
|
4642
|
-
const jsonSchemasConfigDir = path.join(__dirname$1, './schemas/');
|
|
4724
|
+
const jsonSchemasConfigDir = path$1.join(__dirname$1, './schemas/');
|
|
4643
4725
|
|
|
4644
4726
|
process.on('unhandledRejection', (error) => {
|
|
4645
4727
|
throw error;
|