mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-14 02:00:37 +08:00
Chore: some minor changes
This commit is contained in:
parent
af04018be9
commit
d87c01ce5a
@ -7,8 +7,9 @@ import { appendArrayInPlace } from './lib/append-array-in-place';
|
|||||||
import { SOURCE_DIR } from './constants/dir';
|
import { SOURCE_DIR } from './constants/dir';
|
||||||
import { DomainsetOutput } from './lib/create-file';
|
import { DomainsetOutput } from './lib/create-file';
|
||||||
import { CRASHLYTICS_WHITELIST } from './constants/reject-data-source';
|
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();
|
const trie = new HostnameTrie();
|
||||||
|
|
||||||
for await (const line of await fetchRemoteTextByLine('https://publicsuffix.org/list/public_suffix_list.dat', true)) {
|
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) => {
|
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
|
// Move S3 domains to download domain set, since S3 files may be large
|
||||||
appendArrayInPlace(downloadDomainSet, S3OSSDomains);
|
appendSetElementsToArray(downloadDomainSet, S3OSSDomains);
|
||||||
appendArrayInPlace(downloadDomainSet, steamDomainSet);
|
appendArrayInPlace(downloadDomainSet, steamDomainSet);
|
||||||
|
|
||||||
// we have whitelisted the crashlytics domain, and we also want to put it in CDN policy
|
// we have whitelisted the crashlytics domain, and we also want to put it in CDN policy
|
||||||
|
|||||||
@ -145,7 +145,7 @@ async function transformRuleset(parentSpan: Span, sourcePath: string, relativePa
|
|||||||
if (res === $skip) return;
|
if (res === $skip) return;
|
||||||
|
|
||||||
const id = basename;
|
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') {
|
if (type !== 'ip' && type !== 'non_ip') {
|
||||||
throw new TypeError(`Invalid type: ${type}`);
|
throw new TypeError(`Invalid type: ${type}`);
|
||||||
|
|||||||
@ -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 { OUTPUT_MOCK_DIR, OUTPUT_MODULES_DIR, PUBLIC_DIR, ROOT_DIR } from './constants/dir';
|
||||||
import { fastStringCompare, mkdirp, writeFile } from './lib/misc';
|
import { fastStringCompare, mkdirp, writeFile } from './lib/misc';
|
||||||
import picocolors from 'picocolors';
|
import picocolors from 'picocolors';
|
||||||
|
import { tagged as html } from 'foxts/tagged';
|
||||||
import { compareAndWriteFile } from './lib/create-file';
|
import { compareAndWriteFile } from './lib/create-file';
|
||||||
|
|
||||||
const mockDir = path.join(ROOT_DIR, 'Mock');
|
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 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) {
|
function walk(tree: TreeTypeArray) {
|
||||||
let result = '';
|
let result = '';
|
||||||
tree.sort(prioritySorter);
|
tree.sort(prioritySorter);
|
||||||
|
|||||||
@ -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',
|
'! 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')
|
path.join(OUTPUT_INTERNAL_DIR, 'reject-adguardhome.txt')
|
||||||
)
|
)
|
||||||
|
|||||||
@ -22,7 +22,7 @@ export class IPListOutput extends RuleOutput<Preprocessed> {
|
|||||||
appendArrayInPlace(
|
appendArrayInPlace(
|
||||||
results,
|
results,
|
||||||
merge(
|
merge(
|
||||||
appendArrayInPlace(Array.from(this.ipcidrNoResolve), Array.from(this.ipcidr)),
|
appendSetElementsToArray(Array.from(this.ipcidrNoResolve), this.ipcidr),
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@ -61,7 +61,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
|
|||||||
|
|
||||||
appendArrayInPlace(
|
appendArrayInPlace(
|
||||||
results,
|
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.ipcidr6NoResolve, i => `IP-CIDR6,${i},no-resolve`);
|
||||||
appendSetElementsToArray(results, this.ipasnNoResolve, i => `IP-ASN,${i},no-resolve`);
|
appendSetElementsToArray(results, this.ipasnNoResolve, i => `IP-ASN,${i},no-resolve`);
|
||||||
@ -69,7 +69,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
|
|||||||
|
|
||||||
appendArrayInPlace(
|
appendArrayInPlace(
|
||||||
results,
|
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.ipcidr6, i => `IP-CIDR6,${i}`);
|
||||||
appendSetElementsToArray(results, this.ipasn, i => `IP-ASN,${i}`);
|
appendSetElementsToArray(results, this.ipasn, i => `IP-ASN,${i}`);
|
||||||
@ -108,7 +108,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
|
|||||||
|
|
||||||
appendArrayInPlace(
|
appendArrayInPlace(
|
||||||
results,
|
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.ipcidr6NoResolve, i => `IP-CIDR6,${i},no-resolve`);
|
||||||
appendSetElementsToArray(results, this.ipasnNoResolve, i => `IP-ASN,${i},no-resolve`);
|
appendSetElementsToArray(results, this.ipasnNoResolve, i => `IP-ASN,${i},no-resolve`);
|
||||||
@ -116,7 +116,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
|
|||||||
|
|
||||||
appendArrayInPlace(
|
appendArrayInPlace(
|
||||||
results,
|
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.ipcidr6, i => `IP-CIDR6,${i}`);
|
||||||
appendSetElementsToArray(results, this.ipasn, i => `IP-ASN,${i}`);
|
appendSetElementsToArray(results, this.ipasn, i => `IP-ASN,${i}`);
|
||||||
@ -130,7 +130,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
|
|||||||
appendArrayInPlace(
|
appendArrayInPlace(
|
||||||
ip_cidr,
|
ip_cidr,
|
||||||
merge(
|
merge(
|
||||||
appendArrayInPlace(Array.from(this.ipcidrNoResolve), Array.from(this.ipcidr)),
|
appendSetElementsToArray(Array.from(this.ipcidrNoResolve), this.ipcidr),
|
||||||
true
|
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: appendArrayInPlace(['this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'], this.$preprocessed[0]),
|
||||||
domain_suffix: this.$preprocessed[1],
|
domain_suffix: this.$preprocessed[1],
|
||||||
domain_keyword: Array.from(this.domainKeywords),
|
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,
|
ip_cidr,
|
||||||
source_ip_cidr: [...this.sourceIpOrCidr].reduce<string[]>((acc, cur) => {
|
source_ip_cidr: [...this.sourceIpOrCidr].reduce<string[]>((acc, cur) => {
|
||||||
if (cur.includes('/')) {
|
if (cur.includes('/')) {
|
||||||
|
|||||||
@ -31,7 +31,7 @@
|
|||||||
"fast-cidr-tools": "^0.3.1",
|
"fast-cidr-tools": "^0.3.1",
|
||||||
"fast-fifo": "^1.3.2",
|
"fast-fifo": "^1.3.2",
|
||||||
"fdir": "^6.4.2",
|
"fdir": "^6.4.2",
|
||||||
"foxts": "^1.0.10",
|
"foxts": "^1.0.11",
|
||||||
"hash-wasm": "^4.12.0",
|
"hash-wasm": "^4.12.0",
|
||||||
"json-stringify-pretty-compact": "^3.0.0",
|
"json-stringify-pretty-compact": "^3.0.0",
|
||||||
"make-fetch-happen": "^14.0.3",
|
"make-fetch-happen": "^14.0.3",
|
||||||
|
|||||||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@ -45,8 +45,8 @@ importers:
|
|||||||
specifier: ^6.4.2
|
specifier: ^6.4.2
|
||||||
version: 6.4.2(picomatch@4.0.2)
|
version: 6.4.2(picomatch@4.0.2)
|
||||||
foxts:
|
foxts:
|
||||||
specifier: ^1.0.10
|
specifier: ^1.0.11
|
||||||
version: 1.0.10
|
version: 1.0.11
|
||||||
hash-wasm:
|
hash-wasm:
|
||||||
specifier: ^4.12.0
|
specifier: ^4.12.0
|
||||||
version: 4.12.0
|
version: 4.12.0
|
||||||
@ -1145,8 +1145,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==}
|
resolution: {integrity: sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==}
|
||||||
engines: {node: '>= 6'}
|
engines: {node: '>= 6'}
|
||||||
|
|
||||||
foxts@1.0.10:
|
foxts@1.0.11:
|
||||||
resolution: {integrity: sha512-yuZH9YLqXXB3QGYBEywnJs69Jl4E8xDPxNEy4vkSr/nqeKD4t2VCsqeTqPZKT3ZVZSpPmBa7y/0VLyUBMj8P/g==}
|
resolution: {integrity: sha512-yO5eV+OuORNzmRzxBjXRyLPRyac1mR5zog7+EhpTVDfV3mfP7JYLJjCRNJpLudCbCG6mmVM4b8z0AfgWRKKfYA==}
|
||||||
|
|
||||||
fs-constants@1.0.0:
|
fs-constants@1.0.0:
|
||||||
resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==}
|
resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==}
|
||||||
@ -3030,7 +3030,7 @@ snapshots:
|
|||||||
combined-stream: 1.0.8
|
combined-stream: 1.0.8
|
||||||
mime-types: 2.1.35
|
mime-types: 2.1.35
|
||||||
|
|
||||||
foxts@1.0.10: {}
|
foxts@1.0.11: {}
|
||||||
|
|
||||||
fs-constants@1.0.0: {}
|
fs-constants@1.0.0: {}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user