Chore: some minor changes

This commit is contained in:
SukkaW 2024-12-22 12:16:50 +08:00
parent af04018be9
commit d87c01ce5a
8 changed files with 20 additions and 20 deletions

View File

@ -7,8 +7,9 @@ import { appendArrayInPlace } from './lib/append-array-in-place';
import { SOURCE_DIR } from './constants/dir';
import { DomainsetOutput } from './lib/create-file';
import { CRASHLYTICS_WHITELIST } from './constants/reject-data-source';
import { appendSetElementsToArray } from 'foxts/append-set-elements-to-array';
const getS3OSSDomainsPromise = (async (): Promise<string[]> => {
const getS3OSSDomainsPromise = (async (): Promise<Set<string>> => {
const trie = new HostnameTrie();
for await (const line of await fetchRemoteTextByLine('https://publicsuffix.org/list/public_suffix_list.dat', true)) {
@ -44,7 +45,7 @@ const getS3OSSDomainsPromise = (async (): Promise<string[]> => {
}
});
return Array.from(S3OSSDomains);
return S3OSSDomains;
})();
export const buildCdnDownloadConf = task(require.main === module, __filename)(async (span) => {
@ -62,7 +63,7 @@ export const buildCdnDownloadConf = task(require.main === module, __filename)(as
]);
// Move S3 domains to download domain set, since S3 files may be large
appendArrayInPlace(downloadDomainSet, S3OSSDomains);
appendSetElementsToArray(downloadDomainSet, S3OSSDomains);
appendArrayInPlace(downloadDomainSet, steamDomainSet);
// we have whitelisted the crashlytics domain, and we also want to put it in CDN policy

View File

@ -145,7 +145,7 @@ async function transformRuleset(parentSpan: Span, sourcePath: string, relativePa
if (res === $skip) return;
const id = basename;
const [type] = relativePath.slice(0, -extname.length).split(path.sep);
const type = relativePath.slice(0, -extname.length).split(path.sep)[0];
if (type !== 'ip' && type !== 'non_ip') {
throw new TypeError(`Invalid type: ${type}`);

View File

@ -9,6 +9,7 @@ import type { TreeType, TreeTypeArray } from './lib/tree-dir';
import { OUTPUT_MOCK_DIR, OUTPUT_MODULES_DIR, PUBLIC_DIR, ROOT_DIR } from './constants/dir';
import { fastStringCompare, mkdirp, writeFile } from './lib/misc';
import picocolors from 'picocolors';
import { tagged as html } from 'foxts/tagged';
import { compareAndWriteFile } from './lib/create-file';
const mockDir = path.join(ROOT_DIR, 'Mock');
@ -94,8 +95,6 @@ const priorityOrder: Record<'default' | string & {}, number> = {
};
const prioritySorter = (a: TreeType, b: TreeType) => ((priorityOrder[a.name] || priorityOrder.default) - (priorityOrder[b.name] || priorityOrder.default)) || fastStringCompare(a.name, b.name);
const html = (string: TemplateStringsArray, ...values: any[]) => string.reduce((acc, str, i) => acc + str + (values[i] ?? ''), '');
function walk(tree: TreeTypeArray) {
let result = '';
tree.sort(prioritySorter);

View File

@ -164,7 +164,7 @@ export const buildRejectDomainSet = task(require.main === module, __filename)(as
'! Description: The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining',
'!'
],
rejectOutput.adguardhome(/* filterRuleWhitelistDomainSets */)
rejectOutput.adguardhome()
),
path.join(OUTPUT_INTERNAL_DIR, 'reject-adguardhome.txt')
)

View File

@ -22,7 +22,7 @@ export class IPListOutput extends RuleOutput<Preprocessed> {
appendArrayInPlace(
results,
merge(
appendArrayInPlace(Array.from(this.ipcidrNoResolve), Array.from(this.ipcidr)),
appendSetElementsToArray(Array.from(this.ipcidrNoResolve), this.ipcidr),
true
)
);

View File

@ -61,7 +61,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
appendArrayInPlace(
results,
merge(Array.from(this.ipcidrNoResolve)).map(i => `IP-CIDR,${i},no-resolve`, true)
merge(Array.from(this.ipcidrNoResolve), true).map(i => `IP-CIDR,${i},no-resolve`)
);
appendSetElementsToArray(results, this.ipcidr6NoResolve, i => `IP-CIDR6,${i},no-resolve`);
appendSetElementsToArray(results, this.ipasnNoResolve, i => `IP-ASN,${i},no-resolve`);
@ -69,7 +69,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
appendArrayInPlace(
results,
merge(Array.from(this.ipcidr)).map(i => `IP-CIDR,${i}`, true)
merge(Array.from(this.ipcidr), true).map(i => `IP-CIDR,${i}`)
);
appendSetElementsToArray(results, this.ipcidr6, i => `IP-CIDR6,${i}`);
appendSetElementsToArray(results, this.ipasn, i => `IP-ASN,${i}`);
@ -108,7 +108,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
appendArrayInPlace(
results,
merge(Array.from(this.ipcidrNoResolve)).map(i => `IP-CIDR,${i},no-resolve`, true)
merge(Array.from(this.ipcidrNoResolve), true).map(i => `IP-CIDR,${i},no-resolve`)
);
appendSetElementsToArray(results, this.ipcidr6NoResolve, i => `IP-CIDR6,${i},no-resolve`);
appendSetElementsToArray(results, this.ipasnNoResolve, i => `IP-ASN,${i},no-resolve`);
@ -116,7 +116,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
appendArrayInPlace(
results,
merge(Array.from(this.ipcidr)).map(i => `IP-CIDR,${i}`, true)
merge(Array.from(this.ipcidr), true).map(i => `IP-CIDR,${i}`)
);
appendSetElementsToArray(results, this.ipcidr6, i => `IP-CIDR6,${i}`);
appendSetElementsToArray(results, this.ipasn, i => `IP-ASN,${i}`);
@ -130,7 +130,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
appendArrayInPlace(
ip_cidr,
merge(
appendArrayInPlace(Array.from(this.ipcidrNoResolve), Array.from(this.ipcidr)),
appendSetElementsToArray(Array.from(this.ipcidrNoResolve), this.ipcidr),
true
)
);
@ -143,7 +143,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
domain: appendArrayInPlace(['this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'], this.$preprocessed[0]),
domain_suffix: this.$preprocessed[1],
domain_keyword: Array.from(this.domainKeywords),
domain_regex: Array.from(this.domainWildcard).map(RuleOutput.domainWildCardToRegex),
domain_regex: Array.from(this.domainWildcard, RuleOutput.domainWildCardToRegex),
ip_cidr,
source_ip_cidr: [...this.sourceIpOrCidr].reduce<string[]>((acc, cur) => {
if (cur.includes('/')) {

View File

@ -31,7 +31,7 @@
"fast-cidr-tools": "^0.3.1",
"fast-fifo": "^1.3.2",
"fdir": "^6.4.2",
"foxts": "^1.0.10",
"foxts": "^1.0.11",
"hash-wasm": "^4.12.0",
"json-stringify-pretty-compact": "^3.0.0",
"make-fetch-happen": "^14.0.3",

10
pnpm-lock.yaml generated
View File

@ -45,8 +45,8 @@ importers:
specifier: ^6.4.2
version: 6.4.2(picomatch@4.0.2)
foxts:
specifier: ^1.0.10
version: 1.0.10
specifier: ^1.0.11
version: 1.0.11
hash-wasm:
specifier: ^4.12.0
version: 4.12.0
@ -1145,8 +1145,8 @@ packages:
resolution: {integrity: sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==}
engines: {node: '>= 6'}
foxts@1.0.10:
resolution: {integrity: sha512-yuZH9YLqXXB3QGYBEywnJs69Jl4E8xDPxNEy4vkSr/nqeKD4t2VCsqeTqPZKT3ZVZSpPmBa7y/0VLyUBMj8P/g==}
foxts@1.0.11:
resolution: {integrity: sha512-yO5eV+OuORNzmRzxBjXRyLPRyac1mR5zog7+EhpTVDfV3mfP7JYLJjCRNJpLudCbCG6mmVM4b8z0AfgWRKKfYA==}
fs-constants@1.0.0:
resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==}
@ -3030,7 +3030,7 @@ snapshots:
combined-stream: 1.0.8
mime-types: 2.1.35
foxts@1.0.10: {}
foxts@1.0.11: {}
fs-constants@1.0.0: {}