Minor Changes + Housekeeping

This commit is contained in:
SukkaW 2024-07-02 10:50:09 +08:00
parent b325f31990
commit dda0555c0b
8 changed files with 34 additions and 67 deletions

View File

@ -9,7 +9,7 @@ import { domainDeduper } from './lib/domain-deduper';
import { appendArrayInPlace } from './lib/append-array-in-place';
import { sortDomains } from './lib/stable-sort-domain';
const getS3OSSDomainsPromise = (async (): Promise<Set<string>> => {
const getS3OSSDomainsPromise = (async (): Promise<string[]> => {
const trie = createTrie(
(await getPublicSuffixListTextPromise()).split('\n'),
true,
@ -45,7 +45,7 @@ const getS3OSSDomainsPromise = (async (): Promise<Set<string>> => {
}
});
return S3OSSDomains;
return Array.from(S3OSSDomains);
})();
export const buildCdnDownloadConf = task(import.meta.main, import.meta.path)(async (span) => {
@ -62,7 +62,7 @@ export const buildCdnDownloadConf = task(import.meta.main, import.meta.path)(asy
readFileIntoProcessedArray(path.resolve(import.meta.dir, '../Source/domainset/steam.conf'))
]);
appendArrayInPlace(downloadDomainSet, Array.from(S3OSSDomains).map((domain) => `.${domain}`));
appendArrayInPlace(downloadDomainSet, S3OSSDomains.map(domain => `.${domain}`));
appendArrayInPlace(downloadDomainSet, steamDomainSet);
return Promise.all([

View File

@ -20,8 +20,8 @@ const s = new Sema(2);
const latestTopUserAgentsPromise = fsFetchCache.apply(
'https://cdn.jsdelivr.net/npm/top-user-agents@latest/src/desktop.json',
() => fetchWithRetry('https://cdn.jsdelivr.net/npm/top-user-agents@latest/src/desktop.json')
.then(res => res.json() as any)
.then((userAgents: string[]) => userAgents.filter(ua => ua.startsWith('Mozilla/5.0 '))),
.then(res => res.json() as Promise<string[]>)
.then((userAgents) => userAgents.filter(ua => ua.startsWith('Mozilla/5.0 '))),
{
serializer: serializeArray,
deserializer: deserializeArray,

View File

@ -13,35 +13,6 @@ const createNode = (): Node => {
return node;
};
const deepNodeToJSON = (node: Node, wset: WeakSet<Node>) => {
if (wset.has(node)) {
return 'circular';
}
wset.add(node);
const obj: Record<string, any> = {};
if (node[WORDEND]) {
obj['[end]'] = node[WORDEND];
}
node.forEach((value, key) => {
obj[key] = deepNodeToJSON(value, wset);
});
return obj;
};
function createNodeInspectCustom(node: Node) {
const wset = new WeakSet<Node>();
return () => {
try {
return JSON.stringify(deepNodeToJSON(node, wset), null, 2);
} catch (e) {
console.error(e);
return '';
}
};
}
const createKeywordFilter = (keys: string[] | Set<string>) => {
const root = createNode();
@ -92,7 +63,7 @@ const createKeywordFilter = (keys: string[] | Set<string>) => {
// };
// build();
const tester = (text: string) => {
return (text: string) => {
let node: Node | undefined = root;
for (let i = 0, textLen = text.length; i < textLen; i++) {
@ -111,10 +82,6 @@ const createKeywordFilter = (keys: string[] | Set<string>) => {
return false;
};
tester[Bun.inspect.custom] = createNodeInspectCustom(root);
return tester;
};
export default createKeywordFilter;

View File

@ -159,7 +159,7 @@ const MARK = 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe';
export const createRuleset = (
parentSpan: Span,
title: string, description: string[] | readonly string[], date: Date, content: string[],
type: 'ruleset' | 'domainset', surgePath: string, clashPath: string
type: ('ruleset' | 'domainset' | string & {}), surgePath: string, clashPath: string
) => parentSpan.traceChild(`create ruleset: ${path.basename(surgePath, path.extname(surgePath))}`).traceAsyncFn((childSpan) => {
const surgeContent = withBannerArray(
title, description, date,
@ -177,7 +177,7 @@ export const createRuleset = (
_clashContent = [`DOMAIN,${MARK}`, ...surgeRulesetToClashClassicalTextRuleset(content)];
break;
default:
throw new TypeError(`Unknown type: ${type as any}`);
throw new TypeError(`Unknown type: ${type}`);
}
return withBannerArray(title, description, date, _clashContent);
});

View File

@ -426,15 +426,15 @@ class TimSort<T> {
this.tmp = new Array(this.tmpStorageLength);
this.stackLength = (
this.length < 120
? 5
: this.length < 1542
? 10
: this.length < 119151
? 19
: 40
);
if (this.length < 120) {
this.stackLength = 5;
} else if (this.length < 1542) {
this.stackLength = 10;
} else if (this.length < 119151) {
this.stackLength = 19;
} else {
this.stackLength = 40;
}
this.runStart = new Array(this.stackLength);
this.runLength = new Array(this.stackLength);

View File

@ -166,19 +166,19 @@ function printTree(initialTree: TraceResult, printNode: (node: TraceResult, bran
}
function printStats(stats: TraceResult[]): void {
stats.sort((a, b) => a.start - b.start);
const longestTaskName = Math.max(...stats.map(i => i.name.length));
const realStart = Math.min(...stats.map(i => i.start));
const realEnd = Math.max(...stats.map(i => i.end));
const statsStep = ((realEnd - realStart) / 120) | 0;
stats.forEach(stat => {
console.log(
`[${stat.name}]${' '.repeat(longestTaskName - stat.name.length)}`,
' '.repeat(((stat.start - realStart) / statsStep) | 0),
'='.repeat(Math.max(((stat.end - stat.start) / statsStep) | 0, 1))
);
});
stats
.sort((a, b) => a.start - b.start)
.forEach(stat => {
console.log(
`[${stat.name}]${' '.repeat(longestTaskName - stat.name.length)}`,
' '.repeat(((stat.start - realStart) / statsStep) | 0),
'='.repeat(Math.max(((stat.end - stat.start) / statsStep) | 0, 1))
);
});
}

BIN
bun.lockb

Binary file not shown.

View File

@ -29,21 +29,21 @@
"punycode": "^2.3.1",
"table": "^6.8.2",
"tar-stream": "^3.1.7",
"tldts": "^6.1.29",
"tldts-experimental": "^6.1.29",
"tldts": "^6.1.30",
"tldts-experimental": "^6.1.30",
"yaml": "^2.4.5"
},
"devDependencies": {
"@eslint-sukka/node": "^6.0.0-beta.29",
"@eslint-sukka/node": "^6.0.0",
"@types/async-retry": "^1.4.8",
"@types/bun": "^1.1.5",
"@types/bun": "^1.1.6",
"@types/tar-stream": "^3.1.3",
"bun-types": "^1.1.17",
"eslint": "^9.5.0",
"eslint-config-sukka": "^6.0.0-beta.29",
"eslint-formatter-sukka": "^6.0.0-beta.29",
"eslint": "^9.6.0",
"eslint-config-sukka": "^6.0.0",
"eslint-formatter-sukka": "^6.0.0",
"mitata": "^0.1.11",
"typescript": "^5.5.2"
"typescript": "^5.5.3"
},
"resolutions": {
"has": "npm:@nolyfill/has@latest"