From 5ea072dbcc4c9a8dda70d624a8cc9bb6ea13ce35 Mon Sep 17 00:00:00 2001 From: Oskar Date: Mon, 23 Dec 2024 11:11:11 +0100 Subject: [PATCH] Move management interface to its own package --- desktop/package-lock.json | 33 +++++++++++++++---- .../packages/management-interface/.gitignore | 1 + .../build.sh} | 20 +++++------ .../management-interface/package.json | 23 +++++++++++++ .../management-interface/src/index.ts | 2 ++ .../management-interface/tsconfig.json | 17 ++++++++++ desktop/packages/mullvad-vpn/.gitignore | 1 - desktop/packages/mullvad-vpn/gulpfile.js | 13 ++------ desktop/packages/mullvad-vpn/package.json | 6 +--- .../mullvad-vpn/src/main/daemon-rpc.ts | 2 +- .../mullvad-vpn/src/main/grpc-client.ts | 2 +- .../src/main/grpc-type-convertions.ts | 3 +- desktop/packages/mullvad-vpn/tasks/scripts.js | 6 ---- 13 files changed, 87 insertions(+), 42 deletions(-) create mode 100644 desktop/packages/management-interface/.gitignore rename desktop/packages/{mullvad-vpn/scripts/build-proto.sh => management-interface/build.sh} (67%) create mode 100644 desktop/packages/management-interface/package.json create mode 100644 desktop/packages/management-interface/src/index.ts create mode 100644 desktop/packages/management-interface/tsconfig.json diff --git a/desktop/package-lock.json b/desktop/package-lock.json index 64e60bd9935f..bc2c4084ad12 100644 --- a/desktop/package-lock.json +++ b/desktop/package-lock.json @@ -9319,6 +9319,10 @@ "node": ">=0.10.0" } }, + "node_modules/management-interface": { + "resolved": "packages/management-interface", + "link": true + }, "node_modules/map-cache": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz", @@ -14630,6 +14634,20 @@ "zod": "^3.18.0" } }, + "packages/management-interface": { + "version": "0.0.0", + "hasInstallScript": true, + "license": "GPL-3.0", + "devDependencies": { + "grpc_tools_node_protoc_ts": "^5.3.3" + }, + "optionalDependencies": { + "grpc-tools": "^1.12.4" + }, + "peerDependencies": { + "google-protobuf": "*" + } + }, "packages/mullvad-vpn": { "version": "0.0.0", "hasInstallScript": true, @@ -14640,6 +14658,7 @@ "gettext-parser": "^6.0.0", "gl-matrix": "^3.4.3", "google-protobuf": "^3.21.0", + "management-interface": "0.0.0", "node-gettext": "^3.0.0", "nseventforwarder": "0.0.0", "react": "^18.3.1", @@ -14680,7 +14699,6 @@ "eslint-plugin-react-hooks": "^0.0.0-experimental-2d16326d-20240930", "gettext-extractor": "^3.5.4", "globals": "^15.9.0", - "grpc_tools_node_protoc_ts": "^5.3.3", "gulp": "^4.0.2", "gulp-inject-string": "^1.1.2", "gulp-sourcemaps": "^3.0.0", @@ -14693,9 +14711,6 @@ "vinyl-buffer": "^1.0.1", "vinyl-source-stream": "^2.0.0", "xvfb-maybe": "^0.2.1" - }, - "optionalDependencies": { - "grpc-tools": "^1.12.4" } }, "packages/nseventforwarder": { @@ -21978,6 +21993,13 @@ "kind-of": "^6.0.2" } }, + "management-interface": { + "version": "file:packages/management-interface", + "requires": { + "grpc_tools_node_protoc_ts": "^5.3.3", + "grpc-tools": "^1.12.4" + } + }, "map-cache": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz", @@ -22562,12 +22584,11 @@ "gl-matrix": "^3.4.3", "globals": "^15.9.0", "google-protobuf": "^3.21.0", - "grpc_tools_node_protoc_ts": "^5.3.3", - "grpc-tools": "^1.12.4", "gulp": "^4.0.2", "gulp-inject-string": "^1.1.2", "gulp-sourcemaps": "^3.0.0", "gulp-typescript": "^6.0.0-alpha.1", + "management-interface": "0.0.0", "mocha": "^10.8.2", "node-gettext": "^3.0.0", "nseventforwarder": "0.0.0", diff --git a/desktop/packages/management-interface/.gitignore b/desktop/packages/management-interface/.gitignore new file mode 100644 index 000000000000..849ddff3b7ec --- /dev/null +++ b/desktop/packages/management-interface/.gitignore @@ -0,0 +1 @@ +dist/ diff --git a/desktop/packages/mullvad-vpn/scripts/build-proto.sh b/desktop/packages/management-interface/build.sh similarity index 67% rename from desktop/packages/mullvad-vpn/scripts/build-proto.sh rename to desktop/packages/management-interface/build.sh index 69023b72ce0e..db0369fc420c 100755 --- a/desktop/packages/mullvad-vpn/scripts/build-proto.sh +++ b/desktop/packages/management-interface/build.sh @@ -8,24 +8,22 @@ cd "$SCRIPT_DIR" ARCH="$(uname -m)" PLATFORM="$(uname -s)" MANAGEMENT_INTERFACE_PROTO_BUILD_DIR=${MANAGEMENT_INTERFACE_PROTO_BUILD_DIR:-} -NODE_MODULES_DIR="$(cd ../../../node_modules/.bin && pwd)" -PROTO_DIR="../../../../mullvad-management-interface/proto" +NODE_MODULES_DIR="$(cd ../../node_modules/.bin && pwd)" +OUT_DIR="dist" +PROTO_DIR="../../../mullvad-management-interface/proto" PROTO_FILENAME="management_interface.proto" -DESTINATION_DIR="../build/src/main/management_interface" -TYPES_DESTINATION_DIR="../src/main/management_interface" TS_PROTOC_PLUGIN="$NODE_MODULES_DIR/protoc-gen-ts" if [[ "$(uname -s)" == "MINGW"* ]]; then TS_PROTOC_PLUGIN="$TS_PROTOC_PLUGIN.cmd" fi -mkdir -p $DESTINATION_DIR -mkdir -p $TYPES_DESTINATION_DIR +mkdir -p $OUT_DIR if [[ "$PLATFORM" == "Linux" && ("${ARCH,,}" == "arm64" || "${ARCH,,}" == "aarch64") ]]; then if [[ -n "${MANAGEMENT_INTERFACE_PROTO_BUILD_DIR}" ]]; then - cp "$MANAGEMENT_INTERFACE_PROTO_BUILD_DIR"/*.js $DESTINATION_DIR - cp "$MANAGEMENT_INTERFACE_PROTO_BUILD_DIR"/*.ts $TYPES_DESTINATION_DIR + cp "$MANAGEMENT_INTERFACE_PROTO_BUILD_DIR"/*.js . + cp "$MANAGEMENT_INTERFACE_PROTO_BUILD_DIR"/*.ts . else >&2 echo "Building management interface proto files on aarch64 is not supported" >&2 echo "(see https://github.com/grpc/grpc-node/issues/1497)." @@ -35,14 +33,14 @@ if [[ "$PLATFORM" == "Linux" && ("${ARCH,,}" == "arm64" || "${ARCH,,}" == "aarch fi else "$NODE_MODULES_DIR/grpc_tools_node_protoc" \ - --js_out=import_style=commonjs,binary:$DESTINATION_DIR \ - --grpc_out=grpc_js:$DESTINATION_DIR \ + --js_out=import_style=commonjs,binary:$OUT_DIR \ + --grpc_out=grpc_js:$OUT_DIR \ --proto_path=$PROTO_DIR \ $PROTO_DIR/$PROTO_FILENAME "$NODE_MODULES_DIR/grpc_tools_node_protoc" \ --plugin=protoc-gen-ts="$TS_PROTOC_PLUGIN" \ - --ts_out=grpc_js:$TYPES_DESTINATION_DIR \ + --ts_out=grpc_js:$OUT_DIR \ --proto_path=$PROTO_DIR \ $PROTO_DIR/$PROTO_FILENAME fi diff --git a/desktop/packages/management-interface/package.json b/desktop/packages/management-interface/package.json new file mode 100644 index 000000000000..4047394d4d19 --- /dev/null +++ b/desktop/packages/management-interface/package.json @@ -0,0 +1,23 @@ +{ + "name": "management-interface", + "version": "0.0.0", + "author": "Mullvad VPN", + "license": "GPL-3.0", + "description": "Mullvad VPN IPC. Contains types and functions for IPC with daemon.", + "main": "./dist/index.js", + "devDependencies": { + "grpc_tools_node_protoc_ts": "^5.3.3" + }, + "optionalDependencies": { + "grpc-tools": "^1.12.4" + }, + "peerDependencies": { + "google-protobuf": "*" + }, + "scripts": { + "postinstall": "npm run build", + "build": "npm run build-proto && npm run build-typescript", + "build-proto": "bash ./build.sh", + "build-typescript": "tsc" + } +} diff --git a/desktop/packages/management-interface/src/index.ts b/desktop/packages/management-interface/src/index.ts new file mode 100644 index 000000000000..6000bae136f5 --- /dev/null +++ b/desktop/packages/management-interface/src/index.ts @@ -0,0 +1,2 @@ +export * from '../dist/management_interface_grpc_pb'; +export * as types from '../dist/management_interface_pb'; diff --git a/desktop/packages/management-interface/tsconfig.json b/desktop/packages/management-interface/tsconfig.json new file mode 100644 index 000000000000..a89641eb332a --- /dev/null +++ b/desktop/packages/management-interface/tsconfig.json @@ -0,0 +1,17 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "outDir": "dist", + "rootDirs": [ + "src" + ], + "typeRoots": [ + "../../node_modules/@types" + ] + }, + "exclude": [ + "dist" + ] +} diff --git a/desktop/packages/mullvad-vpn/.gitignore b/desktop/packages/mullvad-vpn/.gitignore index 933e161a7066..eb05f76cadb9 100644 --- a/desktop/packages/mullvad-vpn/.gitignore +++ b/desktop/packages/mullvad-vpn/.gitignore @@ -1,7 +1,6 @@ /node_modules /build /scripts/out/ -/src/main/management_interface/ /test/e2e/screenshots/ /test-results/ /standalone-tests.sea.blob diff --git a/desktop/packages/mullvad-vpn/gulpfile.js b/desktop/packages/mullvad-vpn/gulpfile.js index ff5a82df17f0..02375032f4c6 100644 --- a/desktop/packages/mullvad-vpn/gulpfile.js +++ b/desktop/packages/mullvad-vpn/gulpfile.js @@ -1,5 +1,5 @@ const fs = require('fs'); -const { task, series, parallel } = require('gulp'); +const { task, series } = require('gulp'); const scripts = require('./tasks/scripts'); const assets = require('./tasks/assets'); @@ -18,15 +18,8 @@ task('set-prod-env', function (done) { task('clean', function (done) { fs.rm('./build', { recursive: true, force: true }, done); }); -task('build-proto', scripts.buildProto); -task( - 'build', - series('clean', 'set-prod-env', parallel(assets.copyAll, scripts.buildProto), scripts.build), -); -task( - 'develop', - series('clean', 'set-dev-env', scripts.buildProto, scripts.buildNseventforwarder, watch.start), -); +task('build', series('clean', 'set-prod-env', assets.copyAll, scripts.build)); +task('develop', series('clean', 'set-dev-env', scripts.buildNseventforwarder, watch.start)); task('pack-win', series('build', dist.packWin)); task('pack-linux', series('build', dist.packLinux)); task('pack-mac', series('build', dist.packMac)); diff --git a/desktop/packages/mullvad-vpn/package.json b/desktop/packages/mullvad-vpn/package.json index 63bacb6072d7..1b070ac9dbb7 100644 --- a/desktop/packages/mullvad-vpn/package.json +++ b/desktop/packages/mullvad-vpn/package.json @@ -17,6 +17,7 @@ "gettext-parser": "^6.0.0", "gl-matrix": "^3.4.3", "google-protobuf": "^3.21.0", + "management-interface": "0.0.0", "node-gettext": "^3.0.0", "nseventforwarder": "0.0.0", "react": "^18.3.1", @@ -28,9 +29,6 @@ "sprintf-js": "^1.1.2", "styled-components": "^6.1.13" }, - "optionalDependencies": { - "grpc-tools": "^1.12.4" - }, "devDependencies": { "@playwright/test": "^1.41.1", "@types/chai": "^4.3.3", @@ -60,7 +58,6 @@ "eslint-plugin-react-hooks": "^0.0.0-experimental-2d16326d-20240930", "gettext-extractor": "^3.5.4", "globals": "^15.9.0", - "grpc_tools_node_protoc_ts": "^5.3.3", "gulp": "^4.0.2", "gulp-inject-string": "^1.1.2", "gulp-sourcemaps": "^3.0.0", @@ -77,7 +74,6 @@ "scripts": { "preinstall": "test -d node_modules || mkdir node_modules", "build": "gulp build", - "build-proto": "gulp build-proto", "pack-test-executable": "./scripts/build-test-executable.sh", "build-test-executable": "npm run build && npm run pack-test-executable", "lint": "eslint .", diff --git a/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts b/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts index 8cea0d4008a6..9c9321c61d03 100644 --- a/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts +++ b/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts @@ -1,6 +1,7 @@ import * as grpc from '@grpc/grpc-js'; import { Empty } from 'google-protobuf/google/protobuf/empty_pb.js'; import { BoolValue, StringValue } from 'google-protobuf/google/protobuf/wrappers_pb.js'; +import { types as grpcTypes } from 'management-interface'; import { AccessMethodSetting, @@ -44,7 +45,6 @@ import { convertToRelayConstraints, ensureExists, } from './grpc-type-convertions'; -import * as grpcTypes from './management_interface/management_interface_pb'; const DAEMON_RPC_PATH = process.platform === 'win32' ? 'unix:////./pipe/Mullvad VPN' : 'unix:///var/run/mullvad-vpn'; diff --git a/desktop/packages/mullvad-vpn/src/main/grpc-client.ts b/desktop/packages/mullvad-vpn/src/main/grpc-client.ts index fa04cdf85517..1ef5a8e83187 100644 --- a/desktop/packages/mullvad-vpn/src/main/grpc-client.ts +++ b/desktop/packages/mullvad-vpn/src/main/grpc-client.ts @@ -5,10 +5,10 @@ import { StringValue, UInt32Value, } from 'google-protobuf/google/protobuf/wrappers_pb.js'; +import { ManagementServiceClient } from 'management-interface'; import { promisify } from 'util'; import log from '../shared/logging'; -import { ManagementServiceClient } from './management_interface/management_interface_grpc_pb'; const NETWORK_CALL_TIMEOUT = 10000; const CHANNEL_STATE_TIMEOUT = 1000 * 60 * 60; diff --git a/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts b/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts index ee4939e65cab..11da55b6bff3 100644 --- a/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts +++ b/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts @@ -1,3 +1,5 @@ +import { types as grpcTypes } from 'management-interface'; + import { AccessMethod, AccessMethodSetting, @@ -58,7 +60,6 @@ import { TunnelType, wrapConstraint, } from '../shared/daemon-rpc-types'; -import * as grpcTypes from './management_interface/management_interface_pb'; export class ResponseParseError extends Error { constructor(message: string) { diff --git a/desktop/packages/mullvad-vpn/tasks/scripts.js b/desktop/packages/mullvad-vpn/tasks/scripts.js index 9074cd1f1dec..066ad60c6b41 100644 --- a/desktop/packages/mullvad-vpn/tasks/scripts.js +++ b/desktop/packages/mullvad-vpn/tasks/scripts.js @@ -109,10 +109,6 @@ function makeBrowserifyPreload(debug) { return browserifyPreload; } -function buildProto(callback) { - exec('bash ./scripts/build-proto.sh', (err) => callback(err)); -} - function buildNseventforwarder(callback) { if (process.platform === 'darwin') { exec('npm -w nseventforwarder run build-debug', (err) => callback(err)); @@ -122,13 +118,11 @@ function buildNseventforwarder(callback) { } compileScripts.displayName = 'compile-scripts'; -buildProto.displayName = 'build-proto'; buildNseventforwarder.displayName = 'build-nseventforwarder'; exports.build = series( compileScripts, parallel(makeBrowserifyPreload(false), makeBrowserifyRenderer(false)), ); -exports.buildProto = buildProto; exports.buildNseventforwarder = buildNseventforwarder; exports.makeWatchCompiler = makeWatchCompiler;