feat: update ts-proto executable handling to support multiple locations

This commit is contained in:
TrèsAbhi committed 2025-11-27 17:59:34 -06:00
1 parent be778acf39
commit 2e79ccf7eb
1 file changed
+22 -7
+22 -7
View File
@@ -4,7 +4,10 @@ import { readdir, rm } from "fs/promises";
import { promisify } from "util";
const MAX_COMMAND_LENGTH = 2 ** 11;
const TS_PROTO_EXECUTABLE = "./node_modules/.bin/protoc-gen-ts_proto";
const TS_PROTO_EXECUTABLE_LOCATIONS = [
"./node_modules/.bin/protoc-gen-ts_proto",
"../../node_modules/.bin/protoc-gen-ts_proto",
];
const roots = [
// "../../packages/core/src/protos",
@@ -13,12 +16,24 @@ const roots = [
const exec = promisify(execSync);
let executableFileExtension: string;
let tsProtoExecutableLocation: string | undefined = undefined;
if (existsSync(`${TS_PROTO_EXECUTABLE}.exe`)) {
executableFileExtension = ".exe";
} else {
executableFileExtension = "";
for (const location of TS_PROTO_EXECUTABLE_LOCATIONS) {
if (existsSync(location)) {
tsProtoExecutableLocation = location;
break;
} else if (existsSync(`${location}.exe`)) {
tsProtoExecutableLocation = `${location}.exe`;
break;
}
}
if (!tsProtoExecutableLocation) {
throw new Error(
`Could not find ts-proto executable. Checked locations: ${TS_PROTO_EXECUTABLE_LOCATIONS.join(
", "
)}`
);
}
for (const root of roots) {
@@ -33,7 +48,7 @@ for (const root of roots) {
while (files.length > 0) {
let command = [
"protoc",
`--plugin=${TS_PROTO_EXECUTABLE}${executableFileExtension}`,
`--plugin=${tsProtoExecutableLocation}`,
"--ts_proto_opt=esModuleInterop=true",
"--ts_proto_opt=oneof=unions-value",
// "--ts_proto_opt=removeEnumPrefix=true",