浏览代码

Chore: drop `@sukka/listdir`

SukkaW 1 年之前
父节点
当前提交
d9331b8b50
共有 4 个文件被更改,包括 19 次插入12 次删除
  1. 7 3
      Build/build-mitm-hostname.ts
  2. 12 8
      Build/build-public.ts
  3. 二进制
      bun.lockb
  4. 0 1
      package.json

+ 7 - 3
Build/build-mitm-hostname.ts

@@ -1,7 +1,7 @@
 import { readFileByLine } from './lib/fetch-text-by-line';
 import pathFn from 'path';
 import table from 'table';
-import listDir from '@sukka/listdir';
+import { fdir as Fdir } from 'fdir';
 import { green, yellow } from 'picocolors';
 import { processLineFromReadline } from './lib/process-line';
 import { getHostname } from 'tldts';
@@ -37,12 +37,16 @@ const PRESET_MITM_HOSTNAMES = [
 
 (async () => {
   const folderListPath = pathFn.resolve(__dirname, '../List/');
-  const rulesets = await listDir(folderListPath);
+
+  const rulesets = await new Fdir()
+    .withFullPaths()
+    .crawl(folderListPath)
+    .withPromise();
 
   const urlRegexPaths: Array<{ origin: string, processed: string }> = [];
 
   await Promise.all(rulesets.map(async file => {
-    const content = await processLineFromReadline(readFileByLine(pathFn.join(folderListPath, file)));
+    const content = await processLineFromReadline(readFileByLine(file));
     urlRegexPaths.push(
       ...content
         .filter(i => (

+ 12 - 8
Build/build-public.ts

@@ -2,9 +2,11 @@ import path from 'path';
 import { task } from './trace';
 import { treeDir } from './lib/tree-dir';
 import type { TreeType, TreeTypeArray } from './lib/tree-dir';
-import listDir from '@sukka/listdir';
+import { fdir as Fdir } from 'fdir';
 import { sort } from './lib/timsort';
 
+import Trie from 'mnemonist/trie';
+
 const rootPath = path.resolve(import.meta.dir, '../');
 const publicPath = path.resolve(import.meta.dir, '../public');
 
@@ -22,13 +24,15 @@ export const buildPublic = task(import.meta.main, import.meta.path)(async (span)
   await span
     .traceChild('copy public files')
     .traceAsyncFn(async () => {
-      const filesToBeCopied = (await listDir(
-        rootPath,
-        {
-          ignoreHidden: true,
-          ignorePattern: /node_modules|Build|public/
-        }
-      )).filter(file => folderAndFilesToBeDeployed.some(folderOrFile => file.startsWith(folderOrFile)));
+      const trie = Trie.from(await new Fdir()
+        .withRelativePaths()
+        .exclude((dirName) => {
+          return dirName === 'node_modules' || dirName === 'Build' || dirName === 'public' || dirName[0] === '.';
+        })
+        .crawl(rootPath)
+        .withPromise());
+
+      const filesToBeCopied = folderAndFilesToBeDeployed.flatMap(folderOrFile => trie.find(folderOrFile));
 
       return Promise.all(filesToBeCopied.map(file => {
         const src = path.resolve(rootPath, file);

二进制
bun.lockb


+ 0 - 1
package.json

@@ -17,7 +17,6 @@
   "dependencies": {
     "@cliqz/adblocker": "^1.27.5",
     "@gorhill/publicsuffixlist": "3.0.1",
-    "@sukka/listdir": "^0.3.1",
     "async-retry": "^1.3.3",
     "async-sema": "^3.1.1",
     "ci-info": "^4.0.0",