浏览代码

Refactor: make ESLint happy

SukkaW 1 年之前
父节点
当前提交
6877195279

+ 1 - 1
Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts

@@ -9,7 +9,7 @@ import { SHARED_DESCRIPTION } from './lib/constants';
 import { createMemoizedPromise } from './lib/memo-promise';
 import * as yaml from 'yaml';
 import { appendArrayInPlace } from './lib/append-array-in-place';
-import { writeFile } from './lib/bun';
+import { writeFile } from './lib/misc';
 
 export const getDomesticAndDirectDomainsRulesetPromise = createMemoizedPromise(async () => {
   const domestics = await readFileIntoProcessedArray(path.resolve(__dirname, '../Source/non_ip/domestic.conf'));

+ 1 - 1
Build/build-internal-reverse-chn-cidr.ts

@@ -5,7 +5,7 @@ import { exclude, merge } from 'fast-cidr-tools';
 import { getChnCidrPromise } from './build-chn-cidr';
 import { NON_CN_CIDR_INCLUDED_IN_CHNROUTE, RESERVED_IPV4_CIDR } from './constants/cidr';
 
-import { writeFile } from './lib/bun';
+import { writeFile } from './lib/misc';
 
 export const buildInternalReverseChnCIDR = task(require.main === module, __filename)(async () => {
   const cidr = await getChnCidrPromise();

+ 1 - 1
Build/build-public.ts

@@ -7,7 +7,7 @@ import type { TreeType, TreeTypeArray } from './lib/tree-dir';
 import { fdir as Fdir } from 'fdir';
 
 import Trie from 'mnemonist/trie';
-import { writeFile } from './lib/bun';
+import { writeFile } from './lib/misc';
 
 const rootPath = path.resolve(__dirname, '../');
 const publicPath = path.resolve(__dirname, '../public');

+ 1 - 1
Build/build-sgmodule-always-realip.ts

@@ -3,7 +3,7 @@ import { task } from './trace';
 import { compareAndWriteFile } from './lib/create-file';
 import { DIRECTS, LANS } from '../Source/non_ip/direct';
 import * as yaml from 'yaml';
-import { writeFile } from './lib/bun';
+import { writeFile } from './lib/misc';
 
 const HOSTNAMES = [
   // Network Detection, Captive Portal

+ 0 - 43
Build/lib/bun.ts

@@ -1,43 +0,0 @@
-import { dirname } from 'path';
-import fs from 'fs';
-import fsp from 'fs/promises';
-
-const peekStatus = new WeakMap<Promise<any>, 'pending' | 'rejected' | 'fulfilled'>();
-export function track<T>(promise: Promise<T>): Promise<T> {
-  // only set to pending if not already tracked
-  if (!peekStatus.has(promise)) {
-    peekStatus.set(promise, 'pending');
-  }
-
-  // Observe the promise, saving the fulfillment in a closure scope.
-  return promise.then(
-    (v) => {
-      peekStatus.set(promise, 'fulfilled');
-      return v;
-    },
-    (e) => {
-      peekStatus.set(promise, 'rejected');
-      throw e;
-    }
-  );
-}
-
-export function peek(promise: Promise<any>): 'pending' | 'rejected' | 'fulfilled' | 'unknown' {
-  return peekStatus.get(promise) ?? 'unknown';
-}
-
-interface Write {
-  (
-    destination: string,
-    input: NodeJS.TypedArray | string,
-  ): Promise<unknown>
-}
-
-export const writeFile: Write = async (destination: string, input) => {
-  const dir = dirname(destination);
-
-  if (!fs.existsSync(dir)) {
-    await fsp.mkdir(dir, { recursive: true });
-  }
-  return fsp.writeFile(destination, input, { encoding: 'utf-8' });
-};

+ 1 - 2
Build/lib/create-file.ts

@@ -4,9 +4,8 @@ import picocolors from 'picocolors';
 import type { Span } from '../trace';
 import path from 'path';
 import fs from 'fs';
-import { fastStringArrayJoin } from './misc';
+import { fastStringArrayJoin, writeFile } from './misc';
 import { readFileByLine } from './fetch-text-by-line';
-import { writeFile } from './bun';
 
 export async function compareAndWriteFile(span: Span, linesA: string[], filePath: string) {
   let isEqual = true;

+ 16 - 4
Build/lib/misc.ts

@@ -1,3 +1,7 @@
+import { dirname } from 'path';
+import fs from 'fs';
+import fsp from 'fs/promises';
+
 export const isTruthy = <T>(i: T | 0 | '' | false | null | undefined): i is T => !!i;
 
 export const fastStringArrayJoin = (arr: string[], sep: string) => {
@@ -11,8 +15,16 @@ export const fastStringArrayJoin = (arr: string[], sep: string) => {
   return result;
 };
 
-export const fastStringArrayJoin2 = (arr: string[], sep: string) => {
-  return arr.reduce((acc, cur, index) => {
-    return index === 0 ? cur : acc + sep + cur;
-  }, '');
+interface Write {
+  (
+    destination: string,
+    input: NodeJS.TypedArray | string,
+  ): Promise<unknown>
+}
+
+export const writeFile: Write = async (destination: string, input, dir = dirname(destination)) => {
+  if (!fs.existsSync(dir)) {
+    await fsp.mkdir(dir, { recursive: true });
+  }
+  return fsp.writeFile(destination, input, { encoding: 'utf-8' });
 };

+ 1 - 0
Mock/addthis-com_addthis_widget.js

@@ -2,6 +2,7 @@
   'use strict';
 
   const noopfn = function () {
+    // noop
   };
   window.addthis = {
     addEventListener: noopfn,

+ 1 - 0
Mock/www-google-analytics-com_cx_api.js

@@ -2,6 +2,7 @@
   'use strict';
 
   const noopfn = function () {
+    // noop
   };
   window.cxApi = {
     chooseVariation() {

+ 1 - 0
Mock/www-google-analytics-com_inpage_linkid.js

@@ -3,6 +3,7 @@
 
   window._gaq = window._gaq || {
     push() {
+      // noop
     }
   };
 }());