diff --git a/Build/build-cdn-conf.ts b/Build/build-cdn-conf.ts index 8d9e531b..b0c62c7b 100644 --- a/Build/build-cdn-conf.ts +++ b/Build/build-cdn-conf.ts @@ -13,7 +13,7 @@ const getS3OSSDomains = async (): Promise> => { const publicSuffixFile = Bun.file(publicSuffixPath); if (await publicSuffixFile.exists()) { - for await (const line of readFileByLine(publicSuffixPath)) { + for await (const line of readFileByLine(publicSuffixFile)) { trie.add(line); } } else { diff --git a/Build/download-previous-build.js b/Build/download-previous-build.ts similarity index 72% rename from Build/download-previous-build.js rename to Build/download-previous-build.ts index 87615bbf..5e7fd770 100644 --- a/Build/download-previous-build.js +++ b/Build/download-previous-build.ts @@ -1,15 +1,14 @@ -// @ts-check -const tar = require('tar'); -const fsp = require('fs/promises'); -const path = require('path'); -const { tmpdir } = require('os'); -const { Readable } = require('stream'); -const { pipeline } = require('stream/promises'); -const { readFileByLine } = require('./lib/fetch-remote-text-by-line'); -const { isCI } = require('ci-info'); -const { task, traceAsync } = require('./lib/trace-runner'); +import tar from 'tar'; +import fsp from 'fs/promises'; +import path from 'path'; +import os from 'os'; +import { Readable } from 'stream'; +import { pipeline } from 'stream/promises'; +import { readFileByLine } from './lib/fetch-remote-text-by-line'; +import { isCI } from 'ci-info'; +import { task, traceAsync } from './lib/trace-runner'; -const downloadPreviousBuild = task(__filename, async () => { +export const downloadPreviousBuild = task(__filename, async () => { const filesList = ['Clash', 'List']; let allFileExists = true; @@ -41,7 +40,7 @@ const downloadPreviousBuild = task(__filename, async () => { return; } - const extractedPath = path.join(tmpdir(), `sukka-surge-last-build-extracted-${Date.now()}`); + const extractedPath = path.join(os.tmpdir(), `sukka-surge-last-build-extracted-${Date.now()}`); await traceAsync( 'Download and extract previous build', @@ -49,7 +48,7 @@ const downloadPreviousBuild = task(__filename, async () => { fetch('https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master'), fsp.mkdir(extractedPath, { recursive: true }) ]).then(([resp]) => pipeline( - Readable.fromWeb(resp.body), + Readable.fromWeb(resp.body!), tar.x({ cwd: extractedPath, /** @@ -78,7 +77,7 @@ const downloadPreviousBuild = task(__filename, async () => { // return fsp.unlink(extractedPath).catch(() => { }); }); -const downloadPublicSuffixList = task(__filename, async () => { +export const downloadPublicSuffixList = task(__filename, async () => { const publicSuffixDir = path.resolve(__dirname, '../node_modules/.cache'); const publicSuffixPath = path.join(publicSuffixDir, 'public_suffix_list_dat.txt'); @@ -90,9 +89,6 @@ const downloadPublicSuffixList = task(__filename, async () => { return Bun.write(publicSuffixPath, resp); }, 'download-publicsuffixlist'); -module.exports.downloadPreviousBuild = downloadPreviousBuild; -module.exports.downloadPublicSuffixList = downloadPublicSuffixList; - if (import.meta.main) { Promise.all([ downloadPreviousBuild(), diff --git a/Build/lib/create-file.js b/Build/lib/create-file.js index 7126309d..ffc0e53e 100644 --- a/Build/lib/create-file.js +++ b/Build/lib/create-file.js @@ -19,7 +19,7 @@ async function compareAndWriteFile(linesA, filePath) { } else { let index = 0; - for await (const lineB of readFileByLine(filePath)) { + for await (const lineB of readFileByLine(file)) { const lineA = linesA[index]; index++; diff --git a/bun.lockb b/bun.lockb index 810feff1..7ea8d990 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 44ac7c0b..35ea0886 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "devDependencies": { "@eslint-sukka/node": "^4.1.7", "@types/mocha": "10.0.2", + "@types/tar": "^6.1.9", "bun-types": "^1.0.11", "chai": "4.3.10", "eslint-config-sukka": "4.1.7",