Skip to content

Commit

Permalink
Chore: some minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Dec 22, 2024
1 parent af04018 commit d87c01c
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
7 changes: 4 additions & 3 deletions Build/build-cdn-download-conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Build/build-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
3 changes: 1 addition & 2 deletions Build/build-public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Build/build-reject-domainset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)
Expand Down
2 changes: 1 addition & 1 deletion Build/lib/rules/ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
Expand Down
12 changes: 6 additions & 6 deletions Build/lib/rules/ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ 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`);
appendSetElementsToArray(results, this.groipNoResolve, i => `GEOIP,${i},no-resolve`);

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}`);
Expand Down Expand Up @@ -108,15 +108,15 @@ 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`);
appendSetElementsToArray(results, this.groipNoResolve, i => `GEOIP,${i},no-resolve`);

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}`);
Expand All @@ -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
)
);
Expand All @@ -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('/')) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d87c01c

Please sign in to comment.