Add ts-check to build script

This commit is contained in:
SukkaW 2023-06-01 10:52:24 +08:00
parent a1cccf9c88
commit 9a307709a5
7 changed files with 25 additions and 2 deletions

View File

@ -1,3 +1,4 @@
// @ts-check
const { fetch } = require('undici');
const fetchWithRetry = require('@vercel/fetch-retry')(fetch);
module.exports.fetchWithRetry = fetchWithRetry;

View File

@ -1,10 +1,16 @@
// @ts-check
const { parse } = require('tldts');
/**
* @param {string} domain
*/
module.exports.isDomainLoose = (domain) => {
const { isIcann, isPrivate, isIp } = parse(domain, { allowPrivateDomains: true });
return !!(!isIp && (isIcann || isPrivate));
};
/**
* @param {string} domain
*/
module.exports.normalizeDomain = (domain) => {
if (domain == null) {
return null;

View File

@ -1,3 +1,4 @@
// @ts-check
const { fetchWithRetry } = require('./fetch-retry');
const { NetworkFilter } = require('@cliqz/adblocker');
const { normalizeDomain } = require('./is-domain-loose');

View File

@ -1,3 +1,4 @@
// @ts-check
/** @type {[string, boolean][]} */
const HOSTS = [
['https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext', true],

View File

@ -1,5 +1,10 @@
// @ts-check
const { promises: fsPromises } = require('fs');
/**
* @param {string[]} linesA
* @param {string} filePath
*/
async function compareAndWriteFile(linesA, filePath) {
const linesB = (await fsPromises.readFile(filePath, { encoding: 'utf-8' })).split('\n');
@ -14,6 +19,10 @@ async function compareAndWriteFile(linesA, filePath) {
}
}
/**
* @param {string[]} linesA
* @param {string[]} linesB
*/
function stringArrayCompare (linesA, linesB) {
if (linesA.length !== linesB.length) return false;

View File

@ -1,3 +1,5 @@
// @ts-check
/**
* @param {string} title
* @param {string[]} description

View File

@ -1,3 +1,4 @@
// @ts-check
const Piscina = require('piscina');
// const { isCI } = require('ci-info');
@ -5,7 +6,9 @@ const fullsetDomainStartsWithADot = Piscina.workerData
const totalLen = fullsetDomainStartsWithADot.length;
// const log = isCI ? () => { } : console.log.bind(console);
/**
* @param {{ chunk: string[] }} param0
*/
module.exports = ({ chunk }) => {
const chunkLength = chunk.length;
const outputToBeRemoved = new Int8Array(chunkLength);