Refactor VPN proxy client implementation
This commit is contained in:
@@ -3,10 +3,10 @@ import { execFileSync } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import { parseVersion, versionCompatibility } from '../src/shared/versions.js';
|
||||
|
||||
const COMPONENTS = ['macClient', 'gatewayClient', 'gatewayBackend'];
|
||||
const VERSION_FILE = 'src/shared/versions.js';
|
||||
const VERSION_FILE = 'src/shared/versions.ts';
|
||||
const LEGACY_VERSION_FILE = 'src/shared/versions.js';
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const aliases = {
|
||||
mac: 'macClient',
|
||||
@@ -17,6 +17,28 @@ const aliases = {
|
||||
'gateway-backend': 'gatewayBackend',
|
||||
};
|
||||
|
||||
export function parseVersion(value) {
|
||||
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(String(value || ''));
|
||||
return match ? {
|
||||
major: Number(match[1]),
|
||||
minor: Number(match[2]),
|
||||
hotfix: Number(match[3]),
|
||||
} : null;
|
||||
}
|
||||
|
||||
export function versionCompatibility(versions) {
|
||||
const mac = parseVersion(versions?.macClient);
|
||||
const client = parseVersion(versions?.gatewayClient);
|
||||
const backend = parseVersion(versions?.gatewayBackend);
|
||||
const major = Boolean(mac && client && backend
|
||||
&& mac.major === client.major
|
||||
&& client.major === backend.major);
|
||||
const gateway = Boolean(client && backend
|
||||
&& client.major === backend.major
|
||||
&& client.minor === backend.minor);
|
||||
return { compatible: major && gateway, major, gateway };
|
||||
}
|
||||
|
||||
export function versionsFromSource(source) {
|
||||
return Object.fromEntries(COMPONENTS.map((component) => {
|
||||
const match = new RegExp(`${component}:\\s*'(\\d+\\.\\d+\\.\\d+)'`).exec(source);
|
||||
@@ -30,14 +52,16 @@ export function affectedComponents(files) {
|
||||
const add = (...components) => components.forEach((component) => affected.add(component));
|
||||
for (const file of files) {
|
||||
if (file === VERSION_FILE) continue;
|
||||
if (/^(package-lock\.json|src\/shared\/)/.test(file)) add(...COMPONENTS);
|
||||
else if (/^(src\/web\/|public\/|index\.html$|vite\.config\.js$)/.test(file)) {
|
||||
if (/^(?:\.dockerignore$|package(?:-lock)?\.json$|tsconfig\.base\.json$|src\/shared\/)/.test(file)) add(...COMPONENTS);
|
||||
else if (/^(src\/web\/|public\/|index\.html$|tsconfig\.web\.json$|vite\.config\.[cm]?[jt]s$)/.test(file)) {
|
||||
add('macClient', 'gatewayClient');
|
||||
} else if (/^src\/server\//.test(file)) add('macClient', 'gatewayBackend');
|
||||
} else if (/^(src\/server\/|tsconfig\.server\.json$)/.test(file)) add('macClient', 'gatewayBackend');
|
||||
else if (/^(install\.sh|Dockerfile\.client|docker-compose\.client(\.local)?\.yml|entrypoint\.client\.sh|scripts\/(install-macos-client|harbor-network-monitor)\.sh)$/.test(file)) {
|
||||
add('macClient');
|
||||
} else if (/^(Dockerfile|Dockerfile\.runtime-base|docker-compose\.gateway\.yml|entrypoint\.sh|scripts\/(deploy-gateway|build-runtime-base|build-on-107-deploy-111)\.sh)$/.test(file)) {
|
||||
add('gatewayBackend');
|
||||
} else if (/^(\.gitea\/workflows\/gateway-build\.yml|scripts\/runtime-impact\.mjs)$/.test(file)) {
|
||||
add('gatewayBackend');
|
||||
}
|
||||
}
|
||||
return COMPONENTS.filter((component) => affected.has(component));
|
||||
@@ -91,7 +115,7 @@ function git(args) {
|
||||
}
|
||||
|
||||
function changedFiles(base) {
|
||||
const tracked = git(['diff', '--name-only', base, '--']).split('\n');
|
||||
const tracked = git(['diff', '--no-renames', '--name-only', base, '--']).split('\n');
|
||||
const untracked = git(['ls-files', '--others', '--exclude-standard']).split('\n');
|
||||
return [...new Set([...tracked, ...untracked].filter(Boolean))];
|
||||
}
|
||||
@@ -100,7 +124,11 @@ function baselineVersions(base) {
|
||||
try {
|
||||
return versionsFromSource(git(['show', `${base}:${VERSION_FILE}`]));
|
||||
} catch {
|
||||
return null;
|
||||
try {
|
||||
return versionsFromSource(git(['show', `${base}:${LEGACY_VERSION_FILE}`]));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user