瀏覽代碼

Refactor: drop `punycode.js`

SukkaW 5 月之前
父節點
當前提交
02a2302210
共有 3 個文件被更改,包括 8 次插入21 次删除
  1. 8 8
      Build/lib/trie.ts
  2. 0 2
      package.json
  3. 0 11
      pnpm-lock.yaml

+ 8 - 8
Build/lib/trie.ts

@@ -8,7 +8,7 @@ import { noop } from 'foxts/noop';
 import { fastStringArrayJoin } from 'foxts/fast-string-array-join';
 
 import { deleteBit, getBit, missingBit, setBit } from 'foxts/bitwise';
-import { toASCII } from 'punycode/';
+import { domainToASCII } from 'node:url';
 
 const START = 1 << 1;
 const INCLUDE_ALL_SUBDOMAIN = 1 << 2;
@@ -320,13 +320,13 @@ abstract class Triebase<Meta = unknown> {
 
     const onMatches = subdomainOnly
       ? (suffix: string[], subdomain: boolean) => { // fast path (default option)
-        const d = toASCII(fastStringArrayJoin(suffix, '.'));
+        const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
         if (!subdomain && subStringEqual(inputSuffix, d, 1)) return;
 
         results.push(subdomain ? '.' + d : d);
       }
       : (suffix: string[], subdomain: boolean) => { // fast path (default option)
-        const d = toASCII(fastStringArrayJoin(suffix, '.'));
+        const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
         results.push(subdomain ? '.' + d : d);
       };
 
@@ -380,7 +380,7 @@ abstract class Triebase<Meta = unknown> {
 
   public dumpWithoutDot(onSuffix: (suffix: string, subdomain: boolean) => void, withSort = false) {
     const handleSuffix = (suffix: string[], subdomain: boolean) => {
-      onSuffix(toASCII(fastStringArrayJoin(suffix, '.')), subdomain);
+      onSuffix(domainToASCII(fastStringArrayJoin(suffix, '.')), subdomain);
     };
 
     this.walk(handleSuffix, withSort);
@@ -393,11 +393,11 @@ abstract class Triebase<Meta = unknown> {
 
     const handleSuffix = onSuffix
       ? (suffix: string[], subdomain: boolean) => {
-        const d = toASCII(fastStringArrayJoin(suffix, '.'));
+        const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
         onSuffix(subdomain ? '.' + d : d);
       }
       : (suffix: string[], subdomain: boolean) => {
-        const d = toASCII(fastStringArrayJoin(suffix, '.'));
+        const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
         results.push(subdomain ? '.' + d : d);
       };
 
@@ -427,11 +427,11 @@ abstract class Triebase<Meta = unknown> {
 
     const handleSuffix = onSuffix
       ? (suffix: string[], subdomain: boolean, meta: Meta | undefined) => {
-        const d = toASCII(fastStringArrayJoin(suffix, '.'));
+        const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
         return onSuffix(subdomain ? '.' + d : d, meta);
       }
       : (suffix: string[], subdomain: boolean, meta: Meta | undefined) => {
-        const d = toASCII(fastStringArrayJoin(suffix, '.'));
+        const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
         results.push([subdomain ? '.' + d : d, meta]);
       };
 

+ 0 - 2
package.json

@@ -36,7 +36,6 @@
     "json-stringify-pretty-compact": "3.0.0",
     "null-prototype-object": "^1.2.3",
     "picocolors": "^1.1.1",
-    "punycode": "^2.3.1",
     "tar-fs": "^3.1.1",
     "telegram": "^2.26.22",
     "tldts": "^7.0.17",
@@ -58,7 +57,6 @@
     "@types/dns2": "^2.0.10",
     "@types/mocha": "^10.0.10",
     "@types/node": "^24.7.1",
-    "@types/punycode": "^2.1.4",
     "@types/tar-fs": "^2.0.4",
     "@types/yauzl-promise": "^4.0.1",
     "eslint": "^9.37.0",

+ 0 - 11
pnpm-lock.yaml

@@ -65,9 +65,6 @@ importers:
       picocolors:
         specifier: ^1.1.1
         version: 1.1.1
-      punycode:
-        specifier: ^2.3.1
-        version: 2.3.1
       tar-fs:
         specifier: ^3.1.1
         version: 3.1.1
@@ -126,9 +123,6 @@ importers:
       '@types/node':
         specifier: ^24.7.1
         version: 24.7.1
-      '@types/punycode':
-        specifier: ^2.1.4
-        version: 2.1.4
       '@types/tar-fs':
         specifier: ^2.0.4
         version: 2.0.4
@@ -678,9 +672,6 @@ packages:
   '@types/node@24.7.1':
     resolution: {integrity: sha512-CmyhGZanP88uuC5GpWU9q+fI61j2SkhO3UGMUdfYRE6Bcy0ccyzn1Rqj9YAB/ZY4kOXmNf0ocah5GtphmLMP6Q==}
 
-  '@types/punycode@2.1.4':
-    resolution: {integrity: sha512-trzh6NzBnq8yw5e35f8xe8VTYjqM3NE7bohBtvDVf/dtUer3zYTLK1Ka3DG3p7bdtoaOHZucma6FfVKlQ134pQ==}
-
   '@types/stack-utils@2.0.3':
     resolution: {integrity: sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==}
 
@@ -2674,8 +2665,6 @@ snapshots:
     dependencies:
       undici-types: 7.14.0
 
-  '@types/punycode@2.1.4': {}
-
   '@types/stack-utils@2.0.3': {}
 
   '@types/tar-fs@2.0.4':