diff --git a/package.json b/package.json index 8a64b21b4..88e86a73a 100644 --- a/package.json +++ b/package.json @@ -125,6 +125,7 @@ "@types/chai": "^4.3.5", "@types/debug": "^4.1.8", "@types/fs-extra": "^11.0.1", + "@types/ini": "^1.3.31", "@types/inquirer": "^8.2.6", "@types/ioredis-mock": "^8.2.2", "@types/lodash": "^4.14.195", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a9796b7e..be66787ab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -168,6 +168,9 @@ devDependencies: '@types/fs-extra': specifier: ^11.0.1 version: 11.0.1 + '@types/ini': + specifier: ^1.3.31 + version: 1.3.31 '@types/inquirer': specifier: ^8.2.6 version: 8.2.6 @@ -1562,6 +1565,10 @@ packages: /@types/http-cache-semantics@4.0.1: resolution: {integrity: sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==} + /@types/ini@1.3.31: + resolution: {integrity: sha512-8ecxxaG4AlVEM1k9+BsziMw8UsX0qy3jYI1ad/71RrDZ+rdL6aZB0wLfAuflQiDhkD5o4yJ0uPK3OSUic3fG0w==} + dev: true + /@types/inquirer@8.2.6: resolution: {integrity: sha512-3uT88kxg8lNzY8ay2ZjP44DKcRaTGztqeIvN2zHvhzIBH/uAPaL75aBtdNRKbA7xXoMbBt5kX0M00VKAnfOYlA==} dependencies: diff --git a/src/__tests__/__snapshots__/index.test.ts.md b/src/__tests__/__snapshots__/index.test.ts.md index c1434e09c..a1c274fb5 100644 --- a/src/__tests__/__snapshots__/index.test.ts.md +++ b/src/__tests__/__snapshots__/index.test.ts.md @@ -20,8 +20,16 @@ Generated by [AVA](https://avajs.dev). SURFBOARD: 'Surfboard', SURGE: 'Surge', }, - defineProvider: Function defineProvider {}, + defineBlackSSLProvider: Function defineBlackSSLProvider {}, + defineClashProvider: Function defineClashProvider {}, + defineCustomProvider: Function defineCustomProvider {}, + defineShadowsocksJsonSubscribeProvider: Function defineShadowsocksJsonSubscribeProvider {}, + defineShadowsocksSubscribeProvider: Function defineShadowsocksSubscribeProvider {}, + defineShadowsocksrSubscribeProvider: Function defineShadowsocksrSubscribeProvider {}, + defineSsdProvider: Function defineSsdProvider {}, defineSurgioConfig: Function defineSurgioConfig {}, + defineTrojanProvider: Function defineTrojanProvider {}, + defineV2rayNSubscribeProvider: Function defineV2rayNSubscribeProvider {}, utils: { SortFilterWithSortedFilters: Function SortFilterWithSortedFilters {}, SortFilterWithSortedKeywords: Function SortFilterWithSortedKeywords {}, diff --git a/src/__tests__/__snapshots__/index.test.ts.snap b/src/__tests__/__snapshots__/index.test.ts.snap index 56225fc0d..6ebda458b 100644 Binary files a/src/__tests__/__snapshots__/index.test.ts.snap and b/src/__tests__/__snapshots__/index.test.ts.snap differ diff --git a/src/generator/__tests__/artifact.test.ts b/src/generator/__tests__/artifact.test.ts index 1365b1afd..bc9249db4 100644 --- a/src/generator/__tests__/artifact.test.ts +++ b/src/generator/__tests__/artifact.test.ts @@ -4,7 +4,7 @@ import { loadConfig } from '../../config' import { Artifact } from '../artifact' import { getEngine } from '../template' -const resolve = (p) => join(__dirname, '../../../test/fixture/', p) +const resolve = (p: string) => join(__dirname, '../../../test/fixture/', p) test('new Artifact()', async (t) => { const fixture = resolve('plain') diff --git a/src/provider/__tests__/ClashProvider.test.ts b/src/provider/__tests__/ClashProvider.test.ts index b294b4414..067d0a449 100644 --- a/src/provider/__tests__/ClashProvider.test.ts +++ b/src/provider/__tests__/ClashProvider.test.ts @@ -655,7 +655,7 @@ test.serial( test('ClashProvider with hooks', async (t) => { const afterNodeListResponse = sinon.spy((nodeList) => { - nodeList.forEach((node) => { + nodeList.forEach((node: any) => { node.nodeName = 'override' }) }) diff --git a/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.snap b/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.snap index 47571d329..eadcce454 100644 Binary files a/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.snap and b/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.snap differ diff --git a/src/utils/__tests__/surge.test.ts b/src/utils/__tests__/surge.test.ts index 26dc1e23f..51cc4bdef 100644 --- a/src/utils/__tests__/surge.test.ts +++ b/src/utils/__tests__/surge.test.ts @@ -536,7 +536,7 @@ test('getSurgeNodes - Tuic', (t) => { '测试 Tuic = tuic, example.com, 443, token=token, server-cert-fingerprint-sha256=sha256', '测试 Tuic = tuic, example.com, 443, token=token, alpn=h3', '测试 Tuic = tuic, example.com, 443, token=token, sni=sni.example.com, skip-cert-verify=true, alpn=h3', - '测试 Tuic = tuic, example.com, 443, password=password, uuid=uuid, sni=sni.example.com, skip-cert-verify=true, version=5, alpn=h3', + '测试 Tuic = tuic-v5, example.com, 443, password=password, uuid=uuid, sni=sni.example.com, skip-cert-verify=true, alpn=h3', ].join('\n'), ) }) diff --git a/src/utils/surge.ts b/src/utils/surge.ts index 567014ff4..0bd5ddc3d 100644 --- a/src/utils/surge.ts +++ b/src/utils/surge.ts @@ -475,6 +475,37 @@ function nodeListMapper( } case NodeTypeEnum.Tuic: { + if ('version' in nodeConfig && Number(nodeConfig.version) === 5) { + const result = [ + 'tuic-v5', + nodeConfig.hostname, + nodeConfig.port, + ...pickAndFormatStringList( + nodeConfig, + [ + 'password', + 'uuid', + 'sni', + 'underlyingProxy', + 'testUrl', + 'skipCertVerify', + 'serverCertFingerprintSha256', + ], + { + keyFormat: 'kebabCase', + }, + ), + ...(Array.isArray(nodeConfig.alpn) + ? [`alpn=${nodeConfig.alpn.join(',')}`] + : []), + ] + + return [ + nodeConfig.nodeName, + [nodeConfig.nodeName, result.join(', ')].join(' = '), + ] + } + const result = [ 'tuic', nodeConfig.hostname, @@ -483,14 +514,11 @@ function nodeListMapper( nodeConfig, [ 'token', - 'password', - 'uuid', 'sni', 'underlyingProxy', 'testUrl', 'skipCertVerify', 'serverCertFingerprintSha256', - 'version', ], { keyFormat: 'kebabCase', diff --git a/test/cli.cli-test.ts b/test/cli.cli-test.ts index ba06137ca..cbfdec76f 100644 --- a/test/cli.cli-test.ts +++ b/test/cli.cli-test.ts @@ -5,7 +5,7 @@ import ini from 'ini' import { test, expect } from '@oclif/test' const fixture = join(__dirname, './fixture') -const resolve = (p) => join(fixture, p) +const resolve = (p: string) => join(fixture, p) afterEach(async () => { process.env.ENV_SURGIO_PROJECT_DIR = undefined diff --git a/tsconfig.json b/tsconfig.json index 19ddac9f9..8089d8733 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "rootDir": "./src", // https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping "target": "ES2022", "module": "Node16",