From 40743197dcb829745f97bf7e962feceec7761669 Mon Sep 17 00:00:00 2001 From: moloch-- <875022+moloch--@users.noreply.github.com> Date: Sun, 13 Feb 2022 14:43:22 -0600 Subject: [PATCH] insert code to fix _pb.js broken namespaces --- package.json | 2 +- protobuf.sh | 26 +++++++++++++++++++++++++- src/pb/clientpb/client_pb.js | 2 ++ src/pb/commonpb/common_pb.js | 2 ++ src/pb/sliverpb/sliver_pb.js | 2 ++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f4bcc2e..f0b22fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sliver-script", - "version": "1.1.1", + "version": "1.1.3", "description": "TypeScript/JavaScript Sliver client library", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/protobuf.sh b/protobuf.sh index 9e0a7b7..f609393 100755 --- a/protobuf.sh +++ b/protobuf.sh @@ -23,6 +23,11 @@ IN_DIR="./sliver/protobuf" PROTOC="node_modules/.bin/grpc_tools_node_protoc" PROTOC_GEN_TS="node_modules/.bin/protoc-gen-ts" +# By default the _pb.js files are broken, we need to insert this line of code to create the namespaces +# before any of hte _pb.js code can be used. Why are they broken by default? Fuck you that's why. +INIT_NAMESPACE="if (proto === undefined) { var proto = {commonpb: {}, clientpb: {}, sliverpb: {}}; }" + + mkdir -p "$OUT_DIR" mkdir -p "$TS_OUT_DIR" @@ -65,16 +70,35 @@ sed -i "" -e \ "s/from \"grpc\"/from \"@grpc\/grpc-js\"/g" \ "$TS_OUT_DIR/rpcpb/"* -### Remove eval()'s +# *** clientpb *** +# - Init namespace +# - Remove eval()'s sed -i "" -e \ "s/Function('return this')()/(function(){return this;})()/g" \ "$TS_OUT_DIR/clientpb/"* +sed -i "" -e \ + "s/\/\/\ \@ts-nocheck/\/\/\ \@ts-nocheck\n$INIT_NAMESPACE\n/g" \ + "$TS_OUT_DIR/clientpb/"* + +# *** commonpb *** +# - Init namespace +# - Remove eval()'s sed -i "" -e \ "s/Function('return this')()/(function(){return this;})()/g" \ "$TS_OUT_DIR/commonpb/"* +sed -i "" -e \ + "s/\/\/\ \@ts-nocheck/\/\/\ \@ts-nocheck\n$INIT_NAMESPACE\n/g" \ + "$TS_OUT_DIR/commonpb/"* + +# *** sliverpb *** +# - Init namespace +# - Remove eval()'s sed -i "" -e \ "s/Function('return this')()/(function(){return this;})()/g" \ "$TS_OUT_DIR/sliverpb/"* +sed -i "" -e \ + "s/\/\/\ \@ts-nocheck/\/\/\ \@ts-nocheck\n$INIT_NAMESPACE\n/g" \ + "$TS_OUT_DIR/sliverpb/"* \ No newline at end of file diff --git a/src/pb/clientpb/client_pb.js b/src/pb/clientpb/client_pb.js index f7a9664..6e7edf2 100644 --- a/src/pb/clientpb/client_pb.js +++ b/src/pb/clientpb/client_pb.js @@ -10,6 +10,8 @@ // GENERATED CODE -- DO NOT EDIT! /* eslint-disable */ // @ts-nocheck +if (proto === undefined) { var proto = {commonpb: {}, clientpb: {}, sliverpb: {}}; } + var jspb = require('google-protobuf'); var goog = jspb; diff --git a/src/pb/commonpb/common_pb.js b/src/pb/commonpb/common_pb.js index 59fa405..563c6a4 100644 --- a/src/pb/commonpb/common_pb.js +++ b/src/pb/commonpb/common_pb.js @@ -10,6 +10,8 @@ // GENERATED CODE -- DO NOT EDIT! /* eslint-disable */ // @ts-nocheck +if (proto === undefined) { var proto = {commonpb: {}, clientpb: {}, sliverpb: {}}; } + var jspb = require('google-protobuf'); var goog = jspb; diff --git a/src/pb/sliverpb/sliver_pb.js b/src/pb/sliverpb/sliver_pb.js index eac4054..351dfcf 100644 --- a/src/pb/sliverpb/sliver_pb.js +++ b/src/pb/sliverpb/sliver_pb.js @@ -10,6 +10,8 @@ // GENERATED CODE -- DO NOT EDIT! /* eslint-disable */ // @ts-nocheck +if (proto === undefined) { var proto = {commonpb: {}, clientpb: {}, sliverpb: {}}; } + var jspb = require('google-protobuf'); var goog = jspb;